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/LLVMContext.h"#include "llvm/ADT/SmallVector.h"#include "llvm/Support/Compiler.h"#include "llvm/Support/ErrorHandling.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 | ( | LLVMContext & | Context, | |
| 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 44 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 | ( | LLVMContext & | Context, | |
| 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 1085 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::Type::getPPC_FP128Ty(), llvm::CmpInst::getSwappedPredicate(), llvm::Value::getType(), llvm::ConstantInt::isZero(), R, and UIToFP.
Referenced by llvm::ConstantFoldCompareInstruction().
| static ICmpInst::Predicate evaluateICmpRelation | ( | LLVMContext & | Context, | |
| 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 1157 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* FoldBitCast | ( | LLVMContext & | Context, | |
| Constant * | V, | |||
| const Type * | DestTy | |||
| ) | [static] |
Definition at line 94 of file ConstantFold.cpp.
References llvm::lltok::APFloat, BitCastConstantVector(), 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 74 of file ConstantFold.cpp.
References llvm::Type::getContext(), llvm::ConstantExpr::getOpcode(), llvm::Constant::getOperand(), llvm::Value::getType(), llvm::ConstantExpr::isCast(), isEliminableCastPair(), and llvm::Type::isFirstClassType().
Referenced by llvm::ConstantFoldCastInstruction().
| static Constant* GetVectorElement | ( | LLVMContext & | Context, | |
| const Constant * | C, | |||
| unsigned | EltNo | |||
| ) | [static] |
GetVectorElement - If C is a ConstantVector, ConstantAggregateZero or Undef return the specified element value. Otherwise return null.
Definition at line 416 of file ConstantFold.cpp.
References llvm::UndefValue::get(), llvm::Constant::getNullValue(), llvm::Constant::getOperand(), and llvm::Value::getType().
Referenced by llvm::ConstantFoldShuffleVectorInstruction().
| static int IdxCompare | ( | LLVMContext & | Context, | |
| 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 1041 of file ConstantFold.cpp.
References llvm::Type::getInt64Ty(), llvm::ConstantExpr::getSExt(), llvm::Value::getType(), and isMaybeZeroSizedType().
Referenced by evaluateICmpRelation().
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 1019 of file ConstantFold.cpp.
Referenced by IdxCompare().