Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 <llvm/Support/Threading.h> |
| 18 | |
| 19 | #include "compiler_internals.h" |
| 20 | #include "driver/compiler_driver.h" |
| 21 | #include "dataflow_iterator-inl.h" |
| 22 | #include "leb128.h" |
| 23 | #include "mirror/object.h" |
| 24 | #include "runtime.h" |
| 25 | #include "backend.h" |
| 26 | #include "base/logging.h" |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 27 | #include "base/timing_logger.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 28 | |
| 29 | #if defined(ART_USE_PORTABLE_COMPILER) |
| 30 | #include "dex/portable/mir_to_gbc.h" |
| 31 | #include "llvm/llvm_compilation_unit.h" |
| 32 | #endif |
| 33 | |
Vladimir Marko | 5c96e6b | 2013-11-14 15:34:17 +0000 | [diff] [blame] | 34 | #include "dex/quick/dex_file_to_method_inliner_map.h" |
| 35 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 36 | namespace { |
| 37 | #if !defined(ART_USE_PORTABLE_COMPILER) |
| 38 | pthread_once_t llvm_multi_init = PTHREAD_ONCE_INIT; |
| 39 | #endif |
| 40 | void InitializeLLVMForQuick() { |
| 41 | ::llvm::llvm_start_multithreaded(); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | namespace art { |
| 46 | namespace llvm { |
| 47 | ::llvm::Module* makeLLVMModuleContents(::llvm::Module* module); |
| 48 | } |
| 49 | |
| 50 | LLVMInfo::LLVMInfo() { |
| 51 | #if !defined(ART_USE_PORTABLE_COMPILER) |
| 52 | pthread_once(&llvm_multi_init, InitializeLLVMForQuick); |
| 53 | #endif |
| 54 | // Create context, module, intrinsic helper & ir builder |
| 55 | llvm_context_.reset(new ::llvm::LLVMContext()); |
| 56 | llvm_module_ = new ::llvm::Module("art", *llvm_context_); |
| 57 | ::llvm::StructType::create(*llvm_context_, "JavaObject"); |
| 58 | art::llvm::makeLLVMModuleContents(llvm_module_); |
Brian Carlstrom | df62950 | 2013-07-17 22:39:56 -0700 | [diff] [blame] | 59 | intrinsic_helper_.reset(new art::llvm::IntrinsicHelper(*llvm_context_, *llvm_module_)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 60 | ir_builder_.reset(new art::llvm::IRBuilder(*llvm_context_, *llvm_module_, *intrinsic_helper_)); |
| 61 | } |
| 62 | |
| 63 | LLVMInfo::~LLVMInfo() { |
| 64 | } |
| 65 | |
Vladimir Marko | 867a2b3 | 2013-12-10 13:01:13 +0000 | [diff] [blame] | 66 | extern "C" void ArtInitQuickCompilerContext(art::CompilerDriver& driver) { |
| 67 | CHECK(driver.GetCompilerContext() == NULL); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Vladimir Marko | 867a2b3 | 2013-12-10 13:01:13 +0000 | [diff] [blame] | 70 | extern "C" void ArtUnInitQuickCompilerContext(art::CompilerDriver& driver) { |
Vladimir Marko | 5816ed4 | 2013-11-27 17:04:20 +0000 | [diff] [blame] | 71 | CHECK(driver.GetCompilerContext() == NULL); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | /* Default optimizer/debug setting for the compiler. */ |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 75 | static uint32_t kCompilerOptimizerDisableFlags = 0 | // Disable specific optimizations |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 76 | (1 << kLoadStoreElimination) | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 77 | // (1 << kLoadHoisting) | |
| 78 | // (1 << kSuppressLoads) | |
| 79 | // (1 << kNullCheckElimination) | |
| 80 | // (1 << kPromoteRegs) | |
| 81 | // (1 << kTrackLiveTemps) | |
| 82 | // (1 << kSafeOptimizations) | |
| 83 | // (1 << kBBOpt) | |
| 84 | // (1 << kMatch) | |
| 85 | // (1 << kPromoteCompilerTemps) | |
buzbee | 17189ac | 2013-11-08 11:07:02 -0800 | [diff] [blame] | 86 | // (1 << kSuppressExceptionEdges) | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 87 | 0; |
| 88 | |
| 89 | static uint32_t kCompilerDebugFlags = 0 | // Enable debug/testing modes |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 90 | // (1 << kDebugDisplayMissingTargets) | |
| 91 | // (1 << kDebugVerbose) | |
| 92 | // (1 << kDebugDumpCFG) | |
| 93 | // (1 << kDebugSlowFieldPath) | |
| 94 | // (1 << kDebugSlowInvokePath) | |
| 95 | // (1 << kDebugSlowStringPath) | |
| 96 | // (1 << kDebugSlowestFieldPath) | |
| 97 | // (1 << kDebugSlowestStringPath) | |
| 98 | // (1 << kDebugExerciseResolveMethod) | |
| 99 | // (1 << kDebugVerifyDataflow) | |
| 100 | // (1 << kDebugShowMemoryUsage) | |
| 101 | // (1 << kDebugShowNops) | |
| 102 | // (1 << kDebugCountOpcodes) | |
| 103 | // (1 << kDebugDumpCheckStats) | |
| 104 | // (1 << kDebugDumpBitcodeFile) | |
| 105 | // (1 << kDebugVerifyBitcode) | |
| 106 | // (1 << kDebugShowSummaryMemoryUsage) | |
buzbee | ee17e0a | 2013-07-31 10:47:37 -0700 | [diff] [blame] | 107 | // (1 << kDebugShowFilterStats) | |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 108 | // (1 << kDebugTimings) | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 109 | 0; |
| 110 | |
Vladimir Marko | 25724ef | 2013-11-12 15:09:20 +0000 | [diff] [blame] | 111 | CompilationUnit::CompilationUnit(ArenaPool* pool) |
| 112 | : compiler_driver(NULL), |
| 113 | class_linker(NULL), |
| 114 | dex_file(NULL), |
| 115 | class_loader(NULL), |
| 116 | class_def_idx(0), |
| 117 | method_idx(0), |
| 118 | code_item(NULL), |
| 119 | access_flags(0), |
| 120 | invoke_type(kDirect), |
| 121 | shorty(NULL), |
| 122 | disable_opt(0), |
| 123 | enable_debug(0), |
| 124 | verbose(false), |
| 125 | compiler_backend(kNoBackend), |
| 126 | instruction_set(kNone), |
| 127 | num_dalvik_registers(0), |
| 128 | insns(NULL), |
| 129 | num_ins(0), |
| 130 | num_outs(0), |
| 131 | num_regs(0), |
| 132 | num_compiler_temps(0), |
| 133 | compiler_flip_match(false), |
| 134 | arena(pool), |
| 135 | mir_graph(NULL), |
| 136 | cg(NULL), |
| 137 | timings("QuickCompiler", true, false) { |
| 138 | } |
| 139 | |
| 140 | CompilationUnit::~CompilationUnit() { |
| 141 | } |
| 142 | |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 143 | // TODO: Add a cumulative version of logging, and combine with dex2oat --dump-timing |
| 144 | void CompilationUnit::StartTimingSplit(const char* label) { |
| 145 | if (enable_debug & (1 << kDebugTimings)) { |
| 146 | timings.StartSplit(label); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | void CompilationUnit::NewTimingSplit(const char* label) { |
| 151 | if (enable_debug & (1 << kDebugTimings)) { |
| 152 | timings.NewSplit(label); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | void CompilationUnit::EndTiming() { |
| 157 | if (enable_debug & (1 << kDebugTimings)) { |
| 158 | timings.EndSplit(); |
| 159 | LOG(INFO) << "TIMINGS " << PrettyMethod(method_idx, *dex_file); |
Ian Rogers | 5fe9af7 | 2013-11-14 00:17:20 -0800 | [diff] [blame] | 160 | LOG(INFO) << Dumpable<TimingLogger>(timings); |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 161 | } |
| 162 | } |
| 163 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 164 | static CompiledMethod* CompileMethod(CompilerDriver& compiler, |
| 165 | const CompilerBackend compiler_backend, |
| 166 | const DexFile::CodeItem* code_item, |
| 167 | uint32_t access_flags, InvokeType invoke_type, |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 168 | uint16_t class_def_idx, uint32_t method_idx, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 169 | jobject class_loader, const DexFile& dex_file |
| 170 | #if defined(ART_USE_PORTABLE_COMPILER) |
| 171 | , llvm::LlvmCompilationUnit* llvm_compilation_unit |
| 172 | #endif |
| 173 | ) { |
| 174 | VLOG(compiler) << "Compiling " << PrettyMethod(method_idx, dex_file) << "..."; |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 175 | if (code_item->insns_size_in_code_units_ >= 0x10000) { |
| 176 | LOG(INFO) << "Method size exceeds compiler limits: " << code_item->insns_size_in_code_units_ |
| 177 | << " in " << PrettyMethod(method_idx, dex_file); |
| 178 | return NULL; |
| 179 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 180 | |
| 181 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 182 | CompilationUnit cu(&compiler.GetArenaPool()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 183 | |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 184 | cu.compiler_driver = &compiler; |
| 185 | cu.class_linker = class_linker; |
| 186 | cu.instruction_set = compiler.GetInstructionSet(); |
| 187 | cu.compiler_backend = compiler_backend; |
| 188 | DCHECK((cu.instruction_set == kThumb2) || |
| 189 | (cu.instruction_set == kX86) || |
| 190 | (cu.instruction_set == kMips)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 191 | |
| 192 | |
| 193 | /* Adjust this value accordingly once inlining is performed */ |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 194 | cu.num_dalvik_registers = code_item->registers_size_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 195 | // TODO: set this from command line |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 196 | cu.compiler_flip_match = false; |
| 197 | bool use_match = !cu.compiler_method_match.empty(); |
| 198 | bool match = use_match && (cu.compiler_flip_match ^ |
| 199 | (PrettyMethod(method_idx, dex_file).find(cu.compiler_method_match) != |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 200 | std::string::npos)); |
| 201 | if (!use_match || match) { |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 202 | cu.disable_opt = kCompilerOptimizerDisableFlags; |
| 203 | cu.enable_debug = kCompilerDebugFlags; |
| 204 | cu.verbose = VLOG_IS_ON(compiler) || |
| 205 | (cu.enable_debug & (1 << kDebugVerbose)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | /* |
| 209 | * TODO: rework handling of optimization and debug flags. Should we split out |
| 210 | * MIR and backend flags? Need command-line setting as well. |
| 211 | */ |
| 212 | |
| 213 | if (compiler_backend == kPortable) { |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 214 | // Fused long branches not currently useful in bitcode. |
buzbee | 17189ac | 2013-11-08 11:07:02 -0800 | [diff] [blame] | 215 | cu.disable_opt |= |
| 216 | (1 << kBranchFusing) | |
| 217 | (1 << kSuppressExceptionEdges); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 220 | if (cu.instruction_set == kMips) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 221 | // Disable some optimizations for mips for now |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 222 | cu.disable_opt |= ( |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 223 | (1 << kLoadStoreElimination) | |
| 224 | (1 << kLoadHoisting) | |
| 225 | (1 << kSuppressLoads) | |
| 226 | (1 << kNullCheckElimination) | |
| 227 | (1 << kPromoteRegs) | |
| 228 | (1 << kTrackLiveTemps) | |
| 229 | (1 << kSafeOptimizations) | |
| 230 | (1 << kBBOpt) | |
| 231 | (1 << kMatch) | |
| 232 | (1 << kPromoteCompilerTemps)); |
| 233 | } |
| 234 | |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 235 | cu.StartTimingSplit("BuildMIRGraph"); |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 236 | cu.mir_graph.reset(new MIRGraph(&cu, &cu.arena)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 237 | |
| 238 | /* Gathering opcode stats? */ |
| 239 | if (kCompilerDebugFlags & (1 << kDebugCountOpcodes)) { |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 240 | cu.mir_graph->EnableOpcodeCounting(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | /* Build the raw MIR graph */ |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 244 | cu.mir_graph->InlineMethod(code_item, access_flags, invoke_type, class_def_idx, method_idx, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 245 | class_loader, dex_file); |
| 246 | |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 247 | cu.NewTimingSplit("MIROpt:CheckFilters"); |
Ian Rogers | 677ffa4 | 2013-08-21 21:53:05 -0700 | [diff] [blame] | 248 | #if !defined(ART_USE_PORTABLE_COMPILER) |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 249 | if (cu.mir_graph->SkipCompilation(Runtime::Current()->GetCompilerFilter())) { |
buzbee | ee17e0a | 2013-07-31 10:47:37 -0700 | [diff] [blame] | 250 | return NULL; |
| 251 | } |
Ian Rogers | 677ffa4 | 2013-08-21 21:53:05 -0700 | [diff] [blame] | 252 | #endif |
buzbee | ee17e0a | 2013-07-31 10:47:37 -0700 | [diff] [blame] | 253 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 254 | /* Do a code layout pass */ |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 255 | cu.NewTimingSplit("MIROpt:CodeLayout"); |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 256 | cu.mir_graph->CodeLayout(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 257 | |
| 258 | /* Perform SSA transformation for the whole method */ |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 259 | cu.NewTimingSplit("MIROpt:SSATransform"); |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 260 | cu.mir_graph->SSATransformation(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 261 | |
| 262 | /* Do constant propagation */ |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 263 | cu.NewTimingSplit("MIROpt:ConstantProp"); |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 264 | cu.mir_graph->PropagateConstants(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 265 | |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 266 | cu.NewTimingSplit("MIROpt:InitRegLoc"); |
| 267 | cu.mir_graph->InitRegLocations(); |
| 268 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 269 | /* Count uses */ |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 270 | cu.NewTimingSplit("MIROpt:UseCount"); |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 271 | cu.mir_graph->MethodUseCount(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 272 | |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 273 | /* Perform null check elimination and type inference*/ |
| 274 | cu.NewTimingSplit("MIROpt:NCE_TypeInference"); |
| 275 | cu.mir_graph->NullCheckEliminationAndTypeInference(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 276 | |
| 277 | /* Combine basic blocks where possible */ |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 278 | cu.NewTimingSplit("MIROpt:BBCombine"); |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 279 | cu.mir_graph->BasicBlockCombine(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 280 | |
| 281 | /* Do some basic block optimizations */ |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 282 | cu.NewTimingSplit("MIROpt:BBOpt"); |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 283 | cu.mir_graph->BasicBlockOptimization(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 284 | |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 285 | if (cu.enable_debug & (1 << kDebugDumpCheckStats)) { |
| 286 | cu.mir_graph->DumpCheckStats(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | if (kCompilerDebugFlags & (1 << kDebugCountOpcodes)) { |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 290 | cu.mir_graph->ShowOpcodeStats(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 291 | } |
| 292 | |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 293 | /* Reassociate sreg names with original Dalvik vreg names. */ |
| 294 | cu.mir_graph->RemapRegLocations(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 295 | |
| 296 | CompiledMethod* result = NULL; |
| 297 | |
| 298 | #if defined(ART_USE_PORTABLE_COMPILER) |
| 299 | if (compiler_backend == kPortable) { |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 300 | cu.cg.reset(PortableCodeGenerator(&cu, cu.mir_graph.get(), &cu.arena, llvm_compilation_unit)); |
Brian Carlstrom | 9b7085a | 2013-07-18 15:15:21 -0700 | [diff] [blame] | 301 | } else { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 302 | #endif |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 303 | switch (compiler.GetInstructionSet()) { |
| 304 | case kThumb2: |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 305 | cu.cg.reset(ArmCodeGenerator(&cu, cu.mir_graph.get(), &cu.arena)); |
Brian Carlstrom | f69863b | 2013-07-17 21:53:13 -0700 | [diff] [blame] | 306 | break; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 307 | case kMips: |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 308 | cu.cg.reset(MipsCodeGenerator(&cu, cu.mir_graph.get(), &cu.arena)); |
Brian Carlstrom | f69863b | 2013-07-17 21:53:13 -0700 | [diff] [blame] | 309 | break; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 310 | case kX86: |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 311 | cu.cg.reset(X86CodeGenerator(&cu, cu.mir_graph.get(), &cu.arena)); |
Brian Carlstrom | f69863b | 2013-07-17 21:53:13 -0700 | [diff] [blame] | 312 | break; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 313 | default: |
| 314 | LOG(FATAL) << "Unexpected instruction set: " << compiler.GetInstructionSet(); |
| 315 | } |
Brian Carlstrom | 9b7085a | 2013-07-18 15:15:21 -0700 | [diff] [blame] | 316 | #if defined(ART_USE_PORTABLE_COMPILER) |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 317 | } |
Brian Carlstrom | 9b7085a | 2013-07-18 15:15:21 -0700 | [diff] [blame] | 318 | #endif |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 319 | |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 320 | cu.cg->Materialize(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 321 | |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 322 | cu.NewTimingSplit("Dedupe"); /* deduping takes up the vast majority of time in GetCompiledMethod(). */ |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 323 | result = cu.cg->GetCompiledMethod(); |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 324 | cu.NewTimingSplit("Cleanup"); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 325 | |
| 326 | if (result) { |
| 327 | VLOG(compiler) << "Compiled " << PrettyMethod(method_idx, dex_file); |
| 328 | } else { |
| 329 | VLOG(compiler) << "Deferred " << PrettyMethod(method_idx, dex_file); |
| 330 | } |
| 331 | |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 332 | if (cu.enable_debug & (1 << kDebugShowMemoryUsage)) { |
| 333 | if (cu.arena.BytesAllocated() > (5 * 1024 *1024)) { |
| 334 | MemStats mem_stats(cu.arena); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 335 | LOG(INFO) << PrettyMethod(method_idx, dex_file) << " " << Dumpable<MemStats>(mem_stats); |
| 336 | } |
| 337 | } |
| 338 | |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 339 | if (cu.enable_debug & (1 << kDebugShowSummaryMemoryUsage)) { |
| 340 | LOG(INFO) << "MEMINFO " << cu.arena.BytesAllocated() << " " << cu.mir_graph->GetNumBlocks() |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 341 | << " " << PrettyMethod(method_idx, dex_file); |
| 342 | } |
| 343 | |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 344 | cu.EndTiming(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 345 | return result; |
| 346 | } |
| 347 | |
| 348 | CompiledMethod* CompileOneMethod(CompilerDriver& compiler, |
| 349 | const CompilerBackend backend, |
| 350 | const DexFile::CodeItem* code_item, |
| 351 | uint32_t access_flags, |
| 352 | InvokeType invoke_type, |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 353 | uint16_t class_def_idx, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 354 | uint32_t method_idx, |
| 355 | jobject class_loader, |
| 356 | const DexFile& dex_file, |
| 357 | llvm::LlvmCompilationUnit* llvm_compilation_unit) { |
| 358 | return CompileMethod(compiler, backend, code_item, access_flags, invoke_type, class_def_idx, |
| 359 | method_idx, class_loader, dex_file |
| 360 | #if defined(ART_USE_PORTABLE_COMPILER) |
| 361 | , llvm_compilation_unit |
| 362 | #endif |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 363 | ); // NOLINT(whitespace/parens) |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | } // namespace art |
| 367 | |
| 368 | extern "C" art::CompiledMethod* |
| 369 | ArtQuickCompileMethod(art::CompilerDriver& compiler, |
| 370 | const art::DexFile::CodeItem* code_item, |
| 371 | uint32_t access_flags, art::InvokeType invoke_type, |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 372 | uint16_t class_def_idx, uint32_t method_idx, jobject class_loader, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 373 | const art::DexFile& dex_file) { |
| 374 | // TODO: check method fingerprint here to determine appropriate backend type. Until then, use build default |
| 375 | art::CompilerBackend backend = compiler.GetCompilerBackend(); |
| 376 | return art::CompileOneMethod(compiler, backend, code_item, access_flags, invoke_type, |
| 377 | class_def_idx, method_idx, class_loader, dex_file, |
| 378 | NULL /* use thread llvm_info */); |
| 379 | } |