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 /// Returns true if a node with the given target-specific opcode has 39 /// a memory operand. Nodes with such opcodes can only be created with 40 /// `SelectionDAG::getMemIntrinsicNode`. 41 virtual bool isTargetMemoryOpcode(unsigned Opcode) const { return false; } 42 43 /// Returns true if a node with the given target-specific opcode has 44 /// strict floating-point semantics. 45 virtual bool isTargetStrictFPOpcode(unsigned Opcode) const { return false; } 46 47 /// Returns true if a node with the given target-specific opcode 48 /// may raise a floating-point exception. 49 virtual bool mayRaiseFPException(unsigned Opcode) const; 50 51 /// Emit target-specific code that performs a memcpy. 52 /// This can be used by targets to provide code sequences for cases 53 /// that don't fit the target's parameters for simple loads/stores and can be 54 /// more efficient than using a library call. This function can return a null 55 /// SDValue if the target declines to use custom code and a different 56 /// lowering strategy should be used. 57 /// 58 /// If AlwaysInline is true, the size is constant and the target should not 59 /// emit any calls and is strongly encouraged to attempt to emit inline code 60 /// even if it is beyond the usual threshold because this intrinsic is being 61 /// expanded in a place where calls are not feasible (e.g. within the prologue 62 /// for another call). If the target chooses to decline an AlwaysInline 63 /// request here, legalize will resort to using simple loads and stores. 64 virtual SDValue EmitTargetCodeForMemcpy(SelectionDAG &DAG, const SDLoc &dl, 65 SDValue Chain, SDValue Op1, 66 SDValue Op2, SDValue Op3, 67 Align Alignment, bool isVolatile, 68 bool AlwaysInline, 69 MachinePointerInfo DstPtrInfo, 70 MachinePointerInfo SrcPtrInfo) const { 71 return SDValue(); 72 } 73 74 /// Emit target-specific code that performs a memmove. 75 /// This can be used by targets to provide code sequences for cases 76 /// that don't fit the target's parameters for simple loads/stores and can be 77 /// more 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. 80 virtual SDValue EmitTargetCodeForMemmove( 81 SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1, 82 SDValue Op2, SDValue Op3, Align Alignment, bool isVolatile, 83 MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const { 84 return SDValue(); 85 } 86 87 /// Emit target-specific code that performs a memset. 88 /// This can be used by targets to provide code sequences for cases 89 /// that don't fit the target's parameters for simple stores and can be more 90 /// efficient than using a library call. This function can return a null 91 /// SDValue if the target declines to use custom code and a different 92 /// lowering strategy should be used. Note that if AlwaysInline is true the 93 /// function has to return a valid SDValue. 94 virtual SDValue EmitTargetCodeForMemset(SelectionDAG &DAG, const SDLoc &dl, 95 SDValue Chain, SDValue Op1, 96 SDValue Op2, SDValue Op3, 97 Align Alignment, bool isVolatile, 98 bool AlwaysInline, 99 MachinePointerInfo DstPtrInfo) const { 100 return SDValue(); 101 } 102 103 /// Emit target-specific code that performs a memcmp/bcmp, in cases where that is 104 /// faster than a libcall. The first returned SDValue is the result of the 105 /// memcmp and the second is the chain. Both SDValues can be null if a normal 106 /// libcall should be used. 107 virtual std::pair<SDValue, SDValue> 108 EmitTargetCodeForMemcmp(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, 109 SDValue Op1, SDValue Op2, SDValue Op3, 110 MachinePointerInfo Op1PtrInfo, 111 MachinePointerInfo Op2PtrInfo) const { 112 return std::make_pair(SDValue(), SDValue()); 113 } 114 115 /// Emit target-specific code that performs a memchr, in cases where that is 116 /// faster than a libcall. The first returned SDValue is the result of the 117 /// memchr 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> 120 EmitTargetCodeForMemchr(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, 121 SDValue Src, SDValue Char, SDValue Length, 122 MachinePointerInfo SrcPtrInfo) const { 123 return std::make_pair(SDValue(), SDValue()); 124 } 125 126 /// Emit target-specific code that performs a strcpy or stpcpy, in cases 127 /// where that is faster than a libcall. 128 /// The first returned SDValue is the result of the copy (the start 129 /// of the destination string for strcpy, a pointer to the null terminator 130 /// for stpcpy) and the second is the chain. Both SDValues can be null 131 /// if a normal libcall should be used. 132 virtual std::pair<SDValue, SDValue> 133 EmitTargetCodeForStrcpy(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, 134 SDValue Dest, SDValue Src, 135 MachinePointerInfo DestPtrInfo, 136 MachinePointerInfo SrcPtrInfo, bool isStpcpy) const { 137 return std::make_pair(SDValue(), SDValue()); 138 } 139 140 /// Emit target-specific code that performs a strcmp, in cases where that is 141 /// faster than a libcall. 142 /// The first returned SDValue is the result of the strcmp and the second is 143 /// the chain. Both SDValues can be null if a normal libcall should be used. 144 virtual std::pair<SDValue, SDValue> 145 EmitTargetCodeForStrcmp(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, 146 SDValue Op1, SDValue Op2, 147 MachinePointerInfo Op1PtrInfo, 148 MachinePointerInfo Op2PtrInfo) const { 149 return std::make_pair(SDValue(), SDValue()); 150 } 151 152 virtual std::pair<SDValue, SDValue> 153 EmitTargetCodeForStrlen(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, 154 SDValue Src, MachinePointerInfo SrcPtrInfo) const { 155 return std::make_pair(SDValue(), SDValue()); 156 } 157 158 virtual std::pair<SDValue, SDValue> 159 EmitTargetCodeForStrnlen(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, 160 SDValue Src, SDValue MaxLength, 161 MachinePointerInfo SrcPtrInfo) const { 162 return std::make_pair(SDValue(), SDValue()); 163 } 164 165 virtual SDValue EmitTargetCodeForSetTag(SelectionDAG &DAG, const SDLoc &dl, 166 SDValue Chain, SDValue Addr, 167 SDValue Size, 168 MachinePointerInfo DstPtrInfo, 169 bool ZeroData) const { 170 return SDValue(); 171 } 172 173 // Return true if the DAG Combiner should disable generic combines. 174 virtual bool disableGenericCombines(CodeGenOptLevel OptLevel) const { 175 return false; 176 } 177 }; 178 179 } // end namespace llvm 180 181 #endif // LLVM_CODEGEN_SELECTIONDAGTARGETINFO_H 182