LLVM  9.0.0svn
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/StringMap.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Analysis/BlockFrequencyInfo.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/Analysis/ProfileSummaryInfo.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/Analysis/CaptureTracking.h"
#include "llvm/Analysis/Loads.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/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Transforms/Utils/BuildLibCalls.h"
#include "llvm/Transforms/Utils/SizeOpts.h"
Include dependency graph for SimplifyLibCalls.cpp:

Go to the source code of this file.

Functions

static bool ignoreCallingConv (LibFunc Func)
 
static bool isCallingConvCCompatible (CallInst *CI)
 
static bool isOnlyUsedInEqualityComparison (Value *V, Value *With)
 Return true if it is only used in equality comparisons with With. More...
 
static bool callHasFloatingPointArgument (const CallInst *CI)
 
static bool callHasFP128Argument (const CallInst *CI)
 
static ValueconvertStrToNumber (CallInst *CI, StringRef &Str, int64_t Base)
 
static bool isLocallyOpenedFile (Value *File, CallInst *CI, IRBuilder<> &B, const TargetLibraryInfo *TLI)
 
static bool isOnlyUsedInComparisonWithZero (Value *V)
 
static bool canTransformToMemCmp (CallInst *CI, Value *Str, uint64_t Len, const DataLayout &DL)
 
static ValueoptimizeMemCmpConstantSize (CallInst *CI, Value *LHS, Value *RHS, uint64_t Len, IRBuilder<> &B, const DataLayout &DL)
 
static ValuereplaceUnaryCall (CallInst *CI, IRBuilder<> &B, Intrinsic::ID IID)
 
static ValuevalueHasFloatPrecision (Value *Val)
 Return a variant of Val with float type. More...
 
static ValueoptimizeDoubleFP (CallInst *CI, IRBuilder<> &B, bool isBinary, bool isPrecise=false)
 Shrink double -> float functions. More...
 
static ValueoptimizeUnaryDoubleFP (CallInst *CI, IRBuilder<> &B, bool isPrecise=false)
 Shrink double -> float for unary functions. More...
 
static ValueoptimizeBinaryDoubleFP (CallInst *CI, IRBuilder<> &B, bool isPrecise=false)
 Shrink double -> float for binary functions. More...
 
static ValueoptimizeTrigReflections (CallInst *Call, LibFunc Func, IRBuilder<> &B)
 
static ValuegetPow (Value *InnerChain[33], unsigned Exp, IRBuilder<> &B)
 
static ValuegetSqrtCall (Value *V, AttributeList Attrs, bool NoErrno, Module *M, IRBuilder<> &B, const TargetLibraryInfo *TLI)
 
static bool isTrigLibCall (CallInst *CI)
 
static void insertSinCosCall (IRBuilder<> &B, Function *OrigCallee, Value *Arg, bool UseFloat, Value *&Sin, Value *&Cos, Value *&SinCos)
 
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"))
 

Function Documentation

◆ callHasFloatingPointArgument()

static bool callHasFloatingPointArgument ( const CallInst CI)
static

Definition at line 104 of file SimplifyLibCalls.cpp.

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

Referenced by isReportingError().

◆ callHasFP128Argument()

static bool callHasFP128Argument ( const CallInst CI)
static

Definition at line 110 of file SimplifyLibCalls.cpp.

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

Referenced by isReportingError().

◆ canTransformToMemCmp()

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

Definition at line 175 of file SimplifyLibCalls.cpp.

References llvm::CallBase::addParamAttr(), llvm::ConstantDataArraySlice::Array, B, llvm::StringRef::begin(), llvm::tgtok::Bits, C, Callee, llvm::castToCStr(), llvm::StringRef::compare(), llvm::computeKnownBits(), llvm::IRBuilder< T, Inserter >::CreateAnd(), llvm::IRBuilder< T, Inserter >::CreateBitCast(), llvm::IRBuilder< T, Inserter >::CreateConstInBoundsGEP1_64(), llvm::IRBuilder< T, Inserter >::CreateGEP(), llvm::IRBuilder< T, Inserter >::CreateICmp(), llvm::IRBuilder< T, Inserter >::CreateInBoundsGEP(), llvm::IRBuilder< T, Inserter >::CreateIntToPtr(), llvm::IRBuilder< T, Inserter >::CreateIsNotNull(), llvm::IRBuilder< T, Inserter >::CreateLoad(), llvm::IRBuilderBase::CreateMemCpy(), llvm::IRBuilderBase::CreateMemSet(), llvm::IRBuilder< T, Inserter >::CreateNeg(), llvm::IRBuilder< T, Inserter >::CreateSelect(), llvm::IRBuilder< T, Inserter >::CreateSExtOrTrunc(), llvm::IRBuilder< T, Inserter >::CreateShl(), llvm::IRBuilder< T, Inserter >::CreateSub(), llvm::IRBuilder< T, Inserter >::CreateZExt(), llvm::IRBuilder< T, Inserter >::CreateZExtOrTrunc(), llvm::dyn_cast(), E, llvm::emitMemChr(), llvm::emitMemCmp(), llvm::emitStrChr(), llvm::emitStrLen(), llvm::emitStrNCmp(), llvm::StringRef::empty(), llvm::StringRef::end(), llvm::StringRef::find(), llvm::StringRef::find_first_not_of(), llvm::StringRef::find_first_of(), llvm::APInt::flipAllBits(), GEP, llvm::ConstantInt::get(), llvm::CallBase::getArgOperand(), llvm::CallBase::getCalledFunction(), llvm::getConstantDataArrayInfo(), llvm::getConstantStringInfo(), llvm::Value::getContext(), llvm::ConstantDataSequential::getElementAsInteger(), llvm::Instruction::getFunction(), llvm::Function::getFunctionType(), llvm::IRBuilderBase::getInt(), llvm::IRBuilderBase::getInt64(), llvm::IRBuilderBase::getInt8(), llvm::IRBuilderBase::getInt8Ty(), llvm::IRBuilderBase::getIntN(), llvm::IRBuilderBase::getIntNTy(), llvm::Instruction::getModule(), llvm::Constant::getNullValue(), llvm::FunctionType::getParamType(), llvm::CmpInst::getPredicate(), llvm::ConstantInt::getSExtValue(), llvm::GetStringLength(), llvm::Value::getType(), llvm::Function::hasFnAttribute(), I, llvm::CmpInst::ICMP_ULT, llvm::isDereferenceableAndAlignedPointer(), llvm::isGEPBasedOnPointerToString(), llvm::Type::isIntegerTy(), llvm::APInt::isNonNegative(), isOnlyUsedInComparisonWithZero(), isOnlyUsedInEqualityComparison(), llvm::isOnlyUsedInZeroEqualityComparison(), llvm::ConstantInt::isZero(), llvm::ConstantDataArraySlice::Length, llvm::max(), llvm::NextPowerOf2(), llvm::StringRef::npos, llvm::ConstantDataArraySlice::Offset, llvm::StringRef::rfind(), llvm::APInt::setBit(), SI, llvm::StringRef::size(), llvm::StringRef::substr(), llvm::APInt::ule(), llvm::Value::user_begin(), llvm::Value::user_end(), and llvm::KnownBits::Zero.

◆ convertStrToNumber()

static Value* convertStrToNumber ( CallInst CI,
StringRef Str,
int64_t  Base 
)
static

Definition at line 116 of file SimplifyLibCalls.cpp.

◆ getPow()

static Value* getPow ( Value InnerChain[33],
unsigned  Exp,
IRBuilder<> &  B 
)
static

◆ getSqrtCall()

static Value* getSqrtCall ( Value V,
AttributeList  Attrs,
bool  NoErrno,
Module M,
IRBuilder<> &  B,
const TargetLibraryInfo TLI 
)
static

Definition at line 1353 of file SimplifyLibCalls.cpp.

References llvm::abs(), llvm::APFloat::add(), llvm::lltok::APFloat, llvm::AMDGPU::HSAMD::Kernel::Key::Attrs, B, Callee, llvm::APFloatBase::cmpLessThan, llvm::APFloat::compare(), llvm::APFloat::convert(), llvm::APFloat::convertToDouble(), llvm::IRBuilder< T, Inserter >::CreateCall(), llvm::IRBuilder< T, Inserter >::CreateFCmpOGT(), llvm::IRBuilder< T, Inserter >::CreateFCmpOLT(), llvm::IRBuilder< T, Inserter >::CreateFDiv(), llvm::IRBuilder< T, Inserter >::CreateFMul(), llvm::IRBuilder< T, Inserter >::CreateSelect(), llvm::IRBuilder< T, Inserter >::CreateSExt(), llvm::IRBuilder< T, Inserter >::CreateZExt(), llvm::CallBase::doesNotAccessMemory(), llvm::dyn_cast(), llvm::emitUnaryFloatFnCall(), F(), llvm::ConstantFP::get(), llvm::CallBase::getArgOperand(), llvm::Function::getAttributes(), llvm::CallBase::getCalledFunction(), llvm::Value::getContext(), llvm::Intrinsic::getDeclaration(), llvm::Instruction::getFastMathFlags(), llvm::ConstantExpr::getFPExtend(), llvm::ConstantFP::getInfinity(), llvm::IRBuilderBase::getInt32Ty(), llvm::Function::getIntrinsicID(), llvm::Instruction::getModule(), llvm::Value::getName(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Module::getOrInsertFunction(), llvm::GlobalValue::getParent(), getPow(), llvm::APFloat::getSemantics(), llvm::Value::getType(), llvm::Instruction::hasNoInfs(), llvm::Instruction::hasNoNaNs(), llvm::Instruction::hasNoSignedZeros(), llvm::hasUnaryFloatFn(), I, llvm::APFloatBase::IEEEdouble(), llvm::Type::isDoubleTy(), llvm::APFloat::isExactlyValue(), llvm::Instruction::isFast(), llvm::Type::isFloatTy(), llvm::APFloat::isInteger(), llvm::APFloat::isNegative(), llvm::PatternMatch::m_APFloat(), llvm::PatternMatch::m_FMul(), llvm::PatternMatch::m_FPOne(), llvm::PatternMatch::m_SpecificFP(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::Mod, Name, llvm::APFloatBase::opOK, optimizeBinaryDoubleFP(), optimizeUnaryDoubleFP(), llvm::MipsISD::Ret, llvm::APFloatBase::rmNearestTiesToEven, llvm::APFloatBase::rmTowardZero, llvm::CallBase::setCallingConv(), llvm::FastMathFlags::setFast(), llvm::IRBuilderBase::setFastMathFlags(), llvm::FastMathFlags::setNoNaNs(), llvm::FastMathFlags::setNoSignedZeros(), llvm::StringRef::startswith(), and llvm::Constant::stripPointerCasts().

◆ ignoreCallingConv()

static bool ignoreCallingConv ( LibFunc  Func)
static

◆ insertSinCosCall()

static void insertSinCosCall ( IRBuilder<> &  B,
Function OrigCallee,
Value Arg,
bool  UseFloat,
Value *&  Sin,
Value *&  Cos,
Value *&  SinCos 
)
static

◆ isCallingConvCCompatible()

static bool isCallingConvCCompatible ( CallInst CI)
static

◆ isLocallyOpenedFile()

static bool isLocallyOpenedFile ( Value File,
CallInst CI,
IRBuilder<> &  B,
const TargetLibraryInfo TLI 
)
static

◆ isOnlyUsedInComparisonWithZero()

static bool isOnlyUsedInComparisonWithZero ( Value V)
static

Definition at line 163 of file SimplifyLibCalls.cpp.

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

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

References llvm::Value::users().

Referenced by canTransformToMemCmp().

◆ isReportingError()

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

Definition at line 1988 of file SimplifyLibCalls.cpp.

References assert(), B, llvm::AMDGPUISD::BFI, callHasFloatingPointArgument(), callHasFP128Argument(), llvm::castToCStr(), llvm::Instruction::clone(), llvm::IRBuilder< T, Inserter >::CreateAdd(), llvm::IRBuilder< T, Inserter >::CreateGEP(), llvm::IRBuilderBase::CreateGlobalString(), llvm::IRBuilder< T, Inserter >::CreateIntCast(), llvm::IRBuilder< T, Inserter >::CreateLoad(), llvm::IRBuilderBase::CreateMemCpy(), llvm::IRBuilder< T, Inserter >::CreateStore(), llvm::IRBuilder< T, Inserter >::CreateTrunc(), llvm::StringRef::drop_back(), llvm::dyn_cast(), llvm::emitFGetCUnlocked(), llvm::emitFGetSUnlocked(), llvm::emitFPutC(), llvm::emitFPutCUnlocked(), llvm::emitFPutS(), llvm::emitFPutSUnlocked(), llvm::emitFReadUnlocked(), llvm::emitFWrite(), llvm::emitFWriteUnlocked(), llvm::emitPutChar(), llvm::emitPutS(), llvm::emitStrLen(), llvm::StringRef::empty(), llvm::StringRef::find(), llvm::ConstantInt::get(), llvm::CallBase::getArgOperand(), llvm::Function::getAttributes(), llvm::CallBase::getCalledFunction(), llvm::getConstantStringInfo(), llvm::Value::getContext(), llvm::Instruction::getFunction(), llvm::Function::getFunctionType(), llvm::IRBuilderBase::GetInsertBlock(), llvm::IRBuilderBase::getInt32(), llvm::IRBuilderBase::getInt8(), llvm::IRBuilderBase::getInt8Ty(), llvm::Value::getName(), llvm::CallBase::getNumArgOperands(), llvm::User::getOperand(), llvm::Module::getOrInsertFunction(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), llvm::GlobalValue::getParent(), llvm::LoadInst::getPointerOperand(), llvm::GetStringLength(), llvm::Value::getType(), llvm::ConstantInt::getZExtValue(), llvm::Function::hasOptSize(), ignoreCallingConv(), llvm::IRBuilder< T, Inserter >::Insert(), isCallingConvCCompatible(), llvm::GlobalValue::isDeclaration(), llvm::Type::isIntegerTy(), isLocallyOpenedFile(), llvm::Type::isPointerTy(), llvm::CallBase::isStrictFP(), N, llvm::StringRef::npos, optimizeBinaryDoubleFP(), optimizeTrigReflections(), optimizeUnaryDoubleFP(), replaceUnaryCall(), round(), llvm::CallBase::setCalledFunction(), llvm::shouldOptimizeForSize(), Size, llvm::StringRef::size(), and llvm::Value::use_empty().

◆ isTrigLibCall()

static bool isTrigLibCall ( CallInst CI)
static

Definition at line 1745 of file SimplifyLibCalls.cpp.

References llvm::CallBase::hasFnAttr().

Referenced by insertSinCosCall().

◆ optimizeBinaryDoubleFP()

static Value* optimizeBinaryDoubleFP ( CallInst CI,
IRBuilder<> &  B,
bool  isPrecise = false 
)
static

◆ optimizeDoubleFP()

static Value* optimizeDoubleFP ( CallInst CI,
IRBuilder<> &  B,
bool  isBinary,
bool  isPrecise = false 
)
static

◆ optimizeMemCmpConstantSize()

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

◆ optimizeTrigReflections()

static Value* optimizeTrigReflections ( CallInst Call,
LibFunc  Func,
IRBuilder<> &  B 
)
static

◆ optimizeUnaryDoubleFP()

static Value* optimizeUnaryDoubleFP ( CallInst CI,
IRBuilder<> &  B,
bool  isPrecise = false 
)
static

Shrink double -> float for unary functions.

Definition at line 1137 of file SimplifyLibCalls.cpp.

References optimizeDoubleFP().

Referenced by getSqrtCall(), and isReportingError().

◆ replaceUnaryCall()

static Value* replaceUnaryCall ( CallInst CI,
IRBuilder<> &  B,
Intrinsic::ID  IID 
)
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 1058 of file SimplifyLibCalls.cpp.

References llvm::APFloat::convert(), F(), llvm::ConstantFP::get(), llvm::Value::getType(), llvm::APFloatBase::IEEEsingle(), llvm::Type::isFloatTy(), and llvm::APFloatBase::rmNearestTiesToEven.

Referenced by optimizeDoubleFP().

Variable Documentation

◆ 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"))
static