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 | |
| 17 | #include "Dalvik.h" |
| 18 | #include "CompilerInternals.h" |
| 19 | #include "Dataflow.h" |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 20 | #include "leb128.h" |
Brian Carlstrom | 9baa4ae | 2011-09-01 21:14:14 -0700 | [diff] [blame] | 21 | #include "object.h" |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 22 | #include "runtime.h" |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 23 | |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame^] | 24 | #if defined(ART_USE_QUICK_COMPILER) |
| 25 | #include <llvm/Support/Threading.h> |
| 26 | |
| 27 | namespace { |
| 28 | pthread_once_t llvm_multi_init = PTHREAD_ONCE_INIT; |
| 29 | void InitializeLLVMForQuick() { |
| 30 | llvm::llvm_start_multithreaded(); |
| 31 | } |
| 32 | } |
| 33 | #endif |
| 34 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 35 | namespace art { |
| 36 | |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 37 | #if defined(ART_USE_QUICK_COMPILER) |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame^] | 38 | LLVMInfo::LLVMInfo() { |
| 39 | #if !defined(ART_USE_LLVM_COMPILER) |
| 40 | pthread_once(&llvm_multi_init, InitializeLLVMForQuick); |
| 41 | #endif |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 42 | // Create context, module, intrinsic helper & ir builder |
| 43 | llvm_context_.reset(new llvm::LLVMContext()); |
TDYa127 | 55e5e6c | 2012-09-11 15:14:42 -0700 | [diff] [blame] | 44 | llvm_module_ = new llvm::Module("art", *llvm_context_); |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 45 | llvm::StructType::create(*llvm_context_, "JavaObject"); |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 46 | intrinsic_helper_.reset( new greenland::IntrinsicHelper(*llvm_context_, *llvm_module_)); |
| 47 | ir_builder_.reset(new greenland::IRBuilder(*llvm_context_, *llvm_module_, *intrinsic_helper_)); |
| 48 | } |
| 49 | |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame^] | 50 | LLVMInfo::~LLVMInfo() { |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | extern "C" void ArtInitQuickCompilerContext(art::Compiler& compiler) { |
| 54 | CHECK(compiler.GetCompilerContext() == NULL); |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame^] | 55 | LLVMInfo* llvmInfo = new LLVMInfo(); |
| 56 | compiler.SetCompilerContext(llvmInfo); |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | extern "C" void ArtUnInitQuickCompilerContext(art::Compiler& compiler) { |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame^] | 60 | delete reinterpret_cast<LLVMInfo*>(compiler.GetCompilerContext()); |
buzbee | 692be80 | 2012-08-29 15:52:59 -0700 | [diff] [blame] | 61 | compiler.SetCompilerContext(NULL); |
| 62 | } |
| 63 | #endif |
| 64 | |
buzbee | ce30293 | 2011-10-04 14:32:18 -0700 | [diff] [blame] | 65 | /* Default optimizer/debug setting for the compiler. */ |
Elliott Hughes | e52e49b | 2012-04-02 16:05:44 -0700 | [diff] [blame] | 66 | static uint32_t kCompilerOptimizerDisableFlags = 0 | // Disable specific optimizations |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 67 | //(1 << kLoadStoreElimination) | |
| 68 | //(1 << kLoadHoisting) | |
| 69 | //(1 << kSuppressLoads) | |
| 70 | //(1 << kNullCheckElimination) | |
| 71 | //(1 << kPromoteRegs) | |
| 72 | //(1 << kTrackLiveTemps) | |
| 73 | //(1 << kSkipLargeMethodOptimization) | |
| 74 | //(1 << kSafeOptimizations) | |
| 75 | //(1 << kBBOpt) | |
| 76 | //(1 << kMatch) | |
| 77 | //(1 << kPromoteCompilerTemps) | |
| 78 | 0; |
buzbee | ce30293 | 2011-10-04 14:32:18 -0700 | [diff] [blame] | 79 | |
Elliott Hughes | e52e49b | 2012-04-02 16:05:44 -0700 | [diff] [blame] | 80 | static uint32_t kCompilerDebugFlags = 0 | // Enable debug/testing modes |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 81 | //(1 << kDebugDisplayMissingTargets) | |
| 82 | //(1 << kDebugVerbose) | |
| 83 | //(1 << kDebugDumpCFG) | |
| 84 | //(1 << kDebugSlowFieldPath) | |
| 85 | //(1 << kDebugSlowInvokePath) | |
| 86 | //(1 << kDebugSlowStringPath) | |
| 87 | //(1 << kDebugSlowestFieldPath) | |
| 88 | //(1 << kDebugSlowestStringPath) | |
| 89 | //(1 << kDebugExerciseResolveMethod) | |
| 90 | //(1 << kDebugVerifyDataflow) | |
| 91 | //(1 << kDebugShowMemoryUsage) | |
| 92 | //(1 << kDebugShowNops) | |
| 93 | //(1 << kDebugCountOpcodes) | |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame] | 94 | //(1 << kDebugDumpCheckStats) | |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 95 | #if defined(ART_USE_QUICK_COMPILER) |
| 96 | //(1 << kDebugDumpBitcodeFile) | |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 97 | //(1 << kDebugVerifyBitcode) | |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 98 | #endif |
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 | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 101 | inline bool contentIsInsn(const u2* codePtr) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 102 | u2 instr = *codePtr; |
| 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 | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 115 | inline int parseInsn(CompilationUnit* cUnit, const u2* 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, |
| 518 | const u2* codePtr, const u2* 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 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 602 | u2* switchData= (u2 *) (cUnit->insns + curOffset + insn->dalvikInsn.vB); |
| 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, |
| 691 | ArenaBitVector* tryBlockAddr, const u2* codePtr, |
| 692 | const u2* 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, |
| 789 | const DexFile::CodeItem* code_item, |
| 790 | uint32_t access_flags, InvokeType invoke_type, |
| 791 | uint32_t method_idx, jobject class_loader, |
| 792 | const DexFile& dex_file |
| 793 | #if defined(ART_USE_QUICK_COMPILER) |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame^] | 794 | , LLVMInfo* llvm_info, |
buzbee | abc4c6b | 2012-08-23 08:17:15 -0700 | [diff] [blame] | 795 | bool gbcOnly |
| 796 | #endif |
| 797 | ) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 798 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 799 | VLOG(compiler) << "Compiling " << PrettyMethod(method_idx, dex_file) << "..."; |
Brian Carlstrom | 94496d3 | 2011-08-22 09:22:47 -0700 | [diff] [blame] | 800 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 801 | const u2* codePtr = code_item->insns_; |
| 802 | const u2* codeEnd = code_item->insns_ + code_item->insns_size_in_code_units_; |
| 803 | int numBlocks = 0; |
| 804 | unsigned int curOffset = 0; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 805 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 806 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 807 | UniquePtr<CompilationUnit> cUnit(new CompilationUnit); |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 808 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 809 | oatInit(cUnit.get(), compiler); |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 810 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 811 | cUnit->compiler = &compiler; |
| 812 | cUnit->class_linker = class_linker; |
| 813 | cUnit->dex_file = &dex_file; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 814 | cUnit->method_idx = method_idx; |
| 815 | cUnit->code_item = code_item; |
| 816 | cUnit->access_flags = access_flags; |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 817 | cUnit->invoke_type = invoke_type; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 818 | cUnit->shorty = dex_file.GetMethodShorty(dex_file.GetMethodId(method_idx)); |
| 819 | cUnit->instructionSet = compiler.GetInstructionSet(); |
| 820 | cUnit->insns = code_item->insns_; |
| 821 | cUnit->insnsSize = code_item->insns_size_in_code_units_; |
| 822 | cUnit->numIns = code_item->ins_size_; |
| 823 | cUnit->numRegs = code_item->registers_size_ - cUnit->numIns; |
| 824 | cUnit->numOuts = code_item->outs_size_; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 825 | #if defined(ART_USE_QUICK_COMPILER) |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 826 | DCHECK((cUnit->instructionSet == kThumb2) || |
| 827 | (cUnit->instructionSet == kX86) || |
| 828 | (cUnit->instructionSet == kMips)); |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame^] | 829 | cUnit->llvm_info = llvm_info; |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 830 | if (cUnit->instructionSet == kThumb2) { |
| 831 | // TODO: remove this once x86 is tested |
buzbee | 85eee02 | 2012-07-16 22:12:38 -0700 | [diff] [blame] | 832 | cUnit->genBitcode = true; |
| 833 | } |
buzbee | 2a83e8f | 2012-07-13 16:42:30 -0700 | [diff] [blame] | 834 | #endif |
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 | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 849 | #if defined(ART_USE_QUICK_COMPILER) |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 850 | if (cUnit->genBitcode) { |
buzbee | 6459e7c | 2012-10-02 14:42:41 -0700 | [diff] [blame] | 851 | #ifndef NDEBUG |
| 852 | cUnit->enableDebug |= (1 << kDebugVerifyBitcode); |
| 853 | #endif |
buzbee | 2a83e8f | 2012-07-13 16:42:30 -0700 | [diff] [blame] | 854 | //cUnit->printMe = true; |
| 855 | //cUnit->enableDebug |= (1 << kDebugDumpBitcodeFile); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 856 | } |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 857 | #endif |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 858 | if (cUnit->instructionSet == kMips) { |
| 859 | // Disable some optimizations for mips for now |
| 860 | cUnit->disableOpt |= ( |
| 861 | (1 << kLoadStoreElimination) | |
| 862 | (1 << kLoadHoisting) | |
| 863 | (1 << kSuppressLoads) | |
| 864 | (1 << kNullCheckElimination) | |
| 865 | (1 << kPromoteRegs) | |
| 866 | (1 << kTrackLiveTemps) | |
| 867 | (1 << kSkipLargeMethodOptimization) | |
| 868 | (1 << kSafeOptimizations) | |
| 869 | (1 << kBBOpt) | |
| 870 | (1 << kMatch) | |
| 871 | (1 << kPromoteCompilerTemps)); |
| 872 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 873 | /* Are we generating code for the debugger? */ |
| 874 | if (compiler.IsDebuggingSupported()) { |
| 875 | cUnit->genDebugger = true; |
| 876 | // Yes, disable most optimizations |
| 877 | cUnit->disableOpt |= ( |
| 878 | (1 << kLoadStoreElimination) | |
| 879 | (1 << kLoadHoisting) | |
| 880 | (1 << kSuppressLoads) | |
| 881 | (1 << kPromoteRegs) | |
| 882 | (1 << kBBOpt) | |
| 883 | (1 << kMatch) | |
| 884 | (1 << kTrackLiveTemps)); |
| 885 | } |
| 886 | |
| 887 | /* Gathering opcode stats? */ |
| 888 | if (kCompilerDebugFlags & (1 << kDebugCountOpcodes)) { |
| 889 | cUnit->opcodeCount = (int*)oatNew(cUnit.get(), |
| 890 | kNumPackedOpcodes * sizeof(int), true, kAllocMisc); |
| 891 | } |
| 892 | |
| 893 | /* Assume non-throwing leaf */ |
| 894 | cUnit->attrs = (METHOD_IS_LEAF | METHOD_IS_THROW_FREE); |
| 895 | |
| 896 | /* Initialize the block list, estimate size based on insnsSize */ |
| 897 | oatInitGrowableList(cUnit.get(), &cUnit->blockList, cUnit->insnsSize, |
| 898 | kListBlockList); |
| 899 | |
| 900 | /* Initialize the switchTables list */ |
| 901 | oatInitGrowableList(cUnit.get(), &cUnit->switchTables, 4, |
| 902 | kListSwitchTables); |
| 903 | |
| 904 | /* Intialize the fillArrayData list */ |
| 905 | oatInitGrowableList(cUnit.get(), &cUnit->fillArrayData, 4, |
| 906 | kListFillArrayData); |
| 907 | |
| 908 | /* Intialize the throwLaunchpads list, estimate size based on insnsSize */ |
| 909 | oatInitGrowableList(cUnit.get(), &cUnit->throwLaunchpads, cUnit->insnsSize, |
| 910 | kListThrowLaunchPads); |
| 911 | |
| 912 | /* Intialize the instrinsicLaunchpads list */ |
| 913 | oatInitGrowableList(cUnit.get(), &cUnit->intrinsicLaunchpads, 4, |
| 914 | kListMisc); |
| 915 | |
| 916 | |
| 917 | /* Intialize the suspendLaunchpads list */ |
| 918 | oatInitGrowableList(cUnit.get(), &cUnit->suspendLaunchpads, 2048, |
| 919 | kListSuspendLaunchPads); |
| 920 | |
| 921 | /* Allocate the bit-vector to track the beginning of basic blocks */ |
| 922 | ArenaBitVector *tryBlockAddr = oatAllocBitVector(cUnit.get(), |
| 923 | cUnit->insnsSize, |
| 924 | true /* expandable */); |
| 925 | cUnit->tryBlockAddr = tryBlockAddr; |
| 926 | |
| 927 | /* Create the default entry and exit blocks and enter them to the list */ |
| 928 | BasicBlock *entryBlock = oatNewBB(cUnit.get(), kEntryBlock, numBlocks++); |
| 929 | BasicBlock *exitBlock = oatNewBB(cUnit.get(), kExitBlock, numBlocks++); |
| 930 | |
| 931 | cUnit->entryBlock = entryBlock; |
| 932 | cUnit->exitBlock = exitBlock; |
| 933 | |
| 934 | oatInsertGrowableList(cUnit.get(), &cUnit->blockList, (intptr_t) entryBlock); |
| 935 | oatInsertGrowableList(cUnit.get(), &cUnit->blockList, (intptr_t) exitBlock); |
| 936 | |
| 937 | /* Current block to record parsed instructions */ |
| 938 | BasicBlock *curBlock = oatNewBB(cUnit.get(), kDalvikByteCode, numBlocks++); |
| 939 | curBlock->startOffset = 0; |
| 940 | oatInsertGrowableList(cUnit.get(), &cUnit->blockList, (intptr_t) curBlock); |
| 941 | /* Add first block to the fast lookup cache */ |
| 942 | cUnit->blockMap.Put(curBlock->startOffset, curBlock); |
| 943 | entryBlock->fallThrough = curBlock; |
| 944 | oatInsertGrowableList(cUnit.get(), curBlock->predecessors, |
| 945 | (intptr_t)entryBlock); |
| 946 | |
| 947 | /* |
| 948 | * Store back the number of blocks since new blocks may be created of |
| 949 | * accessing cUnit. |
| 950 | */ |
| 951 | cUnit->numBlocks = numBlocks; |
| 952 | |
| 953 | /* Identify code range in try blocks and set up the empty catch blocks */ |
| 954 | processTryCatchBlocks(cUnit.get()); |
| 955 | |
| 956 | /* Set up for simple method detection */ |
| 957 | int numPatterns = sizeof(specialPatterns)/sizeof(specialPatterns[0]); |
| 958 | bool livePattern = (numPatterns > 0) && !(cUnit->disableOpt & (1 << kMatch)); |
Elliott Hughes | abe64aa | 2012-05-30 17:34:45 -0700 | [diff] [blame] | 959 | bool* deadPattern = (bool*)oatNew(cUnit.get(), sizeof(bool) * numPatterns, true, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 960 | kAllocMisc); |
| 961 | SpecialCaseHandler specialCase = kNoHandler; |
| 962 | int patternPos = 0; |
| 963 | |
| 964 | /* Parse all instructions and put them into containing basic blocks */ |
| 965 | while (codePtr < codeEnd) { |
| 966 | MIR *insn = (MIR *) oatNew(cUnit.get(), sizeof(MIR), true, kAllocMIR); |
| 967 | insn->offset = curOffset; |
| 968 | int width = parseInsn(cUnit.get(), codePtr, &insn->dalvikInsn, false); |
| 969 | insn->width = width; |
| 970 | Instruction::Code opcode = insn->dalvikInsn.opcode; |
| 971 | if (cUnit->opcodeCount != NULL) { |
| 972 | cUnit->opcodeCount[static_cast<int>(opcode)]++; |
buzbee | 44b412b | 2012-02-04 08:50:53 -0800 | [diff] [blame] | 973 | } |
| 974 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 975 | /* Terminate when the data section is seen */ |
| 976 | if (width == 0) |
| 977 | break; |
| 978 | |
| 979 | /* Possible simple method? */ |
| 980 | if (livePattern) { |
| 981 | livePattern = false; |
| 982 | specialCase = kNoHandler; |
| 983 | for (int i = 0; i < numPatterns; i++) { |
| 984 | if (!deadPattern[i]) { |
| 985 | if (specialPatterns[i].opcodes[patternPos] == opcode) { |
| 986 | livePattern = true; |
| 987 | specialCase = specialPatterns[i].handlerCode; |
| 988 | } else { |
| 989 | deadPattern[i] = true; |
| 990 | } |
| 991 | } |
| 992 | } |
| 993 | patternPos++; |
buzbee | a7c1268 | 2012-03-19 13:13:53 -0700 | [diff] [blame] | 994 | } |
| 995 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 996 | oatAppendMIR(curBlock, insn); |
buzbee | cefd187 | 2011-09-09 09:59:52 -0700 | [diff] [blame] | 997 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 998 | codePtr += width; |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 999 | int flags = Instruction::FlagsOf(insn->dalvikInsn.opcode); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1000 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1001 | int dfFlags = oatDataFlowAttributes[insn->dalvikInsn.opcode]; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1002 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1003 | if (dfFlags & DF_HAS_DEFS) { |
buzbee | bff2465 | 2012-05-06 16:22:05 -0700 | [diff] [blame] | 1004 | cUnit->defCount += (dfFlags & DF_A_WIDE) ? 2 : 1; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1005 | } |
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 | if (flags & Instruction::kBranch) { |
| 1008 | curBlock = processCanBranch(cUnit.get(), curBlock, insn, curOffset, |
| 1009 | width, flags, codePtr, codeEnd); |
| 1010 | } else if (flags & Instruction::kReturn) { |
| 1011 | curBlock->fallThrough = exitBlock; |
| 1012 | oatInsertGrowableList(cUnit.get(), exitBlock->predecessors, |
| 1013 | (intptr_t)curBlock); |
| 1014 | /* |
| 1015 | * Terminate the current block if there are instructions |
| 1016 | * afterwards. |
| 1017 | */ |
| 1018 | if (codePtr < codeEnd) { |
| 1019 | /* |
| 1020 | * Create a fallthrough block for real instructions |
| 1021 | * (incl. NOP). |
| 1022 | */ |
| 1023 | if (contentIsInsn(codePtr)) { |
| 1024 | findBlock(cUnit.get(), curOffset + width, |
| 1025 | /* split */ |
| 1026 | false, |
| 1027 | /* create */ |
| 1028 | true, |
| 1029 | /* immedPredBlockP */ |
| 1030 | NULL); |
| 1031 | } |
| 1032 | } |
| 1033 | } else if (flags & Instruction::kThrow) { |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 1034 | curBlock = processCanThrow(cUnit.get(), curBlock, insn, curOffset, |
| 1035 | width, flags, tryBlockAddr, codePtr, codeEnd); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1036 | } else if (flags & Instruction::kSwitch) { |
| 1037 | processCanSwitch(cUnit.get(), curBlock, insn, curOffset, width, flags); |
| 1038 | } |
| 1039 | curOffset += width; |
| 1040 | BasicBlock *nextBlock = findBlock(cUnit.get(), curOffset, |
| 1041 | /* split */ |
| 1042 | false, |
| 1043 | /* create */ |
| 1044 | false, |
| 1045 | /* immedPredBlockP */ |
| 1046 | NULL); |
| 1047 | if (nextBlock) { |
| 1048 | /* |
| 1049 | * The next instruction could be the target of a previously parsed |
| 1050 | * forward branch so a block is already created. If the current |
| 1051 | * instruction is not an unconditional branch, connect them through |
| 1052 | * the fall-through link. |
| 1053 | */ |
| 1054 | DCHECK(curBlock->fallThrough == NULL || |
| 1055 | curBlock->fallThrough == nextBlock || |
| 1056 | curBlock->fallThrough == exitBlock); |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 1057 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1058 | if ((curBlock->fallThrough == NULL) && (flags & Instruction::kContinue)) { |
| 1059 | curBlock->fallThrough = nextBlock; |
| 1060 | oatInsertGrowableList(cUnit.get(), nextBlock->predecessors, |
| 1061 | (intptr_t)curBlock); |
| 1062 | } |
| 1063 | curBlock = nextBlock; |
| 1064 | } |
| 1065 | } |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 1066 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1067 | if (!(cUnit->disableOpt & (1 << kSkipLargeMethodOptimization))) { |
| 1068 | if ((cUnit->numBlocks > MANY_BLOCKS) || |
| 1069 | ((cUnit->numBlocks > MANY_BLOCKS_INITIALIZER) && |
| 1070 | PrettyMethod(method_idx, dex_file, false).find("init>") != |
| 1071 | std::string::npos)) { |
| 1072 | cUnit->qdMode = true; |
| 1073 | } |
| 1074 | } |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 1075 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1076 | if (cUnit->qdMode) { |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame] | 1077 | #if !defined(ART_USE_QUICK_COMPILER) |
| 1078 | // Bitcode generation requires full dataflow analysis |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1079 | cUnit->disableDataflow = true; |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame] | 1080 | #endif |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1081 | // Disable optimization which require dataflow/ssa |
| 1082 | cUnit->disableOpt |= |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame] | 1083 | #if !defined(ART_USE_QUICK_COMPILER) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1084 | (1 << kNullCheckElimination) | |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame] | 1085 | #endif |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1086 | (1 << kBBOpt) | |
| 1087 | (1 << kPromoteRegs); |
| 1088 | if (cUnit->printMe) { |
| 1089 | LOG(INFO) << "QD mode enabled: " |
| 1090 | << PrettyMethod(method_idx, dex_file) |
| 1091 | << " too big: " << cUnit->numBlocks; |
| 1092 | } |
| 1093 | } |
buzbee | c1f4504 | 2011-09-21 16:03:19 -0700 | [diff] [blame] | 1094 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1095 | if (cUnit->printMe) { |
| 1096 | oatDumpCompilationUnit(cUnit.get()); |
| 1097 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1098 | |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 1099 | /* Do a code layout pass */ |
| 1100 | oatMethodCodeLayout(cUnit.get()); |
| 1101 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1102 | if (cUnit->enableDebug & (1 << kDebugVerifyDataflow)) { |
| 1103 | /* Verify if all blocks are connected as claimed */ |
| 1104 | oatDataFlowAnalysisDispatcher(cUnit.get(), verifyPredInfo, kAllNodes, |
| 1105 | false /* isIterative */); |
| 1106 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1107 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1108 | /* Perform SSA transformation for the whole method */ |
| 1109 | oatMethodSSATransformation(cUnit.get()); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1110 | |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1111 | /* Do constant propagation */ |
| 1112 | // TODO: Probably need to make these expandable to support new ssa names |
| 1113 | // introducted during MIR optimization passes |
| 1114 | cUnit->isConstantV = oatAllocBitVector(cUnit.get(), cUnit->numSSARegs, |
| 1115 | false /* not expandable */); |
| 1116 | cUnit->constantValues = |
| 1117 | (int*)oatNew(cUnit.get(), sizeof(int) * cUnit->numSSARegs, true, |
| 1118 | kAllocDFInfo); |
| 1119 | oatDataFlowAnalysisDispatcher(cUnit.get(), oatDoConstantPropagation, |
| 1120 | kAllNodes, |
| 1121 | false /* isIterative */); |
| 1122 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1123 | /* Detect loops */ |
| 1124 | oatMethodLoopDetection(cUnit.get()); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1125 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1126 | /* Count uses */ |
| 1127 | oatMethodUseCount(cUnit.get()); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1128 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1129 | /* Perform null check elimination */ |
| 1130 | oatMethodNullCheckElimination(cUnit.get()); |
| 1131 | |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame] | 1132 | /* Combine basic blocks where possible */ |
| 1133 | oatMethodBasicBlockCombine(cUnit.get()); |
| 1134 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1135 | /* Do some basic block optimizations */ |
| 1136 | oatMethodBasicBlockOptimization(cUnit.get()); |
| 1137 | |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame] | 1138 | if (cUnit->enableDebug & (1 << kDebugDumpCheckStats)) { |
| 1139 | oatDumpCheckStats(cUnit.get()); |
| 1140 | } |
| 1141 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1142 | oatInitializeRegAlloc(cUnit.get()); // Needs to happen after SSA naming |
| 1143 | |
| 1144 | /* Allocate Registers using simple local allocation scheme */ |
| 1145 | oatSimpleRegAlloc(cUnit.get()); |
| 1146 | |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1147 | #if defined(ART_USE_QUICK_COMPILER) |
| 1148 | /* Go the LLVM path? */ |
| 1149 | if (cUnit->genBitcode) { |
| 1150 | // MIR->Bitcode |
| 1151 | oatMethodMIR2Bitcode(cUnit.get()); |
TDYa127 | 55e5e6c | 2012-09-11 15:14:42 -0700 | [diff] [blame] | 1152 | if (gbcOnly) { |
buzbee | abc4c6b | 2012-08-23 08:17:15 -0700 | [diff] [blame] | 1153 | // all done |
| 1154 | oatArenaReset(cUnit.get()); |
| 1155 | return NULL; |
| 1156 | } |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1157 | // Bitcode->LIR |
| 1158 | oatMethodBitcode2LIR(cUnit.get()); |
| 1159 | } else { |
| 1160 | #endif |
| 1161 | if (specialCase != kNoHandler) { |
| 1162 | /* |
| 1163 | * Custom codegen for special cases. If for any reason the |
| 1164 | * special codegen doesn't succeed, cUnit->firstLIRInsn will |
| 1165 | * set to NULL; |
| 1166 | */ |
| 1167 | oatSpecialMIR2LIR(cUnit.get(), specialCase); |
| 1168 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1169 | |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1170 | /* Convert MIR to LIR, etc. */ |
| 1171 | if (cUnit->firstLIRInsn == NULL) { |
| 1172 | oatMethodMIR2LIR(cUnit.get()); |
| 1173 | } |
| 1174 | #if defined(ART_USE_QUICK_COMPILER) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1175 | } |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1176 | #endif |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1177 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1178 | // Debugging only |
| 1179 | if (cUnit->enableDebug & (1 << kDebugDumpCFG)) { |
| 1180 | oatDumpCFG(cUnit.get(), "/sdcard/cfg/"); |
| 1181 | } |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 1182 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1183 | /* Method is not empty */ |
| 1184 | if (cUnit->firstLIRInsn) { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1185 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1186 | // mark the targets of switch statement case labels |
| 1187 | oatProcessSwitchTables(cUnit.get()); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1188 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1189 | /* Convert LIR into machine code. */ |
| 1190 | oatAssembleLIR(cUnit.get()); |
buzbee | 99ba964 | 2012-01-25 14:23:14 -0800 | [diff] [blame] | 1191 | |
Elliott Hughes | 3b6baaa | 2011-10-14 19:13:56 -0700 | [diff] [blame] | 1192 | if (cUnit->printMe) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1193 | oatCodegenDump(cUnit.get()); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1194 | } |
| 1195 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1196 | if (cUnit->opcodeCount != NULL) { |
| 1197 | LOG(INFO) << "Opcode Count"; |
| 1198 | for (int i = 0; i < kNumPackedOpcodes; i++) { |
| 1199 | if (cUnit->opcodeCount[i] != 0) { |
| 1200 | LOG(INFO) << "-C- " |
| 1201 | << Instruction::Name(static_cast<Instruction::Code>(i)) |
| 1202 | << " " << cUnit->opcodeCount[i]; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1203 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1204 | } |
| 1205 | } |
| 1206 | } |
buzbee | a7c1268 | 2012-03-19 13:13:53 -0700 | [diff] [blame] | 1207 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1208 | // Combine vmap tables - core regs, then fp regs - into vmapTable |
| 1209 | std::vector<uint16_t> vmapTable; |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 1210 | // Core regs may have been inserted out of order - sort first |
| 1211 | std::sort(cUnit->coreVmapTable.begin(), cUnit->coreVmapTable.end()); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1212 | for (size_t i = 0 ; i < cUnit->coreVmapTable.size(); i++) { |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 1213 | // Copy, stripping out the phys register sort key |
| 1214 | vmapTable.push_back(~(-1 << VREG_NUM_WIDTH) & cUnit->coreVmapTable[i]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1215 | } |
| 1216 | // If we have a frame, push a marker to take place of lr |
| 1217 | if (cUnit->frameSize > 0) { |
| 1218 | vmapTable.push_back(INVALID_VREG); |
| 1219 | } else { |
| 1220 | DCHECK_EQ(__builtin_popcount(cUnit->coreSpillMask), 0); |
| 1221 | DCHECK_EQ(__builtin_popcount(cUnit->fpSpillMask), 0); |
| 1222 | } |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 1223 | // Combine vmap tables - core regs, then fp regs. fp regs already sorted |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1224 | for (uint32_t i = 0; i < cUnit->fpVmapTable.size(); i++) { |
| 1225 | vmapTable.push_back(cUnit->fpVmapTable[i]); |
| 1226 | } |
| 1227 | CompiledMethod* result = |
| 1228 | new CompiledMethod(cUnit->instructionSet, cUnit->codeBuffer, |
Bill Buzbee | a5b3024 | 2012-09-28 07:19:44 -0700 | [diff] [blame] | 1229 | cUnit->frameSize, cUnit->coreSpillMask, cUnit->fpSpillMask, |
| 1230 | cUnit->combinedMappingTable, vmapTable, cUnit->nativeGcMap); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1231 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1232 | VLOG(compiler) << "Compiled " << PrettyMethod(method_idx, dex_file) |
| 1233 | << " (" << (cUnit->codeBuffer.size() * sizeof(cUnit->codeBuffer[0])) |
| 1234 | << " bytes)"; |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 1235 | |
| 1236 | #ifdef WITH_MEMSTATS |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1237 | if (cUnit->enableDebug & (1 << kDebugShowMemoryUsage)) { |
| 1238 | oatDumpMemStats(cUnit.get()); |
| 1239 | } |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 1240 | #endif |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1241 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1242 | oatArenaReset(cUnit.get()); |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 1243 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1244 | return result; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1245 | } |
| 1246 | |
buzbee | abc4c6b | 2012-08-23 08:17:15 -0700 | [diff] [blame] | 1247 | #if defined(ART_USE_QUICK_COMPILER) |
| 1248 | CompiledMethod* oatCompileMethod(Compiler& compiler, |
| 1249 | const DexFile::CodeItem* code_item, |
| 1250 | uint32_t access_flags, InvokeType invoke_type, |
| 1251 | uint32_t method_idx, jobject class_loader, |
| 1252 | const DexFile& dex_file) |
| 1253 | { |
| 1254 | return compileMethod(compiler, code_item, access_flags, invoke_type, method_idx, class_loader, |
TDYa127 | 55e5e6c | 2012-09-11 15:14:42 -0700 | [diff] [blame] | 1255 | dex_file, NULL, false); |
buzbee | abc4c6b | 2012-08-23 08:17:15 -0700 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | /* |
| 1259 | * Given existing llvm module, context, intrinsic_helper and IRBuilder, |
| 1260 | * add the bitcode for the method described by code_item to the module. |
| 1261 | */ |
| 1262 | void oatCompileMethodToGBC(Compiler& compiler, |
| 1263 | const DexFile::CodeItem* code_item, |
| 1264 | uint32_t access_flags, InvokeType invoke_type, |
| 1265 | uint32_t method_idx, jobject class_loader, |
| 1266 | const DexFile& dex_file, |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame^] | 1267 | LLVMInfo* llvm_info) |
buzbee | abc4c6b | 2012-08-23 08:17:15 -0700 | [diff] [blame] | 1268 | { |
| 1269 | compileMethod(compiler, code_item, access_flags, invoke_type, method_idx, class_loader, |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame^] | 1270 | dex_file, llvm_info, true); |
buzbee | abc4c6b | 2012-08-23 08:17:15 -0700 | [diff] [blame] | 1271 | } |
| 1272 | #else |
| 1273 | CompiledMethod* oatCompileMethod(Compiler& compiler, |
| 1274 | const DexFile::CodeItem* code_item, |
| 1275 | uint32_t access_flags, InvokeType invoke_type, |
| 1276 | uint32_t method_idx, jobject class_loader, |
| 1277 | const DexFile& dex_file) |
| 1278 | { |
| 1279 | return compileMethod(compiler, code_item, access_flags, invoke_type, method_idx, class_loader, |
| 1280 | dex_file); |
| 1281 | } |
| 1282 | #endif |
| 1283 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 1284 | } // namespace art |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 1285 | |
Shih-wei Liao | 46bde5c | 2012-08-31 11:28:16 -0700 | [diff] [blame] | 1286 | #if !defined(ART_USE_LLVM_COMPILER) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1287 | extern "C" art::CompiledMethod* |
| 1288 | ArtCompileMethod(art::Compiler& compiler, |
| 1289 | const art::DexFile::CodeItem* code_item, |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 1290 | uint32_t access_flags, art::InvokeType invoke_type, |
| 1291 | uint32_t method_idx, jobject class_loader, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1292 | const art::DexFile& dex_file) |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 1293 | { |
| 1294 | CHECK_EQ(compiler.GetInstructionSet(), art::oatInstructionSet()); |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 1295 | return art::oatCompileMethod(compiler, code_item, access_flags, invoke_type, |
| 1296 | method_idx, class_loader, dex_file); |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 1297 | } |
Shih-wei Liao | 46bde5c | 2012-08-31 11:28:16 -0700 | [diff] [blame] | 1298 | #endif |