Skip to content

Commit a690852

Browse files
[llvm-exegesis] Error instead of aborting on verification failure (#137581)
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.
1 parent 98595cf commit a690852

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

llvm/tools/llvm-exegesis/lib/Assembler.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "llvm/MC/MCInstrInfo.h"
3030
#include "llvm/Object/SymbolSize.h"
3131
#include "llvm/Support/Alignment.h"
32+
#include "llvm/Support/Error.h"
3233
#include "llvm/Support/MemoryBuffer.h"
3334
#include "llvm/Support/raw_ostream.h"
3435

@@ -323,10 +324,8 @@ Error assembleToStream(const ExegesisTarget &ET,
323324
TPC->printAndVerify("After ExegesisTarget::addTargetSpecificPasses");
324325
// Adding the following passes:
325326
// - postrapseudos: expands pseudo return instructions used on some targets.
326-
// - machineverifier: checks that the MachineFunction is well formed.
327327
// - prologepilog: saves and restore callee saved registers.
328-
for (const char *PassName :
329-
{"postrapseudos", "machineverifier", "prologepilog"})
328+
for (const char *PassName : {"postrapseudos", "prologepilog"})
330329
if (addPass(PM, PassName, *TPC))
331330
return make_error<Failure>("Unable to add a mandatory pass");
332331
TPC->setInitialized();
@@ -337,6 +336,10 @@ Error assembleToStream(const ExegesisTarget &ET,
337336
return make_error<Failure>("Cannot add AsmPrinter passes");
338337

339338
PM.run(*Module); // Run all the passes
339+
bool MFWellFormed =
340+
MF.verify(nullptr, "llvm-exegesis Assembly", &outs(), false);
341+
if (!MFWellFormed)
342+
return make_error<Failure>("The machine function failed verification.");
340343
return Error::success();
341344
}
342345

0 commit comments

Comments
 (0)