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");
120 bool Changed =
false;
125 switch (TheLibFunc) {
134 case LibFunc_strrchr:
141 case LibFunc_strtoul:
142 case LibFunc_strtoll:
143 case LibFunc_strtold:
144 case LibFunc_strtoull:
152 case LibFunc_strncat:
153 case LibFunc_strncpy:
154 case LibFunc_stpncpy:
159 case LibFunc_strxfrm:
167 case LibFunc_strncmp:
168 case LibFunc_strcspn:
169 case LibFunc_strcoll:
170 case LibFunc_strcasecmp:
171 case LibFunc_strncasecmp:
178 case LibFunc_strpbrk:
184 case LibFunc_strtok_r:
195 case LibFunc_setvbuf:
200 case LibFunc_strndup:
207 case LibFunc_statvfs:
220 case LibFunc_sprintf:
226 case LibFunc_snprintf:
232 case LibFunc_setitimer:
254 case LibFunc_memrchr:
265 case LibFunc_mempcpy:
266 case LibFunc_memccpy:
267 case LibFunc_memmove:
272 case LibFunc_memcpy_chk:
275 case LibFunc_memalign:
287 case LibFunc_realloc:
302 case LibFunc_realpath:
314 case LibFunc_readlink:
351 case LibFunc_ctermid:
352 case LibFunc_clearerr:
353 case LibFunc_closedir:
389 case LibFunc_fgetc_unlocked:
395 case LibFunc_fsetpos:
396 case LibFunc_flockfile:
397 case LibFunc_funlockfile:
398 case LibFunc_ftrylockfile:
408 case LibFunc_fputc_unlocked:
413 case LibFunc_fstatvfs:
418 case LibFunc_fgets_unlocked:
423 case LibFunc_fread_unlocked:
429 case LibFunc_fwrite_unlocked:
436 case LibFunc_fputs_unlocked:
443 case LibFunc_fprintf:
449 case LibFunc_fgetpos:
455 case LibFunc_getlogin_r:
456 case LibFunc_getc_unlocked:
466 case LibFunc_getchar:
467 case LibFunc_getchar_unlocked:
470 case LibFunc_getitimer:
474 case LibFunc_getpwnam:
492 case LibFunc_unsetenv:
506 case LibFunc_putc_unlocked:
526 case LibFunc_putchar:
527 case LibFunc_putchar_unlocked:
547 case LibFunc_vsscanf:
554 case LibFunc_vfscanf:
564 case LibFunc_vprintf:
569 case LibFunc_vfprintf:
570 case LibFunc_vsprintf:
576 case LibFunc_vsnprintf:
587 case LibFunc_opendir:
593 case LibFunc_tmpfile:
623 case LibFunc_dunder_strdup:
624 case LibFunc_dunder_strndup:
630 case LibFunc_dunder_strtok_r:
635 case LibFunc_under_IO_getc:
639 case LibFunc_under_IO_putc:
643 case LibFunc_dunder_isoc99_scanf:
649 case LibFunc_lstat64:
650 case LibFunc_statvfs64:
656 case LibFunc_dunder_isoc99_sscanf:
663 case LibFunc_fopen64:
671 case LibFunc_fseeko64:
672 case LibFunc_ftello64:
676 case LibFunc_tmpfile64:
680 case LibFunc_fstat64:
681 case LibFunc_fstatvfs64:
690 case LibFunc_gettimeofday:
702 case LibFunc_msvc_new_int:
703 case LibFunc_msvc_new_longlong:
704 case LibFunc_msvc_new_array_int:
705 case LibFunc_msvc_new_array_longlong:
713 case LibFunc_memset_pattern16:
720 case LibFunc_nvvm_reflect:
737 return TLI->
has(FloatFn);
739 return TLI->
has(DoubleFn);
741 return TLI->
has(LongDoubleFn);
754 if (!TLI->
has(LibFunc_strlen))
771 if (!TLI->
has(LibFunc_strchr))
789 if (!TLI->
has(LibFunc_strncmp))
809 if (!TLI->
has(LibFunc_strcpy))
825 if (!TLI->
has(LibFunc_strncpy))
843 if (!TLI->
has(LibFunc_memcpy_chk))
849 Attribute::NoUnwind);
865 if (!TLI->
has(LibFunc_memchr))
884 if (!TLI->
has(LibFunc_memcmp))
932 Attribute::Speculatable));
957 if (!TLI->
has(LibFunc_putchar))
977 if (!TLI->
has(LibFunc_puts))
992 if (!TLI->
has(LibFunc_fputc))
1011 if (!TLI->
has(LibFunc_fputc_unlocked))
1029 if (!TLI->
has(LibFunc_fputs))
1047 if (!TLI->
has(LibFunc_fputs_unlocked))
1065 if (!TLI->
has(LibFunc_fwrite))
1088 if (!TLI->
has(LibFunc_malloc))
1106 if (!TLI.
has(LibFunc_calloc))
1126 if (!TLI->
has(LibFunc_fwrite_unlocked))
1147 if (!TLI->
has(LibFunc_fgetc_unlocked))
1164 if (!TLI->
has(LibFunc_fgets_unlocked))
1183 if (!TLI->
has(LibFunc_fread_unlocked))
bool onlyReadsMemory() const
Determine if the function does not access or only reads memory.
A parsed version of the target data layout string in and methods for querying it. ...
static bool setDoesNotCapture(Function &F, unsigned ArgNo)
LLVMContext & getContext() const
Compute iterated dominance frontiers using a linear time algorithm.
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. ...
2: 32-bit floating point type
This class represents a function call, abstracting a target machine's calling convention.
The two locations do not alias at all.
StringRef getName(LibFunc F) const
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
STATISTIC(NumFunctions, "Total number of functions")
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
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...
Value * emitFPutSUnlocked(Value *Str, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fputs_unlocked function.
LLVMContext & getContext() const
Get the context in which this basic block lives.
Value * emitMalloc(Value *Num, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the malloc function.
static bool setRetDoesNotAlias(Function &F)
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
static bool setNonLazyBind(Function &F)
TypeID getTypeID() const
Return the type id for the type.
LLVMContext & getContext() const
Get the global data context.
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...
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
check if an attributes is in the list of attributes.
Value * emitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilder<> &B, const AttributeList &Attrs)
Emit a call to the unary function named 'Name' (e.g.
Value * emitFPutCUnlocked(Value *Char, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fputc_unlocked function.
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Type * getType() const
All values are typed, get the type of this value.
static bool setDoesNotThrow(Function &F)
BasicBlock * GetInsertBlock() const
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.
bool hasAttribute(unsigned i, Attribute::AttrKind Kind) const
check if an attributes is in the list of attributes.
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
bool has(LibFunc F) const
Tests whether a library function is available.
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.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
amdgpu Simplify well known AMD library false Value * Callee
void setOnlyAccessesArgMemory()
bool doesNotAccessMemory() const
Determine if the function does not access memory.
Value * emitFPutS(Value *Str, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fputs function.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
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...
bool inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI)
Analyze the name and prototype of the given function and set any applicable attributes.
Type * getReturnType() const
Returns the type of the ret val.
void setOnlyReadsMemory()
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
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 isPointerTy() const
True if this is an instance of PointerType.
static bool setOnlyReadsMemory(Function &F)
void addAttribute(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
Class to represent integer types.
Value * castToCStr(Value *V, IRBuilder<> &B)
Return V if it is an i8*, otherwise cast it to i8*.
static bool setDoesNotAccessMemory(Function &F)
const Constant * stripPointerCasts() const
static bool setRetNonNull(Function &F)
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
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.
PointerType * getInt8PtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer to an 8-bit integer value.
void setCallingConv(CallingConv::ID CC)
bool doesNotThrow() const
Determine if the function cannot unwind.
Value * emitFWriteUnlocked(Value *Ptr, Value *Size, Value *N, Value *File, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the fwrite_unlocked function.
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 * emitFGetCUnlocked(Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fgetc_unlocked function. File is a pointer to FILE.
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
Module.h This file contains the declarations for the Module class.
Provides information about what library functions are available for the current target.
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.
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
bool getRtLibUseGOT() const
Returns true if PLT should be avoided for RTLib calls.
Value * emitFPutC(Value *Char, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fputc function.
Value * emitFGetSUnlocked(Value *Str, Value *Size, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fgets_unlocked 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.
AttributeList removeAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified index from this attribute list.
static bool setOnlyAccessesArgMemory(Function &F)
bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
Value * emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the fwrite function.
3: 64-bit floating point type
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())
Value * emitFReadUnlocked(Value *Ptr, Value *Size, Value *N, Value *File, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the fread_unlocked function.
Module * getParent()
Get the module that this global value is contained inside of...
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.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
Value * emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memchr function.
Value * emitCalloc(Value *Num, Value *Size, const AttributeList &Attrs, IRBuilder<> &B, const TargetLibraryInfo &TLI)
Emit a call to the calloc function.
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
StringRef - Represent a constant reference to a string, i.e.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
bool hasUnaryFloatFn(const TargetLibraryInfo *TLI, Type *Ty, LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn)
Check whether the overloaded unary floating point function corresponding to Ty is available...
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute >> Attrs)
Create an AttributeList with the specified parameters in it.
CallInst * CreateCall(Value *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)