LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

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 <cmath>

Include dependency graph for ConstantFolding.cpp:

Go to the source code of this file.

Classes

class  TemplateRules< ArgType, SubClassName >
struct  EmptyRules
struct  BoolRules
struct  NullPointerRules
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 unsigned getSize (const Type *Ty)
Constantllvm::ConstantFoldCastInstruction (const Constant *V, const Type *DestTy)
Constantllvm::ConstantFoldSelectInstruction (const Constant *Cond, const Constant *V1, const Constant *V2)
static int IdxCompare (Constant *C1, Constant *C2)
static Instruction::BinaryOps evaluateRelation (const Constant *V1, const 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 375 of file 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 375 of file ConstantFolding.cpp.


Function Documentation

static Instruction::BinaryOps evaluateRelation const Constant V1,
const 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 669 of file ConstantFolding.cpp.

References llvm::User::getNumOperands(), llvm::ConstantExpr::getOpcode(), llvm::ConstantExpr::getOperand(), llvm::Value::getType(), IdxCompare(), llvm::Type::isLosslesslyConvertibleTo(), llvm::Constant::isNullValue(), llvm::ISD::SetEQ, llvm::ISD::SetGT, llvm::ISD::SetLT, and llvm::ISD::SetNE.

Referenced by llvm::ConstantFoldBinaryInstruction().

static unsigned getSize const Type Ty  )  [static]
 

Definition at line 519 of file ConstantFolding.cpp.

References llvm::Type::getPrimitiveSize().

Referenced by llvm::ConstantFoldCastInstruction().

static int IdxCompare Constant C1,
Constant C2
[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 635 of file ConstantFolding.cpp.

Referenced by evaluateRelation().