LLVM 23.0.0git
AMDGPULibCalls.cpp File Reference

This file does AMD library function optimizations. More...

#include "AMDGPU.h"
#include "AMDGPULibFunc.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/AttributeMask.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/IntrinsicsAMDGPU.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/PatternMatch.h"
#include <cmath>

Go to the source code of this file.

Classes

class  llvm::AMDGPULibCalls
struct  TableEntry

Namespaces

namespace  llvm
 This is an optimization pass for GlobalISel generic memory operations.

Macros

#define DEBUG_TYPE   "amdgpu-simplifylib"
#define MATH_PI   numbers::pi
#define MATH_E   numbers::e
#define MATH_SQRT2   numbers::sqrt2
#define MATH_SQRT1_2   numbers::inv_sqrt2

Typedefs

using TableRef = ArrayRef<TableEntry>

Enumerations

enum class  PowKind { Pow , PowR , PowN , RootN }

Functions

template<typename IRB>
static CallInstCreateCallEx (IRB &B, FunctionCallee Callee, Value *Arg, const Twine &Name="")
template<typename IRB>
static CallInstCreateCallEx2 (IRB &B, FunctionCallee Callee, Value *Arg1, Value *Arg2, const Twine &Name="")
static FunctionTypegetPownType (FunctionType *FT)
static bool HasNative (AMDGPULibFunc::EFuncId id)
static TableRef getOptTable (AMDGPULibFunc::EFuncId id)
static int getVecSize (const AMDGPULibFunc &FInfo)
static AMDGPULibFunc::EType getArgType (const AMDGPULibFunc &FInfo)
static double llvm::log2 (double V)
static ValueemitIsInteger (IRBuilder<> &B, Value *Y)
static ValueemitIsEvenInteger (IRBuilder<> &B, Value *Y)
static ValueemitIsOddInteger (IRBuilder<> &B, Value *Y)
static ValueemitIsInf (IRBuilder<> &B, Value *val)
static ValueemitFastExpYLnx (IRBuilder<> &B, Value *X, Value *Y)
static ValueemitPowFixup (IRBuilder<> &B, Value *X, Value *Y, Value *ExpYLnX, PowKind Kind)
 Emit special case management epilog code for fast pow, powr, pown, and rootn expansions.

Variables

static cl::opt< boolEnablePreLink ("amdgpu-prelink", cl::desc("Enable pre-link mode optimizations"), cl::init(false), cl::Hidden)
static cl::list< std::stringUseNative ("amdgpu-use-native", cl::desc("Comma separated list of functions to replace with native, or all"), cl::CommaSeparated, cl::ValueOptional, cl::Hidden)
static const TableEntry tbl_acos []
static const TableEntry tbl_acosh []
static const TableEntry tbl_acospi []
static const TableEntry tbl_asin []
static const TableEntry tbl_asinh []
static const TableEntry tbl_asinpi []
static const TableEntry tbl_atan []
static const TableEntry tbl_atanh []
static const TableEntry tbl_atanpi []
static const TableEntry tbl_cbrt []
static const TableEntry tbl_cos []
static const TableEntry tbl_cosh []
static const TableEntry tbl_cospi []
static const TableEntry tbl_erfc []
static const TableEntry tbl_erf []
static const TableEntry tbl_exp []
static const TableEntry tbl_exp2 []
static const TableEntry tbl_exp10 []
static const TableEntry tbl_expm1 []
static const TableEntry tbl_log []
static const TableEntry tbl_log2 []
static const TableEntry tbl_log10 []
static const TableEntry tbl_rsqrt []
static const TableEntry tbl_sin []
static const TableEntry tbl_sinh []
static const TableEntry tbl_sinpi []
static const TableEntry tbl_sqrt []
static const TableEntry tbl_tan []
static const TableEntry tbl_tanh []
static const TableEntry tbl_tanpi []
static const TableEntry tbl_tgamma []

Detailed Description

This file does AMD library function optimizations.

Definition in file AMDGPULibCalls.cpp.

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "amdgpu-simplifylib"

Definition at line 27 of file AMDGPULibCalls.cpp.

◆ MATH_E

#define MATH_E   numbers::e

Definition at line 43 of file AMDGPULibCalls.cpp.

◆ MATH_PI

#define MATH_PI   numbers::pi

Definition at line 42 of file AMDGPULibCalls.cpp.

◆ MATH_SQRT1_2

#define MATH_SQRT1_2   numbers::inv_sqrt2

Definition at line 45 of file AMDGPULibCalls.cpp.

◆ MATH_SQRT2

#define MATH_SQRT2   numbers::sqrt2

Definition at line 44 of file AMDGPULibCalls.cpp.

Typedef Documentation

◆ TableRef

Definition at line 367 of file AMDGPULibCalls.cpp.

Enumeration Type Documentation

◆ PowKind

enum class PowKind
strong
Enumerator
Pow 
PowR 
PowN 
RootN 

Definition at line 47 of file AMDGPULibCalls.cpp.

Function Documentation

◆ CreateCallEx()

template<typename IRB>
CallInst * CreateCallEx ( IRB & B,
FunctionCallee Callee,
Value * Arg,
const Twine & Name = "" )
static

Definition at line 165 of file AMDGPULibCalls.cpp.

References B(), llvm::dyn_cast(), and F.

◆ CreateCallEx2()

template<typename IRB>
CallInst * CreateCallEx2 ( IRB & B,
FunctionCallee Callee,
Value * Arg1,
Value * Arg2,
const Twine & Name = "" )
static

Definition at line 174 of file AMDGPULibCalls.cpp.

References B(), llvm::dyn_cast(), and F.

◆ emitFastExpYLnx()

Value * emitFastExpYLnx ( IRBuilder<> & B,
Value * X,
Value * Y )
static

Definition at line 1266 of file AMDGPULibCalls.cpp.

References B(), X, and Y.

◆ emitIsEvenInteger()

Value * emitIsEvenInteger ( IRBuilder<> & B,
Value * Y )
static

Definition at line 1245 of file AMDGPULibCalls.cpp.

References B(), emitIsInteger(), and Y.

Referenced by emitIsOddInteger().

◆ emitIsInf()

Value * emitIsInf ( IRBuilder<> & B,
Value * val )
static

Definition at line 1260 of file AMDGPULibCalls.cpp.

References B(), llvm::ConstantFP::getInfinity(), and llvm::Value::getType().

Referenced by emitPowFixup().

◆ emitIsInteger()

Value * emitIsInteger ( IRBuilder<> & B,
Value * Y )
static

Definition at line 1240 of file AMDGPULibCalls.cpp.

References B(), and Y.

Referenced by emitIsEvenInteger(), emitIsOddInteger(), and emitPowFixup().

◆ emitIsOddInteger()

Value * emitIsOddInteger ( IRBuilder<> & B,
Value * Y )
static

Definition at line 1252 of file AMDGPULibCalls.cpp.

References B(), emitIsEvenInteger(), emitIsInteger(), and Y.

Referenced by emitPowFixup().

◆ emitPowFixup()

Value * emitPowFixup ( IRBuilder<> & B,
Value * X,
Value * Y,
Value * ExpYLnX,
PowKind Kind )
static

Emit special case management epilog code for fast pow, powr, pown, and rootn expansions.

x and y should be the arguments to the library call (possibly with some values clamped). expylnx should be the result to use in normal circumstances.

Definition at line 1277 of file AMDGPULibCalls.cpp.

References B(), emitIsInf(), emitIsInteger(), emitIsOddInteger(), llvm::ConstantFP::getInfinity(), llvm::ConstantFP::getQNaN(), llvm::ConstantFP::getZero(), llvm_unreachable, Pow, PowN, PowR, RootN, X, and Y.

◆ getArgType()

AMDGPULibFunc::EType getArgType ( const AMDGPULibFunc & FInfo)
inlinestatic

◆ getOptTable()

TableRef getOptTable ( AMDGPULibFunc::EFuncId id)
static

Definition at line 369 of file AMDGPULibCalls.cpp.

References llvm::AMDGPULibFuncBase::EI_ACOS, llvm::AMDGPULibFuncBase::EI_ACOSH, llvm::AMDGPULibFuncBase::EI_ACOSPI, llvm::AMDGPULibFuncBase::EI_ASIN, llvm::AMDGPULibFuncBase::EI_ASINH, llvm::AMDGPULibFuncBase::EI_ASINPI, llvm::AMDGPULibFuncBase::EI_ATAN, llvm::AMDGPULibFuncBase::EI_ATANH, llvm::AMDGPULibFuncBase::EI_ATANPI, llvm::AMDGPULibFuncBase::EI_CBRT, llvm::AMDGPULibFuncBase::EI_COS, llvm::AMDGPULibFuncBase::EI_COSH, llvm::AMDGPULibFuncBase::EI_COSPI, llvm::AMDGPULibFuncBase::EI_ERF, llvm::AMDGPULibFuncBase::EI_ERFC, llvm::AMDGPULibFuncBase::EI_EXP, llvm::AMDGPULibFuncBase::EI_EXP10, llvm::AMDGPULibFuncBase::EI_EXP2, llvm::AMDGPULibFuncBase::EI_EXPM1, llvm::AMDGPULibFuncBase::EI_LOG, llvm::AMDGPULibFuncBase::EI_LOG10, llvm::AMDGPULibFuncBase::EI_LOG2, llvm::AMDGPULibFuncBase::EI_NCOS, llvm::AMDGPULibFuncBase::EI_NEXP2, llvm::AMDGPULibFuncBase::EI_NLOG2, llvm::AMDGPULibFuncBase::EI_NRSQRT, llvm::AMDGPULibFuncBase::EI_NSIN, llvm::AMDGPULibFuncBase::EI_NSQRT, llvm::AMDGPULibFuncBase::EI_RSQRT, llvm::AMDGPULibFuncBase::EI_SIN, llvm::AMDGPULibFuncBase::EI_SINH, llvm::AMDGPULibFuncBase::EI_SINPI, llvm::AMDGPULibFuncBase::EI_SQRT, llvm::AMDGPULibFuncBase::EI_TAN, llvm::AMDGPULibFuncBase::EI_TANH, llvm::AMDGPULibFuncBase::EI_TANPI, llvm::AMDGPULibFuncBase::EI_TGAMMA, tbl_acos, tbl_acosh, tbl_acospi, tbl_asin, tbl_asinh, tbl_asinpi, tbl_atan, tbl_atanh, tbl_atanpi, tbl_cbrt, tbl_cos, tbl_cosh, tbl_cospi, tbl_erf, tbl_erfc, tbl_exp, tbl_exp10, tbl_exp2, tbl_expm1, tbl_log, tbl_log10, tbl_log2, tbl_rsqrt, tbl_sin, tbl_sinh, tbl_sinpi, tbl_sqrt, tbl_tan, tbl_tanh, tbl_tanpi, and tbl_tgamma.

◆ getPownType()

◆ getVecSize()

int getVecSize ( const AMDGPULibFunc & FInfo)
inlinestatic

◆ HasNative()

Variable Documentation

◆ EnablePreLink

cl::opt< bool > EnablePreLink("amdgpu-prelink", cl::desc("Enable pre-link mode optimizations"), cl::init(false), cl::Hidden) ( "amdgpu-prelink" ,
cl::desc("Enable pre-link mode optimizations") ,
cl::init(false) ,
cl::Hidden  )
static

◆ tbl_acos

const TableEntry tbl_acos[]
static
Initial value:
= {
{MATH_PI / 2.0, 0.0},
{MATH_PI / 2.0, -0.0},
{0.0, 1.0},
{MATH_PI, -1.0}
}
#define MATH_PI

Definition at line 200 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_acosh

const TableEntry tbl_acosh[]
static
Initial value:
= {
{0.0, 1.0}
}

Definition at line 206 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_acospi

const TableEntry tbl_acospi[]
static
Initial value:
= {
{0.5, 0.0},
{0.5, -0.0},
{0.0, 1.0},
{1.0, -1.0}
}

Definition at line 209 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_asin

const TableEntry tbl_asin[]
static
Initial value:
= {
{0.0, 0.0},
{-0.0, -0.0},
{MATH_PI / 2.0, 1.0},
{-MATH_PI / 2.0, -1.0}
}

Definition at line 215 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_asinh

const TableEntry tbl_asinh[]
static
Initial value:
= {
{0.0, 0.0},
{-0.0, -0.0}
}

Definition at line 221 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_asinpi

const TableEntry tbl_asinpi[]
static
Initial value:
= {
{0.0, 0.0},
{-0.0, -0.0},
{0.5, 1.0},
{-0.5, -1.0}
}

Definition at line 225 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_atan

const TableEntry tbl_atan[]
static
Initial value:
= {
{0.0, 0.0},
{-0.0, -0.0},
{MATH_PI / 4.0, 1.0},
{-MATH_PI / 4.0, -1.0}
}

Definition at line 231 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_atanh

const TableEntry tbl_atanh[]
static
Initial value:
= {
{0.0, 0.0},
{-0.0, -0.0}
}

Definition at line 237 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_atanpi

const TableEntry tbl_atanpi[]
static
Initial value:
= {
{0.0, 0.0},
{-0.0, -0.0},
{0.25, 1.0},
{-0.25, -1.0}
}

Definition at line 241 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_cbrt

const TableEntry tbl_cbrt[]
static
Initial value:
= {
{0.0, 0.0},
{-0.0, -0.0},
{1.0, 1.0},
{-1.0, -1.0},
}

Definition at line 247 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_cos

const TableEntry tbl_cos[]
static
Initial value:
= {
{1.0, 0.0},
{1.0, -0.0}
}

Definition at line 253 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_cosh

const TableEntry tbl_cosh[]
static
Initial value:
= {
{1.0, 0.0},
{1.0, -0.0}
}

Definition at line 257 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_cospi

const TableEntry tbl_cospi[]
static
Initial value:
= {
{1.0, 0.0},
{1.0, -0.0}
}

Definition at line 261 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_erf

const TableEntry tbl_erf[]
static
Initial value:
= {
{0.0, 0.0},
{-0.0, -0.0}
}

Definition at line 269 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_erfc

const TableEntry tbl_erfc[]
static
Initial value:
= {
{1.0, 0.0},
{1.0, -0.0}
}

Definition at line 265 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_exp

const TableEntry tbl_exp[]
static
Initial value:
= {
{1.0, 0.0},
{1.0, -0.0},
{MATH_E, 1.0}
}
#define MATH_E

Definition at line 273 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_exp10

const TableEntry tbl_exp10[]
static
Initial value:
= {
{1.0, 0.0},
{1.0, -0.0},
{10.0, 1.0}
}

Definition at line 283 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_exp2

const TableEntry tbl_exp2[]
static
Initial value:
= {
{1.0, 0.0},
{1.0, -0.0},
{2.0, 1.0}
}

Definition at line 278 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_expm1

const TableEntry tbl_expm1[]
static
Initial value:
= {
{0.0, 0.0},
{-0.0, -0.0}
}

Definition at line 288 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_log

const TableEntry tbl_log[]
static
Initial value:
= {
{0.0, 1.0},
{1.0, MATH_E}
}

Definition at line 292 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_log10

const TableEntry tbl_log10[]
static
Initial value:
= {
{0.0, 1.0},
{1.0, 10.0}
}

Definition at line 300 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_log2

const TableEntry tbl_log2[]
static
Initial value:
= {
{0.0, 1.0},
{1.0, 2.0}
}

Definition at line 296 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_rsqrt

const TableEntry tbl_rsqrt[]
static
Initial value:
= {
{1.0, 1.0},
{MATH_SQRT1_2, 2.0}
}
#define MATH_SQRT1_2

Definition at line 304 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_sin

const TableEntry tbl_sin[]
static
Initial value:
= {
{0.0, 0.0},
{-0.0, -0.0}
}

Definition at line 308 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_sinh

const TableEntry tbl_sinh[]
static
Initial value:
= {
{0.0, 0.0},
{-0.0, -0.0}
}

Definition at line 312 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_sinpi

const TableEntry tbl_sinpi[]
static
Initial value:
= {
{0.0, 0.0},
{-0.0, -0.0}
}

Definition at line 316 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_sqrt

const TableEntry tbl_sqrt[]
static
Initial value:
= {
{0.0, 0.0},
{1.0, 1.0},
{MATH_SQRT2, 2.0}
}
#define MATH_SQRT2

Definition at line 320 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_tan

const TableEntry tbl_tan[]
static
Initial value:
= {
{0.0, 0.0},
{-0.0, -0.0}
}

Definition at line 325 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_tanh

const TableEntry tbl_tanh[]
static
Initial value:
= {
{0.0, 0.0},
{-0.0, -0.0}
}

Definition at line 329 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_tanpi

const TableEntry tbl_tanpi[]
static
Initial value:
= {
{0.0, 0.0},
{-0.0, -0.0}
}

Definition at line 333 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ tbl_tgamma

const TableEntry tbl_tgamma[]
static
Initial value:
= {
{1.0, 1.0},
{1.0, 2.0},
{2.0, 3.0},
{6.0, 4.0}
}

Definition at line 337 of file AMDGPULibCalls.cpp.

Referenced by getOptTable().

◆ UseNative

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) ( "amdgpu-use-native" ,
cl::desc("Comma separated list of functions to replace with native, or all") ,
cl::CommaSeparated ,
cl::ValueOptional ,
cl::Hidden  )
static