Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:07

0001 //===- IRBuilderFolder.h - Const folder interface for IRBuilder -*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file defines for constant folding interface used by IRBuilder.
0010 // It is implemented by ConstantFolder (default), TargetFolder and NoFoler.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_IR_IRBUILDERFOLDER_H
0015 #define LLVM_IR_IRBUILDERFOLDER_H
0016 
0017 #include "llvm/ADT/ArrayRef.h"
0018 #include "llvm/IR/GEPNoWrapFlags.h"
0019 #include "llvm/IR/InstrTypes.h"
0020 #include "llvm/IR/Instruction.h"
0021 
0022 namespace llvm {
0023 
0024 /// IRBuilderFolder - Interface for constant folding in IRBuilder.
0025 class IRBuilderFolder {
0026 public:
0027   virtual ~IRBuilderFolder();
0028 
0029   //===--------------------------------------------------------------------===//
0030   // Value-based folders.
0031   //
0032   // Return an existing value or a constant if the operation can be simplified.
0033   // Otherwise return nullptr.
0034   //===--------------------------------------------------------------------===//
0035 
0036   virtual Value *FoldBinOp(Instruction::BinaryOps Opc, Value *LHS,
0037                            Value *RHS) const = 0;
0038 
0039   virtual Value *FoldExactBinOp(Instruction::BinaryOps Opc, Value *LHS,
0040                                 Value *RHS, bool IsExact) const = 0;
0041 
0042   virtual Value *FoldNoWrapBinOp(Instruction::BinaryOps Opc, Value *LHS,
0043                                  Value *RHS, bool HasNUW,
0044                                  bool HasNSW) const = 0;
0045 
0046   virtual Value *FoldBinOpFMF(Instruction::BinaryOps Opc, Value *LHS,
0047                               Value *RHS, FastMathFlags FMF) const = 0;
0048 
0049   virtual Value *FoldUnOpFMF(Instruction::UnaryOps Opc, Value *V,
0050                              FastMathFlags FMF) const = 0;
0051 
0052   virtual Value *FoldCmp(CmpInst::Predicate P, Value *LHS,
0053                          Value *RHS) const = 0;
0054 
0055   virtual Value *FoldGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
0056                          GEPNoWrapFlags NW) const = 0;
0057 
0058   virtual Value *FoldSelect(Value *C, Value *True, Value *False) const = 0;
0059 
0060   virtual Value *FoldExtractValue(Value *Agg,
0061                                   ArrayRef<unsigned> IdxList) const = 0;
0062 
0063   virtual Value *FoldInsertValue(Value *Agg, Value *Val,
0064                                  ArrayRef<unsigned> IdxList) const = 0;
0065 
0066   virtual Value *FoldExtractElement(Value *Vec, Value *Idx) const = 0;
0067 
0068   virtual Value *FoldInsertElement(Value *Vec, Value *NewElt,
0069                                    Value *Idx) const = 0;
0070 
0071   virtual Value *FoldShuffleVector(Value *V1, Value *V2,
0072                                    ArrayRef<int> Mask) const = 0;
0073 
0074   virtual Value *FoldCast(Instruction::CastOps Op, Value *V,
0075                           Type *DestTy) const = 0;
0076 
0077   virtual Value *
0078   FoldBinaryIntrinsic(Intrinsic::ID ID, Value *LHS, Value *RHS, Type *Ty,
0079                       Instruction *FMFSource = nullptr) const = 0;
0080 
0081   //===--------------------------------------------------------------------===//
0082   // Cast/Conversion Operators
0083   //===--------------------------------------------------------------------===//
0084 
0085   virtual Value *CreatePointerCast(Constant *C, Type *DestTy) const = 0;
0086   virtual Value *CreatePointerBitCastOrAddrSpaceCast(Constant *C,
0087                                                      Type *DestTy) const = 0;
0088 };
0089 
0090 } // end namespace llvm
0091 
0092 #endif // LLVM_IR_IRBUILDERFOLDER_H