diff options
Diffstat (limited to 'llvm/lib/Analysis/HashRecognize.cpp')
| -rw-r--r-- | llvm/lib/Analysis/HashRecognize.cpp | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/llvm/lib/Analysis/HashRecognize.cpp b/llvm/lib/Analysis/HashRecognize.cpp index 1edb8b3bdc9a..1a5dfbe4bed6 100644 --- a/llvm/lib/Analysis/HashRecognize.cpp +++ b/llvm/lib/Analysis/HashRecognize.cpp @@ -442,9 +442,9 @@ getRecurrences(BasicBlock *LoopLatch, const PHINode *IndVar, const Loop &L) { return std::make_pair(SimpleRecurrence, ConditionalRecurrence); } -PolynomialInfo::PolynomialInfo(unsigned TripCount, const Value *LHS, - const APInt &RHS, const Value *ComputedValue, - bool ByteOrderSwapped, const Value *LHSAux) +PolynomialInfo::PolynomialInfo(unsigned TripCount, Value *LHS, const APInt &RHS, + Value *ComputedValue, bool ByteOrderSwapped, + Value *LHSAux) : TripCount(TripCount), LHS(LHS), RHS(RHS), ComputedValue(ComputedValue), ByteOrderSwapped(ByteOrderSwapped), LHSAux(LHSAux) {} @@ -472,13 +472,13 @@ 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); if (ByteOrderSwapped) { - APInt CRCInit(BW, 128); + APInt CRCInit = APInt::getSignedMinValue(BW); for (unsigned I = 1; I < 256; I <<= 1) { CRCInit = CRCInit.shl(1) ^ (CRCInit.isSignBitSet() ? GenPoly : APInt::getZero(BW)); @@ -561,14 +561,14 @@ std::variant<PolynomialInfo, ErrBits, StringRef> HashRecognize::recognizeCRC() const { if (!L.isInnermost()) return "Loop is not innermost"; - unsigned TC = SE.getSmallConstantMaxTripCount(&L); - if (!TC || TC > 256) - return "Unable to find a small constant trip count"; BasicBlock *Latch = L.getLoopLatch(); BasicBlock *Exit = L.getExitBlock(); const PHINode *IndVar = L.getCanonicalInductionVariable(); - if (!Latch || !Exit || !IndVar) + if (!Latch || !Exit || !IndVar || L.getNumBlocks() != 1) return "Loop not in canonical form"; + unsigned TC = SE.getSmallConstantTripCount(&L); + if (!TC || TC > 256 || TC % 8) + return "Unable to find a small constant byte-multiple trip count"; auto R = getRecurrences(Latch, IndVar, L); if (!R) @@ -623,7 +623,7 @@ HashRecognize::recognizeCRC() const { if (!checkExtractBits(ResultBits, TC, IsZero, *ByteOrderSwapped)) return ErrBits(ResultBits, TC, *ByteOrderSwapped); - const Value *LHSAux = SimpleRecurrence ? SimpleRecurrence.Start : nullptr; + Value *LHSAux = SimpleRecurrence ? SimpleRecurrence.Start : nullptr; return PolynomialInfo(TC, ConditionalRecurrence.Start, GenPoly, ComputedValue, *ByteOrderSwapped, LHSAux); } @@ -686,6 +686,13 @@ void HashRecognize::print(raw_ostream &OS) const { void HashRecognize::dump() const { print(dbgs()); } #endif +std::optional<PolynomialInfo> HashRecognize::getResult() const { + auto Res = HashRecognize(L, SE).recognizeCRC(); + if (std::holds_alternative<PolynomialInfo>(Res)) + return std::get<PolynomialInfo>(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<HashRecognizeAnalysis>(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; |
