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);
99 auto *LC = dyn_cast<Constant>(
LHS);
100 auto *RC = dyn_cast<Constant>(
RHS);
111 if (
auto *PC = dyn_cast<Constant>(
Ptr)) {
113 if (
any_of(IdxList, [](
Value *V) {
return !isa<Constant>(V); }))
122 auto *
CC = dyn_cast<Constant>(
C);
123 auto *TC = dyn_cast<Constant>(True);
124 auto *FC = dyn_cast<Constant>(False);
132 if (
auto *CAgg = dyn_cast<Constant>(Agg))
139 auto *CAgg = dyn_cast<Constant>(Agg);
140 auto *CVal = dyn_cast<Constant>(Val);
147 auto *CVec = dyn_cast<Constant>(Vec);
148 auto *CIdx = dyn_cast<Constant>(
Idx);
156 auto *CVec = dyn_cast<Constant>(Vec);
157 auto *CNewElt = dyn_cast<Constant>(NewElt);
158 auto *CIdx = dyn_cast<Constant>(
Idx);
159 if (CVec && CNewElt && CIdx)
166 auto *C1 = dyn_cast<Constant>(V1);
167 auto *C2 = dyn_cast<Constant>(V2);
174 Type *DestTy)
const override {
175 if (
auto *
C = dyn_cast<Constant>(V)) {
198 Type *DestTy)
const override {
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
static bool isDesirableCastOp(unsigned Opcode)
Whether creating a constant expression for this cast is desirable.
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static Constant * getShuffleVector(Constant *V1, Constant *V2, ArrayRef< int > Mask, Type *OnlyIfReducedTy=nullptr)
static bool isSupportedGetElementPtr(const Type *SrcElemTy)
Whether creating a constant expression for this getelementptr type is supported.
static Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a binary or shift operator constant expression, folding if possible.
static bool isDesirableBinOp(unsigned Opcode)
Whether creating a constant expression for this binary operator is desirable.
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, GEPNoWrapFlags NW=GEPNoWrapFlags::none(), std::optional< ConstantRange > InRange=std::nullopt, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
ConstantFolder - Create constants with minimum, target independent, folding.
Value * FoldBinOpFMF(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, FastMathFlags FMF) const override
Value * FoldCast(Instruction::CastOps Op, Value *V, Type *DestTy) const override
Value * FoldCmp(CmpInst::Predicate P, Value *LHS, Value *RHS) const override
Value * FoldExtractElement(Value *Vec, Value *Idx) const override
Value * FoldShuffleVector(Value *V1, Value *V2, ArrayRef< int > Mask) const override
Constant * CreatePointerBitCastOrAddrSpaceCast(Constant *C, Type *DestTy) const override
Value * FoldInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > IdxList) const override
Value * FoldExactBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, bool IsExact) const override
Value * FoldNoWrapBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, bool HasNUW, bool HasNSW) const override
Value * FoldGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, GEPNoWrapFlags NW) const override
Constant * CreatePointerCast(Constant *C, Type *DestTy) const override
Value * FoldUnOpFMF(Instruction::UnaryOps Opc, Value *V, FastMathFlags FMF) const override
Value * FoldBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS) const override
Value * FoldInsertElement(Value *Vec, Value *NewElt, Value *Idx) const override
Value * FoldExtractValue(Value *Agg, ArrayRef< unsigned > IdxList) const override
Value * FoldBinaryIntrinsic(Intrinsic::ID ID, Value *LHS, Value *RHS, Type *Ty, Instruction *FMFSource) const override
Value * FoldSelect(Value *C, Value *True, Value *False) const override
This is an important base class in LLVM.
This class represents an Operation in the Expression.
Convenience struct for specifying and reasoning about fast-math flags.
Represents flags for the getelementptr instruction/expression.
IRBuilderFolder - Interface for constant folding in IRBuilder.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
Constant * ConstantFoldSelectInstruction(Constant *Cond, Constant *V1, Constant *V2)
Attempt to constant fold a select instruction with the specified operands.
Constant * ConstantFoldCompareInstruction(CmpInst::Predicate Predicate, Constant *C1, Constant *C2)
Constant * ConstantFoldUnaryInstruction(unsigned Opcode, Constant *V)
Constant * ConstantFoldExtractValueInstruction(Constant *Agg, ArrayRef< unsigned > Idxs)
Attempt to constant fold an extractvalue instruction with the specified operands and indices.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Constant * ConstantFoldCastInstruction(unsigned opcode, Constant *V, Type *DestTy)
Constant * ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs)
ConstantFoldInsertValueInstruction - Attempt to constant fold an insertvalue instruction with the spe...
Constant * ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1, Constant *V2)