mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-14 16:33:28 +00:00
Handle last value assignments.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41063 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ebcb52aa89
commit
ada054a9ea
@ -419,8 +419,8 @@ bool LoopIndexSplit::processOneIterationLoop(SplitInfo &SD) {
|
|||||||
}
|
}
|
||||||
BR->setUnconditionalDest(LatchSucc);
|
BR->setUnconditionalDest(LatchSucc);
|
||||||
|
|
||||||
BasicBlock *Preheader = L->getLoopPreheader();
|
|
||||||
Instruction *Terminator = Header->getTerminator();
|
Instruction *Terminator = Header->getTerminator();
|
||||||
|
Value *ExitValue = ExitCondition->getOperand(ExitValueNum);
|
||||||
|
|
||||||
// Replace split condition in header.
|
// Replace split condition in header.
|
||||||
// Transform
|
// Transform
|
||||||
@ -436,8 +436,7 @@ bool LoopIndexSplit::processOneIterationLoop(SplitInfo &SD) {
|
|||||||
Terminator);
|
Terminator);
|
||||||
Instruction *C2 = new ICmpInst(SignedPredicate ?
|
Instruction *C2 = new ICmpInst(SignedPredicate ?
|
||||||
ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
|
ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
|
||||||
SD.SplitValue,
|
SD.SplitValue, ExitValue, "lisplit",
|
||||||
ExitCondition->getOperand(ExitValueNum), "lisplit",
|
|
||||||
Terminator);
|
Terminator);
|
||||||
Instruction *NSplitCond = BinaryOperator::createAnd(C1, C2, "lisplit",
|
Instruction *NSplitCond = BinaryOperator::createAnd(C1, C2, "lisplit",
|
||||||
Terminator);
|
Terminator);
|
||||||
@ -454,7 +453,10 @@ bool LoopIndexSplit::processOneIterationLoop(SplitInfo &SD) {
|
|||||||
if (isa<PHINode>(I) || I == LTerminator)
|
if (isa<PHINode>(I) || I == LTerminator)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
I->replaceAllUsesWith(UndefValue::get(I->getType()));
|
if (I == IndVarIncrement)
|
||||||
|
I->replaceAllUsesWith(ExitValue);
|
||||||
|
else
|
||||||
|
I->replaceAllUsesWith(UndefValue::get(I->getType()));
|
||||||
I->eraseFromParent();
|
I->eraseFromParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -485,7 +487,7 @@ bool LoopIndexSplit::safeHeader(SplitInfo &SD, BasicBlock *Header) {
|
|||||||
BI != BE; ++BI) {
|
BI != BE; ++BI) {
|
||||||
Instruction *I = BI;
|
Instruction *I = BI;
|
||||||
|
|
||||||
// PHI Nodes are OK. FIXME : Handle last value assignments.
|
// PHI Nodes are OK.
|
||||||
if (isa<PHINode>(I))
|
if (isa<PHINode>(I))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -520,7 +522,7 @@ bool LoopIndexSplit::safeExitBlock(SplitInfo &SD, BasicBlock *ExitBlock) {
|
|||||||
BI != BE; ++BI) {
|
BI != BE; ++BI) {
|
||||||
Instruction *I = BI;
|
Instruction *I = BI;
|
||||||
|
|
||||||
// PHI Nodes are OK. FIXME : Handle last value assignments.
|
// PHI Nodes are OK.
|
||||||
if (isa<PHINode>(I))
|
if (isa<PHINode>(I))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -686,23 +688,49 @@ bool LoopIndexSplit::splitLoop(SplitInfo &SD) {
|
|||||||
assert (ExitInsn && "Unable to find suitable loop exit branch");
|
assert (ExitInsn && "Unable to find suitable loop exit branch");
|
||||||
BasicBlock *ExitDest = ExitInsn->getSuccessor(1);
|
BasicBlock *ExitDest = ExitInsn->getSuccessor(1);
|
||||||
|
|
||||||
|
if (L->contains(ExitDest)) {
|
||||||
|
ExitDest = ExitInsn->getSuccessor(0);
|
||||||
|
ExitInsn->setSuccessor(0, FalseHeader);
|
||||||
|
} else
|
||||||
|
ExitInsn->setSuccessor(1, FalseHeader);
|
||||||
|
|
||||||
|
// Collect inverse map of Header PHINodes.
|
||||||
|
DenseMap<Value *, Value *> InverseMap;
|
||||||
|
for (BasicBlock::iterator BI = L->getHeader()->begin(),
|
||||||
|
BE = L->getHeader()->end(); BI != BE; ++BI) {
|
||||||
|
if (PHINode *PN = dyn_cast<PHINode>(BI)) {
|
||||||
|
PHINode *PNClone = cast<PHINode>(ValueMap[PN]);
|
||||||
|
InverseMap[PNClone] = PN;
|
||||||
|
} else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update False loop's header
|
||||||
for (BasicBlock::iterator BI = FalseHeader->begin(), BE = FalseHeader->end();
|
for (BasicBlock::iterator BI = FalseHeader->begin(), BE = FalseHeader->end();
|
||||||
BI != BE; ++BI) {
|
BI != BE; ++BI) {
|
||||||
if (PHINode *PN = dyn_cast<PHINode>(BI)) {
|
if (PHINode *PN = dyn_cast<PHINode>(BI)) {
|
||||||
PN->removeIncomingValue(Preheader);
|
PN->removeIncomingValue(Preheader);
|
||||||
if (PN == IndVarClone)
|
if (PN == IndVarClone)
|
||||||
PN->addIncoming(FLStartValue, ExitBlock);
|
PN->addIncoming(FLStartValue, ExitBlock);
|
||||||
// else { FIXME : Handl last value assignments.}
|
else {
|
||||||
}
|
PHINode *OrigPN = cast<PHINode>(InverseMap[PN]);
|
||||||
else
|
Value *V2 = OrigPN->getIncomingValueForBlock(ExitBlock);
|
||||||
|
PN->addIncoming(V2, ExitBlock);
|
||||||
|
}
|
||||||
|
} else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (L->contains(ExitDest)) {
|
// Update ExitDest. Now it's predecessor is False loop's exit block.
|
||||||
ExitDest = ExitInsn->getSuccessor(0);
|
BasicBlock *ExitBlockClone = cast<BasicBlock>(ValueMap[ExitBlock]);
|
||||||
ExitInsn->setSuccessor(0, FalseHeader);
|
for (BasicBlock::iterator BI = ExitDest->begin(), BE = ExitDest->end();
|
||||||
} else
|
BI != BE; ++BI) {
|
||||||
ExitInsn->setSuccessor(1, FalseHeader);
|
if (PHINode *PN = dyn_cast<PHINode>(BI)) {
|
||||||
|
PN->addIncoming(ValueMap[PN->getIncomingValueForBlock(ExitBlock)], ExitBlockClone);
|
||||||
|
PN->removeIncomingValue(ExitBlock);
|
||||||
|
} else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (DT) {
|
if (DT) {
|
||||||
DT->changeImmediateDominator(FalseHeader, ExitBlock);
|
DT->changeImmediateDominator(FalseHeader, ExitBlock);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user