LLVM  15.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  // 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 
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  virtual Value *FoldExtractValue(Value *Agg,
50  ArrayRef<unsigned> IdxList) const = 0;
51 
52  virtual Value *FoldInsertValue(Value *Agg, Value *Val,
53  ArrayRef<unsigned> IdxList) const = 0;
54 
55  //===--------------------------------------------------------------------===//
56  // Binary Operators
57  //===--------------------------------------------------------------------===//
58 
59  virtual Value *CreateFAdd(Constant *LHS, Constant *RHS) const = 0;
60  virtual Value *CreateSub(Constant *LHS, Constant *RHS,
61  bool HasNUW = false, bool HasNSW = false) const = 0;
62  virtual Value *CreateFSub(Constant *LHS, Constant *RHS) const = 0;
63  virtual Value *CreateMul(Constant *LHS, Constant *RHS,
64  bool HasNUW = false, bool HasNSW = false) const = 0;
65  virtual Value *CreateFMul(Constant *LHS, Constant *RHS) const = 0;
67  bool isExact = false) const = 0;
69  bool isExact = false) const = 0;
70  virtual Value *CreateFDiv(Constant *LHS, Constant *RHS) const = 0;
71  virtual Value *CreateURem(Constant *LHS, Constant *RHS) const = 0;
72  virtual Value *CreateSRem(Constant *LHS, Constant *RHS) const = 0;
73  virtual Value *CreateFRem(Constant *LHS, Constant *RHS) const = 0;
74  virtual Value *CreateShl(Constant *LHS, Constant *RHS,
75  bool HasNUW = false, bool HasNSW = false) const = 0;
77  bool isExact = false) const = 0;
79  bool isExact = false) const = 0;
80  virtual Value *CreateXor(Constant *LHS, Constant *RHS) const = 0;
82  Constant *LHS, Constant *RHS) const = 0;
83 
84  //===--------------------------------------------------------------------===//
85  // Unary Operators
86  //===--------------------------------------------------------------------===//
87 
88  virtual Value *CreateNeg(Constant *C,
89  bool HasNUW = false, bool HasNSW = false) const = 0;
90  virtual Value *CreateFNeg(Constant *C) const = 0;
91  virtual Value *CreateNot(Constant *C) const = 0;
92  virtual Value *CreateUnOp(Instruction::UnaryOps Opc, Constant *C) 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 
120  //===--------------------------------------------------------------------===//
121  // Other Instructions
122  //===--------------------------------------------------------------------===//
123 
124  virtual Value *CreateExtractElement(Constant *Vec, Constant *Idx) const = 0;
125  virtual Value *CreateInsertElement(Constant *Vec, Constant *NewElt,
126  Constant *Idx) const = 0;
128  ArrayRef<int> Mask) const = 0;
129 };
130 
131 } // end namespace llvm
132 
133 #endif // LLVM_IR_IRBUILDERFOLDER_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::IRBuilderFolder::CreateFCmp
virtual Value * CreateFCmp(CmpInst::Predicate P, Constant *LHS, Constant *RHS) const =0
llvm::Instruction::UnaryOps
UnaryOps
Definition: Instruction.h:779
llvm::IRBuilderFolder::CreateBitCast
virtual Value * CreateBitCast(Constant *C, Type *DestTy) const =0
llvm::CmpInst::Predicate
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:719
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::IRBuilderFolder
IRBuilderFolder - Interface for constant folding in IRBuilder.
Definition: IRBuilderFolder.h:24
llvm::IRBuilderFolder::CreateInsertElement
virtual Value * CreateInsertElement(Constant *Vec, Constant *NewElt, Constant *Idx) const =0
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::IRBuilderFolder::FoldAnd
virtual Value * FoldAnd(Value *LHS, Value *RHS) const =0
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::IRBuilderFolder::CreateMul
virtual Value * CreateMul(Constant *LHS, Constant *RHS, bool HasNUW=false, bool HasNSW=false) const =0
llvm::IRBuilderFolder::CreateFAdd
virtual Value * CreateFAdd(Constant *LHS, Constant *RHS) const =0
llvm::IRBuilderFolder::CreateIntCast
virtual Value * CreateIntCast(Constant *C, Type *DestTy, bool isSigned) const =0
llvm::IRBuilderFolder::CreateAShr
virtual Value * CreateAShr(Constant *LHS, Constant *RHS, bool isExact=false) const =0
llvm::BitmaskEnumDetail::Mask
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:80
Instruction.h
LHS
Value * LHS
Definition: X86PartialReduction.cpp:75
llvm::IRBuilderFolder::CreatePointerBitCastOrAddrSpaceCast
virtual Value * CreatePointerBitCastOrAddrSpaceCast(Constant *C, Type *DestTy) const =0
llvm::IRBuilderFolder::FoldSelect
virtual Value * FoldSelect(Value *C, Value *True, Value *False) const =0
llvm::IRBuilderFolder::CreateURem
virtual Value * CreateURem(Constant *LHS, Constant *RHS) const =0
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
InstrTypes.h
llvm::Instruction::CastOps
CastOps
Definition: Instruction.h:800
llvm::IRBuilderFolder::CreateFRem
virtual Value * CreateFRem(Constant *LHS, Constant *RHS) const =0
llvm::IRBuilderFolder::CreateSRem
virtual Value * CreateSRem(Constant *LHS, Constant *RHS) const =0
llvm::IRBuilderFolder::FoldOr
virtual Value * FoldOr(Value *LHS, Value *RHS) const =0
llvm::IRBuilderFolder::CreateFMul
virtual Value * CreateFMul(Constant *LHS, Constant *RHS) const =0
llvm::IRBuilderFolder::CreateCast
virtual Value * CreateCast(Instruction::CastOps Op, Constant *C, Type *DestTy) const =0
llvm::IRBuilderFolder::CreateFSub
virtual Value * CreateFSub(Constant *LHS, Constant *RHS) const =0
llvm::IRBuilderFolder::CreateZExtOrBitCast
virtual Value * CreateZExtOrBitCast(Constant *C, Type *DestTy) const =0
llvm::IRBuilderFolder::CreateFPCast
virtual Value * CreateFPCast(Constant *C, Type *DestTy) const =0
llvm::IRBuilderFolder::CreateShl
virtual Value * CreateShl(Constant *LHS, Constant *RHS, bool HasNUW=false, bool HasNSW=false) const =0
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::IRBuilderFolder::CreateTruncOrBitCast
virtual Value * CreateTruncOrBitCast(Constant *C, Type *DestTy) const =0
llvm::IRBuilderFolder::FoldExtractValue
virtual Value * FoldExtractValue(Value *Agg, ArrayRef< unsigned > IdxList) const =0
llvm::IRBuilderFolder::CreateFDiv
virtual Value * CreateFDiv(Constant *LHS, Constant *RHS) const =0
llvm::IRBuilderFolder::CreateIntToPtr
virtual Value * CreateIntToPtr(Constant *C, Type *DestTy) const =0
ArrayRef.h
llvm::IRBuilderFolder::CreateLShr
virtual Value * CreateLShr(Constant *LHS, Constant *RHS, bool isExact=false) const =0
llvm::IRBuilderFolder::CreateNeg
virtual Value * CreateNeg(Constant *C, bool HasNUW=false, bool HasNSW=false) const =0
llvm::IRBuilderFolder::FoldICmp
virtual Value * FoldICmp(CmpInst::Predicate P, Value *LHS, Value *RHS) const =0
llvm::IRBuilderFolder::CreatePtrToInt
virtual Value * CreatePtrToInt(Constant *C, Type *DestTy) const =0
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::IRBuilderFolder::FoldAdd
virtual Value * FoldAdd(Value *LHS, Value *RHS, bool HasNUW=false, bool HasNSW=false) const =0
llvm::IRBuilderFolder::CreatePointerCast
virtual Value * CreatePointerCast(Constant *C, Type *DestTy) const =0
llvm::IRBuilderFolder::CreateSExtOrBitCast
virtual Value * CreateSExtOrBitCast(Constant *C, Type *DestTy) const =0
llvm::IRBuilderFolder::CreateUDiv
virtual Value * CreateUDiv(Constant *LHS, Constant *RHS, bool isExact=false) const =0
llvm::NVPTX::PTXLdStInstCode::V2
@ V2
Definition: NVPTX.h:123
llvm::IRBuilderFolder::CreateNot
virtual Value * CreateNot(Constant *C) const =0
llvm::IRBuilderFolder::CreateFNeg
virtual Value * CreateFNeg(Constant *C) const =0
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:344
llvm::IRBuilderFolder::CreateShuffleVector
virtual Value * CreateShuffleVector(Constant *V1, Constant *V2, ArrayRef< int > Mask) const =0
llvm::IRBuilderFolder::~IRBuilderFolder
virtual ~IRBuilderFolder()
llvm::IRBuilderFolder::CreateBinOp
virtual Value * CreateBinOp(Instruction::BinaryOps Opc, Constant *LHS, Constant *RHS) const =0
llvm::IRBuilderFolder::CreateExtractElement
virtual Value * CreateExtractElement(Constant *Vec, Constant *Idx) const =0
llvm::IRBuilderFolder::CreateXor
virtual Value * CreateXor(Constant *LHS, Constant *RHS) const =0
llvm::IRBuilderFolder::FoldInsertValue
virtual Value * FoldInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > IdxList) const =0
llvm::Instruction::BinaryOps
BinaryOps
Definition: Instruction.h:786
llvm::IRBuilderFolder::FoldGEP
virtual Value * FoldGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, bool IsInBounds=false) const =0
llvm::IRBuilderFolder::CreateSub
virtual Value * CreateSub(Constant *LHS, Constant *RHS, bool HasNUW=false, bool HasNSW=false) const =0
llvm::IRBuilderFolder::CreateUnOp
virtual Value * CreateUnOp(Instruction::UnaryOps Opc, Constant *C) const =0
llvm::IRBuilderFolder::CreateSDiv
virtual Value * CreateSDiv(Constant *LHS, Constant *RHS, bool isExact=false) const =0
llvm::Value
LLVM Value Representation.
Definition: Value.h:74