LLVM 23.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 strstr, in cases where that is
116 /// faster than a libcall. The first returned SDValue is the result of the
117 /// strstr 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, const CallInst *CI) const {
122 return std::make_pair(SDValue(), SDValue());
123 }
124
125 /// Emit target-specific code that performs a memccpy, in cases where that is
126 /// faster than a libcall. The first returned SDValue is the result of the
127 /// memccpy and the second is the chain. Both SDValues can be null if a normal
128 /// libcall should be used.
129 virtual std::pair<SDValue, SDValue>
131 SDValue Dst, SDValue Src, SDValue C, SDValue Size,
132 const CallInst *CI) const {
133 return std::make_pair(SDValue(), SDValue());
134 }
135
136 /// Emit target-specific code that performs a memcmp/bcmp, in cases where that is
137 /// faster than a libcall. The first returned SDValue is the result of the
138 /// memcmp and the second is the chain. Both SDValues can be null if a normal
139 /// libcall should be used.
140 virtual std::pair<SDValue, SDValue>
142 SDValue Op1, SDValue Op2, SDValue Op3,
143 const CallInst *CI) const {
144 return std::make_pair(SDValue(), SDValue());
145 }
146
147 /// Emit target-specific code that performs a memchr, in cases where that is
148 /// faster than a libcall. The first returned SDValue is the result of the
149 /// memchr and the second is the chain. Both SDValues can be null if a normal
150 /// libcall should be used.
151 virtual std::pair<SDValue, SDValue>
153 SDValue Src, SDValue Char, SDValue Length,
154 MachinePointerInfo SrcPtrInfo) const {
155 return std::make_pair(SDValue(), SDValue());
156 }
157
158 /// Emit target-specific code that performs a strcpy or stpcpy, in cases
159 /// where that is faster than a libcall.
160 /// The first returned SDValue is the result of the copy (the start
161 /// of the destination string for strcpy, a pointer to the null terminator
162 /// for stpcpy) and the second is the chain. Both SDValues can be null
163 /// if a normal libcall should be used.
164 virtual std::pair<SDValue, SDValue> EmitTargetCodeForStrcpy(
165 SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Dest,
166 SDValue Src, MachinePointerInfo DestPtrInfo,
167 MachinePointerInfo SrcPtrInfo, bool isStpcpy, const CallInst *CI) const {
168 return std::make_pair(SDValue(), SDValue());
169 }
170
171 /// Emit target-specific code that performs a strcmp, in cases where that is
172 /// faster than a libcall.
173 /// The first returned SDValue is the result of the strcmp and the second is
174 /// the chain. Both SDValues can be null if a normal libcall should be used.
175 virtual std::pair<SDValue, SDValue> EmitTargetCodeForStrcmp(
176 SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1,
177 SDValue Op2, MachinePointerInfo Op1PtrInfo, MachinePointerInfo Op2PtrInfo,
178 const CallInst *CI) const {
179 return std::make_pair(SDValue(), SDValue());
180 }
181
182 virtual std::pair<SDValue, SDValue>
184 SDValue Src, const CallInst *CI) const {
185 return std::make_pair(SDValue(), SDValue());
186 }
187
188 virtual std::pair<SDValue, SDValue>
190 SDValue Src, SDValue MaxLength,
191 MachinePointerInfo SrcPtrInfo) const {
192 return std::make_pair(SDValue(), SDValue());
193 }
194
196 SDValue Chain, SDValue Addr,
198 MachinePointerInfo DstPtrInfo,
199 bool ZeroData) const {
200 return SDValue();
201 }
202
203 // Return true if the DAG Combiner should disable generic combines.
204 virtual bool disableGenericCombines(CodeGenOptLevel OptLevel) const {
205 return false;
206 }
207};
208
209/// Proxy class that targets should inherit from if they wish to use
210/// the generated node descriptions.
212protected:
214
217
218public:
220
221 const char *getTargetNodeName(unsigned Opcode) const override {
222 assert(GenNodeInfo.hasDesc(Opcode) &&
223 "The name should be provided by the derived class");
224 return GenNodeInfo.getName(Opcode).data();
225 }
226
227 bool isTargetMemoryOpcode(unsigned Opcode) const override {
228 if (GenNodeInfo.hasDesc(Opcode))
229 return GenNodeInfo.getDesc(Opcode).hasProperty(SDNPMemOperand);
230 return false;
231 }
232
233 bool isTargetStrictFPOpcode(unsigned Opcode) const override {
234 if (GenNodeInfo.hasDesc(Opcode))
235 return GenNodeInfo.getDesc(Opcode).hasFlag(SDNFIsStrictFP);
236 return false;
237 }
238
240 const SDNode *N) const override {
241 if (GenNodeInfo.hasDesc(N->getOpcode()))
242 GenNodeInfo.verifyNode(DAG, N);
243 }
244};
245
246} // end namespace llvm
247
248#endif // LLVM_CODEGEN_SELECTIONDAGTARGETINFO_H
return SDValue()
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
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 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 std::pair< SDValue, SDValue > EmitTargetCodeForStrlen(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Src, const CallInst *CI) 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 > 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 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 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...
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
@ Length
Definition DWP.cpp:532
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,...