[llvm-commits] [llvm] r43541 - in /llvm/trunk: include/llvm/Analysis/DominatorInternals.h include/llvm/Analysis/Dominators.h include/llvm/CodeGen/MachineDominators.h lib/CodeGen/MachineDominators.cpp

Owen Anderson resistor at mac.com
Tue Oct 30 20:30:15 PDT 2007


Author: resistor
Date: Tue Oct 30 22:30:14 2007
New Revision: 43541

URL: http://llvm.org/viewvc/llvm-project?rev=43541&view=rev
Log:
Some fixes to get MachineDomTree working better.

Added:
    llvm/trunk/lib/CodeGen/MachineDominators.cpp
Modified:
    llvm/trunk/include/llvm/Analysis/DominatorInternals.h
    llvm/trunk/include/llvm/Analysis/Dominators.h
    llvm/trunk/include/llvm/CodeGen/MachineDominators.h

Modified: llvm/trunk/include/llvm/Analysis/DominatorInternals.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/DominatorInternals.h?rev=43541&r1=43540&r2=43541&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Analysis/DominatorInternals.h (original)
+++ llvm/trunk/include/llvm/Analysis/DominatorInternals.h Tue Oct 30 22:30:14 2007
@@ -273,21 +273,24 @@
   // which postdominates all real exits if there are multiple exit blocks.
   typename GraphT::NodeType* Root = DT.Roots.size() == 1 ? DT.Roots[0]
                                                          : 0;
-  DT.DomTreeNodes[Root] = DT.RootNode = new DomTreeNode(Root, 0);
+  DT.DomTreeNodes[Root] = DT.RootNode =
+                        new DomTreeNodeBase<typename GraphT::NodeType>(Root, 0);
   
   // Loop over all of the reachable blocks in the function...
-  for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
+  for (typename FuncT::iterator I = F.begin(), E = F.end(); I != E; ++I)
     if (typename GraphT::NodeType* ImmDom = DT.getIDom(I)) {
       // Reachable block.
-      DomTreeNode *BBNode = DT.DomTreeNodes[I];
+      DomTreeNodeBase<typename GraphT::NodeType> *BBNode = DT.DomTreeNodes[I];
       if (BBNode) continue;  // Haven't calculated this node yet?
 
       // Get or calculate the node for the immediate dominator
-      DomTreeNode *IDomNode = DT.getNodeForBlock(ImmDom);
+      DomTreeNodeBase<typename GraphT::NodeType> *IDomNode =
+                                                     DT.getNodeForBlock(ImmDom);
 
       // Add a new tree node for this BasicBlock, and link it as a child of
       // IDomNode
-      DomTreeNode *C = new DomTreeNode(I, IDomNode);
+      DomTreeNodeBase<typename GraphT::NodeType> *C =
+                    new DomTreeNodeBase<typename GraphT::NodeType>(I, IDomNode);
       DT.DomTreeNodes[I] = IDomNode->addChild(C);
     }
   

Modified: llvm/trunk/include/llvm/Analysis/Dominators.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/Dominators.h?rev=43541&r1=43540&r2=43541&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Analysis/Dominators.h (original)
+++ llvm/trunk/include/llvm/Analysis/Dominators.h Tue Oct 30 22:30:14 2007
@@ -132,6 +132,7 @@
 };
 
 EXTERN_TEMPLATE_INSTANTIATION(class DomTreeNodeBase<BasicBlock>);
+EXTERN_TEMPLATE_INSTANTIATION(class DomTreeNodeBase<MachineBasicBlock>);
 
 template<class NodeT>
 static std::ostream &operator<<(std::ostream &o,
@@ -156,7 +157,6 @@
 }
 
 typedef DomTreeNodeBase<BasicBlock> DomTreeNode;
-typedef DomTreeNodeBase<MachineBasicBlock> MachineDomTreeNode;
 
 //===----------------------------------------------------------------------===//
 /// DominatorTree - Calculate the immediate dominator tree for a function.
@@ -607,6 +607,12 @@
     return I != IDoms.end() ? I->second : 0;
   }
   
+  inline void addRoot(NodeT* BB) {
+    // Unreachable block is not a root node.
+    if (!isa<UnreachableInst>(&BB->back()))
+      this->Roots.push_back(BB);
+  }
+  
 public:
   /// recalculate - compute a dominator tree for the given function
   template<class FT>
@@ -615,9 +621,9 @@
       reset();
       
       // Initialize roots
-      this->Roots.push_back(&F.getEntryBlock());
-      this->IDoms[&F.getEntryBlock()] = 0;
-      this->DomTreeNodes[&F.getEntryBlock()] = 0;
+      this->Roots.push_back(&F.front());
+      this->IDoms[&F.front()] = 0;
+      this->DomTreeNodes[&F.front()] = 0;
       this->Vertex.push_back(0);
       
       Calculate<FT, NodeT*>(*this, F);
@@ -627,13 +633,10 @@
       reset();     // Reset from the last time we were run...
 
       // Initialize the roots list
-      for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
-        TerminatorInst *Insn = I->getTerminator();
-        if (Insn->getNumSuccessors() == 0) {
-          // Unreachable block is not a root node.
-          if (!isa<UnreachableInst>(Insn))
-            this->Roots.push_back(I);
-        }
+      for (typename FT::iterator I = F.begin(), E = F.end(); I != E; ++I) {
+        if (std::distance(GraphTraits<FT*>::child_begin(I),
+                          GraphTraits<FT*>::child_end(I)) == 0)
+          addRoot(I);
 
         // Prepopulate maps so that we don't get iterator invalidation issues later.
         this->IDoms[I] = 0;

Modified: llvm/trunk/include/llvm/CodeGen/MachineDominators.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineDominators.h?rev=43541&r1=43540&r2=43541&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineDominators.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineDominators.h Tue Oct 30 22:30:14 2007
@@ -24,7 +24,17 @@
 
 namespace llvm {
 
-void WriteAsOperand(std::ostream &, const MachineBasicBlock*, bool t) {  }
+inline void WriteAsOperand(std::ostream &, const MachineBasicBlock*, bool t) {  }
+
+template<>
+inline void DominatorTreeBase<MachineBasicBlock>::addRoot(MachineBasicBlock* MBB) {
+  this->Roots.push_back(MBB);
+}
+
+EXTERN_TEMPLATE_INSTANTIATION(class DomTreeNodeBase<MachineBasicBlock>);
+EXTERN_TEMPLATE_INSTANTIATION(class DominatorTreeBase<MachineBasicBlock>);
+
+typedef DomTreeNodeBase<MachineBasicBlock> MachineDomTreeNode;
 
 //===-------------------------------------
 /// DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to
@@ -60,7 +70,11 @@
     return DT->getRootNode();
   }
   
-  virtual bool runOnFunction(Function &F);
+  virtual bool runOnMachineFunction(MachineFunction &F) {
+    DT->recalculate(F);
+    
+    return false;
+  }
   
   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
     AU.setPreservesAll();

Added: llvm/trunk/lib/CodeGen/MachineDominators.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineDominators.cpp?rev=43541&view=auto

==============================================================================
--- llvm/trunk/lib/CodeGen/MachineDominators.cpp (added)
+++ llvm/trunk/lib/CodeGen/MachineDominators.cpp Tue Oct 30 22:30:14 2007
@@ -0,0 +1,24 @@
+//===- MachineDominators.cpp - Machine Dominator Calculation --------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements simple dominator construction algorithms for finding
+// forward dominators on machine functions.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/CodeGen/MachineDominators.h"
+
+using namespace llvm;
+
+TEMPLATE_INSTANTIATION(class DomTreeNodeBase<MachineBasicBlock>);
+TEMPLATE_INSTANTIATION(class DominatorTreeBase<MachineBasicBlock>);
+
+char MachineDominatorTree::ID = 0;
+static RegisterPass<MachineDominatorTree>
+E("machinedomtree", "MachineDominator Tree Construction", true);
\ No newline at end of file





More information about the llvm-commits mailing list