blob: 20dfd2cabd0864b00619129690d796d3a1e1572f [file] [log] [blame]
Chris Lattner0a1762e2008-03-17 03:21:36 +00001//===-- SparcISelLowering.h - Sparc DAG Lowering Interface ------*- 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 defines the interfaces that Sparc uses to lower LLVM code into a
11// selection DAG.
12//
13//===----------------------------------------------------------------------===//
14
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000015#ifndef LLVM_LIB_TARGET_SPARC_SPARCISELLOWERING_H
16#define LLVM_LIB_TARGET_SPARC_SPARCISELLOWERING_H
Chris Lattner0a1762e2008-03-17 03:21:36 +000017
Chris Lattner0a1762e2008-03-17 03:21:36 +000018#include "Sparc.h"
Craig Topperb25fda92012-03-17 18:46:09 +000019#include "llvm/Target/TargetLowering.h"
Chris Lattner0a1762e2008-03-17 03:21:36 +000020
21namespace llvm {
Jakob Stoklund Olesen5ad3b352013-04-02 04:08:54 +000022 class SparcSubtarget;
23
Chris Lattner0a1762e2008-03-17 03:21:36 +000024 namespace SPISD {
Matthias Braund04893f2015-05-07 21:33:59 +000025 enum NodeType : unsigned {
Dan Gohmaned1cf1a2008-09-23 18:42:32 +000026 FIRST_NUMBER = ISD::BUILTIN_OP_END,
Jakob Stoklund Olesend9bbdfd2013-04-03 04:41:44 +000027 CMPICC, // Compare two GPR operands, set icc+xcc.
Chris Lattner0a1762e2008-03-17 03:21:36 +000028 CMPFCC, // Compare two FP operands, set fcc.
29 BRICC, // Branch to dest on icc condition
Jakob Stoklund Olesend9bbdfd2013-04-03 04:41:44 +000030 BRXCC, // Branch to dest on xcc condition (64-bit only).
Chris Lattner0a1762e2008-03-17 03:21:36 +000031 BRFCC, // Branch to dest on fcc condition
32 SELECT_ICC, // Select between two values using the current ICC flags.
Jakob Stoklund Olesen8cfaffa2013-04-04 03:08:00 +000033 SELECT_XCC, // Select between two values using the current XCC flags.
Chris Lattner0a1762e2008-03-17 03:21:36 +000034 SELECT_FCC, // Select between two values using the current FCC flags.
Anton Korobeynikov281cf242008-10-10 20:28:10 +000035
Chris Dewhurst69fa1922016-05-04 09:33:30 +000036 EH_SJLJ_SETJMP, // builtin setjmp operation
37 EH_SJLJ_LONGJMP, // builtin longjmp operation
38
Chris Lattner0a1762e2008-03-17 03:21:36 +000039 Hi, Lo, // Hi/Lo operations, typically on a global address.
Anton Korobeynikov281cf242008-10-10 20:28:10 +000040
Chris Lattner0a1762e2008-03-17 03:21:36 +000041 FTOI, // FP to Int within a FP register.
42 ITOF, // Int to FP within a FP register.
Venkatraman Govindaraju5ae77f72013-11-03 12:28:40 +000043 FTOX, // FP to Int64 within a FP register.
44 XTOF, // Int64 to FP within a FP register.
Anton Korobeynikov281cf242008-10-10 20:28:10 +000045
Chris Lattner0a1762e2008-03-17 03:21:36 +000046 CALL, // A call instruction.
Chris Lattner840c7002009-09-15 17:46:24 +000047 RET_FLAG, // Return with a flag operand.
Venkatraman Govindarajucb1dca62013-09-22 06:48:52 +000048 GLOBAL_BASE_REG, // Global base reg for PIC.
49 FLUSHW, // FLUSH register windows to stack.
50
51 TLS_ADD, // For Thread Local Storage (TLS).
52 TLS_LD,
53 TLS_CALL
Chris Lattner0a1762e2008-03-17 03:21:36 +000054 };
Alexander Kornienkof00654e2015-06-23 09:49:53 +000055 }
Anton Korobeynikov281cf242008-10-10 20:28:10 +000056
Chris Lattner0a1762e2008-03-17 03:21:36 +000057 class SparcTargetLowering : public TargetLowering {
Jakob Stoklund Olesen5ad3b352013-04-02 04:08:54 +000058 const SparcSubtarget *Subtarget;
Chris Lattner0a1762e2008-03-17 03:21:36 +000059 public:
James Y Knightef31eaf2016-05-03 14:57:18 +000060 SparcTargetLowering(const TargetMachine &TM, const SparcSubtarget &STI);
Craig Topperb0c941b2014-04-29 07:57:13 +000061 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
Chris Dewhurst68388a02016-05-18 09:14:13 +000062
63 bool useSoftFloat() const override;
64
Jay Foada0653a32014-05-14 21:14:37 +000065 /// computeKnownBitsForTargetNode - Determine which of the bits specified
Anton Korobeynikov281cf242008-10-10 20:28:10 +000066 /// in Mask are known to be either zero or one and return them in the
Chris Lattner0a1762e2008-03-17 03:21:36 +000067 /// KnownZero/KnownOne bitsets.
Jay Foada0653a32014-05-14 21:14:37 +000068 void computeKnownBitsForTargetNode(const SDValue Op,
69 APInt &KnownZero,
70 APInt &KnownOne,
71 const SelectionDAG &DAG,
72 unsigned Depth = 0) const override;
Anton Korobeynikov281cf242008-10-10 20:28:10 +000073
Craig Topperb0c941b2014-04-29 07:57:13 +000074 MachineBasicBlock *
Dan Gohman25c16532010-05-01 00:01:06 +000075 EmitInstrWithCustomInserter(MachineInstr *MI,
Craig Topperb0c941b2014-04-29 07:57:13 +000076 MachineBasicBlock *MBB) const override;
Anton Korobeynikov281cf242008-10-10 20:28:10 +000077
Craig Topperb0c941b2014-04-29 07:57:13 +000078 const char *getTargetNodeName(unsigned Opcode) const override;
Anton Korobeynikov281cf242008-10-10 20:28:10 +000079
Benjamin Kramer9bfb6272015-07-05 19:29:18 +000080 ConstraintType getConstraintType(StringRef Constraint) const override;
Venkatraman Govindaraju407e4422014-01-22 01:29:51 +000081 ConstraintWeight
82 getSingleConstraintMatchWeight(AsmOperandInfo &info,
Craig Topperb0c941b2014-04-29 07:57:13 +000083 const char *constraint) const override;
Venkatraman Govindaraju407e4422014-01-22 01:29:51 +000084 void LowerAsmOperandForConstraint(SDValue Op,
85 std::string &Constraint,
86 std::vector<SDValue> &Ops,
Craig Topperb0c941b2014-04-29 07:57:13 +000087 SelectionDAG &DAG) const override;
Eric Christopher11e4df72015-02-26 22:38:43 +000088 std::pair<unsigned, const TargetRegisterClass *>
89 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
Benjamin Kramer9bfb6272015-07-05 19:29:18 +000090 StringRef Constraint, MVT VT) const override;
Dan Gohman2fe6bee2008-10-18 02:06:02 +000091
Craig Topperb0c941b2014-04-29 07:57:13 +000092 bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
Mehdi Aminieaabc512015-07-09 15:12:23 +000093 MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override {
Mehdi Amini9639d652015-07-09 02:09:20 +000094 return MVT::i32;
95 }
Bill Wendling31ceb1b2009-06-30 22:38:32 +000096
Joseph Tremouletf748c892015-11-07 01:11:31 +000097 /// If a physical register, this returns the register that receives the
98 /// exception address on entry to an EH pad.
99 unsigned
100 getExceptionPointerRegister(const Constant *PersonalityFn) const override {
101 return SP::I0;
102 }
103
104 /// If a physical register, this returns the register that receives the
105 /// exception typeid on entry to a landing pad.
106 unsigned
107 getExceptionSelectorRegister(const Constant *PersonalityFn) const override {
108 return SP::I1;
109 }
110
Marcin Koscielnicki33571e22016-04-26 10:37:14 +0000111 /// Override to support customized stack guard loading.
112 bool useLoadStackGuardNode() const override;
113 void insertSSPDeclarations(Module &M) const override;
114
Venkatraman Govindarajuf6c8fe92013-12-09 04:02:15 +0000115 /// getSetCCResultType - Return the ISD::SETCC ValueType
Mehdi Amini44ede332015-07-09 02:09:04 +0000116 EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
117 EVT VT) const override;
Venkatraman Govindarajuf6c8fe92013-12-09 04:02:15 +0000118
Craig Topperb0c941b2014-04-29 07:57:13 +0000119 SDValue
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000120 LowerFormalArguments(SDValue Chain,
Sandeep Patel68c5f472009-09-02 08:44:58 +0000121 CallingConv::ID CallConv,
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000122 bool isVarArg,
123 const SmallVectorImpl<ISD::InputArg> &Ins,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000124 SDLoc dl, SelectionDAG &DAG,
Craig Topperb0c941b2014-04-29 07:57:13 +0000125 SmallVectorImpl<SDValue> &InVals) const override;
Jakob Stoklund Olesen0b21f352013-04-02 04:09:02 +0000126 SDValue LowerFormalArguments_32(SDValue Chain,
127 CallingConv::ID CallConv,
128 bool isVarArg,
129 const SmallVectorImpl<ISD::InputArg> &Ins,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000130 SDLoc dl, SelectionDAG &DAG,
Jakob Stoklund Olesen0b21f352013-04-02 04:09:02 +0000131 SmallVectorImpl<SDValue> &InVals) const;
132 SDValue LowerFormalArguments_64(SDValue Chain,
133 CallingConv::ID CallConv,
134 bool isVarArg,
135 const SmallVectorImpl<ISD::InputArg> &Ins,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000136 SDLoc dl, SelectionDAG &DAG,
Jakob Stoklund Olesen0b21f352013-04-02 04:09:02 +0000137 SmallVectorImpl<SDValue> &InVals) const;
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000138
Craig Topperb0c941b2014-04-29 07:57:13 +0000139 SDValue
Justin Holewinskiaa583972012-05-25 16:35:28 +0000140 LowerCall(TargetLowering::CallLoweringInfo &CLI,
Craig Topperb0c941b2014-04-29 07:57:13 +0000141 SmallVectorImpl<SDValue> &InVals) const override;
Jakob Stoklund Olesena30f4832013-04-07 19:10:57 +0000142 SDValue LowerCall_32(TargetLowering::CallLoweringInfo &CLI,
143 SmallVectorImpl<SDValue> &InVals) const;
144 SDValue LowerCall_64(TargetLowering::CallLoweringInfo &CLI,
145 SmallVectorImpl<SDValue> &InVals) const;
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000146
Craig Topperb0c941b2014-04-29 07:57:13 +0000147 SDValue
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000148 LowerReturn(SDValue Chain,
Sandeep Patel68c5f472009-09-02 08:44:58 +0000149 CallingConv::ID CallConv, bool isVarArg,
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000150 const SmallVectorImpl<ISD::OutputArg> &Outs,
Dan Gohmanfe7532a2010-07-07 15:54:55 +0000151 const SmallVectorImpl<SDValue> &OutVals,
Craig Topperb0c941b2014-04-29 07:57:13 +0000152 SDLoc dl, SelectionDAG &DAG) const override;
Jakob Stoklund Olesenedaf66b2013-04-06 23:57:33 +0000153 SDValue LowerReturn_32(SDValue Chain,
154 CallingConv::ID CallConv, bool IsVarArg,
155 const SmallVectorImpl<ISD::OutputArg> &Outs,
156 const SmallVectorImpl<SDValue> &OutVals,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000157 SDLoc DL, SelectionDAG &DAG) const;
Jakob Stoklund Olesenedaf66b2013-04-06 23:57:33 +0000158 SDValue LowerReturn_64(SDValue Chain,
159 CallingConv::ID CallConv, bool IsVarArg,
160 const SmallVectorImpl<ISD::OutputArg> &Outs,
161 const SmallVectorImpl<SDValue> &OutVals,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000162 SDLoc DL, SelectionDAG &DAG) const;
Chris Lattner840c7002009-09-15 17:46:24 +0000163
Dan Gohman21cea8a2010-04-17 15:26:15 +0000164 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
Venkatraman Govindarajucb1dca62013-09-22 06:48:52 +0000165 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman21cea8a2010-04-17 15:26:15 +0000166 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
Venkatraman Govindarajuf80d72f2013-06-03 05:58:33 +0000167 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
Venkatraman Govindarajua82203f2011-02-21 03:42:44 +0000168
Chris Dewhurst69fa1922016-05-04 09:33:30 +0000169 SDValue LowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG,
170 const SparcTargetLowering &TLI) const ;
171 SDValue LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG,
172 const SparcTargetLowering &TLI) const ;
173
Venkatraman Govindarajua82203f2011-02-21 03:42:44 +0000174 unsigned getSRetArgSize(SelectionDAG &DAG, SDValue Callee) const;
Jakob Stoklund Olesen1fb08a82013-04-14 01:33:32 +0000175 SDValue withTargetFlags(SDValue Op, unsigned TF, SelectionDAG &DAG) const;
176 SDValue makeHiLoPair(SDValue Op, unsigned HiTF, unsigned LoTF,
177 SelectionDAG &DAG) const;
Jakob Stoklund Olesene0fc8322013-04-14 04:35:16 +0000178 SDValue makeAddress(SDValue Op, SelectionDAG &DAG) const;
Venkatraman Govindaraju59039dc2013-09-03 04:11:59 +0000179
180 SDValue LowerF128_LibCallArg(SDValue Chain, ArgListTy &Args,
181 SDValue Arg, SDLoc DL,
182 SelectionDAG &DAG) const;
183 SDValue LowerF128Op(SDValue Op, SelectionDAG &DAG,
184 const char *LibFuncName,
185 unsigned numArgs) const;
186 SDValue LowerF128Compare(SDValue LHS, SDValue RHS,
187 unsigned &SPCC,
188 SDLoc DL,
189 SelectionDAG &DAG) const;
190
Marcin Koscielnickifafb4492016-04-26 10:37:01 +0000191 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
192
Craig Topperb0c941b2014-04-29 07:57:13 +0000193 bool ShouldShrinkFPConstant(EVT VT) const override {
Venkatraman Govindaraju59039dc2013-09-03 04:11:59 +0000194 // Do not shrink FP constpool if VT == MVT::f128.
195 // (ldd, call _Q_fdtoq) is more expensive than two ldds.
196 return VT != MVT::f128;
197 }
Venkatraman Govindaraju5ae77f72013-11-03 12:28:40 +0000198
James Y Knightf44fc522016-03-16 22:12:04 +0000199 bool shouldInsertFencesForAtomic(const Instruction *I) const override {
200 // FIXME: We insert fences for each atomics and generate
201 // sub-optimal code for PSO/TSO. (Approximately nobody uses any
202 // mode but TSO, which makes this even more silly)
203 return true;
204 }
205
James Y Knight7306cd42016-03-29 19:09:54 +0000206 AtomicExpansionKind shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const override;
207
Craig Topperb0c941b2014-04-29 07:57:13 +0000208 void ReplaceNodeResults(SDNode *N,
James Y Knight3994be82015-08-10 19:11:39 +0000209 SmallVectorImpl<SDValue>& Results,
210 SelectionDAG &DAG) const override;
Jakob Stoklund Olesen05ae2d62014-01-24 06:23:31 +0000211
212 MachineBasicBlock *expandSelectCC(MachineInstr *MI, MachineBasicBlock *BB,
213 unsigned BROpcode) const;
214 MachineBasicBlock *expandAtomicRMW(MachineInstr *MI,
215 MachineBasicBlock *BB,
216 unsigned Opcode,
217 unsigned CondCode = 0) const;
Chris Dewhurst69fa1922016-05-04 09:33:30 +0000218 MachineBasicBlock *emitEHSjLjSetJmp(MachineInstr *MI,
219 MachineBasicBlock *MBB) const;
220 MachineBasicBlock *emitEHSjLjLongJmp(MachineInstr *MI,
221 MachineBasicBlock *MBB) const;
Chris Lattner0a1762e2008-03-17 03:21:36 +0000222 };
223} // end namespace llvm
224
225#endif // SPARC_ISELLOWERING_H