LLVM API Documentation

ConstantFolding.cpp File Reference

#include "ConstantFolding.h"
#include "llvm/Constants.h"
#include "llvm/Instructions.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
#include "llvm/Support/GetElementPtrTypeIterator.h"
#include "llvm/Support/MathExtras.h"
#include <limits>
#include <cmath>

Include dependency graph for VMCore/ConstantFolding.cpp:

Go to the source code of this file.

Classes

class  TemplateRules< ArgType, SubClassName >
struct  EmptyRules
struct  BoolRules
struct  NullPointerRules
struct  ConstantPackedRules
struct  GeneralPackedRules
struct  DirectRules< ConstantClass, BuiltinType, Ty, SuperClass >
struct  DirectIntRules< ConstantClass, BuiltinType, Ty >
struct  DirectFPRules< ConstantClass, BuiltinType, Ty >

Defines

#define DEF_CAST(TYPE, CLASS, CTYPE)
#define DEF_CAST(TYPE, CLASS, CTYPE)

Functions

static ConstantEvalVectorOp (const ConstantPacked *V1, const ConstantPacked *V2, Constant *(*FP)(Constant *, Constant *))
static unsigned getSize (const Type *Ty)
static ConstantCastConstantPacked (ConstantPacked *CP, const PackedType *DstTy)
Constantllvm::ConstantFoldCastInstruction (const Constant *V, const Type *DestTy)
Constantllvm::ConstantFoldSelectInstruction (const Constant *Cond, const Constant *V1, const Constant *V2)
Constantllvm::ConstantFoldExtractElementInstruction (const Constant *Val, const Constant *Idx)
Constantllvm::ConstantFoldInsertElementInstruction (const Constant *Val, const Constant *Elt, const Constant *Idx)
Constantllvm::ConstantFoldShuffleVectorInstruction (const Constant *V1, const Constant *V2, const Constant *Mask)
static bool isMaybeZeroSizedType (const Type *Ty)
static int IdxCompare (Constant *C1, Constant *C2, const Type *ElTy)
static Instruction::BinaryOps evaluateRelation (Constant *V1, Constant *V2)
Constantllvm::ConstantFoldBinaryInstruction (unsigned Opcode, const Constant *V1, const Constant *V2)
Constantllvm::ConstantFoldGetElementPtr (const Constant *C, const std::vector< Value * > &IdxList)


Define Documentation

#define DEF_CAST ( TYPE,
CLASS,
CTYPE   ) 

Value:

static Constant *CastTo##TYPE  (const ConstantClass *V) {    \
    return CLASS::get(Type::TYPE##Ty, (CTYPE)(BuiltinType)V->getValue()); \
  }

Definition at line 463 of file VMCore/ConstantFolding.cpp.

#define DEF_CAST ( TYPE,
CLASS,
CTYPE   ) 

Value:

static Constant *CastTo##TYPE  (const ConstantBool *V) {    \
    return CLASS::get(Type::TYPE##Ty, (CTYPE)(bool)V->getValue()); \
  }

Definition at line 463 of file VMCore/ConstantFolding.cpp.


Function Documentation

static Constant* CastConstantPacked ( ConstantPacked CP,
const PackedType DstTy 
) [static]

CastConstantPacked - Convert the specified ConstantPacked node to the specified packed type. At this point, we know that the elements of the input packed constant are all simple integer or FP values.

Definition at line 628 of file VMCore/ConstantFolding.cpp.

References llvm::BitsToDouble(), llvm::BitsToFloat(), llvm::CallingConv::C, CP, llvm::DoubleToBits(), llvm::FloatToBits(), llvm::SequentialType::getElementType(), llvm::PackedType::getNumElements(), llvm::Constant::getOperand(), llvm::Value::getType(), llvm::Type::getTypeID(), llvm::Type::isFloatingPoint(), llvm::Type::isIntegral(), and V.

Referenced by llvm::ConstantFoldCastInstruction().

static Instruction::BinaryOps evaluateRelation ( Constant V1,
Constant V2 
) [static]

evaluateRelation - This function determines if there is anything we can decide about the two constants provided. This doesn't need to handle simple things like integer comparisons, but should instead handle ConstantExprs and GlobalValuess. If we can determine that the two constants have a particular relation to each other, we should return the corresponding SetCC code, otherwise return Instruction::BinaryOpsEnd.

To simplify this code we canonicalize the relation so that the first operand is always the most "complex" of the two. We consider simple constants (like ConstantInt) to be the simplest, followed by GlobalValues, followed by ConstantExpr's (the most complex).

Definition at line 982 of file VMCore/ConstantFolding.cpp.

References llvm::gep_type_begin(), llvm::generic_gep_type_iterator< ItTy >::getIndexedType(), llvm::User::getNumOperands(), llvm::ConstantExpr::getOpcode(), llvm::Constant::getOperand(), llvm::ConstantExpr::getOperand(), llvm::Value::getType(), IdxCompare(), llvm::Type::isIntegral(), llvm::Constant::isNullValue(), R, and True.

Referenced by llvm::ConstantFoldBinaryInstruction().

static Constant* EvalVectorOp ( const ConstantPacked V1,
const ConstantPacked V2,
Constant *(*)(Constant *, Constant *)  FP 
) [static]

DoVectorOp - Given two packed constants and a function pointer, apply the function pointer to each element pair, producing a new ConstantPacked constant.

Definition at line 339 of file VMCore/ConstantFolding.cpp.

References llvm::User::getNumOperands(), and llvm::Constant::getOperand().

Referenced by ConstantPackedRules::Add(), ConstantPackedRules::And(), ConstantPackedRules::Div(), ConstantPackedRules::Mul(), ConstantPackedRules::Or(), ConstantPackedRules::Rem(), ConstantPackedRules::Shl(), ConstantPackedRules::Shr(), ConstantPackedRules::Sub(), and ConstantPackedRules::Xor().

static unsigned getSize ( const Type Ty  )  [static]

Definition at line 620 of file VMCore/ConstantFolding.cpp.

References llvm::Type::getPrimitiveSize(), and Ty.

Referenced by llvm::ConstantFoldCastInstruction().

static int IdxCompare ( Constant C1,
Constant C2,
const Type ElTy 
) [static]

IdxCompare - Compare the two constants as though they were getelementptr indices. This allows coersion of the types to be the same thing.

If the two constants are the "same" (after coersion), return 0. If the first is less than the second, return -1, if the second is less than the first, return 1. If the constants are not integral, return -2.

Definition at line 943 of file VMCore/ConstantFolding.cpp.

References isMaybeZeroSizedType().

Referenced by evaluateRelation().

static bool isMaybeZeroSizedType ( const Type Ty  )  [static]

isZeroSizedType - This type is zero sized if its an array or structure of zero sized types. The only leaf zero sized type is an empty structure.

Definition at line 921 of file VMCore/ConstantFolding.cpp.

References Ty.

Referenced by IdxCompare().