Go to the documentation of this file.
16 #ifndef LLVM_IR_CONSTANTFOLDER_H
17 #define LLVM_IR_CONSTANTFOLDER_H
31 virtual void anchor();
45 auto *LC = dyn_cast<Constant>(
LHS);
46 auto *RC = dyn_cast<Constant>(
RHS);
56 bool IsExact)
const override {
57 auto *LC = dyn_cast<Constant>(
LHS);
58 auto *RC = dyn_cast<Constant>(
RHS);
69 bool HasNUW,
bool HasNSW)
const override {
70 auto *LC = dyn_cast<Constant>(
LHS);
71 auto *RC = dyn_cast<Constant>(
RHS);
92 auto *LC = dyn_cast<Constant>(
LHS);
93 auto *RC = dyn_cast<Constant>(
RHS);
100 bool IsInBounds =
false)
const override {
101 if (
auto *PC = dyn_cast<Constant>(Ptr)) {
103 if (
any_of(IdxList, [](
Value *V) {
return !isa<Constant>(V); }))
115 auto *CC = dyn_cast<Constant>(
C);
116 auto *TC = dyn_cast<Constant>(True);
117 auto *
FC = dyn_cast<Constant>(False);
125 if (
auto *CAgg = dyn_cast<Constant>(Agg))
132 auto *CAgg = dyn_cast<Constant>(Agg);
133 auto *CVal = dyn_cast<Constant>(Val);
140 auto *CVec = dyn_cast<Constant>(Vec);
141 auto *CIdx = dyn_cast<Constant>(Idx);
148 Value *Idx)
const override {
149 auto *CVec = dyn_cast<Constant>(Vec);
150 auto *CNewElt = dyn_cast<Constant>(NewElt);
151 auto *CIdx = dyn_cast<Constant>(Idx);
152 if (CVec && CNewElt && CIdx)
159 auto *
C1 = dyn_cast<Constant>(V1);
160 auto *C2 = dyn_cast<Constant>(
V2);
183 Type *DestTy)
const override {
192 Type *DestTy)
const override {
197 bool isSigned)
const override {
206 return CreateCast(Instruction::BitCast,
C, DestTy);
210 return CreateCast(Instruction::IntToPtr,
C, DestTy);
214 return CreateCast(Instruction::PtrToInt,
C, DestTy);
241 #endif // LLVM_IR_CONSTANTFOLDER_H
This is an optimization pass for GlobalISel generic memory operations.
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
Constant * CreateSExtOrBitCast(Constant *C, Type *DestTy) const override
static Constant * getZExtOrBitCast(Constant *C, Type *Ty)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
static Constant * getFPCast(Constant *C, Type *Ty)
Create a FPExt, Bitcast or FPTrunc for fp -> fp casts.
instcombine should handle this C2 when C1
IRBuilderFolder - Interface for constant folding in IRBuilder.
Value * FoldExtractElement(Value *Vec, Value *Idx) const override
static Constant * getSelect(Constant *C, Constant *V1, Constant *V2, Type *OnlyIfReducedTy=nullptr)
Select constant expr.
Value * FoldExactBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, bool IsExact) const override
The instances of the Type class are immutable: once they are created, they are never changed.
Constant * CreateFNeg(Constant *C) const override
static Constant * getInBoundsGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList)
Create an "inbounds" getelementptr.
Value * FoldICmp(CmpInst::Predicate P, Value *LHS, Value *RHS) const override
Constant * CreatePointerBitCastOrAddrSpaceCast(Constant *C, Type *DestTy) const override
Convenience struct for specifying and reasoning about fast-math flags.
Constant * ConstantFoldExtractValueInstruction(Constant *Agg, ArrayRef< unsigned > Idxs)
Attempt to constant fold an extractvalue instruction with the specified operands and indices.
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
Value * FoldSelect(Value *C, Value *True, Value *False) const override
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
ConstantFolder - Create constants with minimum, target independent, folding.
Constant * CreateZExtOrBitCast(Constant *C, Type *DestTy) const override
Value * FoldBinOpFMF(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, FastMathFlags FMF) const override
(vector float) vec_cmpeq(*A, *B) C
Constant * CreateUnOp(Instruction::UnaryOps Opc, Constant *C) const override
static Constant * getFNeg(Constant *C)
Constant * ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1, Constant *V2)
static Constant * getShuffleVector(Constant *V1, Constant *V2, ArrayRef< int > Mask, Type *OnlyIfReducedTy=nullptr)
Constant * CreatePtrToInt(Constant *C, Type *DestTy) const override
static Constant * getCompare(unsigned short pred, Constant *C1, Constant *C2, bool OnlyIfReduced=false)
Return an ICmp or FCmp comparison operator constant expression.
Value * FoldGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, bool IsInBounds=false) const override
Value * FoldShuffleVector(Value *V1, Value *V2, ArrayRef< int > Mask) const override
This is an important base class in LLVM.
Constant * ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs)
ConstantFoldInsertValueInstruction - Attempt to constant fold an insertvalue instruction with the spe...
static Constant * get(unsigned Opcode, Constant *C1, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a unary operator constant expression, folding if possible.
Constant * CreatePointerCast(Constant *C, Type *DestTy) const override
Value * FoldNoWrapBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, bool HasNUW, bool HasNSW) const override
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
static Constant * getTruncOrBitCast(Constant *C, Type *Ty)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
static Constant * getSExtOrBitCast(Constant *C, Type *Ty)
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
Constant * CreateFCmp(CmpInst::Predicate P, Constant *LHS, Constant *RHS) const override
Value * FoldInsertElement(Value *Vec, Value *NewElt, Value *Idx) const override
Constant * CreateIntToPtr(Constant *C, Type *DestTy) const override
static Constant * getIntegerCast(Constant *C, Type *Ty, bool IsSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
Constant * CreateFPCast(Constant *C, Type *DestTy) const override
Value * FoldExtractValue(Value *Agg, ArrayRef< unsigned > IdxList) const override
Constant * CreateBitCast(Constant *C, Type *DestTy) const override
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false, Optional< unsigned > InRangeIndex=None, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
Constant * CreateTruncOrBitCast(Constant *C, Type *DestTy) const override
static bool isDesirableBinOp(unsigned Opcode)
Whether creating a constant expression for this binary operator is desirable.
Value * FoldBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS) const override
Constant * CreateIntCast(Constant *C, Type *DestTy, bool isSigned) const override
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
Value * FoldInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > IdxList) const override
LLVM Value Representation.
Constant * CreateCast(Instruction::CastOps Op, Constant *C, Type *DestTy) const override