/* Create the PC reconstruction slot if not already done */ static ArmLIR *genCheckCommon(CompilationUnit *cUnit, int dOffset, ArmLIR *branch, ArmLIR *pcrLabel) { /* Forget all def info (because we might rollback here. Bug #2367397 */ dvmCompilerResetDefTracking(cUnit); /* Set up the place holder to reconstruct this Dalvik PC */ if (pcrLabel == NULL) { int dPC = (int) (cUnit->method->insns + dOffset); pcrLabel = (ArmLIR *) dvmCompilerNew(sizeof(ArmLIR), true); pcrLabel->opcode = kArmPseudoPCReconstructionCell; pcrLabel->operands[0] = dPC; pcrLabel->operands[1] = dOffset; /* Insert the place holder to the growable list */ dvmInsertGrowableList(&cUnit->pcReconstructionList, (intptr_t) pcrLabel); } /* Branch to the PC reconstruction code */ branch->generic.target = (LIR *) pcrLabel; /* Clear the conservative flags for branches that punt to the interpreter */ relaxBranchMasks(branch); return pcrLabel; }
void dvmInitializeSSAConversion(CompilationUnit *cUnit) { int i; int numDalvikReg = cUnit->pCodeItem->item->registersSize; cUnit->ssaToDalvikMap = dvmCompilerNew(sizeof(GrowableList), false); dvmInitGrowableList(cUnit->ssaToDalvikMap, numDalvikReg); cUnit->numSSARegs = numDalvikReg; LOG(">>>>>>>>>>>>>>>The function is %s<<<<<<<<<<<<<<<<<<\n", __func__); LOG("cUnit->numSSARegs is %d\n", cUnit->numSSARegs); for(i = 0; i < numDalvikReg; i++) { dvmInsertGrowableList(cUnit->ssaToDalvikMap, (void *)ENCODE_REG_SUB(i, 0)); } cUnit->dalvikToSSAMap = dvmCompilerNew(sizeof(int) * numDalvikReg, false); for (i = 0; i < numDalvikReg; i++) { cUnit->dalvikToSSAMap[i] = i; } /* 这里暂时作用不知道,所以删除 for (i = 0; i < cUnit->numBlocks; i++) { BasicBlock *bb = cUnit->blockList[i]; if (bb->blockType == kDalvikByteCode || bb->blockType == kTraceEntryBlock) { bb->dataFlowInfo = dvmCompilerNew(sizeof(BasicBlockDataFlow), true); } } */ }
/* Setup a new SSA register for a given Dalvik register */ static void handleSSADef(CompilationUnit *cUnit, int *defs, int dalvikReg, int regIndex) { int encodedValue = cUnit->dalvikToSSAMap[dalvikReg]; int ssaReg = cUnit->numSSARegs++; /* Bump up the subscript */ int dalvikSub = DECODE_SUB(encodedValue) + 1; int newD2SMapping = ENCODE_REG_SUB(ssaReg, dalvikSub); cUnit->dalvikToSSAMap[dalvikReg] = newD2SMapping; int newS2DMapping = ENCODE_REG_SUB(dalvikReg, dalvikSub); dvmInsertGrowableList(cUnit->ssaToDalvikMap, (void *) newS2DMapping); LOG("the insert newS2DMapping is %x\n", newS2DMapping); defs[regIndex] = ssaReg; }
/* * Record the upper and lower bound information for range checks for each * induction variable. If array A is accessed by index "i+5", the upper and * lower bound will be len(A)-5 and -5, respectively. */ static void updateRangeCheckInfo(CompilationUnit *cUnit, int arrayReg, int idxReg) { InductionVariableInfo *ivInfo; LoopAnalysis *loopAnalysis = cUnit->loopAnalysis; unsigned int i, j; for (i = 0; i < loopAnalysis->ivList->numUsed; i++) { ivInfo = GET_ELEM_N(loopAnalysis->ivList, InductionVariableInfo*, i); if (ivInfo->ssaReg == idxReg) { ArrayAccessInfo *arrayAccessInfo = NULL; for (j = 0; j < loopAnalysis->arrayAccessInfo->numUsed; j++) { ArrayAccessInfo *existingArrayAccessInfo = GET_ELEM_N(loopAnalysis->arrayAccessInfo, ArrayAccessInfo*, j); if (existingArrayAccessInfo->arrayReg == arrayReg) { if (ivInfo->c > existingArrayAccessInfo->maxC) { existingArrayAccessInfo->maxC = ivInfo->c; } if (ivInfo->c < existingArrayAccessInfo->minC) { existingArrayAccessInfo->minC = ivInfo->c; } arrayAccessInfo = existingArrayAccessInfo; break; } } if (arrayAccessInfo == NULL) { arrayAccessInfo = (ArrayAccessInfo *)dvmCompilerNew(sizeof(ArrayAccessInfo), false); arrayAccessInfo->ivReg = ivInfo->basicSSAReg; arrayAccessInfo->arrayReg = arrayReg; arrayAccessInfo->maxC = (ivInfo->c > 0) ? ivInfo->c : 0; arrayAccessInfo->minC = (ivInfo->c < 0) ? ivInfo->c : 0; dvmInsertGrowableList(loopAnalysis->arrayAccessInfo, (intptr_t) arrayAccessInfo); } break; } }
/* Compute the post-order traversal of the CFG */ static void computeDomPostOrderTraversal(CompilationUnit *cUnit, BasicBlock *bb) { BitVectorIterator bvIterator; dvmBitVectorIteratorInit(bb->iDominated, &bvIterator); GrowableList *blockList = &cUnit->blockList; /* Iterate through the dominated blocks first */ while (true) { int bbIdx = dvmBitVectorIteratorNext(&bvIterator); if (bbIdx == -1) break; BasicBlock *dominatedBB = (BasicBlock *) dvmGrowableListGetElement(blockList, bbIdx); computeDomPostOrderTraversal(cUnit, dominatedBB); } /* Enter the current block id */ dvmInsertGrowableList(&cUnit->domPostOrderTraversal, bb->id); /* hacky loop detection */ if (bb->taken && dvmIsBitSet(bb->dominators, bb->taken->id)) { cUnit->hasLoop = true; } }
/* Enter the node to the dfsOrder list then visit its successors */ static void recordDFSPreOrder(CompilationUnit *cUnit, BasicBlock *block) { if (block->visited || block->hidden) return; block->visited = true; /* Enqueue the block id */ dvmInsertGrowableList(&cUnit->dfsOrder, block->id); if (block->fallThrough) recordDFSPreOrder(cUnit, block->fallThrough); if (block->taken) recordDFSPreOrder(cUnit, block->taken); if (block->successorBlockList.blockListType != kNotUsed) { GrowableListIterator iterator; dvmGrowableListIteratorInit(&block->successorBlockList.blocks, &iterator); while (true) { SuccessorBlockInfo *successorBlockInfo = (SuccessorBlockInfo *) dvmGrowableListIteratorNext(&iterator); if (successorBlockInfo == NULL) break; BasicBlock *succBB = successorBlockInfo->block; recordDFSPreOrder(cUnit, succBB); } } return; }