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