LLVM 22.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"
19#include "llvm/IR/InstrTypes.h"
20#include "llvm/IR/Instruction.h"
22
23namespace llvm {
24
25/// IRBuilderFolder - Interface for constant folding in IRBuilder.
27public:
29
30 //===--------------------------------------------------------------------===//
31 // Value-based folders.
32 //
33 // Return an existing value or a constant if the operation can be simplified.
34 // Otherwise return nullptr.
35 //===--------------------------------------------------------------------===//
36
38 Value *RHS) const = 0;
39
41 Value *RHS, bool IsExact) const = 0;
42
44 Value *RHS, bool HasNUW,
45 bool HasNSW) const = 0;
46
48 Value *RHS, FastMathFlags FMF) const = 0;
49
51 FastMathFlags FMF) const = 0;
52
54 Value *RHS) const = 0;
55
56 virtual Value *FoldGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
57 GEPNoWrapFlags NW) const = 0;
58
59 virtual Value *FoldSelect(Value *C, Value *True, Value *False) const = 0;
60
62 ArrayRef<unsigned> IdxList) const = 0;
63
64 virtual Value *FoldInsertValue(Value *Agg, Value *Val,
65 ArrayRef<unsigned> IdxList) const = 0;
66
67 virtual Value *FoldExtractElement(Value *Vec, Value *Idx) const = 0;
68
69 virtual Value *FoldInsertElement(Value *Vec, Value *NewElt,
70 Value *Idx) const = 0;
71
73 ArrayRef<int> Mask) const = 0;
74
76 Type *DestTy) const = 0;
77
78 virtual Value *
80 Instruction *FMFSource = nullptr) const = 0;
81
82 //===--------------------------------------------------------------------===//
83 // Cast/Conversion Operators
84 //===--------------------------------------------------------------------===//
85
86 virtual Value *CreatePointerCast(Constant *C, Type *DestTy) const = 0;
88 Type *DestTy) const = 0;
89};
90
91} // end namespace llvm
92
93#endif // LLVM_IR_IRBUILDERFOLDER_H
#define LLVM_ABI
Definition Compiler.h:213
#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
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:678
This is an important base class in LLVM.
Definition Constant.h:43
This provides a helper for copying FMF from an instruction or setting specified flags.
Definition IRBuilder.h:93
Convenience struct for specifying and reasoning about fast-math flags.
Definition FMF.h:22
Represents flags for the getelementptr instruction/expression.
IRBuilderFolder - Interface for constant folding in IRBuilder.
virtual Value * FoldCmp(CmpInst::Predicate P, Value *LHS, Value *RHS) const =0
virtual Value * FoldUnOpFMF(Instruction::UnaryOps Opc, Value *V, FastMathFlags FMF) const =0
virtual Value * FoldBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS) const =0
virtual Value * FoldBinOpFMF(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, FastMathFlags FMF) const =0
virtual Value * FoldSelect(Value *C, Value *True, Value *False) const =0
virtual Value * FoldShuffleVector(Value *V1, Value *V2, ArrayRef< int > Mask) const =0
virtual Value * CreatePointerBitCastOrAddrSpaceCast(Constant *C, Type *DestTy) const =0
virtual ~IRBuilderFolder()
virtual Value * FoldInsertElement(Value *Vec, Value *NewElt, Value *Idx) const =0
virtual Value * CreatePointerCast(Constant *C, Type *DestTy) const =0
virtual Value * FoldCast(Instruction::CastOps Op, Value *V, Type *DestTy) const =0
virtual Value * FoldBinaryIntrinsic(Intrinsic::ID ID, Value *LHS, Value *RHS, Type *Ty, Instruction *FMFSource=nullptr) const =0
virtual Value * FoldExtractElement(Value *Vec, Value *Idx) const =0
virtual Value * FoldExactBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, bool IsExact) const =0
virtual Value * FoldGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, GEPNoWrapFlags NW) const =0
virtual Value * FoldInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > IdxList) const =0
virtual Value * FoldNoWrapBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, bool HasNUW, bool HasNSW) const =0
virtual Value * FoldExtractValue(Value *Agg, ArrayRef< unsigned > IdxList) const =0
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: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