LLVM
8.0.1
|
#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/ConstantFolding.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.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"
Go to the source code of this file.
Variables | |
static 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")) |
Definition at line 102 of file SimplifyLibCalls.cpp.
References llvm::any_of(), and llvm::User::operands().
Referenced by isReportingError().
|
static |
Definition at line 167 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::ConstantFoldLoadFromConstPtr(), 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 >::CreateICmpNE(), llvm::IRBuilder< T, Inserter >::CreateInBoundsGEP(), llvm::IRBuilder< T, Inserter >::CreateIntCast(), llvm::IRBuilder< T, Inserter >::CreateIntToPtr(), llvm::IRBuilder< T, Inserter >::CreateIsNotNull(), llvm::IRBuilder< T, Inserter >::CreateLoad(), llvm::IRBuilderBase::CreateMemCpy(), llvm::IRBuilderBase::CreateMemMove(), 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::StringRef::data(), llvm::dyn_cast(), E, llvm::emitCalloc(), llvm::emitMalloc(), 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::IntegerType::get(), llvm::ConstantInt::get(), llvm::CallBase::getArgOperand(), llvm::ConstantExpr::getBitCast(), llvm::CallBase::getCalledFunction(), llvm::getConstantDataArrayInfo(), llvm::getConstantStringInfo(), llvm::BasicBlock::getContext(), llvm::Value::getContext(), llvm::ConstantDataSequential::getElementAsInteger(), llvm::Instruction::getFunction(), llvm::Function::getFunctionType(), llvm::IRBuilderBase::GetInsertBlock(), llvm::IRBuilderBase::getInt(), llvm::IRBuilderBase::getInt64(), llvm::IRBuilderBase::getInt8(), llvm::IRBuilderBase::getInt8Ty(), llvm::IRBuilderBase::getIntN(), llvm::DataLayout::getIntPtrType(), llvm::getKnownAlignment(), llvm::Instruction::getModule(), llvm::Constant::getNullValue(), llvm::FunctionType::getParamType(), llvm::Type::getPointerAddressSpace(), llvm::Type::getPointerTo(), llvm::CmpInst::getPredicate(), llvm::ConstantInt::getSExtValue(), llvm::GetStringLength(), llvm::Value::getType(), llvm::ConstantInt::getZExtValue(), 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(), memcmp, llvm::NextPowerOf2(), llvm::Attribute::NoCapture, llvm::StringRef::npos, llvm::ConstantDataArraySlice::Offset, llvm::Value::replaceAllUsesWith(), llvm::MipsISD::Ret, llvm::StringRef::rfind(), llvm::Attribute::SanitizeMemory, llvm::APInt::setBit(), llvm::IRBuilderBase::SetInsertPoint(), SI, llvm::StringRef::size(), llvm::StringRef::substr(), llvm::APInt::ule(), llvm::Value::user_begin(), llvm::Value::user_end(), and llvm::KnownBits::Zero.
Definition at line 108 of file SimplifyLibCalls.cpp.
Referenced by insertSinCosCall().
Definition at line 1166 of file SimplifyLibCalls.cpp.
References llvm::lltok::APFloat, assert(), llvm::AMDGPU::HSAMD::Kernel::Key::Attrs, llvm::APFloat::convert(), llvm::APFloat::convertToInteger(), llvm::IRBuilder< T, Inserter >::CreateCall(), llvm::IRBuilder< T, Inserter >::CreateFMul(), llvm::CallBase::doesNotAccessMemory(), llvm::dyn_cast(), llvm::emitUnaryFloatFnCall(), llvm::Intrinsic::exp, llvm::Intrinsic::exp2, llvm::ConstantFP::get(), llvm::CallBase::getArgOperand(), llvm::Function::getAttributes(), llvm::CallBase::getAttributes(), llvm::CallBase::getCalledFunction(), llvm::Intrinsic::getDeclaration(), llvm::Instruction::getModule(), llvm::Value::getName(), llvm::APFloat::getSemantics(), llvm::Value::getType(), llvm::Value::hasOneUse(), llvm::hasUnaryFloatFn(), llvm::Instruction::isFast(), llvm::APFloat::isInteger(), llvm::APInt::isPowerOf2(), llvm::APInt::logBase2(), llvm::PatternMatch::m_APFloat(), llvm::PatternMatch::m_SpecificFP(), llvm::PatternMatch::match(), llvm::Mod, N, llvm::Value::replaceAllUsesWith(), and llvm::APFloatBase::rmTowardZero.
Referenced by getSqrtCall().
|
static |
Definition at line 1307 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::Intrinsic::fabs, 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::Intrinsic::pow, 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::Intrinsic::sqrt, llvm::StringRef::startswith(), and llvm::Constant::stripPointerCasts().
Definition at line 53 of file SimplifyLibCalls.cpp.
Referenced by isReportingError(), llvm::FortifiedLibCallSimplifier::optimizeCall(), and llvm::LibCallSimplifier::optimizeCall().
|
static |
Definition at line 1708 of file SimplifyLibCalls.cpp.
References llvm::CallBase::addAttribute(), Arg, assert(), llvm::BasicBlock::begin(), C, Callee, llvm::Attribute::Cold, convertStrToNumber(), llvm::IRBuilder< T, Inserter >::CreateAdd(), llvm::IRBuilder< T, Inserter >::CreateAnd(), llvm::IRBuilder< T, Inserter >::CreateCall(), llvm::IRBuilder< T, Inserter >::CreateExtractElement(), llvm::IRBuilder< T, Inserter >::CreateExtractValue(), llvm::IRBuilder< T, Inserter >::CreateICmpNE(), llvm::IRBuilder< T, Inserter >::CreateICmpSLT(), llvm::IRBuilder< T, Inserter >::CreateICmpULT(), llvm::IRBuilder< T, Inserter >::CreateIntCast(), llvm::IRBuilder< T, Inserter >::CreateNSWNeg(), llvm::IRBuilder< T, Inserter >::CreateSelect(), llvm::IRBuilder< T, Inserter >::CreateSub(), llvm::IRBuilder< T, Inserter >::CreateZExt(), llvm::Intrinsic::ctlz, llvm::Intrinsic::cttz, llvm::dyn_cast(), llvm::SmallVectorBase::empty(), F(), llvm::AttributeList::FunctionIndex, llvm::ConstantInt::get(), llvm::StructType::get(), llvm::VectorType::get(), llvm::CallBase::getArgOperand(), llvm::Function::getAttributes(), llvm::CallBase::getCalledFunction(), llvm::getConstantStringInfo(), llvm::Intrinsic::getDeclaration(), llvm::Function::getEntryBlock(), llvm::IRBuilderBase::getFalse(), llvm::Instruction::getFunction(), llvm::IRBuilderBase::GetInsertBlock(), llvm::IRBuilderBase::getInt32(), llvm::IRBuilderBase::getInt32Ty(), llvm::Type::getIntegerBitWidth(), llvm::Constant::getNullValue(), llvm::Module::getOrInsertFunction(), llvm::BasicBlock::getParent(), llvm::GlobalValue::getParent(), llvm::Module::getTargetTriple(), llvm::IRBuilderBase::getTrue(), llvm::Value::getType(), llvm::CallBase::hasFnAttr(), llvm::Type::isFloatTy(), isReportingError(), llvm::Type::isStructTy(), isTrigLibCall(), Name, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::IRBuilderBase::SetInsertPoint(), T, llvm::Value::users(), X, llvm::Triple::x86, and llvm::Triple::x86_64.
Definition at line 58 of file SimplifyLibCalls.cpp.
References llvm::CallingConv::ARM_AAPCS, llvm::CallingConv::ARM_AAPCS_VFP, llvm::CallingConv::ARM_APCS, llvm::CallingConv::C, llvm::CallBase::getCallingConv(), llvm::CallBase::getFunctionType(), llvm::Instruction::getModule(), and llvm::Module::getTargetTriple().
Referenced by isReportingError(), llvm::FortifiedLibCallSimplifier::optimizeCall(), and llvm::LibCallSimplifier::optimizeCall().
|
static |
Definition at line 133 of file SimplifyLibCalls.cpp.
References llvm::dyn_cast(), llvm::ARMBuildAttrs::File, llvm::CallBase::getCalledFunction(), llvm::TargetLibraryInfo::getLibFunc(), llvm::TargetLibraryInfo::has(), llvm::inferLibFuncAttributes(), and llvm::PointerMayBeCaptured().
Referenced by isReportingError().
Definition at line 155 of file SimplifyLibCalls.cpp.
References C, and llvm::Value::users().
Referenced by canTransformToMemCmp().
Return true if it is only used in equality comparisons with With.
Definition at line 91 of file SimplifyLibCalls.cpp.
References llvm::Value::users().
Referenced by canTransformToMemCmp().
Definition at line 1943 of file SimplifyLibCalls.cpp.
References assert(), B, callHasFloatingPointArgument(), llvm::castToCStr(), llvm::Intrinsic::ceil, 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::Intrinsic::fabs, llvm::StringRef::find(), llvm::Intrinsic::floor, 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::BasicBlock::getParent(), llvm::GlobalValue::getParent(), llvm::LoadInst::getPointerOperand(), llvm::GetStringLength(), llvm::Value::getType(), llvm::ConstantInt::getZExtValue(), ignoreCallingConv(), llvm::IRBuilder< T, Inserter >::Insert(), isCallingConvCCompatible(), llvm::GlobalValue::isDeclaration(), llvm::Type::isIntegerTy(), isLocallyOpenedFile(), llvm::Type::isPointerTy(), llvm::CallBase::isStrictFP(), N, llvm::Intrinsic::nearbyint, llvm::StringRef::npos, llvm::Function::optForSize(), optimizeBinaryDoubleFP(), optimizeTrigReflections(), optimizeUnaryDoubleFP(), replaceUnaryCall(), llvm::Intrinsic::rint, llvm::Intrinsic::round, llvm::CallBase::setCalledFunction(), Size, llvm::StringRef::size(), llvm::Intrinsic::trunc, and llvm::Value::use_empty().
Referenced by insertSinCosCall().
Definition at line 1700 of file SimplifyLibCalls.cpp.
References llvm::CallBase::hasFnAttr(), llvm::Attribute::NoUnwind, and llvm::Attribute::ReadNone.
Referenced by insertSinCosCall().
|
static |
Shrink double -> float for binary functions.
Definition at line 1097 of file SimplifyLibCalls.cpp.
References assert(), llvm::IRBuilder< T, Inserter >::CreateCall(), llvm::IRBuilder< T, Inserter >::CreateExtractValue(), llvm::IRBuilder< T, Inserter >::CreateFAdd(), llvm::IRBuilder< T, Inserter >::CreateFMul(), llvm::CallBase::getArgOperand(), llvm::Intrinsic::getDeclaration(), llvm::Instruction::getFastMathFlags(), llvm::Instruction::getModule(), llvm::CallBase::getNumArgOperands(), llvm::Value::getType(), llvm::Type::isArrayTy(), llvm::Instruction::isFast(), optimizeDoubleFP(), llvm::IRBuilderBase::setFastMathFlags(), and llvm::Intrinsic::sqrt.
Referenced by getSqrtCall(), and isReportingError().
|
static |
Shrink double -> float functions.
Definition at line 1032 of file SimplifyLibCalls.cpp.
References llvm::StringRef::back(), llvm::IRBuilder< T, Inserter >::CreateCall(), llvm::IRBuilder< T, Inserter >::CreateFPExt(), llvm::dyn_cast(), llvm::emitBinaryFloatFnCall(), llvm::emitUnaryFloatFnCall(), llvm::CallBase::getArgOperand(), llvm::Function::getAttributes(), llvm::CallBase::getCalledFunction(), llvm::Intrinsic::getDeclaration(), llvm::IRBuilderBase::getDoubleTy(), llvm::Instruction::getFastMathFlags(), llvm::IRBuilderBase::getFloatTy(), llvm::Instruction::getFunction(), llvm::Function::getIntrinsicID(), llvm::Instruction::getModule(), llvm::Value::getName(), llvm::Value::getType(), llvm::Type::isDoubleTy(), llvm::Type::isFloatTy(), llvm::Function::isIntrinsic(), llvm::IRBuilderBase::setFastMathFlags(), llvm::StringRef::size(), llvm::StringRef::startswith(), llvm::Value::users(), and valueHasFloatPrecision().
Referenced by optimizeBinaryDoubleFP(), and optimizeUnaryDoubleFP().
Definition at line 1131 of file SimplifyLibCalls.cpp.
References llvm::IRBuilder< T, Inserter >::CreateCall(), llvm::IRBuilder< T, Inserter >::CreateFNeg(), llvm::CallBase::getArgOperand(), llvm::CallBase::getCalledFunction(), llvm::Instruction::getFastMathFlags(), llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::IRBuilderBase::setFastMathFlags(), and X.
Referenced by isReportingError().
|
static |
Shrink double -> float for unary functions.
Definition at line 1091 of file SimplifyLibCalls.cpp.
References optimizeDoubleFP().
Referenced by getSqrtCall(), and isReportingError().
|
static |
Definition at line 996 of file SimplifyLibCalls.cpp.
References llvm::IRBuilder< T, Inserter >::CreateCall(), F(), llvm::CallBase::getArgOperand(), llvm::Intrinsic::getDeclaration(), llvm::Instruction::getFastMathFlags(), llvm::Instruction::getModule(), llvm::Value::getType(), llvm::IRBuilderBase::setFastMathFlags(), and llvm::Value::takeName().
Referenced by isReportingError().
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 1014 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().