Make some methods const. The only interesting change here is that
[oota-llvm.git] / include / llvm / PassAnalysisSupport.h
index b09ba45e346d3b9bdfdc44925f273ce4414fa3cc..5864fad0d726c58e14f0bd40935cd304e9214510 100644 (file)
 #define LLVM_PASS_ANALYSIS_SUPPORT_H
 
 #include <vector>
+#include "llvm/Pass.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
 
 namespace llvm {
 
-// No need to include Pass.h, we are being included by it!
+class StringRef;
 
 //===----------------------------------------------------------------------===//
 // AnalysisUsage - Represent the analysis usage information of a pass.  This
@@ -79,6 +81,9 @@ public:
     return *this;
   }
 
+  // addPreserved - Add the specified Pass class to the set of analyses
+  // preserved by this pass.
+  //
   template<class PassClass>
   AnalysisUsage &addPreserved() {
     assert(Pass::getClassPassInfo<PassClass>() && "Pass class not registered!");
@@ -86,6 +91,18 @@ public:
     return *this;
   }
 
+  // addPreserved - Add the Pass with the specified argument string to the set
+  // of analyses preserved by this pass. If no such Pass exists, do nothing.
+  // This can be useful when a pass is trivially preserved, but may not be
+  // linked in. Be careful about spelling!
+  //
+  AnalysisUsage &addPreserved(StringRef Arg) {
+    const PassInfo *PI = Pass::lookupPassInfo(Arg);
+    // If the pass exists, preserve it. Otherwise silently do nothing.
+    if (PI) Preserved.push_back(PI);
+    return *this;
+  }
+
   // setPreservesAll - Set by analyses that do not transform their input at all
   void setPreservesAll() { PreservesAll = true; }
   bool getPreservesAll() const { return PreservesAll; }