#include "llvm/Transforms/Utils/BuildLibCalls.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/Support/TypeSize.h"
#include <optional>
usingnamespacellvm;
#define DEBUG_TYPE …
STATISTIC(NumReadNone, "Number of functions inferred as readnone");
STATISTIC(NumInaccessibleMemOnly,
"Number of functions inferred as inaccessiblememonly");
STATISTIC(NumReadOnly, "Number of functions inferred as readonly");
STATISTIC(NumWriteOnly, "Number of functions inferred as writeonly");
STATISTIC(NumArgMemOnly, "Number of functions inferred as argmemonly");
STATISTIC(NumInaccessibleMemOrArgMemOnly,
"Number of functions inferred as inaccessiblemem_or_argmemonly");
STATISTIC(NumNoUnwind, "Number of functions inferred as nounwind");
STATISTIC(NumNoCapture, "Number of arguments inferred as nocapture");
STATISTIC(NumWriteOnlyArg, "Number of arguments inferred as writeonly");
STATISTIC(NumReadOnlyArg, "Number of arguments inferred as readonly");
STATISTIC(NumNoAlias, "Number of function returns inferred as noalias");
STATISTIC(NumNoUndef, "Number of function returns inferred as noundef returns");
STATISTIC(NumReturnedArg, "Number of arguments inferred as returned");
STATISTIC(NumWillReturn, "Number of functions inferred as willreturn");
STATISTIC(NumCold, "Number of functions inferred as cold");
STATISTIC(NumNoReturn, "Number of functions inferred as no return");
static bool setDoesNotAccessMemory(Function &F) { … }
static bool setIsCold(Function &F) { … }
static bool setNoReturn(Function &F) { … }
static bool setOnlyAccessesInaccessibleMemory(Function &F) { … }
static bool setOnlyReadsMemory(Function &F) { … }
static bool setOnlyWritesMemory(Function &F) { … }
static bool setOnlyAccessesArgMemory(Function &F) { … }
static bool setOnlyAccessesInaccessibleMemOrArgMem(Function &F) { … }
static bool setDoesNotThrow(Function &F) { … }
static bool setRetDoesNotAlias(Function &F) { … }
static bool setDoesNotCapture(Function &F, unsigned ArgNo) { … }
static bool setDoesNotAlias(Function &F, unsigned ArgNo) { … }
static bool setOnlyReadsMemory(Function &F, unsigned ArgNo) { … }
static bool setOnlyWritesMemory(Function &F, unsigned ArgNo) { … }
static bool setRetNoUndef(Function &F) { … }
static bool setArgsNoUndef(Function &F) { … }
static bool setArgNoUndef(Function &F, unsigned ArgNo) { … }
static bool setRetAndArgsNoUndef(Function &F) { … }
static bool setReturnedArg(Function &F, unsigned ArgNo) { … }
static bool setNonLazyBind(Function &F) { … }
static bool setDoesNotFreeMemory(Function &F) { … }
static bool setWillReturn(Function &F) { … }
static bool setAlignedAllocParam(Function &F, unsigned ArgNo) { … }
static bool setAllocatedPointerParam(Function &F, unsigned ArgNo) { … }
static bool setAllocSize(Function &F, unsigned ElemSizeArg,
std::optional<unsigned> NumElemsArg) { … }
static bool setAllocFamily(Function &F, StringRef Family) { … }
static bool setAllocKind(Function &F, AllocFnKind K) { … }
bool llvm::inferNonMandatoryLibFuncAttrs(Module *M, StringRef Name,
const TargetLibraryInfo &TLI) { … }
bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
const TargetLibraryInfo &TLI) { … }
static void setArgExtAttr(Function &F, unsigned ArgNo,
const TargetLibraryInfo &TLI, bool Signed = true) { … }
static void setRetExtAttr(Function &F,
const TargetLibraryInfo &TLI, bool Signed = true) { … }
void llvm::markRegisterParameterAttributes(Function *F) { … }
FunctionCallee llvm::getOrInsertLibFunc(Module *M, const TargetLibraryInfo &TLI,
LibFunc TheLibFunc, FunctionType *T,
AttributeList AttributeList) { … }
FunctionCallee llvm::getOrInsertLibFunc(Module *M, const TargetLibraryInfo &TLI,
LibFunc TheLibFunc, FunctionType *T) { … }
bool llvm::isLibFuncEmittable(const Module *M, const TargetLibraryInfo *TLI,
LibFunc TheLibFunc) { … }
bool llvm::isLibFuncEmittable(const Module *M, const TargetLibraryInfo *TLI,
StringRef Name) { … }
bool llvm::hasFloatFn(const Module *M, const TargetLibraryInfo *TLI, Type *Ty,
LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn) { … }
StringRef llvm::getFloatFn(const Module *M, const TargetLibraryInfo *TLI,
Type *Ty, LibFunc DoubleFn, LibFunc FloatFn,
LibFunc LongDoubleFn, LibFunc &TheLibFunc) { … }
static IntegerType *getIntTy(IRBuilderBase &B, const TargetLibraryInfo *TLI) { … }
static IntegerType *getSizeTTy(IRBuilderBase &B, const TargetLibraryInfo *TLI) { … }
static Value *emitLibCall(LibFunc TheLibFunc, Type *ReturnType,
ArrayRef<Type *> ParamTypes,
ArrayRef<Value *> Operands, IRBuilderBase &B,
const TargetLibraryInfo *TLI,
bool IsVaArgs = false) { … }
Value *llvm::emitStrLen(Value *Ptr, IRBuilderBase &B, const DataLayout &DL,
const TargetLibraryInfo *TLI) { … }
Value *llvm::emitStrDup(Value *Ptr, IRBuilderBase &B,
const TargetLibraryInfo *TLI) { … }
Value *llvm::emitStrChr(Value *Ptr, char C, IRBuilderBase &B,
const TargetLibraryInfo *TLI) { … }
Value *llvm::emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
const DataLayout &DL, const TargetLibraryInfo *TLI) { … }
Value *llvm::emitStrCpy(Value *Dst, Value *Src, IRBuilderBase &B,
const TargetLibraryInfo *TLI) { … }
Value *llvm::emitStpCpy(Value *Dst, Value *Src, IRBuilderBase &B,
const TargetLibraryInfo *TLI) { … }
Value *llvm::emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
const TargetLibraryInfo *TLI) { … }
Value *llvm::emitStpNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
const TargetLibraryInfo *TLI) { … }
Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
IRBuilderBase &B, const DataLayout &DL,
const TargetLibraryInfo *TLI) { … }
Value *llvm::emitMemPCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
const DataLayout &DL, const TargetLibraryInfo *TLI) { … }
Value *llvm::emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B,
const DataLayout &DL, const TargetLibraryInfo *TLI) { … }
Value *llvm::emitMemRChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B,
const DataLayout &DL, const TargetLibraryInfo *TLI) { … }
Value *llvm::emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
const DataLayout &DL, const TargetLibraryInfo *TLI) { … }
Value *llvm::emitBCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
const DataLayout &DL, const TargetLibraryInfo *TLI) { … }
Value *llvm::emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len,
IRBuilderBase &B, const TargetLibraryInfo *TLI) { … }
Value *llvm::emitSNPrintf(Value *Dest, Value *Size, Value *Fmt,
ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
const TargetLibraryInfo *TLI) { … }
Value *llvm::emitSPrintf(Value *Dest, Value *Fmt,
ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
const TargetLibraryInfo *TLI) { … }
Value *llvm::emitStrCat(Value *Dest, Value *Src, IRBuilderBase &B,
const TargetLibraryInfo *TLI) { … }
Value *llvm::emitStrLCpy(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
const TargetLibraryInfo *TLI) { … }
Value *llvm::emitStrLCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
const TargetLibraryInfo *TLI) { … }
Value *llvm::emitStrNCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
const TargetLibraryInfo *TLI) { … }
Value *llvm::emitVSNPrintf(Value *Dest, Value *Size, Value *Fmt, Value *VAList,
IRBuilderBase &B, const TargetLibraryInfo *TLI) { … }
Value *llvm::emitVSPrintf(Value *Dest, Value *Fmt, Value *VAList,
IRBuilderBase &B, const TargetLibraryInfo *TLI) { … }
static void appendTypeSuffix(Value *Op, StringRef &Name,
SmallString<20> &NameBuffer) { … }
static Value *emitUnaryFloatFnCallHelper(Value *Op, LibFunc TheLibFunc,
StringRef Name, IRBuilderBase &B,
const AttributeList &Attrs,
const TargetLibraryInfo *TLI) { … }
Value *llvm::emitUnaryFloatFnCall(Value *Op, const TargetLibraryInfo *TLI,
StringRef Name, IRBuilderBase &B,
const AttributeList &Attrs) { … }
Value *llvm::emitUnaryFloatFnCall(Value *Op, const TargetLibraryInfo *TLI,
LibFunc DoubleFn, LibFunc FloatFn,
LibFunc LongDoubleFn, IRBuilderBase &B,
const AttributeList &Attrs) { … }
static Value *emitBinaryFloatFnCallHelper(Value *Op1, Value *Op2,
LibFunc TheLibFunc,
StringRef Name, IRBuilderBase &B,
const AttributeList &Attrs,
const TargetLibraryInfo *TLI) { … }
Value *llvm::emitBinaryFloatFnCall(Value *Op1, Value *Op2,
const TargetLibraryInfo *TLI,
StringRef Name, IRBuilderBase &B,
const AttributeList &Attrs) { … }
Value *llvm::emitBinaryFloatFnCall(Value *Op1, Value *Op2,
const TargetLibraryInfo *TLI,
LibFunc DoubleFn, LibFunc FloatFn,
LibFunc LongDoubleFn, IRBuilderBase &B,
const AttributeList &Attrs) { … }
Value *llvm::emitPutChar(Value *Char, IRBuilderBase &B,
const TargetLibraryInfo *TLI) { … }
Value *llvm::emitPutS(Value *Str, IRBuilderBase &B,
const TargetLibraryInfo *TLI) { … }
Value *llvm::emitFPutC(Value *Char, Value *File, IRBuilderBase &B,
const TargetLibraryInfo *TLI) { … }
Value *llvm::emitFPutS(Value *Str, Value *File, IRBuilderBase &B,
const TargetLibraryInfo *TLI) { … }
Value *llvm::emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilderBase &B,
const DataLayout &DL, const TargetLibraryInfo *TLI) { … }
Value *llvm::emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL,
const TargetLibraryInfo *TLI) { … }
Value *llvm::emitCalloc(Value *Num, Value *Size, IRBuilderBase &B,
const TargetLibraryInfo &TLI, unsigned AddrSpace) { … }
Value *llvm::emitHotColdSizeReturningNew(Value *Num, IRBuilderBase &B,
const TargetLibraryInfo *TLI,
LibFunc SizeFeedbackNewFunc,
uint8_t HotCold) { … }
Value *llvm::emitHotColdSizeReturningNewAligned(Value *Num, Value *Align,
IRBuilderBase &B,
const TargetLibraryInfo *TLI,
LibFunc SizeFeedbackNewFunc,
uint8_t HotCold) { … }
Value *llvm::emitHotColdNew(Value *Num, IRBuilderBase &B,
const TargetLibraryInfo *TLI, LibFunc NewFunc,
uint8_t HotCold) { … }
Value *llvm::emitHotColdNewNoThrow(Value *Num, Value *NoThrow, IRBuilderBase &B,
const TargetLibraryInfo *TLI,
LibFunc NewFunc, uint8_t HotCold) { … }
Value *llvm::emitHotColdNewAligned(Value *Num, Value *Align, IRBuilderBase &B,
const TargetLibraryInfo *TLI,
LibFunc NewFunc, uint8_t HotCold) { … }
Value *llvm::emitHotColdNewAlignedNoThrow(Value *Num, Value *Align,
Value *NoThrow, IRBuilderBase &B,
const TargetLibraryInfo *TLI,
LibFunc NewFunc, uint8_t HotCold) { … }