16#ifndef LLVM_IR_CONSTANTFOLDER_H
17#define LLVM_IR_CONSTANTFOLDER_H
46 auto *LC = dyn_cast<Constant>(
LHS);
47 auto *RC = dyn_cast<Constant>(
RHS);
49 if (ConstantExpr::isDesirableBinOp(
Opc))
50 return ConstantExpr::get(
Opc, LC, RC);
57 bool IsExact)
const override {
58 auto *LC = dyn_cast<Constant>(
LHS);
59 auto *RC = dyn_cast<Constant>(
RHS);
61 if (ConstantExpr::isDesirableBinOp(
Opc))
62 return ConstantExpr::get(
Opc, LC, RC,
63 IsExact ? PossiblyExactOperator::IsExact : 0);
70 bool HasNUW,
bool HasNSW)
const override {
71 auto *LC = dyn_cast<Constant>(
LHS);
72 auto *RC = dyn_cast<Constant>(
RHS);
74 if (ConstantExpr::isDesirableBinOp(
Opc)) {
77 Flags |= OverflowingBinaryOperator::NoUnsignedWrap;
79 Flags |= OverflowingBinaryOperator::NoSignedWrap;
80 return ConstantExpr::get(
Opc, LC, RC, Flags);
100 auto *LC = dyn_cast<Constant>(
LHS);
101 auto *RC = dyn_cast<Constant>(
RHS);
109 if (!ConstantExpr::isSupportedGetElementPtr(Ty))
112 if (
auto *PC = dyn_cast<Constant>(
Ptr)) {
114 if (
any_of(IdxList, [](
Value *V) {
return !isa<Constant>(V); }))
117 return ConstantExpr::getGetElementPtr(Ty, PC, IdxList, NW);
123 auto *CC = dyn_cast<Constant>(
C);
124 auto *TC = dyn_cast<Constant>(True);
125 auto *FC = dyn_cast<Constant>(False);
133 if (
auto *CAgg = dyn_cast<Constant>(Agg))
140 auto *CAgg = dyn_cast<Constant>(Agg);
141 auto *CVal = dyn_cast<Constant>(Val);
148 auto *CVec = dyn_cast<Constant>(Vec);
149 auto *CIdx = dyn_cast<Constant>(
Idx);
151 return ConstantExpr::getExtractElement(CVec, CIdx);
157 auto *CVec = dyn_cast<Constant>(Vec);
158 auto *CNewElt = dyn_cast<Constant>(NewElt);
159 auto *CIdx = dyn_cast<Constant>(
Idx);
160 if (CVec && CNewElt && CIdx)
161 return ConstantExpr::getInsertElement(CVec, CNewElt, CIdx);
167 auto *C1 = dyn_cast<Constant>(V1);
168 auto *C2 = dyn_cast<Constant>(V2);
170 return ConstantExpr::getShuffleVector(C1, C2, Mask);
175 Type *DestTy)
const override {
176 if (
auto *
C = dyn_cast<Constant>(V)) {
177 if (ConstantExpr::isDesirableCastOp(
Op))
178 return ConstantExpr::getCast(
Op,
C, DestTy);
195 return ConstantExpr::getPointerCast(
C, DestTy);
199 Type *DestTy)
const override {
200 return ConstantExpr::getPointerBitCastOrAddrSpaceCast(
C, DestTy);
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION()
\macro LLVM_VIRTUAL_ANCHOR_FUNCTION This macro is used to adhere to LLVM's policy that each class wit...
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.
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.
This provides a helper for copying FMF from an instruction or setting specified flags.
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.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI Constant * ConstantFoldSelectInstruction(Constant *Cond, Constant *V1, Constant *V2)
Attempt to constant fold a select instruction with the specified operands.
LLVM_ABI Constant * ConstantFoldCompareInstruction(CmpInst::Predicate Predicate, Constant *C1, Constant *C2)
LLVM_ABI Constant * ConstantFoldUnaryInstruction(unsigned Opcode, Constant *V)
LLVM_ABI 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.
LLVM_ABI Constant * ConstantFoldCastInstruction(unsigned opcode, Constant *V, Type *DestTy)
LLVM_ABI Constant * ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs)
ConstantFoldInsertValueInstruction - Attempt to constant fold an insertvalue instruction with the spe...
LLVM_ABI Constant * ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1, Constant *V2)