blob: cc6386bccbb1e9d74d1a26f5d84a94ff222575bf [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,
Craig Topperd0af7e82017-04-28 05:31:46 +000069 KnownBits &Known,
Simon Pilgrim37b536e2017-03-31 11:24:16 +000070 const APInt &DemandedElts,
Jay Foada0653a32014-05-14 21:14:37 +000071 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 *
Duncan P. N. Exon Smithe4f5e4f2016-06-30 22:52:52 +000075 EmitInstrWithCustomInserter(MachineInstr &MI,
76 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;
Chris Dewhurst0dfa6bc2016-05-20 09:03:01 +000088
89 unsigned
90 getInlineAsmMemConstraint(StringRef ConstraintCode) const override {
91 if (ConstraintCode == "o")
92 return InlineAsm::Constraint_o;
93 return TargetLowering::getInlineAsmMemConstraint(ConstraintCode);
94 }
95
Eric Christopher11e4df72015-02-26 22:38:43 +000096 std::pair<unsigned, const TargetRegisterClass *>
97 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
Benjamin Kramer9bfb6272015-07-05 19:29:18 +000098 StringRef Constraint, MVT VT) const override;
Dan Gohman2fe6bee2008-10-18 02:06:02 +000099
Craig Topperb0c941b2014-04-29 07:57:13 +0000100 bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
Mehdi Aminieaabc512015-07-09 15:12:23 +0000101 MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override {
Mehdi Amini9639d652015-07-09 02:09:20 +0000102 return MVT::i32;
103 }
Bill Wendling31ceb1b2009-06-30 22:38:32 +0000104
Chris Dewhurstad741172016-05-20 10:21:01 +0000105 unsigned getRegisterByName(const char* RegName, EVT VT,
106 SelectionDAG &DAG) const override;
107
Joseph Tremouletf748c892015-11-07 01:11:31 +0000108 /// If a physical register, this returns the register that receives the
109 /// exception address on entry to an EH pad.
110 unsigned
111 getExceptionPointerRegister(const Constant *PersonalityFn) const override {
112 return SP::I0;
113 }
114
115 /// If a physical register, this returns the register that receives the
116 /// exception typeid on entry to a landing pad.
117 unsigned
118 getExceptionSelectorRegister(const Constant *PersonalityFn) const override {
119 return SP::I1;
120 }
121
Marcin Koscielnicki33571e22016-04-26 10:37:14 +0000122 /// Override to support customized stack guard loading.
123 bool useLoadStackGuardNode() const override;
124 void insertSSPDeclarations(Module &M) const override;
125
Venkatraman Govindarajuf6c8fe92013-12-09 04:02:15 +0000126 /// getSetCCResultType - Return the ISD::SETCC ValueType
Mehdi Amini44ede332015-07-09 02:09:04 +0000127 EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
128 EVT VT) const override;
Venkatraman Govindarajuf6c8fe92013-12-09 04:02:15 +0000129
Craig Topperb0c941b2014-04-29 07:57:13 +0000130 SDValue
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000131 LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
132 const SmallVectorImpl<ISD::InputArg> &Ins,
133 const SDLoc &dl, SelectionDAG &DAG,
134 SmallVectorImpl<SDValue> &InVals) const override;
135 SDValue LowerFormalArguments_32(SDValue Chain, CallingConv::ID CallConv,
Jakob Stoklund Olesen0b21f352013-04-02 04:09:02 +0000136 bool isVarArg,
137 const SmallVectorImpl<ISD::InputArg> &Ins,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000138 const SDLoc &dl, SelectionDAG &DAG,
Jakob Stoklund Olesen0b21f352013-04-02 04:09:02 +0000139 SmallVectorImpl<SDValue> &InVals) const;
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000140 SDValue LowerFormalArguments_64(SDValue Chain, CallingConv::ID CallConv,
Jakob Stoklund Olesen0b21f352013-04-02 04:09:02 +0000141 bool isVarArg,
142 const SmallVectorImpl<ISD::InputArg> &Ins,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000143 const SDLoc &dl, SelectionDAG &DAG,
Jakob Stoklund Olesen0b21f352013-04-02 04:09:02 +0000144 SmallVectorImpl<SDValue> &InVals) const;
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000145
Craig Topperb0c941b2014-04-29 07:57:13 +0000146 SDValue
Justin Holewinskiaa583972012-05-25 16:35:28 +0000147 LowerCall(TargetLowering::CallLoweringInfo &CLI,
Craig Topperb0c941b2014-04-29 07:57:13 +0000148 SmallVectorImpl<SDValue> &InVals) const override;
Jakob Stoklund Olesena30f4832013-04-07 19:10:57 +0000149 SDValue LowerCall_32(TargetLowering::CallLoweringInfo &CLI,
150 SmallVectorImpl<SDValue> &InVals) const;
151 SDValue LowerCall_64(TargetLowering::CallLoweringInfo &CLI,
152 SmallVectorImpl<SDValue> &InVals) const;
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000153
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000154 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
155 const SmallVectorImpl<ISD::OutputArg> &Outs,
156 const SmallVectorImpl<SDValue> &OutVals,
157 const SDLoc &dl, SelectionDAG &DAG) const override;
158 SDValue LowerReturn_32(SDValue Chain, CallingConv::ID CallConv,
159 bool IsVarArg,
Jakob Stoklund Olesenedaf66b2013-04-06 23:57:33 +0000160 const SmallVectorImpl<ISD::OutputArg> &Outs,
161 const SmallVectorImpl<SDValue> &OutVals,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000162 const SDLoc &DL, SelectionDAG &DAG) const;
163 SDValue LowerReturn_64(SDValue Chain, CallingConv::ID CallConv,
164 bool IsVarArg,
Jakob Stoklund Olesenedaf66b2013-04-06 23:57:33 +0000165 const SmallVectorImpl<ISD::OutputArg> &Outs,
166 const SmallVectorImpl<SDValue> &OutVals,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000167 const SDLoc &DL, SelectionDAG &DAG) const;
Chris Lattner840c7002009-09-15 17:46:24 +0000168
Dan Gohman21cea8a2010-04-17 15:26:15 +0000169 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
Venkatraman Govindarajucb1dca62013-09-22 06:48:52 +0000170 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman21cea8a2010-04-17 15:26:15 +0000171 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
Venkatraman Govindarajuf80d72f2013-06-03 05:58:33 +0000172 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
Venkatraman Govindarajua82203f2011-02-21 03:42:44 +0000173
Chris Dewhurst69fa1922016-05-04 09:33:30 +0000174 SDValue LowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG,
175 const SparcTargetLowering &TLI) const ;
176 SDValue LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG,
177 const SparcTargetLowering &TLI) const ;
178
Venkatraman Govindarajua82203f2011-02-21 03:42:44 +0000179 unsigned getSRetArgSize(SelectionDAG &DAG, SDValue Callee) const;
Jakob Stoklund Olesen1fb08a82013-04-14 01:33:32 +0000180 SDValue withTargetFlags(SDValue Op, unsigned TF, SelectionDAG &DAG) const;
181 SDValue makeHiLoPair(SDValue Op, unsigned HiTF, unsigned LoTF,
182 SelectionDAG &DAG) const;
Jakob Stoklund Olesene0fc8322013-04-14 04:35:16 +0000183 SDValue makeAddress(SDValue Op, SelectionDAG &DAG) const;
Venkatraman Govindaraju59039dc2013-09-03 04:11:59 +0000184
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000185 SDValue LowerF128_LibCallArg(SDValue Chain, ArgListTy &Args, SDValue Arg,
186 const SDLoc &DL, SelectionDAG &DAG) const;
Venkatraman Govindaraju59039dc2013-09-03 04:11:59 +0000187 SDValue LowerF128Op(SDValue Op, SelectionDAG &DAG,
188 const char *LibFuncName,
189 unsigned numArgs) const;
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000190 SDValue LowerF128Compare(SDValue LHS, SDValue RHS, unsigned &SPCC,
191 const SDLoc &DL, SelectionDAG &DAG) const;
Venkatraman Govindaraju59039dc2013-09-03 04:11:59 +0000192
Marcin Koscielnickifafb4492016-04-26 10:37:01 +0000193 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
194
Craig Topperb0c941b2014-04-29 07:57:13 +0000195 bool ShouldShrinkFPConstant(EVT VT) const override {
Venkatraman Govindaraju59039dc2013-09-03 04:11:59 +0000196 // Do not shrink FP constpool if VT == MVT::f128.
197 // (ldd, call _Q_fdtoq) is more expensive than two ldds.
198 return VT != MVT::f128;
199 }
Venkatraman Govindaraju5ae77f72013-11-03 12:28:40 +0000200
James Y Knightf44fc522016-03-16 22:12:04 +0000201 bool shouldInsertFencesForAtomic(const Instruction *I) const override {
202 // FIXME: We insert fences for each atomics and generate
203 // sub-optimal code for PSO/TSO. (Approximately nobody uses any
204 // mode but TSO, which makes this even more silly)
205 return true;
206 }
207
James Y Knight7306cd42016-03-29 19:09:54 +0000208 AtomicExpansionKind shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const override;
209
Craig Topperb0c941b2014-04-29 07:57:13 +0000210 void ReplaceNodeResults(SDNode *N,
James Y Knight3994be82015-08-10 19:11:39 +0000211 SmallVectorImpl<SDValue>& Results,
212 SelectionDAG &DAG) const override;
Jakob Stoklund Olesen05ae2d62014-01-24 06:23:31 +0000213
Duncan P. N. Exon Smithe4f5e4f2016-06-30 22:52:52 +0000214 MachineBasicBlock *expandSelectCC(MachineInstr &MI, MachineBasicBlock *BB,
Jakob Stoklund Olesen05ae2d62014-01-24 06:23:31 +0000215 unsigned BROpcode) const;
Duncan P. N. Exon Smithe4f5e4f2016-06-30 22:52:52 +0000216 MachineBasicBlock *emitEHSjLjSetJmp(MachineInstr &MI,
Chris Dewhurst69fa1922016-05-04 09:33:30 +0000217 MachineBasicBlock *MBB) const;
Duncan P. N. Exon Smithe4f5e4f2016-06-30 22:52:52 +0000218 MachineBasicBlock *emitEHSjLjLongJmp(MachineInstr &MI,
Chris Dewhurst69fa1922016-05-04 09:33:30 +0000219 MachineBasicBlock *MBB) const;
Chris Lattner0a1762e2008-03-17 03:21:36 +0000220 };
221} // end namespace llvm
222
223#endif // SPARC_ISELLOWERING_H