LLVM 24.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.
76 ///
77 /// IsTailCall is in/out: on entry, whether an emitted call may be a tail
78 /// call; on exit, whether one was emitted.
79 virtual SDValue
81 SDValue Op1, SDValue Op2, SDValue Op3, Align DstAlign,
82 Align SrcAlign, bool isVolatile, bool AlwaysInline,
83 bool &IsTailCall, MachinePointerInfo DstPtrInfo,
84 MachinePointerInfo SrcPtrInfo) const {
85 IsTailCall = false;
86 return SDValue();
87 }
88
89 /// Emit target-specific code that performs a memmove.
90 /// This can be used by targets to provide code sequences for cases
91 /// that don't fit the target's parameters for simple loads/stores and can be
92 /// more efficient than using a library call. This function can return a null
93 /// SDValue if the target declines to use custom code and a different
94 /// lowering strategy should be used.
95 ///
96 /// IsTailCall is in/out: on entry, whether an emitted call may be a tail
97 /// call; on exit, whether one was emitted.
98 virtual SDValue
100 SDValue Op1, SDValue Op2, SDValue Op3,
101 Align DstAlign, Align SrcAlign, bool isVolatile,
102 bool &IsTailCall, MachinePointerInfo DstPtrInfo,
103 MachinePointerInfo SrcPtrInfo) const {
104 IsTailCall = false;
105 return SDValue();
106 }
107
108 /// Emit target-specific code that performs a memset.
109 /// This can be used by targets to provide code sequences for cases
110 /// that don't fit the target's parameters for simple stores and can be more
111 /// efficient than using a library call. This function can return a null
112 /// SDValue if the target declines to use custom code and a different
113 /// lowering strategy should be used. Note that if AlwaysInline is true the
114 /// function has to return a valid SDValue.
115 ///
116 /// IsTailCall is in/out: on entry, whether an emitted call may be a tail
117 /// call; on exit, whether one was emitted.
119 SDValue Chain, SDValue Op1,
120 SDValue Op2, SDValue Op3,
121 Align Alignment, bool isVolatile,
122 bool AlwaysInline, bool &IsTailCall,
123 MachinePointerInfo DstPtrInfo) const {
124 IsTailCall = false;
125 return SDValue();
126 }
127
128 /// Emit target-specific code that performs a strstr, in cases where that is
129 /// faster than a libcall. The first returned SDValue is the result of the
130 /// strstr and the second is the chain. Both SDValues can be null if a normal
131 /// libcall should be used.
132 virtual std::pair<SDValue, SDValue>
134 SDValue Op1, SDValue Op2, const CallInst *CI) const {
135 return std::make_pair(SDValue(), SDValue());
136 }
137
138 /// Emit target-specific code that performs a memccpy, in cases where that is
139 /// faster than a libcall. The first returned SDValue is the result of the
140 /// memccpy and the second is the chain. Both SDValues can be null if a normal
141 /// libcall should be used.
142 virtual std::pair<SDValue, SDValue>
144 SDValue Dst, SDValue Src, SDValue C, SDValue Size,
145 const CallInst *CI) const {
146 return std::make_pair(SDValue(), SDValue());
147 }
148
149 /// Emit target-specific code that performs a memcmp/bcmp, in cases where that is
150 /// faster than a libcall. The first returned SDValue is the result of the
151 /// memcmp and the second is the chain. Both SDValues can be null if a normal
152 /// libcall should be used.
153 virtual std::pair<SDValue, SDValue>
155 SDValue Op1, SDValue Op2, SDValue Op3,
156 const CallInst *CI) const {
157 return std::make_pair(SDValue(), SDValue());
158 }
159
160 /// Emit target-specific code that performs a memchr, in cases where that is
161 /// faster than a libcall. The first returned SDValue is the result of the
162 /// memchr and the second is the chain. Both SDValues can be null if a normal
163 /// libcall should be used.
164 virtual std::pair<SDValue, SDValue>
166 SDValue Src, SDValue Char, SDValue Length,
167 MachinePointerInfo SrcPtrInfo) const {
168 return std::make_pair(SDValue(), SDValue());
169 }
170
171 /// Emit target-specific code that performs a strcpy or stpcpy, in cases
172 /// where that is faster than a libcall.
173 /// The first returned SDValue is the result of the copy (the start
174 /// of the destination string for strcpy, a pointer to the null terminator
175 /// for stpcpy) and the second is the chain. Both SDValues can be null
176 /// if a normal libcall should be used.
177 virtual std::pair<SDValue, SDValue> EmitTargetCodeForStrcpy(
178 SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Dest,
179 SDValue Src, MachinePointerInfo DestPtrInfo,
180 MachinePointerInfo SrcPtrInfo, bool isStpcpy, const CallInst *CI) const {
181 return std::make_pair(SDValue(), SDValue());
182 }
183
184 /// Emit target-specific code that performs a strcmp, in cases where that is
185 /// faster than a libcall.
186 /// The first returned SDValue is the result of the strcmp and the second is
187 /// the chain. Both SDValues can be null if a normal libcall should be used.
188 virtual std::pair<SDValue, SDValue> EmitTargetCodeForStrcmp(
189 SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1,
190 SDValue Op2, MachinePointerInfo Op1PtrInfo, MachinePointerInfo Op2PtrInfo,
191 const CallInst *CI) const {
192 return std::make_pair(SDValue(), SDValue());
193 }
194
195 virtual std::pair<SDValue, SDValue>
197 SDValue Src, const CallInst *CI) const {
198 return std::make_pair(SDValue(), SDValue());
199 }
200
201 virtual std::pair<SDValue, SDValue>
203 SDValue Src, SDValue MaxLength,
204 MachinePointerInfo SrcPtrInfo) const {
205 return std::make_pair(SDValue(), SDValue());
206 }
207
209 SDValue Chain, SDValue Addr,
211 MachinePointerInfo DstPtrInfo,
212 bool ZeroData) const {
213 return SDValue();
214 }
215
216 // Return true if the DAG Combiner should disable generic combines.
217 virtual bool disableGenericCombines(CodeGenOptLevel OptLevel) const {
218 return false;
219 }
220};
221
222/// Proxy class that targets should inherit from if they wish to use
223/// the generated node descriptions.
225protected:
227
230
231public:
233
234 const char *getTargetNodeName(unsigned Opcode) const override {
235 assert(GenNodeInfo.hasDesc(Opcode) &&
236 "The name should be provided by the derived class");
237 return GenNodeInfo.getName(Opcode).data();
238 }
239
240 bool isTargetMemoryOpcode(unsigned Opcode) const override {
241 if (GenNodeInfo.hasDesc(Opcode))
242 return GenNodeInfo.getDesc(Opcode).hasProperty(SDNPMemOperand);
243 return false;
244 }
245
246 bool isTargetStrictFPOpcode(unsigned Opcode) const override {
247 if (GenNodeInfo.hasDesc(Opcode))
248 return GenNodeInfo.getDesc(Opcode).hasFlag(SDNFIsStrictFP);
249 return false;
250 }
251
253 const SDNode *N) const override {
254 if (GenNodeInfo.hasDesc(N->getOpcode()))
255 GenNodeInfo.verifyNode(DAG, N);
256 }
257};
258
259} // end namespace llvm
260
261#endif // LLVM_CODEGEN_SELECTIONDAGTARGETINFO_H
return SDValue()
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define LLVM_ABI
Definition Compiler.h:211
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...
Represents one node in the SelectionDAG.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
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.
virtual std::pair< SDValue, SDValue > EmitTargetCodeForMemccpy(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src, SDValue C, SDValue Size, const CallInst *CI) const
Emit target-specific code that performs a memccpy, in cases where that is faster than a libcall.
virtual bool isTargetStrictFPOpcode(unsigned Opcode) const
Returns true if a node with the given target-specific opcode has strict floating-point semantics.
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 std::pair< SDValue, SDValue > EmitTargetCodeForStrnlen(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Src, SDValue MaxLength, MachinePointerInfo SrcPtrInfo) const
virtual std::pair< SDValue, SDValue > EmitTargetCodeForStrlen(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Src, const CallInst *CI) const
virtual SDValue EmitTargetCodeForMemset(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1, SDValue Op2, SDValue Op3, Align Alignment, bool isVolatile, bool AlwaysInline, bool &IsTailCall, MachinePointerInfo DstPtrInfo) const
Emit target-specific code that performs a memset.
virtual std::pair< SDValue, SDValue > EmitTargetCodeForStrstr(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1, SDValue Op2, const CallInst *CI) const
Emit target-specific code that performs a strstr, in cases where that is faster than a libcall.
virtual SDValue EmitTargetCodeForMemcpy(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1, SDValue Op2, SDValue Op3, Align DstAlign, Align SrcAlign, bool isVolatile, bool AlwaysInline, bool &IsTailCall, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const
Emit target-specific code that performs a memcpy.
virtual SDValue EmitTargetCodeForMemmove(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1, SDValue Op2, SDValue Op3, Align DstAlign, Align SrcAlign, bool isVolatile, bool &IsTailCall, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const
Emit target-specific code that performs a memmove.
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 std::pair< SDValue, SDValue > EmitTargetCodeForStrcmp(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1, SDValue Op2, MachinePointerInfo Op1PtrInfo, MachinePointerInfo Op2PtrInfo, const CallInst *CI) const
Emit target-specific code that performs a strcmp, 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 bool disableGenericCombines(CodeGenOptLevel OptLevel) const
SelectionDAGTargetInfo(const SelectionDAGTargetInfo &)=delete
virtual SDValue EmitTargetCodeForSetTag(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Addr, SDValue Size, MachinePointerInfo DstPtrInfo, bool ZeroData) const
virtual std::pair< SDValue, SDValue > EmitTargetCodeForStrcpy(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Dest, SDValue Src, MachinePointerInfo DestPtrInfo, MachinePointerInfo SrcPtrInfo, bool isStpcpy, const CallInst *CI) const
Emit target-specific code that performs a strcpy or stpcpy, in cases where that is faster than a libc...
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
This is an optimization pass for GlobalISel generic memory operations.
@ Length
Definition DWP.cpp:577
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:280
@ 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,...