LLVM 22.0.0git
SelectionDAGTargetInfo.h
Go to the documentation of this file.
1//==- llvm/CodeGen/SelectionDAGTargetInfo.h - SelectionDAG Info --*- 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 declares the SelectionDAGTargetInfo class, which targets can
10// subclass to parameterize the SelectionDAG lowering and instruction
11// selection process.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CODEGEN_SELECTIONDAGTARGETINFO_H
16#define LLVM_CODEGEN_SELECTIONDAGTARGETINFO_H
17
22#include <utility>
23
24namespace llvm {
25
26class CallInst;
27class SelectionDAG;
28
29//===----------------------------------------------------------------------===//
30/// Targets can subclass this to parameterize the
31/// SelectionDAG lowering and instruction selection process.
32///
34public:
35 explicit SelectionDAGTargetInfo() = default;
39
40 /// Returns the name of the given target-specific opcode, suitable for
41 /// debug printing.
42 virtual const char *getTargetNodeName(unsigned Opcode) const {
43 return nullptr;
44 }
45
46 /// Returns true if a node with the given target-specific opcode has
47 /// a memory operand. Nodes with such opcodes can only be created with
48 /// `SelectionDAG::getMemIntrinsicNode`.
49 virtual bool isTargetMemoryOpcode(unsigned Opcode) const { return false; }
50
51 /// Returns true if a node with the given target-specific opcode has
52 /// strict floating-point semantics.
53 virtual bool isTargetStrictFPOpcode(unsigned Opcode) const { return false; }
54
55 /// Returns true if a node with the given target-specific opcode
56 /// may raise a floating-point exception.
57 virtual bool mayRaiseFPException(unsigned Opcode) const;
58
59 /// Checks that the given target-specific node is valid. Aborts if it is not.
60 virtual void verifyTargetNode(const SelectionDAG &DAG,
61 const SDNode *N) const {}
62
63 /// Emit target-specific code that performs a memcpy.
64 /// This can be used by targets to provide code sequences for cases
65 /// that don't fit the target's parameters for simple loads/stores and can be
66 /// more efficient than using a library call. This function can return a null
67 /// SDValue if the target declines to use custom code and a different
68 /// lowering strategy should be used.
69 ///
70 /// If AlwaysInline is true, the size is constant and the target should not
71 /// emit any calls and is strongly encouraged to attempt to emit inline code
72 /// even if it is beyond the usual threshold because this intrinsic is being
73 /// expanded in a place where calls are not feasible (e.g. within the prologue
74 /// for another call). If the target chooses to decline an AlwaysInline
75 /// request here, legalize will resort to using simple loads and stores.
77 SDValue Chain, SDValue Op1,
78 SDValue Op2, SDValue Op3,
79 Align Alignment, bool isVolatile,
80 bool AlwaysInline,
81 MachinePointerInfo DstPtrInfo,
82 MachinePointerInfo SrcPtrInfo) const {
83 return SDValue();
84 }
85
86 /// Emit target-specific code that performs a memmove.
87 /// This can be used by targets to provide code sequences for cases
88 /// that don't fit the target's parameters for simple loads/stores and can be
89 /// more efficient than using a library call. This function can return a null
90 /// SDValue if the target declines to use custom code and a different
91 /// lowering strategy should be used.
93 SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1,
94 SDValue Op2, SDValue Op3, Align Alignment, bool isVolatile,
95 MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {
96 return SDValue();
97 }
98
99 /// Emit target-specific code that performs a memset.
100 /// This can be used by targets to provide code sequences for cases
101 /// that don't fit the target's parameters for simple stores and can be more
102 /// efficient than using a library call. This function can return a null
103 /// SDValue if the target declines to use custom code and a different
104 /// lowering strategy should be used. Note that if AlwaysInline is true the
105 /// function has to return a valid SDValue.
107 SDValue Chain, SDValue Op1,
108 SDValue Op2, SDValue Op3,
109 Align Alignment, bool isVolatile,
110 bool AlwaysInline,
111 MachinePointerInfo DstPtrInfo) const {
112 return SDValue();
113 }
114
115 /// Emit target-specific code that performs a memcmp/bcmp, in cases where that is
116 /// faster than a libcall. The first returned SDValue is the result of the
117 /// memcmp and the second is the chain. Both SDValues can be null if a normal
118 /// libcall should be used.
119 virtual std::pair<SDValue, SDValue>
121 SDValue Op1, SDValue Op2, SDValue Op3,
122 const CallInst *CI) const {
123 return std::make_pair(SDValue(), SDValue());
124 }
125
126 /// Emit target-specific code that performs a memchr, in cases where that is
127 /// faster than a libcall. The first returned SDValue is the result of the
128 /// memchr and the second is the chain. Both SDValues can be null if a normal
129 /// libcall should be used.
130 virtual std::pair<SDValue, SDValue>
132 SDValue Src, SDValue Char, SDValue Length,
133 MachinePointerInfo SrcPtrInfo) const {
134 return std::make_pair(SDValue(), SDValue());
135 }
136
137 /// Emit target-specific code that performs a strcpy or stpcpy, in cases
138 /// where that is faster than a libcall.
139 /// The first returned SDValue is the result of the copy (the start
140 /// of the destination string for strcpy, a pointer to the null terminator
141 /// for stpcpy) and the second is the chain. Both SDValues can be null
142 /// if a normal libcall should be used.
143 virtual std::pair<SDValue, SDValue>
145 SDValue Dest, SDValue Src,
146 MachinePointerInfo DestPtrInfo,
147 MachinePointerInfo SrcPtrInfo, bool isStpcpy) const {
148 return std::make_pair(SDValue(), SDValue());
149 }
150
151 /// Emit target-specific code that performs a strcmp, in cases where that is
152 /// faster than a libcall.
153 /// The first returned SDValue is the result of the strcmp and the second is
154 /// the chain. Both SDValues can be null if a normal libcall should be used.
155 virtual std::pair<SDValue, SDValue>
157 SDValue Op1, SDValue Op2,
158 MachinePointerInfo Op1PtrInfo,
159 MachinePointerInfo Op2PtrInfo) const {
160 return std::make_pair(SDValue(), SDValue());
161 }
162
163 virtual std::pair<SDValue, SDValue>
165 SDValue Src, MachinePointerInfo SrcPtrInfo) const {
166 return std::make_pair(SDValue(), SDValue());
167 }
168
169 virtual std::pair<SDValue, SDValue>
171 SDValue Src, SDValue MaxLength,
172 MachinePointerInfo SrcPtrInfo) const {
173 return std::make_pair(SDValue(), SDValue());
174 }
175
177 SDValue Chain, SDValue Addr,
179 MachinePointerInfo DstPtrInfo,
180 bool ZeroData) const {
181 return SDValue();
182 }
183
184 // Return true if the DAG Combiner should disable generic combines.
185 virtual bool disableGenericCombines(CodeGenOptLevel OptLevel) const {
186 return false;
187 }
188};
189
190/// Proxy class that targets should inherit from if they wish to use
191/// the generated node descriptions.
193protected:
195
198
199public:
201
202 const char *getTargetNodeName(unsigned Opcode) const override {
203 assert(GenNodeInfo.hasDesc(Opcode) &&
204 "The name should be provided by the derived class");
205 return GenNodeInfo.getName(Opcode).data();
206 }
207
208 bool isTargetMemoryOpcode(unsigned Opcode) const override {
209 if (GenNodeInfo.hasDesc(Opcode))
211 return false;
212 }
213
214 bool isTargetStrictFPOpcode(unsigned Opcode) const override {
215 if (GenNodeInfo.hasDesc(Opcode))
217 return false;
218 }
219
221 const SDNode *N) const override {
222 if (GenNodeInfo.hasDesc(N->getOpcode()))
224 }
225};
226
227} // end namespace llvm
228
229#endif // LLVM_CODEGEN_SELECTIONDAGTARGETINFO_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
uint64_t Addr
uint64_t Size
This class represents a function call, abstracting a target machine's calling convention.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
const SDNodeDesc & getDesc(unsigned Opcode) const
Returns the description of a node with the given opcode.
Definition: SDNodeInfo.h:95
void verifyNode(const SelectionDAG &DAG, const SDNode *N) const
Definition: SDNodeInfo.cpp:43
StringRef getName(unsigned Opcode) const
Returns the name of the given target-specific opcode, suitable for debug printing.
Definition: SDNodeInfo.h:108
bool hasDesc(unsigned Opcode) const
Returns true if there is a generated description for a node with the given target-specific opcode.
Definition: SDNodeInfo.h:89
Represents one node in the SelectionDAG.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
Proxy class that targets should inherit from if they wish to use the generated node descriptions.
const char * getTargetNodeName(unsigned Opcode) const override
Returns the name of the given target-specific opcode, suitable for debug printing.
bool isTargetStrictFPOpcode(unsigned Opcode) const override
Returns true if a node with the given target-specific opcode has strict floating-point semantics.
SelectionDAGGenTargetInfo(const SDNodeInfo &GenNodeInfo)
bool isTargetMemoryOpcode(unsigned Opcode) const override
Returns true if a node with the given target-specific opcode has a memory operand.
void verifyTargetNode(const SelectionDAG &DAG, const SDNode *N) const override
Checks that the given target-specific node is valid. Aborts if it is not.
Targets can subclass this to parameterize the SelectionDAG lowering and instruction selection process...
virtual bool isTargetStrictFPOpcode(unsigned Opcode) const
Returns true if a node with the given target-specific opcode has strict floating-point semantics.
virtual bool mayRaiseFPException(unsigned Opcode) const
Returns true if a node with the given target-specific opcode may raise a floating-point exception.
virtual bool isTargetMemoryOpcode(unsigned Opcode) const
Returns true if a node with the given target-specific opcode has a memory operand.
virtual void verifyTargetNode(const SelectionDAG &DAG, const SDNode *N) const
Checks that the given target-specific node is valid. Aborts if it is not.
virtual SDValue EmitTargetCodeForMemset(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1, SDValue Op2, SDValue Op3, Align Alignment, bool isVolatile, bool AlwaysInline, MachinePointerInfo DstPtrInfo) const
Emit target-specific code that performs a memset.
virtual std::pair< SDValue, SDValue > EmitTargetCodeForStrnlen(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Src, SDValue MaxLength, MachinePointerInfo SrcPtrInfo) const
virtual SDValue EmitTargetCodeForMemmove(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1, SDValue Op2, SDValue Op3, Align Alignment, bool isVolatile, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const
Emit target-specific code that performs a memmove.
virtual std::pair< SDValue, SDValue > EmitTargetCodeForStrcpy(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Dest, SDValue Src, MachinePointerInfo DestPtrInfo, MachinePointerInfo SrcPtrInfo, bool isStpcpy) const
Emit target-specific code that performs a strcpy or stpcpy, in cases where that is faster than a libc...
virtual SDValue EmitTargetCodeForMemcpy(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1, SDValue Op2, SDValue Op3, Align Alignment, bool isVolatile, bool AlwaysInline, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const
Emit target-specific code that performs a memcpy.
virtual std::pair< SDValue, SDValue > EmitTargetCodeForMemchr(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Src, SDValue Char, SDValue Length, MachinePointerInfo SrcPtrInfo) const
Emit target-specific code that performs a memchr, in cases where that is faster than a libcall.
virtual const char * getTargetNodeName(unsigned Opcode) const
Returns the name of the given target-specific opcode, suitable for debug printing.
SelectionDAGTargetInfo & operator=(const SelectionDAGTargetInfo &)=delete
virtual std::pair< SDValue, SDValue > EmitTargetCodeForMemcmp(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1, SDValue Op2, SDValue Op3, const CallInst *CI) const
Emit target-specific code that performs a memcmp/bcmp, in cases where that is faster than a libcall.
virtual std::pair< SDValue, SDValue > EmitTargetCodeForStrcmp(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1, SDValue Op2, MachinePointerInfo Op1PtrInfo, MachinePointerInfo Op2PtrInfo) const
Emit target-specific code that performs a strcmp, in cases where that is faster than a libcall.
virtual bool disableGenericCombines(CodeGenOptLevel OptLevel) const
SelectionDAGTargetInfo(const SelectionDAGTargetInfo &)=delete
virtual std::pair< SDValue, SDValue > EmitTargetCodeForStrlen(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Src, MachinePointerInfo SrcPtrInfo) const
virtual SDValue EmitTargetCodeForSetTag(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Addr, SDValue Size, MachinePointerInfo DstPtrInfo, bool ZeroData) const
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:229
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:148
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Length
Definition: DWP.cpp:477
CodeGenOptLevel
Code generation optimization level.
Definition: CodeGen.h:82
@ SDNPMemOperand
Definition: SDNodeInfo.h:27
@ SDNFIsStrictFP
Definition: SDNodeInfo.h:48
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
This class contains a discriminated union of information about pointers in memory operands,...
bool hasProperty(SDNP Property) const
Definition: SDNodeInfo.h:70
bool hasFlag(SDNF Flag) const
Definition: SDNodeInfo.h:72