mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-31 10:34:17 +00:00
Remove the wierd "Operands" loop, by traversing basicblocks in reverse order
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10536 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
86f3dda18b
commit
a3df8a964a
@ -304,16 +304,18 @@ void LICM::SinkRegion(DominatorTree::Node *N) {
|
|||||||
// subloop (which would already have been processed).
|
// subloop (which would already have been processed).
|
||||||
if (inSubLoop(BB)) return;
|
if (inSubLoop(BB)) return;
|
||||||
|
|
||||||
for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E; ) {
|
for (BasicBlock::iterator II = BB->end(); II != BB->begin(); ) {
|
||||||
Instruction &I = *II++;
|
Instruction &I = *--II;
|
||||||
|
|
||||||
// Check to see if we can sink this instruction to the exit blocks
|
// Check to see if we can sink this instruction to the exit blocks
|
||||||
// of the loop. We can do this if the all users of the instruction are
|
// of the loop. We can do this if the all users of the instruction are
|
||||||
// outside of the loop. In this case, it doesn't even matter if the
|
// outside of the loop. In this case, it doesn't even matter if the
|
||||||
// operands of the instruction are loop invariant.
|
// operands of the instruction are loop invariant.
|
||||||
//
|
//
|
||||||
if (canSinkOrHoistInst(I) && isNotUsedInLoop(I))
|
if (canSinkOrHoistInst(I) && isNotUsedInLoop(I)) {
|
||||||
|
++II;
|
||||||
sink(I);
|
sink(I);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,14 +405,14 @@ bool LICM::isLoopInvariantInst(Instruction &I) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// sink - When an instruction is found to only be used outside of the loop,
|
/// sink - When an instruction is found to only be used outside of the loop,
|
||||||
/// this function moves it to the exit blocks and patches up SSA form as
|
/// this function moves it to the exit blocks and patches up SSA form as needed.
|
||||||
/// needed.
|
/// This method is guaranteed to remove the original instruction from its
|
||||||
|
/// position, and may either delete it or move it to outside of the loop.
|
||||||
///
|
///
|
||||||
void LICM::sink(Instruction &I) {
|
void LICM::sink(Instruction &I) {
|
||||||
DEBUG(std::cerr << "LICM sinking instruction: " << I);
|
DEBUG(std::cerr << "LICM sinking instruction: " << I);
|
||||||
|
|
||||||
const std::vector<BasicBlock*> &ExitBlocks = CurLoop->getExitBlocks();
|
const std::vector<BasicBlock*> &ExitBlocks = CurLoop->getExitBlocks();
|
||||||
std::vector<Value*> Operands(I.op_begin(), I.op_end());
|
|
||||||
|
|
||||||
if (isa<LoadInst>(I)) ++NumMovedLoads;
|
if (isa<LoadInst>(I)) ++NumMovedLoads;
|
||||||
++NumSunk;
|
++NumSunk;
|
||||||
@ -512,20 +514,18 @@ void LICM::sink(Instruction &I) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the instruction doesn't dominate any exit blocks, it must be dead.
|
||||||
|
if (InsertedBlocks.empty()) {
|
||||||
|
CurAST->remove(&I);
|
||||||
|
I.getParent()->getInstList().erase(&I);
|
||||||
|
}
|
||||||
|
|
||||||
// Finally, promote the fine value to SSA form.
|
// Finally, promote the fine value to SSA form.
|
||||||
std::vector<AllocaInst*> Allocas;
|
std::vector<AllocaInst*> Allocas;
|
||||||
Allocas.push_back(AI);
|
Allocas.push_back(AI);
|
||||||
PromoteMemToReg(Allocas, *DT, *DF, AA->getTargetData());
|
PromoteMemToReg(Allocas, *DT, *DF, AA->getTargetData());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since we just sunk an instruction, check to see if any other instructions
|
|
||||||
// used by this instruction are now sinkable. If so, sink them too.
|
|
||||||
for (unsigned i = 0, e = Operands.size(); i != e; ++i)
|
|
||||||
if (Instruction *OpI = dyn_cast<Instruction>(Operands[i]))
|
|
||||||
if (CurLoop->contains(OpI->getParent()) && canSinkOrHoistInst(*OpI) &&
|
|
||||||
isNotUsedInLoop(*OpI) && isSafeToExecuteUnconditionally(*OpI))
|
|
||||||
sink(*OpI);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// hoist - When an instruction is found to only use loop invariant operands
|
/// hoist - When an instruction is found to only use loop invariant operands
|
||||||
|
Loading…
x
Reference in New Issue
Block a user