[llvm-commits] [llvm] r83555 - in /llvm/trunk: include/llvm/Pass.h include/llvm/PassAnalysisSupport.h lib/CodeGen/MachineFunctionPass.cpp lib/Transforms/Scalar/CodeGenLICM.cpp lib/VMCore/Pass.cpp

Dan Gohman gohman at apple.com
Thu Oct 8 10:00:02 PDT 2009


Author: djg
Date: Thu Oct  8 12:00:02 2009
New Revision: 83555

URL: http://llvm.org/viewvc/llvm-project?rev=83555&view=rev
Log:
Add a form of addPreserved which takes a string argument, to allow passes
to declare that they preserve other passes without needing to pull in
additional header file or library dependencies. Convert MachineFunctionPass
and CodeGenLICM to make use of this.

Modified:
    llvm/trunk/include/llvm/Pass.h
    llvm/trunk/include/llvm/PassAnalysisSupport.h
    llvm/trunk/lib/CodeGen/MachineFunctionPass.cpp
    llvm/trunk/lib/Transforms/Scalar/CodeGenLICM.cpp
    llvm/trunk/lib/VMCore/Pass.cpp

Modified: llvm/trunk/include/llvm/Pass.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Pass.h?rev=83555&r1=83554&r2=83555&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Pass.h (original)
+++ llvm/trunk/include/llvm/Pass.h Thu Oct  8 12:00:02 2009
@@ -46,6 +46,7 @@
 class AnalysisResolver;
 class PMDataManager;
 class raw_ostream;
+class StringRef;
 
 // AnalysisID - Use the PassInfo to identify a pass...
 typedef const PassInfo* AnalysisID;
@@ -164,6 +165,10 @@
   // or null if it is not known.
   static const PassInfo *lookupPassInfo(intptr_t TI);
 
+  // lookupPassInfo - Return the pass info object for the pass with the given
+  // argument string, or null if it is not known.
+  static const PassInfo *lookupPassInfo(const StringRef &Arg);
+
   /// getAnalysisIfAvailable<AnalysisType>() - Subclasses use this function to
   /// get analysis information that might be around, for example to update it.
   /// This is different than getAnalysis in that it can fail (if the analysis

Modified: llvm/trunk/include/llvm/PassAnalysisSupport.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/PassAnalysisSupport.h?rev=83555&r1=83554&r2=83555&view=diff

==============================================================================
--- llvm/trunk/include/llvm/PassAnalysisSupport.h (original)
+++ llvm/trunk/include/llvm/PassAnalysisSupport.h Thu Oct  8 12:00:02 2009
@@ -24,6 +24,8 @@
 
 namespace llvm {
 
+class StringRef;
+
 // No need to include Pass.h, we are being included by it!
 
 //===----------------------------------------------------------------------===//
@@ -79,6 +81,9 @@
     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 @@
     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(const 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; }

Modified: llvm/trunk/lib/CodeGen/MachineFunctionPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineFunctionPass.cpp?rev=83555&r1=83554&r2=83555&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/MachineFunctionPass.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineFunctionPass.cpp Thu Oct  8 12:00:02 2009
@@ -11,11 +11,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/Function.h"
 #include "llvm/Analysis/AliasAnalysis.h"
-#include "llvm/Analysis/ScalarEvolution.h"
-#include "llvm/Analysis/IVUsers.h"
-#include "llvm/Analysis/LiveValues.h"
-#include "llvm/Analysis/MemoryDependenceAnalysis.h"
 #include "llvm/CodeGen/MachineFunctionAnalysis.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
 using namespace llvm;
@@ -36,15 +33,18 @@
 
   // MachineFunctionPass preserves all LLVM IR passes, but there's no
   // high-level way to express this. Instead, just list a bunch of
-  // passes explicitly.
+  // passes explicitly. This does not include setPreservesCFG,
+  // because CodeGen overloads that to mean preserving the MachineBasicBlock
+  // CFG in addition to the LLVM IR CFG.
   AU.addPreserved<AliasAnalysis>();
-  AU.addPreserved<ScalarEvolution>();
-  AU.addPreserved<IVUsers>();
-  AU.addPreserved<MemoryDependenceAnalysis>();
-  AU.addPreserved<LiveValues>();
-  AU.addPreserved<DominatorTree>();
-  AU.addPreserved<DominanceFrontier>();
-  AU.addPreserved<LoopInfo>();
+  AU.addPreserved("scalar-evolution");
+  AU.addPreserved("iv-users");
+  AU.addPreserved("memdep");
+  AU.addPreserved("live-values");
+  AU.addPreserved("domtree");
+  AU.addPreserved("domfrontier");
+  AU.addPreserved("loops");
+  AU.addPreserved("lda");
 
   FunctionPass::getAnalysisUsage(AU);
 }

Modified: llvm/trunk/lib/Transforms/Scalar/CodeGenLICM.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/CodeGenLICM.cpp?rev=83555&r1=83554&r2=83555&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/CodeGenLICM.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/CodeGenLICM.cpp Thu Oct  8 12:00:02 2009
@@ -22,8 +22,6 @@
 #include "llvm/LLVMContext.h"
 #include "llvm/Analysis/LoopPass.h"
 #include "llvm/Analysis/AliasAnalysis.h"
-#include "llvm/Analysis/ScalarEvolution.h"
-#include "llvm/Analysis/IVUsers.h"
 #include "llvm/ADT/DenseMap.h"
 using namespace llvm;
 
@@ -104,8 +102,10 @@
   AU.addPreservedID(LoopSimplifyID);
   AU.addPreserved<LoopInfo>();
   AU.addPreserved<AliasAnalysis>();
-  AU.addPreserved<ScalarEvolution>();
-  AU.addPreserved<IVUsers>();
+  AU.addPreserved("scalar-evolution");
+  AU.addPreserved("iv-users");
+  AU.addPreserved("lda");
+  AU.addPreserved("live-values");
 
   // Hoisting requires a loop preheader.
   AU.addRequiredID(LoopSimplifyID);

Modified: llvm/trunk/lib/VMCore/Pass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Pass.cpp?rev=83555&r1=83554&r2=83555&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Pass.cpp (original)
+++ llvm/trunk/lib/VMCore/Pass.cpp Thu Oct  8 12:00:02 2009
@@ -129,6 +129,9 @@
   /// pass.
   typedef std::map<intptr_t, const PassInfo*> MapType;
   MapType PassInfoMap;
+
+  typedef StringMap<const PassInfo*> StringMapType;
+  StringMapType PassInfoStringMap;
   
   /// AnalysisGroupInfo - Keep track of information for each analysis group.
   struct AnalysisGroupInfo {
@@ -145,10 +148,16 @@
     return I != PassInfoMap.end() ? I->second : 0;
   }
   
+  const PassInfo *GetPassInfo(const StringRef &Arg) const {
+    StringMapType::const_iterator I = PassInfoStringMap.find(Arg);
+    return I != PassInfoStringMap.end() ? I->second : 0;
+  }
+  
   void RegisterPass(const PassInfo &PI) {
     bool Inserted =
       PassInfoMap.insert(std::make_pair(PI.getTypeInfo(),&PI)).second;
     assert(Inserted && "Pass registered multiple times!"); Inserted=Inserted;
+    PassInfoStringMap[PI.getPassArgument()] = &PI;
   }
   
   void UnregisterPass(const PassInfo &PI) {
@@ -157,6 +166,7 @@
     
     // Remove pass from the map.
     PassInfoMap.erase(I);
+    PassInfoStringMap.erase(PI.getPassArgument());
   }
   
   void EnumerateWith(PassRegistrationListener *L) {
@@ -227,6 +237,10 @@
   return getPassRegistrar()->GetPassInfo(TI);
 }
 
+const PassInfo *Pass::lookupPassInfo(const StringRef &Arg) {
+  return getPassRegistrar()->GetPassInfo(Arg);
+}
+
 void PassInfo::registerPass() {
   getPassRegistrar()->RegisterPass(*this);
 





More information about the llvm-commits mailing list