[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
This commit is contained in:
Arthur Eubanks 2020-09-30 13:23:21 -07:00
parent dd14e58252
commit ce5379f0f0
6 changed files with 54 additions and 0 deletions

View File

@ -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) {

View File

@ -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 @@ public:
/// 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

View File

@ -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));

View File

@ -37,6 +37,8 @@ public:
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;

View File

@ -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
}

View File

@ -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());