NFC: Remove 'Result' from the analysis manager api to better reflect the implementati...
authorRiver Riddle <riverriddle@google.com>
Wed, 6 Mar 2019 20:03:14 +0000 (12:03 -0800)
committerjpienaar <jpienaar@google.com>
Sat, 30 Mar 2019 00:02:12 +0000 (17:02 -0700)
PiperOrigin-RevId: 237093101

mlir/include/mlir/Pass/AnalysisManager.h
mlir/include/mlir/Pass/Pass.h
mlir/lib/Transforms/CSE.cpp
mlir/lib/Transforms/MemRefDataFlowOpt.cpp
mlir/unittests/Pass/AnalysisManagerTest.cpp

index cf67c33a5d299408cbbce99bc6fae37dc255c2de..48b04964e173a9f051a7aa4918e12c4d6c25de27 100644 (file)
@@ -34,7 +34,7 @@ struct AnalysisID {
 };
 
 //===----------------------------------------------------------------------===//
-// Analysis Preservation and Result Modeling
+// Analysis Preservation and Concept Modeling
 //===----------------------------------------------------------------------===//
 
 namespace detail {
@@ -93,24 +93,24 @@ template <typename AnalysisT> struct AnalysisModel : public AnalysisConcept {
   AnalysisT analysis;
 };
 
-/// This class represents a cache of analysis results for a single IR unit. All
+/// This class represents a cache of analyses for a single IR unit. All
 /// computation, caching, and invalidation of analyses takes place here.
-template <typename IRUnitT> class AnalysisResultMap {
+template <typename IRUnitT> class AnalysisMap {
   /// A mapping between an analysis id and an existing analysis instance.
-  using ResultMap =
+  using ConceptMap =
       DenseMap<const AnalysisID *, std::unique_ptr<AnalysisConcept>>;
 
 public:
-  explicit AnalysisResultMap(IRUnitT *ir) : ir(ir) {}
+  explicit AnalysisMap(IRUnitT *ir) : ir(ir) {}
 
   /// Get an analysis for the current IR unit, computing it if necessary.
-  template <typename AnalysisT> AnalysisT &getResult() {
-    typename ResultMap::iterator it;
+  template <typename AnalysisT> AnalysisT &getAnalysis() {
+    typename ConceptMap::iterator it;
     bool wasInserted;
     std::tie(it, wasInserted) =
-        results.try_emplace(AnalysisID::getID<AnalysisT>());
+        analyses.try_emplace(AnalysisID::getID<AnalysisT>());
 
-    // If we don't have a cached result for this function, compute it directly
+    // If we don't have a cached analysis for this function, compute it directly
     // and add it to the cache.
     if (wasInserted)
       it->second = llvm::make_unique<AnalysisModel<AnalysisT>>(ir);
@@ -119,34 +119,34 @@ public:
 
   /// Get a cached analysis instance if one exists, otherwise return null.
   template <typename AnalysisT>
-  llvm::Optional<std::reference_wrapper<AnalysisT>> getCachedResult() const {
-    auto res = results.find(AnalysisID::getID<AnalysisT>());
-    if (res == results.end())
+  llvm::Optional<std::reference_wrapper<AnalysisT>> getCachedAnalysis() const {
+    auto res = analyses.find(AnalysisID::getID<AnalysisT>());
+    if (res == analyses.end())
       return llvm::None;
     return {static_cast<AnalysisModel<AnalysisT> &>(*res->second).analysis};
   }
 
-  /// Returns the IR unit that this result map represents.
+  /// Returns the IR unit that this analysis map represents.
   IRUnitT *getIRUnit() { return ir; }
   const IRUnitT *getIRUnit() const { return ir; }
 
-  /// Clear any held analysis results.
-  void clear() { results.clear(); }
+  /// Clear any held analyses.
+  void clear() { analyses.clear(); }
 
   /// Invalidate any cached analyses based upon the given set of preserved
   /// analyses.
   void invalidate(const detail::PreservedAnalyses &pa) {
     // Remove any analyses not marked as preserved.
-    for (auto it = results.begin(), e = results.end(); it != e;) {
+    for (auto it = analyses.begin(), e = analyses.end(); it != e;) {
       auto curIt = it++;
       if (!pa.isPreserved(curIt->first))
-        results.erase(curIt);
+        analyses.erase(curIt);
     }
   }
 
 private:
   IRUnitT *ir;
-  ResultMap results;
+  ConceptMap analyses;
 };
 
 } // namespace detail
@@ -163,19 +163,19 @@ public:
   // exist and if it does it may be stale.
   template <typename AnalysisT>
   llvm::Optional<std::reference_wrapper<AnalysisT>>
-  getCachedModuleResult() const {
-    return parentImpl->getCachedResult<AnalysisT>();
+  getCachedModuleAnalysis() const {
+    return parentImpl->getCachedAnalysis<AnalysisT>();
   }
 
   // Query for the given analysis for the current function.
-  template <typename AnalysisT> AnalysisT &getResult() {
-    return impl->getResult<AnalysisT>();
+  template <typename AnalysisT> AnalysisT &getAnalysis() {
+    return impl->getAnalysis<AnalysisT>();
   }
 
   // Query for a cached entry of the given analysis on the current function.
   template <typename AnalysisT>
-  llvm::Optional<std::reference_wrapper<AnalysisT>> getCachedResult() const {
-    return impl->getCachedResult<AnalysisT>();
+  llvm::Optional<std::reference_wrapper<AnalysisT>> getCachedAnalysis() const {
+    return impl->getCachedAnalysis<AnalysisT>();
   }
 
   /// Invalidate any non preserved analyses,
@@ -190,16 +190,16 @@ public:
   void clear() { impl->clear(); }
 
 private:
-  FunctionAnalysisManager(const detail::AnalysisResultMap<Module> *parentImpl,
-                          detail::AnalysisResultMap<Function> *impl)
+  FunctionAnalysisManager(const detail::AnalysisMap<Module> *parentImpl,
+                          detail::AnalysisMap<Function> *impl)
       : parentImpl(parentImpl), impl(impl) {}
 
-  /// A reference to the results map of the parent module within the owning
+  /// A reference to the analysis map of the parent module within the owning
   /// analysis manager.
-  const detail::AnalysisResultMap<Module> *parentImpl;
+  const detail::AnalysisMap<Module> *parentImpl;
 
-  /// A reference to the results map within the owning analysis manager.
-  detail::AnalysisResultMap<Function> *impl;
+  /// A reference to the impl analysis map within the owning analysis manager.
+  detail::AnalysisMap<Function> *impl;
 
   /// Allow access to the constructor.
   friend class ModuleAnalysisManager;
@@ -215,30 +215,30 @@ public:
   /// Query for the analysis of a function. The analysis is computed if it does
   /// not exist.
   template <typename AnalysisT>
-  AnalysisT &getFunctionResult(Function *function) {
-    return slice(function).getResult<AnalysisT>();
+  AnalysisT &getFunctionAnalysis(Function *function) {
+    return slice(function).getAnalysis<AnalysisT>();
   }
 
-  /// Query for a cached analysis of a function, or return null.
+  /// Query for a cached analysis of a child function, or return null.
   template <typename AnalysisT>
   llvm::Optional<std::reference_wrapper<AnalysisT>>
-  getCachedFunctionResult(Function *function) const {
+  getCachedFunctionAnalysis(Function *function) const {
     auto it = functionAnalyses.find(function);
     if (it == functionAnalyses.end())
       return llvm::None;
-    return it->second.getCachedResult<AnalysisT>();
+    return it->second.getCachedAnalysis<AnalysisT>();
   }
 
-  /// Query for the analysis of a module. The analysis is computed if it does
+  /// Query for the analysis for the module. The analysis is computed if it does
   /// not exist.
-  template <typename AnalysisT> AnalysisT &getResult() {
-    return moduleAnalyses.getResult<AnalysisT>();
+  template <typename AnalysisT> AnalysisT &getAnalysis() {
+    return moduleAnalyses.getAnalysis<AnalysisT>();
   }
 
   /// Query for a cached analysis for the module, or return null.
   template <typename AnalysisT>
-  llvm::Optional<std::reference_wrapper<AnalysisT>> getCachedResult() const {
-    return moduleAnalyses.getCachedResult<AnalysisT>();
+  llvm::Optional<std::reference_wrapper<AnalysisT>> getCachedAnalysis() const {
+    return moduleAnalyses.getCachedAnalysis<AnalysisT>();
   }
 
   /// Create an analysis slice for the given child function.
@@ -249,10 +249,10 @@ public:
 
 private:
   /// The cached analyses for functions within the current module.
-  DenseMap<Function *, detail::AnalysisResultMap<Function>> functionAnalyses;
+  DenseMap<Function *, detail::AnalysisMap<Function>> functionAnalyses;
 
   /// The analyses for the owning module.
-  detail::AnalysisResultMap<Module> moduleAnalyses;
+  detail::AnalysisMap<Module> moduleAnalyses;
 };
 
 } // end namespace mlir
index 5634ce1b0b4223d29c51358896a4525ad782bc57..356b6a95b4fdbe8a6f454489cfe0b9bbdac59e67 100644 (file)
@@ -191,16 +191,16 @@ protected:
     this->getPassState().irAndPassFailed.setInt(true);
   }
 
-  /// Query the result of an analysis for the current ir unit.
-  template <typename AnalysisT> AnalysisT &getAnalysisResult() {
-    return this->getAnalysisManager().template getResult<AnalysisT>();
+  /// Query an analysis for the current ir unit.
+  template <typename AnalysisT> AnalysisT &getAnalysis() {
+    return this->getAnalysisManager().template getAnalysis<AnalysisT>();
   }
 
-  /// Query the cached result of an analysis for the current ir unit if one
+  /// Query a cached instance of an analysis for the current ir unit if one
   /// exists.
   template <typename AnalysisT>
-  llvm::Optional<std::reference_wrapper<AnalysisT>> getCachedAnalysisResult() {
-    return this->getAnalysisManager().template getCachedResult<AnalysisT>();
+  llvm::Optional<std::reference_wrapper<AnalysisT>> getCachedAnalysis() {
+    return this->getAnalysisManager().template getCachedAnalysis<AnalysisT>();
   }
 
   /// Mark all analyses as preserved.
@@ -230,12 +230,11 @@ protected:
 ///   - A 'void runOnFunction()' method.
 template <typename T>
 struct FunctionPass : public detail::PassModel<Function, T, FunctionPassBase> {
-  /// Returns the analysis result for the parent module if it exists.
+  /// Returns the analysis for the parent module if it exists.
   template <typename AnalysisT>
-  llvm::Optional<std::reference_wrapper<AnalysisT>>
-  getCachedModuleAnalysisResult() {
+  llvm::Optional<std::reference_wrapper<AnalysisT>> getCachedModuleAnalysis() {
     return this->getAnalysisManager()
-        .template getCachedModuleResult<AnalysisT>();
+        .template getCachedModuleAnalysis<AnalysisT>();
   }
 };
 
@@ -245,18 +244,18 @@ struct FunctionPass : public detail::PassModel<Function, T, FunctionPassBase> {
 ///   - A 'void runOnModule()' method.
 template <typename T>
 struct ModulePass : public detail::PassModel<Module, T, ModulePassBase> {
-  /// Returns the analysis result for a child function.
-  template <typename AnalysisT>
-  AnalysisT &getFunctionAnalysisResult(Function *f) {
-    return this->getAnalysisManager().template getFunctionResult<AnalysisT>(f);
+  /// Returns the analysis for a child function.
+  template <typename AnalysisT> AnalysisT &getFunctionAnalysis(Function *f) {
+    return this->getAnalysisManager().template getFunctionAnalysis<AnalysisT>(
+        f);
   }
 
-  /// Returns an existing analysis result for a child function if it exists.
+  /// Returns an existing analysis for a child function if it exists.
   template <typename AnalysisT>
   llvm::Optional<std::reference_wrapper<AnalysisT>>
-  getCachedFunctionAnalysisResult(Function *f) {
+  getCachedFunctionAnalysis(Function *f) {
     return this->getAnalysisManager()
-        .template getCachedFunctionResult<AnalysisT>(f);
+        .template getCachedFunctionAnalysis<AnalysisT>(f);
   }
 };
 } // end namespace mlir
index ec1b2471ebb421fcd5ed6bc83d95dc94f1712999..37dfce17bdabfdb6dc9ddebeb21a195cebc3088c 100644 (file)
@@ -223,7 +223,7 @@ void CSE::simplifyBlockList(DominanceInfo &domInfo, BlockList &blockList) {
 }
 
 void CSE::runOnFunction() {
-  simplifyBlockList(getAnalysisResult<DominanceInfo>(),
+  simplifyBlockList(getAnalysis<DominanceInfo>(),
                     getFunction()->getBlockList());
 
   // If no operations were erased, then we mark all analyses as preserved.
index f48f90923ce0b7e1a6b20418322eb1f579bf6e03..f443a34e169ecbbf4a312a3fe0591a0e54dec222 100644 (file)
@@ -217,8 +217,8 @@ void MemRefDataFlowOpt::runOnFunction() {
     return;
   }
 
-  domInfo = &getAnalysisResult<DominanceInfo>();
-  postDomInfo = &getAnalysisResult<PostDominanceInfo>();
+  domInfo = &getAnalysis<DominanceInfo>();
+  postDomInfo = &getAnalysis<PostDominanceInfo>();
 
   loadOpsToErase.clear();
   memrefsToErase.clear();
index 88a91c44252ee09d79a3d6c7cf3fe13845cf1a08..c347102dab8039f9ad7f4116cb2ada14781708b7 100644 (file)
@@ -41,16 +41,16 @@ TEST(AnalysisManagerTest, FineGrainModuleAnalysisPreservation) {
   ModuleAnalysisManager mam(&*module);
 
   // Query two different analyses, but only preserve one before invalidating.
-  mam.getResult<MyAnalysis>();
-  mam.getResult<OtherAnalysis>();
+  mam.getAnalysis<MyAnalysis>();
+  mam.getAnalysis<OtherAnalysis>();
 
   detail::PreservedAnalyses pa;
   pa.preserve<MyAnalysis>();
   mam.invalidate(pa);
 
   // Check that only MyAnalysis is preserved.
-  EXPECT_TRUE(mam.getCachedResult<MyAnalysis>().hasValue());
-  EXPECT_FALSE(mam.getCachedResult<OtherAnalysis>().hasValue());
+  EXPECT_TRUE(mam.getCachedAnalysis<MyAnalysis>().hasValue());
+  EXPECT_FALSE(mam.getCachedAnalysis<OtherAnalysis>().hasValue());
 }
 
 TEST(AnalysisManagerTest, FineGrainFunctionAnalysisPreservation) {
@@ -69,16 +69,16 @@ TEST(AnalysisManagerTest, FineGrainFunctionAnalysisPreservation) {
   FunctionAnalysisManager fam = mam.slice(func1);
 
   // Query two different analyses, but only preserve one before invalidating.
-  fam.getResult<MyAnalysis>();
-  fam.getResult<OtherAnalysis>();
+  fam.getAnalysis<MyAnalysis>();
+  fam.getAnalysis<OtherAnalysis>();
 
   detail::PreservedAnalyses pa;
   pa.preserve<MyAnalysis>();
   fam.invalidate(pa);
 
   // Check that only MyAnalysis is preserved.
-  EXPECT_TRUE(fam.getCachedResult<MyAnalysis>().hasValue());
-  EXPECT_FALSE(fam.getCachedResult<OtherAnalysis>().hasValue());
+  EXPECT_TRUE(fam.getCachedAnalysis<MyAnalysis>().hasValue());
+  EXPECT_FALSE(fam.getCachedAnalysis<OtherAnalysis>().hasValue());
 }
 
 TEST(AnalysisManagerTest, FineGrainChildFunctionAnalysisPreservation) {
@@ -97,16 +97,16 @@ TEST(AnalysisManagerTest, FineGrainChildFunctionAnalysisPreservation) {
   ModuleAnalysisManager mam(&*module);
 
   // Query two different analyses, but only preserve one before invalidating.
-  mam.getFunctionResult<MyAnalysis>(func1);
-  mam.getFunctionResult<OtherAnalysis>(func1);
+  mam.getFunctionAnalysis<MyAnalysis>(func1);
+  mam.getFunctionAnalysis<OtherAnalysis>(func1);
 
   detail::PreservedAnalyses pa;
   pa.preserve<MyAnalysis>();
   mam.invalidate(pa);
 
   // Check that only MyAnalysis is preserved.
-  EXPECT_TRUE(mam.getCachedFunctionResult<MyAnalysis>(func1).hasValue());
-  EXPECT_FALSE(mam.getCachedFunctionResult<OtherAnalysis>(func1).hasValue());
+  EXPECT_TRUE(mam.getCachedFunctionAnalysis<MyAnalysis>(func1).hasValue());
+  EXPECT_FALSE(mam.getCachedFunctionAnalysis<OtherAnalysis>(func1).hasValue());
 }
 
 } // end namespace