[llvm] r200881 - [PM] Don't require analysis results to be const in the new pass manager.

Chandler Carruth chandlerc at gmail.com
Wed Feb 5 13:41:42 PST 2014


Author: chandlerc
Date: Wed Feb  5 15:41:42 2014
New Revision: 200881

URL: http://llvm.org/viewvc/llvm-project?rev=200881&view=rev
Log:
[PM] Don't require analysis results to be const in the new pass manager.

I think this was just over-eagerness on my part. The analysis results
need to often be non-const because they need to (in some cases at least)
be updated by the transformation pass in order to remain correct. It
also makes lazy analyses (a common case) needlessly annoying to write in
order to make their entire state mutable.

Modified:
    llvm/trunk/include/llvm/IR/PassManager.h
    llvm/trunk/lib/IR/PassManager.cpp
    llvm/trunk/unittests/IR/PassManagerTest.cpp

Modified: llvm/trunk/include/llvm/IR/PassManager.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/PassManager.h?rev=200881&r1=200880&r2=200881&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/PassManager.h (original)
+++ llvm/trunk/include/llvm/IR/PassManager.h Wed Feb  5 15:41:42 2014
@@ -481,15 +481,15 @@ public:
   ///
   /// If there is not a valid cached result in the manager already, this will
   /// re-run the analysis to produce a valid result.
-  template <typename PassT> const typename PassT::Result &getResult(IRUnitT IR) {
+  template <typename PassT> typename PassT::Result &getResult(IRUnitT IR) {
     assert(AnalysisPasses.count(PassT::ID()) &&
            "This analysis pass was not registered prior to being queried");
 
-    const ResultConceptT &ResultConcept =
+    ResultConceptT &ResultConcept =
         derived_this()->getResultImpl(PassT::ID(), IR);
     typedef detail::AnalysisResultModel<IRUnitT, PassT, typename PassT::Result>
         ResultModelT;
-    return static_cast<const ResultModelT &>(ResultConcept).Result;
+    return static_cast<ResultModelT &>(ResultConcept).Result;
   }
 
   /// \brief Get the cached result of an analysis pass for this module.
@@ -498,18 +498,18 @@ public:
   ///
   /// \returns null if there is no cached result.
   template <typename PassT>
-  const typename PassT::Result *getCachedResult(IRUnitT IR) const {
+  typename PassT::Result *getCachedResult(IRUnitT IR) const {
     assert(AnalysisPasses.count(PassT::ID()) &&
            "This analysis pass was not registered prior to being queried");
 
-    const ResultConceptT *ResultConcept =
+    ResultConceptT *ResultConcept =
         derived_this()->getCachedResultImpl(PassT::ID(), IR);
     if (!ResultConcept)
       return 0;
 
     typedef detail::AnalysisResultModel<IRUnitT, PassT, typename PassT::Result>
         ResultModelT;
-    return &static_cast<const ResultModelT *>(ResultConcept)->Result;
+    return &static_cast<ResultModelT *>(ResultConcept)->Result;
   }
 
   /// \brief Register an analysis pass with the manager.
@@ -582,10 +582,10 @@ public:
 
 private:
   /// \brief Get a module pass result, running the pass if necessary.
-  const ResultConceptT &getResultImpl(void *PassID, Module *M);
+  ResultConceptT &getResultImpl(void *PassID, Module *M);
 
   /// \brief Get a cached module pass result or return null.
-  const ResultConceptT *getCachedResultImpl(void *PassID, Module *M) const;
+  ResultConceptT *getCachedResultImpl(void *PassID, Module *M) const;
 
   /// \brief Invalidate a module pass result.
   void invalidateImpl(void *PassID, Module *M);
@@ -627,10 +627,10 @@ public:
 
 private:
   /// \brief Get a function pass result, running the pass if necessary.
-  const ResultConceptT &getResultImpl(void *PassID, Function *F);
+  ResultConceptT &getResultImpl(void *PassID, Function *F);
 
   /// \brief Get a cached function pass result or return null.
-  const ResultConceptT *getCachedResultImpl(void *PassID, Function *F) const;
+  ResultConceptT *getCachedResultImpl(void *PassID, Function *F) const;
 
   /// \brief Invalidate a function pass result.
   void invalidateImpl(void *PassID, Function *F);
@@ -711,7 +711,7 @@ public:
   ~Result();
 
   /// \brief Accessor for the \c FunctionAnalysisManager.
-  FunctionAnalysisManager &getManager() const { return FAM; }
+  FunctionAnalysisManager &getManager() { return FAM; }
 
   /// \brief Handler for invalidation of the module.
   ///

Modified: llvm/trunk/lib/IR/PassManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/PassManager.cpp?rev=200881&r1=200880&r2=200881&view=diff
==============================================================================
--- llvm/trunk/lib/IR/PassManager.cpp (original)
+++ llvm/trunk/lib/IR/PassManager.cpp Wed Feb  5 15:41:42 2014
@@ -40,7 +40,7 @@ PreservedAnalyses ModulePassManager::run
   return PA;
 }
 
-const ModuleAnalysisManager::ResultConceptT &
+ModuleAnalysisManager::ResultConceptT &
 ModuleAnalysisManager::getResultImpl(void *PassID, Module *M) {
   ModuleAnalysisResultMapT::iterator RI;
   bool Inserted;
@@ -55,7 +55,7 @@ ModuleAnalysisManager::getResultImpl(voi
   return *RI->second;
 }
 
-const ModuleAnalysisManager::ResultConceptT *
+ModuleAnalysisManager::ResultConceptT *
 ModuleAnalysisManager::getCachedResultImpl(void *PassID, Module *M) const {
   ModuleAnalysisResultMapT::const_iterator RI = ModuleAnalysisResults.find(PassID);
   return RI == ModuleAnalysisResults.end() ? 0 : &*RI->second;
@@ -111,7 +111,7 @@ void FunctionAnalysisManager::clear() {
   FunctionAnalysisResultLists.clear();
 }
 
-const FunctionAnalysisManager::ResultConceptT &
+FunctionAnalysisManager::ResultConceptT &
 FunctionAnalysisManager::getResultImpl(void *PassID, Function *F) {
   FunctionAnalysisResultMapT::iterator RI;
   bool Inserted;
@@ -129,7 +129,7 @@ FunctionAnalysisManager::getResultImpl(v
   return *RI->second->second;
 }
 
-const FunctionAnalysisManager::ResultConceptT *
+FunctionAnalysisManager::ResultConceptT *
 FunctionAnalysisManager::getCachedResultImpl(void *PassID, Function *F) const {
   FunctionAnalysisResultMapT::const_iterator RI =
       FunctionAnalysisResults.find(std::make_pair(PassID, F));

Modified: llvm/trunk/unittests/IR/PassManagerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/PassManagerTest.cpp?rev=200881&r1=200880&r2=200881&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/PassManagerTest.cpp (original)
+++ llvm/trunk/unittests/IR/PassManagerTest.cpp Wed Feb  5 15:41:42 2014
@@ -126,18 +126,18 @@ struct TestFunctionPass {
 
     const ModuleAnalysisManager &MAM =
         AM->getResult<ModuleAnalysisManagerFunctionProxy>(F).getManager();
-    if (const TestModuleAnalysis::Result *TMA =
+    if (TestModuleAnalysis::Result *TMA =
             MAM.getCachedResult<TestModuleAnalysis>(F->getParent()))
       AnalyzedFunctionCount += TMA->FunctionCount;
 
     if (OnlyUseCachedResults) {
       // Hack to force the use of the cached interface.
-      if (const TestFunctionAnalysis::Result *AR =
+      if (TestFunctionAnalysis::Result *AR =
               AM->getCachedResult<TestFunctionAnalysis>(F))
         AnalyzedInstrCount += AR->InstructionCount;
     } else {
       // Typical path just runs the analysis as needed.
-      const TestFunctionAnalysis::Result &AR = AM->getResult<TestFunctionAnalysis>(F);
+      TestFunctionAnalysis::Result &AR = AM->getResult<TestFunctionAnalysis>(F);
       AnalyzedInstrCount += AR.InstructionCount;
     }
 





More information about the llvm-commits mailing list