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

via llvm-commits llvm-commits at lists.llvm.org
Thu May 2 21:44:57 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 1/2] [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);
 

>From ebda9d6de8f3d0e29a80eae55adeaf55876129fa Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Fri, 3 May 2024 12:44:41 +0800
Subject: [PATCH 2/2] print "Verifying machine function" in when debug logging
 is true

---
 llvm/lib/Passes/StandardInstrumentations.cpp | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index 1d6c464c80b1e4..3fadad3ac90c2a 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -1489,8 +1489,12 @@ void VerifyInstrumentation::registerCallbacks(
 
           // TODO: Use complete MachineVerifierPass.
           if (auto *MF = unwrapIR<MachineFunction>(IR)) {
-            dbgs() << "Verifying machine function " << MF->getName() << '\n';
-            verifyMachineFunction("", *MF);
+            if (DebugLogging)
+              dbgs() << "Verifying machine function " << MF->getName() << '\n';
+            verifyMachineFunction(formatv("Broken module found after pass "
+                                          "\"{0}\", compilation aborted!",
+                                          P),
+                                  *MF);
           }
         }
       });



More information about the llvm-commits mailing list