Skip to content

Commit c47df76

Browse files
committed
[HashRecognize] Strip function_ref
1 parent b7ce778 commit c47df76

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

llvm/include/llvm/Analysis/HashRecognize.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,13 @@ struct PolynomialInfo {
6666
// Set to true in the case of big-endian.
6767
bool ByteOrderSwapped;
6868

69-
// A function_ref to generate the Sarwate lookup-table, which can be used to
70-
// optimize CRC in the absence of target-specific instructions.
71-
function_ref<CRCTable(const APInt &, bool)> GenSarwateTable;
72-
7369
// An optional auxiliary checksum that augments the LHS. In the case of CRC,
7470
// it is XOR'ed with the LHS, so that the computation's final remainder is
7571
// zero.
7672
Value *LHSAux;
7773

7874
PolynomialInfo(unsigned TripCount, Value *LHS, const APInt &RHS,
7975
Value *ComputedValue, bool ByteOrderSwapped,
80-
function_ref<CRCTable(const APInt &, bool)> GenSarwateTable,
8176
Value *LHSAux = nullptr);
8277
};
8378

@@ -93,6 +88,10 @@ class HashRecognize {
9388
std::variant<PolynomialInfo, ErrBits, StringRef> recognizeCRC() const;
9489
std::optional<PolynomialInfo> getResult() const;
9590

91+
// Auxilary entry point after analysis to interleave the generating polynomial
92+
// and return a 256-entry CRC table.
93+
static CRCTable genSarwateTable(const APInt &GenPoly, bool ByteOrderSwapped);
94+
9695
void print(raw_ostream &OS) const;
9796

9897
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

llvm/lib/Analysis/HashRecognize.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -442,13 +442,11 @@ getRecurrences(BasicBlock *LoopLatch, const PHINode *IndVar, const Loop &L) {
442442
return std::make_pair(SimpleRecurrence, ConditionalRecurrence);
443443
}
444444

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)
445+
PolynomialInfo::PolynomialInfo(unsigned TripCount, Value *LHS, const APInt &RHS,
446+
Value *ComputedValue, bool ByteOrderSwapped,
447+
Value *LHSAux)
449448
: TripCount(TripCount), LHS(LHS), RHS(RHS), ComputedValue(ComputedValue),
450-
ByteOrderSwapped(ByteOrderSwapped), GenSarwateTable(GenSarwateTable),
451-
LHSAux(LHSAux) {}
449+
ByteOrderSwapped(ByteOrderSwapped), LHSAux(LHSAux) {}
452450

453451
/// In the big-endian case, checks the bottom N bits against CheckFn, and that
454452
/// the rest are unknown. In the little-endian case, checks the top N bits
@@ -473,7 +471,8 @@ static bool checkExtractBits(const KnownBits &Known, unsigned N,
473471
/// Generate a lookup table of 256 entries by interleaving the generating
474472
/// polynomial. The optimization technique of table-lookup for CRC is also
475473
/// called the Sarwate algorithm.
476-
static CRCTable genSarwateTable(const APInt &GenPoly, bool ByteOrderSwapped) {
474+
CRCTable HashRecognize::genSarwateTable(const APInt &GenPoly,
475+
bool ByteOrderSwapped) {
477476
unsigned BW = GenPoly.getBitWidth();
478477
CRCTable Table;
479478
Table[0] = APInt::getZero(BW);
@@ -626,7 +625,7 @@ HashRecognize::recognizeCRC() const {
626625

627626
Value *LHSAux = SimpleRecurrence ? SimpleRecurrence.Start : nullptr;
628627
return PolynomialInfo(TC, ConditionalRecurrence.Start, GenPoly, ComputedValue,
629-
*ByteOrderSwapped, genSarwateTable, LHSAux);
628+
*ByteOrderSwapped, LHSAux);
630629
}
631630

632631
void CRCTable::print(raw_ostream &OS) const {
@@ -680,7 +679,7 @@ void HashRecognize::print(raw_ostream &OS) const {
680679
OS << "\n";
681680
}
682681
OS.indent(2) << "Computed CRC lookup table:\n";
683-
Info.GenSarwateTable(Info.RHS, Info.ByteOrderSwapped).print(OS);
682+
genSarwateTable(Info.RHS, Info.ByteOrderSwapped).print(OS);
684683
}
685684

686685
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

0 commit comments

Comments
 (0)