LLVM 20.0.0git
Macros | Functions
BuildLibCalls.cpp File Reference
#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>

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "build-libcalls"
 

Functions

 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")
 
static bool setDoesNotAccessMemory (Function &F)
 
static bool setIsCold (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)
 
static void setArgExtAttr (Function &F, unsigned ArgNo, const TargetLibraryInfo &TLI, bool Signed=true)
 
static void setRetExtAttr (Function &F, const TargetLibraryInfo &TLI, bool Signed=true)
 
static IntegerTypegetIntTy (IRBuilderBase &B, const TargetLibraryInfo *TLI)
 
static IntegerTypegetSizeTTy (IRBuilderBase &B, const TargetLibraryInfo *TLI)
 
static ValueemitLibCall (LibFunc TheLibFunc, Type *ReturnType, ArrayRef< Type * > ParamTypes, ArrayRef< Value * > Operands, IRBuilderBase &B, const TargetLibraryInfo *TLI, bool IsVaArgs=false)
 
static void appendTypeSuffix (Value *Op, StringRef &Name, SmallString< 20 > &NameBuffer)
 Append a suffix to the function name according to the type of 'Op'.
 
static ValueemitUnaryFloatFnCallHelper (Value *Op, LibFunc TheLibFunc, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs, const TargetLibraryInfo *TLI)
 
static ValueemitBinaryFloatFnCallHelper (Value *Op1, Value *Op2, LibFunc TheLibFunc, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs, const TargetLibraryInfo *TLI)
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "build-libcalls"

Definition at line 32 of file BuildLibCalls.cpp.

Function Documentation

◆ appendTypeSuffix()

static void appendTypeSuffix ( Value Op,
StringRef Name,
SmallString< 20 > &  NameBuffer 
)
static

Append a suffix to the function name according to the type of 'Op'.

Definition at line 1708 of file BuildLibCalls.cpp.

References Name.

Referenced by llvm::emitBinaryFloatFnCall(), and llvm::emitUnaryFloatFnCall().

◆ emitBinaryFloatFnCallHelper()

static Value * emitBinaryFloatFnCallHelper ( Value Op1,
Value Op2,
LibFunc  TheLibFunc,
StringRef  Name,
IRBuilderBase B,
const AttributeList Attrs,
const TargetLibraryInfo TLI 
)
static

◆ emitLibCall()

static Value * emitLibCall ( LibFunc  TheLibFunc,
Type ReturnType,
ArrayRef< Type * >  ParamTypes,
ArrayRef< Value * >  Operands,
IRBuilderBase B,
const TargetLibraryInfo TLI,
bool  IsVaArgs = false 
)
static

◆ emitUnaryFloatFnCallHelper()

static Value * emitUnaryFloatFnCallHelper ( Value Op,
LibFunc  TheLibFunc,
StringRef  Name,
IRBuilderBase B,
const AttributeList Attrs,
const TargetLibraryInfo TLI 
)
static

◆ getIntTy()

static IntegerType * getIntTy ( IRBuilderBase B,
const TargetLibraryInfo TLI 
)
static

◆ getSizeTTy()

static IntegerType * getSizeTTy ( IRBuilderBase B,
const TargetLibraryInfo TLI 
)
static

◆ setAlignedAllocParam()

static bool setAlignedAllocParam ( Function F,
unsigned  ArgNo 
)
static

Definition at line 225 of file BuildLibCalls.cpp.

References F.

Referenced by llvm::inferNonMandatoryLibFuncAttrs().

◆ setAllocatedPointerParam()

static bool setAllocatedPointerParam ( Function F,
unsigned  ArgNo 
)
static

Definition at line 232 of file BuildLibCalls.cpp.

References F.

Referenced by llvm::inferNonMandatoryLibFuncAttrs().

◆ setAllocFamily()

static bool setAllocFamily ( Function F,
StringRef  Family 
)
static

Definition at line 248 of file BuildLibCalls.cpp.

References F.

Referenced by llvm::inferNonMandatoryLibFuncAttrs().

◆ setAllocKind()

static bool setAllocKind ( Function F,
AllocFnKind  K 
)
static

Definition at line 255 of file BuildLibCalls.cpp.

References F, and llvm::Attribute::get().

Referenced by llvm::inferNonMandatoryLibFuncAttrs().

◆ setAllocSize()

static bool setAllocSize ( Function F,
unsigned  ElemSizeArg,
std::optional< unsigned NumElemsArg 
)
static

Definition at line 239 of file BuildLibCalls.cpp.

References F, and llvm::Attribute::getWithAllocSizeArgs().

Referenced by llvm::inferNonMandatoryLibFuncAttrs().

◆ setArgExtAttr()

static void setArgExtAttr ( Function F,
unsigned  ArgNo,
const TargetLibraryInfo TLI,
bool  Signed = true 
)
static

Definition at line 1267 of file BuildLibCalls.cpp.

References F, llvm::Attribute::None, and Signed.

Referenced by llvm::getOrInsertLibFunc().

◆ setArgNoUndef()

static bool setArgNoUndef ( Function F,
unsigned  ArgNo 
)
static

Definition at line 180 of file BuildLibCalls.cpp.

References F.

Referenced by llvm::inferNonMandatoryLibFuncAttrs().

◆ setArgsNoUndef()

static bool setArgsNoUndef ( Function F)
static

Definition at line 168 of file BuildLibCalls.cpp.

References F.

Referenced by llvm::inferNonMandatoryLibFuncAttrs(), and setRetAndArgsNoUndef().

◆ setDoesNotAccessMemory()

static bool setDoesNotAccessMemory ( Function F)
static

Definition at line 54 of file BuildLibCalls.cpp.

References F.

Referenced by llvm::inferNonMandatoryLibFuncAttrs().

◆ setDoesNotAlias()

static bool setDoesNotAlias ( Function F,
unsigned  ArgNo 
)
static

Definition at line 134 of file BuildLibCalls.cpp.

References F.

Referenced by llvm::inferNonMandatoryLibFuncAttrs().

◆ setDoesNotCapture()

static bool setDoesNotCapture ( Function F,
unsigned  ArgNo 
)
static

Definition at line 126 of file BuildLibCalls.cpp.

References F.

Referenced by llvm::inferNonMandatoryLibFuncAttrs().

◆ setDoesNotFreeMemory()

static bool setDoesNotFreeMemory ( Function F)
static

Definition at line 210 of file BuildLibCalls.cpp.

References F.

Referenced by llvm::inferNonMandatoryLibFuncAttrs().

◆ setDoesNotThrow()

static bool setDoesNotThrow ( Function F)
static

Definition at line 110 of file BuildLibCalls.cpp.

References F.

Referenced by llvm::inferNonMandatoryLibFuncAttrs().

◆ setIsCold()

static bool setIsCold ( Function F)
static

Definition at line 62 of file BuildLibCalls.cpp.

References F.

Referenced by llvm::inferNonMandatoryLibFuncAttrs().

◆ setNonLazyBind()

static bool setNonLazyBind ( Function F)
static

Definition at line 203 of file BuildLibCalls.cpp.

References F.

Referenced by llvm::inferNonMandatoryLibFuncAttrs(), and lowerObjCCall().

◆ setOnlyAccessesArgMemory()

static bool setOnlyAccessesArgMemory ( Function F)
static

Definition at line 94 of file BuildLibCalls.cpp.

References F.

Referenced by llvm::inferNonMandatoryLibFuncAttrs().

◆ setOnlyAccessesInaccessibleMemOrArgMem()

static bool setOnlyAccessesInaccessibleMemOrArgMem ( Function F)
static

Definition at line 102 of file BuildLibCalls.cpp.

References F.

Referenced by llvm::inferNonMandatoryLibFuncAttrs().

◆ setOnlyAccessesInaccessibleMemory()

static bool setOnlyAccessesInaccessibleMemory ( Function F)
static

Definition at line 70 of file BuildLibCalls.cpp.

References F.

Referenced by llvm::inferNonMandatoryLibFuncAttrs().

◆ setOnlyReadsMemory() [1/2]

static bool setOnlyReadsMemory ( Function F)
static

Definition at line 78 of file BuildLibCalls.cpp.

References F.

Referenced by llvm::inferNonMandatoryLibFuncAttrs().

◆ setOnlyReadsMemory() [2/2]

static bool setOnlyReadsMemory ( Function F,
unsigned  ArgNo 
)
static

Definition at line 142 of file BuildLibCalls.cpp.

References F.

◆ setOnlyWritesMemory() [1/2]

static bool setOnlyWritesMemory ( Function F)
static

Definition at line 86 of file BuildLibCalls.cpp.

References F.

Referenced by llvm::inferNonMandatoryLibFuncAttrs().

◆ setOnlyWritesMemory() [2/2]

static bool setOnlyWritesMemory ( Function F,
unsigned  ArgNo 
)
static

Definition at line 150 of file BuildLibCalls.cpp.

References F.

◆ setRetAndArgsNoUndef()

static bool setRetAndArgsNoUndef ( Function F)
static

Definition at line 188 of file BuildLibCalls.cpp.

References F, setArgsNoUndef(), and setRetNoUndef().

Referenced by llvm::inferNonMandatoryLibFuncAttrs().

◆ setRetDoesNotAlias()

static bool setRetDoesNotAlias ( Function F)
static

Definition at line 118 of file BuildLibCalls.cpp.

References F.

Referenced by llvm::inferNonMandatoryLibFuncAttrs().

◆ setRetExtAttr()

static void setRetExtAttr ( Function F,
const TargetLibraryInfo TLI,
bool  Signed = true 
)
static

Definition at line 1274 of file BuildLibCalls.cpp.

References F, llvm::Attribute::None, and Signed.

Referenced by llvm::getOrInsertLibFunc().

◆ setRetNoUndef()

static bool setRetNoUndef ( Function F)
static

Definition at line 158 of file BuildLibCalls.cpp.

References F.

Referenced by llvm::inferNonMandatoryLibFuncAttrs(), and setRetAndArgsNoUndef().

◆ setReturnedArg()

static bool setReturnedArg ( Function F,
unsigned  ArgNo 
)
static

Definition at line 195 of file BuildLibCalls.cpp.

References F.

Referenced by llvm::inferNonMandatoryLibFuncAttrs().

◆ setWillReturn()

static bool setWillReturn ( Function F)
static

Definition at line 217 of file BuildLibCalls.cpp.

References F.

Referenced by llvm::inferNonMandatoryLibFuncAttrs().

◆ STATISTIC() [1/15]

STATISTIC ( NumArgMemOnly  ,
"Number of functions inferred as argmemonly"   
)

◆ STATISTIC() [2/15]

STATISTIC ( NumCold  ,
"Number of functions inferred as cold"   
)

◆ STATISTIC() [3/15]

STATISTIC ( NumInaccessibleMemOnly  ,
"Number of functions inferred as inaccessiblememonly"   
)

◆ STATISTIC() [4/15]

STATISTIC ( NumInaccessibleMemOrArgMemOnly  ,
"Number of functions inferred as inaccessiblemem_or_argmemonly"   
)

◆ STATISTIC() [5/15]

STATISTIC ( NumNoAlias  ,
"Number of function returns inferred as noalias"   
)

◆ STATISTIC() [6/15]

STATISTIC ( NumNoCapture  ,
"Number of arguments inferred as nocapture"   
)

◆ STATISTIC() [7/15]

STATISTIC ( NumNoUndef  ,
"Number of function returns inferred as noundef returns"   
)

◆ STATISTIC() [8/15]

STATISTIC ( NumNoUnwind  ,
"Number of functions inferred as nounwind"   
)

◆ STATISTIC() [9/15]

STATISTIC ( NumReadNone  ,
"Number of functions inferred as readnone"   
)

◆ STATISTIC() [10/15]

STATISTIC ( NumReadOnly  ,
"Number of functions inferred as readonly"   
)

◆ STATISTIC() [11/15]

STATISTIC ( NumReadOnlyArg  ,
"Number of arguments inferred as readonly"   
)

◆ STATISTIC() [12/15]

STATISTIC ( NumReturnedArg  ,
"Number of arguments inferred as returned"   
)

◆ STATISTIC() [13/15]

STATISTIC ( NumWillReturn  ,
"Number of functions inferred as willreturn"   
)

◆ STATISTIC() [14/15]

STATISTIC ( NumWriteOnly  ,
"Number of functions inferred as writeonly"   
)

◆ STATISTIC() [15/15]

STATISTIC ( NumWriteOnlyArg  ,
"Number of arguments inferred as writeonly"   
)