18#ifndef LLVM_ANALYSIS_TARGETFOLDER_H
19#define LLVM_ANALYSIS_TARGETFOLDER_H
57 auto *LC = dyn_cast<Constant>(
LHS);
58 auto *RC = dyn_cast<Constant>(
RHS);
60 if (ConstantExpr::isDesirableBinOp(
Opc))
61 return Fold(ConstantExpr::get(
Opc, LC, RC));
68 bool IsExact)
const override {
69 auto *LC = dyn_cast<Constant>(
LHS);
70 auto *RC = dyn_cast<Constant>(
RHS);
72 if (ConstantExpr::isDesirableBinOp(
Opc))
73 return Fold(ConstantExpr::get(
74 Opc, LC, RC, IsExact ? PossiblyExactOperator::IsExact : 0));
81 bool HasNUW,
bool HasNSW)
const override {
82 auto *LC = dyn_cast<Constant>(
LHS);
83 auto *RC = dyn_cast<Constant>(
RHS);
85 if (ConstantExpr::isDesirableBinOp(
Opc)) {
88 Flags |= OverflowingBinaryOperator::NoUnsignedWrap;
90 Flags |= OverflowingBinaryOperator::NoSignedWrap;
91 return Fold(ConstantExpr::get(
Opc, LC, RC, Flags));
104 auto *LC = dyn_cast<Constant>(
LHS);
105 auto *RC = dyn_cast<Constant>(
RHS);
120 if (!ConstantExpr::isSupportedGetElementPtr(Ty))
123 if (
auto *PC = dyn_cast<Constant>(
Ptr)) {
125 if (
any_of(IdxList, [](
Value *V) {
return !isa<Constant>(V); }))
127 return Fold(ConstantExpr::getGetElementPtr(Ty, PC, IdxList, NW));
133 auto *CC = dyn_cast<Constant>(
C);
134 auto *TC = dyn_cast<Constant>(True);
135 auto *FC = dyn_cast<Constant>(False);
144 if (
auto *CAgg = dyn_cast<Constant>(Agg))
151 auto *CAgg = dyn_cast<Constant>(Agg);
152 auto *CVal = dyn_cast<Constant>(Val);
159 auto *CVec = dyn_cast<Constant>(Vec);
160 auto *CIdx = dyn_cast<Constant>(
Idx);
162 return Fold(ConstantExpr::getExtractElement(CVec, CIdx));
168 auto *CVec = dyn_cast<Constant>(Vec);
169 auto *CNewElt = dyn_cast<Constant>(NewElt);
170 auto *CIdx = dyn_cast<Constant>(
Idx);
171 if (CVec && CNewElt && CIdx)
172 return Fold(ConstantExpr::getInsertElement(CVec, CNewElt, CIdx));
178 auto *C1 = dyn_cast<Constant>(V1);
179 auto *C2 = dyn_cast<Constant>(V2);
181 return Fold(ConstantExpr::getShuffleVector(C1, C2, Mask));
186 Type *DestTy)
const override {
187 if (
auto *
C = dyn_cast<Constant>(V))
194 auto *C1 = dyn_cast<Constant>(
LHS);
195 auto *C2 = dyn_cast<Constant>(
RHS);
206 if (
C->getType() == DestTy)
208 return Fold(ConstantExpr::getPointerCast(
C, DestTy));
212 Type *DestTy)
const override {
213 if (
C->getType() == DestTy)
215 return Fold(ConstantExpr::getPointerBitCastOrAddrSpaceCast(
C, DestTy));
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
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.
This is an important base class in LLVM.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
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.
TargetFolder - Create constants with target dependent folding.
Constant * CreatePointerCast(Constant *C, Type *DestTy) const override
Value * FoldShuffleVector(Value *V1, Value *V2, ArrayRef< int > Mask) const override
TargetFolder(const DataLayout &DL)
Value * FoldInsertElement(Value *Vec, Value *NewElt, Value *Idx) const override
Value * FoldSelect(Value *C, Value *True, Value *False) const override
Value * FoldExtractValue(Value *Agg, ArrayRef< unsigned > IdxList) const override
Value * FoldExactBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, bool IsExact) const override
Constant * CreatePointerBitCastOrAddrSpaceCast(Constant *C, Type *DestTy) const override
Value * FoldUnOpFMF(Instruction::UnaryOps Opc, Value *V, FastMathFlags FMF) const override
Value * FoldCmp(CmpInst::Predicate P, Value *LHS, Value *RHS) const override
Value * FoldGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, GEPNoWrapFlags NW) const override
Value * FoldNoWrapBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, bool HasNUW, bool HasNSW) const override
Value * FoldBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS) const override
Value * FoldBinOpFMF(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, FastMathFlags FMF) const override
Value * FoldInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > IdxList) const override
Value * FoldExtractElement(Value *Vec, Value *Idx) const override
Value * FoldCast(Instruction::CastOps Op, Value *V, Type *DestTy) const override
Value * FoldBinaryIntrinsic(Intrinsic::ID ID, Value *LHS, Value *RHS, Type *Ty, Instruction *FMFSource) const override
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 * ConstantFoldBinaryIntrinsic(Intrinsic::ID ID, Constant *LHS, Constant *RHS, Type *Ty, Instruction *FMFSource)
LLVM_ABI Constant * ConstantFoldSelectInstruction(Constant *Cond, Constant *V1, Constant *V2)
Attempt to constant fold a select instruction with the specified operands.
LLVM_ABI Constant * ConstantFoldCompareInstOperands(unsigned Predicate, Constant *LHS, Constant *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const Instruction *I=nullptr)
Attempt to constant fold a compare instruction (icmp/fcmp) with the specified operands.
LLVM_ABI Constant * ConstantFoldExtractValueInstruction(Constant *Agg, ArrayRef< unsigned > Idxs)
Attempt to constant fold an extractvalue instruction with the specified operands and indices.
LLVM_ABI Constant * ConstantFoldConstant(const Constant *C, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldConstant - Fold the constant using the specified DataLayout.
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 * ConstantFoldUnaryOpOperand(unsigned Opcode, Constant *Op, const DataLayout &DL)
Attempt to constant fold a unary operation with the specified operand.
LLVM_ABI Constant * ConstantFoldCastOperand(unsigned Opcode, Constant *C, Type *DestTy, const DataLayout &DL)
Attempt to constant fold a cast with the specified operand.
LLVM_ABI Constant * ConstantFoldBinaryOpOperands(unsigned Opcode, Constant *LHS, Constant *RHS, const DataLayout &DL)
Attempt to constant fold a binary operation with the specified operands.
LLVM_ABI Constant * ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs)
ConstantFoldInsertValueInstruction - Attempt to constant fold an insertvalue instruction with the spe...