Build the correct range for loops with unusual bounds. Fix from Jay Foad.
[oota-llvm.git] / lib / Analysis / CFGPrinter.cpp
index 88fbc261ad8b3b0f1f38b4ba945bf6c9b2ffea67..d32481e7f3bd94a1319c8068923dd1aaed7541e6 100644 (file)
@@ -90,9 +90,52 @@ struct DOTGraphTraits<const Function*> : public DefaultDOTGraphTraits {
 }
 
 namespace {
-  struct VISIBILITY_HIDDEN CFGPrinter : public FunctionPass {
+  struct VISIBILITY_HIDDEN CFGViewer : public FunctionPass {
+    static char ID; // Pass identifcation, replacement for typeid
+    CFGViewer() : FunctionPass((intptr_t)&ID) {}
+
+    virtual bool runOnFunction(Function &F) {
+      F.viewCFG();
+      return false;
+    }
+
+    void print(std::ostream &OS, const Module* = 0) const {}
+
+    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+      AU.setPreservesAll();
+    }
+  };
+
+  char CFGViewer::ID = 0;
+  RegisterPass<CFGViewer> V0("view-cfg",
+                             "View CFG of function");
+
+  struct VISIBILITY_HIDDEN CFGOnlyViewer : public FunctionPass {
     static char ID; // Pass identifcation, replacement for typeid
+    CFGOnlyViewer() : FunctionPass((intptr_t)&ID) {}
+
+    virtual bool runOnFunction(Function &F) {
+      CFGOnly = true;
+      F.viewCFG();
+      CFGOnly = false;
+      return false;
+    }
+
+    void print(std::ostream &OS, const Module* = 0) const {}
+
+    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+      AU.setPreservesAll();
+    }
+  };
+
+  char CFGOnlyViewer::ID = 0;
+  RegisterPass<CFGOnlyViewer> V1("view-cfg-only",
+                                 "View CFG of function (with no function bodies)");
+
+  struct VISIBILITY_HIDDEN CFGPrinter : public FunctionPass {
+    static char ID; // Pass identification, replacement for typeid
     CFGPrinter() : FunctionPass((intptr_t)&ID) {}
+    explicit CFGPrinter(intptr_t pid) : FunctionPass(pid) {}
 
     virtual bool runOnFunction(Function &F) {
       std::string Filename = "cfg." + F.getName() + ".dot";
@@ -119,7 +162,8 @@ namespace {
                               "Print CFG of function to 'dot' file");
 
   struct VISIBILITY_HIDDEN CFGOnlyPrinter : public CFGPrinter {
-    static char ID; // Pass identifcation, replacement for typeid
+    static char ID; // Pass identification, replacement for typeid
+    CFGOnlyPrinter() : CFGPrinter((intptr_t)&ID) {}
     virtual bool runOnFunction(Function &F) {
       bool OldCFGOnly = CFGOnly;
       CFGOnly = true;