LLVM  16.0.0git
NoFolder.h
Go to the documentation of this file.
1 //===- NoFolder.h - Constant folding helper ---------------------*- 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 the NoFolder class, a helper for IRBuilder. It provides
10 // IRBuilder with a set of methods for creating unfolded constants. This is
11 // useful for learners trying to understand how LLVM IR works, and who don't
12 // want details to be hidden by the constant folder. For general constant
13 // creation and folding, use ConstantExpr and the routines in
14 // llvm/Analysis/ConstantFolding.h.
15 //
16 // Note: since it is not actually possible to create unfolded constants, this
17 // class returns instructions rather than constants.
18 //
19 //===----------------------------------------------------------------------===//
20 
21 #ifndef LLVM_IR_NOFOLDER_H
22 #define LLVM_IR_NOFOLDER_H
23 
24 #include "llvm/ADT/ArrayRef.h"
25 #include "llvm/IR/Constants.h"
26 #include "llvm/IR/FMF.h"
28 #include "llvm/IR/InstrTypes.h"
29 #include "llvm/IR/Instruction.h"
30 #include "llvm/IR/Instructions.h"
31 
32 namespace llvm {
33 
34 /// NoFolder - Create "constants" (actually, instructions) with no folding.
35 class NoFolder final : public IRBuilderFolder {
36  virtual void anchor();
37 
38 public:
39  explicit NoFolder() = default;
40 
41  //===--------------------------------------------------------------------===//
42  // Value-based folders.
43  //
44  // Return an existing value or a constant if the operation can be simplified.
45  // Otherwise return nullptr.
46  //===--------------------------------------------------------------------===//
47 
49  Value *RHS) const override {
50  return nullptr;
51  }
52 
54  bool IsExact) const override {
55  return nullptr;
56  }
57 
59  bool HasNUW, bool HasNSW) const override {
60  return nullptr;
61  }
62 
64  FastMathFlags FMF) const override {
65  return nullptr;
66  }
67 
69  FastMathFlags FMF) const override {
70  return nullptr;
71  }
72 
74  return nullptr;
75  }
76 
78  bool IsInBounds = false) const override {
79  return nullptr;
80  }
81 
82  Value *FoldSelect(Value *C, Value *True, Value *False) const override {
83  return nullptr;
84  }
85 
87  ArrayRef<unsigned> IdxList) const override {
88  return nullptr;
89  }
90 
92  ArrayRef<unsigned> IdxList) const override {
93  return nullptr;
94  }
95 
96  Value *FoldExtractElement(Value *Vec, Value *Idx) const override {
97  return nullptr;
98  }
99 
101  Value *Idx) const override {
102  return nullptr;
103  }
104 
106  ArrayRef<int> Mask) const override {
107  return nullptr;
108  }
109 
110  //===--------------------------------------------------------------------===//
111  // Cast/Conversion Operators
112  //===--------------------------------------------------------------------===//
113 
115  Type *DestTy) const override {
116  return CastInst::Create(Op, C, DestTy);
117  }
118 
119  Instruction *CreatePointerCast(Constant *C, Type *DestTy) const override {
120  return CastInst::CreatePointerCast(C, DestTy);
121  }
122 
124  Constant *C, Type *DestTy) const override {
126  }
127 
129  bool isSigned) const override {
130  return CastInst::CreateIntegerCast(C, DestTy, isSigned);
131  }
132 
133  Instruction *CreateFPCast(Constant *C, Type *DestTy) const override {
134  return CastInst::CreateFPCast(C, DestTy);
135  }
136 
137  Instruction *CreateBitCast(Constant *C, Type *DestTy) const override {
138  return CreateCast(Instruction::BitCast, C, DestTy);
139  }
140 
141  Instruction *CreateIntToPtr(Constant *C, Type *DestTy) const override {
142  return CreateCast(Instruction::IntToPtr, C, DestTy);
143  }
144 
145  Instruction *CreatePtrToInt(Constant *C, Type *DestTy) const override {
146  return CreateCast(Instruction::PtrToInt, C, DestTy);
147  }
148 
149  Instruction *CreateZExtOrBitCast(Constant *C, Type *DestTy) const override {
150  return CastInst::CreateZExtOrBitCast(C, DestTy);
151  }
152 
153  Instruction *CreateSExtOrBitCast(Constant *C, Type *DestTy) const override {
154  return CastInst::CreateSExtOrBitCast(C, DestTy);
155  }
156 
157  Instruction *CreateTruncOrBitCast(Constant *C, Type *DestTy) const override {
158  return CastInst::CreateTruncOrBitCast(C, DestTy);
159  }
160 
161  //===--------------------------------------------------------------------===//
162  // Compare Instructions
163  //===--------------------------------------------------------------------===//
164 
166  Constant *LHS, Constant *RHS) const override {
167  return new FCmpInst(P, LHS, RHS);
168  }
169 };
170 
171 } // end namespace llvm
172 
173 #endif // LLVM_IR_NOFOLDER_H
llvm::NoFolder::FoldExtractValue
Value * FoldExtractValue(Value *Agg, ArrayRef< unsigned > IdxList) const override
Definition: NoFolder.h:86
llvm::NoFolder::CreateIntCast
Instruction * CreateIntCast(Constant *C, Type *DestTy, bool isSigned) const override
Definition: NoFolder.h:128
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
FMF.h
llvm::CastInst::CreatePointerBitCastOrAddrSpaceCast
static CastInst * CreatePointerBitCastOrAddrSpaceCast(Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd)
Create a BitCast or an AddrSpaceCast cast instruction.
Definition: Instructions.cpp:3469
llvm::Instruction::UnaryOps
UnaryOps
Definition: Instruction.h:786
llvm::CmpInst::Predicate
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:720
llvm::NoFolder::CreateSExtOrBitCast
Instruction * CreateSExtOrBitCast(Constant *C, Type *DestTy) const override
Definition: NoFolder.h:153
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::NoFolder::FoldGEP
Value * FoldGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, bool IsInBounds=false) const override
Definition: NoFolder.h:77
llvm::IRBuilderFolder
IRBuilderFolder - Interface for constant folding in IRBuilder.
Definition: IRBuilderFolder.h:24
llvm::NoFolder::CreateTruncOrBitCast
Instruction * CreateTruncOrBitCast(Constant *C, Type *DestTy) const override
Definition: NoFolder.h:157
llvm::NoFolder::FoldExactBinOp
Value * FoldExactBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, bool IsExact) const override
Definition: NoFolder.h:53
llvm::CastInst::Create
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
Definition: Instructions.cpp:3340
llvm::NoFolder::CreateCast
Instruction * CreateCast(Instruction::CastOps Op, Constant *C, Type *DestTy) const override
Definition: NoFolder.h:114
llvm::NoFolder::CreateFPCast
Instruction * CreateFPCast(Constant *C, Type *DestTy) const override
Definition: NoFolder.h:133
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::NoFolder::FoldICmp
Value * FoldICmp(CmpInst::Predicate P, Value *LHS, Value *RHS) const override
Definition: NoFolder.h:73
llvm::NoFolder::FoldNoWrapBinOp
Value * FoldNoWrapBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, bool HasNUW, bool HasNSW) const override
Definition: NoFolder.h:58
llvm::CastInst::CreateIntegerCast
static CastInst * CreateIntegerCast(Value *S, Type *Ty, bool isSigned, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a ZExt, BitCast, or Trunc for int -> int casts.
Definition: Instructions.cpp:3506
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::NoFolder::CreatePtrToInt
Instruction * CreatePtrToInt(Constant *C, Type *DestTy) const override
Definition: NoFolder.h:145
llvm::NoFolder::CreateIntToPtr
Instruction * CreateIntToPtr(Constant *C, Type *DestTy) const override
Definition: NoFolder.h:141
llvm::NoFolder::FoldSelect
Value * FoldSelect(Value *C, Value *True, Value *False) const override
Definition: NoFolder.h:82
llvm::FastMathFlags
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:21
llvm::NoFolder::CreateZExtOrBitCast
Instruction * CreateZExtOrBitCast(Constant *C, Type *DestTy) const override
Definition: NoFolder.h:149
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::NoFolder::FoldBinOp
Value * FoldBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS) const override
Definition: NoFolder.h:48
Constants.h
llvm::NoFolder::CreateFCmp
Instruction * CreateFCmp(CmpInst::Predicate P, Constant *LHS, Constant *RHS) const override
Definition: NoFolder.h:165
llvm::NoFolder::FoldShuffleVector
Value * FoldShuffleVector(Value *V1, Value *V2, ArrayRef< int > Mask) const override
Definition: NoFolder.h:105
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
InstrTypes.h
llvm::FCmpInst
This instruction compares its operands according to the predicate given to the constructor.
Definition: Instructions.h:1360
llvm::CastInst::CreateFPCast
static CastInst * CreateFPCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create an FPExt, BitCast, or FPTrunc for fp -> fp casts.
Definition: Instructions.cpp:3534
llvm::NoFolder::CreateBitCast
Instruction * CreateBitCast(Constant *C, Type *DestTy) const override
Definition: NoFolder.h:137
llvm::Instruction::CastOps
CastOps
Definition: Instruction.h:807
llvm::Instruction
Definition: Instruction.h:42
llvm::CastInst::CreateSExtOrBitCast
static CastInst * CreateSExtOrBitCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a SExt or BitCast cast instruction.
Definition: Instructions.cpp:3400
llvm::NoFolder::FoldUnOpFMF
Value * FoldUnOpFMF(Instruction::UnaryOps Opc, Value *V, FastMathFlags FMF) const override
Definition: NoFolder.h:68
llvm::CastInst::CreateTruncOrBitCast
static CastInst * CreateTruncOrBitCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a Trunc or BitCast cast instruction.
Definition: Instructions.cpp:3416
llvm::NoFolder
NoFolder - Create "constants" (actually, instructions) with no folding.
Definition: NoFolder.h:35
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::NoFolder::CreatePointerBitCastOrAddrSpaceCast
Instruction * CreatePointerBitCastOrAddrSpaceCast(Constant *C, Type *DestTy) const override
Definition: NoFolder.h:123
llvm::NoFolder::FoldInsertElement
Value * FoldInsertElement(Value *Vec, Value *NewElt, Value *Idx) const override
Definition: NoFolder.h:100
ArrayRef.h
IRBuilderFolder.h
llvm::NoFolder::CreatePointerCast
Instruction * CreatePointerCast(Constant *C, Type *DestTy) const override
Definition: NoFolder.h:119
Ptr
@ Ptr
Definition: TargetLibraryInfo.cpp:60
llvm::NoFolder::FoldExtractElement
Value * FoldExtractElement(Value *Vec, Value *Idx) const override
Definition: NoFolder.h:96
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::NoFolder::NoFolder
NoFolder()=default
llvm::NoFolder::FoldBinOpFMF
Value * FoldBinOpFMF(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, FastMathFlags FMF) const override
Definition: NoFolder.h:63
llvm::NVPTX::PTXLdStInstCode::V2
@ V2
Definition: NVPTX.h:123
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:348
llvm::Instruction::BinaryOps
BinaryOps
Definition: Instruction.h:793
isSigned
static bool isSigned(unsigned int Opcode)
Definition: ExpandLargeDivRem.cpp:52
Instructions.h
llvm::CastInst::CreatePointerCast
static CastInst * CreatePointerCast(Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd)
Create a BitCast AddrSpaceCast, or a PtrToInt cast instruction.
Definition: Instructions.cpp:3432
llvm::CastInst::CreateZExtOrBitCast
static CastInst * CreateZExtOrBitCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a ZExt or BitCast cast instruction.
Definition: Instructions.cpp:3384
llvm::NoFolder::FoldInsertValue
Value * FoldInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > IdxList) const override
Definition: NoFolder.h:91
llvm::Value
LLVM Value Representation.
Definition: Value.h:74