LLVM 20.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"
31
32namespace llvm {
33
34/// NoFolder - Create "constants" (actually, instructions) with no folding.
35class NoFolder final : public IRBuilderFolder {
36 virtual void anchor();
37
38public:
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 GEPNoWrapFlags NW) 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
111 Type *DestTy) const override {
112 return nullptr;
113 }
114
116 Instruction *FMFSource) const override {
117 return nullptr;
118 }
119
120 //===--------------------------------------------------------------------===//
121 // Cast/Conversion Operators
122 //===--------------------------------------------------------------------===//
123
124 Instruction *CreatePointerCast(Constant *C, Type *DestTy) const override {
125 return CastInst::CreatePointerCast(C, DestTy);
126 }
127
129 Constant *C, Type *DestTy) const override {
131 }
132};
133
134} // end namespace llvm
135
136#endif // LLVM_IR_NOFOLDER_H
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
#define P(N)
Value * RHS
Value * LHS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
static CastInst * CreatePointerBitCastOrAddrSpaceCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a BitCast or an AddrSpaceCast cast instruction.
static 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:757
This is an important base class in LLVM.
Definition: Constant.h:42
This class represents an Operation in the Expression.
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:20
Represents flags for the getelementptr instruction/expression.
IRBuilderFolder - Interface for constant folding in IRBuilder.
NoFolder - Create "constants" (actually, instructions) with no folding.
Definition: NoFolder.h:35
Value * FoldShuffleVector(Value *V1, Value *V2, ArrayRef< int > Mask) const override
Definition: NoFolder.h:105
Value * FoldExactBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, bool IsExact) const override
Definition: NoFolder.h:53
Value * FoldSelect(Value *C, Value *True, Value *False) const override
Definition: NoFolder.h:82
Value * FoldBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS) const override
Definition: NoFolder.h:48
Value * FoldInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > IdxList) const override
Definition: NoFolder.h:91
Value * FoldGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, GEPNoWrapFlags NW) const override
Definition: NoFolder.h:77
Value * FoldBinOpFMF(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, FastMathFlags FMF) const override
Definition: NoFolder.h:63
Value * FoldCast(Instruction::CastOps Op, Value *V, Type *DestTy) const override
Definition: NoFolder.h:110
Value * FoldNoWrapBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, bool HasNUW, bool HasNSW) const override
Definition: NoFolder.h:58
Instruction * CreatePointerBitCastOrAddrSpaceCast(Constant *C, Type *DestTy) const override
Definition: NoFolder.h:128
Value * FoldExtractElement(Value *Vec, Value *Idx) const override
Definition: NoFolder.h:96
Value * FoldCmp(CmpInst::Predicate P, Value *LHS, Value *RHS) const override
Definition: NoFolder.h:73
Instruction * CreatePointerCast(Constant *C, Type *DestTy) const override
Definition: NoFolder.h:124
Value * FoldInsertElement(Value *Vec, Value *NewElt, Value *Idx) const override
Definition: NoFolder.h:100
Value * FoldBinaryIntrinsic(Intrinsic::ID ID, Value *LHS, Value *RHS, Type *Ty, Instruction *FMFSource) const override
Definition: NoFolder.h:115
Value * FoldExtractValue(Value *Agg, ArrayRef< unsigned > IdxList) const override
Definition: NoFolder.h:86
NoFolder()=default
Value * FoldUnOpFMF(Instruction::UnaryOps Opc, Value *V, FastMathFlags FMF) const override
Definition: NoFolder.h:68
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18