29 #define DEBUG_TYPE "build-libcalls"
33 STATISTIC(NumReadNone,
"Number of functions inferred as readnone");
34 STATISTIC(NumReadOnly,
"Number of functions inferred as readonly");
35 STATISTIC(NumArgMemOnly,
"Number of functions inferred as argmemonly");
36 STATISTIC(NumNoUnwind,
"Number of functions inferred as nounwind");
37 STATISTIC(NumNoCapture,
"Number of arguments inferred as nocapture");
38 STATISTIC(NumReadOnlyArg,
"Number of arguments inferred as readonly");
39 STATISTIC(NumNoAlias,
"Number of function returns inferred as noalias");
40 STATISTIC(NumNonNull,
"Number of function returns inferred as nonnull returns");
100 "nonnull applies only to pointers");
113 bool Changed =
false;
114 switch (TheLibFunc) {
123 case LibFunc_strrchr:
130 case LibFunc_strtoul:
131 case LibFunc_strtoll:
132 case LibFunc_strtold:
133 case LibFunc_strtoull:
141 case LibFunc_strncat:
142 case LibFunc_strncpy:
143 case LibFunc_stpncpy:
148 case LibFunc_strxfrm:
156 case LibFunc_strncmp:
157 case LibFunc_strcspn:
158 case LibFunc_strcoll:
159 case LibFunc_strcasecmp:
160 case LibFunc_strncasecmp:
167 case LibFunc_strpbrk:
173 case LibFunc_strtok_r:
184 case LibFunc_setvbuf:
189 case LibFunc_strndup:
196 case LibFunc_statvfs:
209 case LibFunc_sprintf:
215 case LibFunc_snprintf:
221 case LibFunc_setitimer:
243 case LibFunc_memrchr:
254 case LibFunc_mempcpy:
255 case LibFunc_memccpy:
256 case LibFunc_memmove:
261 case LibFunc_memcpy_chk:
264 case LibFunc_memalign:
276 case LibFunc_realloc:
291 case LibFunc_realpath:
303 case LibFunc_readlink:
340 case LibFunc_ctermid:
341 case LibFunc_clearerr:
342 case LibFunc_closedir:
383 case LibFunc_fsetpos:
384 case LibFunc_flockfile:
385 case LibFunc_funlockfile:
386 case LibFunc_ftrylockfile:
400 case LibFunc_fstatvfs:
426 case LibFunc_fprintf:
432 case LibFunc_fgetpos:
438 case LibFunc_getlogin_r:
439 case LibFunc_getc_unlocked:
449 case LibFunc_getchar:
452 case LibFunc_getitimer:
456 case LibFunc_getpwnam:
474 case LibFunc_unsetenv:
507 case LibFunc_putchar:
527 case LibFunc_vsscanf:
534 case LibFunc_vfscanf:
544 case LibFunc_vprintf:
549 case LibFunc_vfprintf:
550 case LibFunc_vsprintf:
556 case LibFunc_vsnprintf:
567 case LibFunc_opendir:
573 case LibFunc_tmpfile:
603 case LibFunc_dunder_strdup:
604 case LibFunc_dunder_strndup:
610 case LibFunc_dunder_strtok_r:
615 case LibFunc_under_IO_getc:
619 case LibFunc_under_IO_putc:
623 case LibFunc_dunder_isoc99_scanf:
629 case LibFunc_lstat64:
630 case LibFunc_statvfs64:
636 case LibFunc_dunder_isoc99_sscanf:
643 case LibFunc_fopen64:
651 case LibFunc_fseeko64:
652 case LibFunc_ftello64:
656 case LibFunc_tmpfile64:
660 case LibFunc_fstat64:
661 case LibFunc_fstatvfs64:
670 case LibFunc_gettimeofday:
682 case LibFunc_msvc_new_int:
683 case LibFunc_msvc_new_longlong:
684 case LibFunc_msvc_new_array_int:
685 case LibFunc_msvc_new_array_longlong:
693 case LibFunc_memset_pattern16:
700 case LibFunc_nvvm_reflect:
721 if (!TLI->
has(LibFunc_strlen))
738 if (!TLI->
has(LibFunc_strchr))
756 if (!TLI->
has(LibFunc_strncmp))
776 if (!TLI->
has(LibFunc_strcpy))
792 if (!TLI->
has(LibFunc_strncpy))
810 if (!TLI->
has(LibFunc_memcpy_chk))
816 Attribute::NoUnwind);
832 if (!TLI->
has(LibFunc_memchr))
851 if (!TLI->
has(LibFunc_memcmp))
899 Attribute::Speculatable));
924 if (!TLI->
has(LibFunc_putchar))
944 if (!TLI->
has(LibFunc_puts))
959 if (!TLI->
has(LibFunc_fputc))
978 if (!TLI->
has(LibFunc_fputs))
996 if (!TLI->
has(LibFunc_fwrite))
bool hasAttribute(unsigned i, Attribute::AttrKind Kind) const
check if an attributes is in the list of attributes.
A parsed version of the target data layout string in and methods for querying it. ...
static bool setDoesNotCapture(Function &F, unsigned ArgNo)
STATISTIC(NumFunctions,"Total number of functions")
bool onlyReadsMemory() const
Determine if the function does not access or only reads memory.
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
adds the attribute to the list of attributes for the given arg.
A Module instance is used to store all the information related to an LLVM module. ...
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
This class represents a function call, abstracting a target machine's calling convention.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
The two locations do not alias at all.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
Value * emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilder<> &B, const TargetLibraryInfo *TLI, StringRef Name="strncpy")
Emit a call to the strncpy function to the builder, for the specified pointer arguments and length...
static bool setRetDoesNotAlias(Function &F)
void setCallingConv(CallingConv::ID CC)
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
bool doesNotThrow() const
Determine if the function cannot unwind.
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr it the function does no...
const Constant * stripPointerCasts() const
Value * emitPutChar(Value *Char, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the putchar function. This assumes that Char is an integer.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Value * emitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilder<> &B, const AttributeList &Attrs)
Emit a call to the unary function named 'Name' (e.g.
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
static bool setDoesNotThrow(Function &F)
Value * emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the __memcpy_chk function to the builder.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Value * emitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B, const TargetLibraryInfo *TLI, StringRef Name="strcpy")
Emit a call to the strcpy function to the builder, for the specified pointer arguments.
bool doesNotAccessMemory() const
Determine if the function does not access memory.
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
check if an attributes is in the list of attributes.
void setOnlyAccessesArgMemory()
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
Value * emitFPutS(Value *Str, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the puts function.
bool inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI)
Analyze the name and prototype of the given function and set any applicable attributes.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
Type * getReturnType() const
Returns the type of the ret val.
void setOnlyReadsMemory()
static void appendTypeSuffix(Value *Op, StringRef &Name, SmallString< 20 > &NameBuffer)
Append a suffix to the function name according to the type of 'Op'.
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.
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
static bool setOnlyReadsMemory(Function &F)
void addAttribute(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
Value * castToCStr(Value *V, IRBuilder<> &B)
Return V if it is an i8*, otherwise cast it to i8*.
static bool setDoesNotAccessMemory(Function &F)
bool isPointerTy() const
True if this is an instance of PointerType.
static bool setRetNonNull(Function &F)
Value * emitStrChr(Value *Ptr, char C, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the strchr function to the builder, for the specified pointer and character.
AttributeList removeAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified index from this attribute list.
LLVMContext & getContext() const
PointerType * getInt8PtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer to an 8-bit integer value.
bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
Value * emitStrLen(Value *Ptr, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the strlen function to the builder, for the specified pointer.
Value * emitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name, IRBuilder<> &B, const AttributeList &Attrs)
Emit a call to the binary function named 'Name' (e.g.
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
Provides information about what library functions are available for the current target.
BasicBlock * GetInsertBlock() const
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
Value * emitFPutC(Value *Char, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fputc function.
void setDoesNotAccessMemory()
Value * emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the strncmp function to the builder.
static bool setOnlyAccessesArgMemory(Function &F)
CallInst * CreateCall(Value *Callee, ArrayRef< Value * > Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
StringRef getName(LibFunc F) const
Value * emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the fwrite function.
Value * emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memcmp function.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVMContext & getContext() const
Get the context in which this basic block lives.
LLVM Value Representation.
Value * emitPutS(Value *Str, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the puts function. This assumes that Str is some pointer.
Value * emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memchr function.
StringRef - Represent a constant reference to a string, i.e.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
bool has(LibFunc F) const
Tests whether a library function is available.
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute >> Attrs)
Create an AttributeList with the specified parameters in it.
LLVMContext & getContext() const
Get the global data context.