Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
14 | pmbaty | 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 | |||
35 | virtual Value *FoldBinOp(Instruction::BinaryOps Opc, Value *LHS, |
||
36 | Value *RHS) const = 0; |
||
37 | |||
38 | virtual Value *FoldExactBinOp(Instruction::BinaryOps Opc, Value *LHS, |
||
39 | Value *RHS, bool IsExact) const = 0; |
||
40 | |||
41 | virtual Value *FoldNoWrapBinOp(Instruction::BinaryOps Opc, Value *LHS, |
||
42 | Value *RHS, bool HasNUW, |
||
43 | bool HasNSW) const = 0; |
||
44 | |||
45 | virtual Value *FoldBinOpFMF(Instruction::BinaryOps Opc, Value *LHS, |
||
46 | Value *RHS, FastMathFlags FMF) const = 0; |
||
47 | |||
48 | virtual Value *FoldUnOpFMF(Instruction::UnaryOps Opc, Value *V, |
||
49 | FastMathFlags FMF) const = 0; |
||
50 | |||
51 | virtual Value *FoldICmp(CmpInst::Predicate P, Value *LHS, |
||
52 | Value *RHS) const = 0; |
||
53 | |||
54 | virtual Value *FoldGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList, |
||
55 | bool IsInBounds = false) const = 0; |
||
56 | |||
57 | virtual Value *FoldSelect(Value *C, Value *True, Value *False) const = 0; |
||
58 | |||
59 | virtual Value *FoldExtractValue(Value *Agg, |
||
60 | ArrayRef<unsigned> IdxList) const = 0; |
||
61 | |||
62 | virtual Value *FoldInsertValue(Value *Agg, Value *Val, |
||
63 | ArrayRef<unsigned> IdxList) const = 0; |
||
64 | |||
65 | virtual Value *FoldExtractElement(Value *Vec, Value *Idx) const = 0; |
||
66 | |||
67 | virtual Value *FoldInsertElement(Value *Vec, Value *NewElt, |
||
68 | Value *Idx) const = 0; |
||
69 | |||
70 | virtual Value *FoldShuffleVector(Value *V1, Value *V2, |
||
71 | ArrayRef<int> Mask) const = 0; |
||
72 | |||
73 | //===--------------------------------------------------------------------===// |
||
74 | // Cast/Conversion Operators |
||
75 | //===--------------------------------------------------------------------===// |
||
76 | |||
77 | virtual Value *CreateCast(Instruction::CastOps Op, Constant *C, |
||
78 | Type *DestTy) const = 0; |
||
79 | virtual Value *CreatePointerCast(Constant *C, Type *DestTy) const = 0; |
||
80 | virtual Value *CreatePointerBitCastOrAddrSpaceCast(Constant *C, |
||
81 | Type *DestTy) const = 0; |
||
82 | virtual Value *CreateIntCast(Constant *C, Type *DestTy, |
||
83 | bool isSigned) const = 0; |
||
84 | virtual Value *CreateFPCast(Constant *C, Type *DestTy) const = 0; |
||
85 | virtual Value *CreateBitCast(Constant *C, Type *DestTy) const = 0; |
||
86 | virtual Value *CreateIntToPtr(Constant *C, Type *DestTy) const = 0; |
||
87 | virtual Value *CreatePtrToInt(Constant *C, Type *DestTy) const = 0; |
||
88 | virtual Value *CreateZExtOrBitCast(Constant *C, Type *DestTy) const = 0; |
||
89 | virtual Value *CreateSExtOrBitCast(Constant *C, Type *DestTy) const = 0; |
||
90 | virtual Value *CreateTruncOrBitCast(Constant *C, Type *DestTy) const = 0; |
||
91 | |||
92 | //===--------------------------------------------------------------------===// |
||
93 | // Compare Instructions |
||
94 | //===--------------------------------------------------------------------===// |
||
95 | |||
96 | virtual Value *CreateFCmp(CmpInst::Predicate P, Constant *LHS, |
||
97 | Constant *RHS) const = 0; |
||
98 | }; |
||
99 | |||
100 | } // end namespace llvm |
||
101 | |||
102 | #endif // LLVM_IR_IRBUILDERFOLDER_H |