/* * Generate a Thumb2 IT instruction, which can nullify up to * four subsequent instructions based on a condition and its * inverse. The condition applies to the first instruction, which * is executed if the condition is met. The string "guide" consists * of 0 to 3 chars, and applies to the 2nd through 4th instruction. * A "T" means the instruction is executed if the condition is * met, and an "E" means the instruction is executed if the condition * is not met. */ static ArmLIR *genIT(CompilationUnit *cUnit, ArmConditionCode code, const char *guide) { int mask; int condBit = code & 1; int altBit = condBit ^ 1; int mask3 = 0; int mask2 = 0; int mask1 = 0; //Note: case fallthroughs intentional switch(strlen(guide)) { case 3: mask1 = (guide[2] == 'T') ? condBit : altBit; case 2: mask2 = (guide[1] == 'T') ? condBit : altBit; case 1: mask3 = (guide[0] == 'T') ? condBit : altBit; break; case 0: break; default: LOGE("Jit: bad case in genIT"); dvmCompilerAbort(cUnit); } mask = (mask3 << 3) | (mask2 << 2) | (mask1 << 1) | (1 << (3 - strlen(guide))); return newLIR2(cUnit, kThumb2It, code, mask); }
static ArmLIR *opReg(CompilationUnit *cUnit, OpKind op, int rDestSrc) { ArmOpcode opcode = kThumbBkpt; switch (op) { case kOpBlx: opcode = kThumbBlxR; break; default: ALOGE("Jit: bad case in opReg"); dvmCompilerAbort(cUnit); } return newLIR1(cUnit, opcode, rDestSrc); }
static ArmLIR *opNone(CompilationUnit *cUnit, OpKind op) { ArmOpcode opcode = kThumbBkpt; switch (op) { case kOpUncondBr: opcode = kThumbBUncond; break; default: ALOGE("Jit: bad case in opNone"); dvmCompilerAbort(cUnit); } return newLIR0(cUnit, opcode); }
static ArmLIR *opImm(CompilationUnit *cUnit, OpKind op, int value) { ArmOpcode opcode = kThumbBkpt; switch (op) { case kOpPush: opcode = kThumbPush; break; case kOpPop: opcode = kThumbPop; break; default: ALOGE("Jit: bad case in opCondBranch"); dvmCompilerAbort(cUnit); } return newLIR1(cUnit, opcode, value); }
/* Handle the content in each basic block */ static bool methodBlockCodeGen(CompilationUnit *cUnit, BasicBlock *bb) { MIR *mir; ArmLIR *labelList = (ArmLIR *) cUnit->blockLabelList; int blockId = bb->id; cUnit->curBlock = bb; labelList[blockId].operands[0] = bb->startOffset; /* Insert the block label */ labelList[blockId].opcode = kArmPseudoNormalBlockLabel; dvmCompilerAppendLIR(cUnit, (LIR *) &labelList[blockId]); dvmCompilerClobberAllRegs(cUnit); dvmCompilerResetNullCheck(cUnit); ArmLIR *headLIR = NULL; if (bb->blockType == kEntryBlock) { /* r0 = callsitePC */ opImm(cUnit, kOpPush, (1 << r0 | 1 << r1 | 1 << r5FP | 1 << r14lr)); opRegImm(cUnit, kOpSub, r5FP, sizeof(StackSaveArea) + cUnit->method->registersSize * 4); } else if (bb->blockType == kExitBlock) { /* No need to pop r0 and r1 */ opRegImm(cUnit, kOpAdd, r13sp, 8); opImm(cUnit, kOpPop, (1 << r5FP | 1 << r15pc)); } for (mir = bb->firstMIRInsn; mir; mir = mir->next) { dvmCompilerResetRegPool(cUnit); if (gDvmJit.disableOpt & (1 << kTrackLiveTemps)) { dvmCompilerClobberAllRegs(cUnit); } if (gDvmJit.disableOpt & (1 << kSuppressLoads)) { dvmCompilerResetDefTracking(cUnit); } Opcode dalvikOpcode = mir->dalvikInsn.opcode; InstructionFormat dalvikFormat = dexGetFormatFromOpcode(dalvikOpcode); ArmLIR *boundaryLIR; /* * Don't generate the boundary LIR unless we are debugging this * trace or we need a scheduling barrier. */ if (headLIR == NULL || cUnit->printMe == true) { boundaryLIR = newLIR2(cUnit, kArmPseudoDalvikByteCodeBoundary, mir->offset, (int) dvmCompilerGetDalvikDisassembly( &mir->dalvikInsn, "")); /* Remember the first LIR for this block */ if (headLIR == NULL) { headLIR = boundaryLIR; /* Set the first boundaryLIR as a scheduling barrier */ headLIR->defMask = ENCODE_ALL; } } /* Don't generate the SSA annotation unless verbose mode is on */ if (cUnit->printMe && mir->ssaRep) { char *ssaString = dvmCompilerGetSSAString(cUnit, mir->ssaRep); newLIR1(cUnit, kArmPseudoSSARep, (int) ssaString); } bool notHandled; switch (dalvikFormat) { case kFmt10t: case kFmt20t: case kFmt30t: notHandled = handleMethodFmt10t_Fmt20t_Fmt30t(cUnit, mir, bb, labelList); break; case kFmt10x: notHandled = handleMethodFmt10x(cUnit, mir); break; case kFmt11n: case kFmt31i: notHandled = handleMethodFmt11n_Fmt31i(cUnit, mir); break; case kFmt11x: notHandled = handleMethodFmt11x(cUnit, mir, bb, labelList); break; case kFmt12x: notHandled = handleMethodFmt12x(cUnit, mir); break; case kFmt20bc: notHandled = handleMethodFmt20bc(cUnit, mir); break; case kFmt21c: case kFmt31c: notHandled = handleMethodFmt21c_Fmt31c(cUnit, mir); break; case kFmt21h: notHandled = handleMethodFmt21h(cUnit, mir); break; case kFmt21s: notHandled = handleMethodFmt21s(cUnit, mir); break; case kFmt21t: notHandled = handleMethodFmt21t(cUnit, mir, bb, labelList); break; case kFmt22b: case kFmt22s: notHandled = handleMethodFmt22b_Fmt22s(cUnit, mir); break; case kFmt22c: notHandled = handleMethodFmt22c(cUnit, mir); break; case kFmt22cs: notHandled = handleMethodFmt22cs(cUnit, mir); break; case kFmt22t: notHandled = handleMethodFmt22t(cUnit, mir, bb, labelList); break; case kFmt22x: case kFmt32x: notHandled = handleMethodFmt22x_Fmt32x(cUnit, mir); break; case kFmt23x: notHandled = handleMethodFmt23x(cUnit, mir); break; case kFmt31t: notHandled = handleMethodFmt31t(cUnit, mir); break; case kFmt3rc: case kFmt35c: notHandled = handleMethodFmt35c_3rc(cUnit, mir, bb, labelList); break; case kFmt3rms: case kFmt35ms: notHandled = handleMethodFmt35ms_3rms(cUnit, mir, bb, labelList); break; case kFmt35mi: case kFmt3rmi: notHandled = handleMethodExecuteInline(cUnit, mir); break; case kFmt51l: notHandled = handleMethodFmt51l(cUnit, mir); break; default: notHandled = true; break; } /* FIXME - to be implemented */ if (notHandled == true && dalvikOpcode >= kNumPackedOpcodes) { notHandled = false; } if (notHandled) { ALOGE("%#06x: Opcode %#x (%s) / Fmt %d not handled", mir->offset, dalvikOpcode, dexGetOpcodeName(dalvikOpcode), dalvikFormat); dvmCompilerAbort(cUnit); break; } } if (headLIR) { /* * Eliminate redundant loads/stores and delay stores into later * slots */ dvmCompilerApplyLocalOptimizations(cUnit, (LIR *) headLIR, cUnit->lastLIRInsn); /* * Generate an unconditional branch to the fallthrough block. */ if (bb->fallThrough) { genUnconditionalBranch(cUnit, &labelList[bb->fallThrough->id]); } } return false; }