buzbee | 67bf885 | 2011-08-17 17:51:35 -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 | |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 17 | #include "compiler.h" |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 18 | #include "compiler_internals.h" |
| 19 | #include "dataflow.h" |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 20 | #include "ssa_transformation.h" |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 21 | #include "leb128.h" |
Brian Carlstrom | 9baa4ae | 2011-09-01 21:14:14 -0700 | [diff] [blame] | 22 | #include "object.h" |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 23 | #include "runtime.h" |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 24 | #include "codegen/codegen_util.h" |
| 25 | #include "codegen/method_bitcode.h" |
| 26 | #include "codegen/method_codegen_driver.h" |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 27 | |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame] | 28 | #include <llvm/Support/Threading.h> |
| 29 | |
| 30 | namespace { |
Shih-wei Liao | 215a926 | 2012-10-12 10:29:46 -0700 | [diff] [blame] | 31 | #if !defined(ART_USE_LLVM_COMPILER) |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame] | 32 | pthread_once_t llvm_multi_init = PTHREAD_ONCE_INIT; |
Shih-wei Liao | 215a926 | 2012-10-12 10:29:46 -0700 | [diff] [blame] | 33 | #endif |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame] | 34 | void InitializeLLVMForQuick() { |
| 35 | llvm::llvm_start_multithreaded(); |
| 36 | } |
| 37 | } |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame] | 38 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 39 | namespace art { |
| 40 | |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame] | 41 | LLVMInfo::LLVMInfo() { |
| 42 | #if !defined(ART_USE_LLVM_COMPILER) |
| 43 | pthread_once(&llvm_multi_init, InitializeLLVMForQuick); |
| 44 | #endif |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 45 | // Create context, module, intrinsic helper & ir builder |
| 46 | llvm_context_.reset(new llvm::LLVMContext()); |
TDYa127 | 55e5e6c | 2012-09-11 15:14:42 -0700 | [diff] [blame] | 47 | llvm_module_ = new llvm::Module("art", *llvm_context_); |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 48 | llvm::StructType::create(*llvm_context_, "JavaObject"); |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 49 | intrinsic_helper_.reset( new greenland::IntrinsicHelper(*llvm_context_, *llvm_module_)); |
| 50 | ir_builder_.reset(new greenland::IRBuilder(*llvm_context_, *llvm_module_, *intrinsic_helper_)); |
| 51 | } |
| 52 | |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame] | 53 | LLVMInfo::~LLVMInfo() { |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | extern "C" void ArtInitQuickCompilerContext(art::Compiler& compiler) { |
| 57 | CHECK(compiler.GetCompilerContext() == NULL); |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame] | 58 | LLVMInfo* llvmInfo = new LLVMInfo(); |
| 59 | compiler.SetCompilerContext(llvmInfo); |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | extern "C" void ArtUnInitQuickCompilerContext(art::Compiler& compiler) { |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame] | 63 | delete reinterpret_cast<LLVMInfo*>(compiler.GetCompilerContext()); |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 64 | compiler.SetCompilerContext(NULL); |
| 65 | } |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 66 | |
buzbee | ce30293 | 2011-10-04 14:32:18 -0700 | [diff] [blame] | 67 | /* Default optimizer/debug setting for the compiler. */ |
Elliott Hughes | e52e49b | 2012-04-02 16:05:44 -0700 | [diff] [blame] | 68 | static uint32_t kCompilerOptimizerDisableFlags = 0 | // Disable specific optimizations |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 69 | //(1 << kLoadStoreElimination) | |
| 70 | //(1 << kLoadHoisting) | |
| 71 | //(1 << kSuppressLoads) | |
| 72 | //(1 << kNullCheckElimination) | |
| 73 | //(1 << kPromoteRegs) | |
| 74 | //(1 << kTrackLiveTemps) | |
| 75 | //(1 << kSkipLargeMethodOptimization) | |
| 76 | //(1 << kSafeOptimizations) | |
| 77 | //(1 << kBBOpt) | |
| 78 | //(1 << kMatch) | |
| 79 | //(1 << kPromoteCompilerTemps) | |
| 80 | 0; |
buzbee | ce30293 | 2011-10-04 14:32:18 -0700 | [diff] [blame] | 81 | |
Elliott Hughes | e52e49b | 2012-04-02 16:05:44 -0700 | [diff] [blame] | 82 | static uint32_t kCompilerDebugFlags = 0 | // Enable debug/testing modes |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 83 | //(1 << kDebugDisplayMissingTargets) | |
| 84 | //(1 << kDebugVerbose) | |
| 85 | //(1 << kDebugDumpCFG) | |
| 86 | //(1 << kDebugSlowFieldPath) | |
| 87 | //(1 << kDebugSlowInvokePath) | |
| 88 | //(1 << kDebugSlowStringPath) | |
| 89 | //(1 << kDebugSlowestFieldPath) | |
| 90 | //(1 << kDebugSlowestStringPath) | |
| 91 | //(1 << kDebugExerciseResolveMethod) | |
| 92 | //(1 << kDebugVerifyDataflow) | |
| 93 | //(1 << kDebugShowMemoryUsage) | |
| 94 | //(1 << kDebugShowNops) | |
| 95 | //(1 << kDebugCountOpcodes) | |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame] | 96 | //(1 << kDebugDumpCheckStats) | |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 97 | //(1 << kDebugDumpBitcodeFile) | |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 98 | //(1 << kDebugVerifyBitcode) | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 99 | 0; |
buzbee | ce30293 | 2011-10-04 14:32:18 -0700 | [diff] [blame] | 100 | |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 101 | inline bool contentIsInsn(const uint16_t* codePtr) { |
| 102 | uint16_t instr = *codePtr; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 103 | Instruction::Code opcode = (Instruction::Code)(instr & 0xff); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 104 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 105 | /* |
| 106 | * Since the low 8-bit in metadata may look like NOP, we need to check |
| 107 | * both the low and whole sub-word to determine whether it is code or data. |
| 108 | */ |
| 109 | return (opcode != Instruction::NOP || instr == 0); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /* |
| 113 | * Parse an instruction, return the length of the instruction |
| 114 | */ |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 115 | inline int parseInsn(CompilationUnit* cUnit, const uint16_t* codePtr, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 116 | DecodedInstruction* decoded_instruction, bool printMe) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 117 | { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 118 | // Don't parse instruction data |
| 119 | if (!contentIsInsn(codePtr)) { |
| 120 | return 0; |
| 121 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 122 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 123 | const Instruction* instruction = Instruction::At(codePtr); |
| 124 | *decoded_instruction = DecodedInstruction(instruction); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 125 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 126 | if (printMe) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 127 | char* decodedString = oatGetDalvikDisassembly(cUnit, *decoded_instruction, |
| 128 | NULL); |
| 129 | LOG(INFO) << codePtr << ": 0x" |
| 130 | << std::hex << static_cast<int>(decoded_instruction->opcode) |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 131 | << " " << decodedString; |
| 132 | } |
| 133 | return instruction->SizeInCodeUnits(); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | #define UNKNOWN_TARGET 0xffffffff |
| 137 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 138 | inline bool isGoto(MIR* insn) { |
| 139 | switch (insn->dalvikInsn.opcode) { |
| 140 | case Instruction::GOTO: |
| 141 | case Instruction::GOTO_16: |
| 142 | case Instruction::GOTO_32: |
| 143 | return true; |
| 144 | default: |
| 145 | return false; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 146 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /* |
| 150 | * Identify unconditional branch instructions |
| 151 | */ |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 152 | inline bool isUnconditionalBranch(MIR* insn) { |
| 153 | switch (insn->dalvikInsn.opcode) { |
| 154 | case Instruction::RETURN_VOID: |
| 155 | case Instruction::RETURN: |
| 156 | case Instruction::RETURN_WIDE: |
| 157 | case Instruction::RETURN_OBJECT: |
| 158 | return true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 159 | default: |
| 160 | return isGoto(insn); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 161 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | /* Split an existing block from the specified code offset into two */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 165 | BasicBlock *splitBlock(CompilationUnit* cUnit, unsigned int codeOffset, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 166 | BasicBlock* origBlock, BasicBlock** immedPredBlockP) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 167 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 168 | MIR* insn = origBlock->firstMIRInsn; |
| 169 | while (insn) { |
| 170 | if (insn->offset == codeOffset) break; |
| 171 | insn = insn->next; |
| 172 | } |
| 173 | if (insn == NULL) { |
| 174 | LOG(FATAL) << "Break split failed"; |
| 175 | } |
| 176 | BasicBlock *bottomBlock = oatNewBB(cUnit, kDalvikByteCode, |
| 177 | cUnit->numBlocks++); |
| 178 | oatInsertGrowableList(cUnit, &cUnit->blockList, (intptr_t) bottomBlock); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 179 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 180 | bottomBlock->startOffset = codeOffset; |
| 181 | bottomBlock->firstMIRInsn = insn; |
| 182 | bottomBlock->lastMIRInsn = origBlock->lastMIRInsn; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 183 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 184 | /* Add it to the quick lookup cache */ |
| 185 | cUnit->blockMap.Put(bottomBlock->startOffset, bottomBlock); |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 186 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 187 | /* Handle the taken path */ |
| 188 | bottomBlock->taken = origBlock->taken; |
| 189 | if (bottomBlock->taken) { |
| 190 | origBlock->taken = NULL; |
| 191 | oatDeleteGrowableList(bottomBlock->taken->predecessors, |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 192 | (intptr_t)origBlock); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 193 | oatInsertGrowableList(cUnit, bottomBlock->taken->predecessors, |
| 194 | (intptr_t)bottomBlock); |
| 195 | } |
| 196 | |
| 197 | /* Handle the fallthrough path */ |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 198 | bottomBlock->fallThrough = origBlock->fallThrough; |
| 199 | origBlock->fallThrough = bottomBlock; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 200 | oatInsertGrowableList(cUnit, bottomBlock->predecessors, |
| 201 | (intptr_t)origBlock); |
| 202 | if (bottomBlock->fallThrough) { |
| 203 | oatDeleteGrowableList(bottomBlock->fallThrough->predecessors, |
| 204 | (intptr_t)origBlock); |
| 205 | oatInsertGrowableList(cUnit, bottomBlock->fallThrough->predecessors, |
| 206 | (intptr_t)bottomBlock); |
| 207 | } |
| 208 | |
| 209 | /* Handle the successor list */ |
| 210 | if (origBlock->successorBlockList.blockListType != kNotUsed) { |
| 211 | bottomBlock->successorBlockList = origBlock->successorBlockList; |
| 212 | origBlock->successorBlockList.blockListType = kNotUsed; |
| 213 | GrowableListIterator iterator; |
| 214 | |
| 215 | oatGrowableListIteratorInit(&bottomBlock->successorBlockList.blocks, |
| 216 | &iterator); |
| 217 | while (true) { |
| 218 | SuccessorBlockInfo *successorBlockInfo = |
| 219 | (SuccessorBlockInfo *) oatGrowableListIteratorNext(&iterator); |
| 220 | if (successorBlockInfo == NULL) break; |
| 221 | BasicBlock *bb = successorBlockInfo->block; |
| 222 | oatDeleteGrowableList(bb->predecessors, (intptr_t)origBlock); |
| 223 | oatInsertGrowableList(cUnit, bb->predecessors, (intptr_t)bottomBlock); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 224 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 225 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 226 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 227 | origBlock->lastMIRInsn = insn->prev; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 228 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 229 | insn->prev->next = NULL; |
| 230 | insn->prev = NULL; |
| 231 | /* |
| 232 | * Update the immediate predecessor block pointer so that outgoing edges |
| 233 | * can be applied to the proper block. |
| 234 | */ |
| 235 | if (immedPredBlockP) { |
| 236 | DCHECK_EQ(*immedPredBlockP, origBlock); |
| 237 | *immedPredBlockP = bottomBlock; |
| 238 | } |
| 239 | return bottomBlock; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | /* |
| 243 | * Given a code offset, find out the block that starts with it. If the offset |
buzbee | 9ab05de | 2012-01-18 15:43:48 -0800 | [diff] [blame] | 244 | * is in the middle of an existing block, split it into two. If immedPredBlockP |
| 245 | * is not non-null and is the block being split, update *immedPredBlockP to |
| 246 | * point to the bottom block so that outgoing edges can be set up properly |
| 247 | * (by the caller) |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 248 | * Utilizes a map for fast lookup of the typical cases. |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 249 | */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 250 | BasicBlock *findBlock(CompilationUnit* cUnit, unsigned int codeOffset, |
| 251 | bool split, bool create, BasicBlock** immedPredBlockP) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 252 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 253 | GrowableList* blockList = &cUnit->blockList; |
| 254 | BasicBlock* bb; |
| 255 | unsigned int i; |
| 256 | SafeMap<unsigned int, BasicBlock*>::iterator it; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 257 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 258 | it = cUnit->blockMap.find(codeOffset); |
| 259 | if (it != cUnit->blockMap.end()) { |
| 260 | return it->second; |
| 261 | } else if (!create) { |
| 262 | return NULL; |
| 263 | } |
| 264 | |
| 265 | if (split) { |
| 266 | for (i = 0; i < blockList->numUsed; i++) { |
| 267 | bb = (BasicBlock *) blockList->elemList[i]; |
| 268 | if (bb->blockType != kDalvikByteCode) continue; |
| 269 | /* Check if a branch jumps into the middle of an existing block */ |
| 270 | if ((codeOffset > bb->startOffset) && (bb->lastMIRInsn != NULL) && |
| 271 | (codeOffset <= bb->lastMIRInsn->offset)) { |
| 272 | BasicBlock *newBB = splitBlock(cUnit, codeOffset, bb, |
| 273 | bb == *immedPredBlockP ? |
| 274 | immedPredBlockP : NULL); |
| 275 | return newBB; |
| 276 | } |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 277 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 278 | } |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 279 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 280 | /* Create a new one */ |
| 281 | bb = oatNewBB(cUnit, kDalvikByteCode, cUnit->numBlocks++); |
| 282 | oatInsertGrowableList(cUnit, &cUnit->blockList, (intptr_t) bb); |
| 283 | bb->startOffset = codeOffset; |
| 284 | cUnit->blockMap.Put(bb->startOffset, bb); |
| 285 | return bb; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 286 | } |
| 287 | |
buzbee | f58c12c | 2012-07-03 15:06:29 -0700 | [diff] [blame] | 288 | /* Find existing block */ |
| 289 | BasicBlock* oatFindBlock(CompilationUnit* cUnit, unsigned int codeOffset) |
| 290 | { |
| 291 | return findBlock(cUnit, codeOffset, false, false, NULL); |
| 292 | } |
| 293 | |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 294 | /* Turn method name into a legal Linux file name */ |
| 295 | void oatReplaceSpecialChars(std::string& str) |
| 296 | { |
| 297 | static const struct { const char before; const char after; } match[] = |
| 298 | {{'/','-'}, {';','#'}, {' ','#'}, {'$','+'}, |
| 299 | {'(','@'}, {')','@'}, {'<','='}, {'>','='}}; |
| 300 | for (unsigned int i = 0; i < sizeof(match)/sizeof(match[0]); i++) { |
| 301 | std::replace(str.begin(), str.end(), match[i].before, match[i].after); |
| 302 | } |
| 303 | } |
| 304 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 305 | /* Dump the CFG into a DOT graph */ |
| 306 | void oatDumpCFG(CompilationUnit* cUnit, const char* dirPrefix) |
| 307 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 308 | FILE* file; |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 309 | std::string fname(PrettyMethod(cUnit->method_idx, *cUnit->dex_file)); |
| 310 | oatReplaceSpecialChars(fname); |
| 311 | fname = StringPrintf("%s%s%x.dot", dirPrefix, fname.c_str(), |
| 312 | cUnit->entryBlock->fallThrough->startOffset); |
| 313 | file = fopen(fname.c_str(), "w"); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 314 | if (file == NULL) { |
| 315 | return; |
| 316 | } |
| 317 | fprintf(file, "digraph G {\n"); |
| 318 | |
| 319 | fprintf(file, " rankdir=TB\n"); |
| 320 | |
| 321 | int numReachableBlocks = cUnit->numReachableBlocks; |
| 322 | int idx; |
| 323 | const GrowableList *blockList = &cUnit->blockList; |
| 324 | |
| 325 | for (idx = 0; idx < numReachableBlocks; idx++) { |
| 326 | int blockIdx = cUnit->dfsOrder.elemList[idx]; |
| 327 | BasicBlock *bb = (BasicBlock *) oatGrowableListGetElement(blockList, |
| 328 | blockIdx); |
| 329 | if (bb == NULL) break; |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame] | 330 | if (bb->blockType == kDead) continue; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 331 | if (bb->blockType == kEntryBlock) { |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 332 | fprintf(file, " entry_%d [shape=Mdiamond];\n", bb->id); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 333 | } else if (bb->blockType == kExitBlock) { |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 334 | fprintf(file, " exit_%d [shape=Mdiamond];\n", bb->id); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 335 | } else if (bb->blockType == kDalvikByteCode) { |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 336 | fprintf(file, " block%04x_%d [shape=record,label = \"{ \\\n", |
| 337 | bb->startOffset, bb->id); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 338 | const MIR *mir; |
| 339 | fprintf(file, " {block id %d\\l}%s\\\n", bb->id, |
| 340 | bb->firstMIRInsn ? " | " : " "); |
| 341 | for (mir = bb->firstMIRInsn; mir; mir = mir->next) { |
| 342 | fprintf(file, " {%04x %s\\l}%s\\\n", mir->offset, |
| 343 | mir->ssaRep ? oatFullDisassembler(cUnit, mir) : |
| 344 | Instruction::Name(mir->dalvikInsn.opcode), |
| 345 | mir->next ? " | " : " "); |
| 346 | } |
| 347 | fprintf(file, " }\"];\n\n"); |
| 348 | } else if (bb->blockType == kExceptionHandling) { |
| 349 | char blockName[BLOCK_NAME_LEN]; |
| 350 | |
| 351 | oatGetBlockName(bb, blockName); |
| 352 | fprintf(file, " %s [shape=invhouse];\n", blockName); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 353 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 354 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 355 | char blockName1[BLOCK_NAME_LEN], blockName2[BLOCK_NAME_LEN]; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 356 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 357 | if (bb->taken) { |
| 358 | oatGetBlockName(bb, blockName1); |
| 359 | oatGetBlockName(bb->taken, blockName2); |
| 360 | fprintf(file, " %s:s -> %s:n [style=dotted]\n", |
| 361 | blockName1, blockName2); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 362 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 363 | if (bb->fallThrough) { |
| 364 | oatGetBlockName(bb, blockName1); |
| 365 | oatGetBlockName(bb->fallThrough, blockName2); |
| 366 | fprintf(file, " %s:s -> %s:n\n", blockName1, blockName2); |
| 367 | } |
| 368 | |
| 369 | if (bb->successorBlockList.blockListType != kNotUsed) { |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 370 | fprintf(file, " succ%04x_%d [shape=%s,label = \"{ \\\n", |
| 371 | bb->startOffset, bb->id, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 372 | (bb->successorBlockList.blockListType == kCatch) ? |
| 373 | "Mrecord" : "record"); |
| 374 | GrowableListIterator iterator; |
| 375 | oatGrowableListIteratorInit(&bb->successorBlockList.blocks, |
| 376 | &iterator); |
| 377 | SuccessorBlockInfo *successorBlockInfo = |
| 378 | (SuccessorBlockInfo *) oatGrowableListIteratorNext(&iterator); |
| 379 | |
| 380 | int succId = 0; |
| 381 | while (true) { |
| 382 | if (successorBlockInfo == NULL) break; |
| 383 | |
| 384 | BasicBlock *destBlock = successorBlockInfo->block; |
| 385 | SuccessorBlockInfo *nextSuccessorBlockInfo = |
| 386 | (SuccessorBlockInfo *) oatGrowableListIteratorNext(&iterator); |
| 387 | |
| 388 | fprintf(file, " {<f%d> %04x: %04x\\l}%s\\\n", |
| 389 | succId++, |
| 390 | successorBlockInfo->key, |
| 391 | destBlock->startOffset, |
| 392 | (nextSuccessorBlockInfo != NULL) ? " | " : " "); |
| 393 | |
| 394 | successorBlockInfo = nextSuccessorBlockInfo; |
| 395 | } |
| 396 | fprintf(file, " }\"];\n\n"); |
| 397 | |
| 398 | oatGetBlockName(bb, blockName1); |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 399 | fprintf(file, " %s:s -> succ%04x_%d:n [style=dashed]\n", |
| 400 | blockName1, bb->startOffset, bb->id); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 401 | |
| 402 | if (bb->successorBlockList.blockListType == kPackedSwitch || |
| 403 | bb->successorBlockList.blockListType == kSparseSwitch) { |
| 404 | |
| 405 | oatGrowableListIteratorInit(&bb->successorBlockList.blocks, |
| 406 | &iterator); |
| 407 | |
| 408 | succId = 0; |
| 409 | while (true) { |
| 410 | SuccessorBlockInfo *successorBlockInfo = (SuccessorBlockInfo *) |
| 411 | oatGrowableListIteratorNext(&iterator); |
| 412 | if (successorBlockInfo == NULL) break; |
| 413 | |
| 414 | BasicBlock *destBlock = successorBlockInfo->block; |
| 415 | |
| 416 | oatGetBlockName(destBlock, blockName2); |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 417 | fprintf(file, " succ%04x_%d:f%d:e -> %s:n\n", bb->startOffset, |
| 418 | bb->id, succId++, blockName2); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 419 | } |
| 420 | } |
| 421 | } |
| 422 | fprintf(file, "\n"); |
| 423 | |
| 424 | /* Display the dominator tree */ |
| 425 | oatGetBlockName(bb, blockName1); |
| 426 | fprintf(file, " cfg%s [label=\"%s\", shape=none];\n", |
| 427 | blockName1, blockName1); |
| 428 | if (bb->iDom) { |
| 429 | oatGetBlockName(bb->iDom, blockName2); |
| 430 | fprintf(file, " cfg%s:s -> cfg%s:n\n\n", blockName2, blockName1); |
| 431 | } |
| 432 | } |
| 433 | fprintf(file, "}\n"); |
| 434 | fclose(file); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | /* Verify if all the successor is connected with all the claimed predecessors */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 438 | bool verifyPredInfo(CompilationUnit* cUnit, BasicBlock* bb) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 439 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 440 | GrowableListIterator iter; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 441 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 442 | oatGrowableListIteratorInit(bb->predecessors, &iter); |
| 443 | while (true) { |
| 444 | BasicBlock *predBB = (BasicBlock*)oatGrowableListIteratorNext(&iter); |
| 445 | if (!predBB) break; |
| 446 | bool found = false; |
| 447 | if (predBB->taken == bb) { |
| 448 | found = true; |
| 449 | } else if (predBB->fallThrough == bb) { |
| 450 | found = true; |
| 451 | } else if (predBB->successorBlockList.blockListType != kNotUsed) { |
| 452 | GrowableListIterator iterator; |
| 453 | oatGrowableListIteratorInit(&predBB->successorBlockList.blocks, |
| 454 | &iterator); |
| 455 | while (true) { |
| 456 | SuccessorBlockInfo *successorBlockInfo = (SuccessorBlockInfo *) |
| 457 | oatGrowableListIteratorNext(&iterator); |
| 458 | if (successorBlockInfo == NULL) break; |
| 459 | BasicBlock *succBB = successorBlockInfo->block; |
| 460 | if (succBB == bb) { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 461 | found = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 462 | break; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 463 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 464 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 465 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 466 | if (found == false) { |
| 467 | char blockName1[BLOCK_NAME_LEN], blockName2[BLOCK_NAME_LEN]; |
| 468 | oatGetBlockName(bb, blockName1); |
| 469 | oatGetBlockName(predBB, blockName2); |
| 470 | oatDumpCFG(cUnit, "/sdcard/cfg/"); |
| 471 | LOG(FATAL) << "Successor " << blockName1 << "not found from " |
| 472 | << blockName2; |
| 473 | } |
| 474 | } |
| 475 | return true; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | /* Identify code range in try blocks and set up the empty catch blocks */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 479 | void processTryCatchBlocks(CompilationUnit* cUnit) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 480 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 481 | const DexFile::CodeItem* code_item = cUnit->code_item; |
| 482 | int triesSize = code_item->tries_size_; |
| 483 | int offset; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 484 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 485 | if (triesSize == 0) { |
| 486 | return; |
| 487 | } |
| 488 | |
| 489 | ArenaBitVector* tryBlockAddr = cUnit->tryBlockAddr; |
| 490 | |
| 491 | for (int i = 0; i < triesSize; i++) { |
| 492 | const DexFile::TryItem* pTry = |
| 493 | DexFile::GetTryItems(*code_item, i); |
| 494 | int startOffset = pTry->start_addr_; |
| 495 | int endOffset = startOffset + pTry->insn_count_; |
| 496 | for (offset = startOffset; offset < endOffset; offset++) { |
| 497 | oatSetBit(cUnit, tryBlockAddr, offset); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 498 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 499 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 500 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 501 | // Iterate over each of the handlers to enqueue the empty Catch blocks |
| 502 | const byte* handlers_ptr = DexFile::GetCatchHandlerData(*code_item, 0); |
| 503 | uint32_t handlers_size = DecodeUnsignedLeb128(&handlers_ptr); |
| 504 | for (uint32_t idx = 0; idx < handlers_size; idx++) { |
| 505 | CatchHandlerIterator iterator(handlers_ptr); |
| 506 | for (; iterator.HasNext(); iterator.Next()) { |
| 507 | uint32_t address = iterator.GetHandlerAddress(); |
| 508 | findBlock(cUnit, address, false /* split */, true /*create*/, |
| 509 | /* immedPredBlockP */ NULL); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 510 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 511 | handlers_ptr = iterator.EndDataPointer(); |
| 512 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 515 | /* Process instructions with the kBranch flag */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 516 | BasicBlock* processCanBranch(CompilationUnit* cUnit, BasicBlock* curBlock, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 517 | MIR* insn, int curOffset, int width, int flags, |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 518 | const uint16_t* codePtr, const uint16_t* codeEnd) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 519 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 520 | int target = curOffset; |
| 521 | switch (insn->dalvikInsn.opcode) { |
| 522 | case Instruction::GOTO: |
| 523 | case Instruction::GOTO_16: |
| 524 | case Instruction::GOTO_32: |
| 525 | target += (int) insn->dalvikInsn.vA; |
| 526 | break; |
| 527 | case Instruction::IF_EQ: |
| 528 | case Instruction::IF_NE: |
| 529 | case Instruction::IF_LT: |
| 530 | case Instruction::IF_GE: |
| 531 | case Instruction::IF_GT: |
| 532 | case Instruction::IF_LE: |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 533 | curBlock->conditionalBranch = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 534 | target += (int) insn->dalvikInsn.vC; |
| 535 | break; |
| 536 | case Instruction::IF_EQZ: |
| 537 | case Instruction::IF_NEZ: |
| 538 | case Instruction::IF_LTZ: |
| 539 | case Instruction::IF_GEZ: |
| 540 | case Instruction::IF_GTZ: |
| 541 | case Instruction::IF_LEZ: |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 542 | curBlock->conditionalBranch = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 543 | target += (int) insn->dalvikInsn.vB; |
| 544 | break; |
| 545 | default: |
| 546 | LOG(FATAL) << "Unexpected opcode(" << (int)insn->dalvikInsn.opcode |
| 547 | << ") with kBranch set"; |
| 548 | } |
| 549 | BasicBlock *takenBlock = findBlock(cUnit, target, |
| 550 | /* split */ |
| 551 | true, |
| 552 | /* create */ |
| 553 | true, |
| 554 | /* immedPredBlockP */ |
| 555 | &curBlock); |
| 556 | curBlock->taken = takenBlock; |
| 557 | oatInsertGrowableList(cUnit, takenBlock->predecessors, (intptr_t)curBlock); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 558 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 559 | /* Always terminate the current block for conditional branches */ |
| 560 | if (flags & Instruction::kContinue) { |
| 561 | BasicBlock *fallthroughBlock = findBlock(cUnit, |
| 562 | curOffset + width, |
| 563 | /* |
| 564 | * If the method is processed |
| 565 | * in sequential order from the |
| 566 | * beginning, we don't need to |
| 567 | * specify split for continue |
| 568 | * blocks. However, this |
| 569 | * routine can be called by |
| 570 | * compileLoop, which starts |
| 571 | * parsing the method from an |
| 572 | * arbitrary address in the |
| 573 | * method body. |
| 574 | */ |
| 575 | true, |
| 576 | /* create */ |
| 577 | true, |
| 578 | /* immedPredBlockP */ |
| 579 | &curBlock); |
| 580 | curBlock->fallThrough = fallthroughBlock; |
| 581 | oatInsertGrowableList(cUnit, fallthroughBlock->predecessors, |
| 582 | (intptr_t)curBlock); |
| 583 | } else if (codePtr < codeEnd) { |
| 584 | /* Create a fallthrough block for real instructions (incl. NOP) */ |
| 585 | if (contentIsInsn(codePtr)) { |
| 586 | findBlock(cUnit, curOffset + width, |
| 587 | /* split */ |
| 588 | false, |
| 589 | /* create */ |
| 590 | true, |
| 591 | /* immedPredBlockP */ |
| 592 | NULL); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 593 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 594 | } |
| 595 | return curBlock; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 598 | /* Process instructions with the kSwitch flag */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 599 | void processCanSwitch(CompilationUnit* cUnit, BasicBlock* curBlock, |
| 600 | MIR* insn, int curOffset, int width, int flags) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 601 | { |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 602 | uint16_t* switchData= (uint16_t*) (cUnit->insns + curOffset + insn->dalvikInsn.vB); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 603 | int size; |
| 604 | int* keyTable; |
| 605 | int* targetTable; |
| 606 | int i; |
| 607 | int firstKey; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 608 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 609 | /* |
| 610 | * Packed switch data format: |
| 611 | * ushort ident = 0x0100 magic value |
| 612 | * ushort size number of entries in the table |
| 613 | * int first_key first (and lowest) switch case value |
| 614 | * int targets[size] branch targets, relative to switch opcode |
| 615 | * |
| 616 | * Total size is (4+size*2) 16-bit code units. |
| 617 | */ |
| 618 | if (insn->dalvikInsn.opcode == Instruction::PACKED_SWITCH) { |
| 619 | DCHECK_EQ(static_cast<int>(switchData[0]), |
| 620 | static_cast<int>(Instruction::kPackedSwitchSignature)); |
| 621 | size = switchData[1]; |
| 622 | firstKey = switchData[2] | (switchData[3] << 16); |
| 623 | targetTable = (int *) &switchData[4]; |
| 624 | keyTable = NULL; // Make the compiler happy |
| 625 | /* |
| 626 | * Sparse switch data format: |
| 627 | * ushort ident = 0x0200 magic value |
| 628 | * ushort size number of entries in the table; > 0 |
| 629 | * int keys[size] keys, sorted low-to-high; 32-bit aligned |
| 630 | * int targets[size] branch targets, relative to switch opcode |
| 631 | * |
| 632 | * Total size is (2+size*4) 16-bit code units. |
| 633 | */ |
| 634 | } else { |
| 635 | DCHECK_EQ(static_cast<int>(switchData[0]), |
| 636 | static_cast<int>(Instruction::kSparseSwitchSignature)); |
| 637 | size = switchData[1]; |
| 638 | keyTable = (int *) &switchData[2]; |
| 639 | targetTable = (int *) &switchData[2 + size*2]; |
| 640 | firstKey = 0; // To make the compiler happy |
| 641 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 642 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 643 | if (curBlock->successorBlockList.blockListType != kNotUsed) { |
| 644 | LOG(FATAL) << "Successor block list already in use: " |
| 645 | << (int)curBlock->successorBlockList.blockListType; |
| 646 | } |
| 647 | curBlock->successorBlockList.blockListType = |
| 648 | (insn->dalvikInsn.opcode == Instruction::PACKED_SWITCH) ? |
| 649 | kPackedSwitch : kSparseSwitch; |
| 650 | oatInitGrowableList(cUnit, &curBlock->successorBlockList.blocks, size, |
| 651 | kListSuccessorBlocks); |
| 652 | |
| 653 | for (i = 0; i < size; i++) { |
| 654 | BasicBlock *caseBlock = findBlock(cUnit, curOffset + targetTable[i], |
| 655 | /* split */ |
| 656 | true, |
| 657 | /* create */ |
| 658 | true, |
| 659 | /* immedPredBlockP */ |
| 660 | &curBlock); |
| 661 | SuccessorBlockInfo *successorBlockInfo = |
| 662 | (SuccessorBlockInfo *) oatNew(cUnit, sizeof(SuccessorBlockInfo), |
| 663 | false, kAllocSuccessor); |
| 664 | successorBlockInfo->block = caseBlock; |
| 665 | successorBlockInfo->key = |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 666 | (insn->dalvikInsn.opcode == Instruction::PACKED_SWITCH) ? |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 667 | firstKey + i : keyTable[i]; |
| 668 | oatInsertGrowableList(cUnit, &curBlock->successorBlockList.blocks, |
| 669 | (intptr_t) successorBlockInfo); |
| 670 | oatInsertGrowableList(cUnit, caseBlock->predecessors, |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 671 | (intptr_t)curBlock); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | /* Fall-through case */ |
| 675 | BasicBlock* fallthroughBlock = findBlock(cUnit, |
| 676 | curOffset + width, |
| 677 | /* split */ |
| 678 | false, |
| 679 | /* create */ |
| 680 | true, |
| 681 | /* immedPredBlockP */ |
| 682 | NULL); |
| 683 | curBlock->fallThrough = fallthroughBlock; |
| 684 | oatInsertGrowableList(cUnit, fallthroughBlock->predecessors, |
| 685 | (intptr_t)curBlock); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 686 | } |
| 687 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 688 | /* Process instructions with the kThrow flag */ |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 689 | BasicBlock* processCanThrow(CompilationUnit* cUnit, BasicBlock* curBlock, |
| 690 | MIR* insn, int curOffset, int width, int flags, |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 691 | ArenaBitVector* tryBlockAddr, const uint16_t* codePtr, |
| 692 | const uint16_t* codeEnd) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 693 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 694 | const DexFile::CodeItem* code_item = cUnit->code_item; |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 695 | bool inTryBlock = oatIsBitSet(tryBlockAddr, curOffset); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 696 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 697 | /* In try block */ |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 698 | if (inTryBlock) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 699 | CatchHandlerIterator iterator(*code_item, curOffset); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 700 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 701 | if (curBlock->successorBlockList.blockListType != kNotUsed) { |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 702 | LOG(INFO) << PrettyMethod(cUnit->method_idx, *cUnit->dex_file); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 703 | LOG(FATAL) << "Successor block list already in use: " |
| 704 | << (int)curBlock->successorBlockList.blockListType; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 705 | } |
| 706 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 707 | curBlock->successorBlockList.blockListType = kCatch; |
| 708 | oatInitGrowableList(cUnit, &curBlock->successorBlockList.blocks, 2, |
| 709 | kListSuccessorBlocks); |
| 710 | |
| 711 | for (;iterator.HasNext(); iterator.Next()) { |
| 712 | BasicBlock *catchBlock = findBlock(cUnit, iterator.GetHandlerAddress(), |
| 713 | false /* split*/, |
| 714 | false /* creat */, |
| 715 | NULL /* immedPredBlockP */); |
| 716 | catchBlock->catchEntry = true; |
buzbee | 6459e7c | 2012-10-02 14:42:41 -0700 | [diff] [blame] | 717 | cUnit->catches.insert(catchBlock->startOffset); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 718 | SuccessorBlockInfo *successorBlockInfo = (SuccessorBlockInfo *) |
| 719 | oatNew(cUnit, sizeof(SuccessorBlockInfo), false, kAllocSuccessor); |
| 720 | successorBlockInfo->block = catchBlock; |
| 721 | successorBlockInfo->key = iterator.GetHandlerTypeIndex(); |
| 722 | oatInsertGrowableList(cUnit, &curBlock->successorBlockList.blocks, |
| 723 | (intptr_t) successorBlockInfo); |
| 724 | oatInsertGrowableList(cUnit, catchBlock->predecessors, |
| 725 | (intptr_t)curBlock); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 726 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 727 | } else { |
| 728 | BasicBlock *ehBlock = oatNewBB(cUnit, kExceptionHandling, |
| 729 | cUnit->numBlocks++); |
| 730 | curBlock->taken = ehBlock; |
| 731 | oatInsertGrowableList(cUnit, &cUnit->blockList, (intptr_t) ehBlock); |
| 732 | ehBlock->startOffset = curOffset; |
| 733 | oatInsertGrowableList(cUnit, ehBlock->predecessors, (intptr_t)curBlock); |
| 734 | } |
| 735 | |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 736 | if (insn->dalvikInsn.opcode == Instruction::THROW){ |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 737 | curBlock->explicitThrow = true; |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 738 | if ((codePtr < codeEnd) && contentIsInsn(codePtr)) { |
| 739 | // Force creation of new block following THROW via side-effect |
| 740 | findBlock(cUnit, curOffset + width, /* split */ false, |
| 741 | /* create */ true, /* immedPredBlockP */ NULL); |
| 742 | } |
| 743 | if (!inTryBlock) { |
| 744 | // Don't split a THROW that can't rethrow - we're done. |
| 745 | return curBlock; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 746 | } |
| 747 | } |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 748 | |
| 749 | /* |
| 750 | * Split the potentially-throwing instruction into two parts. |
| 751 | * The first half will be a pseudo-op that captures the exception |
| 752 | * edges and terminates the basic block. It always falls through. |
| 753 | * Then, create a new basic block that begins with the throwing instruction |
| 754 | * (minus exceptions). Note: this new basic block must NOT be entered into |
| 755 | * the blockMap. If the potentially-throwing instruction is the target of a |
| 756 | * future branch, we need to find the check psuedo half. The new |
| 757 | * basic block containing the work portion of the instruction should |
| 758 | * only be entered via fallthrough from the block containing the |
| 759 | * pseudo exception edge MIR. Note also that this new block is |
| 760 | * not automatically terminated after the work portion, and may |
| 761 | * contain following instructions. |
| 762 | */ |
| 763 | BasicBlock *newBlock = oatNewBB(cUnit, kDalvikByteCode, cUnit->numBlocks++); |
| 764 | oatInsertGrowableList(cUnit, &cUnit->blockList, (intptr_t)newBlock); |
| 765 | newBlock->startOffset = insn->offset; |
| 766 | curBlock->fallThrough = newBlock; |
| 767 | oatInsertGrowableList(cUnit, newBlock->predecessors, (intptr_t)curBlock); |
| 768 | MIR* newInsn = (MIR*)oatNew(cUnit, sizeof(MIR), true, kAllocMIR); |
| 769 | *newInsn = *insn; |
| 770 | insn->dalvikInsn.opcode = |
| 771 | static_cast<Instruction::Code>(kMirOpCheck); |
| 772 | // Associate the two halves |
| 773 | insn->meta.throwInsn = newInsn; |
| 774 | newInsn->meta.throwInsn = insn; |
| 775 | oatAppendMIR(newBlock, newInsn); |
| 776 | return newBlock; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 777 | } |
| 778 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 779 | void oatInit(CompilationUnit* cUnit, const Compiler& compiler) { |
| 780 | if (!oatArchInit()) { |
| 781 | LOG(FATAL) << "Failed to initialize oat"; |
| 782 | } |
| 783 | if (!oatHeapInit(cUnit)) { |
| 784 | LOG(FATAL) << "Failed to initialize oat heap"; |
| 785 | } |
| 786 | } |
| 787 | |
buzbee | abc4c6b | 2012-08-23 08:17:15 -0700 | [diff] [blame] | 788 | CompiledMethod* compileMethod(Compiler& compiler, |
buzbee | c531cef | 2012-10-18 07:09:20 -0700 | [diff] [blame] | 789 | const CompilerBackend compilerBackend, |
buzbee | abc4c6b | 2012-08-23 08:17:15 -0700 | [diff] [blame] | 790 | const DexFile::CodeItem* code_item, |
| 791 | uint32_t access_flags, InvokeType invoke_type, |
| 792 | uint32_t method_idx, jobject class_loader, |
buzbee | c531cef | 2012-10-18 07:09:20 -0700 | [diff] [blame] | 793 | const DexFile& dex_file, |
| 794 | LLVMInfo* llvm_info |
buzbee | abc4c6b | 2012-08-23 08:17:15 -0700 | [diff] [blame] | 795 | ) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 796 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 797 | VLOG(compiler) << "Compiling " << PrettyMethod(method_idx, dex_file) << "..."; |
Brian Carlstrom | 94496d3 | 2011-08-22 09:22:47 -0700 | [diff] [blame] | 798 | |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 799 | const uint16_t* codePtr = code_item->insns_; |
| 800 | const uint16_t* codeEnd = code_item->insns_ + code_item->insns_size_in_code_units_; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 801 | int numBlocks = 0; |
| 802 | unsigned int curOffset = 0; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 803 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 804 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 805 | UniquePtr<CompilationUnit> cUnit(new CompilationUnit); |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 806 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 807 | oatInit(cUnit.get(), compiler); |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 808 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 809 | cUnit->compiler = &compiler; |
| 810 | cUnit->class_linker = class_linker; |
| 811 | cUnit->dex_file = &dex_file; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 812 | cUnit->method_idx = method_idx; |
| 813 | cUnit->code_item = code_item; |
| 814 | cUnit->access_flags = access_flags; |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 815 | cUnit->invoke_type = invoke_type; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 816 | cUnit->shorty = dex_file.GetMethodShorty(dex_file.GetMethodId(method_idx)); |
| 817 | cUnit->instructionSet = compiler.GetInstructionSet(); |
| 818 | cUnit->insns = code_item->insns_; |
| 819 | cUnit->insnsSize = code_item->insns_size_in_code_units_; |
| 820 | cUnit->numIns = code_item->ins_size_; |
| 821 | cUnit->numRegs = code_item->registers_size_ - cUnit->numIns; |
| 822 | cUnit->numOuts = code_item->outs_size_; |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 823 | DCHECK((cUnit->instructionSet == kThumb2) || |
| 824 | (cUnit->instructionSet == kX86) || |
| 825 | (cUnit->instructionSet == kMips)); |
buzbee | c531cef | 2012-10-18 07:09:20 -0700 | [diff] [blame] | 826 | if ((compilerBackend == kQuickGBC) || (compilerBackend == kPortable)) { |
buzbee | 85eee02 | 2012-07-16 22:12:38 -0700 | [diff] [blame] | 827 | cUnit->genBitcode = true; |
| 828 | } |
buzbee | c531cef | 2012-10-18 07:09:20 -0700 | [diff] [blame] | 829 | DCHECK_NE(compilerBackend, kIceland); // TODO: remove when Portable/Iceland merge complete |
| 830 | // TODO: remove this once x86 is tested |
| 831 | if (cUnit->genBitcode && (cUnit->instructionSet != kThumb2)) { |
| 832 | UNIMPLEMENTED(WARNING) << "GBC generation untested for non-Thumb targets"; |
| 833 | } |
| 834 | cUnit->llvm_info = llvm_info; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 835 | /* Adjust this value accordingly once inlining is performed */ |
| 836 | cUnit->numDalvikRegisters = code_item->registers_size_; |
| 837 | // TODO: set this from command line |
| 838 | cUnit->compilerFlipMatch = false; |
| 839 | bool useMatch = !cUnit->compilerMethodMatch.empty(); |
| 840 | bool match = useMatch && (cUnit->compilerFlipMatch ^ |
| 841 | (PrettyMethod(method_idx, dex_file).find(cUnit->compilerMethodMatch) != |
| 842 | std::string::npos)); |
| 843 | if (!useMatch || match) { |
| 844 | cUnit->disableOpt = kCompilerOptimizerDisableFlags; |
| 845 | cUnit->enableDebug = kCompilerDebugFlags; |
| 846 | cUnit->printMe = VLOG_IS_ON(compiler) || |
| 847 | (cUnit->enableDebug & (1 << kDebugVerbose)); |
| 848 | } |
buzbee | 6459e7c | 2012-10-02 14:42:41 -0700 | [diff] [blame] | 849 | #ifndef NDEBUG |
buzbee | c531cef | 2012-10-18 07:09:20 -0700 | [diff] [blame] | 850 | if (cUnit->genBitcode) { |
buzbee | 6459e7c | 2012-10-02 14:42:41 -0700 | [diff] [blame] | 851 | cUnit->enableDebug |= (1 << kDebugVerifyBitcode); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 852 | } |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 853 | #endif |
buzbee | 9281f00 | 2012-10-24 12:17:24 -0700 | [diff] [blame] | 854 | |
| 855 | #if 1 |
| 856 | // *** Temporary **** |
| 857 | // For use in debugging issue 7250540. Disable optimization in problem method |
| 858 | // to see if monkey results change. Should be removed after monkey runs |
| 859 | // complete. |
| 860 | if (PrettyMethod(method_idx, dex_file).find("void com.android.inputmethod.keyboard.Key.<init>(android.content.res.Resources, com.android.inputmethod.keyboard.Keyboard$Params, com.android.inputmethod.keyboard.Keyboard$Builder$Row, org.xmlpull.v1.XmlPullParser)") != std::string::npos) { |
| 861 | cUnit->disableOpt |= ( |
| 862 | (1 << kLoadStoreElimination) | |
| 863 | (1 << kLoadHoisting) | |
| 864 | (1 << kSuppressLoads) | |
buzbee | 663c09f | 2012-10-31 05:21:00 -0700 | [diff] [blame] | 865 | //(1 << kNullCheckElimination) | |
| 866 | //(1 << kPromoteRegs) | |
buzbee | 9281f00 | 2012-10-24 12:17:24 -0700 | [diff] [blame] | 867 | (1 << kTrackLiveTemps) | |
buzbee | 663c09f | 2012-10-31 05:21:00 -0700 | [diff] [blame] | 868 | //(1 << kSkipLargeMethodOptimization) | |
| 869 | //(1 << kSafeOptimizations) | |
buzbee | 9281f00 | 2012-10-24 12:17:24 -0700 | [diff] [blame] | 870 | (1 << kBBOpt) | |
| 871 | (1 << kMatch) | |
buzbee | 663c09f | 2012-10-31 05:21:00 -0700 | [diff] [blame] | 872 | //(1 << kPromoteCompilerTemps) | |
| 873 | 0); |
buzbee | 9281f00 | 2012-10-24 12:17:24 -0700 | [diff] [blame] | 874 | } |
| 875 | #endif |
| 876 | |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 877 | if (cUnit->instructionSet == kMips) { |
| 878 | // Disable some optimizations for mips for now |
| 879 | cUnit->disableOpt |= ( |
| 880 | (1 << kLoadStoreElimination) | |
| 881 | (1 << kLoadHoisting) | |
| 882 | (1 << kSuppressLoads) | |
| 883 | (1 << kNullCheckElimination) | |
| 884 | (1 << kPromoteRegs) | |
| 885 | (1 << kTrackLiveTemps) | |
| 886 | (1 << kSkipLargeMethodOptimization) | |
| 887 | (1 << kSafeOptimizations) | |
| 888 | (1 << kBBOpt) | |
| 889 | (1 << kMatch) | |
| 890 | (1 << kPromoteCompilerTemps)); |
| 891 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 892 | |
| 893 | /* Gathering opcode stats? */ |
| 894 | if (kCompilerDebugFlags & (1 << kDebugCountOpcodes)) { |
| 895 | cUnit->opcodeCount = (int*)oatNew(cUnit.get(), |
| 896 | kNumPackedOpcodes * sizeof(int), true, kAllocMisc); |
| 897 | } |
| 898 | |
| 899 | /* Assume non-throwing leaf */ |
| 900 | cUnit->attrs = (METHOD_IS_LEAF | METHOD_IS_THROW_FREE); |
| 901 | |
| 902 | /* Initialize the block list, estimate size based on insnsSize */ |
| 903 | oatInitGrowableList(cUnit.get(), &cUnit->blockList, cUnit->insnsSize, |
| 904 | kListBlockList); |
| 905 | |
| 906 | /* Initialize the switchTables list */ |
| 907 | oatInitGrowableList(cUnit.get(), &cUnit->switchTables, 4, |
| 908 | kListSwitchTables); |
| 909 | |
| 910 | /* Intialize the fillArrayData list */ |
| 911 | oatInitGrowableList(cUnit.get(), &cUnit->fillArrayData, 4, |
| 912 | kListFillArrayData); |
| 913 | |
| 914 | /* Intialize the throwLaunchpads list, estimate size based on insnsSize */ |
| 915 | oatInitGrowableList(cUnit.get(), &cUnit->throwLaunchpads, cUnit->insnsSize, |
| 916 | kListThrowLaunchPads); |
| 917 | |
| 918 | /* Intialize the instrinsicLaunchpads list */ |
| 919 | oatInitGrowableList(cUnit.get(), &cUnit->intrinsicLaunchpads, 4, |
| 920 | kListMisc); |
| 921 | |
| 922 | |
| 923 | /* Intialize the suspendLaunchpads list */ |
| 924 | oatInitGrowableList(cUnit.get(), &cUnit->suspendLaunchpads, 2048, |
| 925 | kListSuspendLaunchPads); |
| 926 | |
| 927 | /* Allocate the bit-vector to track the beginning of basic blocks */ |
| 928 | ArenaBitVector *tryBlockAddr = oatAllocBitVector(cUnit.get(), |
| 929 | cUnit->insnsSize, |
| 930 | true /* expandable */); |
| 931 | cUnit->tryBlockAddr = tryBlockAddr; |
| 932 | |
| 933 | /* Create the default entry and exit blocks and enter them to the list */ |
| 934 | BasicBlock *entryBlock = oatNewBB(cUnit.get(), kEntryBlock, numBlocks++); |
| 935 | BasicBlock *exitBlock = oatNewBB(cUnit.get(), kExitBlock, numBlocks++); |
| 936 | |
| 937 | cUnit->entryBlock = entryBlock; |
| 938 | cUnit->exitBlock = exitBlock; |
| 939 | |
| 940 | oatInsertGrowableList(cUnit.get(), &cUnit->blockList, (intptr_t) entryBlock); |
| 941 | oatInsertGrowableList(cUnit.get(), &cUnit->blockList, (intptr_t) exitBlock); |
| 942 | |
| 943 | /* Current block to record parsed instructions */ |
| 944 | BasicBlock *curBlock = oatNewBB(cUnit.get(), kDalvikByteCode, numBlocks++); |
| 945 | curBlock->startOffset = 0; |
| 946 | oatInsertGrowableList(cUnit.get(), &cUnit->blockList, (intptr_t) curBlock); |
| 947 | /* Add first block to the fast lookup cache */ |
| 948 | cUnit->blockMap.Put(curBlock->startOffset, curBlock); |
| 949 | entryBlock->fallThrough = curBlock; |
| 950 | oatInsertGrowableList(cUnit.get(), curBlock->predecessors, |
| 951 | (intptr_t)entryBlock); |
| 952 | |
| 953 | /* |
| 954 | * Store back the number of blocks since new blocks may be created of |
| 955 | * accessing cUnit. |
| 956 | */ |
| 957 | cUnit->numBlocks = numBlocks; |
| 958 | |
| 959 | /* Identify code range in try blocks and set up the empty catch blocks */ |
| 960 | processTryCatchBlocks(cUnit.get()); |
| 961 | |
| 962 | /* Set up for simple method detection */ |
| 963 | int numPatterns = sizeof(specialPatterns)/sizeof(specialPatterns[0]); |
| 964 | bool livePattern = (numPatterns > 0) && !(cUnit->disableOpt & (1 << kMatch)); |
Elliott Hughes | abe64aa | 2012-05-30 17:34:45 -0700 | [diff] [blame] | 965 | bool* deadPattern = (bool*)oatNew(cUnit.get(), sizeof(bool) * numPatterns, true, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 966 | kAllocMisc); |
| 967 | SpecialCaseHandler specialCase = kNoHandler; |
| 968 | int patternPos = 0; |
| 969 | |
| 970 | /* Parse all instructions and put them into containing basic blocks */ |
| 971 | while (codePtr < codeEnd) { |
| 972 | MIR *insn = (MIR *) oatNew(cUnit.get(), sizeof(MIR), true, kAllocMIR); |
| 973 | insn->offset = curOffset; |
| 974 | int width = parseInsn(cUnit.get(), codePtr, &insn->dalvikInsn, false); |
| 975 | insn->width = width; |
| 976 | Instruction::Code opcode = insn->dalvikInsn.opcode; |
| 977 | if (cUnit->opcodeCount != NULL) { |
| 978 | cUnit->opcodeCount[static_cast<int>(opcode)]++; |
buzbee | 44b412b | 2012-02-04 08:50:53 -0800 | [diff] [blame] | 979 | } |
| 980 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 981 | /* Terminate when the data section is seen */ |
| 982 | if (width == 0) |
| 983 | break; |
| 984 | |
| 985 | /* Possible simple method? */ |
| 986 | if (livePattern) { |
| 987 | livePattern = false; |
| 988 | specialCase = kNoHandler; |
| 989 | for (int i = 0; i < numPatterns; i++) { |
| 990 | if (!deadPattern[i]) { |
| 991 | if (specialPatterns[i].opcodes[patternPos] == opcode) { |
| 992 | livePattern = true; |
| 993 | specialCase = specialPatterns[i].handlerCode; |
| 994 | } else { |
| 995 | deadPattern[i] = true; |
| 996 | } |
| 997 | } |
| 998 | } |
| 999 | patternPos++; |
buzbee | a7c1268 | 2012-03-19 13:13:53 -0700 | [diff] [blame] | 1000 | } |
| 1001 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1002 | oatAppendMIR(curBlock, insn); |
buzbee | cefd187 | 2011-09-09 09:59:52 -0700 | [diff] [blame] | 1003 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1004 | codePtr += width; |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 1005 | int flags = Instruction::FlagsOf(insn->dalvikInsn.opcode); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1006 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1007 | int dfFlags = oatDataFlowAttributes[insn->dalvikInsn.opcode]; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1008 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1009 | if (dfFlags & DF_HAS_DEFS) { |
buzbee | bff2465 | 2012-05-06 16:22:05 -0700 | [diff] [blame] | 1010 | cUnit->defCount += (dfFlags & DF_A_WIDE) ? 2 : 1; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1011 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1012 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1013 | if (flags & Instruction::kBranch) { |
| 1014 | curBlock = processCanBranch(cUnit.get(), curBlock, insn, curOffset, |
| 1015 | width, flags, codePtr, codeEnd); |
| 1016 | } else if (flags & Instruction::kReturn) { |
| 1017 | curBlock->fallThrough = exitBlock; |
| 1018 | oatInsertGrowableList(cUnit.get(), exitBlock->predecessors, |
| 1019 | (intptr_t)curBlock); |
| 1020 | /* |
| 1021 | * Terminate the current block if there are instructions |
| 1022 | * afterwards. |
| 1023 | */ |
| 1024 | if (codePtr < codeEnd) { |
| 1025 | /* |
| 1026 | * Create a fallthrough block for real instructions |
| 1027 | * (incl. NOP). |
| 1028 | */ |
| 1029 | if (contentIsInsn(codePtr)) { |
| 1030 | findBlock(cUnit.get(), curOffset + width, |
| 1031 | /* split */ |
| 1032 | false, |
| 1033 | /* create */ |
| 1034 | true, |
| 1035 | /* immedPredBlockP */ |
| 1036 | NULL); |
| 1037 | } |
| 1038 | } |
| 1039 | } else if (flags & Instruction::kThrow) { |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 1040 | curBlock = processCanThrow(cUnit.get(), curBlock, insn, curOffset, |
| 1041 | width, flags, tryBlockAddr, codePtr, codeEnd); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1042 | } else if (flags & Instruction::kSwitch) { |
| 1043 | processCanSwitch(cUnit.get(), curBlock, insn, curOffset, width, flags); |
| 1044 | } |
| 1045 | curOffset += width; |
| 1046 | BasicBlock *nextBlock = findBlock(cUnit.get(), curOffset, |
| 1047 | /* split */ |
| 1048 | false, |
| 1049 | /* create */ |
| 1050 | false, |
| 1051 | /* immedPredBlockP */ |
| 1052 | NULL); |
| 1053 | if (nextBlock) { |
| 1054 | /* |
| 1055 | * The next instruction could be the target of a previously parsed |
| 1056 | * forward branch so a block is already created. If the current |
| 1057 | * instruction is not an unconditional branch, connect them through |
| 1058 | * the fall-through link. |
| 1059 | */ |
| 1060 | DCHECK(curBlock->fallThrough == NULL || |
| 1061 | curBlock->fallThrough == nextBlock || |
| 1062 | curBlock->fallThrough == exitBlock); |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 1063 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1064 | if ((curBlock->fallThrough == NULL) && (flags & Instruction::kContinue)) { |
| 1065 | curBlock->fallThrough = nextBlock; |
| 1066 | oatInsertGrowableList(cUnit.get(), nextBlock->predecessors, |
| 1067 | (intptr_t)curBlock); |
| 1068 | } |
| 1069 | curBlock = nextBlock; |
| 1070 | } |
| 1071 | } |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 1072 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1073 | if (!(cUnit->disableOpt & (1 << kSkipLargeMethodOptimization))) { |
| 1074 | if ((cUnit->numBlocks > MANY_BLOCKS) || |
| 1075 | ((cUnit->numBlocks > MANY_BLOCKS_INITIALIZER) && |
| 1076 | PrettyMethod(method_idx, dex_file, false).find("init>") != |
| 1077 | std::string::npos)) { |
| 1078 | cUnit->qdMode = true; |
| 1079 | } |
| 1080 | } |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 1081 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1082 | if (cUnit->qdMode) { |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame] | 1083 | // Bitcode generation requires full dataflow analysis |
buzbee | c531cef | 2012-10-18 07:09:20 -0700 | [diff] [blame] | 1084 | cUnit->disableDataflow = !cUnit->genBitcode; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1085 | // Disable optimization which require dataflow/ssa |
buzbee | c531cef | 2012-10-18 07:09:20 -0700 | [diff] [blame] | 1086 | cUnit->disableOpt |= (1 << kBBOpt) | (1 << kPromoteRegs) | (1 << kNullCheckElimination); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1087 | if (cUnit->printMe) { |
| 1088 | LOG(INFO) << "QD mode enabled: " |
| 1089 | << PrettyMethod(method_idx, dex_file) |
buzbee | c531cef | 2012-10-18 07:09:20 -0700 | [diff] [blame] | 1090 | << " num blocks: " << cUnit->numBlocks; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1091 | } |
| 1092 | } |
buzbee | c1f4504 | 2011-09-21 16:03:19 -0700 | [diff] [blame] | 1093 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1094 | if (cUnit->printMe) { |
| 1095 | oatDumpCompilationUnit(cUnit.get()); |
| 1096 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1097 | |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 1098 | /* Do a code layout pass */ |
| 1099 | oatMethodCodeLayout(cUnit.get()); |
| 1100 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1101 | if (cUnit->enableDebug & (1 << kDebugVerifyDataflow)) { |
| 1102 | /* Verify if all blocks are connected as claimed */ |
| 1103 | oatDataFlowAnalysisDispatcher(cUnit.get(), verifyPredInfo, kAllNodes, |
| 1104 | false /* isIterative */); |
| 1105 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1106 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1107 | /* Perform SSA transformation for the whole method */ |
| 1108 | oatMethodSSATransformation(cUnit.get()); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1109 | |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1110 | /* Do constant propagation */ |
| 1111 | // TODO: Probably need to make these expandable to support new ssa names |
| 1112 | // introducted during MIR optimization passes |
| 1113 | cUnit->isConstantV = oatAllocBitVector(cUnit.get(), cUnit->numSSARegs, |
| 1114 | false /* not expandable */); |
| 1115 | cUnit->constantValues = |
| 1116 | (int*)oatNew(cUnit.get(), sizeof(int) * cUnit->numSSARegs, true, |
| 1117 | kAllocDFInfo); |
| 1118 | oatDataFlowAnalysisDispatcher(cUnit.get(), oatDoConstantPropagation, |
| 1119 | kAllNodes, |
| 1120 | false /* isIterative */); |
| 1121 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1122 | /* Detect loops */ |
| 1123 | oatMethodLoopDetection(cUnit.get()); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1124 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1125 | /* Count uses */ |
| 1126 | oatMethodUseCount(cUnit.get()); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1127 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1128 | /* Perform null check elimination */ |
| 1129 | oatMethodNullCheckElimination(cUnit.get()); |
| 1130 | |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame] | 1131 | /* Combine basic blocks where possible */ |
| 1132 | oatMethodBasicBlockCombine(cUnit.get()); |
| 1133 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1134 | /* Do some basic block optimizations */ |
| 1135 | oatMethodBasicBlockOptimization(cUnit.get()); |
| 1136 | |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame] | 1137 | if (cUnit->enableDebug & (1 << kDebugDumpCheckStats)) { |
| 1138 | oatDumpCheckStats(cUnit.get()); |
| 1139 | } |
| 1140 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1141 | oatInitializeRegAlloc(cUnit.get()); // Needs to happen after SSA naming |
| 1142 | |
| 1143 | /* Allocate Registers using simple local allocation scheme */ |
| 1144 | oatSimpleRegAlloc(cUnit.get()); |
| 1145 | |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1146 | /* Go the LLVM path? */ |
| 1147 | if (cUnit->genBitcode) { |
| 1148 | // MIR->Bitcode |
| 1149 | oatMethodMIR2Bitcode(cUnit.get()); |
buzbee | c531cef | 2012-10-18 07:09:20 -0700 | [diff] [blame] | 1150 | if (compilerBackend == kPortable) { |
buzbee | abc4c6b | 2012-08-23 08:17:15 -0700 | [diff] [blame] | 1151 | // all done |
| 1152 | oatArenaReset(cUnit.get()); |
| 1153 | return NULL; |
| 1154 | } |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1155 | // Bitcode->LIR |
| 1156 | oatMethodBitcode2LIR(cUnit.get()); |
| 1157 | } else { |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1158 | if (specialCase != kNoHandler) { |
| 1159 | /* |
| 1160 | * Custom codegen for special cases. If for any reason the |
| 1161 | * special codegen doesn't succeed, cUnit->firstLIRInsn will |
| 1162 | * set to NULL; |
| 1163 | */ |
| 1164 | oatSpecialMIR2LIR(cUnit.get(), specialCase); |
| 1165 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1166 | |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1167 | /* Convert MIR to LIR, etc. */ |
| 1168 | if (cUnit->firstLIRInsn == NULL) { |
| 1169 | oatMethodMIR2LIR(cUnit.get()); |
| 1170 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1171 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1172 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1173 | // Debugging only |
| 1174 | if (cUnit->enableDebug & (1 << kDebugDumpCFG)) { |
| 1175 | oatDumpCFG(cUnit.get(), "/sdcard/cfg/"); |
| 1176 | } |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 1177 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1178 | /* Method is not empty */ |
| 1179 | if (cUnit->firstLIRInsn) { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1180 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1181 | // mark the targets of switch statement case labels |
| 1182 | oatProcessSwitchTables(cUnit.get()); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1183 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1184 | /* Convert LIR into machine code. */ |
| 1185 | oatAssembleLIR(cUnit.get()); |
buzbee | 99ba964 | 2012-01-25 14:23:14 -0800 | [diff] [blame] | 1186 | |
Elliott Hughes | 3b6baaa | 2011-10-14 19:13:56 -0700 | [diff] [blame] | 1187 | if (cUnit->printMe) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1188 | oatCodegenDump(cUnit.get()); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1189 | } |
| 1190 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1191 | if (cUnit->opcodeCount != NULL) { |
| 1192 | LOG(INFO) << "Opcode Count"; |
| 1193 | for (int i = 0; i < kNumPackedOpcodes; i++) { |
| 1194 | if (cUnit->opcodeCount[i] != 0) { |
| 1195 | LOG(INFO) << "-C- " |
| 1196 | << Instruction::Name(static_cast<Instruction::Code>(i)) |
| 1197 | << " " << cUnit->opcodeCount[i]; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1198 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1199 | } |
| 1200 | } |
| 1201 | } |
buzbee | a7c1268 | 2012-03-19 13:13:53 -0700 | [diff] [blame] | 1202 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1203 | // Combine vmap tables - core regs, then fp regs - into vmapTable |
| 1204 | std::vector<uint16_t> vmapTable; |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 1205 | // Core regs may have been inserted out of order - sort first |
| 1206 | std::sort(cUnit->coreVmapTable.begin(), cUnit->coreVmapTable.end()); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1207 | for (size_t i = 0 ; i < cUnit->coreVmapTable.size(); i++) { |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 1208 | // Copy, stripping out the phys register sort key |
| 1209 | vmapTable.push_back(~(-1 << VREG_NUM_WIDTH) & cUnit->coreVmapTable[i]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1210 | } |
| 1211 | // If we have a frame, push a marker to take place of lr |
| 1212 | if (cUnit->frameSize > 0) { |
| 1213 | vmapTable.push_back(INVALID_VREG); |
| 1214 | } else { |
| 1215 | DCHECK_EQ(__builtin_popcount(cUnit->coreSpillMask), 0); |
| 1216 | DCHECK_EQ(__builtin_popcount(cUnit->fpSpillMask), 0); |
| 1217 | } |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 1218 | // Combine vmap tables - core regs, then fp regs. fp regs already sorted |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1219 | for (uint32_t i = 0; i < cUnit->fpVmapTable.size(); i++) { |
| 1220 | vmapTable.push_back(cUnit->fpVmapTable[i]); |
| 1221 | } |
| 1222 | CompiledMethod* result = |
| 1223 | new CompiledMethod(cUnit->instructionSet, cUnit->codeBuffer, |
Bill Buzbee | a5b3024 | 2012-09-28 07:19:44 -0700 | [diff] [blame] | 1224 | cUnit->frameSize, cUnit->coreSpillMask, cUnit->fpSpillMask, |
| 1225 | cUnit->combinedMappingTable, vmapTable, cUnit->nativeGcMap); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1226 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1227 | VLOG(compiler) << "Compiled " << PrettyMethod(method_idx, dex_file) |
| 1228 | << " (" << (cUnit->codeBuffer.size() * sizeof(cUnit->codeBuffer[0])) |
| 1229 | << " bytes)"; |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 1230 | |
| 1231 | #ifdef WITH_MEMSTATS |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1232 | if (cUnit->enableDebug & (1 << kDebugShowMemoryUsage)) { |
| 1233 | oatDumpMemStats(cUnit.get()); |
| 1234 | } |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 1235 | #endif |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1236 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1237 | oatArenaReset(cUnit.get()); |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 1238 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1239 | return result; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1240 | } |
| 1241 | |
buzbee | abc4c6b | 2012-08-23 08:17:15 -0700 | [diff] [blame] | 1242 | CompiledMethod* oatCompileMethod(Compiler& compiler, |
buzbee | c531cef | 2012-10-18 07:09:20 -0700 | [diff] [blame] | 1243 | const CompilerBackend backend, |
buzbee | abc4c6b | 2012-08-23 08:17:15 -0700 | [diff] [blame] | 1244 | const DexFile::CodeItem* code_item, |
| 1245 | uint32_t access_flags, InvokeType invoke_type, |
| 1246 | uint32_t method_idx, jobject class_loader, |
buzbee | c531cef | 2012-10-18 07:09:20 -0700 | [diff] [blame] | 1247 | const DexFile& dex_file, |
| 1248 | LLVMInfo* llvmInfo) |
buzbee | abc4c6b | 2012-08-23 08:17:15 -0700 | [diff] [blame] | 1249 | { |
buzbee | c531cef | 2012-10-18 07:09:20 -0700 | [diff] [blame] | 1250 | return compileMethod(compiler, backend, code_item, access_flags, invoke_type, method_idx, class_loader, |
| 1251 | dex_file, llvmInfo); |
buzbee | abc4c6b | 2012-08-23 08:17:15 -0700 | [diff] [blame] | 1252 | } |
| 1253 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 1254 | } // namespace art |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 1255 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1256 | extern "C" art::CompiledMethod* |
buzbee | c531cef | 2012-10-18 07:09:20 -0700 | [diff] [blame] | 1257 | ArtQuickCompileMethod(art::Compiler& compiler, |
| 1258 | const art::DexFile::CodeItem* code_item, |
| 1259 | uint32_t access_flags, art::InvokeType invoke_type, |
| 1260 | uint32_t method_idx, jobject class_loader, |
| 1261 | const art::DexFile& dex_file) |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 1262 | { |
| 1263 | CHECK_EQ(compiler.GetInstructionSet(), art::oatInstructionSet()); |
buzbee | c531cef | 2012-10-18 07:09:20 -0700 | [diff] [blame] | 1264 | // TODO: check method fingerprint here to determine appropriate backend type. Until then, use build default |
| 1265 | art::CompilerBackend backend = compiler.GetCompilerBackend(); |
| 1266 | return art::oatCompileMethod(compiler, backend, code_item, access_flags, invoke_type, |
| 1267 | method_idx, class_loader, dex_file, NULL /* use thread llvmInfo */); |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 1268 | } |