Skip to content

Commit 0a25b50

Browse files
authored
[HashRecognize] Introduce dump methods for debug (#142748)
Introduce dump methods to aid interactive debugging with GDB/LLDB. While at it, also fix the header comment in HashRecognize.cpp.
1 parent 54d544b commit 0a25b50

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

llvm/include/llvm/Analysis/HashRecognize.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ using ErrBits = std::tuple<KnownBits, unsigned, bool>;
3535
/// A custom std::array with 256 entries, that also has a print function.
3636
struct CRCTable : public std::array<APInt, 256> {
3737
void print(raw_ostream &OS) const;
38+
39+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
40+
LLVM_DUMP_METHOD void dump() const;
41+
#endif
3842
};
3943

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

9094
void print(raw_ostream &OS) const;
95+
96+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
97+
LLVM_DUMP_METHOD void dump() const;
98+
#endif
9199
};
92100

93101
class HashRecognizePrinterPass

llvm/lib/Analysis/HashRecognize.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===- HashRecognize.h ------------------------------------------*- C++ -*-===//
1+
//===- HashRecognize.cpp ----------------------------------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -274,7 +274,7 @@ struct RecurrenceInfo {
274274
RecurrenceInfo(const Loop &L) : L(L) {}
275275
operator bool() const { return BO; }
276276

277-
void print(raw_ostream &OS, unsigned Indent) const {
277+
void print(raw_ostream &OS, unsigned Indent = 0) const {
278278
OS.indent(Indent) << "Phi: ";
279279
Phi->print(OS);
280280
OS << "\n";
@@ -294,6 +294,10 @@ struct RecurrenceInfo {
294294
}
295295
}
296296

297+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
298+
LLVM_DUMP_METHOD void dump() const { print(dbgs()); }
299+
#endif
300+
297301
bool matchSimpleRecurrence(const PHINode *P);
298302
bool matchConditionalRecurrence(
299303
const PHINode *P,
@@ -628,6 +632,10 @@ void CRCTable::print(raw_ostream &OS) const {
628632
}
629633
}
630634

635+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
636+
void CRCTable::dump() const { print(dbgs()); }
637+
#endif
638+
631639
void HashRecognize::print(raw_ostream &OS) const {
632640
if (!L.isInnermost())
633641
return;
@@ -671,6 +679,10 @@ void HashRecognize::print(raw_ostream &OS) const {
671679
genSarwateTable(Info.RHS, Info.ByteOrderSwapped).print(OS);
672680
}
673681

682+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
683+
void HashRecognize::dump() const { print(dbgs()); }
684+
#endif
685+
674686
HashRecognize::HashRecognize(const Loop &L, ScalarEvolution &SE)
675687
: L(L), SE(SE) {}
676688

0 commit comments

Comments
 (0)