blob: ed9119345e85e6d337bbc5d3700706afb792b7e3 [file] [log] [blame]
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001//===-- MipsISelLowering.cpp - Mips DAG Lowering Implementation -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the interfaces that Mips uses to lower LLVM code into a
11// selection DAG.
12//
13//===----------------------------------------------------------------------===//
14
15#define DEBUG_TYPE "mips-lower"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000016#include "MipsISelLowering.h"
Bruno Cardoso Lopesa2b1bb52007-08-28 05:08:16 +000017#include "MipsMachineFunction.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000018#include "MipsTargetMachine.h"
Chris Lattnerb71b9092009-08-13 06:28:06 +000019#include "MipsTargetObjectFile.h"
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000020#include "MipsSubtarget.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000021#include "llvm/DerivedTypes.h"
22#include "llvm/Function.h"
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +000023#include "llvm/GlobalVariable.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000024#include "llvm/Intrinsics.h"
25#include "llvm/CallingConv.h"
26#include "llvm/CodeGen/CallingConvLower.h"
27#include "llvm/CodeGen/MachineFrameInfo.h"
28#include "llvm/CodeGen/MachineFunction.h"
29#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattner84bc5422007-12-31 04:13:23 +000030#include "llvm/CodeGen/MachineRegisterInfo.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000031#include "llvm/CodeGen/SelectionDAGISel.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000032#include "llvm/CodeGen/ValueTypes.h"
33#include "llvm/Support/Debug.h"
Torok Edwinc25e7582009-07-11 20:10:48 +000034#include "llvm/Support/ErrorHandling.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000035using namespace llvm;
36
Chris Lattnerf0144122009-07-28 03:13:23 +000037const char *MipsTargetLowering::getTargetNodeName(unsigned Opcode) const {
38 switch (Opcode) {
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +000039 case MipsISD::JmpLink : return "MipsISD::JmpLink";
40 case MipsISD::Hi : return "MipsISD::Hi";
41 case MipsISD::Lo : return "MipsISD::Lo";
42 case MipsISD::GPRel : return "MipsISD::GPRel";
43 case MipsISD::Ret : return "MipsISD::Ret";
44 case MipsISD::SelectCC : return "MipsISD::SelectCC";
45 case MipsISD::FPSelectCC : return "MipsISD::FPSelectCC";
46 case MipsISD::FPBrcond : return "MipsISD::FPBrcond";
47 case MipsISD::FPCmp : return "MipsISD::FPCmp";
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +000048 case MipsISD::FPRound : return "MipsISD::FPRound";
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +000049 case MipsISD::MAdd : return "MipsISD::MAdd";
50 case MipsISD::MAddu : return "MipsISD::MAddu";
51 case MipsISD::MSub : return "MipsISD::MSub";
52 case MipsISD::MSubu : return "MipsISD::MSubu";
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +000053 default : return NULL;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000054 }
55}
56
57MipsTargetLowering::
Chris Lattnerf0144122009-07-28 03:13:23 +000058MipsTargetLowering(MipsTargetMachine &TM)
Chris Lattnerb71b9092009-08-13 06:28:06 +000059 : TargetLowering(TM, new MipsTargetObjectFile()) {
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000060 Subtarget = &TM.getSubtarget<MipsSubtarget>();
61
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000062 // Mips does not have i1 type, so use i32 for
Wesley Peckbf17cfa2010-11-23 03:31:01 +000063 // setcc operations results (slt, sgt, ...).
Duncan Sands03228082008-11-23 15:47:28 +000064 setBooleanContents(ZeroOrOneBooleanContent);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000065
66 // Set up the register classes
Owen Anderson825b72b2009-08-11 20:47:22 +000067 addRegisterClass(MVT::i32, Mips::CPURegsRegisterClass);
68 addRegisterClass(MVT::f32, Mips::FGR32RegisterClass);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000069
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000070 // When dealing with single precision only, use libcalls
Bruno Cardoso Lopesbdfbb742009-03-21 00:05:07 +000071 if (!Subtarget->isSingleFloat())
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000072 if (!Subtarget->isFP64bit())
Owen Anderson825b72b2009-08-11 20:47:22 +000073 addRegisterClass(MVT::f64, Mips::AFGR64RegisterClass);
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000074
Wesley Peckbf17cfa2010-11-23 03:31:01 +000075 // Load extented operations for i1 types must be promoted
Owen Anderson825b72b2009-08-11 20:47:22 +000076 setLoadExtAction(ISD::EXTLOAD, MVT::i1, Promote);
77 setLoadExtAction(ISD::ZEXTLOAD, MVT::i1, Promote);
78 setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000079
Eli Friedman6055a6a2009-07-17 04:07:24 +000080 // MIPS doesn't have extending float->double load/store
Owen Anderson825b72b2009-08-11 20:47:22 +000081 setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand);
82 setTruncStoreAction(MVT::f64, MVT::f32, Expand);
Eli Friedman10a36592009-07-17 02:28:12 +000083
Wesley Peckbf17cfa2010-11-23 03:31:01 +000084 // Used by legalize types to correctly generate the setcc result.
85 // Without this, every float setcc comes with a AND/OR with the result,
86 // we don't want this, since the fpcmp result goes to a flag register,
Bruno Cardoso Lopes77283772008-07-31 18:31:28 +000087 // which is used implicitly by brcond and select operations.
Owen Anderson825b72b2009-08-11 20:47:22 +000088 AddPromotedToType(ISD::SETCC, MVT::i1, MVT::i32);
Bruno Cardoso Lopes77283772008-07-31 18:31:28 +000089
Bruno Cardoso Lopes97c25372008-07-09 04:15:08 +000090 // Mips Custom Operations
Owen Anderson825b72b2009-08-11 20:47:22 +000091 setOperationAction(ISD::GlobalAddress, MVT::i32, Custom);
92 setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom);
93 setOperationAction(ISD::JumpTable, MVT::i32, Custom);
94 setOperationAction(ISD::ConstantPool, MVT::i32, Custom);
95 setOperationAction(ISD::SELECT, MVT::f32, Custom);
96 setOperationAction(ISD::SELECT, MVT::f64, Custom);
97 setOperationAction(ISD::SELECT, MVT::i32, Custom);
98 setOperationAction(ISD::SETCC, MVT::f32, Custom);
99 setOperationAction(ISD::SETCC, MVT::f64, Custom);
100 setOperationAction(ISD::BRCOND, MVT::Other, Custom);
101 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Custom);
102 setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom);
Bruno Cardoso Lopes6059b852010-02-06 21:00:02 +0000103 setOperationAction(ISD::VASTART, MVT::Other, Custom);
104
Bruno Cardoso Lopes97c25372008-07-09 04:15:08 +0000105
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000106 // We custom lower AND/OR to handle the case where the DAG contain 'ands/ors'
107 // with operands comming from setcc fp comparions. This is necessary since
Bruno Cardoso Lopes1906c5a2008-08-02 19:37:33 +0000108 // the result from these setcc are in a flag registers (FCR31).
Owen Anderson825b72b2009-08-11 20:47:22 +0000109 setOperationAction(ISD::AND, MVT::i32, Custom);
110 setOperationAction(ISD::OR, MVT::i32, Custom);
Bruno Cardoso Lopes77283772008-07-31 18:31:28 +0000111
Bruno Cardoso Lopes97c25372008-07-09 04:15:08 +0000112 // Operations not directly supported by Mips.
Owen Anderson825b72b2009-08-11 20:47:22 +0000113 setOperationAction(ISD::BR_JT, MVT::Other, Expand);
114 setOperationAction(ISD::BR_CC, MVT::Other, Expand);
115 setOperationAction(ISD::SELECT_CC, MVT::Other, Expand);
116 setOperationAction(ISD::UINT_TO_FP, MVT::i32, Expand);
117 setOperationAction(ISD::FP_TO_UINT, MVT::i32, Expand);
118 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand);
119 setOperationAction(ISD::CTPOP, MVT::i32, Expand);
120 setOperationAction(ISD::CTTZ, MVT::i32, Expand);
121 setOperationAction(ISD::ROTL, MVT::i32, Expand);
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000122
123 if (!Subtarget->isMips32r2())
124 setOperationAction(ISD::ROTR, MVT::i32, Expand);
125
Owen Anderson825b72b2009-08-11 20:47:22 +0000126 setOperationAction(ISD::SHL_PARTS, MVT::i32, Expand);
127 setOperationAction(ISD::SRA_PARTS, MVT::i32, Expand);
128 setOperationAction(ISD::SRL_PARTS, MVT::i32, Expand);
129 setOperationAction(ISD::FCOPYSIGN, MVT::f32, Expand);
130 setOperationAction(ISD::FCOPYSIGN, MVT::f64, Expand);
131 setOperationAction(ISD::FSIN, MVT::f32, Expand);
132 setOperationAction(ISD::FCOS, MVT::f32, Expand);
133 setOperationAction(ISD::FPOWI, MVT::f32, Expand);
134 setOperationAction(ISD::FPOW, MVT::f32, Expand);
135 setOperationAction(ISD::FLOG, MVT::f32, Expand);
136 setOperationAction(ISD::FLOG2, MVT::f32, Expand);
137 setOperationAction(ISD::FLOG10, MVT::f32, Expand);
138 setOperationAction(ISD::FEXP, MVT::f32, Expand);
Bruno Cardoso Lopes97c25372008-07-09 04:15:08 +0000139
Owen Anderson825b72b2009-08-11 20:47:22 +0000140 setOperationAction(ISD::EH_LABEL, MVT::Other, Expand);
Bruno Cardoso Lopes97c25372008-07-09 04:15:08 +0000141
142 // Use the default for now
Owen Anderson825b72b2009-08-11 20:47:22 +0000143 setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
144 setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
145 setOperationAction(ISD::MEMBARRIER, MVT::Other, Expand);
Bruno Cardoso Lopes85e92122008-07-07 19:11:24 +0000146
Bruno Cardoso Lopesea9d4d62008-08-04 06:44:31 +0000147 if (Subtarget->isSingleFloat())
Owen Anderson825b72b2009-08-11 20:47:22 +0000148 setOperationAction(ISD::SELECT_CC, MVT::f64, Expand);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000149
Bruno Cardoso Lopes7728f7e2008-07-09 05:32:22 +0000150 if (!Subtarget->hasSEInReg()) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000151 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand);
152 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand);
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000153 }
154
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000155 if (!Subtarget->hasBitCount())
Owen Anderson825b72b2009-08-11 20:47:22 +0000156 setOperationAction(ISD::CTLZ, MVT::i32, Expand);
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000157
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000158 if (!Subtarget->hasSwap())
Owen Anderson825b72b2009-08-11 20:47:22 +0000159 setOperationAction(ISD::BSWAP, MVT::i32, Expand);
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000160
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000161 setTargetDAGCombine(ISD::ADDE);
162 setTargetDAGCombine(ISD::SUBE);
163
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000164 setStackPointerRegisterToSaveRestore(Mips::SP);
165 computeRegisterProperties();
166}
167
Owen Anderson825b72b2009-08-11 20:47:22 +0000168MVT::SimpleValueType MipsTargetLowering::getSetCCResultType(EVT VT) const {
169 return MVT::i32;
Scott Michel5b8f82e2008-03-10 15:42:14 +0000170}
171
Bill Wendlingb4202b82009-07-01 18:50:55 +0000172/// getFunctionAlignment - Return the Log2 alignment of this function.
Bill Wendling20c568f2009-06-30 22:38:32 +0000173unsigned MipsTargetLowering::getFunctionAlignment(const Function *) const {
174 return 2;
175}
Scott Michel5b8f82e2008-03-10 15:42:14 +0000176
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000177// SelectMadd -
178// Transforms a subgraph in CurDAG if the following pattern is found:
179// (addc multLo, Lo0), (adde multHi, Hi0),
180// where,
181// multHi/Lo: product of multiplication
182// Lo0: initial value of Lo register
183// Hi0: initial value of Hi register
184// Return true if mattern matching was successful.
185static bool SelectMadd(SDNode* ADDENode, SelectionDAG* CurDAG) {
186 // ADDENode's second operand must be a flag output of an ADDC node in order
187 // for the matching to be successful.
188 SDNode* ADDCNode = ADDENode->getOperand(2).getNode();
189
190 if (ADDCNode->getOpcode() != ISD::ADDC)
191 return false;
192
193 SDValue MultHi = ADDENode->getOperand(0);
194 SDValue MultLo = ADDCNode->getOperand(0);
195 SDNode* MultNode = MultHi.getNode();
196 unsigned MultOpc = MultHi.getOpcode();
197
198 // MultHi and MultLo must be generated by the same node,
199 if (MultLo.getNode() != MultNode)
200 return false;
201
202 // and it must be a multiplication.
203 if (MultOpc != ISD::SMUL_LOHI && MultOpc != ISD::UMUL_LOHI)
204 return false;
205
206 // MultLo amd MultHi must be the first and second output of MultNode
207 // respectively.
208 if (MultHi.getResNo() != 1 || MultLo.getResNo() != 0)
209 return false;
210
211 // Transform this to a MADD only if ADDENode and ADDCNode are the only users
212 // of the values of MultNode, in which case MultNode will be removed in later
213 // phases.
214 // If there exist users other than ADDENode or ADDCNode, this function returns
215 // here, which will result in MultNode being mapped to a single MULT
216 // instruction node rather than a pair of MULT and MADD instructions being
217 // produced.
218 if (!MultHi.hasOneUse() || !MultLo.hasOneUse())
219 return false;
220
221 SDValue Chain = CurDAG->getEntryNode();
222 DebugLoc dl = ADDENode->getDebugLoc();
223
224 // create MipsMAdd(u) node
225 MultOpc = MultOpc == ISD::UMUL_LOHI ? MipsISD::MAddu : MipsISD::MAdd;
226
227 SDValue MAdd = CurDAG->getNode(MultOpc, dl,
228 MVT::Glue,
229 MultNode->getOperand(0),// Factor 0
230 MultNode->getOperand(1),// Factor 1
231 ADDCNode->getOperand(1),// Lo0
232 ADDENode->getOperand(1));// Hi0
233
234 // create CopyFromReg nodes
235 SDValue CopyFromLo = CurDAG->getCopyFromReg(Chain, dl, Mips::LO, MVT::i32,
236 MAdd);
237 SDValue CopyFromHi = CurDAG->getCopyFromReg(CopyFromLo.getValue(1), dl,
238 Mips::HI, MVT::i32,
239 CopyFromLo.getValue(2));
240
241 // replace uses of adde and addc here
242 if (!SDValue(ADDCNode, 0).use_empty())
243 CurDAG->ReplaceAllUsesOfValueWith(SDValue(ADDCNode, 0), CopyFromLo);
244
245 if (!SDValue(ADDENode, 0).use_empty())
246 CurDAG->ReplaceAllUsesOfValueWith(SDValue(ADDENode, 0), CopyFromHi);
247
248 return true;
249}
250
251// SelectMsub -
252// Transforms a subgraph in CurDAG if the following pattern is found:
253// (addc Lo0, multLo), (sube Hi0, multHi),
254// where,
255// multHi/Lo: product of multiplication
256// Lo0: initial value of Lo register
257// Hi0: initial value of Hi register
258// Return true if mattern matching was successful.
259static bool SelectMsub(SDNode* SUBENode, SelectionDAG* CurDAG) {
260 // SUBENode's second operand must be a flag output of an SUBC node in order
261 // for the matching to be successful.
262 SDNode* SUBCNode = SUBENode->getOperand(2).getNode();
263
264 if (SUBCNode->getOpcode() != ISD::SUBC)
265 return false;
266
267 SDValue MultHi = SUBENode->getOperand(1);
268 SDValue MultLo = SUBCNode->getOperand(1);
269 SDNode* MultNode = MultHi.getNode();
270 unsigned MultOpc = MultHi.getOpcode();
271
272 // MultHi and MultLo must be generated by the same node,
273 if (MultLo.getNode() != MultNode)
274 return false;
275
276 // and it must be a multiplication.
277 if (MultOpc != ISD::SMUL_LOHI && MultOpc != ISD::UMUL_LOHI)
278 return false;
279
280 // MultLo amd MultHi must be the first and second output of MultNode
281 // respectively.
282 if (MultHi.getResNo() != 1 || MultLo.getResNo() != 0)
283 return false;
284
285 // Transform this to a MSUB only if SUBENode and SUBCNode are the only users
286 // of the values of MultNode, in which case MultNode will be removed in later
287 // phases.
288 // If there exist users other than SUBENode or SUBCNode, this function returns
289 // here, which will result in MultNode being mapped to a single MULT
290 // instruction node rather than a pair of MULT and MSUB instructions being
291 // produced.
292 if (!MultHi.hasOneUse() || !MultLo.hasOneUse())
293 return false;
294
295 SDValue Chain = CurDAG->getEntryNode();
296 DebugLoc dl = SUBENode->getDebugLoc();
297
298 // create MipsSub(u) node
299 MultOpc = MultOpc == ISD::UMUL_LOHI ? MipsISD::MSubu : MipsISD::MSub;
300
301 SDValue MSub = CurDAG->getNode(MultOpc, dl,
302 MVT::Glue,
303 MultNode->getOperand(0),// Factor 0
304 MultNode->getOperand(1),// Factor 1
305 SUBCNode->getOperand(0),// Lo0
306 SUBENode->getOperand(0));// Hi0
307
308 // create CopyFromReg nodes
309 SDValue CopyFromLo = CurDAG->getCopyFromReg(Chain, dl, Mips::LO, MVT::i32,
310 MSub);
311 SDValue CopyFromHi = CurDAG->getCopyFromReg(CopyFromLo.getValue(1), dl,
312 Mips::HI, MVT::i32,
313 CopyFromLo.getValue(2));
314
315 // replace uses of sube and subc here
316 if (!SDValue(SUBCNode, 0).use_empty())
317 CurDAG->ReplaceAllUsesOfValueWith(SDValue(SUBCNode, 0), CopyFromLo);
318
319 if (!SDValue(SUBENode, 0).use_empty())
320 CurDAG->ReplaceAllUsesOfValueWith(SDValue(SUBENode, 0), CopyFromHi);
321
322 return true;
323}
324
325static SDValue PerformADDECombine(SDNode *N, SelectionDAG& DAG,
326 TargetLowering::DAGCombinerInfo &DCI,
327 const MipsSubtarget* Subtarget) {
328 if (DCI.isBeforeLegalize())
329 return SDValue();
330
331 if (Subtarget->isMips32() && SelectMadd(N, &DAG))
332 return SDValue(N, 0);
333
334 return SDValue();
335}
336
337static SDValue PerformSUBECombine(SDNode *N, SelectionDAG& DAG,
338 TargetLowering::DAGCombinerInfo &DCI,
339 const MipsSubtarget* Subtarget) {
340 if (DCI.isBeforeLegalize())
341 return SDValue();
342
343 if (Subtarget->isMips32() && SelectMsub(N, &DAG))
344 return SDValue(N, 0);
345
346 return SDValue();
347}
348
349SDValue MipsTargetLowering::PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI)
350 const {
351 SelectionDAG &DAG = DCI.DAG;
352 unsigned opc = N->getOpcode();
353
354 switch (opc) {
355 default: break;
356 case ISD::ADDE:
357 return PerformADDECombine(N, DAG, DCI, Subtarget);
358 case ISD::SUBE:
359 return PerformSUBECombine(N, DAG, DCI, Subtarget);
360 }
361
362 return SDValue();
363}
364
Dan Gohman475871a2008-07-27 21:46:04 +0000365SDValue MipsTargetLowering::
Dan Gohmand858e902010-04-17 15:26:15 +0000366LowerOperation(SDValue Op, SelectionDAG &DAG) const
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000367{
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000368 switch (Op.getOpcode())
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000369 {
Bruno Cardoso Lopes7da151c2008-08-07 19:08:11 +0000370 case ISD::AND: return LowerANDOR(Op, DAG);
371 case ISD::BRCOND: return LowerBRCOND(Op, DAG);
Bruno Cardoso Lopes7da151c2008-08-07 19:08:11 +0000372 case ISD::ConstantPool: return LowerConstantPool(Op, DAG);
373 case ISD::DYNAMIC_STACKALLOC: return LowerDYNAMIC_STACKALLOC(Op, DAG);
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000374 case ISD::FP_TO_SINT: return LowerFP_TO_SINT(Op, DAG);
Bruno Cardoso Lopes7da151c2008-08-07 19:08:11 +0000375 case ISD::GlobalAddress: return LowerGlobalAddress(Op, DAG);
376 case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG);
377 case ISD::JumpTable: return LowerJumpTable(Op, DAG);
378 case ISD::OR: return LowerANDOR(Op, DAG);
Bruno Cardoso Lopes7da151c2008-08-07 19:08:11 +0000379 case ISD::SELECT: return LowerSELECT(Op, DAG);
Bruno Cardoso Lopes7da151c2008-08-07 19:08:11 +0000380 case ISD::SETCC: return LowerSETCC(Op, DAG);
Bruno Cardoso Lopes6059b852010-02-06 21:00:02 +0000381 case ISD::VASTART: return LowerVASTART(Op, DAG);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000382 }
Dan Gohman475871a2008-07-27 21:46:04 +0000383 return SDValue();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000384}
385
386//===----------------------------------------------------------------------===//
387// Lower helper functions
388//===----------------------------------------------------------------------===//
389
390// AddLiveIn - This helper function adds the specified physical register to the
391// MachineFunction as a live in value. It also creates a corresponding
392// virtual register for it.
393static unsigned
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000394AddLiveIn(MachineFunction &MF, unsigned PReg, TargetRegisterClass *RC)
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000395{
396 assert(RC->contains(PReg) && "Not the correct regclass!");
Chris Lattner84bc5422007-12-31 04:13:23 +0000397 unsigned VReg = MF.getRegInfo().createVirtualRegister(RC);
398 MF.getRegInfo().addLiveIn(PReg, VReg);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000399 return VReg;
400}
401
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000402// Get fp branch code (not opcode) from condition code.
403static Mips::FPBranchCode GetFPBranchCodeFromCond(Mips::CondCode CC) {
404 if (CC >= Mips::FCOND_F && CC <= Mips::FCOND_NGT)
405 return Mips::BRANCH_T;
406
407 if (CC >= Mips::FCOND_T && CC <= Mips::FCOND_GT)
408 return Mips::BRANCH_F;
409
410 return Mips::BRANCH_INVALID;
411}
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000412
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000413static unsigned FPBranchCodeToOpc(Mips::FPBranchCode BC) {
414 switch(BC) {
415 default:
Torok Edwinc23197a2009-07-14 16:55:14 +0000416 llvm_unreachable("Unknown branch code");
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000417 case Mips::BRANCH_T : return Mips::BC1T;
418 case Mips::BRANCH_F : return Mips::BC1F;
419 case Mips::BRANCH_TL : return Mips::BC1TL;
420 case Mips::BRANCH_FL : return Mips::BC1FL;
421 }
422}
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000423
424static Mips::CondCode FPCondCCodeToFCC(ISD::CondCode CC) {
425 switch (CC) {
Torok Edwinc23197a2009-07-14 16:55:14 +0000426 default: llvm_unreachable("Unknown fp condition code!");
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000427 case ISD::SETEQ:
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000428 case ISD::SETOEQ: return Mips::FCOND_EQ;
429 case ISD::SETUNE: return Mips::FCOND_OGL;
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000430 case ISD::SETLT:
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000431 case ISD::SETOLT: return Mips::FCOND_OLT;
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000432 case ISD::SETGT:
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000433 case ISD::SETOGT: return Mips::FCOND_OGT;
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000434 case ISD::SETLE:
435 case ISD::SETOLE: return Mips::FCOND_OLE;
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000436 case ISD::SETGE:
437 case ISD::SETOGE: return Mips::FCOND_OGE;
438 case ISD::SETULT: return Mips::FCOND_ULT;
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000439 case ISD::SETULE: return Mips::FCOND_ULE;
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000440 case ISD::SETUGT: return Mips::FCOND_UGT;
441 case ISD::SETUGE: return Mips::FCOND_UGE;
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000442 case ISD::SETUO: return Mips::FCOND_UN;
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000443 case ISD::SETO: return Mips::FCOND_OR;
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000444 case ISD::SETNE:
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000445 case ISD::SETONE: return Mips::FCOND_NEQ;
446 case ISD::SETUEQ: return Mips::FCOND_UEQ;
447 }
448}
449
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000450MachineBasicBlock *
451MipsTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
Dan Gohmanaf1d8ca2010-05-01 00:01:06 +0000452 MachineBasicBlock *BB) const {
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000453 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
454 bool isFPCmp = false;
Dale Johannesen94817572009-02-13 02:34:39 +0000455 DebugLoc dl = MI->getDebugLoc();
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000456
457 switch (MI->getOpcode()) {
458 default: assert(false && "Unexpected instr type to insert");
459 case Mips::Select_FCC:
Bruno Cardoso Lopesbdfbb742009-03-21 00:05:07 +0000460 case Mips::Select_FCC_S32:
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000461 case Mips::Select_FCC_D32:
462 isFPCmp = true; // FALL THROUGH
463 case Mips::Select_CC:
Bruno Cardoso Lopesbdfbb742009-03-21 00:05:07 +0000464 case Mips::Select_CC_S32:
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000465 case Mips::Select_CC_D32: {
466 // To "insert" a SELECT_CC instruction, we actually have to insert the
467 // diamond control-flow pattern. The incoming instruction knows the
468 // destination vreg to set, the condition code register to branch on, the
469 // true/false values to select between, and a branch opcode to use.
470 const BasicBlock *LLVM_BB = BB->getBasicBlock();
471 MachineFunction::iterator It = BB;
472 ++It;
473
474 // thisMBB:
475 // ...
476 // TrueVal = ...
477 // setcc r1, r2, r3
478 // bNE r1, r0, copy1MBB
479 // fallthrough --> copy0MBB
480 MachineBasicBlock *thisMBB = BB;
481 MachineFunction *F = BB->getParent();
482 MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
483 MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
Dan Gohman14152b42010-07-06 20:24:04 +0000484 F->insert(It, copy0MBB);
485 F->insert(It, sinkMBB);
486
487 // Transfer the remainder of BB and its successor edges to sinkMBB.
488 sinkMBB->splice(sinkMBB->begin(), BB,
489 llvm::next(MachineBasicBlock::iterator(MI)),
490 BB->end());
491 sinkMBB->transferSuccessorsAndUpdatePHIs(BB);
492
493 // Next, add the true and fallthrough blocks as its successors.
494 BB->addSuccessor(copy0MBB);
495 BB->addSuccessor(sinkMBB);
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000496
497 // Emit the right instruction according to the type of the operands compared
498 if (isFPCmp) {
499 // Find the condiction code present in the setcc operation.
500 Mips::CondCode CC = (Mips::CondCode)MI->getOperand(4).getImm();
501 // Get the branch opcode from the branch code.
502 unsigned Opc = FPBranchCodeToOpc(GetFPBranchCodeFromCond(CC));
Dale Johannesen94817572009-02-13 02:34:39 +0000503 BuildMI(BB, dl, TII->get(Opc)).addMBB(sinkMBB);
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000504 } else
Dale Johannesen94817572009-02-13 02:34:39 +0000505 BuildMI(BB, dl, TII->get(Mips::BNE)).addReg(MI->getOperand(1).getReg())
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000506 .addReg(Mips::ZERO).addMBB(sinkMBB);
507
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000508 // copy0MBB:
509 // %FalseValue = ...
510 // # fallthrough to sinkMBB
511 BB = copy0MBB;
512
513 // Update machine-CFG edges
514 BB->addSuccessor(sinkMBB);
515
516 // sinkMBB:
Bruno Cardoso Lopes29e9daa2010-07-20 07:58:51 +0000517 // %Result = phi [ %TrueValue, thisMBB ], [ %FalseValue, copy0MBB ]
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000518 // ...
519 BB = sinkMBB;
Dan Gohman14152b42010-07-06 20:24:04 +0000520 BuildMI(*BB, BB->begin(), dl,
521 TII->get(Mips::PHI), MI->getOperand(0).getReg())
Bruno Cardoso Lopes29e9daa2010-07-20 07:58:51 +0000522 .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB)
523 .addReg(MI->getOperand(3).getReg()).addMBB(copy0MBB);
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000524
Dan Gohman14152b42010-07-06 20:24:04 +0000525 MI->eraseFromParent(); // The pseudo instruction is gone now.
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000526 return BB;
527 }
528 }
529}
530
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000531//===----------------------------------------------------------------------===//
532// Misc Lower Operation implementation
533//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes97843cd2008-07-29 19:29:50 +0000534
Dan Gohman475871a2008-07-27 21:46:04 +0000535SDValue MipsTargetLowering::
Dan Gohmand858e902010-04-17 15:26:15 +0000536LowerFP_TO_SINT(SDValue Op, SelectionDAG &DAG) const
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000537{
538 if (!Subtarget->isMips1())
539 return Op;
540
541 MachineFunction &MF = DAG.getMachineFunction();
542 unsigned CCReg = AddLiveIn(MF, Mips::FCR31, Mips::CCRRegisterClass);
543
544 SDValue Chain = DAG.getEntryNode();
545 DebugLoc dl = Op.getDebugLoc();
546 SDValue Src = Op.getOperand(0);
547
548 // Set the condition register
Owen Anderson825b72b2009-08-11 20:47:22 +0000549 SDValue CondReg = DAG.getCopyFromReg(Chain, dl, CCReg, MVT::i32);
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000550 CondReg = DAG.getCopyToReg(Chain, dl, Mips::AT, CondReg);
Owen Anderson825b72b2009-08-11 20:47:22 +0000551 CondReg = DAG.getCopyFromReg(CondReg, dl, Mips::AT, MVT::i32);
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000552
Owen Anderson825b72b2009-08-11 20:47:22 +0000553 SDValue Cst = DAG.getConstant(3, MVT::i32);
554 SDValue Or = DAG.getNode(ISD::OR, dl, MVT::i32, CondReg, Cst);
555 Cst = DAG.getConstant(2, MVT::i32);
556 SDValue Xor = DAG.getNode(ISD::XOR, dl, MVT::i32, Or, Cst);
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000557
558 SDValue InFlag(0, 0);
559 CondReg = DAG.getCopyToReg(Chain, dl, Mips::FCR31, Xor, InFlag);
560
561 // Emit the round instruction and bit convert to integer
Owen Anderson825b72b2009-08-11 20:47:22 +0000562 SDValue Trunc = DAG.getNode(MipsISD::FPRound, dl, MVT::f32,
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000563 Src, CondReg.getValue(1));
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000564 SDValue BitCvt = DAG.getNode(ISD::BITCAST, dl, MVT::i32, Trunc);
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000565 return BitCvt;
566}
567
568SDValue MipsTargetLowering::
Dan Gohmand858e902010-04-17 15:26:15 +0000569LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const
Bruno Cardoso Lopes7da151c2008-08-07 19:08:11 +0000570{
571 SDValue Chain = Op.getOperand(0);
572 SDValue Size = Op.getOperand(1);
Dale Johannesena05dca42009-02-04 23:02:30 +0000573 DebugLoc dl = Op.getDebugLoc();
Bruno Cardoso Lopes7da151c2008-08-07 19:08:11 +0000574
575 // Get a reference from Mips stack pointer
Owen Anderson825b72b2009-08-11 20:47:22 +0000576 SDValue StackPointer = DAG.getCopyFromReg(Chain, dl, Mips::SP, MVT::i32);
Bruno Cardoso Lopes7da151c2008-08-07 19:08:11 +0000577
578 // Subtract the dynamic size from the actual stack size to
579 // obtain the new stack size.
Owen Anderson825b72b2009-08-11 20:47:22 +0000580 SDValue Sub = DAG.getNode(ISD::SUB, dl, MVT::i32, StackPointer, Size);
Bruno Cardoso Lopes7da151c2008-08-07 19:08:11 +0000581
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000582 // The Sub result contains the new stack start address, so it
Bruno Cardoso Lopes7da151c2008-08-07 19:08:11 +0000583 // must be placed in the stack pointer register.
Dale Johannesena05dca42009-02-04 23:02:30 +0000584 Chain = DAG.getCopyToReg(StackPointer.getValue(1), dl, Mips::SP, Sub);
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000585
586 // This node always has two return values: a new stack pointer
Bruno Cardoso Lopes7da151c2008-08-07 19:08:11 +0000587 // value and a chain
588 SDValue Ops[2] = { Sub, Chain };
Dale Johannesena05dca42009-02-04 23:02:30 +0000589 return DAG.getMergeValues(Ops, 2, dl);
Bruno Cardoso Lopes7da151c2008-08-07 19:08:11 +0000590}
591
592SDValue MipsTargetLowering::
Dan Gohmand858e902010-04-17 15:26:15 +0000593LowerANDOR(SDValue Op, SelectionDAG &DAG) const
Bruno Cardoso Lopes77283772008-07-31 18:31:28 +0000594{
595 SDValue LHS = Op.getOperand(0);
596 SDValue RHS = Op.getOperand(1);
Dale Johannesende064702009-02-06 21:50:26 +0000597 DebugLoc dl = Op.getDebugLoc();
598
Bruno Cardoso Lopes77283772008-07-31 18:31:28 +0000599 if (LHS.getOpcode() != MipsISD::FPCmp || RHS.getOpcode() != MipsISD::FPCmp)
600 return Op;
601
Owen Anderson825b72b2009-08-11 20:47:22 +0000602 SDValue True = DAG.getConstant(1, MVT::i32);
603 SDValue False = DAG.getConstant(0, MVT::i32);
Bruno Cardoso Lopes77283772008-07-31 18:31:28 +0000604
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000605 SDValue LSEL = DAG.getNode(MipsISD::FPSelectCC, dl, True.getValueType(),
Bruno Cardoso Lopes77283772008-07-31 18:31:28 +0000606 LHS, True, False, LHS.getOperand(2));
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000607 SDValue RSEL = DAG.getNode(MipsISD::FPSelectCC, dl, True.getValueType(),
Bruno Cardoso Lopes77283772008-07-31 18:31:28 +0000608 RHS, True, False, RHS.getOperand(2));
609
Owen Anderson825b72b2009-08-11 20:47:22 +0000610 return DAG.getNode(Op.getOpcode(), dl, MVT::i32, LSEL, RSEL);
Bruno Cardoso Lopes77283772008-07-31 18:31:28 +0000611}
612
613SDValue MipsTargetLowering::
Dan Gohmand858e902010-04-17 15:26:15 +0000614LowerBRCOND(SDValue Op, SelectionDAG &DAG) const
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000615{
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000616 // The first operand is the chain, the second is the condition, the third is
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000617 // the block to branch to if the condition is true.
618 SDValue Chain = Op.getOperand(0);
619 SDValue Dest = Op.getOperand(2);
Dale Johannesende064702009-02-06 21:50:26 +0000620 DebugLoc dl = Op.getDebugLoc();
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000621
Bruno Cardoso Lopes77283772008-07-31 18:31:28 +0000622 if (Op.getOperand(1).getOpcode() != MipsISD::FPCmp)
Bruno Cardoso Lopes4b877ca2008-07-30 17:06:13 +0000623 return Op;
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000624
Bruno Cardoso Lopes77283772008-07-31 18:31:28 +0000625 SDValue CondRes = Op.getOperand(1);
626 SDValue CCNode = CondRes.getOperand(2);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000627 Mips::CondCode CC =
628 (Mips::CondCode)cast<ConstantSDNode>(CCNode)->getZExtValue();
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000629 SDValue BrCode = DAG.getConstant(GetFPBranchCodeFromCond(CC), MVT::i32);
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000630
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000631 return DAG.getNode(MipsISD::FPBrcond, dl, Op.getValueType(), Chain, BrCode,
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000632 Dest, CondRes);
633}
634
635SDValue MipsTargetLowering::
Dan Gohmand858e902010-04-17 15:26:15 +0000636LowerSETCC(SDValue Op, SelectionDAG &DAG) const
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000637{
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000638 // The operands to this are the left and right operands to compare (ops #0,
639 // and #1) and the condition code to compare them with (op #2) as a
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000640 // CondCodeSDNode.
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000641 SDValue LHS = Op.getOperand(0);
Dale Johannesende064702009-02-06 21:50:26 +0000642 SDValue RHS = Op.getOperand(1);
643 DebugLoc dl = Op.getDebugLoc();
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000644
645 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get();
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000646
647 return DAG.getNode(MipsISD::FPCmp, dl, Op.getValueType(), LHS, RHS,
Owen Anderson825b72b2009-08-11 20:47:22 +0000648 DAG.getConstant(FPCondCCodeToFCC(CC), MVT::i32));
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000649}
650
651SDValue MipsTargetLowering::
Dan Gohmand858e902010-04-17 15:26:15 +0000652LowerSELECT(SDValue Op, SelectionDAG &DAG) const
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000653{
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000654 SDValue Cond = Op.getOperand(0);
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000655 SDValue True = Op.getOperand(1);
656 SDValue False = Op.getOperand(2);
Dale Johannesende064702009-02-06 21:50:26 +0000657 DebugLoc dl = Op.getDebugLoc();
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000658
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000659 // if the incomming condition comes from a integer compare, the select
660 // operation must be SelectCC or a conditional move if the subtarget
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000661 // supports it.
662 if (Cond.getOpcode() != MipsISD::FPCmp) {
663 if (Subtarget->hasCondMov() && !True.getValueType().isFloatingPoint())
664 return Op;
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000665 return DAG.getNode(MipsISD::SelectCC, dl, True.getValueType(),
Bruno Cardoso Lopes77283772008-07-31 18:31:28 +0000666 Cond, True, False);
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000667 }
668
669 // if the incomming condition comes from fpcmp, the select
670 // operation must use FPSelectCC.
Bruno Cardoso Lopes77283772008-07-31 18:31:28 +0000671 SDValue CCNode = Cond.getOperand(2);
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000672 return DAG.getNode(MipsISD::FPSelectCC, dl, True.getValueType(),
Bruno Cardoso Lopes77283772008-07-31 18:31:28 +0000673 Cond, True, False, CCNode);
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000674}
675
Dan Gohmand858e902010-04-17 15:26:15 +0000676SDValue MipsTargetLowering::LowerGlobalAddress(SDValue Op,
677 SelectionDAG &DAG) const {
Dale Johannesende064702009-02-06 21:50:26 +0000678 // FIXME there isn't actually debug info here
Dale Johannesen33c960f2009-02-04 20:06:27 +0000679 DebugLoc dl = Op.getDebugLoc();
Dan Gohman46510a72010-04-15 01:51:59 +0000680 const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
Bruno Cardoso Lopes97843cd2008-07-29 19:29:50 +0000681
Eli Friedmane2c74082009-08-03 02:22:28 +0000682 if (getTargetMachine().getRelocationModel() != Reloc::PIC_) {
Chris Lattnere3736f82009-08-13 05:41:27 +0000683 SDVTList VTs = DAG.getVTList(MVT::i32);
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000684
Chris Lattnerb71b9092009-08-13 06:28:06 +0000685 MipsTargetObjectFile &TLOF = (MipsTargetObjectFile&)getObjFileLowering();
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000686
Chris Lattnere3736f82009-08-13 05:41:27 +0000687 // %gp_rel relocation
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000688 if (TLOF.IsGlobalInSmallSection(GV, getTargetMachine())) {
689 SDValue GA = DAG.getTargetGlobalAddress(GV, dl, MVT::i32, 0,
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +0000690 MipsII::MO_GPREL);
Chris Lattnere3736f82009-08-13 05:41:27 +0000691 SDValue GPRelNode = DAG.getNode(MipsISD::GPRel, dl, VTs, &GA, 1);
692 SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(MVT::i32);
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000693 return DAG.getNode(ISD::ADD, dl, MVT::i32, GOT, GPRelNode);
Chris Lattnere3736f82009-08-13 05:41:27 +0000694 }
Bruno Cardoso Lopes97843cd2008-07-29 19:29:50 +0000695 // %hi/%lo relocation
Devang Patel0d881da2010-07-06 22:08:15 +0000696 SDValue GA = DAG.getTargetGlobalAddress(GV, dl, MVT::i32, 0,
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +0000697 MipsII::MO_ABS_HILO);
Chris Lattnere3736f82009-08-13 05:41:27 +0000698 SDValue HiPart = DAG.getNode(MipsISD::Hi, dl, VTs, &GA, 1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000699 SDValue Lo = DAG.getNode(MipsISD::Lo, dl, MVT::i32, GA);
700 return DAG.getNode(ISD::ADD, dl, MVT::i32, HiPart, Lo);
Bruno Cardoso Lopes97843cd2008-07-29 19:29:50 +0000701
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +0000702 } else {
Devang Patel0d881da2010-07-06 22:08:15 +0000703 SDValue GA = DAG.getTargetGlobalAddress(GV, dl, MVT::i32, 0,
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +0000704 MipsII::MO_GOT);
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000705 SDValue ResNode = DAG.getLoad(MVT::i32, dl,
Chris Lattnerd1c24ed2010-09-21 06:44:06 +0000706 DAG.getEntryNode(), GA, MachinePointerInfo(),
David Greenef6fa1862010-02-15 16:56:10 +0000707 false, false, 0);
Bruno Cardoso Lopes97843cd2008-07-29 19:29:50 +0000708 // On functions and global targets not internal linked only
709 // a load from got/GP is necessary for PIC to work.
Rafael Espindolabb46f522009-01-15 20:18:42 +0000710 if (!GV->hasLocalLinkage() || isa<Function>(GV))
Bruno Cardoso Lopes97843cd2008-07-29 19:29:50 +0000711 return ResNode;
Owen Anderson825b72b2009-08-11 20:47:22 +0000712 SDValue Lo = DAG.getNode(MipsISD::Lo, dl, MVT::i32, GA);
713 return DAG.getNode(ISD::ADD, dl, MVT::i32, ResNode, Lo);
Bruno Cardoso Lopes97843cd2008-07-29 19:29:50 +0000714 }
715
Torok Edwinc23197a2009-07-14 16:55:14 +0000716 llvm_unreachable("Dont know how to handle GlobalAddress");
Bruno Cardoso Lopes97843cd2008-07-29 19:29:50 +0000717 return SDValue(0,0);
718}
719
720SDValue MipsTargetLowering::
Dan Gohmand858e902010-04-17 15:26:15 +0000721LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const
Bruno Cardoso Lopes97843cd2008-07-29 19:29:50 +0000722{
Torok Edwinc23197a2009-07-14 16:55:14 +0000723 llvm_unreachable("TLS not implemented for MIPS.");
Bruno Cardoso Lopes97843cd2008-07-29 19:29:50 +0000724 return SDValue(); // Not reached
725}
726
727SDValue MipsTargetLowering::
Dan Gohmand858e902010-04-17 15:26:15 +0000728LowerJumpTable(SDValue Op, SelectionDAG &DAG) const
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000729{
Dan Gohman475871a2008-07-27 21:46:04 +0000730 SDValue ResNode;
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000731 SDValue HiPart;
Dale Johannesende064702009-02-06 21:50:26 +0000732 // FIXME there isn't actually debug info here
Dale Johannesen33c960f2009-02-04 20:06:27 +0000733 DebugLoc dl = Op.getDebugLoc();
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +0000734 bool IsPIC = getTargetMachine().getRelocationModel() == Reloc::PIC_;
735 unsigned char OpFlag = IsPIC ? MipsII::MO_GOT : MipsII::MO_ABS_HILO;
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000736
Owen Andersone50ed302009-08-10 22:56:29 +0000737 EVT PtrVT = Op.getValueType();
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000738 JumpTableSDNode *JT = cast<JumpTableSDNode>(Op);
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000739
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +0000740 SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PtrVT, OpFlag);
741
Bruno Cardoso Lopes46773792010-07-20 08:37:04 +0000742 if (!IsPIC) {
Dan Gohman475871a2008-07-27 21:46:04 +0000743 SDValue Ops[] = { JTI };
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +0000744 HiPart = DAG.getNode(MipsISD::Hi, dl, DAG.getVTList(MVT::i32), Ops, 1);
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000745 } else // Emit Load from Global Pointer
Chris Lattnerd1c24ed2010-09-21 06:44:06 +0000746 HiPart = DAG.getLoad(MVT::i32, dl, DAG.getEntryNode(), JTI,
747 MachinePointerInfo(),
David Greenef6fa1862010-02-15 16:56:10 +0000748 false, false, 0);
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000749
Owen Anderson825b72b2009-08-11 20:47:22 +0000750 SDValue Lo = DAG.getNode(MipsISD::Lo, dl, MVT::i32, JTI);
751 ResNode = DAG.getNode(ISD::ADD, dl, MVT::i32, HiPart, Lo);
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000752
753 return ResNode;
754}
755
Dan Gohman475871a2008-07-27 21:46:04 +0000756SDValue MipsTargetLowering::
Dan Gohmand858e902010-04-17 15:26:15 +0000757LowerConstantPool(SDValue Op, SelectionDAG &DAG) const
Bruno Cardoso Lopes97c25372008-07-09 04:15:08 +0000758{
Dan Gohman475871a2008-07-27 21:46:04 +0000759 SDValue ResNode;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000760 ConstantPoolSDNode *N = cast<ConstantPoolSDNode>(Op);
Dan Gohman46510a72010-04-15 01:51:59 +0000761 const Constant *C = N->getConstVal();
Dale Johannesende064702009-02-06 21:50:26 +0000762 // FIXME there isn't actually debug info here
763 DebugLoc dl = Op.getDebugLoc();
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000764
765 // gp_rel relocation
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000766 // FIXME: we should reference the constant pool using small data sections,
Bruno Cardoso Lopesf33bc432008-07-28 19:26:25 +0000767 // but the asm printer currently doens't support this feature without
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000768 // hacking it. This feature should come soon so we can uncomment the
Bruno Cardoso Lopesf33bc432008-07-28 19:26:25 +0000769 // stuff below.
Eli Friedmane2c74082009-08-03 02:22:28 +0000770 //if (IsInSmallSection(C->getType())) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000771 // SDValue GPRelNode = DAG.getNode(MipsISD::GPRel, MVT::i32, CP);
772 // SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(MVT::i32);
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000773 // ResNode = DAG.getNode(ISD::ADD, MVT::i32, GOT, GPRelNode);
Bruno Cardoso Lopesd71cebf2009-11-25 12:17:58 +0000774
775 if (getTargetMachine().getRelocationModel() != Reloc::PIC_) {
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000776 SDValue CP = DAG.getTargetConstantPool(C, MVT::i32, N->getAlignment(),
Bruno Cardoso Lopesd71cebf2009-11-25 12:17:58 +0000777 N->getOffset(), MipsII::MO_ABS_HILO);
Owen Anderson825b72b2009-08-11 20:47:22 +0000778 SDValue HiPart = DAG.getNode(MipsISD::Hi, dl, MVT::i32, CP);
779 SDValue Lo = DAG.getNode(MipsISD::Lo, dl, MVT::i32, CP);
780 ResNode = DAG.getNode(ISD::ADD, dl, MVT::i32, HiPart, Lo);
Bruno Cardoso Lopesd71cebf2009-11-25 12:17:58 +0000781 } else {
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000782 SDValue CP = DAG.getTargetConstantPool(C, MVT::i32, N->getAlignment(),
Bruno Cardoso Lopesd71cebf2009-11-25 12:17:58 +0000783 N->getOffset(), MipsII::MO_GOT);
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000784 SDValue Load = DAG.getLoad(MVT::i32, dl, DAG.getEntryNode(),
Chris Lattnerd1c24ed2010-09-21 06:44:06 +0000785 CP, MachinePointerInfo::getConstantPool(),
786 false, false, 0);
Bruno Cardoso Lopesd71cebf2009-11-25 12:17:58 +0000787 SDValue Lo = DAG.getNode(MipsISD::Lo, dl, MVT::i32, CP);
788 ResNode = DAG.getNode(ISD::ADD, dl, MVT::i32, Load, Lo);
789 }
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000790
791 return ResNode;
Bruno Cardoso Lopes97c25372008-07-09 04:15:08 +0000792}
793
Dan Gohmand858e902010-04-17 15:26:15 +0000794SDValue MipsTargetLowering::LowerVASTART(SDValue Op, SelectionDAG &DAG) const {
Dan Gohman1e93df62010-04-17 14:41:14 +0000795 MachineFunction &MF = DAG.getMachineFunction();
796 MipsFunctionInfo *FuncInfo = MF.getInfo<MipsFunctionInfo>();
797
Bruno Cardoso Lopes6059b852010-02-06 21:00:02 +0000798 DebugLoc dl = Op.getDebugLoc();
Dan Gohman1e93df62010-04-17 14:41:14 +0000799 SDValue FI = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(),
800 getPointerTy());
Bruno Cardoso Lopes6059b852010-02-06 21:00:02 +0000801
802 // vastart just stores the address of the VarArgsFrameIndex slot into the
803 // memory location argument.
804 const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
Chris Lattner8026a9d2010-09-21 17:50:43 +0000805 return DAG.getStore(Op.getOperand(0), dl, FI, Op.getOperand(1),
806 MachinePointerInfo(SV),
David Greenef6fa1862010-02-15 16:56:10 +0000807 false, false, 0);
Bruno Cardoso Lopes6059b852010-02-06 21:00:02 +0000808}
809
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000810//===----------------------------------------------------------------------===//
811// Calling Convention Implementation
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000812//===----------------------------------------------------------------------===//
813
814#include "MipsGenCallingConv.inc"
815
816//===----------------------------------------------------------------------===//
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000817// TODO: Implement a generic logic using tblgen that can support this.
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +0000818// Mips O32 ABI rules:
819// ---
820// i32 - Passed in A0, A1, A2, A3 and stack
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000821// f32 - Only passed in f32 registers if no int reg has been used yet to hold
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +0000822// an argument. Otherwise, passed in A1, A2, A3 and stack.
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000823// f64 - Only passed in two aliased f32 registers if no int reg has been used
824// yet to hold an argument. Otherwise, use A2, A3 and stack. If A1 is
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +0000825// not used, it must be shadowed. If only A3 is avaiable, shadow it and
826// go to stack.
827//===----------------------------------------------------------------------===//
828
Duncan Sands1e96bab2010-11-04 10:49:57 +0000829static bool CC_MipsO32(unsigned ValNo, MVT ValVT,
Duncan Sands1440e8b2010-11-03 11:35:31 +0000830 MVT LocVT, CCValAssign::LocInfo LocInfo,
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +0000831 ISD::ArgFlagsTy ArgFlags, CCState &State) {
832
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000833 static const unsigned IntRegsSize=4, FloatRegsSize=2;
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +0000834
835 static const unsigned IntRegs[] = {
836 Mips::A0, Mips::A1, Mips::A2, Mips::A3
837 };
838 static const unsigned F32Regs[] = {
839 Mips::F12, Mips::F14
840 };
841 static const unsigned F64Regs[] = {
842 Mips::D6, Mips::D7
843 };
844
845 unsigned Reg=0;
846 unsigned UnallocIntReg = State.getFirstUnallocated(IntRegs, IntRegsSize);
847 bool IntRegUsed = (IntRegs[UnallocIntReg] != (unsigned (Mips::A0)));
848
849 // Promote i8 and i16
Owen Anderson825b72b2009-08-11 20:47:22 +0000850 if (LocVT == MVT::i8 || LocVT == MVT::i16) {
851 LocVT = MVT::i32;
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +0000852 if (ArgFlags.isSExt())
853 LocInfo = CCValAssign::SExt;
854 else if (ArgFlags.isZExt())
855 LocInfo = CCValAssign::ZExt;
856 else
857 LocInfo = CCValAssign::AExt;
858 }
859
Owen Anderson825b72b2009-08-11 20:47:22 +0000860 if (ValVT == MVT::i32 || (ValVT == MVT::f32 && IntRegUsed)) {
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +0000861 Reg = State.AllocateReg(IntRegs, IntRegsSize);
862 IntRegUsed = true;
Owen Anderson825b72b2009-08-11 20:47:22 +0000863 LocVT = MVT::i32;
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +0000864 }
865
866 if (ValVT.isFloatingPoint() && !IntRegUsed) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000867 if (ValVT == MVT::f32)
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +0000868 Reg = State.AllocateReg(F32Regs, FloatRegsSize);
869 else
870 Reg = State.AllocateReg(F64Regs, FloatRegsSize);
871 }
872
Owen Anderson825b72b2009-08-11 20:47:22 +0000873 if (ValVT == MVT::f64 && IntRegUsed) {
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +0000874 if (UnallocIntReg != IntRegsSize) {
875 // If we hit register A3 as the first not allocated, we must
876 // mark it as allocated (shadow) and use the stack instead.
877 if (IntRegs[UnallocIntReg] != (unsigned (Mips::A3)))
878 Reg = Mips::A2;
879 for (;UnallocIntReg < IntRegsSize; ++UnallocIntReg)
880 State.AllocateReg(UnallocIntReg);
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000881 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000882 LocVT = MVT::i32;
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +0000883 }
884
885 if (!Reg) {
886 unsigned SizeInBytes = ValVT.getSizeInBits() >> 3;
887 unsigned Offset = State.AllocateStack(SizeInBytes, SizeInBytes);
888 State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
889 } else
890 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
891
892 return false; // CC must always match
893}
894
Duncan Sands1e96bab2010-11-04 10:49:57 +0000895static bool CC_MipsO32_VarArgs(unsigned ValNo, MVT ValVT,
Duncan Sands1440e8b2010-11-03 11:35:31 +0000896 MVT LocVT, CCValAssign::LocInfo LocInfo,
Bruno Cardoso Lopesb37a7422010-02-06 19:20:49 +0000897 ISD::ArgFlagsTy ArgFlags, CCState &State) {
898
899 static const unsigned IntRegsSize=4;
900
901 static const unsigned IntRegs[] = {
902 Mips::A0, Mips::A1, Mips::A2, Mips::A3
903 };
904
905 // Promote i8 and i16
906 if (LocVT == MVT::i8 || LocVT == MVT::i16) {
907 LocVT = MVT::i32;
908 if (ArgFlags.isSExt())
909 LocInfo = CCValAssign::SExt;
910 else if (ArgFlags.isZExt())
911 LocInfo = CCValAssign::ZExt;
912 else
913 LocInfo = CCValAssign::AExt;
914 }
915
916 if (ValVT == MVT::i32 || ValVT == MVT::f32) {
917 if (unsigned Reg = State.AllocateReg(IntRegs, IntRegsSize)) {
918 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, MVT::i32, LocInfo));
919 return false;
920 }
921 unsigned Off = State.AllocateStack(4, 4);
922 State.addLoc(CCValAssign::getMem(ValNo, ValVT, Off, LocVT, LocInfo));
923 return false;
924 }
925
926 unsigned UnallocIntReg = State.getFirstUnallocated(IntRegs, IntRegsSize);
927 if (ValVT == MVT::f64) {
928 if (IntRegs[UnallocIntReg] == (unsigned (Mips::A1))) {
929 // A1 can't be used anymore, because 64 bit arguments
930 // must be aligned when copied back to the caller stack
931 State.AllocateReg(IntRegs, IntRegsSize);
932 UnallocIntReg++;
933 }
934
935 if (IntRegs[UnallocIntReg] == (unsigned (Mips::A0)) ||
936 IntRegs[UnallocIntReg] == (unsigned (Mips::A2))) {
937 unsigned Reg = State.AllocateReg(IntRegs, IntRegsSize);
938 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, MVT::i32, LocInfo));
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000939 // Shadow the next register so it can be used
Bruno Cardoso Lopesb37a7422010-02-06 19:20:49 +0000940 // later to get the other 32bit part.
941 State.AllocateReg(IntRegs, IntRegsSize);
942 return false;
943 }
944
945 // Register is shadowed to preserve alignment, and the
946 // argument goes to a stack location.
947 if (UnallocIntReg != IntRegsSize)
948 State.AllocateReg(IntRegs, IntRegsSize);
949
950 unsigned Off = State.AllocateStack(8, 8);
951 State.addLoc(CCValAssign::getMem(ValNo, ValVT, Off, LocVT, LocInfo));
952 return false;
953 }
954
955 return true; // CC didn't match
956}
957
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +0000958//===----------------------------------------------------------------------===//
Dan Gohman98ca4f22009-08-05 01:29:28 +0000959// Call Calling Convention Implementation
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000960//===----------------------------------------------------------------------===//
961
Dan Gohman98ca4f22009-08-05 01:29:28 +0000962/// LowerCall - functions arguments are copied from virtual regs to
Nate Begeman5bf4b752009-01-26 03:15:54 +0000963/// (physical regs)/(stack frame), CALLSEQ_START and CALLSEQ_END are emitted.
Bruno Cardoso Lopesb37a7422010-02-06 19:20:49 +0000964/// TODO: isTailCall.
Dan Gohman98ca4f22009-08-05 01:29:28 +0000965SDValue
Evan Cheng022d9e12010-02-02 23:55:14 +0000966MipsTargetLowering::LowerCall(SDValue Chain, SDValue Callee,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000967 CallingConv::ID CallConv, bool isVarArg,
Evan Cheng0c439eb2010-01-27 00:07:07 +0000968 bool &isTailCall,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000969 const SmallVectorImpl<ISD::OutputArg> &Outs,
Dan Gohmanc9403652010-07-07 15:54:55 +0000970 const SmallVectorImpl<SDValue> &OutVals,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000971 const SmallVectorImpl<ISD::InputArg> &Ins,
972 DebugLoc dl, SelectionDAG &DAG,
Dan Gohmand858e902010-04-17 15:26:15 +0000973 SmallVectorImpl<SDValue> &InVals) const {
Evan Cheng0c439eb2010-01-27 00:07:07 +0000974 // MIPs target does not yet support tail call optimization.
975 isTailCall = false;
Dan Gohman98ca4f22009-08-05 01:29:28 +0000976
Bruno Cardoso Lopes2ab22d12007-07-11 23:16:16 +0000977 MachineFunction &MF = DAG.getMachineFunction();
Bruno Cardoso Lopes2ab22d12007-07-11 23:16:16 +0000978 MachineFrameInfo *MFI = MF.getFrameInfo();
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +0000979 bool IsPIC = getTargetMachine().getRelocationModel() == Reloc::PIC_;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000980
981 // Analyze operands of the call, assigning locations to each operand.
982 SmallVector<CCValAssign, 16> ArgLocs;
Dan Gohman98ca4f22009-08-05 01:29:28 +0000983 CCState CCInfo(CallConv, isVarArg, getTargetMachine(), ArgLocs,
984 *DAG.getContext());
Bruno Cardoso Lopes2ab22d12007-07-11 23:16:16 +0000985
Bruno Cardoso Lopesb27cb552008-07-15 02:03:36 +0000986 // To meet O32 ABI, Mips must always allocate 16 bytes on
Bruno Cardoso Lopes2ab22d12007-07-11 23:16:16 +0000987 // the stack (even if less than 4 are used as arguments)
Bruno Cardoso Lopesb27cb552008-07-15 02:03:36 +0000988 if (Subtarget->isABI_O32()) {
Duncan Sands1e96bab2010-11-04 10:49:57 +0000989 int VTsize = MVT(MVT::i32).getSizeInBits()/8;
Evan Chenged2ae132010-07-03 00:40:23 +0000990 MFI->CreateFixedObject(VTsize, (VTsize*3), true);
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000991 CCInfo.AnalyzeCallOperands(Outs,
Bruno Cardoso Lopesb37a7422010-02-06 19:20:49 +0000992 isVarArg ? CC_MipsO32_VarArgs : CC_MipsO32);
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +0000993 } else
Dan Gohman98ca4f22009-08-05 01:29:28 +0000994 CCInfo.AnalyzeCallOperands(Outs, CC_Mips);
Wesley Peckbf17cfa2010-11-23 03:31:01 +0000995
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000996 // Get a count of how many bytes are to be pushed on the stack.
997 unsigned NumBytes = CCInfo.getNextStackOffset();
Chris Lattnere563bbc2008-10-11 22:08:30 +0000998 Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumBytes, true));
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000999
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001000 // With EABI is it possible to have 16 args on registers.
Dan Gohman475871a2008-07-27 21:46:04 +00001001 SmallVector<std::pair<unsigned, SDValue>, 16> RegsToPass;
1002 SmallVector<SDValue, 8> MemOpChains;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001003
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001004 // First/LastArgStackLoc contains the first/last
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001005 // "at stack" argument location.
1006 int LastArgStackLoc = 0;
1007 unsigned FirstStackArgLoc = (Subtarget->isABI_EABI() ? 0 : 16);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001008
1009 // Walk the register/memloc assignments, inserting copies/loads.
1010 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
Dan Gohmanc9403652010-07-07 15:54:55 +00001011 SDValue Arg = OutVals[i];
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001012 CCValAssign &VA = ArgLocs[i];
1013
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001014 // Promote the value if needed.
1015 switch (VA.getLocInfo()) {
Torok Edwinc23197a2009-07-14 16:55:14 +00001016 default: llvm_unreachable("Unknown loc info!");
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001017 case CCValAssign::Full:
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +00001018 if (Subtarget->isABI_O32() && VA.isRegLoc()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001019 if (VA.getValVT() == MVT::f32 && VA.getLocVT() == MVT::i32)
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001020 Arg = DAG.getNode(ISD::BITCAST, dl, MVT::i32, Arg);
Owen Anderson825b72b2009-08-11 20:47:22 +00001021 if (VA.getValVT() == MVT::f64 && VA.getLocVT() == MVT::i32) {
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001022 Arg = DAG.getNode(ISD::BITCAST, dl, MVT::i64, Arg);
Owen Anderson825b72b2009-08-11 20:47:22 +00001023 SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Arg,
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +00001024 DAG.getConstant(0, getPointerTy()));
Owen Anderson825b72b2009-08-11 20:47:22 +00001025 SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Arg,
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +00001026 DAG.getConstant(1, getPointerTy()));
1027 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Lo));
1028 RegsToPass.push_back(std::make_pair(VA.getLocReg()+1, Hi));
1029 continue;
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001030 }
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +00001031 }
1032 break;
Chris Lattnere0b12152008-03-17 06:57:02 +00001033 case CCValAssign::SExt:
Dale Johannesen33c960f2009-02-04 20:06:27 +00001034 Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg);
Chris Lattnere0b12152008-03-17 06:57:02 +00001035 break;
1036 case CCValAssign::ZExt:
Dale Johannesen33c960f2009-02-04 20:06:27 +00001037 Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg);
Chris Lattnere0b12152008-03-17 06:57:02 +00001038 break;
1039 case CCValAssign::AExt:
Dale Johannesen33c960f2009-02-04 20:06:27 +00001040 Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg);
Chris Lattnere0b12152008-03-17 06:57:02 +00001041 break;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001042 }
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001043
1044 // Arguments that can be passed on register must be kept at
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +00001045 // RegsToPass vector
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001046 if (VA.isRegLoc()) {
1047 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
Chris Lattnere0b12152008-03-17 06:57:02 +00001048 continue;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001049 }
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001050
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +00001051 // Register can't get to this point...
Chris Lattnere0b12152008-03-17 06:57:02 +00001052 assert(VA.isMemLoc());
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001053
Chris Lattnere0b12152008-03-17 06:57:02 +00001054 // Create the frame index object for this incoming parameter
1055 // This guarantees that when allocating Local Area the firsts
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001056 // 16 bytes which are alwayes reserved won't be overwritten
1057 // if O32 ABI is used. For EABI the first address is zero.
1058 LastArgStackLoc = (FirstStackArgLoc + VA.getLocMemOffset());
Duncan Sands83ec4b62008-06-06 12:08:01 +00001059 int FI = MFI->CreateFixedObject(VA.getValVT().getSizeInBits()/8,
Evan Chenged2ae132010-07-03 00:40:23 +00001060 LastArgStackLoc, true);
Chris Lattnere0b12152008-03-17 06:57:02 +00001061
Dan Gohman475871a2008-07-27 21:46:04 +00001062 SDValue PtrOff = DAG.getFrameIndex(FI,getPointerTy());
Chris Lattnere0b12152008-03-17 06:57:02 +00001063
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001064 // emit ISD::STORE whichs stores the
Chris Lattnere0b12152008-03-17 06:57:02 +00001065 // parameter value to a stack Location
Chris Lattner8026a9d2010-09-21 17:50:43 +00001066 MemOpChains.push_back(DAG.getStore(Chain, dl, Arg, PtrOff,
1067 MachinePointerInfo(),
David Greenef6fa1862010-02-15 16:56:10 +00001068 false, false, 0));
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001069 }
1070
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001071 // Transform all store nodes into one single node because all store
1072 // nodes are independent of each other.
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001073 if (!MemOpChains.empty())
1074 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001075 &MemOpChains[0], MemOpChains.size());
1076
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001077 // Build a sequence of copy-to-reg nodes chained together with token
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001078 // chain and flag operands which copy the outgoing args into registers.
1079 // The InFlag in necessary since all emited instructions must be
1080 // stuck together.
Dan Gohman475871a2008-07-27 21:46:04 +00001081 SDValue InFlag;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001082 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001083 Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first,
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001084 RegsToPass[i].second, InFlag);
1085 InFlag = Chain.getValue(1);
1086 }
1087
Bill Wendling056292f2008-09-16 21:48:12 +00001088 // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001089 // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol
1090 // node so that legalize doesn't hack it.
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +00001091 unsigned char OpFlag = IsPIC ? MipsII::MO_GOT_CALL : MipsII::MO_NO_FLAG;
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001092 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
1093 Callee = DAG.getTargetGlobalAddress(G->getGlobal(), dl,
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +00001094 getPointerTy(), 0, OpFlag);
Bill Wendling056292f2008-09-16 21:48:12 +00001095 else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee))
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001096 Callee = DAG.getTargetExternalSymbol(S->getSymbol(),
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +00001097 getPointerTy(), OpFlag);
Bill Wendling056292f2008-09-16 21:48:12 +00001098
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001099 // MipsJmpLink = #chain, #target_address, #opt_in_flags...
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001100 // = Chain, Callee, Reg#1, Reg#2, ...
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001101 //
1102 // Returns a chain & a flag for retval copy to use.
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00001103 SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
Dan Gohman475871a2008-07-27 21:46:04 +00001104 SmallVector<SDValue, 8> Ops;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001105 Ops.push_back(Chain);
1106 Ops.push_back(Callee);
1107
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001108 // Add argument registers to the end of the list so that they are
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001109 // known live into the call.
1110 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i)
1111 Ops.push_back(DAG.getRegister(RegsToPass[i].first,
1112 RegsToPass[i].second.getValueType()));
1113
Gabor Greifba36cb52008-08-28 21:40:38 +00001114 if (InFlag.getNode())
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001115 Ops.push_back(InFlag);
1116
Dale Johannesen33c960f2009-02-04 20:06:27 +00001117 Chain = DAG.getNode(MipsISD::JmpLink, dl, NodeTys, &Ops[0], Ops.size());
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001118 InFlag = Chain.getValue(1);
1119
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001120 // Create a stack location to hold GP when PIC is used. This stack
1121 // location is used on function prologue to save GP and also after all
1122 // emited CALL's to restore GP.
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +00001123 if (IsPIC) {
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001124 // Function can have an arbitrary number of calls, so
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001125 // hold the LastArgStackLoc with the biggest offset.
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +00001126 int FI;
1127 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001128 if (LastArgStackLoc >= MipsFI->getGPStackOffset()) {
1129 LastArgStackLoc = (!LastArgStackLoc) ? (16) : (LastArgStackLoc+4);
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001130 // Create the frame index only once. SPOffset here can be anything
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +00001131 // (this will be fixed on processFunctionBeforeFrameFinalized)
1132 if (MipsFI->getGPStackOffset() == -1) {
Evan Chenged2ae132010-07-03 00:40:23 +00001133 FI = MFI->CreateFixedObject(4, 0, true);
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +00001134 MipsFI->setGPFI(FI);
1135 }
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001136 MipsFI->setGPStackOffset(LastArgStackLoc);
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +00001137 }
1138
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +00001139 // Reload GP value.
1140 FI = MipsFI->getGPFI();
Chris Lattnerd1c24ed2010-09-21 06:44:06 +00001141 SDValue FIN = DAG.getFrameIndex(FI, getPointerTy());
1142 SDValue GPLoad = DAG.getLoad(MVT::i32, dl, Chain, FIN,
1143 MachinePointerInfo::getFixedStack(FI),
David Greenef6fa1862010-02-15 16:56:10 +00001144 false, false, 0);
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +00001145 Chain = GPLoad.getValue(1);
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001146 Chain = DAG.getCopyToReg(Chain, dl, DAG.getRegister(Mips::GP, MVT::i32),
Dan Gohman475871a2008-07-27 21:46:04 +00001147 GPLoad, SDValue(0,0));
Bruno Cardoso Lopesbdbb7502008-06-01 03:49:39 +00001148 InFlag = Chain.getValue(1);
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001149 }
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +00001150
Bruno Cardoso Lopes3ed6f872010-01-30 18:32:07 +00001151 // Create the CALLSEQ_END node.
1152 Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, true),
1153 DAG.getIntPtrConstant(0, true), InFlag);
1154 InFlag = Chain.getValue(1);
1155
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001156 // Handle result values, copying them out of physregs into vregs that we
1157 // return.
Dan Gohman98ca4f22009-08-05 01:29:28 +00001158 return LowerCallResult(Chain, InFlag, CallConv, isVarArg,
1159 Ins, dl, DAG, InVals);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001160}
1161
Dan Gohman98ca4f22009-08-05 01:29:28 +00001162/// LowerCallResult - Lower the result values of a call into the
1163/// appropriate copies out of appropriate physical registers.
1164SDValue
1165MipsTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +00001166 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman98ca4f22009-08-05 01:29:28 +00001167 const SmallVectorImpl<ISD::InputArg> &Ins,
1168 DebugLoc dl, SelectionDAG &DAG,
Dan Gohmand858e902010-04-17 15:26:15 +00001169 SmallVectorImpl<SDValue> &InVals) const {
Bruno Cardoso Lopes2ab22d12007-07-11 23:16:16 +00001170
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001171 // Assign locations to each value returned by this call.
1172 SmallVector<CCValAssign, 16> RVLocs;
Dan Gohman98ca4f22009-08-05 01:29:28 +00001173 CCState CCInfo(CallConv, isVarArg, getTargetMachine(),
Owen Andersone922c022009-07-22 00:24:57 +00001174 RVLocs, *DAG.getContext());
Bruno Cardoso Lopes2ab22d12007-07-11 23:16:16 +00001175
Dan Gohman98ca4f22009-08-05 01:29:28 +00001176 CCInfo.AnalyzeCallResult(Ins, RetCC_Mips);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001177
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001178 // Copy all of the result registers out of their specified physreg.
1179 for (unsigned i = 0; i != RVLocs.size(); ++i) {
Dale Johannesen33c960f2009-02-04 20:06:27 +00001180 Chain = DAG.getCopyFromReg(Chain, dl, RVLocs[i].getLocReg(),
Dan Gohman98ca4f22009-08-05 01:29:28 +00001181 RVLocs[i].getValVT(), InFlag).getValue(1);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001182 InFlag = Chain.getValue(2);
Dan Gohman98ca4f22009-08-05 01:29:28 +00001183 InVals.push_back(Chain.getValue(0));
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001184 }
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +00001185
Dan Gohman98ca4f22009-08-05 01:29:28 +00001186 return Chain;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001187}
1188
1189//===----------------------------------------------------------------------===//
Dan Gohman98ca4f22009-08-05 01:29:28 +00001190// Formal Arguments Calling Convention Implementation
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001191//===----------------------------------------------------------------------===//
1192
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001193/// LowerFormalArguments - transform physical registers into virtual registers
Bruno Cardoso Lopesb37a7422010-02-06 19:20:49 +00001194/// and generate load operations for arguments places on the stack.
Dan Gohman98ca4f22009-08-05 01:29:28 +00001195SDValue
1196MipsTargetLowering::LowerFormalArguments(SDValue Chain,
Bruno Cardoso Lopesb37a7422010-02-06 19:20:49 +00001197 CallingConv::ID CallConv, bool isVarArg,
1198 const SmallVectorImpl<ISD::InputArg>
1199 &Ins,
1200 DebugLoc dl, SelectionDAG &DAG,
Dan Gohmand858e902010-04-17 15:26:15 +00001201 SmallVectorImpl<SDValue> &InVals)
1202 const {
Dan Gohman98ca4f22009-08-05 01:29:28 +00001203
Bruno Cardoso Lopesf7f3b502008-08-04 07:12:52 +00001204 MachineFunction &MF = DAG.getMachineFunction();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001205 MachineFrameInfo *MFI = MF.getFrameInfo();
Bruno Cardoso Lopesa2b1bb52007-08-28 05:08:16 +00001206 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
Bruno Cardoso Lopes2ab22d12007-07-11 23:16:16 +00001207
1208 unsigned StackReg = MF.getTarget().getRegisterInfo()->getFrameRegister(MF);
Dan Gohman1e93df62010-04-17 14:41:14 +00001209 MipsFI->setVarArgsFrameIndex(0);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001210
Bruno Cardoso Lopesb37a7422010-02-06 19:20:49 +00001211 // Used with vargs to acumulate store chains.
1212 std::vector<SDValue> OutChains;
1213
1214 // Keep track of the last register used for arguments
1215 unsigned ArgRegEnd = 0;
1216
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001217 // Assign locations to all of the incoming arguments.
1218 SmallVector<CCValAssign, 16> ArgLocs;
Dan Gohman98ca4f22009-08-05 01:29:28 +00001219 CCState CCInfo(CallConv, isVarArg, getTargetMachine(),
1220 ArgLocs, *DAG.getContext());
Bruno Cardoso Lopes2ab22d12007-07-11 23:16:16 +00001221
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +00001222 if (Subtarget->isABI_O32())
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001223 CCInfo.AnalyzeFormalArguments(Ins,
Bruno Cardoso Lopesb37a7422010-02-06 19:20:49 +00001224 isVarArg ? CC_MipsO32_VarArgs : CC_MipsO32);
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +00001225 else
Dan Gohman98ca4f22009-08-05 01:29:28 +00001226 CCInfo.AnalyzeFormalArguments(Ins, CC_Mips);
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +00001227
Dan Gohman475871a2008-07-27 21:46:04 +00001228 SDValue StackPtr;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001229
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001230 unsigned FirstStackArgLoc = (Subtarget->isABI_EABI() ? 0 : 16);
1231
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001232 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001233 CCValAssign &VA = ArgLocs[i];
1234
1235 // Arguments stored on registers
1236 if (VA.isRegLoc()) {
Owen Andersone50ed302009-08-10 22:56:29 +00001237 EVT RegVT = VA.getLocVT();
Bruno Cardoso Lopesb37a7422010-02-06 19:20:49 +00001238 ArgRegEnd = VA.getLocReg();
Bill Wendling06b8c192008-07-09 05:55:53 +00001239 TargetRegisterClass *RC = 0;
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +00001240
Owen Anderson825b72b2009-08-11 20:47:22 +00001241 if (RegVT == MVT::i32)
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001242 RC = Mips::CPURegsRegisterClass;
1243 else if (RegVT == MVT::f32)
Bruno Cardoso Lopesbdfbb742009-03-21 00:05:07 +00001244 RC = Mips::FGR32RegisterClass;
Owen Anderson825b72b2009-08-11 20:47:22 +00001245 else if (RegVT == MVT::f64) {
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001246 if (!Subtarget->isSingleFloat())
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001247 RC = Mips::AFGR64RegisterClass;
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001248 } else
Bruno Cardoso Lopesb37a7422010-02-06 19:20:49 +00001249 llvm_unreachable("RegVT not supported by FormalArguments Lowering");
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001250
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001251 // Transform the arguments stored on
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001252 // physical registers into virtual ones
Bruno Cardoso Lopesb37a7422010-02-06 19:20:49 +00001253 unsigned Reg = AddLiveIn(DAG.getMachineFunction(), ArgRegEnd, RC);
Dan Gohman98ca4f22009-08-05 01:29:28 +00001254 SDValue ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, RegVT);
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001255
1256 // If this is an 8 or 16-bit value, it has been passed promoted
1257 // to 32 bits. Insert an assert[sz]ext to capture this, then
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001258 // truncate to the right size.
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +00001259 if (VA.getLocInfo() != CCValAssign::Full) {
Chris Lattnerd4015072009-03-26 05:28:14 +00001260 unsigned Opcode = 0;
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +00001261 if (VA.getLocInfo() == CCValAssign::SExt)
1262 Opcode = ISD::AssertSext;
1263 else if (VA.getLocInfo() == CCValAssign::ZExt)
1264 Opcode = ISD::AssertZext;
Chris Lattnerd4015072009-03-26 05:28:14 +00001265 if (Opcode)
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001266 ArgValue = DAG.getNode(Opcode, dl, RegVT, ArgValue,
Chris Lattnerd4015072009-03-26 05:28:14 +00001267 DAG.getValueType(VA.getValVT()));
Dale Johannesen33c960f2009-02-04 20:06:27 +00001268 ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue);
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +00001269 }
1270
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001271 // Handle O32 ABI cases: i32->f32 and (i32,i32)->f64
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +00001272 if (Subtarget->isABI_O32()) {
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001273 if (RegVT == MVT::i32 && VA.getValVT() == MVT::f32)
1274 ArgValue = DAG.getNode(ISD::BITCAST, dl, MVT::f32, ArgValue);
Owen Anderson825b72b2009-08-11 20:47:22 +00001275 if (RegVT == MVT::i32 && VA.getValVT() == MVT::f64) {
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001276 unsigned Reg2 = AddLiveIn(DAG.getMachineFunction(),
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +00001277 VA.getLocReg()+1, RC);
Dan Gohman98ca4f22009-08-05 01:29:28 +00001278 SDValue ArgValue2 = DAG.getCopyFromReg(Chain, dl, Reg2, RegVT);
Bruno Cardoso Lopesb1fce0a2011-01-18 19:38:25 +00001279 SDValue Pair = DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, ArgValue2, ArgValue);
1280 ArgValue = DAG.getNode(ISD::BITCAST, dl, MVT::f64, Pair);
Bruno Cardoso Lopesb53db4f2009-03-19 02:12:28 +00001281 }
1282 }
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001283
Dan Gohman98ca4f22009-08-05 01:29:28 +00001284 InVals.push_back(ArgValue);
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001285 } else { // VA.isRegLoc()
1286
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001287 // sanity check
1288 assert(VA.isMemLoc());
Bruno Cardoso Lopesb37a7422010-02-06 19:20:49 +00001289
1290 // The last argument is not a register anymore
1291 ArgRegEnd = 0;
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001292
1293 // The stack pointer offset is relative to the caller stack frame.
1294 // Since the real stack size is unknown here, a negative SPOffset
Bruno Cardoso Lopesa2b1bb52007-08-28 05:08:16 +00001295 // is used so there's a way to adjust these offsets when the stack
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001296 // size get known (on EliminateFrameIndex). A dummy SPOffset is
Bruno Cardoso Lopesa2b1bb52007-08-28 05:08:16 +00001297 // used instead of a direct negative address (which is recorded to
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001298 // be used on emitPrologue) to avoid mis-calc of the first stack
Bruno Cardoso Lopesa2b1bb52007-08-28 05:08:16 +00001299 // offset on PEI::calculateFrameObjectOffsets.
1300 // Arguments are always 32-bit.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001301 unsigned ArgSize = VA.getLocVT().getSizeInBits()/8;
Evan Chenged2ae132010-07-03 00:40:23 +00001302 int FI = MFI->CreateFixedObject(ArgSize, 0, true);
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001303 MipsFI->recordLoadArgsFI(FI, -(ArgSize+
1304 (FirstStackArgLoc + VA.getLocMemOffset())));
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001305
1306 // Create load nodes to retrieve arguments from the stack
Dan Gohman475871a2008-07-27 21:46:04 +00001307 SDValue FIN = DAG.getFrameIndex(FI, getPointerTy());
Chris Lattnerd1c24ed2010-09-21 06:44:06 +00001308 InVals.push_back(DAG.getLoad(VA.getValVT(), dl, Chain, FIN,
1309 MachinePointerInfo::getFixedStack(FI),
David Greenef6fa1862010-02-15 16:56:10 +00001310 false, false, 0));
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001311 }
1312 }
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001313
1314 // The mips ABIs for returning structs by value requires that we copy
1315 // the sret argument into $v0 for the return. Save the argument into
1316 // a virtual register so that we can access it from the return points.
1317 if (DAG.getMachineFunction().getFunction()->hasStructRetAttr()) {
1318 unsigned Reg = MipsFI->getSRetReturnReg();
1319 if (!Reg) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001320 Reg = MF.getRegInfo().createVirtualRegister(getRegClassFor(MVT::i32));
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001321 MipsFI->setSRetReturnReg(Reg);
1322 }
Dan Gohman98ca4f22009-08-05 01:29:28 +00001323 SDValue Copy = DAG.getCopyToReg(DAG.getEntryNode(), dl, Reg, InVals[0]);
Owen Anderson825b72b2009-08-11 20:47:22 +00001324 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Copy, Chain);
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001325 }
1326
Bruno Cardoso Lopesb37a7422010-02-06 19:20:49 +00001327 // To meet ABI, when VARARGS are passed on registers, the registers
1328 // must have their values written to the caller stack frame. If the last
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001329 // argument was placed in the stack, there's no need to save any register.
Bruno Cardoso Lopesb37a7422010-02-06 19:20:49 +00001330 if ((isVarArg) && (Subtarget->isABI_O32() && ArgRegEnd)) {
1331 if (StackPtr.getNode() == 0)
1332 StackPtr = DAG.getRegister(StackReg, getPointerTy());
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001333
Bruno Cardoso Lopesb37a7422010-02-06 19:20:49 +00001334 // The last register argument that must be saved is Mips::A3
1335 TargetRegisterClass *RC = Mips::CPURegsRegisterClass;
1336 unsigned StackLoc = ArgLocs.size()-1;
1337
1338 for (++ArgRegEnd; ArgRegEnd <= Mips::A3; ++ArgRegEnd, ++StackLoc) {
1339 unsigned Reg = AddLiveIn(DAG.getMachineFunction(), ArgRegEnd, RC);
1340 SDValue ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, MVT::i32);
1341
Evan Chenged2ae132010-07-03 00:40:23 +00001342 int FI = MFI->CreateFixedObject(4, 0, true);
Bruno Cardoso Lopesb37a7422010-02-06 19:20:49 +00001343 MipsFI->recordStoreVarArgsFI(FI, -(4+(StackLoc*4)));
1344 SDValue PtrOff = DAG.getFrameIndex(FI, getPointerTy());
Chris Lattner8026a9d2010-09-21 17:50:43 +00001345 OutChains.push_back(DAG.getStore(Chain, dl, ArgValue, PtrOff,
1346 MachinePointerInfo(),
David Greenef6fa1862010-02-15 16:56:10 +00001347 false, false, 0));
Bruno Cardoso Lopes6059b852010-02-06 21:00:02 +00001348
1349 // Record the frame index of the first variable argument
1350 // which is a value necessary to VASTART.
Dan Gohman1e93df62010-04-17 14:41:14 +00001351 if (!MipsFI->getVarArgsFrameIndex())
1352 MipsFI->setVarArgsFrameIndex(FI);
Bruno Cardoso Lopesb37a7422010-02-06 19:20:49 +00001353 }
1354 }
1355
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001356 // All stores are grouped in one node to allow the matching between
Bruno Cardoso Lopesb37a7422010-02-06 19:20:49 +00001357 // the size of Ins and InVals. This only happens when on varg functions
1358 if (!OutChains.empty()) {
1359 OutChains.push_back(Chain);
1360 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
1361 &OutChains[0], OutChains.size());
1362 }
1363
Dan Gohman98ca4f22009-08-05 01:29:28 +00001364 return Chain;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001365}
1366
1367//===----------------------------------------------------------------------===//
1368// Return Value Calling Convention Implementation
1369//===----------------------------------------------------------------------===//
1370
Dan Gohman98ca4f22009-08-05 01:29:28 +00001371SDValue
1372MipsTargetLowering::LowerReturn(SDValue Chain,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +00001373 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman98ca4f22009-08-05 01:29:28 +00001374 const SmallVectorImpl<ISD::OutputArg> &Outs,
Dan Gohmanc9403652010-07-07 15:54:55 +00001375 const SmallVectorImpl<SDValue> &OutVals,
Dan Gohmand858e902010-04-17 15:26:15 +00001376 DebugLoc dl, SelectionDAG &DAG) const {
Dan Gohman98ca4f22009-08-05 01:29:28 +00001377
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001378 // CCValAssign - represent the assignment of
1379 // the return value to a location
1380 SmallVector<CCValAssign, 16> RVLocs;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001381
1382 // CCState - Info about the registers and stack slot.
Dan Gohman98ca4f22009-08-05 01:29:28 +00001383 CCState CCInfo(CallConv, isVarArg, getTargetMachine(),
1384 RVLocs, *DAG.getContext());
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001385
Dan Gohman98ca4f22009-08-05 01:29:28 +00001386 // Analize return values.
1387 CCInfo.AnalyzeReturn(Outs, RetCC_Mips);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001388
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001389 // If this is the first return lowered for this function, add
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001390 // the regs to the liveout set for the function.
Chris Lattner84bc5422007-12-31 04:13:23 +00001391 if (DAG.getMachineFunction().getRegInfo().liveout_empty()) {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001392 for (unsigned i = 0; i != RVLocs.size(); ++i)
Bruno Cardoso Lopes2ab22d12007-07-11 23:16:16 +00001393 if (RVLocs[i].isRegLoc())
Chris Lattner84bc5422007-12-31 04:13:23 +00001394 DAG.getMachineFunction().getRegInfo().addLiveOut(RVLocs[i].getLocReg());
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001395 }
1396
Dan Gohman475871a2008-07-27 21:46:04 +00001397 SDValue Flag;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001398
1399 // Copy the result values into the output registers.
1400 for (unsigned i = 0; i != RVLocs.size(); ++i) {
1401 CCValAssign &VA = RVLocs[i];
1402 assert(VA.isRegLoc() && "Can only return in registers!");
1403
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001404 Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(),
Dan Gohmanc9403652010-07-07 15:54:55 +00001405 OutVals[i], Flag);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001406
1407 // guarantee that all emitted copies are
1408 // stuck together, avoiding something bad
1409 Flag = Chain.getValue(1);
1410 }
1411
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001412 // The mips ABIs for returning structs by value requires that we copy
1413 // the sret argument into $v0 for the return. We saved the argument into
1414 // a virtual register in the entry block, so now we copy the value out
1415 // and into $v0.
1416 if (DAG.getMachineFunction().getFunction()->hasStructRetAttr()) {
1417 MachineFunction &MF = DAG.getMachineFunction();
1418 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
1419 unsigned Reg = MipsFI->getSRetReturnReg();
1420
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001421 if (!Reg)
Torok Edwinc23197a2009-07-14 16:55:14 +00001422 llvm_unreachable("sret virtual register not created in the entry block");
Dale Johannesena05dca42009-02-04 23:02:30 +00001423 SDValue Val = DAG.getCopyFromReg(Chain, dl, Reg, getPointerTy());
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001424
Dale Johannesena05dca42009-02-04 23:02:30 +00001425 Chain = DAG.getCopyToReg(Chain, dl, Mips::V0, Val, Flag);
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001426 Flag = Chain.getValue(1);
1427 }
1428
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001429 // Return on Mips is always a "jr $ra"
Gabor Greifba36cb52008-08-28 21:40:38 +00001430 if (Flag.getNode())
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001431 return DAG.getNode(MipsISD::Ret, dl, MVT::Other,
Owen Anderson825b72b2009-08-11 20:47:22 +00001432 Chain, DAG.getRegister(Mips::RA, MVT::i32), Flag);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001433 else // Return Void
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001434 return DAG.getNode(MipsISD::Ret, dl, MVT::Other,
Owen Anderson825b72b2009-08-11 20:47:22 +00001435 Chain, DAG.getRegister(Mips::RA, MVT::i32));
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001436}
Bruno Cardoso Lopes84f47c52007-08-21 16:09:25 +00001437
1438//===----------------------------------------------------------------------===//
1439// Mips Inline Assembly Support
1440//===----------------------------------------------------------------------===//
1441
1442/// getConstraintType - Given a constraint letter, return the type of
1443/// constraint it is for this target.
1444MipsTargetLowering::ConstraintType MipsTargetLowering::
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001445getConstraintType(const std::string &Constraint) const
Bruno Cardoso Lopes84f47c52007-08-21 16:09:25 +00001446{
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001447 // Mips specific constrainy
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001448 // GCC config/mips/constraints.md
1449 //
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001450 // 'd' : An address register. Equivalent to r
1451 // unless generating MIPS16 code.
1452 // 'y' : Equivalent to r; retained for
1453 // backwards compatibility.
1454 // 'f' : Floating Point registers.
Bruno Cardoso Lopes84f47c52007-08-21 16:09:25 +00001455 if (Constraint.size() == 1) {
Bruno Cardoso Lopes84f47c52007-08-21 16:09:25 +00001456 switch (Constraint[0]) {
1457 default : break;
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001458 case 'd':
1459 case 'y':
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001460 case 'f':
Bruno Cardoso Lopes84f47c52007-08-21 16:09:25 +00001461 return C_RegisterClass;
1462 break;
1463 }
1464 }
1465 return TargetLowering::getConstraintType(Constraint);
1466}
1467
John Thompson44ab89e2010-10-29 17:29:13 +00001468/// Examine constraint type and operand type and determine a weight value.
1469/// This object must already have been set up with the operand type
1470/// and the current alternative constraint selected.
1471TargetLowering::ConstraintWeight
1472MipsTargetLowering::getSingleConstraintMatchWeight(
1473 AsmOperandInfo &info, const char *constraint) const {
1474 ConstraintWeight weight = CW_Invalid;
1475 Value *CallOperandVal = info.CallOperandVal;
1476 // If we don't have a value, we can't do a match,
1477 // but allow it at the lowest weight.
1478 if (CallOperandVal == NULL)
1479 return CW_Default;
1480 const Type *type = CallOperandVal->getType();
1481 // Look at the constraint type.
1482 switch (*constraint) {
1483 default:
1484 weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint);
1485 break;
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001486 case 'd':
1487 case 'y':
John Thompson44ab89e2010-10-29 17:29:13 +00001488 if (type->isIntegerTy())
1489 weight = CW_Register;
1490 break;
1491 case 'f':
1492 if (type->isFloatTy())
1493 weight = CW_Register;
1494 break;
1495 }
1496 return weight;
1497}
1498
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001499/// getRegClassForInlineAsmConstraint - Given a constraint letter (e.g. "r"),
1500/// return a list of registers that can be used to satisfy the constraint.
1501/// This should only be used for C_RegisterClass constraints.
Bruno Cardoso Lopes84f47c52007-08-21 16:09:25 +00001502std::pair<unsigned, const TargetRegisterClass*> MipsTargetLowering::
Owen Andersone50ed302009-08-10 22:56:29 +00001503getRegForInlineAsmConstraint(const std::string &Constraint, EVT VT) const
Bruno Cardoso Lopes84f47c52007-08-21 16:09:25 +00001504{
1505 if (Constraint.size() == 1) {
1506 switch (Constraint[0]) {
1507 case 'r':
1508 return std::make_pair(0U, Mips::CPURegsRegisterClass);
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001509 case 'f':
Owen Anderson825b72b2009-08-11 20:47:22 +00001510 if (VT == MVT::f32)
Bruno Cardoso Lopesbdfbb742009-03-21 00:05:07 +00001511 return std::make_pair(0U, Mips::FGR32RegisterClass);
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001512 if (VT == MVT::f64)
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001513 if ((!Subtarget->isSingleFloat()) && (!Subtarget->isFP64bit()))
1514 return std::make_pair(0U, Mips::AFGR64RegisterClass);
Bruno Cardoso Lopes84f47c52007-08-21 16:09:25 +00001515 }
1516 }
1517 return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT);
1518}
1519
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001520/// Given a register class constraint, like 'r', if this corresponds directly
1521/// to an LLVM register class, return a register of 0 and the register class
1522/// pointer.
Bruno Cardoso Lopes84f47c52007-08-21 16:09:25 +00001523std::vector<unsigned> MipsTargetLowering::
1524getRegClassForInlineAsmConstraint(const std::string &Constraint,
Owen Andersone50ed302009-08-10 22:56:29 +00001525 EVT VT) const
Bruno Cardoso Lopes84f47c52007-08-21 16:09:25 +00001526{
1527 if (Constraint.size() != 1)
1528 return std::vector<unsigned>();
1529
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001530 switch (Constraint[0]) {
Bruno Cardoso Lopes84f47c52007-08-21 16:09:25 +00001531 default : break;
1532 case 'r':
1533 // GCC Mips Constraint Letters
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001534 case 'd':
1535 case 'y':
1536 return make_vector<unsigned>(Mips::T0, Mips::T1, Mips::T2, Mips::T3,
1537 Mips::T4, Mips::T5, Mips::T6, Mips::T7, Mips::S0, Mips::S1,
1538 Mips::S2, Mips::S3, Mips::S4, Mips::S5, Mips::S6, Mips::S7,
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001539 Mips::T8, 0);
1540
1541 case 'f':
Owen Anderson825b72b2009-08-11 20:47:22 +00001542 if (VT == MVT::f32) {
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001543 if (Subtarget->isSingleFloat())
1544 return make_vector<unsigned>(Mips::F2, Mips::F3, Mips::F4, Mips::F5,
1545 Mips::F6, Mips::F7, Mips::F8, Mips::F9, Mips::F10, Mips::F11,
1546 Mips::F20, Mips::F21, Mips::F22, Mips::F23, Mips::F24,
1547 Mips::F25, Mips::F26, Mips::F27, Mips::F28, Mips::F29,
1548 Mips::F30, Mips::F31, 0);
1549 else
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001550 return make_vector<unsigned>(Mips::F2, Mips::F4, Mips::F6, Mips::F8,
1551 Mips::F10, Mips::F20, Mips::F22, Mips::F24, Mips::F26,
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001552 Mips::F28, Mips::F30, 0);
Duncan Sands15126422008-07-08 09:33:14 +00001553 }
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001554
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001555 if (VT == MVT::f64)
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001556 if ((!Subtarget->isSingleFloat()) && (!Subtarget->isFP64bit()))
Wesley Peckbf17cfa2010-11-23 03:31:01 +00001557 return make_vector<unsigned>(Mips::D1, Mips::D2, Mips::D3, Mips::D4,
1558 Mips::D5, Mips::D10, Mips::D11, Mips::D12, Mips::D13,
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001559 Mips::D14, Mips::D15, 0);
Bruno Cardoso Lopes84f47c52007-08-21 16:09:25 +00001560 }
1561 return std::vector<unsigned>();
1562}
Dan Gohman6520e202008-10-18 02:06:02 +00001563
1564bool
1565MipsTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const {
1566 // The Mips target isn't yet aware of offsets.
1567 return false;
1568}
Evan Chengeb2f9692009-10-27 19:56:55 +00001569
Evan Chenga1eaa3c2009-10-28 01:43:28 +00001570bool MipsTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const {
1571 if (VT != MVT::f32 && VT != MVT::f64)
1572 return false;
Evan Chengeb2f9692009-10-27 19:56:55 +00001573 return Imm.isZero();
1574}