Pull out this predicate loop into a helper function.

llvm-svn: 80006
This commit is contained in:
Owen Anderson 2009-08-25 17:26:32 +00:00
parent 1d5e9f9368
commit 5e39d1deec
1 changed files with 15 additions and 11 deletions

View File

@ -361,6 +361,17 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
return newFunction; return newFunction;
} }
static BasicBlock* FindPhiPredForUseInBlock(Value* Used, BasicBlock* BB) {
for (Value::use_iterator UI = Used->use_begin(),
UE = Used->use_end(); UI != UE; ++UI) {
PHINode *P = dyn_cast<PHINode>(*UI);
if (P && P->getParent() == BB)
return P->getIncomingBlock(UI);
}
return 0;
}
/// emitCallAndSwitchStatement - This method sets up the caller side by adding /// emitCallAndSwitchStatement - This method sets up the caller side by adding
/// the call instruction, splitting any PHI nodes in the header block as /// the call instruction, splitting any PHI nodes in the header block as
/// necessary. /// necessary.
@ -540,17 +551,10 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
// then we need to test for dominance of the phi's predecessor // then we need to test for dominance of the phi's predecessor
// instead. Unfortunately, this a little complicated since we // instead. Unfortunately, this a little complicated since we
// have already rewritten uses of the value to uses of the reload. // have already rewritten uses of the value to uses of the reload.
for (Value::use_iterator UI = Reloads[out]->use_begin(), BasicBlock* pred = FindPhiPredForUseInBlock(Reloads[out],
UE = Reloads[out]->use_end(); UI != UE; ++UI) { OldTarget);
PHINode *P = dyn_cast<PHINode>(*UI); if (pred && DT && DT->dominates(DefBlock, pred))
if (!P || P->getParent() != OldTarget) continue;
BasicBlock* pred = P->getIncomingBlock(UI);
if (DT->dominates(DefBlock, pred)) {
DominatesDef = true; DominatesDef = true;
break;
}
}
} }
if (DominatesDef) { if (DominatesDef) {