LLVM 22.0.0git
Functions | Variables
SimplifyLibCalls.cpp File Reference
#include "llvm/Transforms/Utils/SimplifyLibCalls.h"
#include "llvm/ADT/APFloat.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/TargetLibraryInfo.h"
#include "llvm/Analysis/Utils/Local.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/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Support/KnownFPClass.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)
  Return true if it is only used in equality comparisons with With.
static ValueconvertStrToInt (CallInst *CI, StringRef &Str, Value *EndPtr, uint64_t Base, bool AsSigned, IRBuilderBase &B)
static void  annotateDereferenceableBytes (CallInst *CI, ArrayRef< unsigned > ArgNos, uint64_t DereferenceableBytes)
static ValuecopyFlags (const CallInst &Old, Value *New)
static StringRef  substr (StringRef Str, uint64_t Len)
  Return a variant of Val with float type.
  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 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 bool  isReportingError (Function *Callee, CallInst *CI, int StreamArg)
static ValueoptimizeNaN (CallInst *CI)
  Constant folding nan/nanf/nanl.

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< boolOptimizeExistingHotColdNew ("optimize-existing-hot-cold-new", cl::Hidden, cl::init(false), cl::desc("Enable optimization of existing hot/cold operator new library calls"))
static cl::opt< boolOptimizeNoBuiltinHotColdNew ("optimize-nobuiltin-hot-cold-new-new", cl::Hidden, cl::init(false), cl::desc("Enable transformation of nobuiltin 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 >  NotColdNewHintValue ("notcold-new-hint-value", cl::Hidden, cl::init(128), cl::desc("Value to pass to hot/cold operator new for " "notcold (warm) 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"))
static cl::opt< unsigned, false, HotColdHintParser >  AmbiguousNewHintValue ("ambiguous-new-hint-value", cl::Hidden, cl::init(222), cl::desc("Value to pass to hot/cold operator new for ambiguous allocation"))

Function Documentation

◆  annotateDereferenceableBytes()

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

Definition at line 276 of file SimplifyLibCalls.cpp.

References llvm::CallBase::addParamAttr(), F, llvm::CallBase::getArgOperand(), llvm::CallBase::getCaller(), llvm::Value::getContext(), llvm::CallBase::getParamDereferenceableBytes(), llvm::CallBase::getParamDereferenceableOrNullBytes(), llvm::Type::getPointerAddressSpace(), llvm::Value::getType(), llvm::Attribute::getWithDereferenceableBytes(), llvm::NullPointerIsDefined(), llvm::CallBase::paramHasAttr(), and llvm::CallBase::removeParamAttr().

Referenced by annotateNonNullAndDereferenceable(), and annotateNonNullNoUndefBasedOnAccess().

◆  annotateNonNullAndDereferenceable()

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

Definition at line 323 of file SimplifyLibCalls.cpp.

References annotateDereferenceableBytes(), annotateNonNullNoUndefBasedOnAccess(), DL, llvm::dyn_cast(), llvm::isKnownNonZero(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), Size, X, and Y.

◆  annotateNonNullNoUndefBasedOnAccess()

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

Definition at line 301 of file SimplifyLibCalls.cpp.

References llvm::CallBase::addParamAttr(), annotateDereferenceableBytes(), F, llvm::CallBase::getArgOperand(), llvm::CallBase::getCaller(), llvm::Type::getPointerAddressSpace(), llvm::Value::getType(), llvm::NullPointerIsDefined(), and llvm::CallBase::paramHasAttr().

Referenced by annotateNonNullAndDereferenceable().

◆  callHasFloatingPointArgument()

bool callHasFloatingPointArgument ( const CallInst * CI )
static

Definition at line 129 of file SimplifyLibCalls.cpp.

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

◆  callHasFP128Argument()

bool callHasFP128Argument ( const CallInst * CI )
static

Definition at line 135 of file SimplifyLibCalls.cpp.

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

◆  canTransformToMemCmp()

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

Definition at line 262 of file SimplifyLibCalls.cpp.

References DL, llvm::Instruction::getFunction(), llvm::Function::hasFnAttribute(), llvm::isDereferenceableAndAlignedPointer(), and isOnlyUsedInComparisonWithZero().

◆  convertStrToInt()

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

Definition at line 148 of file SimplifyLibCalls.cpp.

References B(), llvm::sampleprof::Base, llvm::CallBase::getArgOperand(), llvm::Type::getPrimitiveSizeInBits(), llvm::Value::getType(), llvm::isAlpha(), llvm::isDigit(), llvm::isSpace(), llvm::maxIntN(), llvm::maxUIntN(), llvm::Offset, llvm::SaturatingMultiplyAdd(), and llvm::toUpper().

◆  copyFlags()

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

Definition at line 344 of file SimplifyLibCalls.cpp.

References assert(), llvm::dyn_cast_or_null(), llvm::CallInst::getTailCallKind(), llvm::CallInst::isMustTailCall(), and llvm::CallInst::isNoTailCall().

Referenced by mergeAttributesAndFlags(), optimizeSymmetricCall(), and replaceUnaryCall().

◆  createPowWithIntegerExponent()

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

Definition at line 2348 of file SimplifyLibCalls.cpp.

References B(), llvm::sampleprof::Base, and llvm::Value::getType().

◆  getIntToFPVal()

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

Definition at line 2083 of file SimplifyLibCalls.cpp.

References B(), llvm::BitWidth, llvm::cast(), and llvm::isa().

◆  getSqrtCall()

Value * getSqrtCall ( Value * V,
AttributeList Attrs,
bool NoErrno,
Module * M,
static

Definition at line 2277 of file SimplifyLibCalls.cpp.

References B(), llvm::emitUnaryFloatFnCall(), and llvm::hasFloatFn().

◆  ignoreCallingConv()

bool ignoreCallingConv ( LibFunc Func )
static

Definition at line 112 of file SimplifyLibCalls.cpp.

Referenced by llvm::FortifiedLibCallSimplifier::optimizeCall(), and llvm::LibCallSimplifier::optimizeCall().

◆  insertSinCosCall()

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

Definition at line 2938 of file SimplifyLibCalls.cpp.

References assert(), B(), llvm::BasicBlock::begin(), llvm::dyn_cast(), llvm::FixedVectorType::get(), llvm::StructType::get(), llvm::Function::getAttributes(), llvm::TargetLibraryInfo::getLibFunc(), llvm::getOrInsertLibFunc(), llvm::GlobalValue::getParent(), llvm::Module::getTargetTriple(), llvm::Value::getType(), llvm::isLibFuncEmittable(), llvm::Type::isStructTy(), T, llvm::Triple::x86, and llvm::Triple::x86_64.

◆  isOnlyUsedInComparisonWithZero()

bool isOnlyUsedInComparisonWithZero ( Value * V )
static

Definition at line 250 of file SimplifyLibCalls.cpp.

References llvm::CallingConv::C, llvm::dyn_cast(), and llvm::Value::users().

Referenced by canTransformToMemCmp().

◆  isOnlyUsedInEqualityComparison()

bool isOnlyUsedInEqualityComparison ( Value * V,
Value * With )
static

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

Definition at line 118 of file SimplifyLibCalls.cpp.

References llvm::dyn_cast(), and llvm::Value::users().

◆  isReportingError()

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

Definition at line 3310 of file SimplifyLibCalls.cpp.

References llvm::CallBase::arg_size(), llvm::dyn_cast(), llvm::CallBase::getArgOperand(), llvm::Value::getName(), llvm::LoadInst::getPointerOperand(), and llvm::GlobalValue::isDeclaration().

◆  isTrigLibCall()

bool isTrigLibCall ( CallInst * CI )
static

Definition at line 2931 of file SimplifyLibCalls.cpp.

References llvm::CallBase::doesNotAccessMemory(), and llvm::CallBase::doesNotThrow().

◆  memChrToCharCompare()

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

Definition at line 461 of file SimplifyLibCalls.cpp.

References B(), DL, llvm::CallBase::getArgOperand(), llvm::Constant::getNullValue(), and llvm::Value::getType().

◆  mergeAttributesAndFlags()

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

Definition at line 352 of file SimplifyLibCalls.cpp.

References llvm::CallBase::arg_size(), copyFlags(), llvm::CallBase::getArgOperand(), llvm::Value::getContext(), llvm::CallBase::getParamAttributes(), llvm::CallBase::getRetAttributes(), llvm::Value::getType(), I, llvm::CallBase::removeParamAttrs(), llvm::CallBase::removeRetAttrs(), and llvm::CallBase::setAttributes().

◆  optimizeBinaryDoubleFP()

Value * optimizeBinaryDoubleFP ( CallInst * CI,
bool isPrecise = false )
static

Shrink double -> float for binary functions.

Definition at line 2025 of file SimplifyLibCalls.cpp.

References B(), and optimizeDoubleFP().

◆  optimizeDoubleFP()

Value * optimizeDoubleFP ( CallInst * CI,
bool isBinary,
bool isPrecise = false )
static

Shrink double -> float functions.

Definition at line 1959 of file SimplifyLibCalls.cpp.

References B(), llvm::dyn_cast(), llvm::emitBinaryFloatFnCall(), llvm::emitUnaryFloatFnCall(), llvm::StringRef::ends_with(), llvm::CallBase::getArgOperand(), llvm::Function::getAttributes(), llvm::CallBase::getCalledFunction(), llvm::Instruction::getFastMathFlags(), llvm::Instruction::getFunction(), llvm::Function::getIntrinsicID(), llvm::Value::getName(), llvm::Value::getType(), isBinary(), llvm::Type::isDoubleTy(), llvm::Type::isFloatTy(), llvm::Function::isIntrinsic(), llvm::StringRef::size(), llvm::StringRef::starts_with(), llvm::Value::users(), and valueHasFloatPrecision().

Referenced by optimizeBinaryDoubleFP(), and optimizeUnaryDoubleFP().

◆  optimizeMemCmpConstantSize()

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

Definition at line 1542 of file SimplifyLibCalls.cpp.

References B(), llvm::ConstantFoldLoadFromConstPtr(), DL, llvm::dyn_cast(), llvm::IntegerType::get(), llvm::Value::getContext(), llvm::getKnownAlignment(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::isOnlyUsedInZeroEqualityComparison(), LHS, and RHS.

◆  optimizeMemCmpVarSize()

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

Definition at line 1500 of file SimplifyLibCalls.cpp.

References B(), DL, llvm::getConstantStringInfo(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::CmpInst::ICMP_ULE, LHS, RHS, Size, and llvm::StringRef::size().

◆  optimizeNaN()

Value * optimizeNaN ( CallInst * CI )
static

Constant folding nan/nanf/nanl.

Definition at line 3992 of file SimplifyLibCalls.cpp.

References llvm::StringRef::empty(), llvm::CallBase::getArgOperand(), llvm::StringRef::getAsInteger(), llvm::getConstantStringInfo(), llvm::ConstantFP::getQNaN(), and llvm::Value::getType().

◆  optimizeSymmetricCall()

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

Definition at line 2994 of file SimplifyLibCalls.cpp.

References B(), Call, copyFlags(), llvm::CallBase::getArgOperand(), llvm::CallBase::getCalledFunction(), llvm::PatternMatch::m_CopySign(), llvm::PatternMatch::m_FAbs(), llvm::PatternMatch::m_FNeg(), llvm::MIPatternMatch::m_OneUse(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), and X.

◆  optimizeUnaryDoubleFP()

Value * optimizeUnaryDoubleFP ( CallInst * CI,
bool isPrecise = false )
static

Shrink double -> float for unary functions.

Definition at line 2018 of file SimplifyLibCalls.cpp.

References B(), and optimizeDoubleFP().

Referenced by llvm::LibCallSimplifier::optimizeCall().

◆  replaceUnaryCall()

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

Definition at line 1929 of file SimplifyLibCalls.cpp.

References B(), copyFlags(), llvm::CallBase::getArgOperand(), and llvm::Value::takeName().

◆  substr()

StringRef substr ( StringRef Str,
uint64_t Len )
static

Definition at line 366 of file SimplifyLibCalls.cpp.

Referenced by llvm::StringRef::consume_back(), llvm::StringRef::consume_back_insensitive(), llvm::StringRef::consume_front(), llvm::StringRef::consume_front_insensitive(), llvm::StringRef::drop_back(), llvm::StringRef::drop_front(), llvm::StringRef::drop_until(), llvm::StringRef::drop_while(), llvm::DWARFDataExtractor::DWARFDataExtractor(), llvm::DWARFDataExtractorBase< Relocator >::DWARFDataExtractorBase(), llvm::object::MachOObjectFile::getSectionContents(), llvm::PGOCtxProfileReader::PGOCtxProfileReader(), llvm::DXContainerYAML::PSVInfo::PSVInfo(), llvm::StringRef::rsplit(), llvm::DXContainerYAML::SignatureElement::SignatureElement(), llvm::StringRef::split(), llvm::StringRef::take_until(), and llvm::StringRef::take_while().

◆  valueHasFloatPrecision()

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 1941 of file SimplifyLibCalls.cpp.

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

Referenced by optimizeDoubleFP().

Variable Documentation

◆  AmbiguousNewHintValue

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

◆  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

Referenced by llvm::LibCallSimplifier::optimizeCall().

◆  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

◆  NotColdNewHintValue

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

◆  OptimizeExistingHotColdNew

cl::opt< bool > OptimizeExistingHotColdNew("optimize-existing-hot-cold-new", cl::Hidden, cl::init(false), cl::desc( "Enable optimization of existing hot/cold operator new library calls")) ( "optimize-existing-hot-cold-new" ,
cl::Hidden ,
cl::init(false) ,
cl::desc( "Enable optimization of existing hot/cold operator new library calls")  )
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

◆  OptimizeNoBuiltinHotColdNew

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

Generated on for LLVM by doxygen 1.14.0

AltStyle によって変換されたページ (->オリジナル) /