Skip to content

[HashRecognize] Introduce dump methods for debug #142748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions llvm/include/llvm/Analysis/HashRecognize.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ using ErrBits = std::tuple<KnownBits, unsigned, bool>;
/// A custom std::array with 256 entries, that also has a print function.
struct CRCTable : public std::array<APInt, 256> {
void print(raw_ostream &OS) const;

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void dump() const;
#endif
};

/// The structure that is returned when a polynomial algorithm was recognized by
Expand Down Expand Up @@ -88,6 +92,10 @@ class HashRecognize {
CRCTable genSarwateTable(const APInt &GenPoly, bool ByteOrderSwapped) const;

void print(raw_ostream &OS) const;

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void dump() const;
#endif
};

class HashRecognizePrinterPass
Expand Down
16 changes: 14 additions & 2 deletions llvm/lib/Analysis/HashRecognize.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===- HashRecognize.h ------------------------------------------*- C++ -*-===//
//===- HashRecognize.cpp ----------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down Expand Up @@ -274,7 +274,7 @@ struct RecurrenceInfo {
RecurrenceInfo(const Loop &L) : L(L) {}
operator bool() const { return BO; }

void print(raw_ostream &OS, unsigned Indent) const {
void print(raw_ostream &OS, unsigned Indent = 0) const {
OS.indent(Indent) << "Phi: ";
Phi->print(OS);
OS << "\n";
Expand All @@ -294,6 +294,10 @@ struct RecurrenceInfo {
}
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void dump() const { print(dbgs()); }
#endif

bool matchSimpleRecurrence(const PHINode *P);
bool matchConditionalRecurrence(
const PHINode *P,
Expand Down Expand Up @@ -628,6 +632,10 @@ void CRCTable::print(raw_ostream &OS) const {
}
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void CRCTable::dump() const { print(dbgs()); }
#endif

void HashRecognize::print(raw_ostream &OS) const {
if (!L.isInnermost())
return;
Expand Down Expand Up @@ -671,6 +679,10 @@ void HashRecognize::print(raw_ostream &OS) const {
genSarwateTable(Info.RHS, Info.ByteOrderSwapped).print(OS);
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void HashRecognize::dump() const { print(dbgs()); }
#endif

HashRecognize::HashRecognize(const Loop &L, ScalarEvolution &SE)
: L(L), SE(SE) {}

Expand Down