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 memcmp/bcmp, in cases where that is
126 /// faster than a libcall. The first returned SDValue is the result of the
127 /// memcmp 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 Op1, SDValue Op2, SDValue Op3,
132 const CallInst *CI) const {
133 return std::make_pair(SDValue(), SDValue());
134 }
135
136 /// Emit target-specific code that performs a memchr, in cases where that is
137 /// faster than a libcall. The first returned SDValue is the result of the
138 /// memchr 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 Src, SDValue Char, SDValue Length,
143 MachinePointerInfo SrcPtrInfo) const {
144 return std::make_pair(SDValue(), SDValue());
145 }
146
147 /// Emit target-specific code that performs a strcpy or stpcpy, in cases
148 /// where that is faster than a libcall.
149 /// The first returned SDValue is the result of the copy (the start
150 /// of the destination string for strcpy, a pointer to the null terminator
151 /// for stpcpy) and the second is the chain. Both SDValues can be null
152 /// if a normal libcall should be used.
153 virtual std::pair<SDValue, SDValue> EmitTargetCodeForStrcpy(
154 SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Dest,
155 SDValue Src, MachinePointerInfo DestPtrInfo,
156 MachinePointerInfo SrcPtrInfo, bool isStpcpy, const CallInst *CI) const {
157 return std::make_pair(SDValue(), SDValue());
158 }
159
160 /// Emit target-specific code that performs a strcmp, in cases where that is
161 /// faster than a libcall.
162 /// The first returned SDValue is the result of the strcmp and the second is
163 /// the chain. Both SDValues can be null if a normal libcall should be used.
164 virtual std::pair<SDValue, SDValue>
166 SDValue Op1, SDValue Op2,
167 MachinePointerInfo Op1PtrInfo,
168 MachinePointerInfo Op2PtrInfo) const {
169 return std::make_pair(SDValue(), SDValue());
170 }
171
172 virtual std::pair<SDValue, SDValue>
174 SDValue Src, const CallInst *CI) const {
175 return std::make_pair(SDValue(), SDValue());
176 }
177
178 virtual std::pair<SDValue, SDValue>
180 SDValue Src, SDValue MaxLength,
181 MachinePointerInfo SrcPtrInfo) const {
182 return std::make_pair(SDValue(), SDValue());
183 }
184
186 SDValue Chain, SDValue Addr,
188 MachinePointerInfo DstPtrInfo,
189 bool ZeroData) const {
190 return SDValue();
191 }
192
193 // Return true if the DAG Combiner should disable generic combines.
194 virtual bool disableGenericCombines(CodeGenOptLevel OptLevel) const {
195 return false;
196 }
197};
198
199/// Proxy class that targets should inherit from if they wish to use
200/// the generated node descriptions.
202protected:
204
207
208public:
210
211 const char *getTargetNodeName(unsigned Opcode) const override {
212 assert(GenNodeInfo.hasDesc(Opcode) &&
213 "The name should be provided by the derived class");
214 return GenNodeInfo.getName(Opcode).data();
215 }
216
217 bool isTargetMemoryOpcode(unsigned Opcode) const override {
218 if (GenNodeInfo.hasDesc(Opcode))
219 return GenNodeInfo.getDesc(Opcode).hasProperty(SDNPMemOperand);
220 return false;
221 }
222
223 bool isTargetStrictFPOpcode(unsigned Opcode) const override {
224 if (GenNodeInfo.hasDesc(Opcode))
225 return GenNodeInfo.getDesc(Opcode).hasFlag(SDNFIsStrictFP);
226 return false;
227 }
228
230 const SDNode *N) const override {
231 if (GenNodeInfo.hasDesc(N->getOpcode()))
232 GenNodeInfo.verifyNode(DAG, N);
233 }
234};
235
236} // end namespace llvm
237
238#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 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 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 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.
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,...