15 #define DEBUG_TYPE "amdgpu-simplifylib" 40 cl::desc(
"Enable pre-link mode optimizations"),
45 cl::desc(
"Comma separated list of functions to replace with native, or all"),
49 #define MATH_PI 3.14159265358979323846264338327950288419716939937511 50 #define MATH_E 2.71828182845904523536028747135266249775724709369996 51 #define MATH_SQRT2 1.41421356237309504880168872420969807856967187537695 53 #define MATH_LOG2E 1.4426950408889634073599246810018921374266459541529859 54 #define MATH_LOG10E 0.4342944819032518276511289189166050822943970058036665 56 #define MATH_LOG2_10 3.3219280948873623478703194294893901758648313930245806 58 #define MATH_RLOG2_10 0.3010299956639811952137388947244930267681898814621085 60 #define MATH_RLOG2_E 0.6931471805599453094172321214581765680755001343602552 70 bool AllNative =
false;
79 bool replaceWithNative(
CallInst *
CI,
const FuncInfo &FInfo);
81 bool parseFunctionName(
const StringRef& FMangledName,
82 FuncInfo *FInfo=
nullptr );
84 bool TDOFold(
CallInst *CI,
const FuncInfo &FInfo);
104 bool sincosUseNative(
CallInst *aCI,
const FuncInfo &FInfo);
107 bool evaluateScalarMathFunc(FuncInfo &FInfo,
double& Res0,
109 bool evaluateCall(
CallInst *aCI, FuncInfo &FInfo);
210 "Simplify well-known AMD library calls",
false,
false)
213 "Simplify well-known AMD library
calls",
false, false)
216 "Replace builtin math calls with that native versions.",
219 template <typename IRB>
222 CallInst *R = B.CreateCall(Callee, Arg, Name);
223 if (
Function*
F = dyn_cast<Function>(Callee))
228 template <
typename IRB>
232 if (
Function*
F = dyn_cast<Function>(Callee))
420 TableRef(
const TableEntry (&tbl)[
N]) : size(N), table(&tbl[0]) {}
475 Constant *AMDGPULibCalls::getFunction(
Module *M,
const FuncInfo& fInfo) {
483 bool AMDGPULibCalls::parseFunctionName(
const StringRef& FMangledName,
489 if (
auto Op = dyn_cast<FPMathOperator>(CI))
497 bool AMDGPULibCalls::useNativeFunc(
const StringRef F)
const {
503 AllNative = useNativeFunc(
"all") ||
508 bool AMDGPULibCalls::sincosUseNative(
CallInst *aCI,
const FuncInfo &FInfo) {
509 bool native_sin = useNativeFunc(
"sin");
510 bool native_cos = useNativeFunc(
"cos");
512 if (native_sin && native_cos) {
522 Constant *sinExpr = getFunction(M, nf);
526 Constant *cosExpr = getFunction(M, nf);
527 if (sinExpr && cosExpr) {
533 <<
" with native version of sin/cos");
550 !(AllNative || useNativeFunc(FInfo.
getName()))) {
555 return sincosUseNative(aCI, FInfo);
564 <<
" with native version");
578 if (!Callee->isDeclaration())
581 assert(Callee->
hasName() &&
"Invalid read_pipe/write_pipe function");
582 auto *M = Callee->getParent();
586 if (NumArg != 4 && NumArg != 6)
590 if (!isa<ConstantInt>(PacketSize) || !isa<ConstantInt>(PacketAlign))
592 unsigned Size = cast<ConstantInt>(PacketSize)->getZExtValue();
593 unsigned Align = cast<ConstantInt>(PacketAlign)->getZExtValue();
608 for (
unsigned I = 0;
I != PtrArgLoc; ++
I)
622 for (
unsigned I = 0;
I != PtrArgLoc; ++
I)
641 if (Callee == 0)
return false;
644 if (!parseFunctionName(Callee->
getName(), &FInfo))
659 if (
const FPMathOperator *FPOp = dyn_cast<const FPMathOperator>(CI))
662 if (TDOFold(CI, FInfo))
672 switch (FInfo.
getId()) {
677 "recip must be an either native or half function");
684 "divide must be an either native or half function");
690 return fold_pow(CI, B, FInfo);
709 return fold_sincos(CI, B, AA);
716 return fold_read_write_pipe(CI, B, FInfo);
731 int const sz = (int)tr.
size;
732 const TableEntry *
const ftbl = tr.
table;
738 for (
int eltNo = 0; eltNo <
getVecSize(FInfo); ++eltNo) {
740 CV->getElementAsConstant((
unsigned)eltNo));
741 assert(eltval &&
"Non-FP arguments in math function!");
743 for (
int i=0; i < sz; ++i) {
759 for (
unsigned i = 0; i < DVal.
size(); ++i) {
769 <<
" ---> " << *nval <<
"\n");
775 if (
ConstantFP *CF = dyn_cast<ConstantFP>(opr0)) {
776 for (
int i = 0; i < sz; ++i) {
777 if (CF->isExactlyValue(ftbl[i].input)) {
780 <<
" ---> " << *nval <<
"\n");
791 bool AMDGPULibCalls::replaceWithNative(
CallInst *CI,
const FuncInfo &FInfo) {
800 if (
Constant *FPExpr = getFunction(M, nf)) {
801 DEBUG(
dbgs() <<
"AMDIC: " << *CI <<
" ---> ");
816 if (
ConstantFP *CF = dyn_cast<ConstantFP>(opr0)) {
824 <<
" ---> " << *nval <<
"\n");
844 opr1,
"__div2recip");
854 #if _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L 857 return log(V) / 0.693147180559945309417;
863 const FuncInfo &FInfo) {
867 "fold_pow: encounter a wrong function call");
884 assert(VTy &&
"Oprand of vector function should be of vectortype");
889 CF = CDV ? dyn_cast_or_null<ConstantFP>(CDV->
getSplatValue()) :
nullptr;
890 CINT = CDV ? dyn_cast_or_null<ConstantInt>(CDV->
getSplatValue()) :
nullptr;
898 int ci_opr1 = (CINT ? (int)CINT->
getSExtValue() : 0x1111111);
900 if ((CF && CF->
isZero()) || (CINT && ci_opr1 == 0) || CZero) {
902 DEBUG(
errs() <<
"AMDIC: " << *CI <<
" ---> 1\n");
913 <<
" ---> " << *opr0 <<
"\n");
920 <<
" ---> " << *opr0 <<
" * " << *opr0 <<
"\n");
925 if ((CF && CF->
isExactlyValue(-1.0)) || (CINT && ci_opr1 == -1)) {
928 <<
" ---> 1 / " << *opr0 <<
"\n");
942 if (
Constant *FPExpr = getFunction(M,
945 DEBUG(
errs() <<
"AMDIC: " << *CI <<
" ---> " 946 << FInfo.
getName().c_str() <<
"(" << *opr0 <<
")\n");
947 Value *nval = CreateCallEx(B,FPExpr, opr0, issqrt ?
"__pow2sqrt" 964 int ival = (int)dval;
965 if ((
double)ival == dval) {
968 ci_opr1 = 0x11111111;
973 unsigned abs_opr1 = (ci_opr1 < 0) ? -ci_opr1 : ci_opr1;
974 if (abs_opr1 <= 12) {
984 Value *valx2 =
nullptr;
986 while (abs_opr1 > 0) {
987 valx2 = valx2 ? B.
CreateFMul(valx2, valx2,
"__powx2") : opr0;
989 nval = nval ? B.
CreateFMul(nval, valx2,
"__powprod") : valx2;
1000 nval = B.
CreateFDiv(cnval, nval,
"__1powprod");
1002 DEBUG(
errs() <<
"AMDIC: " << *CI <<
" ---> " 1003 << ((ci_opr1 < 0) ?
"1/prod(" :
"prod(") << *opr0 <<
")\n");
1015 bool needlog =
false;
1016 bool needabs =
false;
1017 bool needcopysign =
false;
1044 "Wrong vector size detected");
1051 if (V < 0.0) needcopysign =
true;
1057 for (
unsigned i=0; i < DVal.size(); ++i) {
1073 if (
const ConstantFP *CF = dyn_cast<ConstantFP>(opr1)) {
1077 if (y != (
double)(int64_t)y)
1085 ? (
double)CDV->getElementAsFloat(i)
1086 : CDV->getElementAsDouble(i);
1087 if (y != (
double)(int64_t)y)
1101 nval = CreateCallEx(B, AbsExpr, opr0,
"__fabs");
1103 nval = cnval ? cnval : opr0;
1110 nval = CreateCallEx(B,LogExpr, nval,
"__log2");
1118 nval = CreateCallEx(B,ExpExpr, nval,
"__exp2");
1125 if (
const VectorType *vTy = dyn_cast<VectorType>(rTy))
1140 DEBUG(
errs() <<
"AMDIC: " << *CI <<
" ---> " 1141 <<
"exp2(" << *opr1 <<
" * log2(" << *opr0 <<
"))\n");
1148 const FuncInfo &FInfo) {
1159 <<
" ---> " << *opr0 <<
"\n");
1164 std::vector<const Type*> ParamsTys;
1165 ParamsTys.push_back(opr0->
getType());
1169 DEBUG(
errs() <<
"AMDIC: " << *CI <<
" ---> sqrt(" << *opr0 <<
")\n");
1170 Value *nval = CreateCallEx(B,FPExpr, opr0,
"__rootn2sqrt");
1174 }
else if (ci_opr1 == 3) {
1178 DEBUG(
errs() <<
"AMDIC: " << *CI <<
" ---> cbrt(" << *opr0 <<
")\n");
1179 Value *nval = CreateCallEx(B,FPExpr, opr0,
"__rootn2cbrt");
1183 }
else if (ci_opr1 == -1) {
1184 DEBUG(
errs() <<
"AMDIC: " << *CI <<
" ---> 1.0 / " << *opr0 <<
"\n");
1190 }
else if (ci_opr1 == -2) {
1191 std::vector<const Type*> ParamsTys;
1192 ParamsTys.push_back(opr0->
getType());
1196 DEBUG(
errs() <<
"AMDIC: " << *CI <<
" ---> rsqrt(" << *opr0 <<
")\n");
1197 Value *nval = CreateCallEx(B,FPExpr, opr0,
"__rootn2rsqrt");
1206 const FuncInfo &FInfo) {
1213 if ((CF0 && CF0->
isZero()) || (CF1 && CF1->isZero())) {
1215 DEBUG(
errs() <<
"AMDIC: " << *CI <<
" ---> " << *opr2 <<
"\n");
1221 DEBUG(
errs() <<
"AMDIC: " << *CI <<
" ---> " 1222 << *opr1 <<
" + " << *opr2 <<
"\n");
1227 if (CF1 && CF1->isExactlyValue(1.0f)) {
1229 DEBUG(
errs() <<
"AMDIC: " << *CI <<
" ---> " 1230 << *opr0 <<
" + " << *opr2 <<
"\n");
1235 if (
ConstantFP *CF = dyn_cast<ConstantFP>(opr2)) {
1238 DEBUG(
errs() <<
"AMDIC: " << *CI <<
" ---> " 1239 << *opr0 <<
" * " << *opr1 <<
"\n");
1250 Constant* AMDGPULibCalls::getNativeFunction(
Module* M,
const FuncInfo& FInfo) {
1253 FuncInfo nf = FInfo;
1255 return getFunction(M, nf);
1260 const FuncInfo &FInfo) {
1263 if (
Constant *FPExpr = getNativeFunction(
1266 DEBUG(
errs() <<
"AMDIC: " << *CI <<
" ---> " 1267 <<
"sqrt(" << *opr0 <<
")\n");
1268 Value *nval = CreateCallEx(B,FPExpr, opr0,
"__sqrt");
1290 int const MaxScan = 30;
1308 std::string
const PairName = fInfo.
mangle();
1312 CallInst *XI = dyn_cast_or_null<CallInst>(U);
1313 if (!XI || XI == CI || XI->
getParent() != CBB)
1324 for (
int I = MaxScan;
I > 0 && BBI != CBB->
begin(); --BBI, --
I) {
1325 if (cast<Instruction>(BBI) == XI) {
1333 if (!UI)
return false;
1342 Function *Fsincos = dyn_cast_or_null<Function>(getFunction(M, nf));
1343 if (!Fsincos)
return false;
1346 AllocaInst *Alloc = insertAlloca(UI, B,
"__sincos_");
1358 DEBUG(
errs() <<
"AMDIC: fold_sincos (" << *CI <<
", " << *UI
1359 <<
") with " << *Call <<
"\n");
1382 assert(BB &&
"Entry block not found!");
1389 const char *prefix) {
1395 std::string(prefix) + UI->
getName());
1401 bool AMDGPULibCalls::evaluateScalarMathFunc(FuncInfo &FInfo,
1402 double& Res0,
double& Res1,
1408 double opr0=0.0, opr1=0.0, opr2=0.0;
1409 ConstantFP *fpopr0 = dyn_cast_or_null<ConstantFP>(copr0);
1410 ConstantFP *fpopr1 = dyn_cast_or_null<ConstantFP>(copr1);
1411 ConstantFP *fpopr2 = dyn_cast_or_null<ConstantFP>(copr2);
1420 ? fpopr1->getValueAPF().convertToDouble()
1421 : (double)fpopr1->getValueAPF().convertToFloat();
1426 ? fpopr2->getValueAPF().convertToDouble()
1427 : (double)fpopr2->getValueAPF().convertToFloat();
1430 switch (FInfo.getId()) {
1431 default :
return false;
1439 Res0 = log(opr0 + sqrt(opr0*opr0 - 1.0));
1452 Res0 = log(opr0 + sqrt(opr0*opr0 + 1.0));
1465 Res0 = (log(opr0 + 1.0) - log(opr0 - 1.0))/2.0;
1473 Res0 = (opr0 < 0.0) ? -pow(-opr0, 1.0/3.0) : pow(opr0, 1.0/3.0);
1493 Res0 = pow(2.0, opr0);
1497 Res0 = pow(10.0, opr0);
1501 Res0 = exp(opr0) - 1.0;
1509 Res0 = log(opr0) / log(2.0);
1513 Res0 = log(opr0) / log(10.0);
1517 Res0 = 1.0 / sqrt(opr0);
1559 Res0 = pow(opr0, opr1);
1563 if (
ConstantInt *iopr1 = dyn_cast_or_null<ConstantInt>(copr1)) {
1564 double val = (double)iopr1->getSExtValue();
1565 Res0 = pow(opr0, val);
1572 if (
ConstantInt *iopr1 = dyn_cast_or_null<ConstantInt>(copr1)) {
1573 double val = (double)iopr1->getSExtValue();
1574 Res0 = pow(opr0, 1.0 / val);
1589 Res0 = opr0 * opr1 + opr2;
1596 bool AMDGPULibCalls::evaluateCall(
CallInst *aCI, FuncInfo &FInfo) {
1605 if ((copr0 = dyn_cast<Constant>(aCI->
getArgOperand(0))) ==
nullptr)
1610 if ((copr1 = dyn_cast<Constant>(aCI->
getArgOperand(1))) ==
nullptr) {
1617 if ((copr2 = dyn_cast<Constant>(aCI->
getArgOperand(2))) ==
nullptr)
1624 double DVal0[16], DVal1[16];
1627 if (!evaluateScalarMathFunc(FInfo, DVal0[0],
1628 DVal1[0], copr0, copr1, copr2)) {
1637 Constant *celt1 = CDV1 ? CDV1->getElementAsConstant(i) :
nullptr;
1638 Constant *celt2 = CDV2 ? CDV2->getElementAsConstant(i) :
nullptr;
1639 if (!evaluateScalarMathFunc(FInfo, DVal0[i],
1640 DVal1[i], celt0, celt1, celt2)) {
1659 if (hasTwoResults) {
1668 if (hasTwoResults) {
1675 if (hasTwoResults) {
1678 "math function with ptr arg not supported yet");
1688 return new AMDGPUSimplifyLibCalls(Opt);
1692 return new AMDGPUUseNativeCalls();
1716 if (skipFunction(F))
1719 bool Changed =
false;
1720 auto AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
1722 DEBUG(
dbgs() <<
"AMDIC: process function ";
1729 for (
auto &BB : F) {
1738 if (Callee == 0)
continue;
1740 DEBUG(
dbgs() <<
"AMDIC: try folding " << *CI <<
"\n";
1742 if(Simplifier.fold(CI, AA))
1750 if (skipFunction(F) ||
UseNative.empty())
1753 bool Changed =
false;
1754 for (
auto &BB : F) {
1763 if (Callee == 0)
continue;
1765 if(Simplifier.useNative(CI))
A vector constant whose element type is a simple 1/2/4/8-byte integer or float/double, and whose elements are just simple data values (i.e.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void push_back(const T &Elt)
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
Function * getCalledFunction() const
Return the function called, or null if this is an indirect function invocation.
static const TableEntry tbl_sqrt[]
static const TableEntry tbl_log10[]
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
AllocaInst * CreateAlloca(Type *Ty, unsigned AddrSpace, Value *ArraySize=nullptr, const Twine &Name="")
void dropAllReferences()
Drop all references to operands.
Value * CreateAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="")
Compute iterated dominance frontiers using a linear time algorithm.
Type * getParamType(unsigned i) const
Parameter type accessors.
Constant * getElementAsConstant(unsigned i) const
Return a Constant for a specified index's element.
A Module instance is used to store all the information related to an LLVM module. ...
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
void setAlignment(unsigned Align)
static const TableEntry tbl_cospi[]
static const TableEntry tbl_cbrt[]
static bool parse(StringRef MangledName, AMDGPULibFunc &Ptr)
void initializeAMDGPUSimplifyLibCallsPass(PassRegistry &)
This class represents a function call, abstracting a target machine's calling convention.
AMDGPUAS getAMDGPUAS(const Module &M)
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
bool isUnsafeMath(const CallInst *CI) const
float convertToFloat() const
LLVMContext & getContext() const
All values hold a context through their type.
static CallInst * Create(Value *Func, ArrayRef< Value *> Args, ArrayRef< OperandBundleDef > Bundles=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
An instruction for reading from memory.
static const TableEntry tbl_erf[]
static IntegerType * getInt64Ty(LLVMContext &C)
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
void setPrefix(ENamePrefix PFX)
LLVMContext & getContext() const
Get the context in which this basic block lives.
static const TableEntry tbl_acosh[]
iterator begin()
Instruction iterator methods.
#define DEBUG_WITH_TYPE(TYPE, X)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
static const TableEntry tbl_atanh[]
std::string getName() const
Get unmangled name for mangled library function and name for unmangled library function.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
amdgpu Simplify well known AMD library false Value Value const Twine & Name
bool hasAttributes() const
Return true if the builder has IR-level attributes.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
OpenCL uses address spaces to differentiate between various memory regions on the hardware...
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
Value * FindAvailableLoadedValue(LoadInst *Load, BasicBlock *ScanBB, BasicBlock::iterator &ScanFrom, unsigned MaxInstsToScan=DefMaxInstsToScan, AliasAnalysis *AA=nullptr, bool *IsLoadCSE=nullptr, unsigned *NumScanedInst=nullptr)
Scan backwards to see if we have the value of the given load available locally within a small number ...
LLVMContext & getContext() const
Get the global data context.
bool isIntegerTy() const
True if this is an instance of IntegerType.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Param * getLeads()
Get leading parameters for mangled lib functions.
static const TableEntry tbl_sinh[]
unsigned getNumArgs() const
INITIALIZE_PASS_BEGIN(AMDGPUSimplifyLibCalls, "amdgpu-simplifylib", "Simplify well-known AMD library calls", false, false) INITIALIZE_PASS_END(AMDGPUSimplifyLibCalls
All zero aggregate value.
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
unsigned NoNaNsFPMath
NoNaNsFPMath - This flag is enabled when the -enable-no-nans-fp-math flag is specified on the command...
Type * getType() const
All values are typed, get the type of this value.
amdgpu Simplify well known AMD library false
static const TableEntry tbl_sinpi[]
bool isNegative() const
Return true if the sign bit is set.
static const TableEntry tbl_asinh[]
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
static const TableEntry tbl_tanpi[]
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Value * CreateSIToFP(Value *V, Type *DestTy, const Twine &Name="")
An instruction for storing to memory.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
AttributeList getAttributes() const
Return the parameter attributes for this call.
Value * CreateZExtOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
amdgpu Simplify well known AMD library false Value * Callee
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block...
static const TableEntry tbl_log2[]
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
static AMDGPULibFunc::EType getArgType(const AMDGPULibFunc &FInfo)
const BasicBlock & getEntryBlock() const
LoadInst * CreateLoad(Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ptr, "...")' correctly, instead of converting the string to 'bool' fo...
static bool runOnFunction(Function &F, bool PostInlining)
initializer< Ty > init(const Ty &Val)
TableRef(const TableEntry(&tbl)[N])
Type * getReturnType() const
Returns the type of the ret val.
bool fold(CallInst *CI, AliasAnalysis *AA=nullptr)
unsigned UnsafeFPMath
UnsafeFPMath - This flag is enabled when the -enable-unsafe-fp-math flag is specified on the command ...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Value * CreateFMul(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
static const TableEntry tbl_exp2[]
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
LLVM Basic Block Representation.
static Function * getFunction(llvm::Module *M, const AMDGPULibFunc &fInfo)
Constant * getSplatValue() const
If this is a splat constant, meaning that all of the elements have the same value, return that value.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
ConstantFP - Floating Point Values [float, double].
static cl::opt< bool > EnablePreLink("amdgpu-prelink", cl::desc("Enable pre-link mode optimizations"), cl::init(false), cl::Hidden)
double convertToDouble() const
float getElementAsFloat(unsigned i) const
If this is an sequential container of floats, return the specified element as a float.
static const TableEntry tbl_atan[]
static const TableEntry tbl_sin[]
Represent the analysis usage information of a pass.
static const TableEntry tbl_rsqrt[]
void setCalledFunction(Value *Fn)
Set the function called.
static const TableEntry tbl_acospi[]
FunctionPass class - This class is used to implement most global optimizations.
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Wrapper class for AMDGPULIbFuncImpl.
static const TableEntry tbl_expm1[]
self_iterator getIterator()
static int getVecSize(const AMDGPULibFunc &FInfo)
static Constant * getSplat(unsigned NumElts, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
unsigned NoInfsFPMath
NoInfsFPMath - This flag is enabled when the -enable-no-infs-fp-math flag is specified on the command...
static double log2(double V)
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
static unsigned getEPtrKindFromAddrSpace(unsigned AS)
void initializeAMDGPUUseNativeCallsPass(PassRegistry &)
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
static const TableEntry tbl_atanpi[]
void setCallingConv(CallingConv::ID CC)
const APFloat & getValueAPF() const
static const TableEntry tbl_exp10[]
Iterator for intrusive lists based on ilist_node.
This is the shared class of boolean and integer constants.
static const TableEntry tbl_asinpi[]
static bool setFastFlags(Function &F, const TargetOptions &Options)
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
ENamePrefix getPrefix() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Utility class for floating point operations which can have information about relaxed accuracy require...
Module.h This file contains the declarations for the Module class.
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
static const TableEntry tbl_log[]
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Class to represent vector types.
static Function * getOrInsertFunction(llvm::Module *M, const AMDGPULibFunc &fInfo)
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
static const TableEntry tbl_cosh[]
iterator_range< user_iterator > users()
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
Value * CreatePointerCast(Value *V, Type *DestTy, const Twine &Name="")
amdgpu Simplify well known AMD library false Value Value * Arg
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
unsigned getNumUses() const
This method computes the number of uses of this Value.
static const TableEntry tbl_exp[]
unsigned getNumArgOperands() const
Return the number of call arguments.
StringRef getValueAsString() const
Return the attribute's value as a string.
static const TableEntry tbl_tanh[]
bool isZero() const
Return true if the value is positive or negative zero.
double getElementAsDouble(unsigned i) const
If this is an sequential container of doubles, return the specified element as a double.
StringRef getName() const
Return a constant reference to the value's name.
const Function * getParent() const
Return the enclosing method, or null if none.
unsigned FLAT_ADDRESS
Address space for flat memory.
static TableRef getOptTable(AMDGPULibFunc::EFuncId id)
FunctionPass * createAMDGPUSimplifyLibCallsPass(const TargetOptions &)
APFloat abs(APFloat X)
Returns the absolute value of the argument.
static const TableEntry tbl_asin[]
Value * CreateFPToSI(Value *V, Type *DestTy, const Twine &Name="")
static cl::list< std::string > UseNative("amdgpu-use-native", cl::desc("Comma separated list of functions to replace with native, or all"), cl::CommaSeparated, cl::ValueOptional, cl::Hidden)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
static const TableEntry tbl_tan[]
static const TableEntry tbl_cos[]
Value * CreateFAdd(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
static bool HasNative(AMDGPULibFunc::EFuncId id)
Value * CreateFDiv(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
const std::string to_string(const T &Value)
void replaceCall(Value *With)
void addAttributes(unsigned i, const AttrBuilder &Attrs)
adds the attributes to the list of attributes.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
FunctionPass * createAMDGPUUseNativeCallsPass()
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
amdgpu Simplify well known AMD library calls
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
static const TableEntry tbl_erfc[]
void setFastMathFlags(FastMathFlags NewFMF)
Set the fast-math flags to be used with generated fp-math operators.
BasicBlock::iterator GetInsertPoint() const
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
std::string mangle() const
Type * getElementType() const
bool isExactlyValue(const APFloat &V) const
We don't rely on operator== working on double values, as it returns true for things that are clearly ...
StringRef - Represent a constant reference to a string, i.e.
unsigned getNumElements() const
Return the number of elements in the array or vector.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
static Constant * get(LLVMContext &Context, ArrayRef< uint8_t > Elts)
get() constructors - Return a constant with vector type with an element count and element type matchi...
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
static const TableEntry tbl_tgamma[]
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
bool useNative(CallInst *CI)
static const TableEntry tbl_acos[]
unsigned PRIVATE_ADDRESS
Address space for private memory.
const BasicBlock * getParent() const
an instruction to allocate memory on the stack
CallInst * CreateCall(Value *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)