LLVM API Documentation
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/Operator.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FEnv.h"
#include "llvm/Support/GetElementPtrTypeIterator.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Target/TargetLibraryInfo.h"
#include <cerrno>
#include <cmath>
Go to the source code of this file.
|
static |
CastGEPIndices - If array indices are not pointer-sized integers, explicitly cast them so that they aren't implicitly casted by the getelementptr.
Definition at line 617 of file ConstantFolding.cpp.
References llvm::SystemZICMP::Any, llvm::CallingConv::C, llvm::ConstantFoldConstantExpression(), llvm::ConstantExpr::getCast(), llvm::CastInst::getCastOpcode(), llvm::ConstantExpr::getGetElementPtr(), llvm::GetElementPtrInst::getIndexedType(), llvm::DataLayout::getIntPtrType(), llvm::Intrinsic::getType(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::ArrayRef< T >::size(), and llvm::ArrayRef< T >::slice().
Referenced by llvm::ConstantFoldInstOperands().
|
static |
Definition at line 1269 of file ConstantFolding.cpp.
References llvm::lltok::APFloat, llvm::APFloat::convert(), llvm::ConstantFP::get(), llvm::Type::getContext(), llvm::APFloat::IEEEhalf, llvm::Type::isDoubleTy(), llvm::Type::isFloatTy(), llvm::Type::isHalfTy(), llvm::sys::llvm_fenv_clearexcept(), llvm::sys::llvm_fenv_testexcept(), llvm_unreachable, and llvm::APFloat::rmNearestTiesToEven.
Referenced by llvm::ConstantFoldCall().
|
static |
Definition at line 912 of file ConstantFolding.cpp.
References llvm::ConstantFoldCompareInstOperands(), llvm::ConstantFoldInstOperands(), llvm::ConstantExpr::getOpcode(), llvm::ConstantExpr::getPredicate(), llvm::Value::getType(), llvm::SmallPtrSet< PtrType, SmallSize >::insert(), llvm::ConstantExpr::isCompare(), llvm::User::op_begin(), llvm::User::op_end(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), and TD.
Referenced by llvm::ConstantFoldConstantExpression().
|
static |
ConstantFoldConvertToInt - Attempt to an SSE floating point to integer conversion of a constant floating point. If roundTowardZero is false, the default IEEE rounding is used (toward nearest, ties to even). This matches the behavior of the non-truncating SSE instructions in the default rounding mode. The desired integer type Ty is used to select how many bits are available for the result. Returns null if the conversion cannot be performed, otherwise returns the Constant value resulting from the conversion.
Definition at line 1299 of file ConstantFolding.cpp.
References llvm::APFloat::convertToInteger(), llvm::ConstantInt::get(), llvm::Type::getIntegerBitWidth(), llvm::APFloat::opInexact, llvm::APFloat::opOK, llvm::APFloat::rmNearestTiesToEven, llvm::APFloat::rmTowardZero, and llvm::sys::fs::status().
Referenced by llvm::ConstantFoldCall().
Definition at line 1247 of file ConstantFolding.cpp.
References llvm::lltok::APFloat, llvm::APFloat::convert(), llvm::ConstantFP::get(), llvm::Type::getContext(), llvm::APFloat::IEEEhalf, llvm::Type::isDoubleTy(), llvm::Type::isFloatTy(), llvm::Type::isHalfTy(), llvm::sys::llvm_fenv_clearexcept(), llvm::sys::llvm_fenv_testexcept(), llvm_unreachable, and llvm::APFloat::rmNearestTiesToEven.
Referenced by llvm::ConstantFoldCall().
|
static |
Definition at line 548 of file ConstantFolding.cpp.
References llvm::CallingConv::C, llvm::ConstantFoldLoadFromConstPtr(), llvm::User::getOperand(), and llvm::LoadInst::isVolatile().
Referenced by llvm::ConstantFoldInstruction().
|
static |
FoldBitCast - Constant fold bitcast, symbolically evaluating it with DataLayout. This always returns a non-null constant, but it may be a ConstantExpr if unfoldable.
Definition at line 48 of file ConstantFolding.cpp.
References llvm::CallingConv::C, llvm::dyn_cast(), llvm::IntegerType::get(), llvm::ConstantInt::get(), llvm::VectorType::get(), llvm::ConstantVector::get(), llvm::Constant::getAggregateElement(), llvm::Constant::getAllOnesValue(), llvm::ConstantExpr::getBitCast(), llvm::Value::getContext(), llvm::ConstantDataSequential::getElementAsInteger(), llvm::SequentialType::getElementType(), llvm::ConstantExpr::getLShr(), llvm::Constant::getNullValue(), llvm::VectorType::getNumElements(), llvm::ConstantExpr::getOr(), llvm::Type::getPrimitiveSizeInBits(), llvm::ConstantExpr::getShl(), llvm::ConstantExpr::getTrunc(), llvm::Value::getType(), llvm::DataLayout::getTypeAllocSizeInBits(), llvm::Type::getVectorElementType(), llvm::Type::getVectorNumElements(), llvm::ConstantExpr::getZExt(), llvm::Constant::isAllOnesValue(), llvm::Type::isFloatingPointTy(), llvm::DataLayout::isLittleEndian(), llvm::Constant::isNullValue(), llvm::Type::isX86_MMXTy(), IT(), and llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back().
Referenced by llvm::ConstantFoldInstOperands(), FoldReinterpretLoadFromConstPtr(), ReadDataFromGlobal(), and SymbolicallyEvaluateGEP().
|
static |
Definition at line 388 of file ConstantFolding.cpp.
References llvm::dyn_cast(), FoldBitCast(), llvm::ConstantInt::get(), llvm::UndefValue::get(), llvm::PointerType::getAddressSpace(), llvm::IntegerType::getBitWidth(), llvm::Value::getContext(), llvm::Type::getContext(), llvm::SequentialType::getElementType(), llvm::GlobalVariable::getInitializer(), llvm::Type::getInt16PtrTy(), llvm::Type::getInt32PtrTy(), llvm::Type::getInt64PtrTy(), llvm::Type::getIntNPtrTy(), llvm::Value::getType(), llvm::DataLayout::getTypeAllocSize(), llvm::DataLayout::getTypeAllocSizeInBits(), llvm::APInt::getZExtValue(), llvm::GlobalVariable::hasDefinitiveInitializer(), llvm::GlobalVariable::isConstant(), IsConstantOffsetFromGlobal(), llvm::DataLayout::isLittleEndian(), llvm::APInt::isNegative(), llvm::Type::isSized(), ReadDataFromGlobal(), and TD.
Referenced by llvm::ConstantFoldLoadFromConstPtr().
|
static |
IsConstantOffsetFromGlobal - If this constant is actually a constant offset from a global, return the global and the constant. Because of constantexprs, this function is recursive.
Definition at line 223 of file ConstantFolding.cpp.
References llvm::GEPOperator::accumulateConstantOffset(), llvm::CallingConv::C, llvm::dyn_cast(), llvm::ConstantExpr::getOpcode(), llvm::User::getOperand(), llvm::DataLayout::getPointerTypeSizeInBits(), llvm::GlobalValue::getType(), llvm::Value::getType(), and TD.
Referenced by FoldReinterpretLoadFromConstPtr(), and SymbolicallyEvaluateBinop().
|
static |
ReadDataFromGlobal - Recursive helper to read bits out of global. C is the constant being copied out of. ByteOffset is an offset into C. CurPtr is the pointer to copy results into and BytesLeft is the number of bytes left in the CurPtr buffer. TD is the target data.
Definition at line 265 of file ConstantFolding.cpp.
References FoldBitCast(), llvm::Constant::getAggregateElement(), llvm::Value::getContext(), llvm::StructLayout::getElementContainingOffset(), llvm::StructLayout::getElementOffset(), llvm::Type::getInt16Ty(), llvm::Type::getInt32Ty(), llvm::Type::getInt64Ty(), llvm::DataLayout::getIntPtrType(), llvm::Type::getSequentialElementType(), llvm::DataLayout::getStructLayout(), llvm::Value::getType(), llvm::DataLayout::getTypeAllocSize(), llvm::Type::getVectorNumElements(), llvm::DataLayout::isLittleEndian(), and TD.
Referenced by FoldReinterpretLoadFromConstPtr().
Strip the pointer casts, but preserve the address space information.
Definition at line 656 of file ConstantFolding.cpp.
References llvm::SequentialType::getElementType(), llvm::ConstantExpr::getPointerCast(), llvm::Type::getPointerTo(), llvm::Value::getType(), and llvm::Type::isPointerTy().
Referenced by SymbolicallyEvaluateGEP().
|
static |
SymbolicallyEvaluateBinop - One of Op0/Op1 is a constant expression. Attempt to symbolically evaluate the result of a binary operator merging these together. If target data info is available, it is provided as DL, otherwise DL is null.
Definition at line 561 of file ConstantFolding.cpp.
References llvm::APIntOps::And(), llvm::ComputeMaskedBits(), llvm::ConstantInt::get(), llvm::Type::getScalarType(), llvm::Value::getType(), llvm::DataLayout::getTypeSizeInBits(), IsConstantOffsetFromGlobal(), llvm::X86II::OpSize, and llvm::APInt::zextOrTrunc().
Referenced by llvm::ConstantFoldInstOperands().
|
static |
SymbolicallyEvaluateGEP - If we can symbolically evaluate the specified GEP constant expression, do so.
Definition at line 673 of file ConstantFolding.cpp.
References llvm::CallingConv::C, llvm::ConstantFoldConstantExpression(), llvm::ArrayRef< T >::data(), llvm::dyn_cast(), FoldBitCast(), llvm::ConstantInt::get(), llvm::Type::getContext(), llvm::StructLayout::getElementContainingOffset(), llvm::StructLayout::getElementOffset(), llvm::ConstantExpr::getGetElementPtr(), llvm::DataLayout::getIndexedOffset(), llvm::Type::getInt32Ty(), llvm::DataLayout::getIntPtrType(), llvm::ConstantExpr::getIntToPtr(), llvm::ConstantExpr::getOpcode(), llvm::User::getOperand(), llvm::Type::getPointerElementType(), llvm::ConstantExpr::getPtrToInt(), llvm::StructLayout::getSizeInBytes(), llvm::DataLayout::getStructLayout(), llvm::ConstantExpr::getSub(), llvm::Value::getType(), llvm::DataLayout::getTypeAllocSize(), llvm::DataLayout::getTypeSizeInBits(), llvm::APInt::getZExtValue(), llvm::Type::isIntegerTy(), llvm::Type::isPointerTy(), llvm::Type::isSized(), llvm::makeArrayRef(), llvm::ArrayRef< T >::size(), StripPtrCastKeepAS(), llvm::APInt::udiv(), llvm::APInt::uge(), and llvm::APInt::zextOrTrunc().
Referenced by llvm::ConstantFoldInstOperands().