aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Passes
diff options
context:
space:
mode:
authorpaperchalice <liujunchang97@outlook.com>2024-05-04 09:00:59 +0800
committerGitHub <noreply@github.com>2024-05-04 09:00:59 +0800
commite7939d0df6ba12fcb808ac68863f7bd9dab47110 (patch)
tree7d8acefcc2e98e6ae3c334f0f177be448d228e58 /llvm/lib/Passes
parentb958ef19489e508e367ad530d4512b7710591550 (diff)
downloadllvm-e7939d0df6ba12fcb808ac68863f7bd9dab47110.zip
llvm-e7939d0df6ba12fcb808ac68863f7bd9dab47110.tar.gz
llvm-e7939d0df6ba12fcb808ac68863f7bd9dab47110.tar.bz2
[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.
Diffstat (limited to 'llvm/lib/Passes')
-rw-r--r--llvm/lib/Passes/PassBuilder.cpp9
-rw-r--r--llvm/lib/Passes/StandardInstrumentations.cpp11
2 files changed, 20 insertions, 0 deletions
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 6f69dfc..51ddb73 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 @@ public:
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 ab37ab5..79aff09 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);
+ }
}
});
}