LLVM 17.0.0git
|
#include "llvm/IR/ConstantFold.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"
#include "llvm/IR/GlobalAlias.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/Support/ErrorHandling.h"
Go to the source code of this file.
Functions | |
static Constant * | BitCastConstantVector (Constant *CV, VectorType *DstTy) |
Convert the specified vector Constant node to the specified vector type. | |
static unsigned | foldConstantCastPair (unsigned opc, ConstantExpr *Op, Type *DstTy) |
This function determines which opcode to use to fold two constant cast expressions together. | |
static Constant * | FoldBitCast (Constant *V, Type *DestTy) |
static Constant * | ExtractConstantBytes (Constant *C, unsigned ByteStart, unsigned ByteSize) |
V is an integer constant which only has a subset of its bytes used. | |
static FCmpInst::Predicate | evaluateFCmpRelation (Constant *V1, Constant *V2) |
This function determines if there is anything we can decide about the two constants provided. | |
static ICmpInst::Predicate | areGlobalsPotentiallyEqual (const GlobalValue *GV1, const GlobalValue *GV2) |
static ICmpInst::Predicate | evaluateICmpRelation (Constant *V1, Constant *V2, bool isSigned) |
This function determines if there is anything we can decide about the two constants provided. | |
static Constant * | constantFoldCompareGlobalToNull (CmpInst::Predicate Predicate, Constant *C1, Constant *C2) |
template<typename IndexTy > | |
static bool | isInBoundsIndices (ArrayRef< IndexTy > Idxs) |
Test whether the given sequence of normalized indices is "inbounds". | |
static bool | isIndexInRangeOfArrayType (uint64_t NumElements, const ConstantInt *CI) |
Test whether a given ConstantInt is in-range for a SequentialType. | |
static Constant * | foldGEPOfGEP (GEPOperator *GEP, Type *PointeeTy, bool InBounds, ArrayRef< Value * > Idxs) |
|
static |
Definition at line 1358 of file ConstantFold.cpp.
References llvm::Type::isEmptyTy(), and llvm::Type::isSized().
Referenced by evaluateICmpRelation().
|
static |
Convert the specified vector Constant 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 43 of file ConstantFold.cpp.
References llvm::CallingConv::C, llvm::ConstantVector::get(), llvm::IntegerType::get(), llvm::ConstantInt::get(), llvm::Constant::getAllOnesValue(), llvm::ConstantExpr::getBitCast(), llvm::Value::getContext(), llvm::ConstantExpr::getExtractElement(), llvm::Constant::getNullValue(), llvm::ConstantVector::getSplat(), llvm::Constant::getSplatValue(), llvm::Value::getType(), llvm::Constant::isAllOnesValue(), and llvm::Constant::isNullValue().
Referenced by FoldBitCast().
|
static |
Definition at line 1567 of file ConstantFold.cpp.
References llvm::PointerType::getAddressSpace(), llvm::Value::getContext(), llvm::ConstantInt::getFalse(), llvm::ConstantInt::getTrue(), llvm::GlobalValue::getType(), llvm::GlobalValue::hasExternalWeakLinkage(), llvm::Constant::isNullValue(), and llvm::NullPointerIsDefined().
Referenced by llvm::ConstantFoldCompareInstruction().
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 1305 of file ConstantFold.cpp.
References assert(), evaluateFCmpRelation(), llvm::ConstantExpr::getFCmp(), llvm::ConstantExpr::getOpcode(), and llvm::Value::getType().
Referenced by llvm::ConstantFoldCompareInstruction(), and evaluateFCmpRelation().
|
static |
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 1394 of file ConstantFold.cpp.
References areGlobalsPotentiallyEqual(), assert(), evaluateICmpRelation(), llvm::ConstantExpr::getICmp(), llvm::Constant::getNullValue(), llvm::ConstantExpr::getOpcode(), llvm::User::getOperand(), llvm::Value::getType(), llvm::GEPOperator::hasAllZeroIndices(), llvm::Type::isFPOrFPVectorTy(), llvm::GEPOperator::isInBounds(), llvm::Type::isIntOrPtrTy(), isSigned(), llvm::NullPointerIsDefined(), and pred.
Referenced by llvm::ConstantFoldCompareInstruction(), and evaluateICmpRelation().
|
static |
V is an integer constant which only has a subset of its bytes used.
The bytes used are indicated by ByteStart (which is the first byte used, counting from the least significant byte) and ByteSize, which is the number of bytes used.
This function analyzes the specified constant to see if the specified byte range can be returned as a simplified constant. If so, the constant is returned, otherwise null is returned.
Definition at line 213 of file ConstantFold.cpp.
References assert(), llvm::CallingConv::C, ExtractConstantBytes(), llvm::IntegerType::get(), llvm::ConstantInt::get(), llvm::ConstantExpr::getAnd(), llvm::ConstantExpr::getLShr(), llvm::Constant::getNullValue(), llvm::ConstantExpr::getOr(), llvm::ConstantExpr::getTrunc(), llvm::Value::getType(), llvm::ConstantInt::getValue(), llvm::APInt::getZExtValue(), LHS, llvm::APInt::lshrInPlace(), RHS, llvm::APInt::uge(), and llvm::APInt::ule().
Referenced by llvm::ConstantFoldCastInstruction(), and ExtractConstantBytes().
Definition at line 109 of file ConstantFold.cpp.
References assert(), BitCastConstantVector(), FP, llvm::ConstantVector::get(), llvm::ConstantPointerNull::get(), llvm::ConstantFP::get(), llvm::ConstantInt::get(), llvm::ConstantExpr::getBitCast(), llvm::Type::getContext(), llvm::Type::getFltSemantics(), llvm::ConstantExpr::getInBoundsGetElementPtr(), llvm::Type::getInt32Ty(), llvm::Type::getNonOpaquePointerElementType(), llvm::Constant::getNullValue(), llvm::Type::getPrimitiveSizeInBits(), llvm::GetElementPtrInst::getTypeAtIndex(), llvm::Type::isFloatingPointTy(), llvm::Type::isIntegerTy(), llvm::Type::isPPC_FP128Ty(), and llvm::SmallVectorTemplateBase< T, bool >::push_back().
Referenced by llvm::ConstantFoldCastInstruction(), and llvm::ConstantFoldCastOperand().
|
static |
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. Determine if it is valid to fold a cast of a cast
opc | opcode of the second cast constant expression |
Op | the first cast constant expression |
DstTy | destination type of the first cast |
Definition at line 84 of file ConstantFold.cpp.
References assert(), llvm::Type::getContext(), llvm::Type::getInt64Ty(), llvm::CastInst::isEliminableCastPair(), and llvm::Type::isFirstClassType().
Referenced by llvm::ConstantFoldCastInstruction().
|
static |
Definition at line 1949 of file ConstantFold.cpp.
References llvm::SmallVectorImpl< T >::append(), llvm::ArrayRef< T >::begin(), E, llvm::ArrayRef< T >::end(), GEP, llvm::gep_type_begin(), llvm::gep_type_end(), llvm::ConstantExpr::get(), llvm::Type::getContext(), llvm::ConstantExpr::getGetElementPtr(), llvm::Type::getIntegerBitWidth(), llvm::Type::getIntNTy(), llvm::ConstantExpr::getSExtOrBitCast(), llvm::Value::getType(), I, llvm::Constant::isNullValue(), llvm::generic_gep_type_iterator< ItTy >::isSequential(), llvm::Type::isVectorTy(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorImpl< T >::reserve(), and llvm::ArrayRef< T >::size().
Referenced by llvm::ConstantFoldGetElementPtr().
Test whether the given sequence of normalized indices is "inbounds".
Definition at line 1904 of file ConstantFold.cpp.
References llvm::ArrayRef< T >::empty(), and llvm::ArrayRef< T >::size().
Referenced by llvm::ConstantFoldGetElementPtr().
|
static |
Test whether a given ConstantInt is in-range for a SequentialType.
Definition at line 1930 of file ConstantFold.cpp.
References llvm::ConstantInt::getSExtValue(), llvm::APInt::getSignificantBits(), and llvm::ConstantInt::getValue().
Referenced by llvm::ConstantFoldGetElementPtr().