in builds without asserts we do not need to allocate the Next pointer in "ghostly...
[oota-llvm.git] / include / llvm / CodeGen / MachineDominators.h
index 01a09a79226501d74d5a42bca7fafcbbbc575ec9..5981e5a3a589fd38f179b9b9e9058b33adde9441 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by Owen Anderson and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -16,9 +16,6 @@
 #define LLVM_CODEGEN_MACHINEDOMINATORS_H
 
 #include "llvm/CodeGen/MachineFunctionPass.h"
-#include "llvm/CodeGen/MachineBasicBlock.h"
-#include "llvm/CodeGen/MachineFunction.h"
-#include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/Analysis/Dominators.h"
 #include "llvm/Analysis/DominatorInternals.h"
 
@@ -45,19 +42,13 @@ public:
   static char ID; // Pass ID, replacement for typeid
   DominatorTreeBase<MachineBasicBlock>* DT;
   
-  MachineDominatorTree() : MachineFunctionPass(intptr_t(&ID)) {
-    DT = new DominatorTreeBase<MachineBasicBlock>(false);
-  }
+  MachineDominatorTree();
   
-  ~MachineDominatorTree() {
-    DT->releaseMemory();
-    delete DT;
-  }
+  ~MachineDominatorTree();
+  
+  DominatorTreeBase<MachineBasicBlock>& getBase() { return *DT; }
   
-   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-     AU.setPreservesAll();
-     MachineFunctionPass::getAnalysisUsage(AU);
-   }
+  virtual void getAnalysisUsage(AnalysisUsage &AU) const;
   
   /// getRoots -  Return the root blocks of the current CFG.  This may include
   /// multiple blocks if we are computing post dominators.  For forward
@@ -75,11 +66,7 @@ public:
     return DT->getRootNode();
   }
   
-  virtual bool runOnMachineFunction(MachineFunction &F) {
-    DT->recalculate(F);
-    
-    return false;
-  }
+  virtual bool runOnMachineFunction(MachineFunction &F);
   
   inline bool dominates(MachineDomTreeNode* A, MachineDomTreeNode* B) const {
     return DT->dominates(A, B);
@@ -171,15 +158,42 @@ public:
   }
   
   
-  virtual void releaseMemory() { 
-    DT->releaseMemory();
-  }
+  virtual void releaseMemory();
   
   virtual void print(std::ostream &OS, const Module* M= 0) const {
     DT->print(OS, M);
   }
 };
 
+//===-------------------------------------
+/// DominatorTree GraphTraits specialization so the DominatorTree can be
+/// iterable by generic graph iterators.
+///
+
+template<class T> struct GraphTraits;
+
+template <> struct GraphTraits<MachineDomTreeNode *> {
+  typedef MachineDomTreeNode NodeType;
+  typedef NodeType::iterator  ChildIteratorType;
+  
+  static NodeType *getEntryNode(NodeType *N) {
+    return N;
+  }
+  static inline ChildIteratorType child_begin(NodeType* N) {
+    return N->begin();
+  }
+  static inline ChildIteratorType child_end(NodeType* N) {
+    return N->end();
+  }
+};
+
+template <> struct GraphTraits<MachineDominatorTree*>
+  : public GraphTraits<MachineDomTreeNode *> {
+  static NodeType *getEntryNode(MachineDominatorTree *DT) {
+    return DT->getRootNode();
+  }
+};
+
 }
 
 #endif