LLVM 19.0.0git
Functions | Variables
SimplifyLibCalls.cpp File Reference
#include "llvm/Transforms/Utils/SimplifyLibCalls.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/Loads.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/AttributeMask.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/TargetParser/Triple.h"
#include "llvm/Transforms/Utils/BuildLibCalls.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/SizeOpts.h"
#include <cmath>

Go to the source code of this file.

Functions

static bool ignoreCallingConv (LibFunc Func)
 
static bool isOnlyUsedInEqualityComparison (Value *V, Value *With)
 Return true if it is only used in equality comparisons with With.
 
static bool callHasFloatingPointArgument (const CallInst *CI)
 
static bool callHasFP128Argument (const CallInst *CI)
 
static ValueconvertStrToInt (CallInst *CI, StringRef &Str, Value *EndPtr, uint64_t Base, bool AsSigned, IRBuilderBase &B)
 
static bool isOnlyUsedInComparisonWithZero (Value *V)
 
static bool canTransformToMemCmp (CallInst *CI, Value *Str, uint64_t Len, const DataLayout &DL)
 
static void annotateDereferenceableBytes (CallInst *CI, ArrayRef< unsigned > ArgNos, uint64_t DereferenceableBytes)
 
static void annotateNonNullNoUndefBasedOnAccess (CallInst *CI, ArrayRef< unsigned > ArgNos)
 
static void annotateNonNullAndDereferenceable (CallInst *CI, ArrayRef< unsigned > ArgNos, Value *Size, const DataLayout &DL)
 
static ValuecopyFlags (const CallInst &Old, Value *New)
 
static ValuemergeAttributesAndFlags (CallInst *NewCI, const CallInst &Old)
 
static StringRef substr (StringRef Str, uint64_t Len)
 
static ValuememChrToCharCompare (CallInst *CI, Value *NBytes, IRBuilderBase &B, const DataLayout &DL)
 
static ValueoptimizeMemCmpVarSize (CallInst *CI, Value *LHS, Value *RHS, Value *Size, bool StrNCmp, IRBuilderBase &B, const DataLayout &DL)
 
static ValueoptimizeMemCmpConstantSize (CallInst *CI, Value *LHS, Value *RHS, uint64_t Len, IRBuilderBase &B, const DataLayout &DL)
 
static ValuereplaceUnaryCall (CallInst *CI, IRBuilderBase &B, Intrinsic::ID IID)
 
static ValuevalueHasFloatPrecision (Value *Val)
 Return a variant of Val with float type.
 
static ValueoptimizeDoubleFP (CallInst *CI, IRBuilderBase &B, bool isBinary, const TargetLibraryInfo *TLI, bool isPrecise=false)
 Shrink double -> float functions.
 
static ValueoptimizeUnaryDoubleFP (CallInst *CI, IRBuilderBase &B, const TargetLibraryInfo *TLI, bool isPrecise=false)
 Shrink double -> float for unary functions.
 
static ValueoptimizeBinaryDoubleFP (CallInst *CI, IRBuilderBase &B, const TargetLibraryInfo *TLI, bool isPrecise=false)
 Shrink double -> float for binary functions.
 
static ValuegetIntToFPVal (Value *I2F, IRBuilderBase &B, unsigned DstWidth)
 
static ValuegetSqrtCall (Value *V, AttributeList Attrs, bool NoErrno, Module *M, IRBuilderBase &B, const TargetLibraryInfo *TLI)
 
static ValuecreatePowWithIntegerExponent (Value *Base, Value *Expo, Module *M, IRBuilderBase &B)
 
static bool isTrigLibCall (CallInst *CI)
 
static bool insertSinCosCall (IRBuilderBase &B, Function *OrigCallee, Value *Arg, bool UseFloat, Value *&Sin, Value *&Cos, Value *&SinCos, const TargetLibraryInfo *TLI)
 
static ValueoptimizeSymmetricCall (CallInst *CI, bool IsEven, IRBuilderBase &B)
 
static bool isReportingError (Function *Callee, CallInst *CI, int StreamArg)
 

Variables

static cl::opt< boolEnableUnsafeFPShrink ("enable-double-float-shrink", cl::Hidden, cl::init(false), cl::desc("Enable unsafe double to float " "shrinking for math lib calls"))
 
static cl::opt< boolOptimizeHotColdNew ("optimize-hot-cold-new", cl::Hidden, cl::init(false), cl::desc("Enable hot/cold operator new library calls"))
 
static cl::opt< unsigned, false, HotColdHintParser > ColdNewHintValue ("cold-new-hint-value", cl::Hidden, cl::init(1), cl::desc("Value to pass to hot/cold operator new for cold allocation"))
 
static cl::opt< unsigned, false, HotColdHintParser > HotNewHintValue ("hot-new-hint-value", cl::Hidden, cl::init(254), cl::desc("Value to pass to hot/cold operator new for hot allocation"))
 

Function Documentation

◆ annotateDereferenceableBytes()

static void annotateDereferenceableBytes ( CallInst CI,
ArrayRef< unsigned ArgNos,
uint64_t  DereferenceableBytes 
)
static

◆ annotateNonNullAndDereferenceable()

static void annotateNonNullAndDereferenceable ( CallInst CI,
ArrayRef< unsigned ArgNos,
Value Size,
const DataLayout DL 
)
static

◆ annotateNonNullNoUndefBasedOnAccess()

static void annotateNonNullNoUndefBasedOnAccess ( CallInst CI,
ArrayRef< unsigned ArgNos 
)
static

◆ callHasFloatingPointArgument()

static bool callHasFloatingPointArgument ( const CallInst CI)
static

Definition at line 109 of file SimplifyLibCalls.cpp.

References llvm::any_of(), and llvm::User::operands().

◆ callHasFP128Argument()

static bool callHasFP128Argument ( const CallInst CI)
static

Definition at line 115 of file SimplifyLibCalls.cpp.

References llvm::any_of(), and llvm::User::operands().

◆ canTransformToMemCmp()

static bool canTransformToMemCmp ( CallInst CI,
Value Str,
uint64_t  Len,
const DataLayout DL 
)
static

◆ convertStrToInt()

static Value * convertStrToInt ( CallInst CI,
StringRef Str,
Value EndPtr,
uint64_t  Base,
bool  AsSigned,
IRBuilderBase B 
)
static

◆ copyFlags()

static Value * copyFlags ( const CallInst Old,
Value New 
)
static

◆ createPowWithIntegerExponent()

static Value * createPowWithIntegerExponent ( Value Base,
Value Expo,
Module M,
IRBuilderBase B 
)
static

◆ getIntToFPVal()

static Value * getIntToFPVal ( Value I2F,
IRBuilderBase B,
unsigned  DstWidth 
)
static

Definition at line 1913 of file SimplifyLibCalls.cpp.

References B, and llvm::BitWidth.

◆ getSqrtCall()

static Value * getSqrtCall ( Value V,
AttributeList  Attrs,
bool  NoErrno,
Module M,
IRBuilderBase B,
const TargetLibraryInfo TLI 
)
static

◆ ignoreCallingConv()

static bool ignoreCallingConv ( LibFunc  Func)
static

◆ insertSinCosCall()

static bool insertSinCosCall ( IRBuilderBase B,
Function OrigCallee,
Value Arg,
bool  UseFloat,
Value *&  Sin,
Value *&  Cos,
Value *&  SinCos,
const TargetLibraryInfo TLI 
)
static

◆ isOnlyUsedInComparisonWithZero()

static bool isOnlyUsedInComparisonWithZero ( Value V)
static

Definition at line 230 of file SimplifyLibCalls.cpp.

References llvm::CallingConv::C.

Referenced by canTransformToMemCmp().

◆ isOnlyUsedInEqualityComparison()

static bool isOnlyUsedInEqualityComparison ( Value V,
Value With 
)
static

Return true if it is only used in equality comparisons with With.

Definition at line 98 of file SimplifyLibCalls.cpp.

◆ isReportingError()

static bool isReportingError ( Function Callee,
CallInst CI,
int  StreamArg 
)
static

◆ isTrigLibCall()

static bool isTrigLibCall ( CallInst CI)
static

◆ memChrToCharCompare()

static Value * memChrToCharCompare ( CallInst CI,
Value NBytes,
IRBuilderBase B,
const DataLayout DL 
)
static

◆ mergeAttributesAndFlags()

static Value * mergeAttributesAndFlags ( CallInst NewCI,
const CallInst Old 
)
static

◆ optimizeBinaryDoubleFP()

static Value * optimizeBinaryDoubleFP ( CallInst CI,
IRBuilderBase B,
const TargetLibraryInfo TLI,
bool  isPrecise = false 
)
static

Shrink double -> float for binary functions.

Definition at line 1875 of file SimplifyLibCalls.cpp.

References B, and optimizeDoubleFP().

◆ optimizeDoubleFP()

static Value * optimizeDoubleFP ( CallInst CI,
IRBuilderBase B,
bool  isBinary,
const TargetLibraryInfo TLI,
bool  isPrecise = false 
)
static

◆ optimizeMemCmpConstantSize()

static Value * optimizeMemCmpConstantSize ( CallInst CI,
Value LHS,
Value RHS,
uint64_t  Len,
IRBuilderBase B,
const DataLayout DL 
)
static

◆ optimizeMemCmpVarSize()

static Value * optimizeMemCmpVarSize ( CallInst CI,
Value LHS,
Value RHS,
Value Size,
bool  StrNCmp,
IRBuilderBase B,
const DataLayout DL 
)
static

◆ optimizeSymmetricCall()

static Value * optimizeSymmetricCall ( CallInst CI,
bool  IsEven,
IRBuilderBase B 
)
static

◆ optimizeUnaryDoubleFP()

static Value * optimizeUnaryDoubleFP ( CallInst CI,
IRBuilderBase B,
const TargetLibraryInfo TLI,
bool  isPrecise = false 
)
static

Shrink double -> float for unary functions.

Definition at line 1868 of file SimplifyLibCalls.cpp.

References B, and optimizeDoubleFP().

◆ replaceUnaryCall()

static Value * replaceUnaryCall ( CallInst CI,
IRBuilderBase B,
Intrinsic::ID  IID 
)
static

◆ substr()

static StringRef substr ( StringRef  Str,
uint64_t  Len 
)
static

◆ valueHasFloatPrecision()

static Value * valueHasFloatPrecision ( Value Val)
static

Return a variant of Val with float type.

Currently this works in two cases: If Val is an FPExtension of a float value to something bigger, simply return the operand. If Val is a ConstantFP but can be converted to a float ConstantFP without loss of precision do so.

Definition at line 1790 of file SimplifyLibCalls.cpp.

References F, llvm::APFloatBase::IEEEsingle(), and llvm::APFloatBase::rmNearestTiesToEven.

Referenced by optimizeDoubleFP().

Variable Documentation

◆ ColdNewHintValue

cl::opt< unsigned, false, HotColdHintParser > ColdNewHintValue("cold-new-hint-value", cl::Hidden, cl::init(1), cl::desc("Value to pass to hot/cold operator new for cold allocation")) ( "cold-new-hint-value"  ,
cl::Hidden  ,
cl::init(1)  ,
cl::desc("Value to pass to hot/cold operator new for cold allocation")   
)
static

◆ EnableUnsafeFPShrink

cl::opt< bool > EnableUnsafeFPShrink("enable-double-float-shrink", cl::Hidden, cl::init(false), cl::desc("Enable unsafe double to float " "shrinking for math lib calls")) ( "enable-double-float-shrink"  ,
cl::Hidden  ,
cl::init(false)  ,
cl::desc("Enable unsafe double to float " "shrinking for math lib calls")   
)
static

◆ HotNewHintValue

cl::opt< unsigned, false, HotColdHintParser > HotNewHintValue("hot-new-hint-value", cl::Hidden, cl::init(254), cl::desc("Value to pass to hot/cold operator new for hot allocation")) ( "hot-new-hint-value"  ,
cl::Hidden  ,
cl::init(254)  ,
cl::desc("Value to pass to hot/cold operator new for hot allocation")   
)
static

◆ OptimizeHotColdNew

cl::opt< bool > OptimizeHotColdNew("optimize-hot-cold-new", cl::Hidden, cl::init(false), cl::desc("Enable hot/cold operator new library calls")) ( "optimize-hot-cold-new"  ,
cl::Hidden  ,
cl::init(false)  ,
cl::desc("Enable hot/cold operator new library calls")   
)
static