Skip to content

Conversation

@boomanaiden154
Copy link
Contributor

This patch makes llvm-exegesis emit an error when the machine function fails in MachineVerification rather than aborting. This allows downstream users (particularly https://github.com/google/gematria) to handle these errors rather than having the entire process crash. This essentially be NFC from the user perspective minus the addition of the new error message.

This patch makes llvm-exegesis emit an error when the machine function
fails in MachineVerification rather than aborting. This allows
downstream users (particularly https://github.com/google/gematria) to
handle these errors rather than having the entire process crash. This
essentially be NFC from the user perspective minus the addition of the
new error message.
@llvmbot
Copy link
Member

llvmbot commented Apr 28, 2025

@llvm/pr-subscribers-tools-llvm-exegesis

Author: Aiden Grossman (boomanaiden154)

Changes

This patch makes llvm-exegesis emit an error when the machine function fails in MachineVerification rather than aborting. This allows downstream users (particularly https://github.com/google/gematria) to handle these errors rather than having the entire process crash. This essentially be NFC from the user perspective minus the addition of the new error message.


Full diff: https://github.com/llvm/llvm-project/pull/137581.diff

1 Files Affected:

  • (modified) llvm/tools/llvm-exegesis/lib/Assembler.cpp (+6-3)
diff --git a/llvm/tools/llvm-exegesis/lib/Assembler.cpp b/llvm/tools/llvm-exegesis/lib/Assembler.cpp
index f638478e0c51d..67f3d75a5e879 100644
--- a/llvm/tools/llvm-exegesis/lib/Assembler.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Assembler.cpp
@@ -29,6 +29,7 @@
 #include "llvm/MC/MCInstrInfo.h"
 #include "llvm/Object/SymbolSize.h"
 #include "llvm/Support/Alignment.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -323,10 +324,8 @@ Error assembleToStream(const ExegesisTarget &ET,
   TPC->printAndVerify("After ExegesisTarget::addTargetSpecificPasses");
   // Adding the following passes:
   // - postrapseudos: expands pseudo return instructions used on some targets.
-  // - machineverifier: checks that the MachineFunction is well formed.
   // - prologepilog: saves and restore callee saved registers.
-  for (const char *PassName :
-       {"postrapseudos", "machineverifier", "prologepilog"})
+  for (const char *PassName : {"postrapseudos", "prologepilog"})
     if (addPass(PM, PassName, *TPC))
       return make_error<Failure>("Unable to add a mandatory pass");
   TPC->setInitialized();
@@ -337,6 +336,10 @@ Error assembleToStream(const ExegesisTarget &ET,
     return make_error<Failure>("Cannot add AsmPrinter passes");
 
   PM.run(*Module); // Run all the passes
+  bool MFWellFormed =
+      MF.verify(nullptr, "llvm-exegesis Assembly", &outs(), false);
+  if (!MFWellFormed)
+    return make_error<Failure>("The machine function failed verification.");
   return Error::success();
 }
 

@boomanaiden154 boomanaiden154 requested a review from mshockwave May 15, 2025 22:44
@boomanaiden154
Copy link
Contributor Author

@mshockwave Bump on this when you get a chance. Thanks!

Copy link
Member

@mshockwave mshockwave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry this slipped through my radar. LGTM.

@boomanaiden154 boomanaiden154 merged commit a690852 into llvm:main May 20, 2025
11 checks passed
@boomanaiden154 boomanaiden154 deleted the exegesis-mc-verify-error-not-abort branch May 20, 2025 21:48
boomanaiden154 added a commit to boomanaiden154/gematria that referenced this pull request May 20, 2025
This includes llvm/llvm-project#137581 which
makes it a bit nicer to deal with verification failures, some of which
come from inline assembly and would be difficult to fix within LLVM.
boomanaiden154 added a commit to google/gematria that referenced this pull request May 21, 2025
This includes llvm/llvm-project#137581 which
makes it a bit nicer to deal with verification failures, some of which
come from inline assembly and would be difficult to fix within LLVM.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants