Skip to content

Commit defd659

Browse files
added OPM support and added pass into llc pipeline
1 parent fb2d1bb commit defd659

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,9 @@ void AMDGPUPassConfig::addIRPasses() {
13151315
isPassEnabled(EnableImageIntrinsicOptimizer))
13161316
addPass(createAMDGPUImageIntrinsicOptimizerPass(&TM));
13171317

1318+
if (EnableUniformIntrinsicCombine)
1319+
addPass(createAMDGPUUniformIntrinsicCombineLegacyPass());
1320+
13181321
// This can be disabled by passing ::Disable here or on the command line
13191322
// with --expand-variadics-override=disable.
13201323
addPass(createExpandVariadicsPass(ExpandVariadicsMode::Lowering));

llvm/lib/Target/AMDGPU/AMDGPUUniformIntrinsicCombine.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,62 @@ static bool runUniformIntrinsicCombine(Function &F, const UniformityInfo &UI) {
136136
return IsChanged;
137137
}
138138

139+
// Legacy PM version
140+
static bool runUniformIntrinsicCombine(Module &M, ModulePass &P) {
141+
bool IsChanged = false;
142+
ValueMap<const Value *, bool> Tracker;
143+
144+
for (Function &F : M) {
145+
switch (F.getIntrinsicID()) {
146+
case Intrinsic::amdgcn_permlane64:
147+
case Intrinsic::amdgcn_readfirstlane:
148+
case Intrinsic::amdgcn_readlane:
149+
case Intrinsic::amdgcn_ballot:
150+
break;
151+
default:
152+
continue;
153+
}
154+
155+
for (User *U : make_early_inc_range(F.users())) {
156+
auto *II = cast<IntrinsicInst>(U);
157+
Function *ParentF = II->getFunction();
158+
auto &UI = P.getAnalysis<UniformityInfoWrapperPass>(*ParentF)
159+
.getUniformityInfo();
160+
IsChanged |= optimizeUniformIntrinsic(*II, UI, Tracker);
161+
}
162+
}
163+
return IsChanged;
164+
}
165+
166+
namespace {
167+
class AMDGPUUniformIntrinsicCombineLegacy : public ModulePass {
168+
public:
169+
static char ID;
170+
AMDGPUUniformIntrinsicCombineLegacy() : ModulePass(ID) {
171+
initializeAMDGPUUniformIntrinsicCombineLegacyPass(
172+
*PassRegistry::getPassRegistry());
173+
}
174+
175+
private:
176+
bool runOnModule(Module &M) override;
177+
void getAnalysisUsage(AnalysisUsage &AU) const override {
178+
AU.setPreservesCFG();
179+
AU.addRequired<UniformityInfoWrapperPass>();
180+
AU.addRequired<TargetPassConfig>();
181+
}
182+
};
183+
} // namespace
184+
185+
char AMDGPUUniformIntrinsicCombineLegacy::ID = 0;
186+
char &llvm::AMDGPUUniformIntrinsicCombineLegacyPassID =
187+
AMDGPUUniformIntrinsicCombineLegacy::ID;
188+
189+
bool AMDGPUUniformIntrinsicCombineLegacy::runOnModule(Module &M) {
190+
if (skipModule(M))
191+
return false;
192+
return runUniformIntrinsicCombine(M, *this);
193+
}
194+
139195
PreservedAnalyses
140196
AMDGPUUniformIntrinsicCombinePass::run(Function &F,
141197
FunctionAnalysisManager &AM) {

llvm/test/CodeGen/AMDGPU/llc-pipeline.ll

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
; GCN-O0-NEXT: AMDGPU Remove Incompatible Functions
3232
; GCN-O0-NEXT: AMDGPU Printf lowering
3333
; GCN-O0-NEXT: Lower ctors and dtors for AMDGPU
34+
; GCN-O0-NEXT: AMDGPU Uniform Intrinsic Combine
35+
; GCN-O0-NEXT: FunctionPass Manager
36+
; GCN-O0-NEXT: Dominator Tree Construction
37+
; GCN-O0-NEXT: Cycle Info Analysis
38+
; GCN-O0-NEXT: Uniformity Analysis
3439
; GCN-O0-NEXT: Expand variadic functions
3540
; GCN-O0-NEXT: AMDGPU Inline All Functions
3641
; GCN-O0-NEXT: Inliner for always_inline functions
@@ -179,6 +184,11 @@
179184
; GCN-O1-NEXT: AMDGPU Remove Incompatible Functions
180185
; GCN-O1-NEXT: AMDGPU Printf lowering
181186
; GCN-O1-NEXT: Lower ctors and dtors for AMDGPU
187+
; GCN-O1-NEXT: AMDGPU Uniform Intrinsic Combine
188+
; GCN-O1-NEXT: FunctionPass Manager
189+
; GCN-O1-NEXT: Dominator Tree Construction
190+
; GCN-O1-NEXT: Cycle Info Analysis
191+
; GCN-O1-NEXT: Uniformity Analysis
182192
; GCN-O1-NEXT: Expand variadic functions
183193
; GCN-O1-NEXT: AMDGPU Inline All Functions
184194
; GCN-O1-NEXT: Inliner for always_inline functions
@@ -466,6 +476,11 @@
466476
; GCN-O1-OPTS-NEXT: AMDGPU Remove Incompatible Functions
467477
; GCN-O1-OPTS-NEXT: AMDGPU Printf lowering
468478
; GCN-O1-OPTS-NEXT: Lower ctors and dtors for AMDGPU
479+
; GCN-O1-OPTS-NEXT: AMDGPU Uniform Intrinsic Combine
480+
; GCN-O1-OPTS-NEXT: FunctionPass Manager
481+
; GCN-O1-OPTS-NEXT: Dominator Tree Construction
482+
; GCN-O1-OPTS-NEXT: Cycle Info Analysis
483+
; GCN-O1-OPTS-NEXT: Uniformity Analysis
469484
; GCN-O1-OPTS-NEXT: Expand variadic functions
470485
; GCN-O1-OPTS-NEXT: AMDGPU Inline All Functions
471486
; GCN-O1-OPTS-NEXT: Inliner for always_inline functions
@@ -783,6 +798,11 @@
783798
; GCN-O2-NEXT: Lower ctors and dtors for AMDGPU
784799
; GCN-O2-NEXT: FunctionPass Manager
785800
; GCN-O2-NEXT: AMDGPU Image Intrinsic Optimizer
801+
; GCN-O2-NEXT: AMDGPU Uniform Intrinsic Combine
802+
; GCN-O2-NEXT: FunctionPass Manager
803+
; GCN-O2-NEXT: Dominator Tree Construction
804+
; GCN-O2-NEXT: Cycle Info Analysis
805+
; GCN-O2-NEXT: Uniformity Analysis
786806
; GCN-O2-NEXT: Expand variadic functions
787807
; GCN-O2-NEXT: AMDGPU Inline All Functions
788808
; GCN-O2-NEXT: Inliner for always_inline functions
@@ -1104,6 +1124,11 @@
11041124
; GCN-O3-NEXT: Lower ctors and dtors for AMDGPU
11051125
; GCN-O3-NEXT: FunctionPass Manager
11061126
; GCN-O3-NEXT: AMDGPU Image Intrinsic Optimizer
1127+
; GCN-O3-NEXT: AMDGPU Uniform Intrinsic Combine
1128+
; GCN-O3-NEXT: FunctionPass Manager
1129+
; GCN-O3-NEXT: Dominator Tree Construction
1130+
; GCN-O3-NEXT: Cycle Info Analysis
1131+
; GCN-O3-NEXT: Uniformity Analysis
11071132
; GCN-O3-NEXT: Expand variadic functions
11081133
; GCN-O3-NEXT: AMDGPU Inline All Functions
11091134
; GCN-O3-NEXT: Inliner for always_inline functions

0 commit comments

Comments
 (0)