[llvm-commits] CVS: llvm/lib/Transforms/Scalar/PredicateSimplifier.cpp

Owen Anderson resistor at mac.com
Tue Apr 24 21:19:11 PDT 2007



Changes in directory llvm/lib/Transforms/Scalar:

PredicateSimplifier.cpp updated: 1.69 -> 1.70
---
Log message:

Undo my previous changes.  Since my approach to this problem is being revised,
this approach is no longer appropriate.


---
Diffs of the changes:  (+31 -32)

 PredicateSimplifier.cpp |   63 +++++++++++++++++++++++-------------------------
 1 files changed, 31 insertions(+), 32 deletions(-)


Index: llvm/lib/Transforms/Scalar/PredicateSimplifier.cpp
diff -u llvm/lib/Transforms/Scalar/PredicateSimplifier.cpp:1.69 llvm/lib/Transforms/Scalar/PredicateSimplifier.cpp:1.70
--- llvm/lib/Transforms/Scalar/PredicateSimplifier.cpp:1.69	Sat Apr 21 02:38:12 2007
+++ llvm/lib/Transforms/Scalar/PredicateSimplifier.cpp	Tue Apr 24 23:18:54 2007
@@ -1980,19 +1980,21 @@
   /// can't be equal and will solve setcc instructions when possible.
   /// @brief Root of the predicate simplifier optimization.
   class VISIBILITY_HIDDEN PredicateSimplifier : public FunctionPass {
+    DominatorTree *DT;
     ETForest *Forest;
     bool modified;
     InequalityGraph *IG;
     UnreachableBlocks UB;
     ValueRanges *VR;
 
-    std::vector<BasicBlock *> WorkList;
+    std::vector<DominatorTree::Node *> WorkList;
 
   public:
     bool runOnFunction(Function &F);
 
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
       AU.addRequiredID(BreakCriticalEdgesID);
+      AU.addRequired<DominatorTree>();
       AU.addRequired<ETForest>();
       AU.addRequired<TargetData>();
       AU.addPreserved<TargetData>();
@@ -2008,15 +2010,15 @@
     class VISIBILITY_HIDDEN Forwards : public InstVisitor<Forwards> {
       friend class InstVisitor<Forwards>;
       PredicateSimplifier *PS;
-      BasicBlock *Node;
+      DominatorTree::Node *DTNode;
 
     public:
       InequalityGraph &IG;
       UnreachableBlocks &UB;
       ValueRanges &VR;
 
-      Forwards(PredicateSimplifier *PS, BasicBlock* node)
-        : PS(PS), Node(node), IG(*PS->IG), UB(PS->UB), VR(*PS->VR) {}
+      Forwards(PredicateSimplifier *PS, DominatorTree::Node *DTNode)
+        : PS(PS), DTNode(DTNode), IG(*PS->IG), UB(PS->UB), VR(*PS->VR) {}
 
       void visitTerminatorInst(TerminatorInst &TI);
       void visitBranchInst(BranchInst &BI);
@@ -2036,32 +2038,31 @@
     // Used by terminator instructions to proceed from the current basic
     // block to the next. Verifies that "current" dominates "next",
     // then calls visitBasicBlock.
-    void proceedToSuccessors(BasicBlock *Current) {
-      std::vector<BasicBlock*> Children;
-      Forest->getChildren(Current, Children);
-      for (std::vector<BasicBlock*>::iterator I = Children.begin(),
-           E = Children.end(); I != E; ++I) {
+    void proceedToSuccessors(DominatorTree::Node *Current) {
+      for (DominatorTree::Node::iterator I = Current->begin(),
+           E = Current->end(); I != E; ++I) {
         WorkList.push_back(*I);
       }
     }
 
-    void proceedToSuccessor(BasicBlock *Next) {
+    void proceedToSuccessor(DominatorTree::Node *Next) {
       WorkList.push_back(Next);
     }
 
     // Visits each instruction in the basic block.
-    void visitBasicBlock(BasicBlock *BB) {
+    void visitBasicBlock(DominatorTree::Node *Node) {
+      BasicBlock *BB = Node->getBlock();
       ETNode *ET = Forest->getNodeForBlock(BB);
       DOUT << "Entering Basic Block: " << BB->getName()
            << " (" << ET->getDFSNumIn() << ")\n";
       for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;) {
-        visitInstruction(I++, BB, ET);
+        visitInstruction(I++, Node, ET);
       }
     }
 
     // Tries to simplify each Instruction and add new properties to
     // the PropertySet.
-    void visitInstruction(Instruction *I, BasicBlock *node, ETNode *ET) {
+    void visitInstruction(Instruction *I, DominatorTree::Node *DT, ETNode *ET) {
       DOUT << "Considering instruction " << *I << "\n";
       DEBUG(IG->dump());
 
@@ -2105,13 +2106,14 @@
 
       std::string name = I->getParent()->getName();
       DOUT << "push (%" << name << ")\n";
-      Forwards visit(this, node);
+      Forwards visit(this, DT);
       visit.visit(*I);
       DOUT << "pop (%" << name << ")\n";
     }
   };
 
   bool PredicateSimplifier::runOnFunction(Function &F) {
+    DT = &getAnalysis<DominatorTree>();
     Forest = &getAnalysis<ETForest>();
 
     TargetData *TD = &getAnalysis<TargetData>();
@@ -2125,12 +2127,12 @@
     BasicBlock *RootBlock = &F.getEntryBlock();
     IG = new InequalityGraph(Forest->getNodeForBlock(RootBlock));
     VR = new ValueRanges(TD);
-    WorkList.push_back(Forest->getRoot());
+    WorkList.push_back(DT->getRootNode());
 
     do {
-      BasicBlock *node = WorkList.back();
+      DominatorTree::Node *DTNode = WorkList.back();
       WorkList.pop_back();
-      if (!UB.isDead(node)) visitBasicBlock(node);
+      if (!UB.isDead(DTNode->getBlock())) visitBasicBlock(DTNode);
     } while (!WorkList.empty());
 
     delete VR;
@@ -2142,12 +2144,12 @@
   }
 
   void PredicateSimplifier::Forwards::visitTerminatorInst(TerminatorInst &TI) {
-    PS->proceedToSuccessors(Node);
+    PS->proceedToSuccessors(DTNode);
   }
 
   void PredicateSimplifier::Forwards::visitBranchInst(BranchInst &BI) {
     if (BI.isUnconditional()) {
-      PS->proceedToSuccessors(Node);
+      PS->proceedToSuccessors(DTNode);
       return;
     }
 
@@ -2156,26 +2158,24 @@
     BasicBlock *FalseDest = BI.getSuccessor(1);
 
     if (isa<Constant>(Condition) || TrueDest == FalseDest) {
-      PS->proceedToSuccessors(Node);
+      PS->proceedToSuccessors(DTNode);
       return;
     }
 
-    std::vector<BasicBlock*> Children;
-    PS->Forest->getChildren(Node, Children);
-    for (std::vector<BasicBlock*>::iterator I = Children.begin(),
-         E = Children.end(); I != E; ++I) {
-      BasicBlock *Dest = *I;
+    for (DominatorTree::Node::iterator I = DTNode->begin(), E = DTNode->end();
+         I != E; ++I) {
+      BasicBlock *Dest = (*I)->getBlock();
       DOUT << "Branch thinking about %" << Dest->getName()
            << "(" << PS->Forest->getNodeForBlock(Dest)->getDFSNumIn() << ")\n";
 
       if (Dest == TrueDest) {
-        DOUT << "(" << Node->getName() << ") true set:\n";
+        DOUT << "(" << DTNode->getBlock()->getName() << ") true set:\n";
         VRPSolver VRP(IG, UB, VR, PS->Forest, PS->modified, Dest);
         VRP.add(ConstantInt::getTrue(), Condition, ICmpInst::ICMP_EQ);
         VRP.solve();
         DEBUG(IG.dump());
       } else if (Dest == FalseDest) {
-        DOUT << "(" << Node->getName() << ") false set:\n";
+        DOUT << "(" << DTNode->getBlock()->getName() << ") false set:\n";
         VRPSolver VRP(IG, UB, VR, PS->Forest, PS->modified, Dest);
         VRP.add(ConstantInt::getFalse(), Condition, ICmpInst::ICMP_EQ);
         VRP.solve();
@@ -2191,11 +2191,10 @@
 
     // Set the EQProperty in each of the cases BBs, and the NEProperties
     // in the default BB.
-    std::vector<BasicBlock*> Children;
-    PS->Forest->getChildren(Node, Children);
-    for (std::vector<BasicBlock*>::iterator I = Children.begin(),
-         E = Children.end(); I != E; ++I) {
-      BasicBlock *BB = *I;
+
+    for (DominatorTree::Node::iterator I = DTNode->begin(), E = DTNode->end();
+         I != E; ++I) {
+      BasicBlock *BB = (*I)->getBlock();
       DOUT << "Switch thinking about BB %" << BB->getName()
            << "(" << PS->Forest->getNodeForBlock(BB)->getDFSNumIn() << ")\n";
 






More information about the llvm-commits mailing list