AU.addRequired<LoopInfo>();
AU.addRequired<DominatorSet>();
AU.addRequired<DominatorTree>();
+ AU.addRequired<ETForest>();
AU.addPreserved<LoopInfo>();
AU.addPreserved<DominatorSet>();
/// FindPHIToPartitionLoops - The first part of loop-nestification is to find a
/// PHI node that tells us how to partition the loops.
-static PHINode *FindPHIToPartitionLoops(Loop *L, DominatorSet &DS,
- AliasAnalysis *AA) {
+static PHINode *FindPHIToPartitionLoops(Loop *L, ETForest *EF,
+ AliasAnalysis *AA) {
for (BasicBlock::iterator I = L->getHeader()->begin(); isa<PHINode>(I); ) {
PHINode *PN = cast<PHINode>(I);
++I;
if (Value *V = PN->hasConstantValue())
- if (!isa<Instruction>(V) || DS.dominates(cast<Instruction>(V), PN)) {
+ if (!isa<Instruction>(V) || EF->dominates(cast<Instruction>(V), PN)) {
// This is a degenerate PHI already, don't modify it!
PN->replaceAllUsesWith(V);
if (AA) AA->deleteValue(PN);
/// created.
///
Loop *LoopSimplify::SeparateNestedLoop(Loop *L) {
- PHINode *PN = FindPHIToPartitionLoops(L, getAnalysis<DominatorSet>(), AA);
+ ETForest *EF = getAnalysisToUpdate<ETForest>();
+ PHINode *PN = FindPHIToPartitionLoops(L, EF, AA);
if (PN == 0) return 0; // No known way to partition.
// Pull out all predecessors that have varying values in the loop. This
DFSInfoValid = true;
}
+// dominates - Return true if A dominates B. THis performs the
+// special checks necessary if A and B are in the same basic block.
+bool ETForestBase::dominates(Instruction *A, Instruction *B) {
+ BasicBlock *BBA = A->getParent(), *BBB = B->getParent();
+ if (BBA != BBB) return dominates(BBA, BBB);
+
+ // Loop through the basic block until we find A or B.
+ BasicBlock::iterator I = BBA->begin();
+ for (; &*I != A && &*I != B; ++I) /*empty*/;
+
+ if(!IsPostDominators) {
+ // A dominates B if it is found first in the basic block.
+ return &*I == A;
+ } else {
+ // A post-dominates B if B is found first in the basic block.
+ return &*I == B;
+ }
+}
+
ETNode *ETForest::getNodeForBlock(BasicBlock *BB) {
ETNode *&BBNode = Nodes[BB];
if (BBNode) return BBNode;