Skip to content

Commit 74054ca

Browse files
authored
[HashRecognize] Make it a non-PM analysis (#144742)
Make HashRecognize a non-PassManager analysis that can be called to get the result on-demand, creating a new getResult() entry-point. The issue was discovered when attempting to use the analysis to perform a transform in LoopIdiomRecognize.
1 parent 1c35fe4 commit 74054ca

File tree

3 files changed

+12
-21
lines changed

3 files changed

+12
-21
lines changed

llvm/include/llvm/Analysis/HashRecognize.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,13 @@ class HashRecognize {
8484
public:
8585
HashRecognize(const Loop &L, ScalarEvolution &SE);
8686

87-
// The main analysis entry point.
87+
// The main analysis entry points.
8888
std::variant<PolynomialInfo, ErrBits, StringRef> recognizeCRC() const;
89+
std::optional<PolynomialInfo> getResult() const;
8990

9091
// Auxilary entry point after analysis to interleave the generating polynomial
9192
// and return a 256-entry CRC table.
92-
CRCTable genSarwateTable(const APInt &GenPoly, bool ByteOrderSwapped) const;
93+
static CRCTable genSarwateTable(const APInt &GenPoly, bool ByteOrderSwapped);
9394

9495
void print(raw_ostream &OS) const;
9596

@@ -107,15 +108,6 @@ class HashRecognizePrinterPass
107108
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM,
108109
LoopStandardAnalysisResults &AR, LPMUpdater &);
109110
};
110-
111-
class HashRecognizeAnalysis : public AnalysisInfoMixin<HashRecognizeAnalysis> {
112-
friend AnalysisInfoMixin<HashRecognizeAnalysis>;
113-
static AnalysisKey Key;
114-
115-
public:
116-
using Result = HashRecognize;
117-
Result run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR);
118-
};
119111
} // namespace llvm
120112

121113
#endif

llvm/lib/Analysis/HashRecognize.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ static bool checkExtractBits(const KnownBits &Known, unsigned N,
472472
/// polynomial. The optimization technique of table-lookup for CRC is also
473473
/// called the Sarwate algorithm.
474474
CRCTable HashRecognize::genSarwateTable(const APInt &GenPoly,
475-
bool ByteOrderSwapped) const {
475+
bool ByteOrderSwapped) {
476476
unsigned BW = GenPoly.getBitWidth();
477477
CRCTable Table;
478478
Table[0] = APInt::getZero(BW);
@@ -686,20 +686,20 @@ void HashRecognize::print(raw_ostream &OS) const {
686686
void HashRecognize::dump() const { print(dbgs()); }
687687
#endif
688688

689+
std::optional<PolynomialInfo> HashRecognize::getResult() const {
690+
auto Res = HashRecognize(L, SE).recognizeCRC();
691+
if (std::holds_alternative<PolynomialInfo>(Res))
692+
return std::get<PolynomialInfo>(Res);
693+
return std::nullopt;
694+
}
695+
689696
HashRecognize::HashRecognize(const Loop &L, ScalarEvolution &SE)
690697
: L(L), SE(SE) {}
691698

692699
PreservedAnalyses HashRecognizePrinterPass::run(Loop &L,
693700
LoopAnalysisManager &AM,
694701
LoopStandardAnalysisResults &AR,
695702
LPMUpdater &) {
696-
AM.getResult<HashRecognizeAnalysis>(L, AR).print(OS);
703+
HashRecognize(L, AR.SE).print(OS);
697704
return PreservedAnalyses::all();
698705
}
699-
700-
HashRecognize HashRecognizeAnalysis::run(Loop &L, LoopAnalysisManager &AM,
701-
LoopStandardAnalysisResults &AR) {
702-
return {L, AR.SE};
703-
}
704-
705-
AnalysisKey HashRecognizeAnalysis::Key;

llvm/lib/Passes/PassRegistry.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,6 @@ LOOPNEST_PASS("no-op-loopnest", NoOpLoopNestPass())
672672
#define LOOP_ANALYSIS(NAME, CREATE_PASS)
673673
#endif
674674
LOOP_ANALYSIS("ddg", DDGAnalysis())
675-
LOOP_ANALYSIS("hash-recognize", HashRecognizeAnalysis())
676675
LOOP_ANALYSIS("iv-users", IVUsersAnalysis())
677676
LOOP_ANALYSIS("no-op-loop", NoOpLoopAnalysis())
678677
LOOP_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis(PIC))

0 commit comments

Comments
 (0)