xref: /freebsd/contrib/llvm-project/llvm/include/llvm/CodeGen/SelectionDAGTargetInfo.h (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
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 
18 #include "llvm/CodeGen/MachineMemOperand.h"
19 #include "llvm/CodeGen/SelectionDAGNodes.h"
20 #include "llvm/Support/CodeGen.h"
21 #include <utility>
22 
23 namespace llvm {
24 
25 class SelectionDAG;
26 
27 //===----------------------------------------------------------------------===//
28 /// Targets can subclass this to parameterize the
29 /// SelectionDAG lowering and instruction selection process.
30 ///
31 class SelectionDAGTargetInfo {
32 public:
33   explicit SelectionDAGTargetInfo() = default;
34   SelectionDAGTargetInfo(const SelectionDAGTargetInfo &) = delete;
35   SelectionDAGTargetInfo &operator=(const SelectionDAGTargetInfo &) = delete;
36   virtual ~SelectionDAGTargetInfo();
37 
38   /// Emit target-specific code that performs a memcpy.
39   /// This can be used by targets to provide code sequences for cases
40   /// that don't fit the target's parameters for simple loads/stores and can be
41   /// more efficient than using a library call. This function can return a null
42   /// SDValue if the target declines to use custom code and a different
43   /// lowering strategy should be used.
44   ///
45   /// If AlwaysInline is true, the size is constant and the target should not
46   /// emit any calls and is strongly encouraged to attempt to emit inline code
47   /// even if it is beyond the usual threshold because this intrinsic is being
48   /// expanded in a place where calls are not feasible (e.g. within the prologue
49   /// for another call). If the target chooses to decline an AlwaysInline
50   /// request here, legalize will resort to using simple loads and stores.
51   virtual SDValue EmitTargetCodeForMemcpy(SelectionDAG &DAG, const SDLoc &dl,
52                                           SDValue Chain, SDValue Op1,
53                                           SDValue Op2, SDValue Op3,
54                                           Align Alignment, bool isVolatile,
55                                           bool AlwaysInline,
56                                           MachinePointerInfo DstPtrInfo,
57                                           MachinePointerInfo SrcPtrInfo) const {
58     return SDValue();
59   }
60 
61   /// Emit target-specific code that performs a memmove.
62   /// This can be used by targets to provide code sequences for cases
63   /// that don't fit the target's parameters for simple loads/stores and can be
64   /// more efficient than using a library call. This function can return a null
65   /// SDValue if the target declines to use custom code and a different
66   /// lowering strategy should be used.
67   virtual SDValue EmitTargetCodeForMemmove(
68       SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1,
69       SDValue Op2, SDValue Op3, Align Alignment, bool isVolatile,
70       MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {
71     return SDValue();
72   }
73 
74   /// Emit target-specific code that performs a memset.
75   /// This can be used by targets to provide code sequences for cases
76   /// that don't fit the target's parameters for simple stores and can be more
77   /// efficient than using a library call. This function can return a null
78   /// SDValue if the target declines to use custom code and a different
79   /// lowering strategy should be used. Note that if AlwaysInline is true the
80   /// function has to return a valid SDValue.
81   virtual SDValue EmitTargetCodeForMemset(SelectionDAG &DAG, const SDLoc &dl,
82                                           SDValue Chain, SDValue Op1,
83                                           SDValue Op2, SDValue Op3,
84                                           Align Alignment, bool isVolatile,
85                                           bool AlwaysInline,
86                                           MachinePointerInfo DstPtrInfo) const {
87     return SDValue();
88   }
89 
90   /// Emit target-specific code that performs a memcmp/bcmp, in cases where that is
91   /// faster than a libcall. The first returned SDValue is the result of the
92   /// memcmp and the second is the chain. Both SDValues can be null if a normal
93   /// libcall should be used.
94   virtual std::pair<SDValue, SDValue>
95   EmitTargetCodeForMemcmp(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain,
96                           SDValue Op1, SDValue Op2, SDValue Op3,
97                           MachinePointerInfo Op1PtrInfo,
98                           MachinePointerInfo Op2PtrInfo) const {
99     return std::make_pair(SDValue(), SDValue());
100   }
101 
102   /// Emit target-specific code that performs a memchr, in cases where that is
103   /// faster than a libcall. The first returned SDValue is the result of the
104   /// memchr and the second is the chain. Both SDValues can be null if a normal
105   /// libcall should be used.
106   virtual std::pair<SDValue, SDValue>
107   EmitTargetCodeForMemchr(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain,
108                           SDValue Src, SDValue Char, SDValue Length,
109                           MachinePointerInfo SrcPtrInfo) const {
110     return std::make_pair(SDValue(), SDValue());
111   }
112 
113   /// Emit target-specific code that performs a strcpy or stpcpy, in cases
114   /// where that is faster than a libcall.
115   /// The first returned SDValue is the result of the copy (the start
116   /// of the destination string for strcpy, a pointer to the null terminator
117   /// for stpcpy) and the second is the chain.  Both SDValues can be null
118   /// if a normal libcall should be used.
119   virtual std::pair<SDValue, SDValue>
120   EmitTargetCodeForStrcpy(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain,
121                           SDValue Dest, SDValue Src,
122                           MachinePointerInfo DestPtrInfo,
123                           MachinePointerInfo SrcPtrInfo, bool isStpcpy) const {
124     return std::make_pair(SDValue(), SDValue());
125   }
126 
127   /// Emit target-specific code that performs a strcmp, in cases where that is
128   /// faster than a libcall.
129   /// The first returned SDValue is the result of the strcmp and the second is
130   /// the chain. Both SDValues can be null if a normal libcall should be used.
131   virtual std::pair<SDValue, SDValue>
132   EmitTargetCodeForStrcmp(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain,
133                           SDValue Op1, SDValue Op2,
134                           MachinePointerInfo Op1PtrInfo,
135                           MachinePointerInfo Op2PtrInfo) const {
136     return std::make_pair(SDValue(), SDValue());
137   }
138 
139   virtual std::pair<SDValue, SDValue>
140   EmitTargetCodeForStrlen(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain,
141                           SDValue Src, MachinePointerInfo SrcPtrInfo) const {
142     return std::make_pair(SDValue(), SDValue());
143   }
144 
145   virtual std::pair<SDValue, SDValue>
146   EmitTargetCodeForStrnlen(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain,
147                            SDValue Src, SDValue MaxLength,
148                            MachinePointerInfo SrcPtrInfo) const {
149     return std::make_pair(SDValue(), SDValue());
150   }
151 
152   virtual SDValue EmitTargetCodeForSetTag(SelectionDAG &DAG, const SDLoc &dl,
153                                           SDValue Chain, SDValue Addr,
154                                           SDValue Size,
155                                           MachinePointerInfo DstPtrInfo,
156                                           bool ZeroData) const {
157     return SDValue();
158   }
159 
160   // Return true if the DAG Combiner should disable generic combines.
161   virtual bool disableGenericCombines(CodeGenOptLevel OptLevel) const {
162     return false;
163   }
164 };
165 
166 } // end namespace llvm
167 
168 #endif // LLVM_CODEGEN_SELECTIONDAGTARGETINFO_H
169