LLVM  12.0.0git
IRBuilderFolder.h
Go to the documentation of this file.
1 //===- IRBuilderFolder.h - Const folder interface for IRBuilder -*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines for constant folding interface used by IRBuilder.
10 // It is implemented by ConstantFolder (default), TargetFolder and NoFoler.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_IR_IRBUILDERFOLDER_H
15 #define LLVM_IR_IRBUILDERFOLDER_H
16 
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/IR/InstrTypes.h"
19 #include "llvm/IR/Instruction.h"
20 
21 namespace llvm {
22 
23 /// IRBuilderFolder - Interface for constant folding in IRBuilder.
25 public:
26  virtual ~IRBuilderFolder();
27 
28  //===--------------------------------------------------------------------===//
29  // Binary Operators
30  //===--------------------------------------------------------------------===//
31 
32  virtual Value *CreateAdd(Constant *LHS, Constant *RHS,
33  bool HasNUW = false, bool HasNSW = false) const = 0;
34  virtual Value *CreateFAdd(Constant *LHS, Constant *RHS) const = 0;
35  virtual Value *CreateSub(Constant *LHS, Constant *RHS,
36  bool HasNUW = false, bool HasNSW = false) const = 0;
37  virtual Value *CreateFSub(Constant *LHS, Constant *RHS) const = 0;
38  virtual Value *CreateMul(Constant *LHS, Constant *RHS,
39  bool HasNUW = false, bool HasNSW = false) const = 0;
40  virtual Value *CreateFMul(Constant *LHS, Constant *RHS) const = 0;
41  virtual Value *CreateUDiv(Constant *LHS, Constant *RHS,
42  bool isExact = false) const = 0;
43  virtual Value *CreateSDiv(Constant *LHS, Constant *RHS,
44  bool isExact = false) const = 0;
45  virtual Value *CreateFDiv(Constant *LHS, Constant *RHS) const = 0;
46  virtual Value *CreateURem(Constant *LHS, Constant *RHS) const = 0;
47  virtual Value *CreateSRem(Constant *LHS, Constant *RHS) const = 0;
48  virtual Value *CreateFRem(Constant *LHS, Constant *RHS) const = 0;
49  virtual Value *CreateShl(Constant *LHS, Constant *RHS,
50  bool HasNUW = false, bool HasNSW = false) const = 0;
51  virtual Value *CreateLShr(Constant *LHS, Constant *RHS,
52  bool isExact = false) const = 0;
53  virtual Value *CreateAShr(Constant *LHS, Constant *RHS,
54  bool isExact = false) const = 0;
55  virtual Value *CreateAnd(Constant *LHS, Constant *RHS) const = 0;
56  virtual Value *CreateOr(Constant *LHS, Constant *RHS) const = 0;
57  virtual Value *CreateXor(Constant *LHS, Constant *RHS) const = 0;
59  Constant *LHS, Constant *RHS) const = 0;
60 
61  //===--------------------------------------------------------------------===//
62  // Unary Operators
63  //===--------------------------------------------------------------------===//
64 
65  virtual Value *CreateNeg(Constant *C,
66  bool HasNUW = false, bool HasNSW = false) const = 0;
67  virtual Value *CreateFNeg(Constant *C) const = 0;
68  virtual Value *CreateNot(Constant *C) const = 0;
69  virtual Value *CreateUnOp(Instruction::UnaryOps Opc, Constant *C) const = 0;
70 
71  //===--------------------------------------------------------------------===//
72  // Memory Instructions
73  //===--------------------------------------------------------------------===//
74 
75  virtual Value *CreateGetElementPtr(Type *Ty, Constant *C,
76  ArrayRef<Constant *> IdxList) const = 0;
77  // This form of the function only exists to avoid ambiguous overload
78  // warnings about whether to convert Idx to ArrayRef<Constant *> or
79  // ArrayRef<Value *>.
80  virtual Value *CreateGetElementPtr(Type *Ty, Constant *C,
81  Constant *Idx) const = 0;
82  virtual Value *CreateGetElementPtr(Type *Ty, Constant *C,
83  ArrayRef<Value *> IdxList) const = 0;
85  Type *Ty, Constant *C, ArrayRef<Constant *> IdxList) const = 0;
86  // This form of the function only exists to avoid ambiguous overload
87  // warnings about whether to convert Idx to ArrayRef<Constant *> or
88  // ArrayRef<Value *>.
90  Constant *Idx) const = 0;
92  Type *Ty, Constant *C, ArrayRef<Value *> IdxList) const = 0;
93 
94  //===--------------------------------------------------------------------===//
95  // Cast/Conversion Operators
96  //===--------------------------------------------------------------------===//
97 
99  Type *DestTy) const = 0;
100  virtual Value *CreatePointerCast(Constant *C, Type *DestTy) const = 0;
102  Type *DestTy) const = 0;
103  virtual Value *CreateIntCast(Constant *C, Type *DestTy,
104  bool isSigned) const = 0;
105  virtual Value *CreateFPCast(Constant *C, Type *DestTy) const = 0;
106  virtual Value *CreateBitCast(Constant *C, Type *DestTy) const = 0;
107  virtual Value *CreateIntToPtr(Constant *C, Type *DestTy) const = 0;
108  virtual Value *CreatePtrToInt(Constant *C, Type *DestTy) const = 0;
109  virtual Value *CreateZExtOrBitCast(Constant *C, Type *DestTy) const = 0;
110  virtual Value *CreateSExtOrBitCast(Constant *C, Type *DestTy) const = 0;
111  virtual Value *CreateTruncOrBitCast(Constant *C, Type *DestTy) const = 0;
112 
113  //===--------------------------------------------------------------------===//
114  // Compare Instructions
115  //===--------------------------------------------------------------------===//
116 
118  Constant *RHS) const = 0;
119  virtual Value *CreateFCmp(CmpInst::Predicate P, Constant *LHS,
120  Constant *RHS) const = 0;
121 
122  //===--------------------------------------------------------------------===//
123  // Other Instructions
124  //===--------------------------------------------------------------------===//
125 
126  virtual Value *CreateSelect(Constant *C, Constant *True,
127  Constant *False) const = 0;
128  virtual Value *CreateExtractElement(Constant *Vec, Constant *Idx) const = 0;
129  virtual Value *CreateInsertElement(Constant *Vec, Constant *NewElt,
130  Constant *Idx) const = 0;
132  ArrayRef<int> Mask) const = 0;
133  virtual Value *CreateExtractValue(Constant *Agg,
134  ArrayRef<unsigned> IdxList) const = 0;
135  virtual Value *CreateInsertValue(Constant *Agg, Constant *Val,
136  ArrayRef<unsigned> IdxList) const = 0;
137 };
138 
139 } // end namespace llvm
140 
141 #endif // LLVM_IR_IRBUILDERFOLDER_H
virtual Value * CreateNot(Constant *C) const =0
virtual Value * CreateFDiv(Constant *LHS, Constant *RHS) const =0
uint64_t CallInst * C
virtual Value * CreateSub(Constant *LHS, Constant *RHS, bool HasNUW=false, bool HasNSW=false) const =0
This class represents lattice values for constants.
Definition: AllocatorList.h:23
virtual Value * CreateSExtOrBitCast(Constant *C, Type *DestTy) const =0
virtual Value * CreateFSub(Constant *LHS, Constant *RHS) const =0
virtual Value * CreateInsertValue(Constant *Agg, Constant *Val, ArrayRef< unsigned > IdxList) const =0
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:725
virtual Value * CreateBinOp(Instruction::BinaryOps Opc, Constant *LHS, Constant *RHS) const =0
virtual Value * CreateFMul(Constant *LHS, Constant *RHS) const =0
virtual Value * CreateMul(Constant *LHS, Constant *RHS, bool HasNUW=false, bool HasNSW=false) const =0
virtual Value * CreateXor(Constant *LHS, Constant *RHS) const =0
virtual Value * CreateFRem(Constant *LHS, Constant *RHS) const =0
virtual Value * CreateFNeg(Constant *C) const =0
virtual Value * CreateNeg(Constant *C, bool HasNUW=false, bool HasNSW=false) const =0
virtual Value * CreateURem(Constant *LHS, Constant *RHS) const =0
virtual Value * CreateICmp(CmpInst::Predicate P, Constant *LHS, Constant *RHS) const =0
virtual Value * CreateFAdd(Constant *LHS, Constant *RHS) const =0
virtual ~IRBuilderFolder()
Definition: IRBuilder.cpp:1148
virtual Value * CreateUDiv(Constant *LHS, Constant *RHS, bool isExact=false) const =0
std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E&#39;s largest value.
Definition: BitmaskEnum.h:80
virtual Value * CreateSRem(Constant *LHS, Constant *RHS) const =0
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
virtual Value * CreateAdd(Constant *LHS, Constant *RHS, bool HasNUW=false, bool HasNSW=false) const =0
virtual Value * CreateIntCast(Constant *C, Type *DestTy, bool isSigned) const =0
virtual Value * CreateZExtOrBitCast(Constant *C, Type *DestTy) const =0
#define P(N)
virtual Value * CreatePtrToInt(Constant *C, Type *DestTy) const =0
virtual Value * CreateSelect(Constant *C, Constant *True, Constant *False) const =0
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
virtual Value * CreateTruncOrBitCast(Constant *C, Type *DestTy) const =0
This is an important base class in LLVM.
Definition: Constant.h:41
virtual Value * CreateShuffleVector(Constant *V1, Constant *V2, ArrayRef< int > Mask) const =0
virtual Value * CreateSDiv(Constant *LHS, Constant *RHS, bool isExact=false) const =0
virtual Value * CreateShl(Constant *LHS, Constant *RHS, bool HasNUW=false, bool HasNSW=false) const =0
virtual Value * CreateOr(Constant *LHS, Constant *RHS) const =0
IRBuilderFolder - Interface for constant folding in IRBuilder.
virtual Value * CreateLShr(Constant *LHS, Constant *RHS, bool isExact=false) const =0
virtual Value * CreateExtractValue(Constant *Agg, ArrayRef< unsigned > IdxList) const =0
virtual Value * CreateFPCast(Constant *C, Type *DestTy) const =0
virtual Value * CreateBitCast(Constant *C, Type *DestTy) const =0
virtual Value * CreateExtractElement(Constant *Vec, Constant *Idx) const =0
virtual Value * CreatePointerBitCastOrAddrSpaceCast(Constant *C, Type *DestTy) const =0
virtual Value * CreateUnOp(Instruction::UnaryOps Opc, Constant *C) const =0
virtual Value * CreatePointerCast(Constant *C, Type *DestTy) const =0
virtual Value * CreateIntToPtr(Constant *C, Type *DestTy) const =0
virtual Value * CreateInsertElement(Constant *Vec, Constant *NewElt, Constant *Idx) const =0
virtual Value * CreateAShr(Constant *LHS, Constant *RHS, bool isExact=false) const =0
LLVM Value Representation.
Definition: Value.h:74
virtual Value * CreateAnd(Constant *LHS, Constant *RHS) const =0
virtual Value * CreateCast(Instruction::CastOps Op, Constant *C, Type *DestTy) const =0
virtual Value * CreateFCmp(CmpInst::Predicate P, Constant *LHS, Constant *RHS) const =0
virtual Value * CreateGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant *> IdxList) const =0
virtual Value * CreateInBoundsGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant *> IdxList) const =0