[llvm] [PassBuilder] Parse machine function analyses inside require/invalidate (PR #96634)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 26 00:52:36 PDT 2024


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

>From 32b659bd3d46e079c4df4972d8f6f97137c62844 Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Tue, 25 Jun 2024 17:20:46 +0800
Subject: [PATCH 1/2] [PassBuilder] Parse machine function analyses inside
 require/invalidate Now we have several machine function analyses, but forget
 to support them in `PassBuilder`.

---
 llvm/lib/Passes/PassBuilder.cpp | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index e2f0515f5275e..a87d0b5955b83 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -1910,6 +1910,18 @@ Error PassBuilder::parseMachinePass(MachineFunctionPassManager &MFPM,
     MFPM.addPass(CREATE_PASS(Params.get()));                                   \
     return Error::success();                                                   \
   }
+#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS)                           \
+  if (Name == "require<" NAME ">") {                                           \
+    MFPM.addPass(                                                              \
+        RequireAnalysisPass<std::remove_reference_t<decltype(CREATE_PASS)>,    \
+                            MachineFunction>());                               \
+    return Error::success();                                                   \
+  }                                                                            \
+  if (Name == "invalidate<" NAME ">") {                                        \
+    MFPM.addPass(InvalidateAnalysisPass<                                       \
+                 std::remove_reference_t<decltype(CREATE_PASS)>>());           \
+    return Error::success();                                                   \
+  }
 #include "llvm/Passes/MachinePassRegistry.def"
 
   for (auto &C : MachineFunctionPipelineParsingCallbacks)

>From c78a88aefa8c051500beff7bce6132a0bf699715 Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Wed, 26 Jun 2024 15:51:35 +0800
Subject: [PATCH 2/2] Add test

---
 llvm/test/tools/llc/new-pm/pipeline.mir | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/llvm/test/tools/llc/new-pm/pipeline.mir b/llvm/test/tools/llc/new-pm/pipeline.mir
index 6baa710060f05..ee058f763b779 100644
--- a/llvm/test/tools/llc/new-pm/pipeline.mir
+++ b/llvm/test/tools/llc/new-pm/pipeline.mir
@@ -1,7 +1,10 @@
 # RUN: llc -mtriple=x86_64-pc-linux-gnu -x mir -passes=no-op-machine-function --print-pipeline-passes -filetype=null < %s | FileCheck %s --match-full-lines
+# RUN: llc -mtriple=x86_64-pc-linux-gnu -x mir -passes='require<machine-dom-tree>,print<machine-dom-tree>' -print-pipeline-passes < %s | FileCheck --check-prefix=ANALYSIS %s
 
 # CHECK: function(machine-function(no-op-machine-function)),PrintMIRPreparePass,function(machine-function(print))
 
+# ANALYSIS: require<machine-dom-tree>,print<machine-dom-tree>
+
 ---
 name: f
 body: |



More information about the llvm-commits mailing list