20
20
#include " llvm/IR/IntrinsicInst.h"
21
21
#include " llvm/IR/IntrinsicsAMDGPU.h"
22
22
#include " llvm/InitializePasses.h"
23
- #include " llvm/Target/TargetMachine.h"
24
23
#include < cmath>
25
24
26
25
#define DEBUG_TYPE " amdgpu-simplifylib"
@@ -49,8 +48,6 @@ class AMDGPULibCalls {
49
48
50
49
typedef llvm::AMDGPULibFunc FuncInfo;
51
50
52
- const TargetMachine *TM;
53
-
54
51
bool UnsafeFPMath = false ;
55
52
56
53
// -fuse-native.
@@ -101,13 +98,11 @@ class AMDGPULibCalls {
101
98
bool fold_read_write_pipe (CallInst *CI, IRBuilder<> &B,
102
99
const FuncInfo &FInfo);
103
100
104
- // llvm.amdgcn.wavefrontsize
105
- bool fold_wavefrontsize (CallInst *CI, IRBuilder<> &B);
106
-
107
101
// Get insertion point at entry.
108
102
BasicBlock::iterator getEntryIns (CallInst * UI);
109
103
// Insert an Alloc instruction.
110
104
AllocaInst* insertAlloca (CallInst * UI, IRBuilder<> &B, const char *prefix);
105
+
111
106
// Get a scalar native builtin single argument FP function
112
107
FunctionCallee getNativeFunction (Module *M, const FuncInfo &FInfo);
113
108
@@ -126,7 +121,7 @@ class AMDGPULibCalls {
126
121
}
127
122
128
123
public:
129
- AMDGPULibCalls (const TargetMachine *TM_ = nullptr ) : TM(TM_ ) {}
124
+ AMDGPULibCalls () {}
130
125
131
126
bool fold (CallInst *CI);
132
127
@@ -148,8 +143,7 @@ namespace {
148
143
public:
149
144
static char ID; // Pass identification
150
145
151
- AMDGPUSimplifyLibCalls (const TargetMachine *TM = nullptr )
152
- : FunctionPass(ID), Simplifier(TM) {
146
+ AMDGPUSimplifyLibCalls () : FunctionPass(ID) {
153
147
initializeAMDGPUSimplifyLibCallsPass (*PassRegistry::getPassRegistry ());
154
148
}
155
149
@@ -602,18 +596,8 @@ bool AMDGPULibCalls::fold_read_write_pipe(CallInst *CI, IRBuilder<> &B,
602
596
bool AMDGPULibCalls::fold (CallInst *CI) {
603
597
Function *Callee = CI->getCalledFunction ();
604
598
// Ignore indirect calls.
605
- if (!Callee || CI->isNoBuiltin ())
606
- return false ;
607
-
608
- IRBuilder<> B (CI);
609
- switch (Callee->getIntrinsicID ()) {
610
- case Intrinsic::not_intrinsic:
611
- break ;
612
- case Intrinsic::amdgcn_wavefrontsize:
613
- return !EnablePreLink && fold_wavefrontsize (CI, B);
614
- default :
599
+ if (!Callee || Callee->isIntrinsic () || CI->isNoBuiltin ())
615
600
return false ;
616
- }
617
601
618
602
FuncInfo FInfo;
619
603
if (!parseFunctionName (Callee->getName (), FInfo))
@@ -629,6 +613,8 @@ bool AMDGPULibCalls::fold(CallInst *CI) {
629
613
if (TDOFold (CI, FInfo))
630
614
return true ;
631
615
616
+ IRBuilder<> B (CI);
617
+
632
618
if (FPMathOperator *FPOp = dyn_cast<FPMathOperator>(CI)) {
633
619
// Under unsafe-math, evaluate calls if possible.
634
620
// According to Brian Sumner, we can do this for all f32 function calls
@@ -1310,28 +1296,6 @@ bool AMDGPULibCalls::fold_sincos(FPMathOperator *FPOp, IRBuilder<> &B,
1310
1296
return true ;
1311
1297
}
1312
1298
1313
- bool AMDGPULibCalls::fold_wavefrontsize (CallInst *CI, IRBuilder<> &B) {
1314
- if (!TM)
1315
- return false ;
1316
-
1317
- StringRef CPU = TM->getTargetCPU ();
1318
- StringRef Features = TM->getTargetFeatureString ();
1319
- if ((CPU.empty () || CPU.equals_insensitive (" generic" )) &&
1320
- (Features.empty () || !Features.contains_insensitive (" wavefrontsize" )))
1321
- return false ;
1322
-
1323
- Function *F = CI->getParent ()->getParent ();
1324
- const GCNSubtarget &ST = TM->getSubtarget <GCNSubtarget>(*F);
1325
- unsigned N = ST.getWavefrontSize ();
1326
-
1327
- LLVM_DEBUG (errs () << " AMDIC: fold_wavefrontsize (" << *CI << " ) with "
1328
- << N << " \n " );
1329
-
1330
- CI->replaceAllUsesWith (ConstantInt::get (B.getInt32Ty (), N));
1331
- CI->eraseFromParent ();
1332
- return true ;
1333
- }
1334
-
1335
1299
// Get insertion point at entry.
1336
1300
BasicBlock::iterator AMDGPULibCalls::getEntryIns (CallInst * UI) {
1337
1301
Function * Func = UI->getParent ()->getParent ();
@@ -1642,8 +1606,8 @@ bool AMDGPULibCalls::evaluateCall(CallInst *aCI, const FuncInfo &FInfo) {
1642
1606
}
1643
1607
1644
1608
// Public interface to the Simplify LibCalls pass.
1645
- FunctionPass *llvm::createAMDGPUSimplifyLibCallsPass (const TargetMachine *TM ) {
1646
- return new AMDGPUSimplifyLibCalls (TM );
1609
+ FunctionPass *llvm::createAMDGPUSimplifyLibCallsPass () {
1610
+ return new AMDGPUSimplifyLibCalls ();
1647
1611
}
1648
1612
1649
1613
FunctionPass *llvm::createAMDGPUUseNativeCallsPass () {
@@ -1677,7 +1641,7 @@ bool AMDGPUSimplifyLibCalls::runOnFunction(Function &F) {
1677
1641
1678
1642
PreservedAnalyses AMDGPUSimplifyLibCallsPass::run (Function &F,
1679
1643
FunctionAnalysisManager &AM) {
1680
- AMDGPULibCalls Simplifier (&TM) ;
1644
+ AMDGPULibCalls Simplifier;
1681
1645
Simplifier.initNativeFuncs ();
1682
1646
Simplifier.initFunction (F);
1683
1647
0 commit comments