1 //===-- SparcISelLowering.h - Sparc DAG Lowering Interface ------*- 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 defines the interfaces that Sparc uses to lower LLVM code into a 10 // selection DAG. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_LIB_TARGET_SPARC_SPARCISELLOWERING_H 15 #define LLVM_LIB_TARGET_SPARC_SPARCISELLOWERING_H 16 17 #include "Sparc.h" 18 #include "llvm/CodeGen/TargetLowering.h" 19 20 namespace llvm { 21 class SparcSubtarget; 22 23 namespace SPISD { 24 enum NodeType : unsigned { 25 FIRST_NUMBER = ISD::BUILTIN_OP_END, 26 CMPICC, // Compare two GPR operands, set icc+xcc. 27 CMPFCC, // Compare two FP operands, set fcc. 28 BRICC, // Branch to dest on icc condition 29 BRXCC, // Branch to dest on xcc condition (64-bit only). 30 BRFCC, // Branch to dest on fcc condition 31 SELECT_ICC, // Select between two values using the current ICC flags. 32 SELECT_XCC, // Select between two values using the current XCC flags. 33 SELECT_FCC, // Select between two values using the current FCC flags. 34 35 Hi, Lo, // Hi/Lo operations, typically on a global address. 36 37 FTOI, // FP to Int within a FP register. 38 ITOF, // Int to FP within a FP register. 39 FTOX, // FP to Int64 within a FP register. 40 XTOF, // Int64 to FP within a FP register. 41 42 CALL, // A call instruction. 43 RET_FLAG, // Return with a flag operand. 44 GLOBAL_BASE_REG, // Global base reg for PIC. 45 FLUSHW, // FLUSH register windows to stack. 46 47 TAIL_CALL, // Tail call 48 49 TLS_ADD, // For Thread Local Storage (TLS). 50 TLS_LD, 51 TLS_CALL, 52 53 LOAD_GDOP, // Load operation w/ gdop relocation. 54 }; 55 } 56 57 class SparcTargetLowering : public TargetLowering { 58 const SparcSubtarget *Subtarget; 59 public: 60 SparcTargetLowering(const TargetMachine &TM, const SparcSubtarget &STI); 61 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override; 62 63 bool useSoftFloat() const override; 64 65 /// computeKnownBitsForTargetNode - Determine which of the bits specified 66 /// in Mask are known to be either zero or one and return them in the 67 /// KnownZero/KnownOne bitsets. 68 void computeKnownBitsForTargetNode(const SDValue Op, 69 KnownBits &Known, 70 const APInt &DemandedElts, 71 const SelectionDAG &DAG, 72 unsigned Depth = 0) const override; 73 74 MachineBasicBlock * 75 EmitInstrWithCustomInserter(MachineInstr &MI, 76 MachineBasicBlock *MBB) const override; 77 78 const char *getTargetNodeName(unsigned Opcode) const override; 79 80 ConstraintType getConstraintType(StringRef Constraint) const override; 81 ConstraintWeight 82 getSingleConstraintMatchWeight(AsmOperandInfo &info, 83 const char *constraint) const override; 84 void LowerAsmOperandForConstraint(SDValue Op, 85 std::string &Constraint, 86 std::vector<SDValue> &Ops, 87 SelectionDAG &DAG) const override; 88 89 std::pair<unsigned, const TargetRegisterClass *> 90 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, 91 StringRef Constraint, MVT VT) const override; 92 93 bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override; 94 MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override { 95 return MVT::i32; 96 } 97 98 Register getRegisterByName(const char* RegName, LLT VT, 99 const MachineFunction &MF) const override; 100 101 /// If a physical register, this returns the register that receives the 102 /// exception address on entry to an EH pad. 103 Register 104 getExceptionPointerRegister(const Constant *PersonalityFn) const override { 105 return SP::I0; 106 } 107 108 /// If a physical register, this returns the register that receives the 109 /// exception typeid on entry to a landing pad. 110 Register 111 getExceptionSelectorRegister(const Constant *PersonalityFn) const override { 112 return SP::I1; 113 } 114 115 /// Override to support customized stack guard loading. 116 bool useLoadStackGuardNode() const override; 117 void insertSSPDeclarations(Module &M) const override; 118 119 /// getSetCCResultType - Return the ISD::SETCC ValueType 120 EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, 121 EVT VT) const override; 122 123 SDValue 124 LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, 125 const SmallVectorImpl<ISD::InputArg> &Ins, 126 const SDLoc &dl, SelectionDAG &DAG, 127 SmallVectorImpl<SDValue> &InVals) const override; 128 SDValue LowerFormalArguments_32(SDValue Chain, CallingConv::ID CallConv, 129 bool isVarArg, 130 const SmallVectorImpl<ISD::InputArg> &Ins, 131 const SDLoc &dl, SelectionDAG &DAG, 132 SmallVectorImpl<SDValue> &InVals) const; 133 SDValue LowerFormalArguments_64(SDValue Chain, CallingConv::ID CallConv, 134 bool isVarArg, 135 const SmallVectorImpl<ISD::InputArg> &Ins, 136 const SDLoc &dl, SelectionDAG &DAG, 137 SmallVectorImpl<SDValue> &InVals) const; 138 139 SDValue 140 LowerCall(TargetLowering::CallLoweringInfo &CLI, 141 SmallVectorImpl<SDValue> &InVals) const override; 142 SDValue LowerCall_32(TargetLowering::CallLoweringInfo &CLI, 143 SmallVectorImpl<SDValue> &InVals) const; 144 SDValue LowerCall_64(TargetLowering::CallLoweringInfo &CLI, 145 SmallVectorImpl<SDValue> &InVals) const; 146 147 bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF, 148 bool isVarArg, 149 const SmallVectorImpl<ISD::OutputArg> &Outs, 150 LLVMContext &Context) const override; 151 152 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, 153 const SmallVectorImpl<ISD::OutputArg> &Outs, 154 const SmallVectorImpl<SDValue> &OutVals, 155 const SDLoc &dl, SelectionDAG &DAG) const override; 156 SDValue LowerReturn_32(SDValue Chain, CallingConv::ID CallConv, 157 bool IsVarArg, 158 const SmallVectorImpl<ISD::OutputArg> &Outs, 159 const SmallVectorImpl<SDValue> &OutVals, 160 const SDLoc &DL, SelectionDAG &DAG) const; 161 SDValue LowerReturn_64(SDValue Chain, CallingConv::ID CallConv, 162 bool IsVarArg, 163 const SmallVectorImpl<ISD::OutputArg> &Outs, 164 const SmallVectorImpl<SDValue> &OutVals, 165 const SDLoc &DL, SelectionDAG &DAG) const; 166 167 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const; 168 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const; 169 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const; 170 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const; 171 172 SDValue withTargetFlags(SDValue Op, unsigned TF, SelectionDAG &DAG) const; 173 SDValue makeHiLoPair(SDValue Op, unsigned HiTF, unsigned LoTF, 174 SelectionDAG &DAG) const; 175 SDValue makeAddress(SDValue Op, SelectionDAG &DAG) const; 176 177 SDValue LowerF128_LibCallArg(SDValue Chain, ArgListTy &Args, SDValue Arg, 178 const SDLoc &DL, SelectionDAG &DAG) const; 179 SDValue LowerF128Op(SDValue Op, SelectionDAG &DAG, 180 const char *LibFuncName, 181 unsigned numArgs) const; 182 SDValue LowerF128Compare(SDValue LHS, SDValue RHS, unsigned &SPCC, 183 const SDLoc &DL, SelectionDAG &DAG) const; 184 185 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const; 186 187 SDValue PerformBITCASTCombine(SDNode *N, DAGCombinerInfo &DCI) const; 188 189 SDValue bitcastConstantFPToInt(ConstantFPSDNode *C, const SDLoc &DL, 190 SelectionDAG &DAG) const; 191 192 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override; 193 194 bool IsEligibleForTailCallOptimization(CCState &CCInfo, 195 CallLoweringInfo &CLI, 196 MachineFunction &MF) const; 197 198 bool ShouldShrinkFPConstant(EVT VT) const override { 199 // Do not shrink FP constpool if VT == MVT::f128. 200 // (ldd, call _Q_fdtoq) is more expensive than two ldds. 201 return VT != MVT::f128; 202 } 203 204 bool shouldInsertFencesForAtomic(const Instruction *I) const override { 205 // FIXME: We insert fences for each atomics and generate 206 // sub-optimal code for PSO/TSO. (Approximately nobody uses any 207 // mode but TSO, which makes this even more silly) 208 return true; 209 } 210 211 AtomicExpansionKind shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const override; 212 213 void ReplaceNodeResults(SDNode *N, 214 SmallVectorImpl<SDValue>& Results, 215 SelectionDAG &DAG) const override; 216 217 MachineBasicBlock *expandSelectCC(MachineInstr &MI, MachineBasicBlock *BB, 218 unsigned BROpcode) const; 219 }; 220 } // end namespace llvm 221 222 #endif // SPARC_ISELLOWERING_H 223