LLVM API Documentation
#include "ConstantFold.h"#include "llvm/Constants.h"#include "llvm/Instructions.h"#include "llvm/DerivedTypes.h"#include "llvm/Function.h"#include "llvm/GlobalAlias.h"#include "llvm/ADT/SmallVector.h"#include "llvm/Support/Compiler.h"#include "llvm/Support/GetElementPtrTypeIterator.h"#include "llvm/Support/ManagedStatic.h"#include "llvm/Support/MathExtras.h"#include <limits>

Go to the source code of this file.
| static Constant* BitCastConstantVector | ( | ConstantVector * | CV, | |
| const VectorType * | DstTy | |||
| ) | [static] |
BitCastConstantVector - Convert the specified ConstantVector node to the specified vector type. At this point, we know that the elements of the input vector constant are all simple integer or FP values.
Definition at line 42 of file ConstantFold.cpp.
References llvm::SequentialType::getElementType(), llvm::VectorType::getNumElements(), llvm::User::getNumOperands(), and llvm::Constant::getOperand().
Referenced by FoldBitCast().
| static FCmpInst::Predicate evaluateFCmpRelation | ( | const Constant * | V1, | |
| const Constant * | V2 | |||
| ) | [static] |
evaluateFCmpRelation - This function determines if there is anything we can decide about the two constants provided. This doesn't need to handle simple things like ConstantFP comparisons, but should instead handle ConstantExprs. If we can determine that the two constants have a particular relation to each other, we should return the corresponding FCmpInst predicate, otherwise return FCmpInst::BAD_FCMP_PREDICATE. This is used below in ConstantFoldCompareInstruction.
To simplify this code we canonicalize the relation so that the first operand is always the most "complex" of the two. We consider ConstantFP to be the simplest, and ConstantExprs to be the most complex.
Definition at line 957 of file ConstantFold.cpp.
References llvm::CmpInst::BAD_FCMP_PREDICATE, C2, llvm::dyn_cast(), llvm::CmpInst::FCMP_OEQ, llvm::CmpInst::FCMP_OGT, llvm::CmpInst::FCMP_OLT, FPTrunc, llvm::ConstantExpr::getFCmp(), llvm::ConstantExpr::getOpcode(), llvm::CmpInst::getSwappedPredicate(), llvm::Value::getType(), llvm::ConstantInt::isZero(), llvm::Type::PPC_FP128Ty, R, and UIToFP.
Referenced by llvm::ConstantFoldCompareInstruction().
| static ICmpInst::Predicate evaluateICmpRelation | ( | const Constant * | V1, | |
| const Constant * | V2, | |||
| bool | isSigned | |||
| ) | [static] |
evaluateICmpRelation - 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 GlobalValues. If we can determine that the two constants have a particular relation to each other, we should return the corresponding ICmp predicate, otherwise return ICmpInst::BAD_ICMP_PREDICATE.
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 1028 of file ConstantFold.cpp.
References llvm::CmpInst::BAD_ICMP_PREDICATE, BitCast, C2, llvm::dyn_cast(), FPToUI, FPTrunc, llvm::gep_type_begin(), llvm::ConstantExpr::getICmp(), llvm::generic_gep_type_iterator< ItTy >::getIndexedType(), llvm::Constant::getNullValue(), llvm::User::getNumOperands(), llvm::ConstantExpr::getOpcode(), llvm::Constant::getOperand(), llvm::CmpInst::getSwappedPredicate(), llvm::Value::getType(), GV, llvm::GlobalValue::hasExternalWeakLinkage(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::ICMP_ULT, IdxCompare(), llvm::Type::isInteger(), llvm::Constant::isNullValue(), llvm::ConstantInt::isZero(), pred, R, llvm::Attribute::SExt, UIToFP, and ZExt.
Referenced by llvm::ConstantFoldCompareInstruction().
| static Constant* EvalVectorOp | ( | const ConstantVector * | V1, | |
| const ConstantVector * | V2, | |||
| const VectorType * | VTy, | |||
| Constant *(*)(Constant *, Constant *) | FP | |||
| ) | [static] |
EvalVectorOp - Given two vector constants and a function pointer, apply the function pointer to each element pair, producing a new ConstantVector constant. Either or both of V1 and V2 may be NULL, meaning a ConstantAggregateZero operand.
Definition at line 572 of file ConstantFold.cpp.
References C2, llvm::ConstantVector::get(), llvm::SequentialType::getElementType(), llvm::Constant::getNullValue(), llvm::VectorType::getNumElements(), and llvm::Constant::getOperand().
Referenced by llvm::ConstantFoldBinaryInstruction().
Definition at line 91 of file ConstantFold.cpp.
References llvm::lltok::APFloat, BitCastConstantVector(), CI, llvm::Value::getType(), llvm::Type::isFloatingPoint(), llvm::Type::isInteger(), llvm::SmallVectorImpl< T >::push_back(), and llvm::SmallVectorImpl< T >::size().
| static unsigned foldConstantCastPair | ( | unsigned | opc, | |
| const ConstantExpr * | Op, | |||
| const Type * | DstTy | |||
| ) | [static] |
Determine if it is valid to fold a cast of a cast.
This function determines which opcode to use to fold two constant cast expressions together. It uses CastInst::isEliminableCastPair to determine the opcode. Consequently its just a wrapper around that function.
| opc | opcode of the second cast constant expression |
| Op | the first cast constant expression |
| DstTy | desintation type of the first cast |
Definition at line 71 of file ConstantFold.cpp.
References llvm::ConstantExpr::getOpcode(), llvm::Constant::getOperand(), llvm::Value::getType(), llvm::ConstantExpr::isCast(), isEliminableCastPair(), and llvm::Type::isFirstClassType().
Referenced by llvm::ConstantFoldCastInstruction().
GetVectorElement - If C is a ConstantVector, ConstantAggregateZero or Undef return the specified element value. Otherwise return null.
Definition at line 410 of file ConstantFold.cpp.
References llvm::UndefValue::get(), llvm::Constant::getNullValue(), llvm::Constant::getOperand(), and llvm::Value::getType().
Referenced by llvm::ConstantFoldShuffleVectorInstruction().
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 914 of file ConstantFold.cpp.
References llvm::ConstantExpr::getSExt(), llvm::Value::getType(), llvm::Type::Int64Ty, and isMaybeZeroSizedType().
Referenced by evaluateICmpRelation().
| 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 892 of file ConstantFold.cpp.
Referenced by IdxCompare().
This web site is hosted by the Computer Science Department at the University of Illinois at Urbana-Champaign.