From 719e574d38e02be7550dfcbc5060b612a399a24c Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Wed, 4 Jun 2025 10:08:58 +0100 Subject: [PATCH 1/2] [HashRecognize] Introduce dump methods for debug Introduce dump methods to aid interactive debugging with GDB/LLDB. While at it, also fix the header comment in HashRecognize.cpp. --- llvm/include/llvm/Analysis/HashRecognize.h | 12 ++++++++++-- llvm/lib/Analysis/HashRecognize.cpp | 16 ++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/llvm/include/llvm/Analysis/HashRecognize.h b/llvm/include/llvm/Analysis/HashRecognize.h index 7a31ab681bed5..86051f0580719 100644 --- a/llvm/include/llvm/Analysis/HashRecognize.h +++ b/llvm/include/llvm/Analysis/HashRecognize.h @@ -34,7 +34,11 @@ using ErrBits = std::tuple; /// A custom std::array with 256 entries, that also has a print function. struct CRCTable : public std::array { - void print(raw_ostream &OS) const; + LLVM_DUMP_METHOD 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 @@ -87,7 +91,11 @@ class HashRecognize { // and return a 256-entry CRC table. CRCTable genSarwateTable(const APInt &GenPoly, bool ByteOrderSwapped) const; - void print(raw_ostream &OS) const; + LLVM_DUMP_METHOD void print(raw_ostream &OS) const; + +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) + LLVM_DUMP_METHOD void dump() const; +#endif }; class HashRecognizePrinterPass diff --git a/llvm/lib/Analysis/HashRecognize.cpp b/llvm/lib/Analysis/HashRecognize.cpp index c6e9f2b64f876..22e88eacd6ff8 100644 --- a/llvm/lib/Analysis/HashRecognize.cpp +++ b/llvm/lib/Analysis/HashRecognize.cpp @@ -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. @@ -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 { + LLVM_DUMP_METHOD void print(raw_ostream &OS, unsigned Indent = 0) const { OS.indent(Indent) << "Phi: "; Phi->print(OS); OS << "\n"; @@ -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, @@ -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; @@ -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) {} From 44500bebfa6861d85fec2b5238dedbed9a81d51c Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Wed, 4 Jun 2025 13:39:34 +0100 Subject: [PATCH 2/2] [HashRecognize] Strip LLVM_DUMP_METHOD from print fns --- llvm/include/llvm/Analysis/HashRecognize.h | 4 ++-- llvm/lib/Analysis/HashRecognize.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/Analysis/HashRecognize.h b/llvm/include/llvm/Analysis/HashRecognize.h index 86051f0580719..8ab68a5dc2cb1 100644 --- a/llvm/include/llvm/Analysis/HashRecognize.h +++ b/llvm/include/llvm/Analysis/HashRecognize.h @@ -34,7 +34,7 @@ using ErrBits = std::tuple; /// A custom std::array with 256 entries, that also has a print function. struct CRCTable : public std::array { - LLVM_DUMP_METHOD void print(raw_ostream &OS) const; + void print(raw_ostream &OS) const; #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) LLVM_DUMP_METHOD void dump() const; @@ -91,7 +91,7 @@ class HashRecognize { // and return a 256-entry CRC table. CRCTable genSarwateTable(const APInt &GenPoly, bool ByteOrderSwapped) const; - LLVM_DUMP_METHOD void print(raw_ostream &OS) const; + void print(raw_ostream &OS) const; #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) LLVM_DUMP_METHOD void dump() const; diff --git a/llvm/lib/Analysis/HashRecognize.cpp b/llvm/lib/Analysis/HashRecognize.cpp index 22e88eacd6ff8..b245548dea6d5 100644 --- a/llvm/lib/Analysis/HashRecognize.cpp +++ b/llvm/lib/Analysis/HashRecognize.cpp @@ -274,7 +274,7 @@ struct RecurrenceInfo { RecurrenceInfo(const Loop &L) : L(L) {} operator bool() const { return BO; } - LLVM_DUMP_METHOD void print(raw_ostream &OS, unsigned Indent = 0) const { + void print(raw_ostream &OS, unsigned Indent = 0) const { OS.indent(Indent) << "Phi: "; Phi->print(OS); OS << "\n";