LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
ConstantFolding.cpp File Reference
#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>
Include dependency graph for ConstantFolding.cpp:

Go to the source code of this file.

Functions

static ConstantFoldBitCast (Constant *C, Type *DestTy, const DataLayout &TD)
 
static bool IsConstantOffsetFromGlobal (Constant *C, GlobalValue *&GV, APInt &Offset, const DataLayout &TD)
 
static bool ReadDataFromGlobal (Constant *C, uint64_t ByteOffset, unsigned char *CurPtr, unsigned BytesLeft, const DataLayout &TD)
 
static ConstantFoldReinterpretLoadFromConstPtr (Constant *C, const DataLayout &TD)
 
static ConstantConstantFoldLoadInst (const LoadInst *LI, const DataLayout *TD)
 
static ConstantSymbolicallyEvaluateBinop (unsigned Opc, Constant *Op0, Constant *Op1, const DataLayout *DL)
 
static ConstantCastGEPIndices (ArrayRef< Constant * > Ops, Type *ResultTy, const DataLayout *TD, const TargetLibraryInfo *TLI)
 
static ConstantStripPtrCastKeepAS (Constant *Ptr)
 Strip the pointer casts, but preserve the address space information. More...
 
static ConstantSymbolicallyEvaluateGEP (ArrayRef< Constant * > Ops, Type *ResultTy, const DataLayout *TD, const TargetLibraryInfo *TLI)
 
static ConstantConstantFoldConstantExpressionImpl (const ConstantExpr *CE, const DataLayout *TD, const TargetLibraryInfo *TLI, SmallPtrSet< ConstantExpr *, 4 > &FoldedOps)
 
static ConstantConstantFoldFP (double(*NativeFP)(double), double V, Type *Ty)
 
static ConstantConstantFoldBinaryFP (double(*NativeFP)(double, double), double V, double W, Type *Ty)
 
static ConstantConstantFoldConvertToInt (const APFloat &Val, bool roundTowardZero, Type *Ty)
 

Function Documentation

static Constant* CastGEPIndices ( ArrayRef< Constant * >  Ops,
Type ResultTy,
const DataLayout TD,
const TargetLibraryInfo TLI 
)
static
static Constant* ConstantFoldBinaryFP ( double(*)(double, double)  NativeFP,
double  V,
double  W,
Type Ty 
)
static
static Constant* ConstantFoldConstantExpressionImpl ( const ConstantExpr CE,
const DataLayout TD,
const TargetLibraryInfo TLI,
SmallPtrSet< ConstantExpr *, 4 > &  FoldedOps 
)
static
static Constant* ConstantFoldConvertToInt ( const APFloat Val,
bool  roundTowardZero,
Type Ty 
)
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().

static Constant* ConstantFoldFP ( double(*)(double)  NativeFP,
double  V,
Type Ty 
)
static
static Constant* ConstantFoldLoadInst ( const LoadInst LI,
const DataLayout TD 
)
static
static Constant* FoldBitCast ( Constant C,
Type DestTy,
const DataLayout TD 
)
static
static Constant* FoldReinterpretLoadFromConstPtr ( Constant C,
const DataLayout TD 
)
static
static bool IsConstantOffsetFromGlobal ( Constant C,
GlobalValue *&  GV,
APInt Offset,
const DataLayout TD 
)
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 bool ReadDataFromGlobal ( Constant C,
uint64_t  ByteOffset,
unsigned char *  CurPtr,
unsigned  BytesLeft,
const DataLayout TD 
)
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().

static Constant* StripPtrCastKeepAS ( Constant Ptr)
static

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 Constant* SymbolicallyEvaluateBinop ( unsigned  Opc,
Constant Op0,
Constant Op1,
const DataLayout DL 
)
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 Constant* SymbolicallyEvaluateGEP ( ArrayRef< Constant * >  Ops,
Type ResultTy,
const DataLayout TD,
const TargetLibraryInfo TLI 
)
static