[llvm] [NewPM][BPF] Add BPFPassRegistry.def (PR #86241)

via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 21 21:08:01 PDT 2024


https://github.com/paperchalice created https://github.com/llvm/llvm-project/pull/86241

Prepare migration for dag-isel.

>From 1a1d795a44ac54259f5f92d2616bed6e2c2c7756 Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Fri, 22 Mar 2024 12:01:14 +0800
Subject: [PATCH] [NewPM][BPF] Add BPFPassRegistry.def Prepare migration for
 dag-isel

---
 llvm/lib/Target/BPF/BPFPassRegistry.def  | 32 ++++++++++++++++++++++++
 llvm/lib/Target/BPF/BPFTargetMachine.cpp | 25 ++++++------------
 2 files changed, 40 insertions(+), 17 deletions(-)
 create mode 100644 llvm/lib/Target/BPF/BPFPassRegistry.def

diff --git a/llvm/lib/Target/BPF/BPFPassRegistry.def b/llvm/lib/Target/BPF/BPFPassRegistry.def
new file mode 100644
index 00000000000000..73a8ef2f95bf3c
--- /dev/null
+++ b/llvm/lib/Target/BPF/BPFPassRegistry.def
@@ -0,0 +1,32 @@
+//===- BPFPassRegistry.def - Registry of BPF passes -------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is used as the registry of passes that are part of the
+// BPF backend.
+//
+//===----------------------------------------------------------------------===//
+
+// NOTE: NO INCLUDE GUARD DESIRED!
+
+#ifndef FUNCTION_PASS
+#define FUNCTION_PASS(NAME, CREATE_PASS)
+#endif
+FUNCTION_PASS("bpf-aspace-simplify", BPFASpaceCastSimplifyPass())
+FUNCTION_PASS("bpf-ir-peephole", BPFIRPeepholePass())
+#undef FUNCTION_PASS
+
+#ifndef FUNCTION_PASS_WITH_PARAMS
+#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS)
+#endif
+FUNCTION_PASS_WITH_PARAMS(
+    "bpf-preserve-static-offset", "BPFPreserveStaticOffsetPass",
+    [=](bool AllowPartial) {
+      return BPFPreserveStaticOffsetPass(AllowPartial);
+    },
+    parseBPFPreserveStaticOffsetOptions, "allow-partial")
+#undef FUNCTION_PASS_WITH_PARAMS
diff --git a/llvm/lib/Target/BPF/BPFTargetMachine.cpp b/llvm/lib/Target/BPF/BPFTargetMachine.cpp
index 5f26bec2e390c8..a7bed69b0f2ab6 100644
--- a/llvm/lib/Target/BPF/BPFTargetMachine.cpp
+++ b/llvm/lib/Target/BPF/BPFTargetMachine.cpp
@@ -108,25 +108,16 @@ TargetPassConfig *BPFTargetMachine::createPassConfig(PassManagerBase &PM) {
   return new BPFPassConfig(*this, PM);
 }
 
+static Expected<bool> parseBPFPreserveStaticOffsetOptions(StringRef Params) {
+  return PassBuilder::parseSinglePassOption(Params, "allow-partial",
+                                            "BPFPreserveStaticOffsetPass");
+}
+
 void BPFTargetMachine::registerPassBuilderCallbacks(
     PassBuilder &PB, bool PopulateClassToPassNames) {
-  PB.registerPipelineParsingCallback(
-      [](StringRef PassName, FunctionPassManager &FPM,
-         ArrayRef<PassBuilder::PipelineElement>) {
-        if (PassName == "bpf-ir-peephole") {
-          FPM.addPass(BPFIRPeepholePass());
-          return true;
-        }
-        if (PassName == "bpf-preserve-static-offset") {
-          FPM.addPass(BPFPreserveStaticOffsetPass(false));
-          return true;
-        }
-        if (PassName == "bpf-aspace-simplify") {
-          FPM.addPass(BPFASpaceCastSimplifyPass());
-          return true;
-        }
-        return false;
-      });
+#define GET_PASS_REGISTRY "BPFPassRegistry.def"
+#include "llvm/Passes/TargetPassRegistry.inc"
+
   PB.registerPipelineStartEPCallback(
       [=](ModulePassManager &MPM, OptimizationLevel) {
         FunctionPassManager FPM;



More information about the llvm-commits mailing list