[llvm] llvm-reduce: Don't print verifier failed machine functions (PR #109673)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 23 08:11:03 PDT 2024
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/109673
This produces far too much terminal output, particularly for the
instruction reduction. Since it doesn't consider the liveness of of
the instructions it's deleting, it produces quite a lot of verifier
errors.
>From 356cba3a14405771ac0dd32f8e15d3bd536f85d7 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Fri, 22 Apr 2022 17:50:51 -0400
Subject: [PATCH] llvm-reduce: Don't print verifier failed machine functions
This produces far too much terminal output, particularly for the
instruction reduction. Since it doesn't consider the liveness of of
the instructions it's deleting, it produces quite a lot of verifier
errors.
---
llvm/include/llvm/CodeGen/MachineFunction.h | 2 +-
llvm/lib/CodeGen/MachineVerifier.cpp | 33 +++++++++++++--------
llvm/tools/llvm-reduce/ReducerWorkItem.cpp | 6 +++-
3 files changed, 26 insertions(+), 15 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h b/llvm/include/llvm/CodeGen/MachineFunction.h
index aeb72ca24d79b8..d91ce8067c24ae 100644
--- a/llvm/include/llvm/CodeGen/MachineFunction.h
+++ b/llvm/include/llvm/CodeGen/MachineFunction.h
@@ -897,7 +897,7 @@ class LLVM_ABI MachineFunction {
/// for debugger use.
/// \returns true if no problems were found.
bool verify(Pass *p = nullptr, const char *Banner = nullptr,
- bool AbortOnError = true) const;
+ bool AbortOnError = true, bool PrintFuncOnError = true) const;
/// Run the current MachineFunction through the machine code verifier, useful
/// for debugger use.
diff --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp
index 27664207d1e696..d155d51ee18791 100644
--- a/llvm/lib/CodeGen/MachineVerifier.cpp
+++ b/llvm/lib/CodeGen/MachineVerifier.cpp
@@ -94,16 +94,18 @@ using namespace llvm;
namespace {
struct MachineVerifier {
- MachineVerifier(MachineFunctionAnalysisManager &MFAM, const char *b)
- : MFAM(&MFAM), Banner(b) {}
+ MachineVerifier(MachineFunctionAnalysisManager &MFAM, const char *b,
+ bool PrintFuncOnError = true)
+ : MFAM(&MFAM), Banner(b), PrintFuncOnError(PrintFuncOnError) {}
- MachineVerifier(Pass *pass, const char *b) : PASS(pass), Banner(b) {}
+ MachineVerifier(Pass *pass, const char *b, bool PrintFuncOnError = true)
+ : PASS(pass), Banner(b), PrintFuncOnError(PrintFuncOnError) {}
MachineVerifier(const char *b, LiveVariables *LiveVars,
LiveIntervals *LiveInts, LiveStacks *LiveStks,
- SlotIndexes *Indexes)
- : Banner(b), LiveVars(LiveVars), LiveInts(LiveInts), LiveStks(LiveStks),
- Indexes(Indexes) {}
+ SlotIndexes *Indexes, bool PrintFuncOnError = true)
+ : Banner(b), PrintFuncOnError(PrintFuncOnError), LiveVars(LiveVars),
+ LiveInts(LiveInts), LiveStks(LiveStks), Indexes(Indexes) {}
unsigned verify(const MachineFunction &MF);
@@ -118,6 +120,7 @@ namespace {
const RegisterBankInfo *RBI = nullptr;
unsigned foundErrors = 0;
+ bool PrintFuncOnError = false;
// Avoid querying the MachineFunctionProperties for each operand.
bool isFunctionRegBankSelected = false;
@@ -379,10 +382,11 @@ void llvm::verifyMachineFunction(const std::string &Banner,
report_fatal_error("Found " + Twine(FoundErrors) + " machine code errors.");
}
-bool MachineFunction::verify(Pass *p, const char *Banner, bool AbortOnErrors)
- const {
+bool MachineFunction::verify(Pass *p, const char *Banner, bool AbortOnErrors,
+ bool PrintFuncOnError) const {
MachineFunction &MF = const_cast<MachineFunction&>(*this);
- unsigned FoundErrors = MachineVerifier(p, Banner).verify(MF);
+ unsigned FoundErrors =
+ MachineVerifier(p, Banner, PrintFuncOnError).verify(MF);
if (AbortOnErrors && FoundErrors)
report_fatal_error("Found "+Twine(FoundErrors)+" machine code errors.");
return FoundErrors == 0;
@@ -544,10 +548,13 @@ void MachineVerifier::report(const char *msg, const MachineFunction *MF) {
if (!foundErrors++) {
if (Banner)
errs() << "# " << Banner << '\n';
- if (LiveInts != nullptr)
- LiveInts->print(errs());
- else
- MF->print(errs(), Indexes);
+
+ if (PrintFuncOnError) {
+ if (LiveInts != nullptr)
+ LiveInts->print(errs());
+ else
+ MF->print(errs(), Indexes);
+ }
}
errs() << "*** Bad machine code: " << msg << " ***\n"
<< "- function: " << MF->getName() << "\n";
diff --git a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
index 1510e9fb32007e..6ccfaff8fa3e15 100644
--- a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
+++ b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
@@ -450,7 +450,11 @@ bool ReducerWorkItem::verify(raw_fd_ostream *OS) const {
for (const Function &F : getModule()) {
if (const MachineFunction *MF = MMI->getMachineFunction(F)) {
- if (!MF->verify(nullptr, "", /*AbortOnError=*/false))
+ // With the current state of quality, most reduction attempts fail the
+ // machine verifier. Avoid spamming large function dumps on nearly every
+ // attempt until the situation is better.
+ if (!MF->verify(nullptr, "", /*AbortOnError=*/false,
+ /*PrintFuncOnError=*/false))
return true;
}
}
More information about the llvm-commits
mailing list