LLVM 24.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.
28
29public:
30 virtual ~IRBuilderFolder() = default;
31
32 //===--------------------------------------------------------------------===//
33 // Value-based folders.
34 //
35 // Return an existing value or a constant if the operation can be simplified.
36 // Otherwise return nullptr.
37 //===--------------------------------------------------------------------===//
38
40 Value *RHS) const = 0;
41
43 Value *RHS, bool IsExact) const = 0;
44
46 Value *RHS, bool HasNUW,
47 bool HasNSW) const = 0;
48
50 Value *RHS, FastMathFlags FMF) const = 0;
51
53 FastMathFlags FMF) const = 0;
54
56 Value *RHS) const = 0;
57
58 virtual Value *FoldGEP(const DataLayout &DL, Type *Ty, Value *Ptr,
59 ArrayRef<Value *> IdxList,
60 GEPNoWrapFlags NW) const = 0;
61
63 FastMathFlags FMF = FastMathFlags()) const = 0;
64
66 ArrayRef<unsigned> IdxList) const = 0;
67
68 virtual Value *FoldInsertValue(Value *Agg, Value *Val,
69 ArrayRef<unsigned> IdxList) const = 0;
70
71 virtual Value *FoldExtractElement(Value *Vec, Value *Idx) const = 0;
72
73 virtual Value *FoldInsertElement(Value *Vec, Value *NewElt,
74 Value *Idx) const = 0;
75
77 ArrayRef<int> Mask) const = 0;
78
80 Type *DestTy) const = 0;
81
83 Type *Ty, FastMathFlags FMF = {},
84 Function *CtxF = nullptr) const = 0;
85
87 Value *Offset) const = 0;
88
89 virtual Value *FoldBitExtract(Type *Ty, Value *Src, Value *Offset) const = 0;
90
91 //===--------------------------------------------------------------------===//
92 // Cast/Conversion Operators
93 //===--------------------------------------------------------------------===//
94
95 virtual Value *CreatePointerCast(Constant *C, Type *DestTy) const = 0;
97 Type *DestTy) const = 0;
98};
99
100} // end namespace llvm
101
102#endif // LLVM_IR_IRBUILDERFOLDER_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#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:785
#define LLVM_ABI
Definition Compiler.h:215
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#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
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
This is an important base class in LLVM.
Definition Constant.h:43
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
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.
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 * FoldBitInsert(Value *Base, Value *Val, Value *Offset) const =0
virtual ~IRBuilderFolder()=default
virtual Value * FoldSelect(Value *C, Value *True, Value *False, FastMathFlags FMF=FastMathFlags()) const =0
virtual Value * FoldIntrinsic(Intrinsic::ID ID, ArrayRef< Value * > Ops, Type *Ty, FastMathFlags FMF={}, Function *CtxF=nullptr) const =0
virtual Value * FoldShuffleVector(Value *V1, Value *V2, ArrayRef< int > Mask) const =0
virtual Value * CreatePointerBitCastOrAddrSpaceCast(Constant *C, Type *DestTy) const =0
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 * FoldExtractElement(Value *Vec, Value *Idx) const =0
virtual Value * FoldBitExtract(Type *Ty, Value *Src, Value *Offset) const =0
virtual Value * FoldExactBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, bool IsExact) const =0
virtual Value * FoldGEP(const DataLayout &DL, 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:46
LLVM Value Representation.
Definition Value.h:75
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
DWARFExpression::Operation Op