mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-04 07:32:13 +00:00
Rename bunch of variables.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41250 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
60cbab4252
commit
0b8e02b704
@ -705,89 +705,94 @@ void LoopIndexSplit::removeBlocks(BasicBlock *DeadBB, Loop *LP,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// splitLoop - Split current loop L in two loops using split information
|
||||||
|
/// SD. Update dominator information. Maintain LCSSA form.
|
||||||
bool LoopIndexSplit::splitLoop(SplitInfo &SD) {
|
bool LoopIndexSplit::splitLoop(SplitInfo &SD) {
|
||||||
|
|
||||||
BasicBlock *Preheader = L->getLoopPreheader();
|
// True loop is original loop. False loop is cloned loop.
|
||||||
BasicBlock *SplitBlock = SD.SplitCondition->getParent();
|
|
||||||
BasicBlock *Latch = L->getLoopLatch();
|
BasicBlock *TL_Preheader = L->getLoopPreheader();
|
||||||
BasicBlock *Header = L->getHeader();
|
BasicBlock *TL_SplitCondBlock = SD.SplitCondition->getParent();
|
||||||
BranchInst *SplitTerminator = cast<BranchInst>(SplitBlock->getTerminator());
|
BasicBlock *TL_Latch = L->getLoopLatch();
|
||||||
|
BasicBlock *TL_Header = L->getHeader();
|
||||||
|
BranchInst *TL_SplitTerminator =
|
||||||
|
cast<BranchInst>(TL_SplitCondBlock->getTerminator());
|
||||||
|
|
||||||
// FIXME - Unable to handle triange loops at the moment.
|
// FIXME - Unable to handle triange loops at the moment.
|
||||||
// In triangle loop, split condition is in header and one of the
|
// In triangle loop, split condition is in header and one of the
|
||||||
// the split destination is loop latch. If split condition is EQ
|
// the split destination is loop latch. If split condition is EQ
|
||||||
// then such loops are already handle in processOneIterationLoop().
|
// then such loops are already handle in processOneIterationLoop().
|
||||||
if (Header == SplitBlock
|
BasicBlock *Succ0 = TL_SplitTerminator->getSuccessor(0);
|
||||||
&& (Latch == SplitTerminator->getSuccessor(0)
|
BasicBlock *Succ1 = TL_SplitTerminator->getSuccessor(1);
|
||||||
|| Latch == SplitTerminator->getSuccessor(1)))
|
if (TL_Header == TL_SplitCondBlock
|
||||||
|
&& (TL_Latch == Succ0 || TL_Latch == Succ1))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// If one of the split condition branch is post dominating other then loop
|
// If one of the split condition branch is post dominating other then loop
|
||||||
// index split is not appropriate.
|
// index split is not appropriate.
|
||||||
BasicBlock *Succ0 = SplitTerminator->getSuccessor(0);
|
if (DT->dominates(Succ0, TL_Latch) || DT->dominates(Succ1, TL_Latch))
|
||||||
BasicBlock *Succ1 = SplitTerminator->getSuccessor(1);
|
|
||||||
if (DT->dominates(Succ0, Latch) || DT->dominates(Succ1, Latch))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// If one of the split condition branch is a predecessor of the other
|
// If one of the split condition branch is a predecessor of the other
|
||||||
// split condition branch head then do not split loop on this condition.
|
// split condition branch head then do not split loop on this condition.
|
||||||
for(pred_iterator PI = pred_begin(Succ0), PE = pred_end(Succ0); PI != PE; ++PI)
|
for(pred_iterator PI = pred_begin(Succ0), PE = pred_end(Succ0);
|
||||||
|
PI != PE; ++PI)
|
||||||
if (Succ1 == *PI)
|
if (Succ1 == *PI)
|
||||||
return false;
|
return false;
|
||||||
for(pred_iterator PI = pred_begin(Succ1), PE = pred_end(Succ1); PI != PE; ++PI)
|
for(pred_iterator PI = pred_begin(Succ1), PE = pred_end(Succ1);
|
||||||
|
PI != PE; ++PI)
|
||||||
if (Succ0 == *PI)
|
if (Succ0 == *PI)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// True loop is original loop. False loop is cloned loop.
|
|
||||||
|
|
||||||
bool SignedPredicate = ExitCondition->isSignedPredicate();
|
bool SignedPredicate = ExitCondition->isSignedPredicate();
|
||||||
//[*] Calculate True loop's new Exit Value in loop preheader.
|
//[*] Calculate True loop's new Exit Value in loop preheader.
|
||||||
// TLExitValue = min(SplitValue, ExitValue)
|
// TL_ExitValue = min(SplitValue, ExitValue)
|
||||||
//[*] Calculate False loop's new Start Value in loop preheader.
|
//[*] Calculate False loop's new Start Value in loop preheader.
|
||||||
// FLStartValue = min(SplitValue, TrueLoop.StartValue)
|
// FL_StartValue = min(SplitValue, TrueLoop.StartValue)
|
||||||
Value *TLExitValue = NULL;
|
Value *TL_ExitValue = NULL;
|
||||||
Value *FLStartValue = NULL;
|
Value *FL_StartValue = NULL;
|
||||||
if (isa<ConstantInt>(SD.SplitValue)) {
|
if (isa<ConstantInt>(SD.SplitValue)) {
|
||||||
TLExitValue = SD.SplitValue;
|
TL_ExitValue = SD.SplitValue;
|
||||||
FLStartValue = SD.SplitValue;
|
FL_StartValue = SD.SplitValue;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Instruction *TL_PHTerminator = TL_Preheader->getTerminator();
|
||||||
Value *C1 = new ICmpInst(SignedPredicate ?
|
Value *C1 = new ICmpInst(SignedPredicate ?
|
||||||
ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
|
ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
|
||||||
SD.SplitValue,
|
SD.SplitValue,
|
||||||
ExitCondition->getOperand(ExitValueNum),
|
ExitCondition->getOperand(ExitValueNum),
|
||||||
"lsplit.ev",
|
"lsplit.ev", TL_PHTerminator);
|
||||||
Preheader->getTerminator());
|
TL_ExitValue = new SelectInst(C1, SD.SplitValue,
|
||||||
TLExitValue = new SelectInst(C1, SD.SplitValue,
|
|
||||||
ExitCondition->getOperand(ExitValueNum),
|
ExitCondition->getOperand(ExitValueNum),
|
||||||
"lsplit.ev", Preheader->getTerminator());
|
"lsplit.ev", TL_PHTerminator);
|
||||||
|
|
||||||
Value *C2 = new ICmpInst(SignedPredicate ?
|
Value *C2 = new ICmpInst(SignedPredicate ?
|
||||||
ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
|
ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
|
||||||
SD.SplitValue, StartValue, "lsplit.sv",
|
SD.SplitValue, StartValue, "lsplit.sv",
|
||||||
Preheader->getTerminator());
|
TL_PHTerminator);
|
||||||
FLStartValue = new SelectInst(C2, SD.SplitValue, StartValue,
|
FL_StartValue = new SelectInst(C2, SD.SplitValue, StartValue,
|
||||||
"lsplit.sv", Preheader->getTerminator());
|
"lsplit.sv", TL_Preheader->getTerminator());
|
||||||
}
|
}
|
||||||
|
|
||||||
//[*] Clone loop. Avoid true destination of split condition and
|
//[*] Clone loop. Avoid true destination of split condition and
|
||||||
// the blocks dominated by true destination.
|
// the blocks dominated by true destination.
|
||||||
DenseMap<const Value *, Value *> ValueMap;
|
DenseMap<const Value *, Value *> ValueMap;
|
||||||
Loop *FalseLoop = CloneLoop(L, LPM, LI, ValueMap, this);
|
Loop *FalseLoop = CloneLoop(L, LPM, LI, ValueMap, this);
|
||||||
BasicBlock *FalseHeader = FalseLoop->getHeader();
|
BasicBlock *FL_Header = FalseLoop->getHeader();
|
||||||
|
|
||||||
//[*] True loop's exit edge enters False loop.
|
//[*] True loop's exit edge enters False loop.
|
||||||
PHINode *IndVarClone = cast<PHINode>(ValueMap[IndVar]);
|
PHINode *FL_IndVar = cast<PHINode>(ValueMap[IndVar]);
|
||||||
BasicBlock *ExitingBlock = ExitCondition->getParent();
|
BasicBlock *TL_ExitingBlock = ExitCondition->getParent();
|
||||||
BranchInst *ExitInsn = dyn_cast<BranchInst>(ExitingBlock->getTerminator());
|
BranchInst *TL_ExitInsn =
|
||||||
assert (ExitInsn && "Unable to find suitable loop exit branch");
|
dyn_cast<BranchInst>(TL_ExitingBlock->getTerminator());
|
||||||
BasicBlock *ExitDest = ExitInsn->getSuccessor(1);
|
assert (TL_ExitInsn && "Unable to find suitable loop exit branch");
|
||||||
|
BasicBlock *TL_ExitDest = TL_ExitInsn->getSuccessor(1);
|
||||||
|
|
||||||
if (L->contains(ExitDest)) {
|
if (L->contains(TL_ExitDest)) {
|
||||||
ExitDest = ExitInsn->getSuccessor(0);
|
TL_ExitDest = TL_ExitInsn->getSuccessor(0);
|
||||||
ExitInsn->setSuccessor(0, FalseHeader);
|
TL_ExitInsn->setSuccessor(0, FL_Header);
|
||||||
} else
|
} else
|
||||||
ExitInsn->setSuccessor(1, FalseHeader);
|
TL_ExitInsn->setSuccessor(1, FL_Header);
|
||||||
|
|
||||||
// Collect inverse map of Header PHINodes.
|
// Collect inverse map of Header PHINodes.
|
||||||
DenseMap<Value *, Value *> InverseMap;
|
DenseMap<Value *, Value *> InverseMap;
|
||||||
@ -801,65 +806,68 @@ bool LoopIndexSplit::splitLoop(SplitInfo &SD) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update False loop's header
|
// Update False loop's header
|
||||||
for (BasicBlock::iterator BI = FalseHeader->begin(), BE = FalseHeader->end();
|
for (BasicBlock::iterator BI = FL_Header->begin(), BE = FL_Header->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(TL_Preheader);
|
||||||
if (PN == IndVarClone)
|
if (PN == FL_IndVar)
|
||||||
PN->addIncoming(FLStartValue, ExitingBlock);
|
PN->addIncoming(FL_StartValue, TL_ExitingBlock);
|
||||||
else {
|
else {
|
||||||
PHINode *OrigPN = cast<PHINode>(InverseMap[PN]);
|
PHINode *OrigPN = cast<PHINode>(InverseMap[PN]);
|
||||||
Value *V2 = OrigPN->getIncomingValueForBlock(ExitingBlock);
|
Value *V2 = OrigPN->getIncomingValueForBlock(TL_ExitingBlock);
|
||||||
PN->addIncoming(V2, ExitingBlock);
|
PN->addIncoming(V2, TL_ExitingBlock);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update ExitDest. Now it's predecessor is False loop's exit block.
|
// Update TL_ExitDest. Now it's predecessor is False loop's exit block.
|
||||||
BasicBlock *ExitingBlockClone = cast<BasicBlock>(ValueMap[ExitingBlock]);
|
BasicBlock *FL_ExitingBlock = cast<BasicBlock>(ValueMap[TL_ExitingBlock]);
|
||||||
for (BasicBlock::iterator BI = ExitDest->begin(), BE = ExitDest->end();
|
for (BasicBlock::iterator BI = TL_ExitDest->begin(), BE = TL_ExitDest->end();
|
||||||
BI != BE; ++BI) {
|
BI != BE; ++BI) {
|
||||||
if (PHINode *PN = dyn_cast<PHINode>(BI)) {
|
if (PHINode *PN = dyn_cast<PHINode>(BI)) {
|
||||||
PN->addIncoming(ValueMap[PN->getIncomingValueForBlock(ExitingBlock)], ExitingBlockClone);
|
PN->addIncoming(ValueMap[PN->getIncomingValueForBlock(TL_ExitingBlock)],
|
||||||
PN->removeIncomingValue(ExitingBlock);
|
FL_ExitingBlock);
|
||||||
|
PN->removeIncomingValue(TL_ExitingBlock);
|
||||||
} else
|
} else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DT) {
|
if (DT) {
|
||||||
DT->changeImmediateDominator(FalseHeader, ExitingBlock);
|
DT->changeImmediateDominator(FL_Header, TL_ExitingBlock);
|
||||||
DT->changeImmediateDominator(ExitDest, cast<BasicBlock>(ValueMap[ExitingBlock]));
|
DT->changeImmediateDominator(TL_ExitDest,
|
||||||
|
cast<BasicBlock>(ValueMap[TL_ExitingBlock]));
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (!L->contains(ExitDest) && " Unable to find exit edge destination");
|
assert (!L->contains(TL_ExitDest) && " Unable to find exit edge destination");
|
||||||
|
|
||||||
//[*] Split Exit Edge.
|
//[*] Split Exit Edge.
|
||||||
BasicBlock *TL_ExitBlock = SplitEdge(ExitingBlock, FalseHeader, this);
|
BasicBlock *TL_ExitBlock = SplitEdge(TL_ExitingBlock, FL_Header, this);
|
||||||
|
|
||||||
//[*] Eliminate split condition's false branch from True loop.
|
//[*] Eliminate split condition's false branch from True loop.
|
||||||
BranchInst *BR = cast<BranchInst>(SplitBlock->getTerminator());
|
BranchInst *TL_BR = cast<BranchInst>(TL_SplitCondBlock->getTerminator());
|
||||||
BasicBlock *FBB = BR->getSuccessor(1);
|
BasicBlock *TL_FalseBlock = TL_BR->getSuccessor(1);
|
||||||
BR->setUnconditionalDest(BR->getSuccessor(0));
|
TL_BR->setUnconditionalDest(TL_BR->getSuccessor(0));
|
||||||
removeBlocks(FBB, L, BR->getSuccessor(0));
|
removeBlocks(TL_FalseBlock, L, TL_BR->getSuccessor(0));
|
||||||
|
|
||||||
//[*] Update True loop's exit value using new exit value.
|
//[*] Update True loop's exit value using new exit value.
|
||||||
ExitCondition->setOperand(ExitValueNum, TLExitValue);
|
ExitCondition->setOperand(ExitValueNum, TL_ExitValue);
|
||||||
|
|
||||||
//[*] Eliminate split condition's true branch in False loop CFG.
|
//[*] Eliminate split condition's true branch in False loop CFG.
|
||||||
BasicBlock *FSplitBlock = cast<BasicBlock>(ValueMap[SplitBlock]);
|
BasicBlock *FL_SplitCondBlock = cast<BasicBlock>(ValueMap[TL_SplitCondBlock]);
|
||||||
BranchInst *FBR = cast<BranchInst>(FSplitBlock->getTerminator());
|
BranchInst *FL_BR = cast<BranchInst>(FL_SplitCondBlock->getTerminator());
|
||||||
BasicBlock *TBB = FBR->getSuccessor(0);
|
BasicBlock *FL_TrueBlock = FL_BR->getSuccessor(0);
|
||||||
FBR->setUnconditionalDest(FBR->getSuccessor(1));
|
FL_BR->setUnconditionalDest(FL_BR->getSuccessor(1));
|
||||||
removeBlocks(TBB, FalseLoop, cast<BasicBlock>(FBR->getSuccessor(0)));
|
removeBlocks(FL_TrueBlock, FalseLoop,
|
||||||
|
cast<BasicBlock>(FL_BR->getSuccessor(0)));
|
||||||
|
|
||||||
//[*] Preserve LCSSA
|
//[*] Preserve LCSSA
|
||||||
for(BasicBlock::iterator BI = FalseHeader->begin(), BE = FalseHeader->end();
|
for(BasicBlock::iterator BI = FL_Header->begin(), BE = FL_Header->end();
|
||||||
BI != BE; ++BI) {
|
BI != BE; ++BI) {
|
||||||
if (PHINode *PN = dyn_cast<PHINode>(BI)) {
|
if (PHINode *PN = dyn_cast<PHINode>(BI)) {
|
||||||
Value *V1 = PN->getIncomingValueForBlock(TL_ExitBlock);
|
Value *V1 = PN->getIncomingValueForBlock(TL_ExitBlock);
|
||||||
PHINode *newPHI = new PHINode(PN->getType(), PN->getName());
|
PHINode *newPHI = new PHINode(PN->getType(), PN->getName());
|
||||||
newPHI->addIncoming(V1, ExitingBlock);
|
newPHI->addIncoming(V1, TL_ExitingBlock);
|
||||||
TL_ExitBlock->getInstList().push_front(newPHI);
|
TL_ExitBlock->getInstList().push_front(newPHI);
|
||||||
PN->removeIncomingValue(TL_ExitBlock);
|
PN->removeIncomingValue(TL_ExitBlock);
|
||||||
PN->addIncoming(newPHI, TL_ExitBlock);
|
PN->addIncoming(newPHI, TL_ExitBlock);
|
||||||
@ -869,4 +877,3 @@ bool LoopIndexSplit::splitLoop(SplitInfo &SD) {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user