From cbd6d44c0a94f3d26671b5325aa21bbf1335ffe8 Mon Sep 17 00:00:00 2001 From: buzbee Date: Sat, 17 Nov 2012 14:11:25 -0800 Subject: C++'ification of Quick compiler's casts o Eliminate old useless LIR casts. o Replace remaining C-style casts with new C++ versions. o Unified instruction encoding enum o Expand usage of the auto-generated ostream helpers for enum LOG messages. o Replaced all usages of intptr_t with uintptr_t. o Fixed bug in removeRedundantBranches, and moved to common code Change-Id: I53211c0de1be913f958c8fde915296ac08345b7e --- src/compiler/codegen/local_optimizations.cc | 56 +++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 10 deletions(-) (limited to 'src/compiler/codegen/local_optimizations.cc') diff --git a/src/compiler/codegen/local_optimizations.cc b/src/compiler/codegen/local_optimizations.cc index e485f03a36..03f9463324 100644 --- a/src/compiler/codegen/local_optimizations.cc +++ b/src/compiler/codegen/local_optimizations.cc @@ -50,7 +50,7 @@ void convertMemOpIntoMove(CompilationUnit* cUnit, LIR* origLIR, int dest, * will need to be re-checked (eg the new dest clobbers the src used in * thisLIR). */ - oatInsertLIRAfter((LIR*) origLIR, (LIR*) moveLIR); + oatInsertLIRAfter(origLIR, moveLIR); } /* @@ -240,15 +240,14 @@ void applyLoadStoreElimination(CompilationUnit* cUnit, LIR* headLIR, DEBUG_OPT(dumpDependentInsnPair(thisLIR, checkLIR, "REG CLOBBERED")); /* Only sink store instructions */ if (sinkDistance && !isThisLIRLoad) { - LIR* newStoreLIR = - (LIR* ) oatNew(cUnit, sizeof(LIR), true, kAllocLIR); + LIR* newStoreLIR = static_cast(oatNew(cUnit, sizeof(LIR), true, kAllocLIR)); *newStoreLIR = *thisLIR; /* * Stop point found - insert *before* the checkLIR * since the instruction list is scanned in the * top-down order. */ - oatInsertLIRBefore((LIR*) checkLIR, (LIR*) newStoreLIR); + oatInsertLIRBefore(checkLIR, newStoreLIR); thisLIR->flags.isNop = true; } break; @@ -429,14 +428,13 @@ void applyLoadHoisting(CompilationUnit* cUnit, LIR* headLIR, LIR* tailLIR) /* Found a slot to hoist to */ if (slot >= 0) { LIR* curLIR = prevInstList[slot]; - LIR* newLoadLIR = (LIR* ) oatNew(cUnit, sizeof(LIR), - true, kAllocLIR); + LIR* newLoadLIR = static_cast(oatNew(cUnit, sizeof(LIR), true, kAllocLIR)); *newLoadLIR = *thisLIR; /* * Insertion is guaranteed to succeed since checkLIR * is never the first LIR on the list */ - oatInsertLIRBefore((LIR*) curLIR, (LIR*) newLoadLIR); + oatInsertLIRBefore(curLIR, newLoadLIR); thisLIR->flags.isNop = true; } } @@ -447,11 +445,49 @@ void oatApplyLocalOptimizations(CompilationUnit* cUnit, LIR* headLIR, LIR* tailLIR) { if (!(cUnit->disableOpt & (1 << kLoadStoreElimination))) { - applyLoadStoreElimination(cUnit, (LIR* ) headLIR, - (LIR* ) tailLIR); + applyLoadStoreElimination(cUnit, headLIR, tailLIR); } if (!(cUnit->disableOpt & (1 << kLoadHoisting))) { - applyLoadHoisting(cUnit, (LIR* ) headLIR, (LIR* ) tailLIR); + applyLoadHoisting(cUnit, headLIR, tailLIR); + } +} + +/* + * Nop any unconditional branches that go to the next instruction. + * Note: new redundant branches may be inserted later, and we'll + * use a check in final instruction assembly to nop those out. + */ +void removeRedundantBranches(CompilationUnit* cUnit) +{ + LIR* thisLIR; + + for (thisLIR = cUnit->firstLIRInsn; thisLIR != cUnit->lastLIRInsn; thisLIR = NEXT_LIR(thisLIR)) { + + /* Branch to the next instruction */ + if (branchUnconditional(thisLIR)) { + LIR* nextLIR = thisLIR; + + while (true) { + nextLIR = NEXT_LIR(nextLIR); + + /* + * Is the branch target the next instruction? + */ + if (nextLIR == thisLIR->target) { + thisLIR->flags.isNop = true; + break; + } + + /* + * Found real useful stuff between the branch and the target. + * Need to explicitly check the lastLIRInsn here because it + * might be the last real instruction. + */ + if (!isPseudoOpcode(nextLIR->opcode) || + (nextLIR == cUnit->lastLIRInsn)) + break; + } + } } } -- cgit v1.2.3-59-g8ed1b