LLVM 23.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"
32
33namespace llvm {
34
35/// NoFolder - Create "constants" (actually, instructions) with no folding.
36class LLVM_ABI NoFolder final : public IRBuilderFolder {
38
39public:
40 explicit NoFolder() = default;
41
42 //===--------------------------------------------------------------------===//
43 // Value-based folders.
44 //
45 // Return an existing value or a constant if the operation can be simplified.
46 // Otherwise return nullptr.
47 //===--------------------------------------------------------------------===//
48
50 Value *RHS) const override {
51 return nullptr;
52 }
53
55 bool IsExact) const override {
56 return nullptr;
57 }
58
60 bool HasNUW, bool HasNSW) const override {
61 return nullptr;
62 }
63
65 FastMathFlags FMF) const override {
66 return nullptr;
67 }
68
70 FastMathFlags FMF) const override {
71 return nullptr;
72 }
73
75 return nullptr;
76 }
77
79 GEPNoWrapFlags NW) const override {
80 return nullptr;
81 }
82
83 Value *FoldSelect(Value *C, Value *True, Value *False,
84 FastMathFlags FMF) const override {
85 return nullptr;
86 }
87
89 ArrayRef<unsigned> IdxList) const override {
90 return nullptr;
91 }
92
94 ArrayRef<unsigned> IdxList) const override {
95 return nullptr;
96 }
97
98 Value *FoldExtractElement(Value *Vec, Value *Idx) const override {
99 return nullptr;
100 }
101
103 Value *Idx) const override {
104 return nullptr;
105 }
106
108 ArrayRef<int> Mask) const override {
109 return nullptr;
110 }
111
113 Type *DestTy) const override {
114 return nullptr;
115 }
116
118 FastMathFlags FMF) const override {
119 return nullptr;
120 }
121
122 //===--------------------------------------------------------------------===//
123 // Cast/Conversion Operators
124 //===--------------------------------------------------------------------===//
125
126 Instruction *CreatePointerCast(Constant *C, Type *DestTy) const override {
127 return CastInst::CreatePointerCast(C, DestTy);
128 }
129
134};
135
136} // end namespace llvm
137
138#endif // LLVM_IR_NOFOLDER_H
#define LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION()
\macro LLVM_VIRTUAL_ANCHOR_FUNCTION This macro is used to adhere to LLVM's policy that each class wit...
Definition Compiler.h:760
#define LLVM_ABI
Definition Compiler.h:213
This file contains the declarations for the subclasses of Constant, which represent the different fla...
#define P(N)
Value * RHS
Value * LHS
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
static LLVM_ABI CastInst * CreatePointerBitCastOrAddrSpaceCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a BitCast or an AddrSpaceCast cast instruction.
static LLVM_ABI CastInst * CreatePointerCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a BitCast, AddrSpaceCast or a PtrToInt cast instruction.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:676
This is an important base class in LLVM.
Definition Constant.h:43
Convenience struct for specifying and reasoning about fast-math flags.
Definition FMF.h:23
Represents flags for the getelementptr instruction/expression.
IRBuilderFolder - Interface for constant folding in IRBuilder.
Value * FoldShuffleVector(Value *V1, Value *V2, ArrayRef< int > Mask) const override
Definition NoFolder.h:107
Value * FoldExactBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, bool IsExact) const override
Definition NoFolder.h:54
Value * FoldBinaryIntrinsic(Intrinsic::ID ID, Value *LHS, Value *RHS, Type *Ty, FastMathFlags FMF) const override
Definition NoFolder.h:117
Value * FoldBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS) const override
Definition NoFolder.h:49
Value * FoldInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > IdxList) const override
Definition NoFolder.h:93
Value * FoldGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, GEPNoWrapFlags NW) const override
Definition NoFolder.h:78
Value * FoldBinOpFMF(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, FastMathFlags FMF) const override
Definition NoFolder.h:64
Value * FoldCast(Instruction::CastOps Op, Value *V, Type *DestTy) const override
Definition NoFolder.h:112
Value * FoldNoWrapBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, bool HasNUW, bool HasNSW) const override
Definition NoFolder.h:59
Instruction * CreatePointerBitCastOrAddrSpaceCast(Constant *C, Type *DestTy) const override
Definition NoFolder.h:130
Value * FoldExtractElement(Value *Vec, Value *Idx) const override
Definition NoFolder.h:98
Value * FoldCmp(CmpInst::Predicate P, Value *LHS, Value *RHS) const override
Definition NoFolder.h:74
Instruction * CreatePointerCast(Constant *C, Type *DestTy) const override
Definition NoFolder.h:126
Value * FoldInsertElement(Value *Vec, Value *NewElt, Value *Idx) const override
Definition NoFolder.h:102
Value * FoldExtractValue(Value *Agg, ArrayRef< unsigned > IdxList) const override
Definition NoFolder.h:88
Value * FoldSelect(Value *C, Value *True, Value *False, FastMathFlags FMF) const override
Definition NoFolder.h:83
NoFolder()=default
Value * FoldUnOpFMF(Instruction::UnaryOps Opc, Value *V, FastMathFlags FMF) const override
Definition NoFolder.h:69
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
DWARFExpression::Operation Op