Debian Codegraph @

suite/synctools/tablegen/include/llvm/IR/IRBuilderFolder.h

raw symbols SCIP
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.
24 class IRBuilderFolder {
25 public:
26 virtual ~IRBuilderFolder();
27
28 //===--------------------------------------------------------------------===//
29 // Value-based folders.
30 //
31 // Return an existing value or a constant if the operation can be simplified.
32 // Otherwise return nullptr.
33 //===--------------------------------------------------------------------===//
34 virtual Value *FoldAdd(Value *LHS, Value *RHS, bool HasNUW = false,
35 bool HasNSW = false) const = 0;
36
37 virtual Value *FoldAnd(Value *LHS, Value *RHS) const = 0;
38
39 virtual Value *FoldOr(Value *LHS, Value *RHS) const = 0;
40
41 virtual Value *FoldICmp(CmpInst::Predicate P, Value *LHS,
42 Value *RHS) const = 0;
43
44 virtual Value *FoldGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
45 bool IsInBounds = false) const = 0;
46
47 virtual Value *FoldSelect(Value *C, Value *True, Value *False) const = 0;
48
49 //===--------------------------------------------------------------------===//
50 // Binary Operators
51 //===--------------------------------------------------------------------===//
52
53 virtual Value *CreateFAdd(Constant *LHS, Constant *RHS) const = 0;
54 virtual Value *CreateSub(Constant *LHS, Constant *RHS,
55 bool HasNUW = false, bool HasNSW = false) const = 0;
56 virtual Value *CreateFSub(Constant *LHS, Constant *RHS) const = 0;
57 virtual Value *CreateMul(Constant *LHS, Constant *RHS,
58 bool HasNUW = false, bool HasNSW = false) const = 0;
59 virtual Value *CreateFMul(Constant *LHS, Constant *RHS) const = 0;
60 virtual Value *CreateUDiv(Constant *LHS, Constant *RHS,
61 bool isExact = false) const = 0;
62 virtual Value *CreateSDiv(Constant *LHS, Constant *RHS,
63 bool isExact = false) const = 0;
64 virtual Value *CreateFDiv(Constant *LHS, Constant *RHS) const = 0;
65 virtual Value *CreateURem(Constant *LHS, Constant *RHS) const = 0;
66 virtual Value *CreateSRem(Constant *LHS, Constant *RHS) const = 0;
67 virtual Value *CreateFRem(Constant *LHS, Constant *RHS) const = 0;
68 virtual Value *CreateShl(Constant *LHS, Constant *RHS,
69 bool HasNUW = false, bool HasNSW = false) const = 0;
70 virtual Value *CreateLShr(Constant *LHS, Constant *RHS,
71 bool isExact = false) const = 0;
72 virtual Value *CreateAShr(Constant *LHS, Constant *RHS,
73 bool isExact = false) const = 0;
74 virtual Value *CreateXor(Constant *LHS, Constant *RHS) const = 0;
75 virtual Value *CreateBinOp(Instruction::BinaryOps Opc,
76 Constant *LHS, Constant *RHS) const = 0;
77
78 //===--------------------------------------------------------------------===//
79 // Unary Operators
80 //===--------------------------------------------------------------------===//
81
82 virtual Value *CreateNeg(Constant *C,
83 bool HasNUW = false, bool HasNSW = false) const = 0;
84 virtual Value *CreateFNeg(Constant *C) const = 0;
85 virtual Value *CreateNot(Constant *C) const = 0;
86 virtual Value *CreateUnOp(Instruction::UnaryOps Opc, Constant *C) const = 0;
87
88 //===--------------------------------------------------------------------===//
89 // Cast/Conversion Operators
90 //===--------------------------------------------------------------------===//
91
92 virtual Value *CreateCast(Instruction::CastOps Op, Constant *C,
93 Type *DestTy) const = 0;
94 virtual Value *CreatePointerCast(Constant *C, Type *DestTy) const = 0;
95 virtual Value *CreatePointerBitCastOrAddrSpaceCast(Constant *C,
96 Type *DestTy) const = 0;
97 virtual Value *CreateIntCast(Constant *C, Type *DestTy,
98 bool isSigned) const = 0;
99 virtual Value *CreateFPCast(Constant *C, Type *DestTy) const = 0;
100 virtual Value *CreateBitCast(Constant *C, Type *DestTy) const = 0;
101 virtual Value *CreateIntToPtr(Constant *C, Type *DestTy) const = 0;
102 virtual Value *CreatePtrToInt(Constant *C, Type *DestTy) const = 0;
103 virtual Value *CreateZExtOrBitCast(Constant *C, Type *DestTy) const = 0;
104 virtual Value *CreateSExtOrBitCast(Constant *C, Type *DestTy) const = 0;
105 virtual Value *CreateTruncOrBitCast(Constant *C, Type *DestTy) const = 0;
106
107 //===--------------------------------------------------------------------===//
108 // Compare Instructions
109 //===--------------------------------------------------------------------===//
110
111 virtual Value *CreateFCmp(CmpInst::Predicate P, Constant *LHS,
112 Constant *RHS) const = 0;
113
114 //===--------------------------------------------------------------------===//
115 // Other Instructions
116 //===--------------------------------------------------------------------===//
117
118 virtual Value *CreateExtractElement(Constant *Vec, Constant *Idx) const = 0;
119 virtual Value *CreateInsertElement(Constant *Vec, Constant *NewElt,
120 Constant *Idx) const = 0;
121 virtual Value *CreateShuffleVector(Constant *V1, Constant *V2,
122 ArrayRef<int> Mask) const = 0;
123 virtual Value *CreateExtractValue(Constant *Agg,
124 ArrayRef<unsigned> IdxList) const = 0;
125 virtual Value *CreateInsertValue(Constant *Agg, Constant *Val,
126 ArrayRef<unsigned> IdxList) const = 0;
127 };
128
129 } // end namespace llvm
130
131 #endif // LLVM_IR_IRBUILDERFOLDER_H