Skip to content

Commit 4e838ba

Browse files
committed
[NewPM][AMDGPU] Port amdgpu-always-inline
And add to AMDGPU opt pipeline. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D94025
1 parent fd323a8 commit 4e838ba

File tree

5 files changed

+33
-7
lines changed

5 files changed

+33
-7
lines changed

llvm/lib/Target/AMDGPU/AMDGPU.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,15 @@ FunctionPass *createAMDGPUISelDag(
253253
TargetMachine *TM = nullptr,
254254
CodeGenOpt::Level OptLevel = CodeGenOpt::Default);
255255
ModulePass *createAMDGPUAlwaysInlinePass(bool GlobalOpt = true);
256+
257+
struct AMDGPUAlwaysInlinePass : PassInfoMixin<AMDGPUAlwaysInlinePass> {
258+
AMDGPUAlwaysInlinePass(bool GlobalOpt = true) : GlobalOpt(GlobalOpt) {}
259+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
260+
261+
private:
262+
bool GlobalOpt;
263+
};
264+
256265
ModulePass *createR600OpenCLImageTypeLoweringPass();
257266
FunctionPass *createAMDGPUAnnotateUniformValues();
258267

llvm/lib/Target/AMDGPU/AMDGPUAlwaysInlinePass.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "Utils/AMDGPUBaseInfo.h"
1818
#include "llvm/ADT/SmallPtrSet.h"
1919
#include "llvm/IR/Module.h"
20+
#include "llvm/IR/PassManager.h"
2021
#include "llvm/Transforms/Utils/Cloning.h"
2122

2223
using namespace llvm;
@@ -32,8 +33,6 @@ static cl::opt<bool> StressCalls(
3233
class AMDGPUAlwaysInline : public ModulePass {
3334
bool GlobalOpt;
3435

35-
void recursivelyVisitUsers(GlobalValue &GV,
36-
SmallPtrSetImpl<Function *> &FuncsToAlwaysInline);
3736
public:
3837
static char ID;
3938

@@ -53,9 +52,9 @@ INITIALIZE_PASS(AMDGPUAlwaysInline, "amdgpu-always-inline",
5352

5453
char AMDGPUAlwaysInline::ID = 0;
5554

56-
void AMDGPUAlwaysInline::recursivelyVisitUsers(
57-
GlobalValue &GV,
58-
SmallPtrSetImpl<Function *> &FuncsToAlwaysInline) {
55+
static void
56+
recursivelyVisitUsers(GlobalValue &GV,
57+
SmallPtrSetImpl<Function *> &FuncsToAlwaysInline) {
5958
SmallVector<User *, 16> Stack;
6059

6160
SmallPtrSet<const Value *, 8> Visited;
@@ -91,7 +90,7 @@ void AMDGPUAlwaysInline::recursivelyVisitUsers(
9190
}
9291
}
9392

94-
bool AMDGPUAlwaysInline::runOnModule(Module &M) {
93+
static bool alwaysInlineImpl(Module &M, bool GlobalOpt) {
9594
std::vector<GlobalAlias*> AliasesToRemove;
9695

9796
SmallPtrSet<Function *, 8> FuncsToAlwaysInline;
@@ -157,7 +156,16 @@ bool AMDGPUAlwaysInline::runOnModule(Module &M) {
157156
return !FuncsToAlwaysInline.empty() || !FuncsToNoInline.empty();
158157
}
159158

159+
bool AMDGPUAlwaysInline::runOnModule(Module &M) {
160+
return alwaysInlineImpl(M, GlobalOpt);
161+
}
162+
160163
ModulePass *llvm::createAMDGPUAlwaysInlinePass(bool GlobalOpt) {
161164
return new AMDGPUAlwaysInline(GlobalOpt);
162165
}
163166

167+
PreservedAnalyses AMDGPUAlwaysInlinePass::run(Module &M,
168+
ModuleAnalysisManager &AM) {
169+
alwaysInlineImpl(M, GlobalOpt);
170+
return PreservedAnalyses::all();
171+
}

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,10 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB,
506506
PM.addPass(AMDGPUPrintfRuntimeBindingPass());
507507
return true;
508508
}
509+
if (PassName == "amdgpu-always-inline") {
510+
PM.addPass(AMDGPUAlwaysInlinePass());
511+
return true;
512+
}
509513
return false;
510514
});
511515
PB.registerPipelineParsingCallback(
@@ -565,6 +569,8 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB,
565569
if (InternalizeSymbols) {
566570
PM.addPass(GlobalDCEPass());
567571
}
572+
if (EarlyInlineAll && !EnableFunctionCalls)
573+
PM.addPass(AMDGPUAlwaysInlinePass());
568574
});
569575

570576
PB.registerCGSCCOptimizerLateEPCallback(

llvm/test/CodeGen/AMDGPU/force-alwaysinline-lds-global-address.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -amdgpu-always-inline %s | FileCheck -check-prefixes=CALLS-ENABLED,ALL %s
2+
; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=amdgpu-always-inline %s | FileCheck -check-prefixes=CALLS-ENABLED,ALL %s
23
; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -amdgpu-stress-function-calls -amdgpu-always-inline %s | FileCheck -check-prefixes=STRESS-CALLS,ALL %s
4+
; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -amdgpu-stress-function-calls -passes=amdgpu-always-inline %s | FileCheck -check-prefixes=STRESS-CALLS,ALL %s
35

46
target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5"
57

llvm/tools/opt/opt.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,8 @@ static bool shouldPinPassToLegacyPM(StringRef Pass) {
471471
"amdgpu-propagate-attributes-early",
472472
"amdgpu-propagate-attributes-late",
473473
"amdgpu-unify-metadata",
474-
"amdgpu-printf-runtime-binding"};
474+
"amdgpu-printf-runtime-binding",
475+
"amdgpu-always-inline"};
475476
for (const auto &P : PassNameExactToIgnore)
476477
if (Pass == P)
477478
return false;

0 commit comments

Comments
 (0)