Correctly handle the case where a comparison is created in one BasicBlock and

used by a terminator in another.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81437 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nick Lewycky
2009-09-10 07:02:09 +00:00
parent 28275fdf02
commit fd5249e15b
2 changed files with 31 additions and 39 deletions

View File

@@ -81,6 +81,7 @@ namespace llvm {
SmallVector<SmallVector<Instruction *, 1>, 0> value_stack; SmallVector<SmallVector<Instruction *, 1>, 0> value_stack;
void insertSigmaFunctions(SmallVectorImpl<Instruction *> &value); void insertSigmaFunctions(SmallVectorImpl<Instruction *> &value);
void insertSigma(TerminatorInst *TI, Instruction *I, unsigned pos);
void insertPhiFunctions(SmallVectorImpl<Instruction *> &value); void insertPhiFunctions(SmallVectorImpl<Instruction *> &value);
void renameInit(SmallVectorImpl<Instruction *> &value); void renameInit(SmallVectorImpl<Instruction *> &value);
void rename(BasicBlock *BB); void rename(BasicBlock *BB);
@@ -92,8 +93,6 @@ namespace llvm {
unsigned getPositionPhi(PHINode *PN); unsigned getPositionPhi(PHINode *PN);
unsigned getPositionSigma(PHINode *PN); unsigned getPositionSigma(PHINode *PN);
unsigned isUsedInTerminator(CmpInst *CI);
void init(SmallVectorImpl<Instruction *> &value); void init(SmallVectorImpl<Instruction *> &value);
void clean(); void clean();
}; };

View File

@@ -80,38 +80,45 @@ void SSI::insertSigmaFunctions(SmallVectorImpl<Instruction *> &value) {
if (!needConstruction[i]) if (!needConstruction[i])
continue; continue;
bool need = false;
for (Value::use_iterator begin = value[i]->use_begin(), end = for (Value::use_iterator begin = value[i]->use_begin(), end =
value[i]->use_end(); begin != end; ++begin) { value[i]->use_end(); begin != end; ++begin) {
// Test if the Use of the Value is in a comparator // Test if the Use of the Value is in a comparator
CmpInst *CI = dyn_cast<CmpInst>(begin); if (CmpInst *CI = dyn_cast<CmpInst>(begin)) {
if (CI && isUsedInTerminator(CI)) { // Iterates through all uses of CmpInst
// Basic Block of the Instruction for (Value::use_iterator begin_ci = CI->use_begin(), end_ci =
BasicBlock *BB = CI->getParent(); CI->use_end(); begin_ci != end_ci; ++begin_ci) {
// Last Instruction of the Basic Block // Test if any use of CmpInst is in a Terminator
const TerminatorInst *TI = BB->getTerminator(); if (TerminatorInst *TI = dyn_cast<TerminatorInst>(begin_ci)) {
insertSigma(TI, value[i], i);
}
}
}
}
}
}
for (unsigned j = 0, e = TI->getNumSuccessors(); j < e; ++j) { /// Inserts Sigma Functions in every BasicBlock successor to Terminator
/// Instruction TI. All inserted Sigma Function are related to Instruction I.
///
void SSI::insertSigma(TerminatorInst *TI, Instruction *I, unsigned pos) {
// Basic Block of the Terminator Instruction
BasicBlock *BB = TI->getParent();
for (unsigned i = 0, e = TI->getNumSuccessors(); i < e; ++i) {
// Next Basic Block // Next Basic Block
BasicBlock *BB_next = TI->getSuccessor(j); BasicBlock *BB_next = TI->getSuccessor(i);
if (BB_next != BB && if (BB_next != BB &&
BB_next->getSinglePredecessor() != NULL && BB_next->getSinglePredecessor() != NULL &&
dominateAny(BB_next, value[i])) { dominateAny(BB_next, I)) {
PHINode *PN = PHINode::Create( PHINode *PN = PHINode::Create(I->getType(), SSI_SIG, BB_next->begin());
value[i]->getType(), SSI_SIG, BB_next->begin()); PN->addIncoming(I, BB);
PN->addIncoming(value[i], BB); sigmas.insert(std::make_pair(PN, pos));
sigmas.insert(std::make_pair(PN, i));
created.insert(PN); created.insert(PN);
need = true; needConstruction[pos] = true;
defsites[i].push_back(BB_next); defsites[pos].push_back(BB_next);
++NumSigmaInserted; ++NumSigmaInserted;
} }
} }
} }
}
needConstruction[i] = need;
}
}
/// Insert phi functions when necessary /// Insert phi functions when necessary
/// ///
@@ -371,20 +378,6 @@ unsigned SSI::getPositionSigma(PHINode *PN) {
return val->second; return val->second;
} }
/// Return true if the the Comparison Instruction is an operator
/// of the Terminator instruction of its Basic Block.
///
unsigned SSI::isUsedInTerminator(CmpInst *CI) {
TerminatorInst *TI = CI->getParent()->getTerminator();
if (TI->getNumOperands() == 0) {
return false;
} else if (CI == TI->getOperand(0)) {
return true;
} else {
return false;
}
}
/// Initializes /// Initializes
/// ///
void SSI::init(SmallVectorImpl<Instruction *> &value) { void SSI::init(SmallVectorImpl<Instruction *> &value) {