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 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 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" |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 20 | #include "MipsSubtarget.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 21 | #include "llvm/DerivedTypes.h" |
| 22 | #include "llvm/Function.h" |
Bruno Cardoso Lopes | 91fd532 | 2008-07-21 18:52:34 +0000 | [diff] [blame^] | 23 | #include "llvm/GlobalVariable.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 24 | #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 Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/SelectionDAGISel.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/ValueTypes.h" |
| 33 | #include "llvm/Support/Debug.h" |
| 34 | #include <queue> |
| 35 | #include <set> |
| 36 | |
| 37 | using namespace llvm; |
| 38 | |
| 39 | const char *MipsTargetLowering:: |
| 40 | getTargetNodeName(unsigned Opcode) const |
| 41 | { |
| 42 | switch (Opcode) |
| 43 | { |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 44 | case MipsISD::JmpLink : return "MipsISD::JmpLink"; |
| 45 | case MipsISD::Hi : return "MipsISD::Hi"; |
| 46 | case MipsISD::Lo : return "MipsISD::Lo"; |
Bruno Cardoso Lopes | 91fd532 | 2008-07-21 18:52:34 +0000 | [diff] [blame^] | 47 | case MipsISD::GPRel : return "MipsISD::GPRel"; |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 48 | case MipsISD::Ret : return "MipsISD::Ret"; |
| 49 | case MipsISD::SelectCC : return "MipsISD::SelectCC"; |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 50 | case MipsISD::FPBrcond : return "MipsISD::FPBrcond"; |
| 51 | case MipsISD::FPCmp : return "MipsISD::FPCmp"; |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 52 | default : return NULL; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | |
| 56 | MipsTargetLowering:: |
| 57 | MipsTargetLowering(MipsTargetMachine &TM): TargetLowering(TM) |
| 58 | { |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 59 | Subtarget = &TM.getSubtarget<MipsSubtarget>(); |
| 60 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 61 | // Mips does not have i1 type, so use i32 for |
| 62 | // setcc operations results (slt, sgt, ...). |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 63 | setSetCCResultContents(ZeroOrOneSetCCResult); |
| 64 | |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 65 | // JumpTable targets must use GOT when using PIC_ |
| 66 | setUsesGlobalOffsetTable(true); |
| 67 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 68 | // Set up the register classes |
| 69 | addRegisterClass(MVT::i32, Mips::CPURegsRegisterClass); |
| 70 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 71 | // When dealing with single precision only, use libcalls |
| 72 | if (!Subtarget->isSingleFloat()) { |
| 73 | addRegisterClass(MVT::f32, Mips::AFGR32RegisterClass); |
| 74 | if (!Subtarget->isFP64bit()) |
| 75 | addRegisterClass(MVT::f64, Mips::AFGR64RegisterClass); |
| 76 | } else |
| 77 | addRegisterClass(MVT::f32, Mips::FGR32RegisterClass); |
| 78 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 79 | // Load extented operations for i1 types must be promoted |
| 80 | setLoadXAction(ISD::EXTLOAD, MVT::i1, Promote); |
| 81 | setLoadXAction(ISD::ZEXTLOAD, MVT::i1, Promote); |
| 82 | setLoadXAction(ISD::SEXTLOAD, MVT::i1, Promote); |
| 83 | |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 84 | // Mips Custom Operations |
| 85 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
| 86 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); |
| 87 | setOperationAction(ISD::RET, MVT::Other, Custom); |
| 88 | setOperationAction(ISD::JumpTable, MVT::i32, Custom); |
| 89 | setOperationAction(ISD::ConstantPool, MVT::f32, Custom); |
| 90 | setOperationAction(ISD::SELECT_CC, MVT::i32, Custom); |
| 91 | setOperationAction(ISD::SELECT_CC, MVT::f32, Custom); |
| 92 | |
| 93 | // Operations not directly supported by Mips. |
Bruno Cardoso Lopes | 85e9212 | 2008-07-07 19:11:24 +0000 | [diff] [blame] | 94 | setOperationAction(ISD::BR_JT, MVT::Other, Expand); |
| 95 | setOperationAction(ISD::BR_CC, MVT::Other, Expand); |
| 96 | setOperationAction(ISD::SELECT_CC, MVT::Other, Expand); |
| 97 | setOperationAction(ISD::SELECT, MVT::i32, Expand); |
| 98 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Expand); |
| 99 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Expand); |
| 100 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 101 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
| 102 | setOperationAction(ISD::CTTZ, MVT::i32, Expand); |
| 103 | setOperationAction(ISD::CTLZ, MVT::i32, Expand); |
| 104 | setOperationAction(ISD::ROTL, MVT::i32, Expand); |
| 105 | setOperationAction(ISD::ROTR, MVT::i32, Expand); |
| 106 | setOperationAction(ISD::BSWAP, MVT::i32, Expand); |
| 107 | setOperationAction(ISD::SHL_PARTS, MVT::i32, Expand); |
| 108 | setOperationAction(ISD::SRA_PARTS, MVT::i32, Expand); |
| 109 | setOperationAction(ISD::SRL_PARTS, MVT::i32, Expand); |
| 110 | |
| 111 | // We don't have line number support yet. |
| 112 | setOperationAction(ISD::DBG_STOPPOINT, MVT::Other, Expand); |
| 113 | setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand); |
| 114 | setOperationAction(ISD::DBG_LABEL, MVT::Other, Expand); |
| 115 | setOperationAction(ISD::EH_LABEL, MVT::Other, Expand); |
| 116 | |
| 117 | // Use the default for now |
| 118 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
| 119 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
| 120 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Expand); |
Bruno Cardoso Lopes | 85e9212 | 2008-07-07 19:11:24 +0000 | [diff] [blame] | 121 | |
| 122 | if (Subtarget->isSingleFloat()) |
| 123 | setOperationAction(ISD::SELECT_CC, MVT::f64, Expand); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 124 | |
Bruno Cardoso Lopes | 7728f7e | 2008-07-09 05:32:22 +0000 | [diff] [blame] | 125 | if (!Subtarget->hasSEInReg()) { |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 126 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 127 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand); |
| 128 | } |
| 129 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 130 | setStackPointerRegisterToSaveRestore(Mips::SP); |
| 131 | computeRegisterProperties(); |
| 132 | } |
| 133 | |
| 134 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 135 | MVT MipsTargetLowering::getSetCCResultType(const SDOperand &) const { |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 136 | return MVT::i32; |
| 137 | } |
| 138 | |
| 139 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 140 | SDOperand MipsTargetLowering:: |
| 141 | LowerOperation(SDOperand Op, SelectionDAG &DAG) |
| 142 | { |
| 143 | switch (Op.getOpcode()) |
| 144 | { |
| 145 | case ISD::CALL: return LowerCALL(Op, DAG); |
| 146 | case ISD::FORMAL_ARGUMENTS: return LowerFORMAL_ARGUMENTS(Op, DAG); |
| 147 | case ISD::RET: return LowerRET(Op, DAG); |
| 148 | case ISD::GlobalAddress: return LowerGlobalAddress(Op, DAG); |
Lauro Ramos Venancio | 75ce010 | 2007-07-11 17:19:51 +0000 | [diff] [blame] | 149 | case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 150 | case ISD::JumpTable: return LowerJumpTable(Op, DAG); |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 151 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 152 | case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 153 | } |
| 154 | return SDOperand(); |
| 155 | } |
| 156 | |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 157 | MachineBasicBlock * |
| 158 | MipsTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
| 159 | MachineBasicBlock *BB) |
| 160 | { |
| 161 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 162 | switch (MI->getOpcode()) { |
| 163 | default: assert(false && "Unexpected instr type to insert"); |
| 164 | case Mips::Select_CC: { |
| 165 | // To "insert" a SELECT_CC instruction, we actually have to insert the |
| 166 | // diamond control-flow pattern. The incoming instruction knows the |
| 167 | // destination vreg to set, the condition code register to branch on, the |
| 168 | // true/false values to select between, and a branch opcode to use. |
| 169 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 170 | MachineFunction::iterator It = BB; |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 171 | ++It; |
| 172 | |
| 173 | // thisMBB: |
| 174 | // ... |
| 175 | // TrueVal = ... |
| 176 | // setcc r1, r2, r3 |
| 177 | // bNE r1, r0, copy1MBB |
| 178 | // fallthrough --> copy0MBB |
| 179 | MachineBasicBlock *thisMBB = BB; |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 180 | MachineFunction *F = BB->getParent(); |
| 181 | MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 182 | MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 183 | BuildMI(BB, TII->get(Mips::BNE)).addReg(MI->getOperand(1).getReg()) |
| 184 | .addReg(Mips::ZERO).addMBB(sinkMBB); |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 185 | F->insert(It, copy0MBB); |
| 186 | F->insert(It, sinkMBB); |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 187 | // Update machine-CFG edges by first adding all successors of the current |
| 188 | // block to the new block which will contain the Phi node for the select. |
| 189 | for(MachineBasicBlock::succ_iterator i = BB->succ_begin(), |
| 190 | e = BB->succ_end(); i != e; ++i) |
| 191 | sinkMBB->addSuccessor(*i); |
| 192 | // Next, remove all successors of the current block, and add the true |
| 193 | // and fallthrough blocks as its successors. |
| 194 | while(!BB->succ_empty()) |
| 195 | BB->removeSuccessor(BB->succ_begin()); |
| 196 | BB->addSuccessor(copy0MBB); |
| 197 | BB->addSuccessor(sinkMBB); |
| 198 | |
| 199 | // copy0MBB: |
| 200 | // %FalseValue = ... |
| 201 | // # fallthrough to sinkMBB |
| 202 | BB = copy0MBB; |
| 203 | |
| 204 | // Update machine-CFG edges |
| 205 | BB->addSuccessor(sinkMBB); |
| 206 | |
| 207 | // sinkMBB: |
| 208 | // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] |
| 209 | // ... |
| 210 | BB = sinkMBB; |
| 211 | BuildMI(BB, TII->get(Mips::PHI), MI->getOperand(0).getReg()) |
| 212 | .addReg(MI->getOperand(2).getReg()).addMBB(copy0MBB) |
| 213 | .addReg(MI->getOperand(3).getReg()).addMBB(thisMBB); |
| 214 | |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 215 | F->DeleteMachineInstr(MI); // The pseudo instruction is gone now. |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 216 | return BB; |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 221 | //===----------------------------------------------------------------------===// |
| 222 | // Lower helper functions |
| 223 | //===----------------------------------------------------------------------===// |
| 224 | |
| 225 | // AddLiveIn - This helper function adds the specified physical register to the |
| 226 | // MachineFunction as a live in value. It also creates a corresponding |
| 227 | // virtual register for it. |
| 228 | static unsigned |
| 229 | AddLiveIn(MachineFunction &MF, unsigned PReg, TargetRegisterClass *RC) |
| 230 | { |
| 231 | assert(RC->contains(PReg) && "Not the correct regclass!"); |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 232 | unsigned VReg = MF.getRegInfo().createVirtualRegister(RC); |
| 233 | MF.getRegInfo().addLiveIn(PReg, VReg); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 234 | return VReg; |
| 235 | } |
| 236 | |
Bruno Cardoso Lopes | 91fd532 | 2008-07-21 18:52:34 +0000 | [diff] [blame^] | 237 | // Discover if this global address can be placed into small data/bss section. |
| 238 | // This should happen for globals with size less than small section size |
| 239 | // threshold in no abicall environments. Data in this section must be addressed |
| 240 | // using gp_rel operator. |
| 241 | bool MipsTargetLowering::IsGlobalInSmallSection(GlobalValue *GV) |
| 242 | { |
| 243 | const TargetData *TD = getTargetData(); |
| 244 | const Value *V = dyn_cast<Value>(GV); |
| 245 | const GlobalVariable *GVA = dyn_cast<GlobalVariable>(V); |
| 246 | |
| 247 | //const PointerType *PTy = GV->getType(); |
| 248 | const Type *Ty = GV->getType()->getElementType(); |
| 249 | unsigned Size = TD->getABITypeSize(Ty); |
| 250 | |
| 251 | // if this is a internal constant string, there is a special |
| 252 | // section for it, but not in small data/bss. |
| 253 | if (GVA->hasInitializer() && GV->hasInternalLinkage()) { |
| 254 | Constant *C = GVA->getInitializer(); |
| 255 | const ConstantArray *CVA = dyn_cast<ConstantArray>(C); |
| 256 | if (CVA && CVA->isCString()) |
| 257 | return false; |
| 258 | } |
| 259 | |
| 260 | if (Size > 0 && (Size <= Subtarget->getSSectionThreshold())) |
| 261 | return true; |
| 262 | |
| 263 | return false; |
| 264 | } |
| 265 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 266 | //===----------------------------------------------------------------------===// |
| 267 | // Misc Lower Operation implementation |
| 268 | //===----------------------------------------------------------------------===// |
| 269 | SDOperand MipsTargetLowering:: |
| 270 | LowerGlobalAddress(SDOperand Op, SelectionDAG &DAG) |
| 271 | { |
| 272 | GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 273 | SDOperand GA = DAG.getTargetGlobalAddress(GV, MVT::i32); |
Bruno Cardoso Lopes | 7ff6fa2 | 2007-08-18 02:16:30 +0000 | [diff] [blame] | 274 | |
Bruno Cardoso Lopes | 91fd532 | 2008-07-21 18:52:34 +0000 | [diff] [blame^] | 275 | if (!Subtarget->hasABICall()) { |
| 276 | if (isa<Function>(GV)) return GA; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 277 | const MVT *VTs = DAG.getNodeValueTypes(MVT::i32); |
Bruno Cardoso Lopes | 8262df3 | 2007-10-09 03:15:11 +0000 | [diff] [blame] | 278 | SDOperand Ops[] = { GA }; |
Bruno Cardoso Lopes | 7ff6fa2 | 2007-08-18 02:16:30 +0000 | [diff] [blame] | 279 | |
Bruno Cardoso Lopes | 91fd532 | 2008-07-21 18:52:34 +0000 | [diff] [blame^] | 280 | if (IsGlobalInSmallSection(GV)) { // %gp_rel relocation |
| 281 | SDOperand GPRelNode = DAG.getNode(MipsISD::GPRel, VTs, 1, Ops, 1); |
| 282 | SDOperand GOT = DAG.getNode(ISD::GLOBAL_OFFSET_TABLE, MVT::i32); |
| 283 | return DAG.getNode(ISD::ADD, MVT::i32, GOT, GPRelNode); |
| 284 | } |
| 285 | // %hi/%lo relocation |
| 286 | SDOperand HiPart = DAG.getNode(MipsISD::Hi, VTs, 1, Ops, 1); |
| 287 | SDOperand Lo = DAG.getNode(MipsISD::Lo, MVT::i32, GA); |
| 288 | return DAG.getNode(ISD::ADD, MVT::i32, HiPart, Lo); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 289 | |
Bruno Cardoso Lopes | 91fd532 | 2008-07-21 18:52:34 +0000 | [diff] [blame^] | 290 | } else { // Abicall relocations, TODO: make this cleaner. |
| 291 | SDOperand ResNode = DAG.getLoad(MVT::i32, DAG.getEntryNode(), GA, NULL, 0); |
| 292 | // On functions and global targets not internal linked only |
| 293 | // a load from got/GP is necessary for PIC to work. |
| 294 | if (!GV->hasInternalLinkage() || isa<Function>(GV)) |
| 295 | return ResNode; |
| 296 | SDOperand Lo = DAG.getNode(MipsISD::Lo, MVT::i32, GA); |
| 297 | return DAG.getNode(ISD::ADD, MVT::i32, ResNode, Lo); |
| 298 | } |
Bruno Cardoso Lopes | 8262df3 | 2007-10-09 03:15:11 +0000 | [diff] [blame] | 299 | |
Bruno Cardoso Lopes | 91fd532 | 2008-07-21 18:52:34 +0000 | [diff] [blame^] | 300 | assert(0 && "Dont know how to handle GlobalAddress"); |
| 301 | return SDOperand(0,0); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | SDOperand MipsTargetLowering:: |
Lauro Ramos Venancio | 75ce010 | 2007-07-11 17:19:51 +0000 | [diff] [blame] | 305 | LowerGlobalTLSAddress(SDOperand Op, SelectionDAG &DAG) |
| 306 | { |
| 307 | assert(0 && "TLS not implemented for MIPS."); |
Chris Lattner | d27c991 | 2008-03-30 18:22:13 +0000 | [diff] [blame] | 308 | return SDOperand(); // Not reached |
Lauro Ramos Venancio | 75ce010 | 2007-07-11 17:19:51 +0000 | [diff] [blame] | 309 | } |
| 310 | |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 311 | SDOperand MipsTargetLowering:: |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 312 | LowerSELECT_CC(SDOperand Op, SelectionDAG &DAG) |
| 313 | { |
| 314 | SDOperand LHS = Op.getOperand(0); |
| 315 | SDOperand RHS = Op.getOperand(1); |
| 316 | SDOperand True = Op.getOperand(2); |
| 317 | SDOperand False = Op.getOperand(3); |
| 318 | SDOperand CC = Op.getOperand(4); |
| 319 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 320 | const MVT *VTs = DAG.getNodeValueTypes(MVT::i32); |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 321 | SDOperand Ops[] = { LHS, RHS, CC }; |
| 322 | SDOperand SetCCRes = DAG.getNode(ISD::SETCC, VTs, 1, Ops, 3); |
| 323 | |
| 324 | return DAG.getNode(MipsISD::SelectCC, True.getValueType(), |
| 325 | SetCCRes, True, False); |
| 326 | } |
| 327 | |
| 328 | SDOperand MipsTargetLowering:: |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 329 | LowerJumpTable(SDOperand Op, SelectionDAG &DAG) |
| 330 | { |
| 331 | SDOperand ResNode; |
| 332 | SDOperand HiPart; |
| 333 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 334 | MVT PtrVT = Op.getValueType(); |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 335 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Op); |
| 336 | SDOperand JTI = DAG.getTargetJumpTable(JT->getIndex(), PtrVT); |
| 337 | |
| 338 | if (getTargetMachine().getRelocationModel() != Reloc::PIC_) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 339 | const MVT *VTs = DAG.getNodeValueTypes(MVT::i32); |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 340 | SDOperand Ops[] = { JTI }; |
| 341 | HiPart = DAG.getNode(MipsISD::Hi, VTs, 1, Ops, 1); |
| 342 | } else // Emit Load from Global Pointer |
| 343 | HiPart = DAG.getLoad(MVT::i32, DAG.getEntryNode(), JTI, NULL, 0); |
| 344 | |
| 345 | SDOperand Lo = DAG.getNode(MipsISD::Lo, MVT::i32, JTI); |
| 346 | ResNode = DAG.getNode(ISD::ADD, MVT::i32, HiPart, Lo); |
| 347 | |
| 348 | return ResNode; |
| 349 | } |
| 350 | |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 351 | SDOperand MipsTargetLowering:: |
| 352 | LowerConstantPool(SDOperand Op, SelectionDAG &DAG) |
| 353 | { |
| 354 | assert(0 && "ConstantPool not implemented for MIPS."); |
| 355 | return SDOperand(); // Not reached |
| 356 | } |
| 357 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 358 | //===----------------------------------------------------------------------===// |
| 359 | // Calling Convention Implementation |
| 360 | // |
| 361 | // The lower operations present on calling convention works on this order: |
| 362 | // LowerCALL (virt regs --> phys regs, virt regs --> stack) |
| 363 | // LowerFORMAL_ARGUMENTS (phys --> virt regs, stack --> virt regs) |
| 364 | // LowerRET (virt regs --> phys regs) |
| 365 | // LowerCALL (phys regs --> virt regs) |
| 366 | // |
| 367 | //===----------------------------------------------------------------------===// |
| 368 | |
| 369 | #include "MipsGenCallingConv.inc" |
| 370 | |
| 371 | //===----------------------------------------------------------------------===// |
| 372 | // CALL Calling Convention Implementation |
| 373 | //===----------------------------------------------------------------------===// |
| 374 | |
| 375 | /// Mips custom CALL implementation |
| 376 | SDOperand MipsTargetLowering:: |
| 377 | LowerCALL(SDOperand Op, SelectionDAG &DAG) |
| 378 | { |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 379 | unsigned CallingConv = cast<ConstantSDNode>(Op.getOperand(1))->getValue(); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 380 | |
| 381 | // By now, only CallingConv::C implemented |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 382 | switch (CallingConv) { |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 383 | default: |
| 384 | assert(0 && "Unsupported calling convention"); |
| 385 | case CallingConv::Fast: |
| 386 | case CallingConv::C: |
| 387 | return LowerCCCCallTo(Op, DAG, CallingConv); |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | /// LowerCCCCallTo - functions arguments are copied from virtual |
| 392 | /// regs to (physical regs)/(stack frame), CALLSEQ_START and |
| 393 | /// CALLSEQ_END are emitted. |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 394 | /// TODO: isVarArg, isTailCall. |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 395 | SDOperand MipsTargetLowering:: |
| 396 | LowerCCCCallTo(SDOperand Op, SelectionDAG &DAG, unsigned CC) |
| 397 | { |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 398 | MachineFunction &MF = DAG.getMachineFunction(); |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 399 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 400 | SDOperand Chain = Op.getOperand(0); |
| 401 | SDOperand Callee = Op.getOperand(4); |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 402 | bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getValue() != 0; |
| 403 | |
| 404 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 405 | |
| 406 | // Analyze operands of the call, assigning locations to each operand. |
| 407 | SmallVector<CCValAssign, 16> ArgLocs; |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 408 | CCState CCInfo(CC, isVarArg, getTargetMachine(), ArgLocs); |
| 409 | |
Bruno Cardoso Lopes | b27cb55 | 2008-07-15 02:03:36 +0000 | [diff] [blame] | 410 | // To meet O32 ABI, Mips must always allocate 16 bytes on |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 411 | // the stack (even if less than 4 are used as arguments) |
Bruno Cardoso Lopes | b27cb55 | 2008-07-15 02:03:36 +0000 | [diff] [blame] | 412 | if (Subtarget->isABI_O32()) { |
| 413 | int VTsize = MVT(MVT::i32).getSizeInBits()/8; |
| 414 | MFI->CreateFixedObject(VTsize, (VTsize*3)); |
| 415 | } |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 416 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 417 | CCInfo.AnalyzeCallOperands(Op.Val, CC_Mips); |
| 418 | |
| 419 | // Get a count of how many bytes are to be pushed on the stack. |
| 420 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 421 | Chain = DAG.getCALLSEQ_START(Chain,DAG.getConstant(NumBytes, |
| 422 | getPointerTy())); |
| 423 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 424 | // With EABI is it possible to have 16 args on registers. |
| 425 | SmallVector<std::pair<unsigned, SDOperand>, 16> RegsToPass; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 426 | SmallVector<SDOperand, 8> MemOpChains; |
| 427 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 428 | // First/LastArgStackLoc contains the first/last |
| 429 | // "at stack" argument location. |
| 430 | int LastArgStackLoc = 0; |
| 431 | unsigned FirstStackArgLoc = (Subtarget->isABI_EABI() ? 0 : 16); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 432 | |
| 433 | // Walk the register/memloc assignments, inserting copies/loads. |
| 434 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 435 | CCValAssign &VA = ArgLocs[i]; |
| 436 | |
| 437 | // Arguments start after the 5 first operands of ISD::CALL |
| 438 | SDOperand Arg = Op.getOperand(5+2*VA.getValNo()); |
| 439 | |
| 440 | // Promote the value if needed. |
| 441 | switch (VA.getLocInfo()) { |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 442 | default: assert(0 && "Unknown loc info!"); |
| 443 | case CCValAssign::Full: break; |
| 444 | case CCValAssign::SExt: |
| 445 | Arg = DAG.getNode(ISD::SIGN_EXTEND, VA.getLocVT(), Arg); |
| 446 | break; |
| 447 | case CCValAssign::ZExt: |
| 448 | Arg = DAG.getNode(ISD::ZERO_EXTEND, VA.getLocVT(), Arg); |
| 449 | break; |
| 450 | case CCValAssign::AExt: |
| 451 | Arg = DAG.getNode(ISD::ANY_EXTEND, VA.getLocVT(), Arg); |
| 452 | break; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 453 | } |
| 454 | |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 455 | // Arguments that can be passed on register must be kept at |
| 456 | // RegsToPass vector |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 457 | if (VA.isRegLoc()) { |
| 458 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 459 | continue; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 460 | } |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 461 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 462 | // Register cant get to this point... |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 463 | assert(VA.isMemLoc()); |
| 464 | |
| 465 | // Create the frame index object for this incoming parameter |
| 466 | // This guarantees that when allocating Local Area the firsts |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 467 | // 16 bytes which are alwayes reserved won't be overwritten |
| 468 | // if O32 ABI is used. For EABI the first address is zero. |
| 469 | LastArgStackLoc = (FirstStackArgLoc + VA.getLocMemOffset()); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 470 | int FI = MFI->CreateFixedObject(VA.getValVT().getSizeInBits()/8, |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 471 | LastArgStackLoc); |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 472 | |
| 473 | SDOperand PtrOff = DAG.getFrameIndex(FI,getPointerTy()); |
| 474 | |
| 475 | // emit ISD::STORE whichs stores the |
| 476 | // parameter value to a stack Location |
| 477 | MemOpChains.push_back(DAG.getStore(Chain, Arg, PtrOff, NULL, 0)); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 480 | // Transform all store nodes into one single node because all store |
| 481 | // nodes are independent of each other. |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 482 | if (!MemOpChains.empty()) |
| 483 | Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, |
| 484 | &MemOpChains[0], MemOpChains.size()); |
| 485 | |
| 486 | // Build a sequence of copy-to-reg nodes chained together with token |
| 487 | // chain and flag operands which copy the outgoing args into registers. |
| 488 | // The InFlag in necessary since all emited instructions must be |
| 489 | // stuck together. |
| 490 | SDOperand InFlag; |
| 491 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 492 | Chain = DAG.getCopyToReg(Chain, RegsToPass[i].first, |
| 493 | RegsToPass[i].second, InFlag); |
| 494 | InFlag = Chain.getValue(1); |
| 495 | } |
| 496 | |
Bruno Cardoso Lopes | 8262df3 | 2007-10-09 03:15:11 +0000 | [diff] [blame] | 497 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
| 498 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 499 | // node so that legalize doesn't hack it. |
| 500 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 501 | Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy()); |
Bruno Cardoso Lopes | 8262df3 | 2007-10-09 03:15:11 +0000 | [diff] [blame] | 502 | else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 503 | Callee = DAG.getTargetExternalSymbol(S->getSymbol(), getPointerTy()); |
| 504 | |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 505 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 506 | // MipsJmpLink = #chain, #target_address, #opt_in_flags... |
| 507 | // = Chain, Callee, Reg#1, Reg#2, ... |
| 508 | // |
| 509 | // Returns a chain & a flag for retval copy to use. |
| 510 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Flag); |
| 511 | SmallVector<SDOperand, 8> Ops; |
| 512 | Ops.push_back(Chain); |
| 513 | Ops.push_back(Callee); |
| 514 | |
| 515 | // Add argument registers to the end of the list so that they are |
| 516 | // known live into the call. |
| 517 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) |
| 518 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 519 | RegsToPass[i].second.getValueType())); |
| 520 | |
| 521 | if (InFlag.Val) |
| 522 | Ops.push_back(InFlag); |
| 523 | |
| 524 | Chain = DAG.getNode(MipsISD::JmpLink, NodeTys, &Ops[0], Ops.size()); |
| 525 | InFlag = Chain.getValue(1); |
| 526 | |
Bruno Cardoso Lopes | d2947ee | 2008-06-04 01:45:25 +0000 | [diff] [blame] | 527 | // Create the CALLSEQ_END node. |
Bruno Cardoso Lopes | bdbb750 | 2008-06-01 03:49:39 +0000 | [diff] [blame] | 528 | Chain = DAG.getCALLSEQ_END(Chain, |
| 529 | DAG.getConstant(NumBytes, getPointerTy()), |
| 530 | DAG.getConstant(0, getPointerTy()), |
| 531 | InFlag); |
| 532 | InFlag = Chain.getValue(1); |
| 533 | |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 534 | // Create a stack location to hold GP when PIC is used. This stack |
| 535 | // location is used on function prologue to save GP and also after all |
| 536 | // emited CALL's to restore GP. |
| 537 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 538 | // Function can have an arbitrary number of calls, so |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 539 | // hold the LastArgStackLoc with the biggest offset. |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 540 | int FI; |
| 541 | MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>(); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 542 | if (LastArgStackLoc >= MipsFI->getGPStackOffset()) { |
| 543 | LastArgStackLoc = (!LastArgStackLoc) ? (16) : (LastArgStackLoc+4); |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 544 | // Create the frame index only once. SPOffset here can be anything |
| 545 | // (this will be fixed on processFunctionBeforeFrameFinalized) |
| 546 | if (MipsFI->getGPStackOffset() == -1) { |
| 547 | FI = MFI->CreateFixedObject(4, 0); |
| 548 | MipsFI->setGPFI(FI); |
| 549 | } |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 550 | MipsFI->setGPStackOffset(LastArgStackLoc); |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 551 | } |
| 552 | |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 553 | // Reload GP value. |
| 554 | FI = MipsFI->getGPFI(); |
| 555 | SDOperand FIN = DAG.getFrameIndex(FI,getPointerTy()); |
| 556 | SDOperand GPLoad = DAG.getLoad(MVT::i32, Chain, FIN, NULL, 0); |
| 557 | Chain = GPLoad.getValue(1); |
| 558 | Chain = DAG.getCopyToReg(Chain, DAG.getRegister(Mips::GP, MVT::i32), |
| 559 | GPLoad, SDOperand(0,0)); |
Bruno Cardoso Lopes | bdbb750 | 2008-06-01 03:49:39 +0000 | [diff] [blame] | 560 | InFlag = Chain.getValue(1); |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 561 | } |
| 562 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 563 | // Handle result values, copying them out of physregs into vregs that we |
| 564 | // return. |
| 565 | return SDOperand(LowerCallResult(Chain, InFlag, Op.Val, CC, DAG), Op.ResNo); |
| 566 | } |
| 567 | |
| 568 | /// LowerCallResult - Lower the result values of an ISD::CALL into the |
| 569 | /// appropriate copies out of appropriate physical registers. This assumes that |
| 570 | /// Chain/InFlag are the input chain/flag to use, and that TheCall is the call |
| 571 | /// being lowered. Returns a SDNode with the same number of values as the |
| 572 | /// ISD::CALL. |
| 573 | SDNode *MipsTargetLowering:: |
| 574 | LowerCallResult(SDOperand Chain, SDOperand InFlag, SDNode *TheCall, |
| 575 | unsigned CallingConv, SelectionDAG &DAG) { |
| 576 | |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 577 | bool isVarArg = cast<ConstantSDNode>(TheCall->getOperand(2))->getValue() != 0; |
| 578 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 579 | // Assign locations to each value returned by this call. |
| 580 | SmallVector<CCValAssign, 16> RVLocs; |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 581 | CCState CCInfo(CallingConv, isVarArg, getTargetMachine(), RVLocs); |
| 582 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 583 | CCInfo.AnalyzeCallResult(TheCall, RetCC_Mips); |
| 584 | SmallVector<SDOperand, 8> ResultVals; |
| 585 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 586 | // Copy all of the result registers out of their specified physreg. |
| 587 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 588 | Chain = DAG.getCopyFromReg(Chain, RVLocs[i].getLocReg(), |
| 589 | RVLocs[i].getValVT(), InFlag).getValue(1); |
| 590 | InFlag = Chain.getValue(2); |
| 591 | ResultVals.push_back(Chain.getValue(0)); |
| 592 | } |
| 593 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 594 | ResultVals.push_back(Chain); |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 595 | |
| 596 | // Merge everything together with a MERGE_VALUES node. |
Duncan Sands | f951620 | 2008-06-30 10:19:09 +0000 | [diff] [blame] | 597 | return DAG.getMergeValues(TheCall->getVTList(), &ResultVals[0], |
| 598 | ResultVals.size()).Val; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | //===----------------------------------------------------------------------===// |
| 602 | // FORMAL_ARGUMENTS Calling Convention Implementation |
| 603 | //===----------------------------------------------------------------------===// |
| 604 | |
| 605 | /// Mips custom FORMAL_ARGUMENTS implementation |
| 606 | SDOperand MipsTargetLowering:: |
| 607 | LowerFORMAL_ARGUMENTS(SDOperand Op, SelectionDAG &DAG) |
| 608 | { |
| 609 | unsigned CC = cast<ConstantSDNode>(Op.getOperand(1))->getValue(); |
| 610 | switch(CC) |
| 611 | { |
| 612 | default: |
| 613 | assert(0 && "Unsupported calling convention"); |
| 614 | case CallingConv::C: |
| 615 | return LowerCCCArguments(Op, DAG); |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | /// LowerCCCArguments - transform physical registers into |
| 620 | /// virtual registers and generate load operations for |
| 621 | /// arguments places on the stack. |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 622 | /// TODO: isVarArg |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 623 | SDOperand MipsTargetLowering:: |
| 624 | LowerCCCArguments(SDOperand Op, SelectionDAG &DAG) |
| 625 | { |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 626 | SDOperand Root = Op.getOperand(0); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 627 | MachineFunction &MF = DAG.getMachineFunction(); |
| 628 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Bruno Cardoso Lopes | a2b1bb5 | 2007-08-28 05:08:16 +0000 | [diff] [blame] | 629 | MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>(); |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 630 | |
| 631 | bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getValue() != 0; |
| 632 | unsigned CC = DAG.getMachineFunction().getFunction()->getCallingConv(); |
| 633 | |
| 634 | unsigned StackReg = MF.getTarget().getRegisterInfo()->getFrameRegister(MF); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 635 | |
Bruno Cardoso Lopes | 91fd532 | 2008-07-21 18:52:34 +0000 | [diff] [blame^] | 636 | // GP must be live into PIC and non-PIC call target. |
| 637 | AddLiveIn(MF, Mips::GP, Mips::CPURegsRegisterClass); |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 638 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 639 | // Assign locations to all of the incoming arguments. |
| 640 | SmallVector<CCValAssign, 16> ArgLocs; |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 641 | CCState CCInfo(CC, isVarArg, getTargetMachine(), ArgLocs); |
| 642 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 643 | CCInfo.AnalyzeFormalArguments(Op.Val, CC_Mips); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 644 | SmallVector<SDOperand, 16> ArgValues; |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 645 | SDOperand StackPtr; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 646 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 647 | unsigned FirstStackArgLoc = (Subtarget->isABI_EABI() ? 0 : 16); |
| 648 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 649 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 650 | |
| 651 | CCValAssign &VA = ArgLocs[i]; |
| 652 | |
| 653 | // Arguments stored on registers |
| 654 | if (VA.isRegLoc()) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 655 | MVT RegVT = VA.getLocVT(); |
Bill Wendling | 06b8c19 | 2008-07-09 05:55:53 +0000 | [diff] [blame] | 656 | TargetRegisterClass *RC = 0; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 657 | |
| 658 | if (RegVT == MVT::i32) |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 659 | RC = Mips::CPURegsRegisterClass; |
| 660 | else if (RegVT == MVT::f32) { |
| 661 | if (Subtarget->isSingleFloat()) |
| 662 | RC = Mips::FGR32RegisterClass; |
| 663 | else |
| 664 | RC = Mips::AFGR32RegisterClass; |
| 665 | } else if (RegVT == MVT::f64) { |
| 666 | if (!Subtarget->isSingleFloat()) |
| 667 | RC = Mips::AFGR64RegisterClass; |
| 668 | } else |
| 669 | assert(0 && "RegVT not supported by FORMAL_ARGUMENTS Lowering"); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 670 | |
| 671 | // Transform the arguments stored on |
| 672 | // physical registers into virtual ones |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 673 | unsigned Reg = AddLiveIn(DAG.getMachineFunction(), VA.getLocReg(), RC); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 674 | SDOperand ArgValue = DAG.getCopyFromReg(Root, Reg, RegVT); |
| 675 | |
| 676 | // If this is an 8 or 16-bit value, it is really passed promoted |
| 677 | // to 32 bits. Insert an assert[sz]ext to capture this, then |
| 678 | // truncate to the right size. |
| 679 | if (VA.getLocInfo() == CCValAssign::SExt) |
| 680 | ArgValue = DAG.getNode(ISD::AssertSext, RegVT, ArgValue, |
| 681 | DAG.getValueType(VA.getValVT())); |
| 682 | else if (VA.getLocInfo() == CCValAssign::ZExt) |
| 683 | ArgValue = DAG.getNode(ISD::AssertZext, RegVT, ArgValue, |
| 684 | DAG.getValueType(VA.getValVT())); |
| 685 | |
| 686 | if (VA.getLocInfo() != CCValAssign::Full) |
| 687 | ArgValue = DAG.getNode(ISD::TRUNCATE, VA.getValVT(), ArgValue); |
| 688 | |
| 689 | ArgValues.push_back(ArgValue); |
| 690 | |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 691 | // To meet ABI, when VARARGS are passed on registers, the registers |
Bruno Cardoso Lopes | a2b1bb5 | 2007-08-28 05:08:16 +0000 | [diff] [blame] | 692 | // must have their values written to the caller stack frame. |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 693 | if ((isVarArg) && (Subtarget->isABI_O32())) { |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 694 | if (StackPtr.Val == 0) |
| 695 | StackPtr = DAG.getRegister(StackReg, getPointerTy()); |
| 696 | |
Bruno Cardoso Lopes | a2b1bb5 | 2007-08-28 05:08:16 +0000 | [diff] [blame] | 697 | // The stack pointer offset is relative to the caller stack frame. |
| 698 | // Since the real stack size is unknown here, a negative SPOffset |
| 699 | // is used so there's a way to adjust these offsets when the stack |
| 700 | // size get known (on EliminateFrameIndex). A dummy SPOffset is |
| 701 | // used instead of a direct negative address (which is recorded to |
| 702 | // be used on emitPrologue) to avoid mis-calc of the first stack |
| 703 | // offset on PEI::calculateFrameObjectOffsets. |
| 704 | // Arguments are always 32-bit. |
| 705 | int FI = MFI->CreateFixedObject(4, 0); |
| 706 | MipsFI->recordStoreVarArgsFI(FI, -(4+(i*4))); |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 707 | SDOperand PtrOff = DAG.getFrameIndex(FI, getPointerTy()); |
| 708 | |
| 709 | // emit ISD::STORE whichs stores the |
| 710 | // parameter value to a stack Location |
| 711 | ArgValues.push_back(DAG.getStore(Root, ArgValue, PtrOff, NULL, 0)); |
| 712 | } |
| 713 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 714 | } else { // VA.isRegLoc() |
| 715 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 716 | // sanity check |
| 717 | assert(VA.isMemLoc()); |
| 718 | |
Bruno Cardoso Lopes | a2b1bb5 | 2007-08-28 05:08:16 +0000 | [diff] [blame] | 719 | // The stack pointer offset is relative to the caller stack frame. |
| 720 | // Since the real stack size is unknown here, a negative SPOffset |
| 721 | // is used so there's a way to adjust these offsets when the stack |
| 722 | // size get known (on EliminateFrameIndex). A dummy SPOffset is |
| 723 | // used instead of a direct negative address (which is recorded to |
| 724 | // be used on emitPrologue) to avoid mis-calc of the first stack |
| 725 | // offset on PEI::calculateFrameObjectOffsets. |
| 726 | // Arguments are always 32-bit. |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 727 | unsigned ArgSize = VA.getLocVT().getSizeInBits()/8; |
| 728 | int FI = MFI->CreateFixedObject(ArgSize, 0); |
| 729 | MipsFI->recordLoadArgsFI(FI, -(ArgSize+ |
| 730 | (FirstStackArgLoc + VA.getLocMemOffset()))); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 731 | |
| 732 | // Create load nodes to retrieve arguments from the stack |
| 733 | SDOperand FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 734 | ArgValues.push_back(DAG.getLoad(VA.getValVT(), Root, FIN, NULL, 0)); |
| 735 | } |
| 736 | } |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 737 | |
| 738 | // The mips ABIs for returning structs by value requires that we copy |
| 739 | // the sret argument into $v0 for the return. Save the argument into |
| 740 | // a virtual register so that we can access it from the return points. |
| 741 | if (DAG.getMachineFunction().getFunction()->hasStructRetAttr()) { |
| 742 | unsigned Reg = MipsFI->getSRetReturnReg(); |
| 743 | if (!Reg) { |
| 744 | Reg = MF.getRegInfo().createVirtualRegister(getRegClassFor(MVT::i32)); |
| 745 | MipsFI->setSRetReturnReg(Reg); |
| 746 | } |
| 747 | SDOperand Copy = DAG.getCopyToReg(DAG.getEntryNode(), Reg, ArgValues[0]); |
| 748 | Root = DAG.getNode(ISD::TokenFactor, MVT::Other, Copy, Root); |
| 749 | } |
| 750 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 751 | ArgValues.push_back(Root); |
| 752 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 753 | // Return the new list of results. |
Duncan Sands | f951620 | 2008-06-30 10:19:09 +0000 | [diff] [blame] | 754 | return DAG.getMergeValues(Op.Val->getVTList(), &ArgValues[0], |
| 755 | ArgValues.size()).getValue(Op.ResNo); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | //===----------------------------------------------------------------------===// |
| 759 | // Return Value Calling Convention Implementation |
| 760 | //===----------------------------------------------------------------------===// |
| 761 | |
| 762 | SDOperand MipsTargetLowering:: |
| 763 | LowerRET(SDOperand Op, SelectionDAG &DAG) |
| 764 | { |
| 765 | // CCValAssign - represent the assignment of |
| 766 | // the return value to a location |
| 767 | SmallVector<CCValAssign, 16> RVLocs; |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 768 | unsigned CC = DAG.getMachineFunction().getFunction()->getCallingConv(); |
| 769 | bool isVarArg = DAG.getMachineFunction().getFunction()->isVarArg(); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 770 | |
| 771 | // CCState - Info about the registers and stack slot. |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 772 | CCState CCInfo(CC, isVarArg, getTargetMachine(), RVLocs); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 773 | |
| 774 | // Analize return values of ISD::RET |
| 775 | CCInfo.AnalyzeReturn(Op.Val, RetCC_Mips); |
| 776 | |
| 777 | // If this is the first return lowered for this function, add |
| 778 | // the regs to the liveout set for the function. |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 779 | if (DAG.getMachineFunction().getRegInfo().liveout_empty()) { |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 780 | for (unsigned i = 0; i != RVLocs.size(); ++i) |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 781 | if (RVLocs[i].isRegLoc()) |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 782 | DAG.getMachineFunction().getRegInfo().addLiveOut(RVLocs[i].getLocReg()); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | // The chain is always operand #0 |
| 786 | SDOperand Chain = Op.getOperand(0); |
| 787 | SDOperand Flag; |
| 788 | |
| 789 | // Copy the result values into the output registers. |
| 790 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 791 | CCValAssign &VA = RVLocs[i]; |
| 792 | assert(VA.isRegLoc() && "Can only return in registers!"); |
| 793 | |
| 794 | // ISD::RET => ret chain, (regnum1,val1), ... |
| 795 | // So i*2+1 index only the regnums |
Bruno Cardoso Lopes | 8262df3 | 2007-10-09 03:15:11 +0000 | [diff] [blame] | 796 | 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] | 797 | |
| 798 | // guarantee that all emitted copies are |
| 799 | // stuck together, avoiding something bad |
| 800 | Flag = Chain.getValue(1); |
| 801 | } |
| 802 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 803 | // The mips ABIs for returning structs by value requires that we copy |
| 804 | // the sret argument into $v0 for the return. We saved the argument into |
| 805 | // a virtual register in the entry block, so now we copy the value out |
| 806 | // and into $v0. |
| 807 | if (DAG.getMachineFunction().getFunction()->hasStructRetAttr()) { |
| 808 | MachineFunction &MF = DAG.getMachineFunction(); |
| 809 | MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>(); |
| 810 | unsigned Reg = MipsFI->getSRetReturnReg(); |
| 811 | |
| 812 | if (!Reg) |
| 813 | assert(0 && "sret virtual register not created in the entry block"); |
| 814 | SDOperand Val = DAG.getCopyFromReg(Chain, Reg, getPointerTy()); |
| 815 | |
| 816 | Chain = DAG.getCopyToReg(Chain, Mips::V0, Val, Flag); |
| 817 | Flag = Chain.getValue(1); |
| 818 | } |
| 819 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 820 | // Return on Mips is always a "jr $ra" |
| 821 | if (Flag.Val) |
| 822 | return DAG.getNode(MipsISD::Ret, MVT::Other, |
Bruno Cardoso Lopes | 8262df3 | 2007-10-09 03:15:11 +0000 | [diff] [blame] | 823 | Chain, DAG.getRegister(Mips::RA, MVT::i32), Flag); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 824 | else // Return Void |
| 825 | return DAG.getNode(MipsISD::Ret, MVT::Other, |
Bruno Cardoso Lopes | 8262df3 | 2007-10-09 03:15:11 +0000 | [diff] [blame] | 826 | Chain, DAG.getRegister(Mips::RA, MVT::i32)); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 827 | } |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 828 | |
| 829 | //===----------------------------------------------------------------------===// |
| 830 | // Mips Inline Assembly Support |
| 831 | //===----------------------------------------------------------------------===// |
| 832 | |
| 833 | /// getConstraintType - Given a constraint letter, return the type of |
| 834 | /// constraint it is for this target. |
| 835 | MipsTargetLowering::ConstraintType MipsTargetLowering:: |
| 836 | getConstraintType(const std::string &Constraint) const |
| 837 | { |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 838 | // Mips specific constrainy |
| 839 | // GCC config/mips/constraints.md |
| 840 | // |
| 841 | // 'd' : An address register. Equivalent to r |
| 842 | // unless generating MIPS16 code. |
| 843 | // 'y' : Equivalent to r; retained for |
| 844 | // backwards compatibility. |
Bruno Cardoso Lopes | 7b76da1 | 2008-07-09 04:45:36 +0000 | [diff] [blame] | 845 | // 'f' : Floating Point registers. |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 846 | if (Constraint.size() == 1) { |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 847 | switch (Constraint[0]) { |
| 848 | default : break; |
| 849 | case 'd': |
| 850 | case 'y': |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 851 | case 'f': |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 852 | return C_RegisterClass; |
| 853 | break; |
| 854 | } |
| 855 | } |
| 856 | return TargetLowering::getConstraintType(Constraint); |
| 857 | } |
| 858 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 859 | /// getRegClassForInlineAsmConstraint - Given a constraint letter (e.g. "r"), |
| 860 | /// return a list of registers that can be used to satisfy the constraint. |
| 861 | /// This should only be used for C_RegisterClass constraints. |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 862 | std::pair<unsigned, const TargetRegisterClass*> MipsTargetLowering:: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 863 | getRegForInlineAsmConstraint(const std::string &Constraint, MVT VT) const |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 864 | { |
| 865 | if (Constraint.size() == 1) { |
| 866 | switch (Constraint[0]) { |
| 867 | case 'r': |
| 868 | return std::make_pair(0U, Mips::CPURegsRegisterClass); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 869 | case 'f': |
Duncan Sands | 1512642 | 2008-07-08 09:33:14 +0000 | [diff] [blame] | 870 | if (VT == MVT::f32) { |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 871 | if (Subtarget->isSingleFloat()) |
| 872 | return std::make_pair(0U, Mips::FGR32RegisterClass); |
| 873 | else |
| 874 | return std::make_pair(0U, Mips::AFGR32RegisterClass); |
Duncan Sands | 1512642 | 2008-07-08 09:33:14 +0000 | [diff] [blame] | 875 | } |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 876 | if (VT == MVT::f64) |
| 877 | if ((!Subtarget->isSingleFloat()) && (!Subtarget->isFP64bit())) |
| 878 | return std::make_pair(0U, Mips::AFGR64RegisterClass); |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 879 | } |
| 880 | } |
| 881 | return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); |
| 882 | } |
| 883 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 884 | /// Given a register class constraint, like 'r', if this corresponds directly |
| 885 | /// to an LLVM register class, return a register of 0 and the register class |
| 886 | /// pointer. |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 887 | std::vector<unsigned> MipsTargetLowering:: |
| 888 | getRegClassForInlineAsmConstraint(const std::string &Constraint, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 889 | MVT VT) const |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 890 | { |
| 891 | if (Constraint.size() != 1) |
| 892 | return std::vector<unsigned>(); |
| 893 | |
| 894 | switch (Constraint[0]) { |
| 895 | default : break; |
| 896 | case 'r': |
| 897 | // GCC Mips Constraint Letters |
| 898 | case 'd': |
| 899 | case 'y': |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 900 | return make_vector<unsigned>(Mips::T0, Mips::T1, Mips::T2, Mips::T3, |
| 901 | Mips::T4, Mips::T5, Mips::T6, Mips::T7, Mips::S0, Mips::S1, |
| 902 | Mips::S2, Mips::S3, Mips::S4, Mips::S5, Mips::S6, Mips::S7, |
| 903 | Mips::T8, 0); |
| 904 | |
| 905 | case 'f': |
Duncan Sands | 1512642 | 2008-07-08 09:33:14 +0000 | [diff] [blame] | 906 | if (VT == MVT::f32) { |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 907 | if (Subtarget->isSingleFloat()) |
| 908 | return make_vector<unsigned>(Mips::F2, Mips::F3, Mips::F4, Mips::F5, |
| 909 | Mips::F6, Mips::F7, Mips::F8, Mips::F9, Mips::F10, Mips::F11, |
| 910 | Mips::F20, Mips::F21, Mips::F22, Mips::F23, Mips::F24, |
| 911 | Mips::F25, Mips::F26, Mips::F27, Mips::F28, Mips::F29, |
| 912 | Mips::F30, Mips::F31, 0); |
| 913 | else |
| 914 | return make_vector<unsigned>(Mips::F2, Mips::F4, Mips::F6, Mips::F8, |
| 915 | Mips::F10, Mips::F20, Mips::F22, Mips::F24, Mips::F26, |
| 916 | Mips::F28, Mips::F30, 0); |
Duncan Sands | 1512642 | 2008-07-08 09:33:14 +0000 | [diff] [blame] | 917 | } |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 918 | |
| 919 | if (VT == MVT::f64) |
| 920 | if ((!Subtarget->isSingleFloat()) && (!Subtarget->isFP64bit())) |
| 921 | return make_vector<unsigned>(Mips::D1, Mips::D2, Mips::D3, Mips::D4, |
| 922 | Mips::D5, Mips::D10, Mips::D11, Mips::D12, Mips::D13, |
| 923 | Mips::D14, Mips::D15, 0); |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 924 | } |
| 925 | return std::vector<unsigned>(); |
| 926 | } |