[llvm] [Instrumentation] Support verifying machine function (PR #90931)

via llvm-commits llvm-commits at lists.llvm.org
Thu May 2 19:12:14 PDT 2024


https://github.com/paperchalice updated https://github.com/llvm/llvm-project/pull/90931

>From 4c847d299cf76789f61841d836b5ee2effcf54eb Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Fri, 3 May 2024 10:04:28 +0800
Subject: [PATCH] [Instrumentation] Support verifying machine function

---
 llvm/lib/Passes/StandardInstrumentations.cpp |  6 ++++++
 llvm/test/tools/llc/new-pm/verify.mir        | 10 ++++++++++
 llvm/tools/llc/NewPMDriver.cpp               |  2 +-
 3 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/tools/llc/new-pm/verify.mir

diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index 63490c83e85f05..1d6c464c80b1e4 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -1486,6 +1486,12 @@ void VerifyInstrumentation::registerCallbacks(
                                          "\"{0}\", compilation aborted!",
                                          P));
           }
+
+          // TODO: Use complete MachineVerifierPass.
+          if (auto *MF = unwrapIR<MachineFunction>(IR)) {
+            dbgs() << "Verifying machine function " << MF->getName() << '\n';
+            verifyMachineFunction("", *MF);
+          }
         }
       });
 }
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..71c25b14d7c858
--- /dev/null
+++ b/llvm/test/tools/llc/new-pm/verify.mir
@@ -0,0 +1,10 @@
+# RUN: llc -mtriple=x86_64-pc-linux-gnu -x mir -passes=no-op-machine-function -filetype=null < %s 2>&1 | FileCheck %s
+
+# CHECK: Verifying machine function f
+
+---
+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