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");
101 "nonnull applies only to pointers");
114 bool Changed =
false;
115 switch (TheLibFunc) {
116 case LibFunc::strlen:
121 case LibFunc::strchr:
122 case LibFunc::strrchr:
126 case LibFunc::strtol:
127 case LibFunc::strtod:
128 case LibFunc::strtof:
129 case LibFunc::strtoul:
130 case LibFunc::strtoll:
131 case LibFunc::strtold:
132 case LibFunc::strtoull:
137 case LibFunc::strcpy:
138 case LibFunc::stpcpy:
139 case LibFunc::strcat:
140 case LibFunc::strncat:
141 case LibFunc::strncpy:
142 case LibFunc::stpncpy:
147 case LibFunc::strxfrm:
154 case LibFunc::strspn:
155 case LibFunc::strncmp:
156 case LibFunc::strcspn:
157 case LibFunc::strcoll:
158 case LibFunc::strcasecmp:
159 case LibFunc::strncasecmp:
165 case LibFunc::strstr:
166 case LibFunc::strpbrk:
171 case LibFunc::strtok:
172 case LibFunc::strtok_r:
182 case LibFunc::setbuf:
183 case LibFunc::setvbuf:
187 case LibFunc::strdup:
188 case LibFunc::strndup:
195 case LibFunc::statvfs:
201 case LibFunc::sscanf:
208 case LibFunc::sprintf:
214 case LibFunc::snprintf:
220 case LibFunc::setitimer:
226 case LibFunc::system:
231 case LibFunc::malloc:
235 case LibFunc::memcmp:
241 case LibFunc::memchr:
242 case LibFunc::memrchr:
252 case LibFunc::memcpy:
253 case LibFunc::mempcpy:
254 case LibFunc::memccpy:
255 case LibFunc::memmove:
260 case LibFunc::memcpy_chk:
263 case LibFunc::memalign:
271 case LibFunc::mktime:
275 case LibFunc::realloc:
284 case LibFunc::rewind:
290 case LibFunc::realpath:
302 case LibFunc::readlink:
329 case LibFunc::calloc:
339 case LibFunc::ctermid:
340 case LibFunc::clearerr:
341 case LibFunc::closedir:
366 case LibFunc::fdopen:
377 case LibFunc::fseeko:
378 case LibFunc::ftello:
379 case LibFunc::fileno:
380 case LibFunc::fflush:
381 case LibFunc::fclose:
382 case LibFunc::fsetpos:
383 case LibFunc::flockfile:
384 case LibFunc::funlockfile:
385 case LibFunc::ftrylockfile:
389 case LibFunc::ferror:
397 case LibFunc::frexpf:
398 case LibFunc::frexpl:
399 case LibFunc::fstatvfs:
412 case LibFunc::fwrite:
424 case LibFunc::fscanf:
425 case LibFunc::fprintf:
431 case LibFunc::fgetpos:
437 case LibFunc::getlogin_r:
438 case LibFunc::getc_unlocked:
442 case LibFunc::getenv:
448 case LibFunc::getchar:
451 case LibFunc::getitimer:
455 case LibFunc::getpwnam:
460 case LibFunc::ungetc:
468 case LibFunc::unlink:
473 case LibFunc::unsetenv:
479 case LibFunc::utimes:
491 case LibFunc::printf:
492 case LibFunc::perror:
501 case LibFunc::pwrite:
506 case LibFunc::putchar:
517 case LibFunc::pclose:
521 case LibFunc::vscanf:
526 case LibFunc::vsscanf:
533 case LibFunc::vfscanf:
539 case LibFunc::valloc:
543 case LibFunc::vprintf:
548 case LibFunc::vfprintf:
549 case LibFunc::vsprintf:
555 case LibFunc::vsnprintf:
566 case LibFunc::opendir:
572 case LibFunc::tmpfile:
593 case LibFunc::lchown:
602 case LibFunc::dunder_strdup:
603 case LibFunc::dunder_strndup:
609 case LibFunc::dunder_strtok_r:
614 case LibFunc::under_IO_getc:
618 case LibFunc::under_IO_putc:
622 case LibFunc::dunder_isoc99_scanf:
627 case LibFunc::stat64:
628 case LibFunc::lstat64:
629 case LibFunc::statvfs64:
635 case LibFunc::dunder_isoc99_sscanf:
642 case LibFunc::fopen64:
650 case LibFunc::fseeko64:
651 case LibFunc::ftello64:
655 case LibFunc::tmpfile64:
659 case LibFunc::fstat64:
660 case LibFunc::fstatvfs64:
664 case LibFunc::open64:
669 case LibFunc::gettimeofday:
681 case LibFunc::msvc_new_int:
682 case LibFunc::msvc_new_longlong:
683 case LibFunc::msvc_new_array_int:
684 case LibFunc::msvc_new_array_longlong:
692 case LibFunc::memset_pattern16:
699 case LibFunc::nvvm_reflect:
720 if (!TLI->
has(LibFunc::strlen))
737 if (!TLI->
has(LibFunc::strchr))
755 if (!TLI->
has(LibFunc::strncmp))
775 if (!TLI->
has(LibFunc::strcpy))
791 if (!TLI->
has(LibFunc::strncpy))
809 if (!TLI->
has(LibFunc::memcpy_chk))
815 Attribute::NoUnwind);
831 if (!TLI->
has(LibFunc::memchr))
850 if (!TLI->
has(LibFunc::memcmp))
917 if (!TLI->
has(LibFunc::putchar))
937 if (!TLI->
has(LibFunc::puts))
952 if (!TLI->
has(LibFunc::fputc))
971 if (!TLI->
has(LibFunc::fputs))
989 if (!TLI->
has(LibFunc::fwrite))
A parsed version of the target data layout string in and methods for querying it. ...
STATISTIC(NumFunctions,"Total number of functions")
value_type read(const void *memory)
Read a value of a particular endianness from memory.
bool onlyReadsMemory() const
Determine if the function does not access or only reads memory.
A Module instance is used to store all the information related to an LLVM module. ...
std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
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.
Type * getReturnType() const
Returns the type of the ret val.
Value * emitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilder<> &B, const AttributeSet &Attrs)
Emit a call to the unary function named 'Name' (e.g.
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...
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with strcmp
bool doesNotAlias(unsigned n) const
Determine if the parameter or return value is marked with NoAlias attribute.
void setCallingConv(CallingConv::ID CC)
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
bool doesNotThrow() const
Determine if the function cannot unwind.
bool has(LibFunc::Func F) const
Tests whether a library function is available.
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr it the function does no...
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 * 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...
IEEEFloat frexp(const IEEEFloat &Val, int &Exp, IEEEFloat::roundingMode RM)
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.
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
bool doesNotAccessMemory() const
Determine if the function does not access memory.
void setOnlyAccessesArgMemory()
void setAttributes(AttributeSet Attrs)
Set the parameter attributes for this call.
void setDoesNotCapture(unsigned n)
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 getLibFunc(StringRef funcName, LibFunc::Func &F) const
Searches for a particular function name.
bool inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI)
Analyze the name and prototype of the given function and set any applicable attributes.
void setOnlyReadsMemory()
Constant * stripPointerCasts()
static void appendTypeSuffix(Value *Op, StringRef &Name, SmallString< 20 > &NameBuffer)
Append a suffix to the function name according to the type of 'Op'.
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeSet AttributeList)
Look up the specified function in the module symbol table.
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 setDoesNotAlias(unsigned n)
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 void write(bool isBE, void *P, T V)
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.
bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
static bool setNonNull(Function &F, unsigned n)
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 * 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
Value * stripPointerCasts()
Strip off pointer casts, all-zero GEPs, and aliases.
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.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
AttributeSet getAttributes() const
Return the attribute list for this Function.
Value * emitFPutC(Value *Char, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fputc function.
StringRef getName(LibFunc::Func F) const
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)
static void rename(GlobalValue *GV)
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.
static bool setDoesNotCapture(Function &F, unsigned n)
LLVM Value Representation.
bool doesNotCapture(unsigned n) const
Determine if the parameter can be captured.
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.
Value * emitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name, IRBuilder<> &B, const AttributeSet &Attrs)
Emit a call to the binary function named 'Name' (e.g.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
static bool setDoesNotAlias(Function &F, unsigned n)
LLVMContext & getContext() const
Get the global data context.