blob: 9bb17199e01a08d281e9cb461c369b50dd1d7023 [file] [log] [blame]
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +00001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "compilers.h"
18#include "dex/mir_graph.h"
19#include "dex/quick/mir_to_lir.h"
20#include "elf_writer_quick.h"
21#include "mirror/art_method-inl.h"
22
23namespace art {
24
25extern "C" void ArtInitQuickCompilerContext(art::CompilerDriver& driver);
26extern "C" void ArtUnInitQuickCompilerContext(art::CompilerDriver& driver);
27extern "C" art::CompiledMethod* ArtQuickCompileMethod(art::CompilerDriver& driver,
28 const art::DexFile::CodeItem* code_item,
29 uint32_t access_flags,
30 art::InvokeType invoke_type,
31 uint16_t class_def_idx,
32 uint32_t method_idx,
33 jobject class_loader,
34 const art::DexFile& dex_file);
35
36extern "C" art::CompiledMethod* ArtQuickJniCompileMethod(art::CompilerDriver& driver,
37 uint32_t access_flags, uint32_t method_idx,
38 const art::DexFile& dex_file);
39
40// Hack for CFI CIE initialization
41extern std::vector<uint8_t>* X86CFIInitialization();
42
43void QuickCompiler::Init(CompilerDriver& driver) const {
44 ArtInitQuickCompilerContext(driver);
45}
46
47void QuickCompiler::UnInit(CompilerDriver& driver) const {
48 ArtUnInitQuickCompilerContext(driver);
49}
50
51CompiledMethod* QuickCompiler::Compile(CompilerDriver& driver,
52 const DexFile::CodeItem* code_item,
53 uint32_t access_flags,
54 InvokeType invoke_type,
55 uint16_t class_def_idx,
56 uint32_t method_idx,
57 jobject class_loader,
58 const DexFile& dex_file) const {
59 CompiledMethod* method = TryCompileWithSeaIR(driver,
60 code_item,
61 access_flags,
62 invoke_type,
63 class_def_idx,
64 method_idx,
65 class_loader,
66 dex_file);
67 if (method != nullptr) return method;
68
69 return ArtQuickCompileMethod(driver,
70 code_item,
71 access_flags,
72 invoke_type,
73 class_def_idx,
74 method_idx,
75 class_loader,
76 dex_file);
77}
78
79CompiledMethod* QuickCompiler::JniCompile(CompilerDriver& driver,
80 uint32_t access_flags,
81 uint32_t method_idx,
82 const DexFile& dex_file) const {
83 return ArtQuickJniCompileMethod(driver, access_flags, method_idx, dex_file);
84}
85
86uintptr_t QuickCompiler::GetEntryPointOf(mirror::ArtMethod* method) const {
87 return reinterpret_cast<uintptr_t>(method->GetEntryPointFromQuickCompiledCode());
88}
89
90bool QuickCompiler::WriteElf(art::File* file,
91 OatWriter* oat_writer,
92 const std::vector<const art::DexFile*>& dex_files,
93 const std::string& android_root,
94 bool is_host, const CompilerDriver& driver) const
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000095 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
96 return art::ElfWriterQuick::Create(file, oat_writer, dex_files, android_root, is_host, driver);
97}
98
99Backend* QuickCompiler::GetCodeGenerator(CompilationUnit* cu, void* compilation_unit) const {
100 Mir2Lir* mir_to_lir = nullptr;
101 switch (cu->instruction_set) {
102 case kThumb2:
103 mir_to_lir = ArmCodeGenerator(cu, cu->mir_graph.get(), &cu->arena);
104 break;
105 case kMips:
106 mir_to_lir = MipsCodeGenerator(cu, cu->mir_graph.get(), &cu->arena);
107 break;
108 case kX86:
109 mir_to_lir = X86CodeGenerator(cu, cu->mir_graph.get(), &cu->arena);
110 break;
111 default:
112 LOG(FATAL) << "Unexpected instruction set: " << cu->instruction_set;
113 }
114
115 /* The number of compiler temporaries depends on backend so set it up now if possible */
116 if (mir_to_lir) {
117 size_t max_temps = mir_to_lir->GetMaxPossibleCompilerTemps();
118 bool set_max = cu->mir_graph->SetMaxAvailableNonSpecialCompilerTemps(max_temps);
119 CHECK(set_max);
120 }
121 return mir_to_lir;
122}
123
124std::vector<uint8_t>* QuickCompiler::GetCallFrameInformationInitialization(
Nicolas Geoffray896362b2014-03-13 09:50:25 +0000125 const CompilerDriver& driver) const {
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000126 if (driver.GetInstructionSet() == kX86) {
127 return X86CFIInitialization();
128 }
129 return nullptr;
130}
131
132CompiledMethod* OptimizingCompiler::Compile(CompilerDriver& driver,
133 const DexFile::CodeItem* code_item,
134 uint32_t access_flags,
135 InvokeType invoke_type,
136 uint16_t class_def_idx,
137 uint32_t method_idx,
138 jobject class_loader,
139 const DexFile& dex_file) const {
140 CompiledMethod* method = TryCompile(
141 driver, code_item, access_flags, invoke_type, class_def_idx, method_idx,
142 class_loader, dex_file);
143 if (method != nullptr) return method;
144
145 return QuickCompiler::Compile(
146 driver, code_item, access_flags, invoke_type, class_def_idx, method_idx,
147 class_loader, dex_file);
148}
149
150} // namespace art