[clang] ce5379f - [NPM] Add target specific hook to add passes for New Pass Manager
Arthur Eubanks via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 30 13:30:01 PDT 2020
Author: Arthur Eubanks
Date: 2020-09-30T13:29:43-07:00
New Revision: ce5379f0f0675592fd10a522009fd5b1561ca72b
URL: https://github.com/llvm/llvm-project/commit/ce5379f0f0675592fd10a522009fd5b1561ca72b
DIFF: https://github.com/llvm/llvm-project/commit/ce5379f0f0675592fd10a522009fd5b1561ca72b.diff
LOG: [NPM] Add target specific hook to add passes for New Pass Manager
The patch adds a new TargetMachine member "registerPassBuilderCallbacks" for targets to add passes to the pass pipeline using the New Pass Manager (similar to adjustPassManager for the Legacy Pass Manager).
Reviewed By: aeubanks
Differential Revision: https://reviews.llvm.org/D88138
Added:
llvm/test/CodeGen/Hexagon/registerpassbuildercallbacks.ll
Modified:
clang/lib/CodeGen/BackendUtil.cpp
llvm/include/llvm/Target/TargetMachine.h
llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp
llvm/lib/Target/Hexagon/HexagonTargetMachine.h
llvm/tools/opt/NewPMDriver.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index d77590cc2adf..dbd67a6ebe9b 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1214,6 +1214,9 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
PB.registerLoopAnalyses(LAM);
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
+ if (TM)
+ TM->registerPassBuilderCallbacks(PB, CodeGenOpts.DebugPassManager);
+
ModulePassManager MPM(CodeGenOpts.DebugPassManager);
if (!CodeGenOpts.DisableLLVMPasses) {
diff --git a/llvm/include/llvm/Target/TargetMachine.h b/llvm/include/llvm/Target/TargetMachine.h
index 60d4fb579bb9..4a9152832107 100644
--- a/llvm/include/llvm/Target/TargetMachine.h
+++ b/llvm/include/llvm/Target/TargetMachine.h
@@ -34,6 +34,7 @@ class MCRegisterInfo;
class MCSubtargetInfo;
class MCSymbol;
class raw_pwrite_stream;
+class PassBuilder;
class PassManagerBuilder;
struct PerFunctionMIParsingState;
class SMDiagnostic;
@@ -294,6 +295,11 @@ class TargetMachine {
/// PassManagerBuilder::addExtension.
virtual void adjustPassManager(PassManagerBuilder &) {}
+ /// Allow the target to modify the pass pipeline with New Pass Manager
+ /// (similar to adjustPassManager for Legacy Pass manager).
+ virtual void registerPassBuilderCallbacks(PassBuilder &,
+ bool DebugPassManager) {}
+
/// Add passes to the specified pass manager to get the specified file
/// emitted. Typically this will involve several steps of code generation.
/// This method should return true if emission of this file type is not
diff --git a/llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp b/llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp
index cb3b6fbdd69e..0f15c46bc8bb 100644
--- a/llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp
@@ -22,6 +22,7 @@
#include "llvm/CodeGen/TargetPassConfig.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
+#include "llvm/Passes/PassBuilder.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
@@ -273,6 +274,18 @@ void HexagonTargetMachine::adjustPassManager(PassManagerBuilder &PMB) {
});
}
+void HexagonTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB,
+ bool DebugPassManager) {
+ PB.registerOptimizerLastEPCallback(
+ [=](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
+ LoopPassManager LPM(DebugPassManager);
+ FunctionPassManager FPM(DebugPassManager);
+ LPM.addPass(HexagonVectorLoopCarriedReusePass());
+ FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM)));
+ MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
+ });
+}
+
TargetTransformInfo
HexagonTargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(HexagonTTIImpl(this, F));
diff --git a/llvm/lib/Target/Hexagon/HexagonTargetMachine.h b/llvm/lib/Target/Hexagon/HexagonTargetMachine.h
index 7ee4474e90e3..fa174128f708 100644
--- a/llvm/lib/Target/Hexagon/HexagonTargetMachine.h
+++ b/llvm/lib/Target/Hexagon/HexagonTargetMachine.h
@@ -37,6 +37,8 @@ class HexagonTargetMachine : public LLVMTargetMachine {
static unsigned getModuleMatchQuality(const Module &M);
void adjustPassManager(PassManagerBuilder &PMB) override;
+ void registerPassBuilderCallbacks(PassBuilder &PB,
+ bool DebugPassManager) override;
TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
TargetTransformInfo getTargetTransformInfo(const Function &F) override;
diff --git a/llvm/test/CodeGen/Hexagon/registerpassbuildercallbacks.ll b/llvm/test/CodeGen/Hexagon/registerpassbuildercallbacks.ll
new file mode 100644
index 000000000000..18bca19ac245
--- /dev/null
+++ b/llvm/test/CodeGen/Hexagon/registerpassbuildercallbacks.ll
@@ -0,0 +1,27 @@
+; RUN: opt -mtriple=hexagon -disable-verify -debug-pass-manager \
+; RUN: -disable-output -passes='default<O1>' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefix=NPM
+; RUN: opt -mtriple=hexagon -disable-verify -debug-pass-manager \
+; RUN: -disable-output -passes='default<O2>' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefix=NPM
+; RUN: opt -mtriple=hexagon -disable-verify -debug-pass-manager \
+; RUN: -disable-output -passes='default<O3>' -S %s 2>&1 \
+; RUN: | FileCheck %s --check-prefix=NPM
+
+; Test TargetMachine::registerPassBuilderCallbacks
+; NPM: Running pass: HexagonVectorLoopCarriedReusePass
+
+declare void @bar() local_unnamed_addr
+
+define void @foo(i32 %n) local_unnamed_addr {
+entry:
+ br label %loop
+loop:
+ %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
+ %iv.next = add i32 %iv, 1
+ tail call void @bar()
+ %cmp = icmp eq i32 %iv, %n
+ br i1 %cmp, label %exit, label %loop
+exit:
+ ret void
+}
diff --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp
index c6c4191c1459..f01d33efe45a 100644
--- a/llvm/tools/opt/NewPMDriver.cpp
+++ b/llvm/tools/opt/NewPMDriver.cpp
@@ -375,6 +375,9 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
PB.registerLoopAnalyses(LAM);
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
+ if (TM)
+ TM->registerPassBuilderCallbacks(PB, DebugPM);
+
ModulePassManager MPM(DebugPM);
if (VK > VK_NoVerifier)
MPM.addPass(VerifierPass());
More information about the cfe-commits
mailing list