File indexing completed on 2026-05-10 08:43:13
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef LLVM_ANALYSIS_INSTSIMPLIFYFOLDER_H
0020 #define LLVM_ANALYSIS_INSTSIMPLIFYFOLDER_H
0021
0022 #include "llvm/ADT/ArrayRef.h"
0023 #include "llvm/Analysis/InstructionSimplify.h"
0024 #include "llvm/Analysis/TargetFolder.h"
0025 #include "llvm/IR/CmpPredicate.h"
0026 #include "llvm/IR/IRBuilderFolder.h"
0027 #include "llvm/IR/Instruction.h"
0028
0029 namespace llvm {
0030 class Constant;
0031
0032
0033
0034
0035 class InstSimplifyFolder final : public IRBuilderFolder {
0036 TargetFolder ConstFolder;
0037 SimplifyQuery SQ;
0038
0039 virtual void anchor();
0040
0041 public:
0042 explicit InstSimplifyFolder(const DataLayout &DL) : ConstFolder(DL), SQ(DL) {}
0043
0044
0045
0046
0047
0048
0049
0050
0051 Value *FoldBinOp(Instruction::BinaryOps Opc, Value *LHS,
0052 Value *RHS) const override {
0053 return simplifyBinOp(Opc, LHS, RHS, SQ);
0054 }
0055
0056 Value *FoldExactBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS,
0057 bool IsExact) const override {
0058 return simplifyBinOp(Opc, LHS, RHS, SQ);
0059 }
0060
0061 Value *FoldNoWrapBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS,
0062 bool HasNUW, bool HasNSW) const override {
0063 return simplifyBinOp(Opc, LHS, RHS, SQ);
0064 }
0065
0066 Value *FoldBinOpFMF(Instruction::BinaryOps Opc, Value *LHS, Value *RHS,
0067 FastMathFlags FMF) const override {
0068 return simplifyBinOp(Opc, LHS, RHS, FMF, SQ);
0069 }
0070
0071 Value *FoldUnOpFMF(Instruction::UnaryOps Opc, Value *V,
0072 FastMathFlags FMF) const override {
0073 return simplifyUnOp(Opc, V, FMF, SQ);
0074 }
0075
0076 Value *FoldCmp(CmpInst::Predicate P, Value *LHS, Value *RHS) const override {
0077 return simplifyCmpInst(P, LHS, RHS, SQ);
0078 }
0079
0080 Value *FoldGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
0081 GEPNoWrapFlags NW) const override {
0082 return simplifyGEPInst(Ty, Ptr, IdxList, NW, SQ);
0083 }
0084
0085 Value *FoldSelect(Value *C, Value *True, Value *False) const override {
0086 return simplifySelectInst(C, True, False, SQ);
0087 }
0088
0089 Value *FoldExtractValue(Value *Agg,
0090 ArrayRef<unsigned> IdxList) const override {
0091 return simplifyExtractValueInst(Agg, IdxList, SQ);
0092 };
0093
0094 Value *FoldInsertValue(Value *Agg, Value *Val,
0095 ArrayRef<unsigned> IdxList) const override {
0096 return simplifyInsertValueInst(Agg, Val, IdxList, SQ);
0097 }
0098
0099 Value *FoldExtractElement(Value *Vec, Value *Idx) const override {
0100 return simplifyExtractElementInst(Vec, Idx, SQ);
0101 }
0102
0103 Value *FoldInsertElement(Value *Vec, Value *NewElt,
0104 Value *Idx) const override {
0105 return simplifyInsertElementInst(Vec, NewElt, Idx, SQ);
0106 }
0107
0108 Value *FoldShuffleVector(Value *V1, Value *V2,
0109 ArrayRef<int> Mask) const override {
0110 Type *RetTy = VectorType::get(
0111 cast<VectorType>(V1->getType())->getElementType(), Mask.size(),
0112 isa<ScalableVectorType>(V1->getType()));
0113 return simplifyShuffleVectorInst(V1, V2, Mask, RetTy, SQ);
0114 }
0115
0116 Value *FoldCast(Instruction::CastOps Op, Value *V,
0117 Type *DestTy) const override {
0118 return simplifyCastInst(Op, V, DestTy, SQ);
0119 }
0120
0121 Value *FoldBinaryIntrinsic(Intrinsic::ID ID, Value *LHS, Value *RHS, Type *Ty,
0122 Instruction *FMFSource) const override {
0123 return simplifyBinaryIntrinsic(ID, Ty, LHS, RHS, SQ,
0124 dyn_cast_if_present<CallBase>(FMFSource));
0125 }
0126
0127
0128
0129
0130
0131 Value *CreatePointerCast(Constant *C, Type *DestTy) const override {
0132 if (C->getType() == DestTy)
0133 return C;
0134 return ConstFolder.CreatePointerCast(C, DestTy);
0135 }
0136
0137 Value *CreatePointerBitCastOrAddrSpaceCast(Constant *C,
0138 Type *DestTy) const override {
0139 if (C->getType() == DestTy)
0140 return C;
0141 return ConstFolder.CreatePointerBitCastOrAddrSpaceCast(C, DestTy);
0142 }
0143 };
0144
0145 }
0146
0147 #endif