1//==-- llvm/CodeGen/SelectionDAGTargetInfo.h - SelectionDAG Info -*- C++ -*-==//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file declares the SelectionDAGTargetInfo class, which targets can
11// subclass to parameterize the SelectionDAG lowering and instruction
12// selection process.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_CODEGEN_SELECTIONDAGTARGETINFO_H
17#define LLVM_CODEGEN_SELECTIONDAGTARGETINFO_H
18
19#include "llvm/CodeGen/SelectionDAGNodes.h"
20#include "llvm/Support/CodeGen.h"
21
22namespace llvm {
23
24//===----------------------------------------------------------------------===//
25/// Targets can subclass this to parameterize the
26/// SelectionDAG lowering and instruction selection process.
27///
28class SelectionDAGTargetInfo {
29  SelectionDAGTargetInfo(const SelectionDAGTargetInfo &) = delete;
30  void operator=(const SelectionDAGTargetInfo &) = delete;
31
32public:
33  explicit SelectionDAGTargetInfo() = default;
34  virtual ~SelectionDAGTargetInfo();
35
36  /// Emit target-specific code that performs a memcpy.
37  /// This can be used by targets to provide code sequences for cases
38  /// that don't fit the target's parameters for simple loads/stores and can be
39  /// more efficient than using a library call. This function can return a null
40  /// SDValue if the target declines to use custom code and a different
41  /// lowering strategy should be used.
42  ///
43  /// If AlwaysInline is true, the size is constant and the target should not
44  /// emit any calls and is strongly encouraged to attempt to emit inline code
45  /// even if it is beyond the usual threshold because this intrinsic is being
46  /// expanded in a place where calls are not feasible (e.g. within the prologue
47  /// for another call). If the target chooses to decline an AlwaysInline
48  /// request here, legalize will resort to using simple loads and stores.
49  virtual SDValue EmitTargetCodeForMemcpy(SelectionDAG &DAG, const SDLoc &dl,
50                                          SDValue Chain, SDValue Op1,
51                                          SDValue Op2, SDValue Op3,
52                                          unsigned Align, bool isVolatile,
53                                          bool AlwaysInline,
54                                          MachinePointerInfo DstPtrInfo,
55                                          MachinePointerInfo SrcPtrInfo) const {
56    return SDValue();
57  }
58
59  /// Emit target-specific code that performs a memmove.
60  /// This can be used by targets to provide code sequences for cases
61  /// that don't fit the target's parameters for simple loads/stores and can be
62  /// more efficient than using a library call. This function can return a null
63  /// SDValue if the target declines to use custom code and a different
64  /// lowering strategy should be used.
65  virtual SDValue EmitTargetCodeForMemmove(
66      SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1,
67      SDValue Op2, SDValue Op3, unsigned Align, bool isVolatile,
68      MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {
69    return SDValue();
70  }
71
72  /// Emit target-specific code that performs a memset.
73  /// This can be used by targets to provide code sequences for cases
74  /// that don't fit the target's parameters for simple stores and can be more
75  /// efficient than using a library call. This function can return a null
76  /// SDValue if the target declines to use custom code and a different
77  /// lowering strategy should be used.
78  virtual SDValue EmitTargetCodeForMemset(SelectionDAG &DAG, const SDLoc &dl,
79                                          SDValue Chain, SDValue Op1,
80                                          SDValue Op2, SDValue Op3,
81                                          unsigned Align, bool isVolatile,
82                                          MachinePointerInfo DstPtrInfo) const {
83    return SDValue();
84  }
85
86  /// Emit target-specific code that performs a memcmp, in cases where that is
87  /// faster than a libcall. The first returned SDValue is the result of the
88  /// memcmp and the second is the chain. Both SDValues can be null if a normal
89  /// libcall should be used.
90  virtual std::pair<SDValue, SDValue>
91  EmitTargetCodeForMemcmp(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain,
92                          SDValue Op1, SDValue Op2, SDValue Op3,
93                          MachinePointerInfo Op1PtrInfo,
94                          MachinePointerInfo Op2PtrInfo) const {
95    return std::make_pair(SDValue(), SDValue());
96  }
97
98  /// Emit target-specific code that performs a memchr, in cases where that is
99  /// faster than a libcall. The first returned SDValue is the result of the
100  /// memchr and the second is the chain. Both SDValues can be null if a normal
101  /// libcall should be used.
102  virtual std::pair<SDValue, SDValue>
103  EmitTargetCodeForMemchr(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain,
104                          SDValue Src, SDValue Char, SDValue Length,
105                          MachinePointerInfo SrcPtrInfo) const {
106    return std::make_pair(SDValue(), SDValue());
107  }
108
109  /// Emit target-specific code that performs a strcpy or stpcpy, in cases
110  /// where that is faster than a libcall.
111  /// The first returned SDValue is the result of the copy (the start
112  /// of the destination string for strcpy, a pointer to the null terminator
113  /// for stpcpy) and the second is the chain.  Both SDValues can be null
114  /// if a normal libcall should be used.
115  virtual std::pair<SDValue, SDValue>
116  EmitTargetCodeForStrcpy(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain,
117                          SDValue Dest, SDValue Src,
118                          MachinePointerInfo DestPtrInfo,
119                          MachinePointerInfo SrcPtrInfo, bool isStpcpy) const {
120    return std::make_pair(SDValue(), SDValue());
121  }
122
123  /// Emit target-specific code that performs a strcmp, in cases where that is
124  /// faster than a libcall.
125  /// The first returned SDValue is the result of the strcmp and the second is
126  /// the chain. Both SDValues can be null if a normal libcall should be used.
127  virtual std::pair<SDValue, SDValue>
128  EmitTargetCodeForStrcmp(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain,
129                          SDValue Op1, SDValue Op2,
130                          MachinePointerInfo Op1PtrInfo,
131                          MachinePointerInfo Op2PtrInfo) const {
132    return std::make_pair(SDValue(), SDValue());
133  }
134
135  virtual std::pair<SDValue, SDValue>
136  EmitTargetCodeForStrlen(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain,
137                          SDValue Src, MachinePointerInfo SrcPtrInfo) const {
138    return std::make_pair(SDValue(), SDValue());
139  }
140
141  virtual std::pair<SDValue, SDValue>
142  EmitTargetCodeForStrnlen(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain,
143                           SDValue Src, SDValue MaxLength,
144                           MachinePointerInfo SrcPtrInfo) const {
145    return std::make_pair(SDValue(), SDValue());
146  }
147  // Return true when the decision to generate FMA's (or FMS, FMLA etc) rather
148  // than FMUL and ADD is delegated to the machine combiner.
149  virtual bool generateFMAsInMachineCombiner(CodeGenOpt::Level OptLevel) const {
150    return false;
151  }
152};
153
154} // end llvm namespace
155
156#endif
157