mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-22 19:38:40 +00:00
generalize the fix for PR977 to also fix
Transforms/LCSSA/2006-10-31-UnreachableBlock-2.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31317 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
237f0de7d5
commit
cbea67f55b
@ -71,8 +71,8 @@ namespace {
|
|||||||
private:
|
private:
|
||||||
SetVector<Instruction*> getLoopValuesUsedOutsideLoop(Loop *L);
|
SetVector<Instruction*> getLoopValuesUsedOutsideLoop(Loop *L);
|
||||||
|
|
||||||
PHINode *GetValueForBlock(DominatorTree::Node *BB, Instruction *OrigInst,
|
Value *GetValueForBlock(DominatorTree::Node *BB, Instruction *OrigInst,
|
||||||
std::map<DominatorTree::Node*, PHINode*> &Phis);
|
std::map<DominatorTree::Node*, Value*> &Phis);
|
||||||
|
|
||||||
/// inLoop - returns true if the given block is within the current loop
|
/// inLoop - returns true if the given block is within the current loop
|
||||||
const bool inLoop(BasicBlock* B) {
|
const bool inLoop(BasicBlock* B) {
|
||||||
@ -140,7 +140,7 @@ void LCSSA::ProcessInstruction(Instruction *Instr,
|
|||||||
++NumLCSSA; // We are applying the transformation
|
++NumLCSSA; // We are applying the transformation
|
||||||
|
|
||||||
// Keep track of the blocks that have the value available already.
|
// Keep track of the blocks that have the value available already.
|
||||||
std::map<DominatorTree::Node*, PHINode*> Phis;
|
std::map<DominatorTree::Node*, Value*> Phis;
|
||||||
|
|
||||||
DominatorTree::Node *InstrNode = DT->getNode(Instr->getParent());
|
DominatorTree::Node *InstrNode = DT->getNode(Instr->getParent());
|
||||||
|
|
||||||
@ -150,18 +150,18 @@ void LCSSA::ProcessInstruction(Instruction *Instr,
|
|||||||
BBE = exitBlocks.end(); BBI != BBE; ++BBI) {
|
BBE = exitBlocks.end(); BBI != BBE; ++BBI) {
|
||||||
BasicBlock *BB = *BBI;
|
BasicBlock *BB = *BBI;
|
||||||
DominatorTree::Node *ExitBBNode = DT->getNode(BB);
|
DominatorTree::Node *ExitBBNode = DT->getNode(BB);
|
||||||
PHINode *&Phi = Phis[ExitBBNode];
|
Value *&Phi = Phis[ExitBBNode];
|
||||||
if (!Phi && InstrNode->dominates(ExitBBNode)) {
|
if (!Phi && InstrNode->dominates(ExitBBNode)) {
|
||||||
Phi = new PHINode(Instr->getType(), Instr->getName()+".lcssa",
|
PHINode *PN = new PHINode(Instr->getType(), Instr->getName()+".lcssa",
|
||||||
BB->begin());
|
BB->begin());
|
||||||
Phi->reserveOperandSpace(std::distance(pred_begin(BB), pred_end(BB)));
|
PN->reserveOperandSpace(std::distance(pred_begin(BB), pred_end(BB)));
|
||||||
|
|
||||||
|
// Remember that this phi makes the value alive in this block.
|
||||||
|
Phi = PN;
|
||||||
|
|
||||||
// Add inputs from inside the loop for this PHI.
|
// Add inputs from inside the loop for this PHI.
|
||||||
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
|
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
|
||||||
Phi->addIncoming(Instr, *PI);
|
PN->addIncoming(Instr, *PI);
|
||||||
|
|
||||||
// Remember that this phi makes the value alive in this block.
|
|
||||||
Phis[ExitBBNode] = Phi;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,14 +184,7 @@ void LCSSA::ProcessInstruction(Instruction *Instr,
|
|||||||
|
|
||||||
// Otherwise, patch up uses of the value with the appropriate LCSSA Phi,
|
// Otherwise, patch up uses of the value with the appropriate LCSSA Phi,
|
||||||
// inserting PHI nodes into join points where needed.
|
// inserting PHI nodes into join points where needed.
|
||||||
DominatorTree::Node *UserBBNode = DT->getNode(UserBB);
|
Value *Val = GetValueForBlock(DT->getNode(UserBB), Instr, Phis);
|
||||||
|
|
||||||
// If the block has no dominator info, it is unreachable.
|
|
||||||
Value *Val;
|
|
||||||
if (UserBBNode)
|
|
||||||
Val = GetValueForBlock(UserBBNode, Instr, Phis);
|
|
||||||
else
|
|
||||||
Val = UndefValue::get(Instr->getType());
|
|
||||||
|
|
||||||
// Preincrement the iterator to avoid invalidating it when we change the
|
// Preincrement the iterator to avoid invalidating it when we change the
|
||||||
// value.
|
// value.
|
||||||
@ -233,10 +226,14 @@ SetVector<Instruction*> LCSSA::getLoopValuesUsedOutsideLoop(Loop *L) {
|
|||||||
|
|
||||||
/// GetValueForBlock - Get the value to use within the specified basic block.
|
/// GetValueForBlock - Get the value to use within the specified basic block.
|
||||||
/// available values are in Phis.
|
/// available values are in Phis.
|
||||||
PHINode *LCSSA::GetValueForBlock(DominatorTree::Node *BB, Instruction *OrigInst,
|
Value *LCSSA::GetValueForBlock(DominatorTree::Node *BB, Instruction *OrigInst,
|
||||||
std::map<DominatorTree::Node*, PHINode*> &Phis) {
|
std::map<DominatorTree::Node*, Value*> &Phis) {
|
||||||
|
// If there is no dominator info for this BB, it is unreachable.
|
||||||
|
if (BB == 0)
|
||||||
|
return UndefValue::get(OrigInst->getType());
|
||||||
|
|
||||||
// If we have already computed this value, return the previously computed val.
|
// If we have already computed this value, return the previously computed val.
|
||||||
PHINode *&V = Phis[BB];
|
Value *&V = Phis[BB];
|
||||||
if (V) return V;
|
if (V) return V;
|
||||||
|
|
||||||
DominatorTree::Node *IDom = BB->getIDom();
|
DominatorTree::Node *IDom = BB->getIDom();
|
||||||
@ -262,13 +259,14 @@ PHINode *LCSSA::GetValueForBlock(DominatorTree::Node *BB, Instruction *OrigInst,
|
|||||||
|
|
||||||
// Otherwise, the idom is the loop, so we need to insert a PHI node. Do so
|
// Otherwise, the idom is the loop, so we need to insert a PHI node. Do so
|
||||||
// now, then get values to fill in the incoming values for the PHI.
|
// now, then get values to fill in the incoming values for the PHI.
|
||||||
V = new PHINode(OrigInst->getType(), OrigInst->getName()+".lcssa",
|
PHINode *PN = new PHINode(OrigInst->getType(), OrigInst->getName()+".lcssa",
|
||||||
BBN->begin());
|
BBN->begin());
|
||||||
V->reserveOperandSpace(std::distance(pred_begin(BBN), pred_end(BBN)));
|
PN->reserveOperandSpace(std::distance(pred_begin(BBN), pred_end(BBN)));
|
||||||
|
V = PN;
|
||||||
|
|
||||||
// Fill in the incoming values for the block.
|
// Fill in the incoming values for the block.
|
||||||
for (pred_iterator PI = pred_begin(BBN), E = pred_end(BBN); PI != E; ++PI)
|
for (pred_iterator PI = pred_begin(BBN), E = pred_end(BBN); PI != E; ++PI)
|
||||||
V->addIncoming(GetValueForBlock(DT->getNode(*PI), OrigInst, Phis), *PI);
|
PN->addIncoming(GetValueForBlock(DT->getNode(*PI), OrigInst, Phis), *PI);
|
||||||
return V;
|
return PN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user