@@ -442,11 +442,13 @@ getRecurrences(BasicBlock *LoopLatch, const PHINode *IndVar, const Loop &L) {
442
442
return std::make_pair (SimpleRecurrence, ConditionalRecurrence);
443
443
}
444
444
445
- PolynomialInfo::PolynomialInfo (unsigned TripCount, Value *LHS, const APInt &RHS,
446
- Value *ComputedValue, bool ByteOrderSwapped,
447
- Value *LHSAux)
445
+ PolynomialInfo::PolynomialInfo (
446
+ unsigned TripCount, Value *LHS, const APInt &RHS, Value *ComputedValue,
447
+ bool ByteOrderSwapped,
448
+ function_ref<CRCTable(const APInt &, bool )> GenSarwateTable, Value *LHSAux)
448
449
: TripCount(TripCount), LHS(LHS), RHS(RHS), ComputedValue(ComputedValue),
449
- ByteOrderSwapped(ByteOrderSwapped), LHSAux(LHSAux) {}
450
+ ByteOrderSwapped(ByteOrderSwapped), GenSarwateTable(GenSarwateTable),
451
+ LHSAux(LHSAux) {}
450
452
451
453
// / In the big-endian case, checks the bottom N bits against CheckFn, and that
452
454
// / the rest are unknown. In the little-endian case, checks the top N bits
@@ -471,8 +473,7 @@ static bool checkExtractBits(const KnownBits &Known, unsigned N,
471
473
// / Generate a lookup table of 256 entries by interleaving the generating
472
474
// / polynomial. The optimization technique of table-lookup for CRC is also
473
475
// / called the Sarwate algorithm.
474
- CRCTable HashRecognize::genSarwateTable (const APInt &GenPoly,
475
- bool ByteOrderSwapped) const {
476
+ static CRCTable genSarwateTable (const APInt &GenPoly, bool ByteOrderSwapped) {
476
477
unsigned BW = GenPoly.getBitWidth ();
477
478
CRCTable Table;
478
479
Table[0 ] = APInt::getZero (BW);
@@ -625,7 +626,7 @@ HashRecognize::recognizeCRC() const {
625
626
626
627
Value *LHSAux = SimpleRecurrence ? SimpleRecurrence.Start : nullptr ;
627
628
return PolynomialInfo (TC, ConditionalRecurrence.Start , GenPoly, ComputedValue,
628
- *ByteOrderSwapped, LHSAux);
629
+ *ByteOrderSwapped, genSarwateTable, LHSAux);
629
630
}
630
631
631
632
void CRCTable::print (raw_ostream &OS) const {
@@ -679,27 +680,27 @@ void HashRecognize::print(raw_ostream &OS) const {
679
680
OS << " \n " ;
680
681
}
681
682
OS.indent (2 ) << " Computed CRC lookup table:\n " ;
682
- genSarwateTable (Info.RHS , Info.ByteOrderSwapped ).print (OS);
683
+ Info. GenSarwateTable (Info.RHS , Info.ByteOrderSwapped ).print (OS);
683
684
}
684
685
685
686
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
686
687
void HashRecognize::dump () const { print (dbgs ()); }
687
688
#endif
688
689
690
+ std::optional<PolynomialInfo> HashRecognize::getResult () const {
691
+ auto Res = HashRecognize (L, SE).recognizeCRC ();
692
+ if (std::holds_alternative<PolynomialInfo>(Res))
693
+ return std::get<PolynomialInfo>(Res);
694
+ return std::nullopt;
695
+ }
696
+
689
697
HashRecognize::HashRecognize (const Loop &L, ScalarEvolution &SE)
690
698
: L(L), SE(SE) {}
691
699
692
700
PreservedAnalyses HashRecognizePrinterPass::run (Loop &L,
693
701
LoopAnalysisManager &AM,
694
702
LoopStandardAnalysisResults &AR,
695
703
LPMUpdater &) {
696
- AM. getResult <HashRecognizeAnalysis> (L, AR).print (OS);
704
+ HashRecognize (L, AR. SE ).print (OS);
697
705
return PreservedAnalyses::all ();
698
706
}
699
-
700
- HashRecognize HashRecognizeAnalysis::run (Loop &L, LoopAnalysisManager &AM,
701
- LoopStandardAnalysisResults &AR) {
702
- return {L, AR.SE };
703
- }
704
-
705
- AnalysisKey HashRecognizeAnalysis::Key;
0 commit comments