blob: 90d03984060cd029af2d5e045470a1d28043fca2 [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,
Simon Pilgrim37b536e2017-03-31 11:24:16 +000071 const APInt &DemandedElts,
Jay Foada0653a32014-05-14 21:14:37 +000072 const SelectionDAG &DAG,
73 unsigned Depth = 0) const override;
Anton Korobeynikov281cf242008-10-10 20:28:10 +000074
Craig Topperb0c941b2014-04-29 07:57:13 +000075 MachineBasicBlock *
Duncan P. N. Exon Smithe4f5e4f2016-06-30 22:52:52 +000076 EmitInstrWithCustomInserter(MachineInstr &MI,
77 MachineBasicBlock *MBB) const override;
Anton Korobeynikov281cf242008-10-10 20:28:10 +000078
Craig Topperb0c941b2014-04-29 07:57:13 +000079 const char *getTargetNodeName(unsigned Opcode) const override;
Anton Korobeynikov281cf242008-10-10 20:28:10 +000080
Benjamin Kramer9bfb6272015-07-05 19:29:18 +000081 ConstraintType getConstraintType(StringRef Constraint) const override;
Venkatraman Govindaraju407e4422014-01-22 01:29:51 +000082 ConstraintWeight
83 getSingleConstraintMatchWeight(AsmOperandInfo &info,
Craig Topperb0c941b2014-04-29 07:57:13 +000084 const char *constraint) const override;
Venkatraman Govindaraju407e4422014-01-22 01:29:51 +000085 void LowerAsmOperandForConstraint(SDValue Op,
86 std::string &Constraint,
87 std::vector<SDValue> &Ops,
Craig Topperb0c941b2014-04-29 07:57:13 +000088 SelectionDAG &DAG) const override;
Chris Dewhurst0dfa6bc2016-05-20 09:03:01 +000089
90 unsigned
91 getInlineAsmMemConstraint(StringRef ConstraintCode) const override {
92 if (ConstraintCode == "o")
93 return InlineAsm::Constraint_o;
94 return TargetLowering::getInlineAsmMemConstraint(ConstraintCode);
95 }
96
Eric Christopher11e4df72015-02-26 22:38:43 +000097 std::pair<unsigned, const TargetRegisterClass *>
98 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
Benjamin Kramer9bfb6272015-07-05 19:29:18 +000099 StringRef Constraint, MVT VT) const override;
Dan Gohman2fe6bee2008-10-18 02:06:02 +0000100
Craig Topperb0c941b2014-04-29 07:57:13 +0000101 bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
Mehdi Aminieaabc512015-07-09 15:12:23 +0000102 MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override {
Mehdi Amini9639d652015-07-09 02:09:20 +0000103 return MVT::i32;
104 }
Bill Wendling31ceb1b2009-06-30 22:38:32 +0000105
Chris Dewhurstad741172016-05-20 10:21:01 +0000106 unsigned getRegisterByName(const char* RegName, EVT VT,
107 SelectionDAG &DAG) const override;
108
Joseph Tremouletf748c892015-11-07 01:11:31 +0000109 /// If a physical register, this returns the register that receives the
110 /// exception address on entry to an EH pad.
111 unsigned
112 getExceptionPointerRegister(const Constant *PersonalityFn) const override {
113 return SP::I0;
114 }
115
116 /// If a physical register, this returns the register that receives the
117 /// exception typeid on entry to a landing pad.
118 unsigned
119 getExceptionSelectorRegister(const Constant *PersonalityFn) const override {
120 return SP::I1;
121 }
122
Marcin Koscielnicki33571e22016-04-26 10:37:14 +0000123 /// Override to support customized stack guard loading.
124 bool useLoadStackGuardNode() const override;
125 void insertSSPDeclarations(Module &M) const override;
126
Venkatraman Govindarajuf6c8fe92013-12-09 04:02:15 +0000127 /// getSetCCResultType - Return the ISD::SETCC ValueType
Mehdi Amini44ede332015-07-09 02:09:04 +0000128 EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
129 EVT VT) const override;
Venkatraman Govindarajuf6c8fe92013-12-09 04:02:15 +0000130
Craig Topperb0c941b2014-04-29 07:57:13 +0000131 SDValue
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000132 LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
133 const SmallVectorImpl<ISD::InputArg> &Ins,
134 const SDLoc &dl, SelectionDAG &DAG,
135 SmallVectorImpl<SDValue> &InVals) const override;
136 SDValue LowerFormalArguments_32(SDValue Chain, CallingConv::ID CallConv,
Jakob Stoklund Olesen0b21f352013-04-02 04:09:02 +0000137 bool isVarArg,
138 const SmallVectorImpl<ISD::InputArg> &Ins,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000139 const SDLoc &dl, SelectionDAG &DAG,
Jakob Stoklund Olesen0b21f352013-04-02 04:09:02 +0000140 SmallVectorImpl<SDValue> &InVals) const;
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000141 SDValue LowerFormalArguments_64(SDValue Chain, CallingConv::ID CallConv,
Jakob Stoklund Olesen0b21f352013-04-02 04:09:02 +0000142 bool isVarArg,
143 const SmallVectorImpl<ISD::InputArg> &Ins,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000144 const SDLoc &dl, SelectionDAG &DAG,
Jakob Stoklund Olesen0b21f352013-04-02 04:09:02 +0000145 SmallVectorImpl<SDValue> &InVals) const;
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000146
Craig Topperb0c941b2014-04-29 07:57:13 +0000147 SDValue
Justin Holewinskiaa583972012-05-25 16:35:28 +0000148 LowerCall(TargetLowering::CallLoweringInfo &CLI,
Craig Topperb0c941b2014-04-29 07:57:13 +0000149 SmallVectorImpl<SDValue> &InVals) const override;
Jakob Stoklund Olesena30f4832013-04-07 19:10:57 +0000150 SDValue LowerCall_32(TargetLowering::CallLoweringInfo &CLI,
151 SmallVectorImpl<SDValue> &InVals) const;
152 SDValue LowerCall_64(TargetLowering::CallLoweringInfo &CLI,
153 SmallVectorImpl<SDValue> &InVals) const;
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000154
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000155 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
156 const SmallVectorImpl<ISD::OutputArg> &Outs,
157 const SmallVectorImpl<SDValue> &OutVals,
158 const SDLoc &dl, SelectionDAG &DAG) const override;
159 SDValue LowerReturn_32(SDValue Chain, CallingConv::ID CallConv,
160 bool IsVarArg,
Jakob Stoklund Olesenedaf66b2013-04-06 23:57:33 +0000161 const SmallVectorImpl<ISD::OutputArg> &Outs,
162 const SmallVectorImpl<SDValue> &OutVals,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000163 const SDLoc &DL, SelectionDAG &DAG) const;
164 SDValue LowerReturn_64(SDValue Chain, CallingConv::ID CallConv,
165 bool IsVarArg,
Jakob Stoklund Olesenedaf66b2013-04-06 23:57:33 +0000166 const SmallVectorImpl<ISD::OutputArg> &Outs,
167 const SmallVectorImpl<SDValue> &OutVals,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000168 const SDLoc &DL, SelectionDAG &DAG) const;
Chris Lattner840c7002009-09-15 17:46:24 +0000169
Dan Gohman21cea8a2010-04-17 15:26:15 +0000170 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
Venkatraman Govindarajucb1dca62013-09-22 06:48:52 +0000171 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
Dan Gohman21cea8a2010-04-17 15:26:15 +0000172 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
Venkatraman Govindarajuf80d72f2013-06-03 05:58:33 +0000173 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
Venkatraman Govindarajua82203f2011-02-21 03:42:44 +0000174
Chris Dewhurst69fa1922016-05-04 09:33:30 +0000175 SDValue LowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG,
176 const SparcTargetLowering &TLI) const ;
177 SDValue LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG,
178 const SparcTargetLowering &TLI) const ;
179
Venkatraman Govindarajua82203f2011-02-21 03:42:44 +0000180 unsigned getSRetArgSize(SelectionDAG &DAG, SDValue Callee) const;
Jakob Stoklund Olesen1fb08a82013-04-14 01:33:32 +0000181 SDValue withTargetFlags(SDValue Op, unsigned TF, SelectionDAG &DAG) const;
182 SDValue makeHiLoPair(SDValue Op, unsigned HiTF, unsigned LoTF,
183 SelectionDAG &DAG) const;
Jakob Stoklund Olesene0fc8322013-04-14 04:35:16 +0000184 SDValue makeAddress(SDValue Op, SelectionDAG &DAG) const;
Venkatraman Govindaraju59039dc2013-09-03 04:11:59 +0000185
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000186 SDValue LowerF128_LibCallArg(SDValue Chain, ArgListTy &Args, SDValue Arg,
187 const SDLoc &DL, SelectionDAG &DAG) const;
Venkatraman Govindaraju59039dc2013-09-03 04:11:59 +0000188 SDValue LowerF128Op(SDValue Op, SelectionDAG &DAG,
189 const char *LibFuncName,
190 unsigned numArgs) const;
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000191 SDValue LowerF128Compare(SDValue LHS, SDValue RHS, unsigned &SPCC,
192 const SDLoc &DL, SelectionDAG &DAG) const;
Venkatraman Govindaraju59039dc2013-09-03 04:11:59 +0000193
Marcin Koscielnickifafb4492016-04-26 10:37:01 +0000194 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
195
Craig Topperb0c941b2014-04-29 07:57:13 +0000196 bool ShouldShrinkFPConstant(EVT VT) const override {
Venkatraman Govindaraju59039dc2013-09-03 04:11:59 +0000197 // Do not shrink FP constpool if VT == MVT::f128.
198 // (ldd, call _Q_fdtoq) is more expensive than two ldds.
199 return VT != MVT::f128;
200 }
Venkatraman Govindaraju5ae77f72013-11-03 12:28:40 +0000201
James Y Knightf44fc522016-03-16 22:12:04 +0000202 bool shouldInsertFencesForAtomic(const Instruction *I) const override {
203 // FIXME: We insert fences for each atomics and generate
204 // sub-optimal code for PSO/TSO. (Approximately nobody uses any
205 // mode but TSO, which makes this even more silly)
206 return true;
207 }
208
James Y Knight7306cd42016-03-29 19:09:54 +0000209 AtomicExpansionKind shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const override;
210
Craig Topperb0c941b2014-04-29 07:57:13 +0000211 void ReplaceNodeResults(SDNode *N,
James Y Knight3994be82015-08-10 19:11:39 +0000212 SmallVectorImpl<SDValue>& Results,
213 SelectionDAG &DAG) const override;
Jakob Stoklund Olesen05ae2d62014-01-24 06:23:31 +0000214
Duncan P. N. Exon Smithe4f5e4f2016-06-30 22:52:52 +0000215 MachineBasicBlock *expandSelectCC(MachineInstr &MI, MachineBasicBlock *BB,
Jakob Stoklund Olesen05ae2d62014-01-24 06:23:31 +0000216 unsigned BROpcode) const;
Duncan P. N. Exon Smithe4f5e4f2016-06-30 22:52:52 +0000217 MachineBasicBlock *emitEHSjLjSetJmp(MachineInstr &MI,
Chris Dewhurst69fa1922016-05-04 09:33:30 +0000218 MachineBasicBlock *MBB) const;
Duncan P. N. Exon Smithe4f5e4f2016-06-30 22:52:52 +0000219 MachineBasicBlock *emitEHSjLjLongJmp(MachineInstr &MI,
Chris Dewhurst69fa1922016-05-04 09:33:30 +0000220 MachineBasicBlock *MBB) const;
Chris Lattner0a1762e2008-03-17 03:21:36 +0000221 };
222} // end namespace llvm
223
224#endif // SPARC_ISELLOWERING_H