[llvm] e7939d0 - [Instrumentation] Support verifying machine function (#90931)
via llvm-commits
llvm-commits at lists.llvm.org
Fri May 3 18:01:04 PDT 2024
Author: paperchalice
Date: 2024-05-04T09:00:59+08:00
New Revision: e7939d0df6ba12fcb808ac68863f7bd9dab47110
URL: https://github.com/llvm/llvm-project/commit/e7939d0df6ba12fcb808ac68863f7bd9dab47110
DIFF: https://github.com/llvm/llvm-project/commit/e7939d0df6ba12fcb808ac68863f7bd9dab47110.diff
LOG: [Instrumentation] Support verifying machine function (#90931)
We need it to test isel related passes. Currently
`verifyMachineFunction` is incomplete (no LiveIntervals support), but is
enough for testing isel pass, will migrate to complete
`MachineVerifierPass` in future.
Added:
llvm/test/tools/llc/new-pm/verify.mir
Modified:
llvm/include/llvm/Passes/MachinePassRegistry.def
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Passes/StandardInstrumentations.cpp
llvm/test/CodeGen/MIR/X86/machine-verifier.mir
llvm/tools/llc/NewPMDriver.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Passes/MachinePassRegistry.def b/llvm/include/llvm/Passes/MachinePassRegistry.def
index 5a14d619ea076f..380bffe75b3099 100644
--- a/llvm/include/llvm/Passes/MachinePassRegistry.def
+++ b/llvm/include/llvm/Passes/MachinePassRegistry.def
@@ -128,6 +128,7 @@ MACHINE_FUNCTION_PASS("no-op-machine-function", NoOpMachineFunctionPass())
MACHINE_FUNCTION_PASS("print", PrintMIRPass())
MACHINE_FUNCTION_PASS("require-all-machine-function-properties",
RequireAllMachineFunctionPropertiesPass())
+MACHINE_FUNCTION_PASS("trigger-verifier-error", TriggerVerifierErrorPass())
#undef MACHINE_FUNCTION_PASS
// After a pass is converted to new pass manager, its entry should be moved from
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 6f69dfce91b336..51ddb73943b10d 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -93,6 +93,7 @@
#include "llvm/CodeGen/MIRPrinter.h"
#include "llvm/CodeGen/MachineFunctionAnalysis.h"
#include "llvm/CodeGen/MachinePassManager.h"
+#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/PreISelIntrinsicLowering.h"
#include "llvm/CodeGen/SafeStack.h"
#include "llvm/CodeGen/SelectOptimize.h"
@@ -363,6 +364,14 @@ class TriggerVerifierErrorPass
return PreservedAnalyses::none();
}
+ PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &) {
+ // Intentionally create a virtual register and set NoVRegs property.
+ auto &MRI = MF.getRegInfo();
+ MRI.createGenericVirtualRegister(LLT::scalar(8));
+ MF.getProperties().set(MachineFunctionProperties::Property::NoVRegs);
+ return PreservedAnalyses::all();
+ }
+
static StringRef name() { return "TriggerVerifierErrorPass"; }
};
diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index ab37ab52146441..79aff096fb0858 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -1487,6 +1487,17 @@ void VerifyInstrumentation::registerCallbacks(
"\"{0}\", compilation aborted!",
P));
}
+
+ // TODO: Use complete MachineVerifierPass.
+ if (auto *MF = unwrapIR<MachineFunction>(IR)) {
+ if (DebugLogging)
+ dbgs() << "Verifying machine function " << MF->getName() << '\n';
+ verifyMachineFunction(
+ formatv("Broken machine function found after pass "
+ "\"{0}\", compilation aborted!",
+ P),
+ *MF);
+ }
}
});
}
diff --git a/llvm/test/CodeGen/MIR/X86/machine-verifier.mir b/llvm/test/CodeGen/MIR/X86/machine-verifier.mir
index 5cf5e8f0adc92d..6966b3e6778e25 100644
--- a/llvm/test/CodeGen/MIR/X86/machine-verifier.mir
+++ b/llvm/test/CodeGen/MIR/X86/machine-verifier.mir
@@ -1,5 +1,5 @@
# RUN: not --crash llc -march=x86-64 -run-pass none -o /dev/null %s 2>&1 | FileCheck %s
-# This test ensures that the MIR parser runs the machine verifier after parsing.
+# This test ensures that the VerifyInstrumentation works for machine function.
--- |
diff --git a/llvm/test/tools/llc/new-pm/verify.mir b/llvm/test/tools/llc/new-pm/verify.mir
new file mode 100644
index 00000000000000..0cc7fc837e5bed
--- /dev/null
+++ b/llvm/test/tools/llc/new-pm/verify.mir
@@ -0,0 +1,10 @@
+# RUN: not --crash llc -mtriple=x86_64-pc-linux-gnu -debug-pass-manager -passes='module(function(machine-function(trigger-verifier-error)))' -filetype=null %s 2>&1 | FileCheck %s
+
+# CHECK: Verifying machine function f
+# CHECK: Broken machine function found after pass "TriggerVerifierErrorPass"
+---
+name: f
+body: |
+ bb.0:
+ RET 0
+...
diff --git a/llvm/tools/llc/NewPMDriver.cpp b/llvm/tools/llc/NewPMDriver.cpp
index 6d9956ea07d356..fb1959c6457f4a 100644
--- a/llvm/tools/llc/NewPMDriver.cpp
+++ b/llvm/tools/llc/NewPMDriver.cpp
@@ -115,7 +115,7 @@ int llvm::compileModuleWithNewPM(
MachineModuleInfo MMI(&LLVMTM);
PassInstrumentationCallbacks PIC;
- StandardInstrumentations SI(Context, Opt.DebugPM);
+ StandardInstrumentations SI(Context, Opt.DebugPM, !NoVerify);
SI.registerCallbacks(PIC);
registerCodeGenCallback(PIC, LLVMTM);
More information about the llvm-commits
mailing list