diff --git a/llvm/include/llvm/Analysis/HashRecognize.h b/llvm/include/llvm/Analysis/HashRecognize.h index c169383bf7b08..0361dfcd23528 100644 --- a/llvm/include/llvm/Analysis/HashRecognize.h +++ b/llvm/include/llvm/Analysis/HashRecognize.h @@ -84,12 +84,13 @@ class HashRecognize { public: HashRecognize(const Loop &L, ScalarEvolution &SE); - // The main analysis entry point. + // The main analysis entry points. std::variant recognizeCRC() const; + std::optional getResult() const; // Auxilary entry point after analysis to interleave the generating polynomial // and return a 256-entry CRC table. - CRCTable genSarwateTable(const APInt &GenPoly, bool ByteOrderSwapped) const; + static CRCTable genSarwateTable(const APInt &GenPoly, bool ByteOrderSwapped); void print(raw_ostream &OS) const; @@ -107,15 +108,6 @@ class HashRecognizePrinterPass PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &); }; - -class HashRecognizeAnalysis : public AnalysisInfoMixin { - friend AnalysisInfoMixin; - static AnalysisKey Key; - -public: - using Result = HashRecognize; - Result run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR); -}; } // namespace llvm #endif diff --git a/llvm/lib/Analysis/HashRecognize.cpp b/llvm/lib/Analysis/HashRecognize.cpp index d11602f921872..1a5dfbe4bed6e 100644 --- a/llvm/lib/Analysis/HashRecognize.cpp +++ b/llvm/lib/Analysis/HashRecognize.cpp @@ -472,7 +472,7 @@ static bool checkExtractBits(const KnownBits &Known, unsigned N, /// polynomial. The optimization technique of table-lookup for CRC is also /// called the Sarwate algorithm. CRCTable HashRecognize::genSarwateTable(const APInt &GenPoly, - bool ByteOrderSwapped) const { + bool ByteOrderSwapped) { unsigned BW = GenPoly.getBitWidth(); CRCTable Table; Table[0] = APInt::getZero(BW); @@ -686,6 +686,13 @@ void HashRecognize::print(raw_ostream &OS) const { void HashRecognize::dump() const { print(dbgs()); } #endif +std::optional HashRecognize::getResult() const { + auto Res = HashRecognize(L, SE).recognizeCRC(); + if (std::holds_alternative(Res)) + return std::get(Res); + return std::nullopt; +} + HashRecognize::HashRecognize(const Loop &L, ScalarEvolution &SE) : L(L), SE(SE) {} @@ -693,13 +700,6 @@ PreservedAnalyses HashRecognizePrinterPass::run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &) { - AM.getResult(L, AR).print(OS); + HashRecognize(L, AR.SE).print(OS); return PreservedAnalyses::all(); } - -HashRecognize HashRecognizeAnalysis::run(Loop &L, LoopAnalysisManager &AM, - LoopStandardAnalysisResults &AR) { - return {L, AR.SE}; -} - -AnalysisKey HashRecognizeAnalysis::Key; diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def index f761d0dab09a8..ec14c6a9211d9 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -672,7 +672,6 @@ LOOPNEST_PASS("no-op-loopnest", NoOpLoopNestPass()) #define LOOP_ANALYSIS(NAME, CREATE_PASS) #endif LOOP_ANALYSIS("ddg", DDGAnalysis()) -LOOP_ANALYSIS("hash-recognize", HashRecognizeAnalysis()) LOOP_ANALYSIS("iv-users", IVUsersAnalysis()) LOOP_ANALYSIS("no-op-loop", NoOpLoopAnalysis()) LOOP_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis(PIC))