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 | |
| 34 | namespace { |
| 35 | #if !defined(ART_USE_PORTABLE_COMPILER) |
| 36 | pthread_once_t llvm_multi_init = PTHREAD_ONCE_INIT; |
| 37 | #endif |
| 38 | void InitializeLLVMForQuick() { |
| 39 | ::llvm::llvm_start_multithreaded(); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | namespace art { |
| 44 | namespace llvm { |
| 45 | ::llvm::Module* makeLLVMModuleContents(::llvm::Module* module); |
| 46 | } |
| 47 | |
| 48 | LLVMInfo::LLVMInfo() { |
| 49 | #if !defined(ART_USE_PORTABLE_COMPILER) |
| 50 | pthread_once(&llvm_multi_init, InitializeLLVMForQuick); |
| 51 | #endif |
| 52 | // Create context, module, intrinsic helper & ir builder |
| 53 | llvm_context_.reset(new ::llvm::LLVMContext()); |
| 54 | llvm_module_ = new ::llvm::Module("art", *llvm_context_); |
| 55 | ::llvm::StructType::create(*llvm_context_, "JavaObject"); |
| 56 | art::llvm::makeLLVMModuleContents(llvm_module_); |
Brian Carlstrom | df62950 | 2013-07-17 22:39:56 -0700 | [diff] [blame] | 57 | intrinsic_helper_.reset(new art::llvm::IntrinsicHelper(*llvm_context_, *llvm_module_)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 58 | ir_builder_.reset(new art::llvm::IRBuilder(*llvm_context_, *llvm_module_, *intrinsic_helper_)); |
| 59 | } |
| 60 | |
| 61 | LLVMInfo::~LLVMInfo() { |
| 62 | } |
| 63 | |
| 64 | extern "C" void ArtInitQuickCompilerContext(art::CompilerDriver& compiler) { |
| 65 | CHECK(compiler.GetCompilerContext() == NULL); |
| 66 | LLVMInfo* llvm_info = new LLVMInfo(); |
| 67 | compiler.SetCompilerContext(llvm_info); |
| 68 | } |
| 69 | |
| 70 | extern "C" void ArtUnInitQuickCompilerContext(art::CompilerDriver& compiler) { |
| 71 | delete reinterpret_cast<LLVMInfo*>(compiler.GetCompilerContext()); |
| 72 | compiler.SetCompilerContext(NULL); |
| 73 | } |
| 74 | |
| 75 | /* Default optimizer/debug setting for the compiler. */ |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 76 | static uint32_t kCompilerOptimizerDisableFlags = 0 | // Disable specific optimizations |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 77 | (1 << kLoadStoreElimination) | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 78 | // (1 << kLoadHoisting) | |
| 79 | // (1 << kSuppressLoads) | |
| 80 | // (1 << kNullCheckElimination) | |
| 81 | // (1 << kPromoteRegs) | |
| 82 | // (1 << kTrackLiveTemps) | |
| 83 | // (1 << kSafeOptimizations) | |
| 84 | // (1 << kBBOpt) | |
| 85 | // (1 << kMatch) | |
| 86 | // (1 << kPromoteCompilerTemps) | |
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 | |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 111 | // TODO: Add a cumulative version of logging, and combine with dex2oat --dump-timing |
| 112 | void CompilationUnit::StartTimingSplit(const char* label) { |
| 113 | if (enable_debug & (1 << kDebugTimings)) { |
| 114 | timings.StartSplit(label); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | void CompilationUnit::NewTimingSplit(const char* label) { |
| 119 | if (enable_debug & (1 << kDebugTimings)) { |
| 120 | timings.NewSplit(label); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | void CompilationUnit::EndTiming() { |
| 125 | if (enable_debug & (1 << kDebugTimings)) { |
| 126 | timings.EndSplit(); |
| 127 | LOG(INFO) << "TIMINGS " << PrettyMethod(method_idx, *dex_file); |
| 128 | LOG(INFO) << Dumpable<base::TimingLogger>(timings); |
| 129 | } |
| 130 | } |
| 131 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 132 | static CompiledMethod* CompileMethod(CompilerDriver& compiler, |
| 133 | const CompilerBackend compiler_backend, |
| 134 | const DexFile::CodeItem* code_item, |
| 135 | uint32_t access_flags, InvokeType invoke_type, |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 136 | uint16_t class_def_idx, uint32_t method_idx, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 137 | jobject class_loader, const DexFile& dex_file |
| 138 | #if defined(ART_USE_PORTABLE_COMPILER) |
| 139 | , llvm::LlvmCompilationUnit* llvm_compilation_unit |
| 140 | #endif |
| 141 | ) { |
| 142 | VLOG(compiler) << "Compiling " << PrettyMethod(method_idx, dex_file) << "..."; |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 143 | if (code_item->insns_size_in_code_units_ >= 0x10000) { |
| 144 | LOG(INFO) << "Method size exceeds compiler limits: " << code_item->insns_size_in_code_units_ |
| 145 | << " in " << PrettyMethod(method_idx, dex_file); |
| 146 | return NULL; |
| 147 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 148 | |
| 149 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 150 | CompilationUnit cu(&compiler.GetArenaPool()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 151 | |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 152 | cu.compiler_driver = &compiler; |
| 153 | cu.class_linker = class_linker; |
| 154 | cu.instruction_set = compiler.GetInstructionSet(); |
| 155 | cu.compiler_backend = compiler_backend; |
| 156 | DCHECK((cu.instruction_set == kThumb2) || |
| 157 | (cu.instruction_set == kX86) || |
| 158 | (cu.instruction_set == kMips)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 159 | |
| 160 | |
| 161 | /* Adjust this value accordingly once inlining is performed */ |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 162 | cu.num_dalvik_registers = code_item->registers_size_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 163 | // TODO: set this from command line |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 164 | cu.compiler_flip_match = false; |
| 165 | bool use_match = !cu.compiler_method_match.empty(); |
| 166 | bool match = use_match && (cu.compiler_flip_match ^ |
| 167 | (PrettyMethod(method_idx, dex_file).find(cu.compiler_method_match) != |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 168 | std::string::npos)); |
| 169 | if (!use_match || match) { |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 170 | cu.disable_opt = kCompilerOptimizerDisableFlags; |
| 171 | cu.enable_debug = kCompilerDebugFlags; |
| 172 | cu.verbose = VLOG_IS_ON(compiler) || |
| 173 | (cu.enable_debug & (1 << kDebugVerbose)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | /* |
| 177 | * TODO: rework handling of optimization and debug flags. Should we split out |
| 178 | * MIR and backend flags? Need command-line setting as well. |
| 179 | */ |
| 180 | |
| 181 | if (compiler_backend == kPortable) { |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 182 | // Fused long branches not currently useful in bitcode. |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 183 | cu.disable_opt |= (1 << kBranchFusing); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 186 | if (cu.instruction_set == kMips) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 187 | // Disable some optimizations for mips for now |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 188 | cu.disable_opt |= ( |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 189 | (1 << kLoadStoreElimination) | |
| 190 | (1 << kLoadHoisting) | |
| 191 | (1 << kSuppressLoads) | |
| 192 | (1 << kNullCheckElimination) | |
| 193 | (1 << kPromoteRegs) | |
| 194 | (1 << kTrackLiveTemps) | |
| 195 | (1 << kSafeOptimizations) | |
| 196 | (1 << kBBOpt) | |
| 197 | (1 << kMatch) | |
| 198 | (1 << kPromoteCompilerTemps)); |
| 199 | } |
| 200 | |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 201 | cu.StartTimingSplit("BuildMIRGraph"); |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 202 | cu.mir_graph.reset(new MIRGraph(&cu, &cu.arena)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 203 | |
| 204 | /* Gathering opcode stats? */ |
| 205 | if (kCompilerDebugFlags & (1 << kDebugCountOpcodes)) { |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 206 | cu.mir_graph->EnableOpcodeCounting(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | /* Build the raw MIR graph */ |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 210 | 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] | 211 | class_loader, dex_file); |
| 212 | |
Ian Rogers | 677ffa4 | 2013-08-21 21:53:05 -0700 | [diff] [blame] | 213 | #if !defined(ART_USE_PORTABLE_COMPILER) |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 214 | if (cu.mir_graph->SkipCompilation(Runtime::Current()->GetCompilerFilter())) { |
buzbee | ee17e0a | 2013-07-31 10:47:37 -0700 | [diff] [blame] | 215 | return NULL; |
| 216 | } |
Ian Rogers | 677ffa4 | 2013-08-21 21:53:05 -0700 | [diff] [blame] | 217 | #endif |
buzbee | ee17e0a | 2013-07-31 10:47:37 -0700 | [diff] [blame] | 218 | |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 219 | cu.NewTimingSplit("MIROpt:CodeLayout"); |
| 220 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 221 | /* Do a code layout pass */ |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 222 | cu.mir_graph->CodeLayout(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 223 | |
| 224 | /* Perform SSA transformation for the whole method */ |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 225 | cu.NewTimingSplit("MIROpt:SSATransform"); |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 226 | cu.mir_graph->SSATransformation(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 227 | |
| 228 | /* Do constant propagation */ |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 229 | cu.NewTimingSplit("MIROpt:ConstantProp"); |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 230 | cu.mir_graph->PropagateConstants(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 231 | |
| 232 | /* Count uses */ |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 233 | cu.mir_graph->MethodUseCount(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 234 | |
| 235 | /* Perform null check elimination */ |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 236 | cu.NewTimingSplit("MIROpt:NullCheckElimination"); |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 237 | cu.mir_graph->NullCheckElimination(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 238 | |
| 239 | /* Combine basic blocks where possible */ |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 240 | cu.NewTimingSplit("MIROpt:BBOpt"); |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 241 | cu.mir_graph->BasicBlockCombine(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 242 | |
| 243 | /* Do some basic block optimizations */ |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 244 | cu.mir_graph->BasicBlockOptimization(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 245 | |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 246 | if (cu.enable_debug & (1 << kDebugDumpCheckStats)) { |
| 247 | cu.mir_graph->DumpCheckStats(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | if (kCompilerDebugFlags & (1 << kDebugCountOpcodes)) { |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 251 | cu.mir_graph->ShowOpcodeStats(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | /* Set up regLocation[] array to describe values - one for each ssa_name. */ |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 255 | cu.mir_graph->BuildRegLocations(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 256 | |
| 257 | CompiledMethod* result = NULL; |
| 258 | |
| 259 | #if defined(ART_USE_PORTABLE_COMPILER) |
| 260 | if (compiler_backend == kPortable) { |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 261 | 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] | 262 | } else { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 263 | #endif |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 264 | switch (compiler.GetInstructionSet()) { |
| 265 | case kThumb2: |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 266 | cu.cg.reset(ArmCodeGenerator(&cu, cu.mir_graph.get(), &cu.arena)); |
Brian Carlstrom | f69863b | 2013-07-17 21:53:13 -0700 | [diff] [blame] | 267 | break; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 268 | case kMips: |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 269 | cu.cg.reset(MipsCodeGenerator(&cu, cu.mir_graph.get(), &cu.arena)); |
Brian Carlstrom | f69863b | 2013-07-17 21:53:13 -0700 | [diff] [blame] | 270 | break; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 271 | case kX86: |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 272 | cu.cg.reset(X86CodeGenerator(&cu, cu.mir_graph.get(), &cu.arena)); |
Brian Carlstrom | f69863b | 2013-07-17 21:53:13 -0700 | [diff] [blame] | 273 | break; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 274 | default: |
| 275 | LOG(FATAL) << "Unexpected instruction set: " << compiler.GetInstructionSet(); |
| 276 | } |
Brian Carlstrom | 9b7085a | 2013-07-18 15:15:21 -0700 | [diff] [blame] | 277 | #if defined(ART_USE_PORTABLE_COMPILER) |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 278 | } |
Brian Carlstrom | 9b7085a | 2013-07-18 15:15:21 -0700 | [diff] [blame] | 279 | #endif |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 280 | |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 281 | cu.cg->Materialize(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 282 | |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 283 | cu.NewTimingSplit("Cleanup"); |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 284 | result = cu.cg->GetCompiledMethod(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 285 | |
| 286 | if (result) { |
| 287 | VLOG(compiler) << "Compiled " << PrettyMethod(method_idx, dex_file); |
| 288 | } else { |
| 289 | VLOG(compiler) << "Deferred " << PrettyMethod(method_idx, dex_file); |
| 290 | } |
| 291 | |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 292 | if (cu.enable_debug & (1 << kDebugShowMemoryUsage)) { |
| 293 | if (cu.arena.BytesAllocated() > (5 * 1024 *1024)) { |
| 294 | MemStats mem_stats(cu.arena); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 295 | LOG(INFO) << PrettyMethod(method_idx, dex_file) << " " << Dumpable<MemStats>(mem_stats); |
| 296 | } |
| 297 | } |
| 298 | |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 299 | if (cu.enable_debug & (1 << kDebugShowSummaryMemoryUsage)) { |
| 300 | LOG(INFO) << "MEMINFO " << cu.arena.BytesAllocated() << " " << cu.mir_graph->GetNumBlocks() |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 301 | << " " << PrettyMethod(method_idx, dex_file); |
| 302 | } |
| 303 | |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 304 | cu.EndTiming(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 305 | return result; |
| 306 | } |
| 307 | |
| 308 | CompiledMethod* CompileOneMethod(CompilerDriver& compiler, |
| 309 | const CompilerBackend backend, |
| 310 | const DexFile::CodeItem* code_item, |
| 311 | uint32_t access_flags, |
| 312 | InvokeType invoke_type, |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 313 | uint16_t class_def_idx, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 314 | uint32_t method_idx, |
| 315 | jobject class_loader, |
| 316 | const DexFile& dex_file, |
| 317 | llvm::LlvmCompilationUnit* llvm_compilation_unit) { |
| 318 | return CompileMethod(compiler, backend, code_item, access_flags, invoke_type, class_def_idx, |
| 319 | method_idx, class_loader, dex_file |
| 320 | #if defined(ART_USE_PORTABLE_COMPILER) |
| 321 | , llvm_compilation_unit |
| 322 | #endif |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 323 | ); // NOLINT(whitespace/parens) |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | } // namespace art |
| 327 | |
| 328 | extern "C" art::CompiledMethod* |
| 329 | ArtQuickCompileMethod(art::CompilerDriver& compiler, |
| 330 | const art::DexFile::CodeItem* code_item, |
| 331 | uint32_t access_flags, art::InvokeType invoke_type, |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 332 | uint16_t class_def_idx, uint32_t method_idx, jobject class_loader, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 333 | const art::DexFile& dex_file) { |
| 334 | // TODO: check method fingerprint here to determine appropriate backend type. Until then, use build default |
| 335 | art::CompilerBackend backend = compiler.GetCompilerBackend(); |
| 336 | return art::CompileOneMethod(compiler, backend, code_item, access_flags, invoke_type, |
| 337 | class_def_idx, method_idx, class_loader, dex_file, |
| 338 | NULL /* use thread llvm_info */); |
| 339 | } |