Skip to content

Commit 7bf1cb7

Browse files
authored
[AMDGPU][NewPM] Port AMDGPURemoveIncompatibleFunctions to NPM (#122261)
1 parent f15da5f commit 7bf1cb7

8 files changed

+96
-18
lines changed

llvm/lib/Target/AMDGPU/AMDGPU.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ extern char &AMDGPUAnnotateUniformValuesLegacyPassID;
380380
void initializeAMDGPUCodeGenPreparePass(PassRegistry&);
381381
extern char &AMDGPUCodeGenPrepareID;
382382

383-
void initializeAMDGPURemoveIncompatibleFunctionsPass(PassRegistry &);
383+
void initializeAMDGPURemoveIncompatibleFunctionsLegacyPass(PassRegistry &);
384384
extern char &AMDGPURemoveIncompatibleFunctionsID;
385385

386386
void initializeAMDGPULateCodeGenPrepareLegacyPass(PassRegistry &);

llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ MODULE_PASS("amdgpu-perf-hint",
2626
AMDGPUPerfHintAnalysisPass(
2727
*static_cast<const GCNTargetMachine *>(this)))
2828
MODULE_PASS("amdgpu-printf-runtime-binding", AMDGPUPrintfRuntimeBindingPass())
29+
MODULE_PASS("amdgpu-remove-incompatible-functions", AMDGPURemoveIncompatibleFunctionsPass(*this))
2930
MODULE_PASS("amdgpu-unify-metadata", AMDGPUUnifyMetadataPass())
3031
#undef MODULE_PASS
3132

llvm/lib/Target/AMDGPU/AMDGPURemoveIncompatibleFunctions.cpp

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
#include "AMDGPURemoveIncompatibleFunctions.h"
1516
#include "AMDGPU.h"
1617
#include "GCNSubtarget.h"
1718
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
@@ -33,25 +34,16 @@ namespace {
3334

3435
using Generation = AMDGPUSubtarget::Generation;
3536

36-
class AMDGPURemoveIncompatibleFunctions : public ModulePass {
37+
class AMDGPURemoveIncompatibleFunctions {
3738
public:
38-
static char ID;
39-
4039
AMDGPURemoveIncompatibleFunctions(const TargetMachine *TM = nullptr)
41-
: ModulePass(ID), TM(TM) {
40+
: TM(TM) {
4241
assert(TM && "No TargetMachine!");
4342
}
44-
45-
StringRef getPassName() const override {
46-
return "AMDGPU Remove Incompatible Functions";
47-
}
48-
49-
void getAnalysisUsage(AnalysisUsage &AU) const override {}
50-
5143
/// Checks a single function, returns true if the function must be deleted.
5244
bool checkFunction(Function &F);
5345

54-
bool runOnModule(Module &M) override {
46+
bool run(Module &M) {
5547
assert(TM->getTargetTriple().isAMDGCN());
5648

5749
SmallVector<Function *, 4> FnsToDelete;
@@ -71,6 +63,28 @@ class AMDGPURemoveIncompatibleFunctions : public ModulePass {
7163
const TargetMachine *TM = nullptr;
7264
};
7365

66+
class AMDGPURemoveIncompatibleFunctionsLegacy : public ModulePass {
67+
public:
68+
static char ID;
69+
70+
AMDGPURemoveIncompatibleFunctionsLegacy(const TargetMachine *TM)
71+
: ModulePass(ID), TM(TM) {}
72+
73+
bool runOnModule(Module &M) override {
74+
AMDGPURemoveIncompatibleFunctions Pass(TM);
75+
return Pass.run(M);
76+
}
77+
78+
StringRef getPassName() const override {
79+
return "AMDGPU Remove Incompatible Functions";
80+
}
81+
82+
void getAnalysisUsage(AnalysisUsage &AU) const override {}
83+
84+
private:
85+
const TargetMachine *TM = nullptr;
86+
};
87+
7488
StringRef getFeatureName(unsigned Feature) {
7589
for (const SubtargetFeatureKV &KV : AMDGPUFeatureKV)
7690
if (Feature == KV.Value)
@@ -131,6 +145,15 @@ void reportFunctionRemoved(Function &F, unsigned Feature) {
131145
}
132146
} // end anonymous namespace
133147

148+
PreservedAnalyses
149+
AMDGPURemoveIncompatibleFunctionsPass::run(Module &M,
150+
ModuleAnalysisManager &MAM) {
151+
AMDGPURemoveIncompatibleFunctions Impl(TM);
152+
if (Impl.run(M))
153+
return PreservedAnalyses::none();
154+
return PreservedAnalyses::all();
155+
}
156+
134157
bool AMDGPURemoveIncompatibleFunctions::checkFunction(Function &F) {
135158
if (F.isDeclaration())
136159
return false;
@@ -182,12 +205,12 @@ bool AMDGPURemoveIncompatibleFunctions::checkFunction(Function &F) {
182205
return false;
183206
}
184207

185-
INITIALIZE_PASS(AMDGPURemoveIncompatibleFunctions, DEBUG_TYPE,
208+
INITIALIZE_PASS(AMDGPURemoveIncompatibleFunctionsLegacy, DEBUG_TYPE,
186209
"AMDGPU Remove Incompatible Functions", false, false)
187210

188-
char AMDGPURemoveIncompatibleFunctions::ID = 0;
211+
char AMDGPURemoveIncompatibleFunctionsLegacy::ID = 0;
189212

190213
ModulePass *
191214
llvm::createAMDGPURemoveIncompatibleFunctionsPass(const TargetMachine *TM) {
192-
return new AMDGPURemoveIncompatibleFunctions(TM);
215+
return new AMDGPURemoveIncompatibleFunctionsLegacy(TM);
193216
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===- AMDGPURemoveIncompatibleFunctions.h ----------------------*- C++- *-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIB_TARGET_AMDGPU_REMOVEINCOMPATIBLEFUNCTIONS_H
10+
#define LLVM_LIB_TARGET_AMDGPU_REMOVEINCOMPATIBLEFUNCTIONS_H
11+
12+
#include "llvm/IR/PassManager.h"
13+
#include "llvm/Target/TargetMachine.h"
14+
15+
namespace llvm {
16+
class AMDGPURemoveIncompatibleFunctionsPass
17+
: public PassInfoMixin<AMDGPURemoveIncompatibleFunctionsPass> {
18+
const TargetMachine *TM;
19+
20+
public:
21+
AMDGPURemoveIncompatibleFunctionsPass(const TargetMachine &TM) : TM(&TM) {}
22+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
23+
};
24+
} // namespace llvm
25+
26+
#endif // LLVM_LIB_TARGET_AMDGPU_REMOVEINCOMPATIBLEFUNCTIONS_H

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "AMDGPUISelDAGToDAG.h"
2424
#include "AMDGPUMacroFusion.h"
2525
#include "AMDGPUPerfHintAnalysis.h"
26+
#include "AMDGPURemoveIncompatibleFunctions.h"
2627
#include "AMDGPUSplitModule.h"
2728
#include "AMDGPUTargetObjectFile.h"
2829
#include "AMDGPUTargetTransformInfo.h"
@@ -507,7 +508,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() {
507508
initializeAMDGPUPromoteAllocaToVectorPass(*PR);
508509
initializeAMDGPUCodeGenPreparePass(*PR);
509510
initializeAMDGPULateCodeGenPrepareLegacyPass(*PR);
510-
initializeAMDGPURemoveIncompatibleFunctionsPass(*PR);
511+
initializeAMDGPURemoveIncompatibleFunctionsLegacyPass(*PR);
511512
initializeAMDGPULowerModuleLDSLegacyPass(*PR);
512513
initializeAMDGPULowerBufferFatPointersPass(*PR);
513514
initializeAMDGPUReserveWWMRegsPass(*PR);
@@ -1925,7 +1926,8 @@ AMDGPUCodeGenPassBuilder::AMDGPUCodeGenPassBuilder(
19251926
}
19261927

19271928
void AMDGPUCodeGenPassBuilder::addIRPasses(AddIRPass &addPass) const {
1928-
// TODO: Missing AMDGPURemoveIncompatibleFunctions
1929+
if (RemoveIncompatibleFunctions && TM.getTargetTriple().isAMDGCN())
1930+
addPass(AMDGPURemoveIncompatibleFunctionsPass(TM));
19291931

19301932
addPass(AMDGPUPrintfRuntimeBindingPass());
19311933
if (LowerCtorDtor)

llvm/test/CodeGen/AMDGPU/remove-incompatible-functions.ll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44
; RUN: FileCheck --check-prefix=WARN-GFX7 %s < %t
55
; RUN: llc -mtriple=amdgcn -mcpu=bonaire -verify-machineinstrs < %s
66

7+
; RUN: llc -enable-new-pm -mtriple=amdgcn -mcpu=bonaire -stop-after=amdgpu-remove-incompatible-functions\
8+
; RUN: -pass-remarks=amdgpu-remove-incompatible-functions < %s 2>%t | FileCheck -check-prefixes=GFX7,IR %s
9+
; RUN: FileCheck --check-prefix=WARN-GFX7 %s < %t
10+
711
; RUN: llc -mtriple=amdgcn -mcpu=fiji -stop-after=amdgpu-remove-incompatible-functions\
812
; RUN: -pass-remarks=amdgpu-remove-incompatible-functions < %s 2>%t | FileCheck -check-prefixes=GFX8,IR %s
913
; RUN: FileCheck --check-prefix=WARN-GFX8 %s < %t
1014
; RUN: llc -mtriple=amdgcn -mcpu=fiji -verify-machineinstrs < %s
1115

16+
; RUN: llc -enable-new-pm -mtriple=amdgcn -mcpu=fiji -stop-after=amdgpu-remove-incompatible-functions\
17+
; RUN: -pass-remarks=amdgpu-remove-incompatible-functions < %s 2>%t | FileCheck -check-prefixes=GFX8,IR %s
18+
; RUN: FileCheck --check-prefix=WARN-GFX8 %s < %t
19+
1220
; RUN: llc -mtriple=amdgcn -mcpu=gfx906 -stop-after=amdgpu-remove-incompatible-functions\
1321
; RUN: -pass-remarks=amdgpu-remove-incompatible-functions < %s 2>%t | FileCheck -check-prefixes=GFX9,GFX906,IR %s
1422
; RUN: FileCheck --check-prefix=WARN-GFX906 %s < %t

llvm/test/CodeGen/AMDGPU/remove-incompatible-s-time.ll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@
44
; RUN: FileCheck -allow-empty --check-prefixes=WARN-REALTIME,WARN-MEMTIME %s < %t
55
; RUN: llc -mtriple=amdgcn -mcpu=gfx1030 -verify-machineinstrs < %s
66

7+
; RUN: llc -enable-new-pm -mtriple=amdgcn -mcpu=gfx1030 -stop-after=amdgpu-remove-incompatible-functions\
8+
; RUN: -pass-remarks=amdgpu-remove-incompatible-functions %s -o - 2>%t | FileCheck -check-prefixes=COMPATIBLE,REALTIME,MEMTIME %s
9+
; RUN: FileCheck -allow-empty --check-prefixes=WARN-REALTIME,WARN-MEMTIME %s < %t
10+
; RUN: llc -enable-new-pm -mtriple=amdgcn -mcpu=gfx1030 -verify-machineinstrs < %s
11+
712
; RUN: llc -mtriple=amdgcn -mcpu=gfx1102 -stop-after=amdgpu-remove-incompatible-functions\
813
; RUN: -pass-remarks=amdgpu-remove-incompatible-functions %s -o - 2>%t | FileCheck -check-prefixes=INCOMPATIBLE,NOREALTIME,NOMEMTIME %s
914
; RUN: FileCheck --check-prefixes=WARN-NOREALTIME,WARN-NOMEMTIME %s < %t
1015
; RUN: llc -mtriple=amdgcn -mcpu=gfx1102 -verify-machineinstrs < %s
1116

17+
; RUN: llc -enable-new-pm -mtriple=amdgcn -mcpu=gfx1102 -stop-after=amdgpu-remove-incompatible-functions\
18+
; RUN: -pass-remarks=amdgpu-remove-incompatible-functions %s -o - 2>%t | FileCheck -check-prefixes=INCOMPATIBLE,NOREALTIME,NOMEMTIME %s
19+
; RUN: FileCheck --check-prefixes=WARN-NOREALTIME,WARN-NOMEMTIME %s < %t
20+
; RUN: llc -enable-new-pm -mtriple=amdgcn -mcpu=gfx1102 -verify-machineinstrs < %s
21+
1222
; Note: This test checks the IR, but also has a run line to codegen the file just to check we
1323
; do not crash when trying to select those functions.
1424

llvm/test/CodeGen/AMDGPU/remove-incompatible-wave32-feature.ll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@
1212
; RUN: -pass-remarks=amdgpu-remove-incompatible-functions < %s 2>%t | FileCheck -check-prefixes=GFX10 %s
1313
; RUN: llc -mtriple=amdgcn -mcpu=gfx1011 -mattr=-wavefrontsize32,+wavefrontsize64 -verify-machineinstrs < %s
1414

15+
; RUN: llc -enable-new-pm -mtriple=amdgcn -mcpu=gfx1011 -mattr=-wavefrontsize32,+wavefrontsize64 -stop-after=amdgpu-remove-incompatible-functions\
16+
; RUN: -pass-remarks=amdgpu-remove-incompatible-functions < %s 2>%t | FileCheck -check-prefixes=GFX10 %s
17+
; RUN: llc -enable-new-pm -mtriple=amdgcn -mcpu=gfx1011 -mattr=-wavefrontsize32,+wavefrontsize64 -verify-machineinstrs < %s
18+
1519
; RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -mattr=-wavefrontsize32,+wavefrontsize64 -stop-after=amdgpu-remove-incompatible-functions\
1620
; RUN: -pass-remarks=amdgpu-remove-incompatible-functions < %s 2>%t | FileCheck -check-prefixes=GFX11 %s
1721
; RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -mattr=-wavefrontsize32,+wavefrontsize64 -verify-machineinstrs < %s
1822

23+
; RUN: llc -enable-new-pm -mtriple=amdgcn -mcpu=gfx1100 -mattr=-wavefrontsize32,+wavefrontsize64 -stop-after=amdgpu-remove-incompatible-functions\
24+
; RUN: -pass-remarks=amdgpu-remove-incompatible-functions < %s 2>%t | FileCheck -check-prefixes=GFX11 %s
25+
; RUN: llc -enable-new-pm -mtriple=amdgcn -mcpu=gfx1100 -mattr=-wavefrontsize32,+wavefrontsize64 -verify-machineinstrs < %s
26+
1927
; WARN-GFX906: removing function 'needs_wavefrontsize32': +wavefrontsize32 is not supported on the current target
2028
; WARN-GFX906-NOT: not supported
2129

0 commit comments

Comments
 (0)