Index: include/llvm/IR/SafepointIRVerifier.h =================================================================== --- include/llvm/IR/SafepointIRVerifier.h +++ include/llvm/IR/SafepointIRVerifier.h @@ -22,6 +22,7 @@ class Function; class FunctionPass; +class Module; /// Run the safepoint verifier over a single function. Crashes on failure. void verifySafepointIR(Function &F); @@ -29,6 +30,20 @@ /// Create an instance of the safepoint verifier pass which can be added to /// a pass pipeline to check for relocation bugs. FunctionPass *createSafepointIRVerifierPass(); + +/// Create an instance of the safepoint verifier pass which can be added to +/// a pass pipeline to check for relocation bugs. +class SafepointIRVerifierPass : public PassInfoMixin { + +public: + explicit SafepointIRVerifierPass() {} + + PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); + PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); + +private: + void run(const Function &F, const DominatorTree &DT); +}; } #endif // LLVM_IR_SAFEPOINT_IR_VERIFIER Index: lib/IR/SafepointIRVerifier.cpp =================================================================== --- lib/IR/SafepointIRVerifier.cpp +++ lib/IR/SafepointIRVerifier.cpp @@ -197,6 +197,28 @@ static void Verify(const Function &F, const DominatorTree &DT, const CFGDeadness &CD); +namespace llvm { + +void SafepointIRVerifierPass::run(const Function &F, const DominatorTree &DT) { + CFGDeadness CD; + CD.processFunction(F, DT); + Verify(F, DT, CD); +} + +PreservedAnalyses SafepointIRVerifierPass::run(Module &M, + ModuleAnalysisManager &AM) { + auto &FAM = AM.getResult(M).getManager(); + for (auto &F : M) + run(F, FAM.getResult(F)); + return PreservedAnalyses::all(); +} +PreservedAnalyses SafepointIRVerifierPass::run(Function &F, + FunctionAnalysisManager &AM) { + run(F, AM.getResult(F)); + return PreservedAnalyses::all(); +} +} + namespace { struct SafepointIRVerifier : public FunctionPass { Index: lib/Passes/PassBuilder.cpp =================================================================== --- lib/Passes/PassBuilder.cpp +++ lib/Passes/PassBuilder.cpp @@ -56,6 +56,7 @@ #include "llvm/IR/Dominators.h" #include "llvm/IR/IRPrintingPasses.h" #include "llvm/IR/PassManager.h" +#include "llvm/IR/SafepointIRVerifier.h" #include "llvm/IR/Verifier.h" #include "llvm/Support/Debug.h" #include "llvm/Support/FormatVariadic.h" Index: lib/Passes/PassRegistry.def =================================================================== --- lib/Passes/PassRegistry.def +++ lib/Passes/PassRegistry.def @@ -78,6 +78,7 @@ MODULE_PASS("rewrite-statepoints-for-gc", RewriteStatepointsForGC()) MODULE_PASS("rewrite-symbols", RewriteSymbolPass()) MODULE_PASS("rpo-functionattrs", ReversePostOrderFunctionAttrsPass()) +MODULE_PASS("verify-safepoint-ir", SafepointIRVerifierPass()) MODULE_PASS("sample-profile", SampleProfileLoaderPass()) MODULE_PASS("strip-dead-prototypes", StripDeadPrototypesPass()) MODULE_PASS("synthetic-counts-propagation", SyntheticCountsPropagation()) @@ -216,6 +217,7 @@ FUNCTION_PASS("print", ScalarEvolutionPrinterPass(dbgs())) FUNCTION_PASS("print", StackSafetyPrinterPass(dbgs())) FUNCTION_PASS("reassociate", ReassociatePass()) +FUNCTION_PASS("verify-safepoint-ir", SafepointIRVerifierPass()) FUNCTION_PASS("scalarizer", ScalarizerPass()) FUNCTION_PASS("sccp", SCCPPass()) FUNCTION_PASS("simplify-cfg", SimplifyCFGPass())