[llvm] Fix MachineOutliner::createPrinterPass. (PR #115787)

Han Shen via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 12 14:46:30 PST 2024


https://github.com/shenhanc78 updated https://github.com/llvm/llvm-project/pull/115787

>From 997cf5864a3f93d1256964124734f92a590739bc Mon Sep 17 00:00:00 2001
From: Han Shen <shenhan at google.com>
Date: Mon, 11 Nov 2024 14:55:39 -0800
Subject: [PATCH 1/2] Fix MachineOutliner::createPrinterPass.

MachineOutliner is a MachineFunctionPass, so its createPrinterPass
should use createMachineFunctionPrinterPass instead of falling back to
the default implementation in ModulePass::createPrinterPass.

Crrently "-c -mllvm -print-after=machine-outliner -mllvm
-enable-machine-outliner" prints llvm ir instead of llvm machine ir.
---
 llvm/lib/CodeGen/MachineOutliner.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp
index 2ae6b4f2c64c9b..0f1c52758f17ec 100644
--- a/llvm/lib/CodeGen/MachineOutliner.cpp
+++ b/llvm/lib/CodeGen/MachineOutliner.cpp
@@ -460,6 +460,12 @@ struct MachineOutliner : public ModulePass {
 
   StringRef getPassName() const override { return "Machine Outliner"; }
 
+  /// createPrinterPass - Get a machine function printer pass.
+  Pass *createPrinterPass(raw_ostream &OS,
+                          const std::string &Banner) const override {
+    return createMachineFunctionPrinterPass(OS, Banner);
+  }
+
   void getAnalysisUsage(AnalysisUsage &AU) const override {
     AU.addRequired<MachineModuleInfoWrapperPass>();
     AU.addPreserved<MachineModuleInfoWrapperPass>();

>From ea0c8a34d6b2218b71579dcbef8836897587738a Mon Sep 17 00:00:00 2001
From: Han Shen <shenhan at google.com>
Date: Tue, 12 Nov 2024 14:43:47 -0800
Subject: [PATCH 2/2] Added test case.

---
 .../CodeGen/Generic/machine-outliner-printer.ll     | 13 +++++++++++++
 1 file changed, 13 insertions(+)
 create mode 100644 llvm/test/CodeGen/Generic/machine-outliner-printer.ll

diff --git a/llvm/test/CodeGen/Generic/machine-outliner-printer.ll b/llvm/test/CodeGen/Generic/machine-outliner-printer.ll
new file mode 100644
index 00000000000000..c480fec9b87c21
--- /dev/null
+++ b/llvm/test/CodeGen/Generic/machine-outliner-printer.ll
@@ -0,0 +1,13 @@
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu \
+; RUN:   -enable-machine-outliner -print-after=machine-outliner \
+; RUN:   -o /dev/null \
+; RUN:   2>&1 | FileCheck %s -check-prefixes=MIR
+
+define i32 @empty_1() #0 {
+  ret i32 1
+}
+
+; NOTE: only machine ir shall be printed
+; MIR:	   RET64 killed $eax
+; MIR-NOT: ret i32 1
+



More information about the llvm-commits mailing list