blob: 06218a0ecfab5025e65bc9655c60a6750a1174eb [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- MipsISelLowering.cpp - Mips DAG Lowering Implementation -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Bruno Cardoso Lopes and is distributed under the
6// University of Illinois Open Source License. See LICENSE.TXT for details.
7//
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"
16
17#include "MipsISelLowering.h"
18#include "MipsTargetMachine.h"
19#include "llvm/DerivedTypes.h"
20#include "llvm/Function.h"
21#include "llvm/Intrinsics.h"
22#include "llvm/CallingConv.h"
Bruno Cardoso Lopes753b0552007-08-21 16:09:25 +000023#include "llvm/ADT/VectorExtras.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000024#include "llvm/CodeGen/CallingConvLower.h"
25#include "llvm/CodeGen/MachineFrameInfo.h"
26#include "llvm/CodeGen/MachineFunction.h"
27#include "llvm/CodeGen/MachineInstrBuilder.h"
28#include "llvm/CodeGen/SelectionDAGISel.h"
29#include "llvm/CodeGen/SSARegMap.h"
30#include "llvm/CodeGen/ValueTypes.h"
31#include "llvm/Support/Debug.h"
32#include <queue>
33#include <set>
34
35using namespace llvm;
36
37const char *MipsTargetLowering::
38getTargetNodeName(unsigned Opcode) const
39{
40 switch (Opcode)
41 {
42 case MipsISD::JmpLink : return "MipsISD::JmpLink";
43 case MipsISD::Hi : return "MipsISD::Hi";
44 case MipsISD::Lo : return "MipsISD::Lo";
45 case MipsISD::Ret : return "MipsISD::Ret";
Bruno Cardoso Lopes77ba7152007-08-18 02:16:30 +000046 case MipsISD::Add : return "MipsISD::Add";
Dan Gohmanf17a25c2007-07-18 16:29:46 +000047 default : return NULL;
48 }
49}
50
51MipsTargetLowering::
52MipsTargetLowering(MipsTargetMachine &TM): TargetLowering(TM)
53{
54 // Mips does not have i1 type, so use i32 for
55 // setcc operations results (slt, sgt, ...).
56 setSetCCResultType(MVT::i32);
57 setSetCCResultContents(ZeroOrOneSetCCResult);
58
59 // Set up the register classes
60 addRegisterClass(MVT::i32, Mips::CPURegsRegisterClass);
61
62 // Custom
63 setOperationAction(ISD::GlobalAddress, MVT::i32, Custom);
64 setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom);
65 setOperationAction(ISD::RET, MVT::Other, Custom);
66
67 // Load extented operations for i1 types must be promoted
68 setLoadXAction(ISD::EXTLOAD, MVT::i1, Promote);
69 setLoadXAction(ISD::ZEXTLOAD, MVT::i1, Promote);
70 setLoadXAction(ISD::SEXTLOAD, MVT::i1, Promote);
71
72 // Store operations for i1 types must be promoted
73 setStoreXAction(MVT::i1, Promote);
74
75 // Mips does not have these NodeTypes below.
76 setOperationAction(ISD::BR_JT, MVT::Other, Expand);
77 setOperationAction(ISD::BR_CC, MVT::Other, Expand);
78 setOperationAction(ISD::SELECT_CC, MVT::Other, Expand);
79 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand);
80 setOperationAction(ISD::SELECT, MVT::i32, Expand);
81
82 // Mips not supported intrinsics.
83 setOperationAction(ISD::MEMMOVE, MVT::Other, Expand);
84 setOperationAction(ISD::MEMSET, MVT::Other, Expand);
85 setOperationAction(ISD::MEMCPY, MVT::Other, Expand);
86
87 setOperationAction(ISD::CTPOP, MVT::i32, Expand);
88 setOperationAction(ISD::CTTZ , MVT::i32, Expand);
89 setOperationAction(ISD::CTLZ , MVT::i32, Expand);
90 setOperationAction(ISD::ROTL , MVT::i32, Expand);
91 setOperationAction(ISD::ROTR , MVT::i32, Expand);
92 setOperationAction(ISD::BSWAP, MVT::i32, Expand);
93
94 setOperationAction(ISD::SHL_PARTS, MVT::i32, Expand);
95 setOperationAction(ISD::SRA_PARTS, MVT::i32, Expand);
96 setOperationAction(ISD::SRL_PARTS, MVT::i32, Expand);
97
98 // We don't have line number support yet.
99 setOperationAction(ISD::LOCATION, MVT::Other, Expand);
100 setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand);
101 setOperationAction(ISD::LABEL, MVT::Other, Expand);
102
103 // Use the default for now
104 setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
105 setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
106
Duncan Sands38947cd2007-07-27 12:58:54 +0000107 setOperationAction(ISD::ADJUST_TRAMP, MVT::i32, Expand);
108
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000109 setStackPointerRegisterToSaveRestore(Mips::SP);
110 computeRegisterProperties();
111}
112
113
114SDOperand MipsTargetLowering::
115LowerOperation(SDOperand Op, SelectionDAG &DAG)
116{
117 switch (Op.getOpcode())
118 {
119 case ISD::CALL: return LowerCALL(Op, DAG);
120 case ISD::FORMAL_ARGUMENTS: return LowerFORMAL_ARGUMENTS(Op, DAG);
121 case ISD::RET: return LowerRET(Op, DAG);
122 case ISD::GlobalAddress: return LowerGlobalAddress(Op, DAG);
123 case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000124 }
125 return SDOperand();
126}
127
128//===----------------------------------------------------------------------===//
129// Lower helper functions
130//===----------------------------------------------------------------------===//
131
132// AddLiveIn - This helper function adds the specified physical register to the
133// MachineFunction as a live in value. It also creates a corresponding
134// virtual register for it.
135static unsigned
136AddLiveIn(MachineFunction &MF, unsigned PReg, TargetRegisterClass *RC)
137{
138 assert(RC->contains(PReg) && "Not the correct regclass!");
139 unsigned VReg = MF.getSSARegMap()->createVirtualRegister(RC);
140 MF.addLiveIn(PReg, VReg);
141 return VReg;
142}
143
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000144//===----------------------------------------------------------------------===//
145// Misc Lower Operation implementation
146//===----------------------------------------------------------------------===//
147SDOperand MipsTargetLowering::
148LowerGlobalAddress(SDOperand Op, SelectionDAG &DAG)
149{
150 GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
151
152 SDOperand GA = DAG.getTargetGlobalAddress(GV, MVT::i32);
Bruno Cardoso Lopes77ba7152007-08-18 02:16:30 +0000153
154 const MVT::ValueType *VTs = DAG.getNodeValueTypes(MVT::i32, MVT::Flag);
155 SDOperand Ops[] = { GA };
156
157 SDOperand Hi = DAG.getNode(MipsISD::Hi, VTs, 2, Ops, 1);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000158 SDOperand Lo = DAG.getNode(MipsISD::Lo, MVT::i32, GA);
159
Bruno Cardoso Lopes77ba7152007-08-18 02:16:30 +0000160 SDOperand InFlag = Hi.getValue(1);
161 return DAG.getNode(MipsISD::Add, MVT::i32, Lo, Hi, InFlag);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000162}
163
164SDOperand MipsTargetLowering::
165LowerGlobalTLSAddress(SDOperand Op, SelectionDAG &DAG)
166{
167 assert(0 && "TLS not implemented for MIPS.");
168}
169
170//===----------------------------------------------------------------------===//
171// Calling Convention Implementation
172//
173// The lower operations present on calling convention works on this order:
174// LowerCALL (virt regs --> phys regs, virt regs --> stack)
175// LowerFORMAL_ARGUMENTS (phys --> virt regs, stack --> virt regs)
176// LowerRET (virt regs --> phys regs)
177// LowerCALL (phys regs --> virt regs)
178//
179//===----------------------------------------------------------------------===//
180
181#include "MipsGenCallingConv.inc"
182
183//===----------------------------------------------------------------------===//
184// CALL Calling Convention Implementation
185//===----------------------------------------------------------------------===//
186
187/// Mips custom CALL implementation
188SDOperand MipsTargetLowering::
189LowerCALL(SDOperand Op, SelectionDAG &DAG)
190{
191 unsigned CallingConv= cast<ConstantSDNode>(Op.getOperand(1))->getValue();
192
193 // By now, only CallingConv::C implemented
194 switch (CallingConv)
195 {
196 default:
197 assert(0 && "Unsupported calling convention");
198 case CallingConv::Fast:
199 case CallingConv::C:
200 return LowerCCCCallTo(Op, DAG, CallingConv);
201 }
202}
203
204/// LowerCCCCallTo - functions arguments are copied from virtual
205/// regs to (physical regs)/(stack frame), CALLSEQ_START and
206/// CALLSEQ_END are emitted.
207/// TODO: isVarArg, isTailCall, sret, GOT, linkage types.
208SDOperand MipsTargetLowering::
209LowerCCCCallTo(SDOperand Op, SelectionDAG &DAG, unsigned CC)
210{
211 MachineFunction &MF = DAG.getMachineFunction();
212 unsigned StackReg = MF.getTarget().getRegisterInfo()->getFrameRegister(MF);
213
214 SDOperand Chain = Op.getOperand(0);
215 SDOperand Callee = Op.getOperand(4);
216 bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getValue() != 0;
217
218 MachineFrameInfo *MFI = MF.getFrameInfo();
219
220 // Analyze operands of the call, assigning locations to each operand.
221 SmallVector<CCValAssign, 16> ArgLocs;
222 CCState CCInfo(CC, isVarArg, getTargetMachine(), ArgLocs);
223
224 // To meet ABI, Mips must always allocate 16 bytes on
225 // the stack (even if less than 4 are used as arguments)
226 int VTsize = MVT::getSizeInBits(MVT::i32)/8;
227 MFI->CreateFixedObject(VTsize, -(VTsize*3));
228
229 CCInfo.AnalyzeCallOperands(Op.Val, CC_Mips);
230
231 // Get a count of how many bytes are to be pushed on the stack.
232 unsigned NumBytes = CCInfo.getNextStackOffset();
233 Chain = DAG.getCALLSEQ_START(Chain,DAG.getConstant(NumBytes,
234 getPointerTy()));
235
236 SmallVector<std::pair<unsigned, SDOperand>, 8> RegsToPass;
237 SmallVector<SDOperand, 8> MemOpChains;
238
239 SDOperand StackPtr;
240
241 // Walk the register/memloc assignments, inserting copies/loads.
242 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
243 CCValAssign &VA = ArgLocs[i];
244
245 // Arguments start after the 5 first operands of ISD::CALL
246 SDOperand Arg = Op.getOperand(5+2*VA.getValNo());
247
248 // Promote the value if needed.
249 switch (VA.getLocInfo()) {
250 default: assert(0 && "Unknown loc info!");
251 case CCValAssign::Full: break;
252 case CCValAssign::SExt:
253 Arg = DAG.getNode(ISD::SIGN_EXTEND, VA.getLocVT(), Arg);
254 break;
255 case CCValAssign::ZExt:
256 Arg = DAG.getNode(ISD::ZERO_EXTEND, VA.getLocVT(), Arg);
257 break;
258 case CCValAssign::AExt:
259 Arg = DAG.getNode(ISD::ANY_EXTEND, VA.getLocVT(), Arg);
260 break;
261 }
262
263 // Arguments that can be passed on register,
264 // must be kept at RegsToPass vector
265 if (VA.isRegLoc()) {
266 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
267 } else {
268
269 assert(VA.isMemLoc());
270
271 if (StackPtr.Val == 0)
272 StackPtr = DAG.getRegister(StackReg, getPointerTy());
273
274 // Create the frame index object for this incoming parameter
275 // This guarantees that when allocating Local Area our room
276 // will not be overwritten.
277 int FI = MFI->CreateFixedObject(MVT::getSizeInBits(VA.getValVT())/8,
278 -(16 + VA.getLocMemOffset()) );
279
280 SDOperand PtrOff = DAG.getFrameIndex(FI,getPointerTy());
281
282 // emit ISD::STORE whichs stores the
283 // parameter value to a stack Location
284 MemOpChains.push_back(DAG.getStore(Chain, Arg, PtrOff, NULL, 0));
285 }
286 }
287
288 // Transform all store nodes into one single node because
289 // all store nodes are independent of each other.
290 if (!MemOpChains.empty())
291 Chain = DAG.getNode(ISD::TokenFactor, MVT::Other,
292 &MemOpChains[0], MemOpChains.size());
293
294 // Build a sequence of copy-to-reg nodes chained together with token
295 // chain and flag operands which copy the outgoing args into registers.
296 // The InFlag in necessary since all emited instructions must be
297 // stuck together.
298 SDOperand InFlag;
299 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
300 Chain = DAG.getCopyToReg(Chain, RegsToPass[i].first,
301 RegsToPass[i].second, InFlag);
302 InFlag = Chain.getValue(1);
303 }
304
305 // If the callee is a GlobalAddress node (quite common, every direct
306 // call is) turn it into a TargetGlobalAddress node so that legalize
307 // doesn't hack it.
308 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
309 Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy());
310 } else
311 if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee))
312 Callee = DAG.getTargetExternalSymbol(S->getSymbol(), getPointerTy());
313
314 // MipsJmpLink = #chain, #target_address, #opt_in_flags...
315 // = Chain, Callee, Reg#1, Reg#2, ...
316 //
317 // Returns a chain & a flag for retval copy to use.
318 SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Flag);
319 SmallVector<SDOperand, 8> Ops;
320 Ops.push_back(Chain);
321 Ops.push_back(Callee);
322
323 // Add argument registers to the end of the list so that they are
324 // known live into the call.
325 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i)
326 Ops.push_back(DAG.getRegister(RegsToPass[i].first,
327 RegsToPass[i].second.getValueType()));
328
329 if (InFlag.Val)
330 Ops.push_back(InFlag);
331
332 Chain = DAG.getNode(MipsISD::JmpLink, NodeTys, &Ops[0], Ops.size());
333 InFlag = Chain.getValue(1);
334
335 // Create the CALLSEQ_END node.
336 NodeTys = DAG.getVTList(MVT::Other, MVT::Flag);
337 Ops.clear();
338 Ops.push_back(Chain);
339 Ops.push_back(DAG.getConstant(NumBytes, getPointerTy()));
340 Ops.push_back(InFlag);
341 Chain = DAG.getNode(ISD::CALLSEQ_END, NodeTys, &Ops[0], Ops.size());
342 InFlag = Chain.getValue(1);
343
344 // Handle result values, copying them out of physregs into vregs that we
345 // return.
346 return SDOperand(LowerCallResult(Chain, InFlag, Op.Val, CC, DAG), Op.ResNo);
347}
348
349/// LowerCallResult - Lower the result values of an ISD::CALL into the
350/// appropriate copies out of appropriate physical registers. This assumes that
351/// Chain/InFlag are the input chain/flag to use, and that TheCall is the call
352/// being lowered. Returns a SDNode with the same number of values as the
353/// ISD::CALL.
354SDNode *MipsTargetLowering::
355LowerCallResult(SDOperand Chain, SDOperand InFlag, SDNode *TheCall,
356 unsigned CallingConv, SelectionDAG &DAG) {
357
358 bool isVarArg = cast<ConstantSDNode>(TheCall->getOperand(2))->getValue() != 0;
359
360 // Assign locations to each value returned by this call.
361 SmallVector<CCValAssign, 16> RVLocs;
362 CCState CCInfo(CallingConv, isVarArg, getTargetMachine(), RVLocs);
363
364 CCInfo.AnalyzeCallResult(TheCall, RetCC_Mips);
365 SmallVector<SDOperand, 8> ResultVals;
366
367 // Returns void
Bruno Cardoso Lopes77ba7152007-08-18 02:16:30 +0000368 //if (!RVLocs.size())
369 // return Chain.Val;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000370
371 // Copy all of the result registers out of their specified physreg.
372 for (unsigned i = 0; i != RVLocs.size(); ++i) {
373 Chain = DAG.getCopyFromReg(Chain, RVLocs[i].getLocReg(),
374 RVLocs[i].getValVT(), InFlag).getValue(1);
375 InFlag = Chain.getValue(2);
376 ResultVals.push_back(Chain.getValue(0));
377 }
378
379 // Merge everything together with a MERGE_VALUES node.
380 ResultVals.push_back(Chain);
381 return DAG.getNode(ISD::MERGE_VALUES, TheCall->getVTList(),
382 &ResultVals[0], ResultVals.size()).Val;
383}
384
385//===----------------------------------------------------------------------===//
386// FORMAL_ARGUMENTS Calling Convention Implementation
387//===----------------------------------------------------------------------===//
388
389/// Mips custom FORMAL_ARGUMENTS implementation
390SDOperand MipsTargetLowering::
391LowerFORMAL_ARGUMENTS(SDOperand Op, SelectionDAG &DAG)
392{
393 unsigned CC = cast<ConstantSDNode>(Op.getOperand(1))->getValue();
394 switch(CC)
395 {
396 default:
397 assert(0 && "Unsupported calling convention");
398 case CallingConv::C:
399 return LowerCCCArguments(Op, DAG);
400 }
401}
402
403/// LowerCCCArguments - transform physical registers into
404/// virtual registers and generate load operations for
405/// arguments places on the stack.
406/// TODO: isVarArg, sret
407SDOperand MipsTargetLowering::
408LowerCCCArguments(SDOperand Op, SelectionDAG &DAG)
409{
410 SDOperand Root = Op.getOperand(0);
411 MachineFunction &MF = DAG.getMachineFunction();
412 MachineFrameInfo *MFI = MF.getFrameInfo();
413
414 bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getValue() != 0;
415 unsigned CC = DAG.getMachineFunction().getFunction()->getCallingConv();
416
417 unsigned StackReg = MF.getTarget().getRegisterInfo()->getFrameRegister(MF);
418
419 // Assign locations to all of the incoming arguments.
420 SmallVector<CCValAssign, 16> ArgLocs;
421 CCState CCInfo(CC, isVarArg, getTargetMachine(), ArgLocs);
422
423 CCInfo.AnalyzeFormalArguments(Op.Val, CC_Mips);
424 SmallVector<SDOperand, 8> ArgValues;
425 SDOperand StackPtr;
426
427 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
428
429 CCValAssign &VA = ArgLocs[i];
430
431 // Arguments stored on registers
432 if (VA.isRegLoc()) {
433 MVT::ValueType RegVT = VA.getLocVT();
434 TargetRegisterClass *RC;
435
436 if (RegVT == MVT::i32)
437 RC = Mips::CPURegsRegisterClass;
438 else
439 assert(0 && "support only Mips::CPURegsRegisterClass");
440
441
442 // Transform the arguments stored on
443 // physical registers into virtual ones
444 unsigned Reg = AddLiveIn(DAG.getMachineFunction(), VA.getLocReg(), RC);
445 SDOperand ArgValue = DAG.getCopyFromReg(Root, Reg, RegVT);
446
447 // If this is an 8 or 16-bit value, it is really passed promoted
448 // to 32 bits. Insert an assert[sz]ext to capture this, then
449 // truncate to the right size.
450 if (VA.getLocInfo() == CCValAssign::SExt)
451 ArgValue = DAG.getNode(ISD::AssertSext, RegVT, ArgValue,
452 DAG.getValueType(VA.getValVT()));
453 else if (VA.getLocInfo() == CCValAssign::ZExt)
454 ArgValue = DAG.getNode(ISD::AssertZext, RegVT, ArgValue,
455 DAG.getValueType(VA.getValVT()));
456
457 if (VA.getLocInfo() != CCValAssign::Full)
458 ArgValue = DAG.getNode(ISD::TRUNCATE, VA.getValVT(), ArgValue);
459
460 ArgValues.push_back(ArgValue);
461
462 // To meet ABI, when VARARGS are passed on registers, the registers
463 // containt must be written to the their always reserved home location
464 // on the stack.
465 if (isVarArg) {
466
467 if (StackPtr.Val == 0)
468 StackPtr = DAG.getRegister(StackReg, getPointerTy());
469
470 // Create the frame index object for this incoming parameter
471 // The first 16 bytes are reserved.
472 int FI = MFI->CreateFixedObject(MVT::getSizeInBits(VA.getValVT())/8,
473 i*4);
474 SDOperand PtrOff = DAG.getFrameIndex(FI, getPointerTy());
475
476 // emit ISD::STORE whichs stores the
477 // parameter value to a stack Location
478 ArgValues.push_back(DAG.getStore(Root, ArgValue, PtrOff, NULL, 0));
479 }
480
481 } else {
482 // sanity check
483 assert(VA.isMemLoc());
484
485 // Create the frame index object for this incoming parameter...
486 int FI = MFI->CreateFixedObject(MVT::getSizeInBits(VA.getValVT())/8,
487 (16 + VA.getLocMemOffset()));
488
489 // Create load nodes to retrieve arguments from the stack
490 SDOperand FIN = DAG.getFrameIndex(FI, getPointerTy());
491 ArgValues.push_back(DAG.getLoad(VA.getValVT(), Root, FIN, NULL, 0));
492 }
493 }
494 ArgValues.push_back(Root);
495
496 // Return the new list of results.
497 return DAG.getNode(ISD::MERGE_VALUES, Op.Val->getVTList(),
498 &ArgValues[0], ArgValues.size()).getValue(Op.ResNo);
499}
500
501//===----------------------------------------------------------------------===//
502// Return Value Calling Convention Implementation
503//===----------------------------------------------------------------------===//
504
505SDOperand MipsTargetLowering::
506LowerRET(SDOperand Op, SelectionDAG &DAG)
507{
508 // CCValAssign - represent the assignment of
509 // the return value to a location
510 SmallVector<CCValAssign, 16> RVLocs;
511 unsigned CC = DAG.getMachineFunction().getFunction()->getCallingConv();
512 bool isVarArg = DAG.getMachineFunction().getFunction()->isVarArg();
513
514 // CCState - Info about the registers and stack slot.
515 CCState CCInfo(CC, isVarArg, getTargetMachine(), RVLocs);
516
517 // Analize return values of ISD::RET
518 CCInfo.AnalyzeReturn(Op.Val, RetCC_Mips);
519
520 // If this is the first return lowered for this function, add
521 // the regs to the liveout set for the function.
522 if (DAG.getMachineFunction().liveout_empty()) {
523 for (unsigned i = 0; i != RVLocs.size(); ++i)
524 if (RVLocs[i].isRegLoc())
525 DAG.getMachineFunction().addLiveOut(RVLocs[i].getLocReg());
526 }
527
528 // The chain is always operand #0
529 SDOperand Chain = Op.getOperand(0);
530 SDOperand Flag;
531
532 // Copy the result values into the output registers.
533 for (unsigned i = 0; i != RVLocs.size(); ++i) {
534 CCValAssign &VA = RVLocs[i];
535 assert(VA.isRegLoc() && "Can only return in registers!");
536
537 // ISD::RET => ret chain, (regnum1,val1), ...
538 // So i*2+1 index only the regnums
539 Chain = DAG.getCopyToReg(Chain, VA.getLocReg(),
540 Op.getOperand(i*2+1), Flag);
541
542 // guarantee that all emitted copies are
543 // stuck together, avoiding something bad
544 Flag = Chain.getValue(1);
545 }
546
547 // Return on Mips is always a "jr $ra"
548 if (Flag.Val)
549 return DAG.getNode(MipsISD::Ret, MVT::Other,
550 Chain, DAG.getRegister(Mips::RA, MVT::i32), Flag);
551 else // Return Void
552 return DAG.getNode(MipsISD::Ret, MVT::Other,
553 Chain, DAG.getRegister(Mips::RA, MVT::i32));
554}
Bruno Cardoso Lopes753b0552007-08-21 16:09:25 +0000555
556//===----------------------------------------------------------------------===//
557// Mips Inline Assembly Support
558//===----------------------------------------------------------------------===//
559
560/// getConstraintType - Given a constraint letter, return the type of
561/// constraint it is for this target.
562MipsTargetLowering::ConstraintType MipsTargetLowering::
563getConstraintType(const std::string &Constraint) const
564{
565 if (Constraint.size() == 1) {
566 // Mips specific constrainy
567 // GCC config/mips/constraints.md
568 //
569 // 'd' : An address register. Equivalent to r
570 // unless generating MIPS16 code.
571 // 'y' : Equivalent to r; retained for
572 // backwards compatibility.
573 //
574 switch (Constraint[0]) {
575 default : break;
576 case 'd':
577 case 'y':
578 return C_RegisterClass;
579 break;
580 }
581 }
582 return TargetLowering::getConstraintType(Constraint);
583}
584
585std::pair<unsigned, const TargetRegisterClass*> MipsTargetLowering::
586getRegForInlineAsmConstraint(const std::string &Constraint,
587 MVT::ValueType VT) const
588{
589 if (Constraint.size() == 1) {
590 switch (Constraint[0]) {
591 case 'r':
592 return std::make_pair(0U, Mips::CPURegsRegisterClass);
593 break;
594 }
595 }
596 return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT);
597}
598
599std::vector<unsigned> MipsTargetLowering::
600getRegClassForInlineAsmConstraint(const std::string &Constraint,
601 MVT::ValueType VT) const
602{
603 if (Constraint.size() != 1)
604 return std::vector<unsigned>();
605
606 switch (Constraint[0]) {
607 default : break;
608 case 'r':
609 // GCC Mips Constraint Letters
610 case 'd':
611 case 'y':
612 return make_vector<unsigned>(Mips::V0, Mips::V1, Mips::A0,
613 Mips::A1, Mips::A2, Mips::A3,
614 Mips::T0, Mips::T1, Mips::T2,
615 Mips::T3, Mips::T4, Mips::T5,
616 Mips::T6, Mips::T7, Mips::S0,
617 Mips::S1, Mips::S2, Mips::S3,
618 Mips::S4, Mips::S5, Mips::S6,
619 Mips::S7, Mips::T8, Mips::T9, 0);
620 break;
621 }
622 return std::vector<unsigned>();
623}