aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp93
1 files changed, 72 insertions, 21 deletions
diff --git a/contrib/llvm-project/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp b/contrib/llvm-project/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
index 4a14259f1bdb..6b7f57252b7a 100644
--- a/contrib/llvm-project/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
+++ b/contrib/llvm-project/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
@@ -13,27 +13,12 @@
#include "AMDGPU.h"
#include "AMDGPULibFunc.h"
-#include "AMDGPUSubtarget.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/StringSet.h"
+#include "GCNSubtarget.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/Loads.h"
-#include "llvm/IR/Constants.h"
-#include "llvm/IR/DerivedTypes.h"
-#include "llvm/IR/Function.h"
-#include "llvm/IR/IRBuilder.h"
-#include "llvm/IR/Instructions.h"
-#include "llvm/IR/Intrinsics.h"
-#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/Module.h"
-#include "llvm/IR/ValueSymbolTable.h"
+#include "llvm/IR/IntrinsicsAMDGPU.h"
#include "llvm/InitializePasses.h"
-#include "llvm/Support/Debug.h"
-#include "llvm/Support/MathExtras.h"
-#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
-#include <cmath>
-#include <vector>
#define DEBUG_TYPE "amdgpu-simplifylib"
@@ -495,8 +480,7 @@ bool AMDGPULibCalls::isUnsafeMath(const CallInst *CI) const {
}
bool AMDGPULibCalls::useNativeFunc(const StringRef F) const {
- return AllNative ||
- std::find(UseNative.begin(), UseNative.end(), F) != UseNative.end();
+ return AllNative || llvm::is_contained(UseNative, F);
}
void AMDGPULibCalls::initNativeFuncs() {
@@ -1289,6 +1273,7 @@ bool AMDGPULibCalls::fold_sincos(CallInst *CI, IRBuilder<> &B,
BasicBlock * const CBB = CI->getParent();
int const MaxScan = 30;
+ bool Changed = false;
{ // fold in load value.
LoadInst *LI = dyn_cast<LoadInst>(CArgVal);
@@ -1296,6 +1281,7 @@ bool AMDGPULibCalls::fold_sincos(CallInst *CI, IRBuilder<> &B,
BasicBlock::iterator BBI = LI->getIterator();
Value *AvailableVal = FindAvailableLoadedValue(LI, CBB, BBI, MaxScan, AA);
if (AvailableVal) {
+ Changed = true;
CArgVal->replaceAllUsesWith(AvailableVal);
if (CArgVal->getNumUses() == 0)
LI->eraseFromParent();
@@ -1331,7 +1317,8 @@ bool AMDGPULibCalls::fold_sincos(CallInst *CI, IRBuilder<> &B,
if (UI) break;
}
- if (!UI) return false;
+ if (!UI)
+ return Changed;
// Merge the sin and cos.
@@ -1340,7 +1327,8 @@ bool AMDGPULibCalls::fold_sincos(CallInst *CI, IRBuilder<> &B,
AMDGPULibFunc nf(AMDGPULibFunc::EI_SINCOS, fInfo);
nf.getLeads()[0].PtrKind = AMDGPULibFunc::getEPtrKindFromAddrSpace(AMDGPUAS::FLAT_ADDRESS);
FunctionCallee Fsincos = getFunction(M, nf);
- if (!Fsincos) return false;
+ if (!Fsincos)
+ return Changed;
BasicBlock::iterator ItOld = B.GetInsertPoint();
AllocaInst *Alloc = insertAlloca(UI, B, "__sincos_");
@@ -1747,6 +1735,40 @@ bool AMDGPUSimplifyLibCalls::runOnFunction(Function &F) {
return Changed;
}
+PreservedAnalyses AMDGPUSimplifyLibCallsPass::run(Function &F,
+ FunctionAnalysisManager &AM) {
+ AMDGPULibCalls Simplifier(&TM);
+ Simplifier.initNativeFuncs();
+
+ bool Changed = false;
+ auto AA = &AM.getResult<AAManager>(F);
+
+ LLVM_DEBUG(dbgs() << "AMDIC: process function ";
+ F.printAsOperand(dbgs(), false, F.getParent()); dbgs() << '\n';);
+
+ for (auto &BB : F) {
+ for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E;) {
+ // Ignore non-calls.
+ CallInst *CI = dyn_cast<CallInst>(I);
+ ++I;
+ // Ignore intrinsics that do not become real instructions.
+ if (!CI || isa<DbgInfoIntrinsic>(CI) || CI->isLifetimeStartOrEnd())
+ continue;
+
+ // Ignore indirect calls.
+ Function *Callee = CI->getCalledFunction();
+ if (Callee == 0)
+ continue;
+
+ LLVM_DEBUG(dbgs() << "AMDIC: try folding " << *CI << "\n";
+ dbgs().flush());
+ if (Simplifier.fold(CI, AA))
+ Changed = true;
+ }
+ }
+ return Changed ? PreservedAnalyses::none() : PreservedAnalyses::all();
+}
+
bool AMDGPUUseNativeCalls::runOnFunction(Function &F) {
if (skipFunction(F) || UseNative.empty())
return false;
@@ -1769,3 +1791,32 @@ bool AMDGPUUseNativeCalls::runOnFunction(Function &F) {
}
return Changed;
}
+
+PreservedAnalyses AMDGPUUseNativeCallsPass::run(Function &F,
+ FunctionAnalysisManager &AM) {
+ if (UseNative.empty())
+ return PreservedAnalyses::all();
+
+ AMDGPULibCalls Simplifier;
+ Simplifier.initNativeFuncs();
+
+ bool Changed = false;
+ for (auto &BB : F) {
+ for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E;) {
+ // Ignore non-calls.
+ CallInst *CI = dyn_cast<CallInst>(I);
+ ++I;
+ if (!CI)
+ continue;
+
+ // Ignore indirect calls.
+ Function *Callee = CI->getCalledFunction();
+ if (Callee == 0)
+ continue;
+
+ if (Simplifier.useNative(CI))
+ Changed = true;
+ }
+ }
+ return Changed ? PreservedAnalyses::none() : PreservedAnalyses::all();
+}