[llvm] [CodeGen] Allow `CodeGenPassBuilder` to add module pass after function pass (PR #77084)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 10 19:57:53 PST 2024
================
@@ -0,0 +1,158 @@
+//===- llvm/unittest/CodeGen/CodeGenPassBuilderTest.cpp -------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/CodeGen/CodeGenPassBuilder.h"
+#include "llvm/CodeGen/MachinePassManager.h"
+#include "llvm/CodeGen/TargetPassConfig.h"
+#include "llvm/MC/MCStreamer.h"
+#include "llvm/MC/TargetRegistry.h"
+#include "llvm/Passes/PassBuilder.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/TargetSelect.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/TargetParser/Host.h"
+#include "gtest/gtest.h"
+#include <string>
+
+using namespace llvm;
+
+namespace {
+
+struct NoOpModulePass : PassInfoMixin<NoOpModulePass> {
+ PreservedAnalyses run(Module &M, ModuleAnalysisManager &) {
+ return PreservedAnalyses::all();
+ }
+
+ static StringRef name() { return "NoOpModulePass"; }
+};
+
+struct NoOpFunctionPass : PassInfoMixin<NoOpFunctionPass> {
+ PreservedAnalyses run(Function &F, FunctionAnalysisManager &) {
+ return PreservedAnalyses::all();
+ }
+ static StringRef name() { return "NoOpFunctionPass"; }
+};
+
+class DummyCodeGenPassBuilder
+ : public CodeGenPassBuilder<DummyCodeGenPassBuilder> {
+public:
+ DummyCodeGenPassBuilder(LLVMTargetMachine &TM, CGPassBuilderOption Opts,
+ PassInstrumentationCallbacks *PIC)
+ : CodeGenPassBuilder(TM, Opts, PIC){};
+
+ void addPreISel(AddIRPass &addPass) const {
+ addPass(NoOpModulePass());
+ addPass(NoOpFunctionPass());
+ addPass(NoOpFunctionPass());
+ addPass(NoOpFunctionPass());
+ addPass(NoOpModulePass());
+ addPass(NoOpFunctionPass());
+ }
+
+ void addAsmPrinter(AddMachinePass &, CreateMCStreamer) const {}
+
+ Error addInstSelector(AddMachinePass &) const { return Error::success(); }
+};
+
+class CodeGenPassBuilderTest : public testing::Test {
+public:
+ LLVMTargetMachine *TM;
+
+ static void SetUpTestCase() {
+ InitializeAllTargets();
+ InitializeAllTargetMCs();
+
+ static const char *argv[] = {
+ "test",
+ "-print-pipeline-passes",
+ };
+ int argc = sizeof(argv) / sizeof(char *);
----------------
arsenm wrote:
this can use std::size
https://github.com/llvm/llvm-project/pull/77084
More information about the llvm-commits
mailing list