From d43f630de85d0d65f6141885cf06a59d82113d8e Mon Sep 17 00:00:00 2001 From: River Riddle Date: Wed, 6 Mar 2019 12:03:14 -0800 Subject: [PATCH] NFC: Remove 'Result' from the analysis manager api to better reflect the implementation. There is no distinction between analysis computation and result. PiperOrigin-RevId: 237093101 --- mlir/include/mlir/Pass/AnalysisManager.h | 84 ++++++++++----------- mlir/include/mlir/Pass/Pass.h | 33 ++++---- mlir/lib/Transforms/CSE.cpp | 2 +- mlir/lib/Transforms/MemRefDataFlowOpt.cpp | 4 +- mlir/unittests/Pass/AnalysisManagerTest.cpp | 24 +++--- 5 files changed, 73 insertions(+), 74 deletions(-) diff --git a/mlir/include/mlir/Pass/AnalysisManager.h b/mlir/include/mlir/Pass/AnalysisManager.h index cf67c33a5d29..48b04964e173 100644 --- a/mlir/include/mlir/Pass/AnalysisManager.h +++ b/mlir/include/mlir/Pass/AnalysisManager.h @@ -34,7 +34,7 @@ struct AnalysisID { }; //===----------------------------------------------------------------------===// -// Analysis Preservation and Result Modeling +// Analysis Preservation and Concept Modeling //===----------------------------------------------------------------------===// namespace detail { @@ -93,24 +93,24 @@ template 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 class AnalysisResultMap { +template class AnalysisMap { /// A mapping between an analysis id and an existing analysis instance. - using ResultMap = + using ConceptMap = DenseMap>; 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 AnalysisT &getResult() { - typename ResultMap::iterator it; + template AnalysisT &getAnalysis() { + typename ConceptMap::iterator it; bool wasInserted; std::tie(it, wasInserted) = - results.try_emplace(AnalysisID::getID()); + analyses.try_emplace(AnalysisID::getID()); - // 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>(ir); @@ -119,34 +119,34 @@ public: /// Get a cached analysis instance if one exists, otherwise return null. template - llvm::Optional> getCachedResult() const { - auto res = results.find(AnalysisID::getID()); - if (res == results.end()) + llvm::Optional> getCachedAnalysis() const { + auto res = analyses.find(AnalysisID::getID()); + if (res == analyses.end()) return llvm::None; return {static_cast &>(*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 llvm::Optional> - getCachedModuleResult() const { - return parentImpl->getCachedResult(); + getCachedModuleAnalysis() const { + return parentImpl->getCachedAnalysis(); } // Query for the given analysis for the current function. - template AnalysisT &getResult() { - return impl->getResult(); + template AnalysisT &getAnalysis() { + return impl->getAnalysis(); } // Query for a cached entry of the given analysis on the current function. template - llvm::Optional> getCachedResult() const { - return impl->getCachedResult(); + llvm::Optional> getCachedAnalysis() const { + return impl->getCachedAnalysis(); } /// Invalidate any non preserved analyses, @@ -190,16 +190,16 @@ public: void clear() { impl->clear(); } private: - FunctionAnalysisManager(const detail::AnalysisResultMap *parentImpl, - detail::AnalysisResultMap *impl) + FunctionAnalysisManager(const detail::AnalysisMap *parentImpl, + detail::AnalysisMap *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 *parentImpl; + const detail::AnalysisMap *parentImpl; - /// A reference to the results map within the owning analysis manager. - detail::AnalysisResultMap *impl; + /// A reference to the impl analysis map within the owning analysis manager. + detail::AnalysisMap *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 - AnalysisT &getFunctionResult(Function *function) { - return slice(function).getResult(); + AnalysisT &getFunctionAnalysis(Function *function) { + return slice(function).getAnalysis(); } - /// Query for a cached analysis of a function, or return null. + /// Query for a cached analysis of a child function, or return null. template llvm::Optional> - getCachedFunctionResult(Function *function) const { + getCachedFunctionAnalysis(Function *function) const { auto it = functionAnalyses.find(function); if (it == functionAnalyses.end()) return llvm::None; - return it->second.getCachedResult(); + return it->second.getCachedAnalysis(); } - /// 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 AnalysisT &getResult() { - return moduleAnalyses.getResult(); + template AnalysisT &getAnalysis() { + return moduleAnalyses.getAnalysis(); } /// Query for a cached analysis for the module, or return null. template - llvm::Optional> getCachedResult() const { - return moduleAnalyses.getCachedResult(); + llvm::Optional> getCachedAnalysis() const { + return moduleAnalyses.getCachedAnalysis(); } /// 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> functionAnalyses; + DenseMap> functionAnalyses; /// The analyses for the owning module. - detail::AnalysisResultMap moduleAnalyses; + detail::AnalysisMap moduleAnalyses; }; } // end namespace mlir diff --git a/mlir/include/mlir/Pass/Pass.h b/mlir/include/mlir/Pass/Pass.h index 5634ce1b0b42..356b6a95b4fd 100644 --- a/mlir/include/mlir/Pass/Pass.h +++ b/mlir/include/mlir/Pass/Pass.h @@ -191,16 +191,16 @@ protected: this->getPassState().irAndPassFailed.setInt(true); } - /// Query the result of an analysis for the current ir unit. - template AnalysisT &getAnalysisResult() { - return this->getAnalysisManager().template getResult(); + /// Query an analysis for the current ir unit. + template AnalysisT &getAnalysis() { + return this->getAnalysisManager().template getAnalysis(); } - /// 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 - llvm::Optional> getCachedAnalysisResult() { - return this->getAnalysisManager().template getCachedResult(); + llvm::Optional> getCachedAnalysis() { + return this->getAnalysisManager().template getCachedAnalysis(); } /// Mark all analyses as preserved. @@ -230,12 +230,11 @@ protected: /// - A 'void runOnFunction()' method. template struct FunctionPass : public detail::PassModel { - /// Returns the analysis result for the parent module if it exists. + /// Returns the analysis for the parent module if it exists. template - llvm::Optional> - getCachedModuleAnalysisResult() { + llvm::Optional> getCachedModuleAnalysis() { return this->getAnalysisManager() - .template getCachedModuleResult(); + .template getCachedModuleAnalysis(); } }; @@ -245,18 +244,18 @@ struct FunctionPass : public detail::PassModel { /// - A 'void runOnModule()' method. template struct ModulePass : public detail::PassModel { - /// Returns the analysis result for a child function. - template - AnalysisT &getFunctionAnalysisResult(Function *f) { - return this->getAnalysisManager().template getFunctionResult(f); + /// Returns the analysis for a child function. + template AnalysisT &getFunctionAnalysis(Function *f) { + return this->getAnalysisManager().template getFunctionAnalysis( + 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 llvm::Optional> - getCachedFunctionAnalysisResult(Function *f) { + getCachedFunctionAnalysis(Function *f) { return this->getAnalysisManager() - .template getCachedFunctionResult(f); + .template getCachedFunctionAnalysis(f); } }; } // end namespace mlir diff --git a/mlir/lib/Transforms/CSE.cpp b/mlir/lib/Transforms/CSE.cpp index ec1b2471ebb4..37dfce17bdab 100644 --- a/mlir/lib/Transforms/CSE.cpp +++ b/mlir/lib/Transforms/CSE.cpp @@ -223,7 +223,7 @@ void CSE::simplifyBlockList(DominanceInfo &domInfo, BlockList &blockList) { } void CSE::runOnFunction() { - simplifyBlockList(getAnalysisResult(), + simplifyBlockList(getAnalysis(), getFunction()->getBlockList()); // If no operations were erased, then we mark all analyses as preserved. diff --git a/mlir/lib/Transforms/MemRefDataFlowOpt.cpp b/mlir/lib/Transforms/MemRefDataFlowOpt.cpp index f48f90923ce0..f443a34e169e 100644 --- a/mlir/lib/Transforms/MemRefDataFlowOpt.cpp +++ b/mlir/lib/Transforms/MemRefDataFlowOpt.cpp @@ -217,8 +217,8 @@ void MemRefDataFlowOpt::runOnFunction() { return; } - domInfo = &getAnalysisResult(); - postDomInfo = &getAnalysisResult(); + domInfo = &getAnalysis(); + postDomInfo = &getAnalysis(); loadOpsToErase.clear(); memrefsToErase.clear(); diff --git a/mlir/unittests/Pass/AnalysisManagerTest.cpp b/mlir/unittests/Pass/AnalysisManagerTest.cpp index 88a91c44252e..c347102dab80 100644 --- a/mlir/unittests/Pass/AnalysisManagerTest.cpp +++ b/mlir/unittests/Pass/AnalysisManagerTest.cpp @@ -41,16 +41,16 @@ TEST(AnalysisManagerTest, FineGrainModuleAnalysisPreservation) { ModuleAnalysisManager mam(&*module); // Query two different analyses, but only preserve one before invalidating. - mam.getResult(); - mam.getResult(); + mam.getAnalysis(); + mam.getAnalysis(); detail::PreservedAnalyses pa; pa.preserve(); mam.invalidate(pa); // Check that only MyAnalysis is preserved. - EXPECT_TRUE(mam.getCachedResult().hasValue()); - EXPECT_FALSE(mam.getCachedResult().hasValue()); + EXPECT_TRUE(mam.getCachedAnalysis().hasValue()); + EXPECT_FALSE(mam.getCachedAnalysis().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(); - fam.getResult(); + fam.getAnalysis(); + fam.getAnalysis(); detail::PreservedAnalyses pa; pa.preserve(); fam.invalidate(pa); // Check that only MyAnalysis is preserved. - EXPECT_TRUE(fam.getCachedResult().hasValue()); - EXPECT_FALSE(fam.getCachedResult().hasValue()); + EXPECT_TRUE(fam.getCachedAnalysis().hasValue()); + EXPECT_FALSE(fam.getCachedAnalysis().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(func1); - mam.getFunctionResult(func1); + mam.getFunctionAnalysis(func1); + mam.getFunctionAnalysis(func1); detail::PreservedAnalyses pa; pa.preserve(); mam.invalidate(pa); // Check that only MyAnalysis is preserved. - EXPECT_TRUE(mam.getCachedFunctionResult(func1).hasValue()); - EXPECT_FALSE(mam.getCachedFunctionResult(func1).hasValue()); + EXPECT_TRUE(mam.getCachedFunctionAnalysis(func1).hasValue()); + EXPECT_FALSE(mam.getCachedFunctionAnalysis(func1).hasValue()); } } // end namespace -- 2.34.1