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" |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 34 | #include "llvm/Support/ErrorHandling.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 35 | using namespace llvm; |
| 36 | |
| 37 | const char *MipsTargetLowering:: |
| 38 | getTargetNodeName(unsigned Opcode) const |
| 39 | { |
| 40 | switch (Opcode) |
| 41 | { |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +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::GPRel : return "MipsISD::GPRel"; |
| 46 | case MipsISD::Ret : return "MipsISD::Ret"; |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 47 | case MipsISD::CMov : return "MipsISD::CMov"; |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 48 | case MipsISD::SelectCC : return "MipsISD::SelectCC"; |
| 49 | case MipsISD::FPSelectCC : return "MipsISD::FPSelectCC"; |
| 50 | case MipsISD::FPBrcond : return "MipsISD::FPBrcond"; |
| 51 | case MipsISD::FPCmp : return "MipsISD::FPCmp"; |
Bruno Cardoso Lopes | d3bdf19 | 2009-05-27 17:23:44 +0000 | [diff] [blame] | 52 | case MipsISD::FPRound : return "MipsISD::FPRound"; |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 53 | default : return NULL; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | |
| 57 | MipsTargetLowering:: |
| 58 | MipsTargetLowering(MipsTargetMachine &TM): TargetLowering(TM) |
| 59 | { |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 60 | Subtarget = &TM.getSubtarget<MipsSubtarget>(); |
| 61 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 62 | // Mips does not have i1 type, so use i32 for |
| 63 | // setcc operations results (slt, sgt, ...). |
Duncan Sands | 0322808 | 2008-11-23 15:47:28 +0000 | [diff] [blame] | 64 | setBooleanContents(ZeroOrOneBooleanContent); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 65 | |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 66 | // JumpTable targets must use GOT when using PIC_ |
| 67 | setUsesGlobalOffsetTable(true); |
| 68 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 69 | // Set up the register classes |
| 70 | addRegisterClass(MVT::i32, Mips::CPURegsRegisterClass); |
Bruno Cardoso Lopes | bdfbb74 | 2009-03-21 00:05:07 +0000 | [diff] [blame] | 71 | addRegisterClass(MVT::f32, Mips::FGR32RegisterClass); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 72 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 73 | // When dealing with single precision only, use libcalls |
Bruno Cardoso Lopes | bdfbb74 | 2009-03-21 00:05:07 +0000 | [diff] [blame] | 74 | if (!Subtarget->isSingleFloat()) |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 75 | if (!Subtarget->isFP64bit()) |
| 76 | addRegisterClass(MVT::f64, Mips::AFGR64RegisterClass); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 77 | |
Bruno Cardoso Lopes | 7030ae7 | 2008-07-30 19:00:31 +0000 | [diff] [blame] | 78 | // Legal fp constants |
| 79 | addLegalFPImmediate(APFloat(+0.0f)); |
| 80 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 81 | // Load extented operations for i1 types must be promoted |
Evan Cheng | 0329466 | 2008-10-14 21:26:46 +0000 | [diff] [blame] | 82 | setLoadExtAction(ISD::EXTLOAD, MVT::i1, Promote); |
| 83 | setLoadExtAction(ISD::ZEXTLOAD, MVT::i1, Promote); |
| 84 | setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 85 | |
Eli Friedman | 6055a6a | 2009-07-17 04:07:24 +0000 | [diff] [blame] | 86 | // MIPS doesn't have extending float->double load/store |
Eli Friedman | 10a3659 | 2009-07-17 02:28:12 +0000 | [diff] [blame] | 87 | setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand); |
Eli Friedman | 6055a6a | 2009-07-17 04:07:24 +0000 | [diff] [blame] | 88 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
Eli Friedman | 10a3659 | 2009-07-17 02:28:12 +0000 | [diff] [blame] | 89 | |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 90 | // Used by legalize types to correctly generate the setcc result. |
Bruno Cardoso Lopes | 1906c5a | 2008-08-02 19:37:33 +0000 | [diff] [blame] | 91 | // Without this, every float setcc comes with a AND/OR with the result, |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 92 | // we don't want this, since the fpcmp result goes to a flag register, |
| 93 | // which is used implicitly by brcond and select operations. |
| 94 | AddPromotedToType(ISD::SETCC, MVT::i1, MVT::i32); |
| 95 | |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 96 | // Mips Custom Operations |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 97 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
| 98 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); |
| 99 | setOperationAction(ISD::RET, MVT::Other, Custom); |
| 100 | setOperationAction(ISD::JumpTable, MVT::i32, Custom); |
| 101 | setOperationAction(ISD::ConstantPool, MVT::i32, Custom); |
| 102 | setOperationAction(ISD::SELECT, MVT::f32, Custom); |
Eli Friedman | 6314ac2 | 2009-06-16 06:40:59 +0000 | [diff] [blame] | 103 | setOperationAction(ISD::SELECT, MVT::f64, Custom); |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 104 | setOperationAction(ISD::SELECT, MVT::i32, Custom); |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 105 | setOperationAction(ISD::SETCC, MVT::f32, Custom); |
Bruno Cardoso Lopes | d3bdf19 | 2009-05-27 17:23:44 +0000 | [diff] [blame] | 106 | setOperationAction(ISD::SETCC, MVT::f64, Custom); |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 107 | setOperationAction(ISD::BRCOND, MVT::Other, Custom); |
| 108 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Custom); |
Bruno Cardoso Lopes | d3bdf19 | 2009-05-27 17:23:44 +0000 | [diff] [blame] | 109 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 110 | |
Bruno Cardoso Lopes | 1906c5a | 2008-08-02 19:37:33 +0000 | [diff] [blame] | 111 | // We custom lower AND/OR to handle the case where the DAG contain 'ands/ors' |
| 112 | // with operands comming from setcc fp comparions. This is necessary since |
| 113 | // the result from these setcc are in a flag registers (FCR31). |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 114 | setOperationAction(ISD::AND, MVT::i32, Custom); |
Bruno Cardoso Lopes | 1906c5a | 2008-08-02 19:37:33 +0000 | [diff] [blame] | 115 | setOperationAction(ISD::OR, MVT::i32, Custom); |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 116 | |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 117 | // Operations not directly supported by Mips. |
Bruno Cardoso Lopes | 85e9212 | 2008-07-07 19:11:24 +0000 | [diff] [blame] | 118 | setOperationAction(ISD::BR_JT, MVT::Other, Expand); |
| 119 | setOperationAction(ISD::BR_CC, MVT::Other, Expand); |
| 120 | setOperationAction(ISD::SELECT_CC, MVT::Other, Expand); |
Bruno Cardoso Lopes | 85e9212 | 2008-07-07 19:11:24 +0000 | [diff] [blame] | 121 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Expand); |
| 122 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Expand); |
| 123 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 124 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
| 125 | setOperationAction(ISD::CTTZ, MVT::i32, Expand); |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 126 | setOperationAction(ISD::ROTL, MVT::i32, Expand); |
Eli Friedman | 10a3659 | 2009-07-17 02:28:12 +0000 | [diff] [blame] | 127 | setOperationAction(ISD::ROTR, MVT::i32, Expand); |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 128 | setOperationAction(ISD::SHL_PARTS, MVT::i32, Expand); |
| 129 | setOperationAction(ISD::SRA_PARTS, MVT::i32, Expand); |
| 130 | setOperationAction(ISD::SRL_PARTS, MVT::i32, Expand); |
Bruno Cardoso Lopes | 7bd7182 | 2008-07-31 18:50:54 +0000 | [diff] [blame] | 131 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Expand); |
Eli Friedman | 6314ac2 | 2009-06-16 06:40:59 +0000 | [diff] [blame] | 132 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Expand); |
Eli Friedman | 10a3659 | 2009-07-17 02:28:12 +0000 | [diff] [blame] | 133 | setOperationAction(ISD::FSIN, MVT::f32, Expand); |
| 134 | setOperationAction(ISD::FCOS, MVT::f32, Expand); |
| 135 | setOperationAction(ISD::FPOWI, MVT::f32, Expand); |
| 136 | setOperationAction(ISD::FPOW, MVT::f32, Expand); |
| 137 | setOperationAction(ISD::FLOG, MVT::f32, Expand); |
| 138 | setOperationAction(ISD::FLOG2, MVT::f32, Expand); |
| 139 | setOperationAction(ISD::FLOG10, MVT::f32, Expand); |
| 140 | setOperationAction(ISD::FEXP, MVT::f32, Expand); |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 141 | |
| 142 | // We don't have line number support yet. |
| 143 | setOperationAction(ISD::DBG_STOPPOINT, MVT::Other, Expand); |
| 144 | setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand); |
| 145 | setOperationAction(ISD::DBG_LABEL, MVT::Other, Expand); |
| 146 | setOperationAction(ISD::EH_LABEL, MVT::Other, Expand); |
| 147 | |
| 148 | // Use the default for now |
| 149 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
| 150 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
| 151 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Expand); |
Bruno Cardoso Lopes | 85e9212 | 2008-07-07 19:11:24 +0000 | [diff] [blame] | 152 | |
Bruno Cardoso Lopes | ea9d4d6 | 2008-08-04 06:44:31 +0000 | [diff] [blame] | 153 | if (Subtarget->isSingleFloat()) |
Bruno Cardoso Lopes | 85e9212 | 2008-07-07 19:11:24 +0000 | [diff] [blame] | 154 | setOperationAction(ISD::SELECT_CC, MVT::f64, Expand); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 155 | |
Bruno Cardoso Lopes | 7728f7e | 2008-07-09 05:32:22 +0000 | [diff] [blame] | 156 | if (!Subtarget->hasSEInReg()) { |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 157 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 158 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand); |
| 159 | } |
| 160 | |
Bruno Cardoso Lopes | 65ad452 | 2008-08-08 06:16:31 +0000 | [diff] [blame] | 161 | if (!Subtarget->hasBitCount()) |
| 162 | setOperationAction(ISD::CTLZ, MVT::i32, Expand); |
| 163 | |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 164 | if (!Subtarget->hasSwap()) |
| 165 | setOperationAction(ISD::BSWAP, MVT::i32, Expand); |
| 166 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 167 | setStackPointerRegisterToSaveRestore(Mips::SP); |
| 168 | computeRegisterProperties(); |
| 169 | } |
| 170 | |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 171 | MVT MipsTargetLowering::getSetCCResultType(MVT VT) const { |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 172 | return MVT::i32; |
| 173 | } |
| 174 | |
Bill Wendling | b4202b8 | 2009-07-01 18:50:55 +0000 | [diff] [blame] | 175 | /// getFunctionAlignment - Return the Log2 alignment of this function. |
Bill Wendling | 20c568f | 2009-06-30 22:38:32 +0000 | [diff] [blame] | 176 | unsigned MipsTargetLowering::getFunctionAlignment(const Function *) const { |
| 177 | return 2; |
| 178 | } |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 179 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 180 | SDValue MipsTargetLowering:: |
| 181 | LowerOperation(SDValue Op, SelectionDAG &DAG) |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 182 | { |
| 183 | switch (Op.getOpcode()) |
| 184 | { |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 185 | case ISD::AND: return LowerANDOR(Op, DAG); |
| 186 | case ISD::BRCOND: return LowerBRCOND(Op, DAG); |
| 187 | case ISD::CALL: return LowerCALL(Op, DAG); |
| 188 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
| 189 | case ISD::DYNAMIC_STACKALLOC: return LowerDYNAMIC_STACKALLOC(Op, DAG); |
| 190 | case ISD::FORMAL_ARGUMENTS: return LowerFORMAL_ARGUMENTS(Op, DAG); |
Bruno Cardoso Lopes | d3bdf19 | 2009-05-27 17:23:44 +0000 | [diff] [blame] | 191 | case ISD::FP_TO_SINT: return LowerFP_TO_SINT(Op, DAG); |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 192 | case ISD::GlobalAddress: return LowerGlobalAddress(Op, DAG); |
| 193 | case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); |
| 194 | case ISD::JumpTable: return LowerJumpTable(Op, DAG); |
| 195 | case ISD::OR: return LowerANDOR(Op, DAG); |
| 196 | case ISD::RET: return LowerRET(Op, DAG); |
| 197 | case ISD::SELECT: return LowerSELECT(Op, DAG); |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 198 | case ISD::SETCC: return LowerSETCC(Op, DAG); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 199 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 200 | return SDValue(); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | //===----------------------------------------------------------------------===// |
| 204 | // Lower helper functions |
| 205 | //===----------------------------------------------------------------------===// |
| 206 | |
| 207 | // AddLiveIn - This helper function adds the specified physical register to the |
| 208 | // MachineFunction as a live in value. It also creates a corresponding |
| 209 | // virtual register for it. |
| 210 | static unsigned |
| 211 | AddLiveIn(MachineFunction &MF, unsigned PReg, TargetRegisterClass *RC) |
| 212 | { |
| 213 | assert(RC->contains(PReg) && "Not the correct regclass!"); |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 214 | unsigned VReg = MF.getRegInfo().createVirtualRegister(RC); |
| 215 | MF.getRegInfo().addLiveIn(PReg, VReg); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 216 | return VReg; |
| 217 | } |
| 218 | |
Bruno Cardoso Lopes | 92e87f2 | 2008-07-23 16:01:50 +0000 | [diff] [blame] | 219 | // A address must be loaded from a small section if its size is less than the |
| 220 | // small section size threshold. Data in this section must be addressed using |
| 221 | // gp_rel operator. |
| 222 | bool MipsTargetLowering::IsInSmallSection(unsigned Size) { |
| 223 | return (Size > 0 && (Size <= Subtarget->getSSectionThreshold())); |
| 224 | } |
| 225 | |
Bruno Cardoso Lopes | 91fd532 | 2008-07-21 18:52:34 +0000 | [diff] [blame] | 226 | // Discover if this global address can be placed into small data/bss section. |
Bruno Cardoso Lopes | 91fd532 | 2008-07-21 18:52:34 +0000 | [diff] [blame] | 227 | bool MipsTargetLowering::IsGlobalInSmallSection(GlobalValue *GV) |
| 228 | { |
| 229 | const TargetData *TD = getTargetData(); |
Bruno Cardoso Lopes | feb95cc | 2008-07-22 15:34:27 +0000 | [diff] [blame] | 230 | const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV); |
| 231 | |
| 232 | if (!GVA) |
| 233 | return false; |
Bruno Cardoso Lopes | 91fd532 | 2008-07-21 18:52:34 +0000 | [diff] [blame] | 234 | |
Bruno Cardoso Lopes | 91fd532 | 2008-07-21 18:52:34 +0000 | [diff] [blame] | 235 | const Type *Ty = GV->getType()->getElementType(); |
Duncan Sands | 777d230 | 2009-05-09 07:06:46 +0000 | [diff] [blame] | 236 | unsigned Size = TD->getTypeAllocSize(Ty); |
Bruno Cardoso Lopes | 91fd532 | 2008-07-21 18:52:34 +0000 | [diff] [blame] | 237 | |
| 238 | // if this is a internal constant string, there is a special |
| 239 | // section for it, but not in small data/bss. |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 240 | if (GVA->hasInitializer() && GV->hasLocalLinkage()) { |
Bruno Cardoso Lopes | 91fd532 | 2008-07-21 18:52:34 +0000 | [diff] [blame] | 241 | Constant *C = GVA->getInitializer(); |
| 242 | const ConstantArray *CVA = dyn_cast<ConstantArray>(C); |
Owen Anderson | 1ca29d3 | 2009-07-13 21:27:19 +0000 | [diff] [blame] | 243 | if (CVA && CVA->isCString()) |
Bruno Cardoso Lopes | 91fd532 | 2008-07-21 18:52:34 +0000 | [diff] [blame] | 244 | return false; |
| 245 | } |
| 246 | |
Bruno Cardoso Lopes | 92e87f2 | 2008-07-23 16:01:50 +0000 | [diff] [blame] | 247 | return IsInSmallSection(Size); |
Bruno Cardoso Lopes | 91fd532 | 2008-07-21 18:52:34 +0000 | [diff] [blame] | 248 | } |
| 249 | |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 250 | // Get fp branch code (not opcode) from condition code. |
| 251 | static Mips::FPBranchCode GetFPBranchCodeFromCond(Mips::CondCode CC) { |
| 252 | if (CC >= Mips::FCOND_F && CC <= Mips::FCOND_NGT) |
| 253 | return Mips::BRANCH_T; |
| 254 | |
| 255 | if (CC >= Mips::FCOND_T && CC <= Mips::FCOND_GT) |
| 256 | return Mips::BRANCH_F; |
| 257 | |
| 258 | return Mips::BRANCH_INVALID; |
| 259 | } |
| 260 | |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 261 | static unsigned FPBranchCodeToOpc(Mips::FPBranchCode BC) { |
| 262 | switch(BC) { |
| 263 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 264 | llvm_unreachable("Unknown branch code"); |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 265 | case Mips::BRANCH_T : return Mips::BC1T; |
| 266 | case Mips::BRANCH_F : return Mips::BC1F; |
| 267 | case Mips::BRANCH_TL : return Mips::BC1TL; |
| 268 | case Mips::BRANCH_FL : return Mips::BC1FL; |
| 269 | } |
| 270 | } |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 271 | |
| 272 | static Mips::CondCode FPCondCCodeToFCC(ISD::CondCode CC) { |
| 273 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 274 | default: llvm_unreachable("Unknown fp condition code!"); |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 275 | case ISD::SETEQ: |
| 276 | case ISD::SETOEQ: return Mips::FCOND_EQ; |
| 277 | case ISD::SETUNE: return Mips::FCOND_OGL; |
| 278 | case ISD::SETLT: |
| 279 | case ISD::SETOLT: return Mips::FCOND_OLT; |
| 280 | case ISD::SETGT: |
| 281 | case ISD::SETOGT: return Mips::FCOND_OGT; |
| 282 | case ISD::SETLE: |
| 283 | case ISD::SETOLE: return Mips::FCOND_OLE; |
| 284 | case ISD::SETGE: |
| 285 | case ISD::SETOGE: return Mips::FCOND_OGE; |
| 286 | case ISD::SETULT: return Mips::FCOND_ULT; |
| 287 | case ISD::SETULE: return Mips::FCOND_ULE; |
| 288 | case ISD::SETUGT: return Mips::FCOND_UGT; |
| 289 | case ISD::SETUGE: return Mips::FCOND_UGE; |
| 290 | case ISD::SETUO: return Mips::FCOND_UN; |
| 291 | case ISD::SETO: return Mips::FCOND_OR; |
| 292 | case ISD::SETNE: |
| 293 | case ISD::SETONE: return Mips::FCOND_NEQ; |
| 294 | case ISD::SETUEQ: return Mips::FCOND_UEQ; |
| 295 | } |
| 296 | } |
| 297 | |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 298 | MachineBasicBlock * |
| 299 | MipsTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
Dan Gohman | 1fdbc1d | 2009-02-07 16:15:20 +0000 | [diff] [blame] | 300 | MachineBasicBlock *BB) const { |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 301 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 302 | bool isFPCmp = false; |
Dale Johannesen | 9481757 | 2009-02-13 02:34:39 +0000 | [diff] [blame] | 303 | DebugLoc dl = MI->getDebugLoc(); |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 304 | |
| 305 | switch (MI->getOpcode()) { |
| 306 | default: assert(false && "Unexpected instr type to insert"); |
| 307 | case Mips::Select_FCC: |
Bruno Cardoso Lopes | bdfbb74 | 2009-03-21 00:05:07 +0000 | [diff] [blame] | 308 | case Mips::Select_FCC_S32: |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 309 | case Mips::Select_FCC_D32: |
| 310 | isFPCmp = true; // FALL THROUGH |
| 311 | case Mips::Select_CC: |
Bruno Cardoso Lopes | bdfbb74 | 2009-03-21 00:05:07 +0000 | [diff] [blame] | 312 | case Mips::Select_CC_S32: |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 313 | case Mips::Select_CC_D32: { |
| 314 | // To "insert" a SELECT_CC instruction, we actually have to insert the |
| 315 | // diamond control-flow pattern. The incoming instruction knows the |
| 316 | // destination vreg to set, the condition code register to branch on, the |
| 317 | // true/false values to select between, and a branch opcode to use. |
| 318 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 319 | MachineFunction::iterator It = BB; |
| 320 | ++It; |
| 321 | |
| 322 | // thisMBB: |
| 323 | // ... |
| 324 | // TrueVal = ... |
| 325 | // setcc r1, r2, r3 |
| 326 | // bNE r1, r0, copy1MBB |
| 327 | // fallthrough --> copy0MBB |
| 328 | MachineBasicBlock *thisMBB = BB; |
| 329 | MachineFunction *F = BB->getParent(); |
| 330 | MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 331 | MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 332 | |
| 333 | // Emit the right instruction according to the type of the operands compared |
| 334 | if (isFPCmp) { |
| 335 | // Find the condiction code present in the setcc operation. |
| 336 | Mips::CondCode CC = (Mips::CondCode)MI->getOperand(4).getImm(); |
| 337 | // Get the branch opcode from the branch code. |
| 338 | unsigned Opc = FPBranchCodeToOpc(GetFPBranchCodeFromCond(CC)); |
Dale Johannesen | 9481757 | 2009-02-13 02:34:39 +0000 | [diff] [blame] | 339 | BuildMI(BB, dl, TII->get(Opc)).addMBB(sinkMBB); |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 340 | } else |
Dale Johannesen | 9481757 | 2009-02-13 02:34:39 +0000 | [diff] [blame] | 341 | BuildMI(BB, dl, TII->get(Mips::BNE)).addReg(MI->getOperand(1).getReg()) |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 342 | .addReg(Mips::ZERO).addMBB(sinkMBB); |
| 343 | |
| 344 | F->insert(It, copy0MBB); |
| 345 | F->insert(It, sinkMBB); |
| 346 | // Update machine-CFG edges by first adding all successors of the current |
| 347 | // block to the new block which will contain the Phi node for the select. |
| 348 | for(MachineBasicBlock::succ_iterator i = BB->succ_begin(), |
| 349 | e = BB->succ_end(); i != e; ++i) |
| 350 | sinkMBB->addSuccessor(*i); |
| 351 | // Next, remove all successors of the current block, and add the true |
| 352 | // and fallthrough blocks as its successors. |
| 353 | while(!BB->succ_empty()) |
| 354 | BB->removeSuccessor(BB->succ_begin()); |
| 355 | BB->addSuccessor(copy0MBB); |
| 356 | BB->addSuccessor(sinkMBB); |
| 357 | |
| 358 | // copy0MBB: |
| 359 | // %FalseValue = ... |
| 360 | // # fallthrough to sinkMBB |
| 361 | BB = copy0MBB; |
| 362 | |
| 363 | // Update machine-CFG edges |
| 364 | BB->addSuccessor(sinkMBB); |
| 365 | |
| 366 | // sinkMBB: |
| 367 | // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] |
| 368 | // ... |
| 369 | BB = sinkMBB; |
Dale Johannesen | 9481757 | 2009-02-13 02:34:39 +0000 | [diff] [blame] | 370 | BuildMI(BB, dl, TII->get(Mips::PHI), MI->getOperand(0).getReg()) |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 371 | .addReg(MI->getOperand(2).getReg()).addMBB(copy0MBB) |
| 372 | .addReg(MI->getOperand(3).getReg()).addMBB(thisMBB); |
| 373 | |
| 374 | F->DeleteMachineInstr(MI); // The pseudo instruction is gone now. |
| 375 | return BB; |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 380 | //===----------------------------------------------------------------------===// |
| 381 | // Misc Lower Operation implementation |
| 382 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 383 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 384 | SDValue MipsTargetLowering:: |
Bruno Cardoso Lopes | d3bdf19 | 2009-05-27 17:23:44 +0000 | [diff] [blame] | 385 | LowerFP_TO_SINT(SDValue Op, SelectionDAG &DAG) |
| 386 | { |
| 387 | if (!Subtarget->isMips1()) |
| 388 | return Op; |
| 389 | |
| 390 | MachineFunction &MF = DAG.getMachineFunction(); |
| 391 | unsigned CCReg = AddLiveIn(MF, Mips::FCR31, Mips::CCRRegisterClass); |
| 392 | |
| 393 | SDValue Chain = DAG.getEntryNode(); |
| 394 | DebugLoc dl = Op.getDebugLoc(); |
| 395 | SDValue Src = Op.getOperand(0); |
| 396 | |
| 397 | // Set the condition register |
| 398 | SDValue CondReg = DAG.getCopyFromReg(Chain, dl, CCReg, MVT::i32); |
| 399 | CondReg = DAG.getCopyToReg(Chain, dl, Mips::AT, CondReg); |
| 400 | CondReg = DAG.getCopyFromReg(CondReg, dl, Mips::AT, MVT::i32); |
| 401 | |
| 402 | SDValue Cst = DAG.getConstant(3, MVT::i32); |
| 403 | SDValue Or = DAG.getNode(ISD::OR, dl, MVT::i32, CondReg, Cst); |
| 404 | Cst = DAG.getConstant(2, MVT::i32); |
| 405 | SDValue Xor = DAG.getNode(ISD::XOR, dl, MVT::i32, Or, Cst); |
| 406 | |
| 407 | SDValue InFlag(0, 0); |
| 408 | CondReg = DAG.getCopyToReg(Chain, dl, Mips::FCR31, Xor, InFlag); |
| 409 | |
| 410 | // Emit the round instruction and bit convert to integer |
| 411 | SDValue Trunc = DAG.getNode(MipsISD::FPRound, dl, MVT::f32, |
| 412 | Src, CondReg.getValue(1)); |
| 413 | SDValue BitCvt = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::i32, Trunc); |
| 414 | return BitCvt; |
| 415 | } |
| 416 | |
| 417 | SDValue MipsTargetLowering:: |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 418 | LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) |
| 419 | { |
| 420 | SDValue Chain = Op.getOperand(0); |
| 421 | SDValue Size = Op.getOperand(1); |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 422 | DebugLoc dl = Op.getDebugLoc(); |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 423 | |
| 424 | // Get a reference from Mips stack pointer |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 425 | SDValue StackPointer = DAG.getCopyFromReg(Chain, dl, Mips::SP, MVT::i32); |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 426 | |
| 427 | // Subtract the dynamic size from the actual stack size to |
| 428 | // obtain the new stack size. |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 429 | SDValue Sub = DAG.getNode(ISD::SUB, dl, MVT::i32, StackPointer, Size); |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 430 | |
| 431 | // The Sub result contains the new stack start address, so it |
| 432 | // must be placed in the stack pointer register. |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 433 | Chain = DAG.getCopyToReg(StackPointer.getValue(1), dl, Mips::SP, Sub); |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 434 | |
| 435 | // This node always has two return values: a new stack pointer |
| 436 | // value and a chain |
| 437 | SDValue Ops[2] = { Sub, Chain }; |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 438 | return DAG.getMergeValues(Ops, 2, dl); |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | SDValue MipsTargetLowering:: |
Bruno Cardoso Lopes | 1906c5a | 2008-08-02 19:37:33 +0000 | [diff] [blame] | 442 | LowerANDOR(SDValue Op, SelectionDAG &DAG) |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 443 | { |
| 444 | SDValue LHS = Op.getOperand(0); |
| 445 | SDValue RHS = Op.getOperand(1); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 446 | DebugLoc dl = Op.getDebugLoc(); |
| 447 | |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 448 | if (LHS.getOpcode() != MipsISD::FPCmp || RHS.getOpcode() != MipsISD::FPCmp) |
| 449 | return Op; |
| 450 | |
| 451 | SDValue True = DAG.getConstant(1, MVT::i32); |
| 452 | SDValue False = DAG.getConstant(0, MVT::i32); |
| 453 | |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 454 | SDValue LSEL = DAG.getNode(MipsISD::FPSelectCC, dl, True.getValueType(), |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 455 | LHS, True, False, LHS.getOperand(2)); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 456 | SDValue RSEL = DAG.getNode(MipsISD::FPSelectCC, dl, True.getValueType(), |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 457 | RHS, True, False, RHS.getOperand(2)); |
| 458 | |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 459 | return DAG.getNode(Op.getOpcode(), dl, MVT::i32, LSEL, RSEL); |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | SDValue MipsTargetLowering:: |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 463 | LowerBRCOND(SDValue Op, SelectionDAG &DAG) |
| 464 | { |
| 465 | // The first operand is the chain, the second is the condition, the third is |
| 466 | // the block to branch to if the condition is true. |
| 467 | SDValue Chain = Op.getOperand(0); |
| 468 | SDValue Dest = Op.getOperand(2); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 469 | DebugLoc dl = Op.getDebugLoc(); |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 470 | |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 471 | if (Op.getOperand(1).getOpcode() != MipsISD::FPCmp) |
Bruno Cardoso Lopes | 4b877ca | 2008-07-30 17:06:13 +0000 | [diff] [blame] | 472 | return Op; |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 473 | |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 474 | SDValue CondRes = Op.getOperand(1); |
| 475 | SDValue CCNode = CondRes.getOperand(2); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 476 | Mips::CondCode CC = |
| 477 | (Mips::CondCode)cast<ConstantSDNode>(CCNode)->getZExtValue(); |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 478 | SDValue BrCode = DAG.getConstant(GetFPBranchCodeFromCond(CC), MVT::i32); |
| 479 | |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 480 | return DAG.getNode(MipsISD::FPBrcond, dl, Op.getValueType(), Chain, BrCode, |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 481 | Dest, CondRes); |
| 482 | } |
| 483 | |
| 484 | SDValue MipsTargetLowering:: |
| 485 | LowerSETCC(SDValue Op, SelectionDAG &DAG) |
| 486 | { |
| 487 | // The operands to this are the left and right operands to compare (ops #0, |
| 488 | // and #1) and the condition code to compare them with (op #2) as a |
| 489 | // CondCodeSDNode. |
| 490 | SDValue LHS = Op.getOperand(0); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 491 | SDValue RHS = Op.getOperand(1); |
| 492 | DebugLoc dl = Op.getDebugLoc(); |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 493 | |
| 494 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get(); |
| 495 | |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 496 | return DAG.getNode(MipsISD::FPCmp, dl, Op.getValueType(), LHS, RHS, |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 497 | DAG.getConstant(FPCondCCodeToFCC(CC), MVT::i32)); |
| 498 | } |
| 499 | |
| 500 | SDValue MipsTargetLowering:: |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 501 | LowerSELECT(SDValue Op, SelectionDAG &DAG) |
| 502 | { |
| 503 | SDValue Cond = Op.getOperand(0); |
| 504 | SDValue True = Op.getOperand(1); |
| 505 | SDValue False = Op.getOperand(2); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 506 | DebugLoc dl = Op.getDebugLoc(); |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 507 | |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 508 | // if the incomming condition comes from a integer compare, the select |
| 509 | // operation must be SelectCC or a conditional move if the subtarget |
| 510 | // supports it. |
| 511 | if (Cond.getOpcode() != MipsISD::FPCmp) { |
| 512 | if (Subtarget->hasCondMov() && !True.getValueType().isFloatingPoint()) |
| 513 | return Op; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 514 | return DAG.getNode(MipsISD::SelectCC, dl, True.getValueType(), |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 515 | Cond, True, False); |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | // if the incomming condition comes from fpcmp, the select |
| 519 | // operation must use FPSelectCC. |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 520 | SDValue CCNode = Cond.getOperand(2); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 521 | return DAG.getNode(MipsISD::FPSelectCC, dl, True.getValueType(), |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 522 | Cond, True, False, CCNode); |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | SDValue MipsTargetLowering:: |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 526 | LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) |
| 527 | { |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 528 | // FIXME there isn't actually debug info here |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 529 | DebugLoc dl = Op.getDebugLoc(); |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 530 | GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
| 531 | SDValue GA = DAG.getTargetGlobalAddress(GV, MVT::i32); |
| 532 | |
| 533 | if (!Subtarget->hasABICall()) { |
Dan Gohman | fc16657 | 2009-04-09 23:54:40 +0000 | [diff] [blame] | 534 | SDVTList VTs = DAG.getVTList(MVT::i32); |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 535 | SDValue Ops[] = { GA }; |
Bruno Cardoso Lopes | 4b877ca | 2008-07-30 17:06:13 +0000 | [diff] [blame] | 536 | // %gp_rel relocation |
| 537 | if (!isa<Function>(GV) && IsGlobalInSmallSection(GV)) { |
Dan Gohman | fc16657 | 2009-04-09 23:54:40 +0000 | [diff] [blame] | 538 | SDValue GPRelNode = DAG.getNode(MipsISD::GPRel, dl, VTs, Ops, 1); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 539 | SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 540 | return DAG.getNode(ISD::ADD, dl, MVT::i32, GOT, GPRelNode); |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 541 | } |
| 542 | // %hi/%lo relocation |
Dan Gohman | fc16657 | 2009-04-09 23:54:40 +0000 | [diff] [blame] | 543 | SDValue HiPart = DAG.getNode(MipsISD::Hi, dl, VTs, Ops, 1); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 544 | SDValue Lo = DAG.getNode(MipsISD::Lo, dl, MVT::i32, GA); |
| 545 | return DAG.getNode(ISD::ADD, dl, MVT::i32, HiPart, Lo); |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 546 | |
| 547 | } else { // Abicall relocations, TODO: make this cleaner. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 548 | SDValue ResNode = DAG.getLoad(MVT::i32, dl, |
| 549 | DAG.getEntryNode(), GA, NULL, 0); |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 550 | // On functions and global targets not internal linked only |
| 551 | // a load from got/GP is necessary for PIC to work. |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 552 | if (!GV->hasLocalLinkage() || isa<Function>(GV)) |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 553 | return ResNode; |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 554 | SDValue Lo = DAG.getNode(MipsISD::Lo, dl, MVT::i32, GA); |
| 555 | return DAG.getNode(ISD::ADD, dl, MVT::i32, ResNode, Lo); |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 556 | } |
| 557 | |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 558 | llvm_unreachable("Dont know how to handle GlobalAddress"); |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 559 | return SDValue(0,0); |
| 560 | } |
| 561 | |
| 562 | SDValue MipsTargetLowering:: |
| 563 | LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) |
| 564 | { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 565 | llvm_unreachable("TLS not implemented for MIPS."); |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 566 | return SDValue(); // Not reached |
| 567 | } |
| 568 | |
| 569 | SDValue MipsTargetLowering:: |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 570 | LowerJumpTable(SDValue Op, SelectionDAG &DAG) |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 571 | { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 572 | SDValue ResNode; |
| 573 | SDValue HiPart; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 574 | // FIXME there isn't actually debug info here |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 575 | DebugLoc dl = Op.getDebugLoc(); |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 576 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 577 | MVT PtrVT = Op.getValueType(); |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 578 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Op); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 579 | SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PtrVT); |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 580 | |
| 581 | if (getTargetMachine().getRelocationModel() != Reloc::PIC_) { |
Dan Gohman | fc16657 | 2009-04-09 23:54:40 +0000 | [diff] [blame] | 582 | SDVTList VTs = DAG.getVTList(MVT::i32); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 583 | SDValue Ops[] = { JTI }; |
Dan Gohman | fc16657 | 2009-04-09 23:54:40 +0000 | [diff] [blame] | 584 | HiPart = DAG.getNode(MipsISD::Hi, dl, VTs, Ops, 1); |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 585 | } else // Emit Load from Global Pointer |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 586 | HiPart = DAG.getLoad(MVT::i32, dl, DAG.getEntryNode(), JTI, NULL, 0); |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 587 | |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 588 | SDValue Lo = DAG.getNode(MipsISD::Lo, dl, MVT::i32, JTI); |
| 589 | ResNode = DAG.getNode(ISD::ADD, dl, MVT::i32, HiPart, Lo); |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 590 | |
| 591 | return ResNode; |
| 592 | } |
| 593 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 594 | SDValue MipsTargetLowering:: |
| 595 | LowerConstantPool(SDValue Op, SelectionDAG &DAG) |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 596 | { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 597 | SDValue ResNode; |
Bruno Cardoso Lopes | 92e87f2 | 2008-07-23 16:01:50 +0000 | [diff] [blame] | 598 | ConstantPoolSDNode *N = cast<ConstantPoolSDNode>(Op); |
| 599 | Constant *C = N->getConstVal(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 600 | SDValue CP = DAG.getTargetConstantPool(C, MVT::i32, N->getAlignment()); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 601 | // FIXME there isn't actually debug info here |
| 602 | DebugLoc dl = Op.getDebugLoc(); |
Bruno Cardoso Lopes | 92e87f2 | 2008-07-23 16:01:50 +0000 | [diff] [blame] | 603 | |
| 604 | // gp_rel relocation |
Bruno Cardoso Lopes | f33bc43 | 2008-07-28 19:26:25 +0000 | [diff] [blame] | 605 | // FIXME: we should reference the constant pool using small data sections, |
| 606 | // but the asm printer currently doens't support this feature without |
| 607 | // hacking it. This feature should come soon so we can uncomment the |
| 608 | // stuff below. |
| 609 | //if (!Subtarget->hasABICall() && |
Duncan Sands | 777d230 | 2009-05-09 07:06:46 +0000 | [diff] [blame] | 610 | // IsInSmallSection(getTargetData()->getTypeAllocSize(C->getType()))) { |
Bruno Cardoso Lopes | f33bc43 | 2008-07-28 19:26:25 +0000 | [diff] [blame] | 611 | // SDValue GPRelNode = DAG.getNode(MipsISD::GPRel, MVT::i32, CP); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 612 | // SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(MVT::i32); |
Bruno Cardoso Lopes | f33bc43 | 2008-07-28 19:26:25 +0000 | [diff] [blame] | 613 | // ResNode = DAG.getNode(ISD::ADD, MVT::i32, GOT, GPRelNode); |
| 614 | //} else { // %hi/%lo relocation |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 615 | SDValue HiPart = DAG.getNode(MipsISD::Hi, dl, MVT::i32, CP); |
| 616 | SDValue Lo = DAG.getNode(MipsISD::Lo, dl, MVT::i32, CP); |
| 617 | ResNode = DAG.getNode(ISD::ADD, dl, MVT::i32, HiPart, Lo); |
Bruno Cardoso Lopes | f33bc43 | 2008-07-28 19:26:25 +0000 | [diff] [blame] | 618 | //} |
Bruno Cardoso Lopes | 92e87f2 | 2008-07-23 16:01:50 +0000 | [diff] [blame] | 619 | |
| 620 | return ResNode; |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 621 | } |
| 622 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 623 | //===----------------------------------------------------------------------===// |
| 624 | // Calling Convention Implementation |
| 625 | // |
| 626 | // The lower operations present on calling convention works on this order: |
| 627 | // LowerCALL (virt regs --> phys regs, virt regs --> stack) |
| 628 | // LowerFORMAL_ARGUMENTS (phys --> virt regs, stack --> virt regs) |
| 629 | // LowerRET (virt regs --> phys regs) |
| 630 | // LowerCALL (phys regs --> virt regs) |
| 631 | // |
| 632 | //===----------------------------------------------------------------------===// |
| 633 | |
| 634 | #include "MipsGenCallingConv.inc" |
| 635 | |
| 636 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 637 | // TODO: Implement a generic logic using tblgen that can support this. |
| 638 | // Mips O32 ABI rules: |
| 639 | // --- |
| 640 | // i32 - Passed in A0, A1, A2, A3 and stack |
| 641 | // f32 - Only passed in f32 registers if no int reg has been used yet to hold |
| 642 | // an argument. Otherwise, passed in A1, A2, A3 and stack. |
| 643 | // f64 - Only passed in two aliased f32 registers if no int reg has been used |
| 644 | // yet to hold an argument. Otherwise, use A2, A3 and stack. If A1 is |
| 645 | // not used, it must be shadowed. If only A3 is avaiable, shadow it and |
| 646 | // go to stack. |
| 647 | //===----------------------------------------------------------------------===// |
| 648 | |
| 649 | static bool CC_MipsO32(unsigned ValNo, MVT ValVT, |
| 650 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 651 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
| 652 | |
| 653 | static const unsigned IntRegsSize=4, FloatRegsSize=2; |
| 654 | |
| 655 | static const unsigned IntRegs[] = { |
| 656 | Mips::A0, Mips::A1, Mips::A2, Mips::A3 |
| 657 | }; |
| 658 | static const unsigned F32Regs[] = { |
| 659 | Mips::F12, Mips::F14 |
| 660 | }; |
| 661 | static const unsigned F64Regs[] = { |
| 662 | Mips::D6, Mips::D7 |
| 663 | }; |
| 664 | |
| 665 | unsigned Reg=0; |
| 666 | unsigned UnallocIntReg = State.getFirstUnallocated(IntRegs, IntRegsSize); |
| 667 | bool IntRegUsed = (IntRegs[UnallocIntReg] != (unsigned (Mips::A0))); |
| 668 | |
| 669 | // Promote i8 and i16 |
| 670 | if (LocVT == MVT::i8 || LocVT == MVT::i16) { |
| 671 | LocVT = MVT::i32; |
| 672 | if (ArgFlags.isSExt()) |
| 673 | LocInfo = CCValAssign::SExt; |
| 674 | else if (ArgFlags.isZExt()) |
| 675 | LocInfo = CCValAssign::ZExt; |
| 676 | else |
| 677 | LocInfo = CCValAssign::AExt; |
| 678 | } |
| 679 | |
| 680 | if (ValVT == MVT::i32 || (ValVT == MVT::f32 && IntRegUsed)) { |
| 681 | Reg = State.AllocateReg(IntRegs, IntRegsSize); |
| 682 | IntRegUsed = true; |
| 683 | LocVT = MVT::i32; |
| 684 | } |
| 685 | |
| 686 | if (ValVT.isFloatingPoint() && !IntRegUsed) { |
| 687 | if (ValVT == MVT::f32) |
| 688 | Reg = State.AllocateReg(F32Regs, FloatRegsSize); |
| 689 | else |
| 690 | Reg = State.AllocateReg(F64Regs, FloatRegsSize); |
| 691 | } |
| 692 | |
| 693 | if (ValVT == MVT::f64 && IntRegUsed) { |
| 694 | if (UnallocIntReg != IntRegsSize) { |
| 695 | // If we hit register A3 as the first not allocated, we must |
| 696 | // mark it as allocated (shadow) and use the stack instead. |
| 697 | if (IntRegs[UnallocIntReg] != (unsigned (Mips::A3))) |
| 698 | Reg = Mips::A2; |
| 699 | for (;UnallocIntReg < IntRegsSize; ++UnallocIntReg) |
| 700 | State.AllocateReg(UnallocIntReg); |
| 701 | } |
| 702 | LocVT = MVT::i32; |
| 703 | } |
| 704 | |
| 705 | if (!Reg) { |
| 706 | unsigned SizeInBytes = ValVT.getSizeInBits() >> 3; |
| 707 | unsigned Offset = State.AllocateStack(SizeInBytes, SizeInBytes); |
| 708 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
| 709 | } else |
| 710 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 711 | |
| 712 | return false; // CC must always match |
| 713 | } |
| 714 | |
| 715 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 716 | // CALL Calling Convention Implementation |
| 717 | //===----------------------------------------------------------------------===// |
| 718 | |
Nate Begeman | 5bf4b75 | 2009-01-26 03:15:54 +0000 | [diff] [blame] | 719 | /// LowerCALL - functions arguments are copied from virtual regs to |
| 720 | /// (physical regs)/(stack frame), CALLSEQ_START and CALLSEQ_END are emitted. |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 721 | /// TODO: isVarArg, isTailCall. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 722 | SDValue MipsTargetLowering:: |
Bruno Cardoso Lopes | f7f3b50 | 2008-08-04 07:12:52 +0000 | [diff] [blame] | 723 | LowerCALL(SDValue Op, SelectionDAG &DAG) |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 724 | { |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 725 | MachineFunction &MF = DAG.getMachineFunction(); |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 726 | |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 727 | CallSDNode *TheCall = cast<CallSDNode>(Op.getNode()); |
| 728 | SDValue Chain = TheCall->getChain(); |
| 729 | SDValue Callee = TheCall->getCallee(); |
| 730 | bool isVarArg = TheCall->isVarArg(); |
| 731 | unsigned CC = TheCall->getCallingConv(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 732 | DebugLoc dl = TheCall->getDebugLoc(); |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 733 | |
| 734 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 735 | |
| 736 | // Analyze operands of the call, assigning locations to each operand. |
| 737 | SmallVector<CCValAssign, 16> ArgLocs; |
Owen Anderson | d1474d0 | 2009-07-09 17:57:24 +0000 | [diff] [blame] | 738 | CCState CCInfo(CC, isVarArg, getTargetMachine(), ArgLocs, DAG.getContext()); |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 739 | |
Bruno Cardoso Lopes | b27cb55 | 2008-07-15 02:03:36 +0000 | [diff] [blame] | 740 | // To meet O32 ABI, Mips must always allocate 16 bytes on |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 741 | // the stack (even if less than 4 are used as arguments) |
Bruno Cardoso Lopes | b27cb55 | 2008-07-15 02:03:36 +0000 | [diff] [blame] | 742 | if (Subtarget->isABI_O32()) { |
| 743 | int VTsize = MVT(MVT::i32).getSizeInBits()/8; |
| 744 | MFI->CreateFixedObject(VTsize, (VTsize*3)); |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 745 | CCInfo.AnalyzeCallOperands(TheCall, CC_MipsO32); |
| 746 | } else |
| 747 | CCInfo.AnalyzeCallOperands(TheCall, CC_Mips); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 748 | |
| 749 | // Get a count of how many bytes are to be pushed on the stack. |
| 750 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 751 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumBytes, true)); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 752 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 753 | // With EABI is it possible to have 16 args on registers. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 754 | SmallVector<std::pair<unsigned, SDValue>, 16> RegsToPass; |
| 755 | SmallVector<SDValue, 8> MemOpChains; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 756 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 757 | // First/LastArgStackLoc contains the first/last |
| 758 | // "at stack" argument location. |
| 759 | int LastArgStackLoc = 0; |
| 760 | unsigned FirstStackArgLoc = (Subtarget->isABI_EABI() ? 0 : 16); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 761 | |
| 762 | // Walk the register/memloc assignments, inserting copies/loads. |
| 763 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 764 | SDValue Arg = TheCall->getArg(i); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 765 | CCValAssign &VA = ArgLocs[i]; |
| 766 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 767 | // Promote the value if needed. |
| 768 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 769 | default: llvm_unreachable("Unknown loc info!"); |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 770 | case CCValAssign::Full: |
| 771 | if (Subtarget->isABI_O32() && VA.isRegLoc()) { |
| 772 | if (VA.getValVT() == MVT::f32 && VA.getLocVT() == MVT::i32) |
| 773 | Arg = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::i32, Arg); |
| 774 | if (VA.getValVT() == MVT::f64 && VA.getLocVT() == MVT::i32) { |
| 775 | Arg = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::i64, Arg); |
| 776 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Arg, |
| 777 | DAG.getConstant(0, getPointerTy())); |
| 778 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Arg, |
| 779 | DAG.getConstant(1, getPointerTy())); |
| 780 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Lo)); |
| 781 | RegsToPass.push_back(std::make_pair(VA.getLocReg()+1, Hi)); |
| 782 | continue; |
| 783 | } |
| 784 | } |
| 785 | break; |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 786 | case CCValAssign::SExt: |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 787 | Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 788 | break; |
| 789 | case CCValAssign::ZExt: |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 790 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 791 | break; |
| 792 | case CCValAssign::AExt: |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 793 | Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 794 | break; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 795 | } |
| 796 | |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 797 | // Arguments that can be passed on register must be kept at |
| 798 | // RegsToPass vector |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 799 | if (VA.isRegLoc()) { |
| 800 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 801 | continue; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 802 | } |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 803 | |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 804 | // Register can't get to this point... |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 805 | assert(VA.isMemLoc()); |
| 806 | |
| 807 | // Create the frame index object for this incoming parameter |
| 808 | // This guarantees that when allocating Local Area the firsts |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 809 | // 16 bytes which are alwayes reserved won't be overwritten |
| 810 | // if O32 ABI is used. For EABI the first address is zero. |
| 811 | LastArgStackLoc = (FirstStackArgLoc + VA.getLocMemOffset()); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 812 | int FI = MFI->CreateFixedObject(VA.getValVT().getSizeInBits()/8, |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 813 | LastArgStackLoc); |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 814 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 815 | SDValue PtrOff = DAG.getFrameIndex(FI,getPointerTy()); |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 816 | |
| 817 | // emit ISD::STORE whichs stores the |
| 818 | // parameter value to a stack Location |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 819 | MemOpChains.push_back(DAG.getStore(Chain, dl, Arg, PtrOff, NULL, 0)); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 820 | } |
| 821 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 822 | // Transform all store nodes into one single node because all store |
| 823 | // nodes are independent of each other. |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 824 | if (!MemOpChains.empty()) |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 825 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 826 | &MemOpChains[0], MemOpChains.size()); |
| 827 | |
| 828 | // Build a sequence of copy-to-reg nodes chained together with token |
| 829 | // chain and flag operands which copy the outgoing args into registers. |
| 830 | // The InFlag in necessary since all emited instructions must be |
| 831 | // stuck together. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 832 | SDValue InFlag; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 833 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 834 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 835 | RegsToPass[i].second, InFlag); |
| 836 | InFlag = Chain.getValue(1); |
| 837 | } |
| 838 | |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 839 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
| 840 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 841 | // node so that legalize doesn't hack it. |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 842 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 843 | Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy()); |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 844 | else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) |
| 845 | Callee = DAG.getTargetExternalSymbol(S->getSymbol(), getPointerTy()); |
| 846 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 847 | // MipsJmpLink = #chain, #target_address, #opt_in_flags... |
| 848 | // = Chain, Callee, Reg#1, Reg#2, ... |
| 849 | // |
| 850 | // Returns a chain & a flag for retval copy to use. |
| 851 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Flag); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 852 | SmallVector<SDValue, 8> Ops; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 853 | Ops.push_back(Chain); |
| 854 | Ops.push_back(Callee); |
| 855 | |
| 856 | // Add argument registers to the end of the list so that they are |
| 857 | // known live into the call. |
| 858 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) |
| 859 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 860 | RegsToPass[i].second.getValueType())); |
| 861 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 862 | if (InFlag.getNode()) |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 863 | Ops.push_back(InFlag); |
| 864 | |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 865 | Chain = DAG.getNode(MipsISD::JmpLink, dl, NodeTys, &Ops[0], Ops.size()); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 866 | InFlag = Chain.getValue(1); |
| 867 | |
Bruno Cardoso Lopes | d2947ee | 2008-06-04 01:45:25 +0000 | [diff] [blame] | 868 | // Create the CALLSEQ_END node. |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 869 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, true), |
| 870 | DAG.getIntPtrConstant(0, true), InFlag); |
Bruno Cardoso Lopes | bdbb750 | 2008-06-01 03:49:39 +0000 | [diff] [blame] | 871 | InFlag = Chain.getValue(1); |
| 872 | |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 873 | // Create a stack location to hold GP when PIC is used. This stack |
| 874 | // location is used on function prologue to save GP and also after all |
| 875 | // emited CALL's to restore GP. |
| 876 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 877 | // Function can have an arbitrary number of calls, so |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 878 | // hold the LastArgStackLoc with the biggest offset. |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 879 | int FI; |
| 880 | MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>(); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 881 | if (LastArgStackLoc >= MipsFI->getGPStackOffset()) { |
| 882 | LastArgStackLoc = (!LastArgStackLoc) ? (16) : (LastArgStackLoc+4); |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 883 | // Create the frame index only once. SPOffset here can be anything |
| 884 | // (this will be fixed on processFunctionBeforeFrameFinalized) |
| 885 | if (MipsFI->getGPStackOffset() == -1) { |
| 886 | FI = MFI->CreateFixedObject(4, 0); |
| 887 | MipsFI->setGPFI(FI); |
| 888 | } |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 889 | MipsFI->setGPStackOffset(LastArgStackLoc); |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 890 | } |
| 891 | |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 892 | // Reload GP value. |
| 893 | FI = MipsFI->getGPFI(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 894 | SDValue FIN = DAG.getFrameIndex(FI,getPointerTy()); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 895 | SDValue GPLoad = DAG.getLoad(MVT::i32, dl, Chain, FIN, NULL, 0); |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 896 | Chain = GPLoad.getValue(1); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 897 | Chain = DAG.getCopyToReg(Chain, dl, DAG.getRegister(Mips::GP, MVT::i32), |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 898 | GPLoad, SDValue(0,0)); |
Bruno Cardoso Lopes | bdbb750 | 2008-06-01 03:49:39 +0000 | [diff] [blame] | 899 | InFlag = Chain.getValue(1); |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 900 | } |
| 901 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 902 | // Handle result values, copying them out of physregs into vregs that we |
| 903 | // return. |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 904 | return SDValue(LowerCallResult(Chain, InFlag, TheCall, CC, DAG), Op.getResNo()); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | /// LowerCallResult - Lower the result values of an ISD::CALL into the |
| 908 | /// appropriate copies out of appropriate physical registers. This assumes that |
| 909 | /// Chain/InFlag are the input chain/flag to use, and that TheCall is the call |
| 910 | /// being lowered. Returns a SDNode with the same number of values as the |
| 911 | /// ISD::CALL. |
| 912 | SDNode *MipsTargetLowering:: |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 913 | LowerCallResult(SDValue Chain, SDValue InFlag, CallSDNode *TheCall, |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 914 | unsigned CallingConv, SelectionDAG &DAG) { |
| 915 | |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 916 | bool isVarArg = TheCall->isVarArg(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 917 | DebugLoc dl = TheCall->getDebugLoc(); |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 918 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 919 | // Assign locations to each value returned by this call. |
| 920 | SmallVector<CCValAssign, 16> RVLocs; |
Owen Anderson | d1474d0 | 2009-07-09 17:57:24 +0000 | [diff] [blame] | 921 | CCState CCInfo(CallingConv, isVarArg, getTargetMachine(), |
| 922 | RVLocs, DAG.getContext()); |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 923 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 924 | CCInfo.AnalyzeCallResult(TheCall, RetCC_Mips); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 925 | SmallVector<SDValue, 8> ResultVals; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 926 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 927 | // Copy all of the result registers out of their specified physreg. |
| 928 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 929 | Chain = DAG.getCopyFromReg(Chain, dl, RVLocs[i].getLocReg(), |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 930 | RVLocs[i].getValVT(), InFlag).getValue(1); |
| 931 | InFlag = Chain.getValue(2); |
| 932 | ResultVals.push_back(Chain.getValue(0)); |
| 933 | } |
| 934 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 935 | ResultVals.push_back(Chain); |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 936 | |
| 937 | // Merge everything together with a MERGE_VALUES node. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 938 | return DAG.getNode(ISD::MERGE_VALUES, dl, TheCall->getVTList(), |
Duncan Sands | aaffa05 | 2008-12-01 11:41:29 +0000 | [diff] [blame] | 939 | &ResultVals[0], ResultVals.size()).getNode(); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | //===----------------------------------------------------------------------===// |
| 943 | // FORMAL_ARGUMENTS Calling Convention Implementation |
| 944 | //===----------------------------------------------------------------------===// |
| 945 | |
Bruno Cardoso Lopes | f7f3b50 | 2008-08-04 07:12:52 +0000 | [diff] [blame] | 946 | /// LowerFORMAL_ARGUMENTS - transform physical registers into |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 947 | /// virtual registers and generate load operations for |
| 948 | /// arguments places on the stack. |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 949 | /// TODO: isVarArg |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 950 | SDValue MipsTargetLowering:: |
Bruno Cardoso Lopes | f7f3b50 | 2008-08-04 07:12:52 +0000 | [diff] [blame] | 951 | LowerFORMAL_ARGUMENTS(SDValue Op, SelectionDAG &DAG) |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 952 | { |
Bruno Cardoso Lopes | f7f3b50 | 2008-08-04 07:12:52 +0000 | [diff] [blame] | 953 | SDValue Root = Op.getOperand(0); |
| 954 | MachineFunction &MF = DAG.getMachineFunction(); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 955 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Bruno Cardoso Lopes | a2b1bb5 | 2007-08-28 05:08:16 +0000 | [diff] [blame] | 956 | MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 957 | DebugLoc dl = Op.getDebugLoc(); |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 958 | |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 959 | bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue() != 0; |
Bruno Cardoso Lopes | f7f3b50 | 2008-08-04 07:12:52 +0000 | [diff] [blame] | 960 | unsigned CC = DAG.getMachineFunction().getFunction()->getCallingConv(); |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 961 | |
| 962 | unsigned StackReg = MF.getTarget().getRegisterInfo()->getFrameRegister(MF); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 963 | |
| 964 | // Assign locations to all of the incoming arguments. |
| 965 | SmallVector<CCValAssign, 16> ArgLocs; |
Owen Anderson | d1474d0 | 2009-07-09 17:57:24 +0000 | [diff] [blame] | 966 | CCState CCInfo(CC, isVarArg, getTargetMachine(), ArgLocs, DAG.getContext()); |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 967 | |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 968 | if (Subtarget->isABI_O32()) |
| 969 | CCInfo.AnalyzeFormalArguments(Op.getNode(), CC_MipsO32); |
| 970 | else |
| 971 | CCInfo.AnalyzeFormalArguments(Op.getNode(), CC_Mips); |
| 972 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 973 | SmallVector<SDValue, 16> ArgValues; |
| 974 | SDValue StackPtr; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 975 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 976 | unsigned FirstStackArgLoc = (Subtarget->isABI_EABI() ? 0 : 16); |
| 977 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 978 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 979 | CCValAssign &VA = ArgLocs[i]; |
| 980 | |
| 981 | // Arguments stored on registers |
| 982 | if (VA.isRegLoc()) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 983 | MVT RegVT = VA.getLocVT(); |
Bill Wendling | 06b8c19 | 2008-07-09 05:55:53 +0000 | [diff] [blame] | 984 | TargetRegisterClass *RC = 0; |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 985 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 986 | if (RegVT == MVT::i32) |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 987 | RC = Mips::CPURegsRegisterClass; |
Bruno Cardoso Lopes | bdfbb74 | 2009-03-21 00:05:07 +0000 | [diff] [blame] | 988 | else if (RegVT == MVT::f32) |
| 989 | RC = Mips::FGR32RegisterClass; |
| 990 | else if (RegVT == MVT::f64) { |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 991 | if (!Subtarget->isSingleFloat()) |
| 992 | RC = Mips::AFGR64RegisterClass; |
| 993 | } else |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 994 | llvm_unreachable("RegVT not supported by FORMAL_ARGUMENTS Lowering"); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 995 | |
| 996 | // Transform the arguments stored on |
| 997 | // physical registers into virtual ones |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 998 | unsigned Reg = AddLiveIn(DAG.getMachineFunction(), VA.getLocReg(), RC); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 999 | SDValue ArgValue = DAG.getCopyFromReg(Root, dl, Reg, RegVT); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1000 | |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 1001 | // If this is an 8 or 16-bit value, it has been passed promoted |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1002 | // to 32 bits. Insert an assert[sz]ext to capture this, then |
| 1003 | // truncate to the right size. |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 1004 | if (VA.getLocInfo() != CCValAssign::Full) { |
Chris Lattner | d401507 | 2009-03-26 05:28:14 +0000 | [diff] [blame] | 1005 | unsigned Opcode = 0; |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 1006 | if (VA.getLocInfo() == CCValAssign::SExt) |
| 1007 | Opcode = ISD::AssertSext; |
| 1008 | else if (VA.getLocInfo() == CCValAssign::ZExt) |
| 1009 | Opcode = ISD::AssertZext; |
Chris Lattner | d401507 | 2009-03-26 05:28:14 +0000 | [diff] [blame] | 1010 | if (Opcode) |
| 1011 | ArgValue = DAG.getNode(Opcode, dl, RegVT, ArgValue, |
| 1012 | DAG.getValueType(VA.getValVT())); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1013 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | // Handle O32 ABI cases: i32->f32 and (i32,i32)->f64 |
| 1017 | if (Subtarget->isABI_O32()) { |
| 1018 | if (RegVT == MVT::i32 && VA.getValVT() == MVT::f32) |
| 1019 | ArgValue = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f32, ArgValue); |
| 1020 | if (RegVT == MVT::i32 && VA.getValVT() == MVT::f64) { |
| 1021 | unsigned Reg2 = AddLiveIn(DAG.getMachineFunction(), |
| 1022 | VA.getLocReg()+1, RC); |
| 1023 | SDValue ArgValue2 = DAG.getCopyFromReg(Root, dl, Reg2, RegVT); |
| 1024 | SDValue Hi = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f32, ArgValue); |
| 1025 | SDValue Lo = DAG.getNode(ISD::BIT_CONVERT, dl, MVT::f32, ArgValue2); |
| 1026 | ArgValue = DAG.getNode(ISD::BUILD_PAIR, dl, MVT::f64, Lo, Hi); |
| 1027 | } |
| 1028 | } |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1029 | |
| 1030 | ArgValues.push_back(ArgValue); |
| 1031 | |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 1032 | // To meet ABI, when VARARGS are passed on registers, the registers |
Bruno Cardoso Lopes | a2b1bb5 | 2007-08-28 05:08:16 +0000 | [diff] [blame] | 1033 | // must have their values written to the caller stack frame. |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1034 | if ((isVarArg) && (Subtarget->isABI_O32())) { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1035 | if (StackPtr.getNode() == 0) |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 1036 | StackPtr = DAG.getRegister(StackReg, getPointerTy()); |
| 1037 | |
Bruno Cardoso Lopes | a2b1bb5 | 2007-08-28 05:08:16 +0000 | [diff] [blame] | 1038 | // The stack pointer offset is relative to the caller stack frame. |
| 1039 | // Since the real stack size is unknown here, a negative SPOffset |
| 1040 | // is used so there's a way to adjust these offsets when the stack |
| 1041 | // size get known (on EliminateFrameIndex). A dummy SPOffset is |
| 1042 | // used instead of a direct negative address (which is recorded to |
| 1043 | // be used on emitPrologue) to avoid mis-calc of the first stack |
| 1044 | // offset on PEI::calculateFrameObjectOffsets. |
| 1045 | // Arguments are always 32-bit. |
| 1046 | int FI = MFI->CreateFixedObject(4, 0); |
| 1047 | MipsFI->recordStoreVarArgsFI(FI, -(4+(i*4))); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1048 | SDValue PtrOff = DAG.getFrameIndex(FI, getPointerTy()); |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 1049 | |
| 1050 | // emit ISD::STORE whichs stores the |
| 1051 | // parameter value to a stack Location |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1052 | ArgValues.push_back(DAG.getStore(Root, dl, ArgValue, PtrOff, NULL, 0)); |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1055 | } else { // VA.isRegLoc() |
| 1056 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1057 | // sanity check |
| 1058 | assert(VA.isMemLoc()); |
| 1059 | |
Bruno Cardoso Lopes | a2b1bb5 | 2007-08-28 05:08:16 +0000 | [diff] [blame] | 1060 | // The stack pointer offset is relative to the caller stack frame. |
| 1061 | // Since the real stack size is unknown here, a negative SPOffset |
| 1062 | // is used so there's a way to adjust these offsets when the stack |
| 1063 | // size get known (on EliminateFrameIndex). A dummy SPOffset is |
| 1064 | // used instead of a direct negative address (which is recorded to |
| 1065 | // be used on emitPrologue) to avoid mis-calc of the first stack |
| 1066 | // offset on PEI::calculateFrameObjectOffsets. |
| 1067 | // Arguments are always 32-bit. |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1068 | unsigned ArgSize = VA.getLocVT().getSizeInBits()/8; |
| 1069 | int FI = MFI->CreateFixedObject(ArgSize, 0); |
| 1070 | MipsFI->recordLoadArgsFI(FI, -(ArgSize+ |
| 1071 | (FirstStackArgLoc + VA.getLocMemOffset()))); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1072 | |
| 1073 | // Create load nodes to retrieve arguments from the stack |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1074 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1075 | ArgValues.push_back(DAG.getLoad(VA.getValVT(), dl, Root, FIN, NULL, 0)); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1076 | } |
| 1077 | } |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1078 | |
| 1079 | // The mips ABIs for returning structs by value requires that we copy |
| 1080 | // the sret argument into $v0 for the return. Save the argument into |
| 1081 | // a virtual register so that we can access it from the return points. |
| 1082 | if (DAG.getMachineFunction().getFunction()->hasStructRetAttr()) { |
| 1083 | unsigned Reg = MipsFI->getSRetReturnReg(); |
| 1084 | if (!Reg) { |
| 1085 | Reg = MF.getRegInfo().createVirtualRegister(getRegClassFor(MVT::i32)); |
| 1086 | MipsFI->setSRetReturnReg(Reg); |
| 1087 | } |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1088 | SDValue Copy = DAG.getCopyToReg(DAG.getEntryNode(), dl, Reg, ArgValues[0]); |
| 1089 | Root = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Copy, Root); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1092 | ArgValues.push_back(Root); |
| 1093 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1094 | // Return the new list of results. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1095 | return DAG.getNode(ISD::MERGE_VALUES, dl, Op.getNode()->getVTList(), |
Duncan Sands | aaffa05 | 2008-12-01 11:41:29 +0000 | [diff] [blame] | 1096 | &ArgValues[0], ArgValues.size()).getValue(Op.getResNo()); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | //===----------------------------------------------------------------------===// |
| 1100 | // Return Value Calling Convention Implementation |
| 1101 | //===----------------------------------------------------------------------===// |
| 1102 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1103 | SDValue MipsTargetLowering:: |
| 1104 | LowerRET(SDValue Op, SelectionDAG &DAG) |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1105 | { |
| 1106 | // CCValAssign - represent the assignment of |
| 1107 | // the return value to a location |
| 1108 | SmallVector<CCValAssign, 16> RVLocs; |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 1109 | unsigned CC = DAG.getMachineFunction().getFunction()->getCallingConv(); |
| 1110 | bool isVarArg = DAG.getMachineFunction().getFunction()->isVarArg(); |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 1111 | DebugLoc dl = Op.getDebugLoc(); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1112 | |
| 1113 | // CCState - Info about the registers and stack slot. |
Owen Anderson | d1474d0 | 2009-07-09 17:57:24 +0000 | [diff] [blame] | 1114 | CCState CCInfo(CC, isVarArg, getTargetMachine(), RVLocs, DAG.getContext()); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1115 | |
| 1116 | // Analize return values of ISD::RET |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1117 | CCInfo.AnalyzeReturn(Op.getNode(), RetCC_Mips); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1118 | |
| 1119 | // If this is the first return lowered for this function, add |
| 1120 | // the regs to the liveout set for the function. |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 1121 | if (DAG.getMachineFunction().getRegInfo().liveout_empty()) { |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1122 | for (unsigned i = 0; i != RVLocs.size(); ++i) |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 1123 | if (RVLocs[i].isRegLoc()) |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 1124 | DAG.getMachineFunction().getRegInfo().addLiveOut(RVLocs[i].getLocReg()); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | // The chain is always operand #0 |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1128 | SDValue Chain = Op.getOperand(0); |
| 1129 | SDValue Flag; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1130 | |
| 1131 | // Copy the result values into the output registers. |
| 1132 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 1133 | CCValAssign &VA = RVLocs[i]; |
| 1134 | assert(VA.isRegLoc() && "Can only return in registers!"); |
| 1135 | |
| 1136 | // ISD::RET => ret chain, (regnum1,val1), ... |
| 1137 | // So i*2+1 index only the regnums |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 1138 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
| 1139 | Op.getOperand(i*2+1), Flag); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1140 | |
| 1141 | // guarantee that all emitted copies are |
| 1142 | // stuck together, avoiding something bad |
| 1143 | Flag = Chain.getValue(1); |
| 1144 | } |
| 1145 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1146 | // The mips ABIs for returning structs by value requires that we copy |
| 1147 | // the sret argument into $v0 for the return. We saved the argument into |
| 1148 | // a virtual register in the entry block, so now we copy the value out |
| 1149 | // and into $v0. |
| 1150 | if (DAG.getMachineFunction().getFunction()->hasStructRetAttr()) { |
| 1151 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1152 | MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>(); |
| 1153 | unsigned Reg = MipsFI->getSRetReturnReg(); |
| 1154 | |
| 1155 | if (!Reg) |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1156 | llvm_unreachable("sret virtual register not created in the entry block"); |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 1157 | SDValue Val = DAG.getCopyFromReg(Chain, dl, Reg, getPointerTy()); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1158 | |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 1159 | Chain = DAG.getCopyToReg(Chain, dl, Mips::V0, Val, Flag); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1160 | Flag = Chain.getValue(1); |
| 1161 | } |
| 1162 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1163 | // Return on Mips is always a "jr $ra" |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1164 | if (Flag.getNode()) |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 1165 | return DAG.getNode(MipsISD::Ret, dl, MVT::Other, |
Bruno Cardoso Lopes | 8262df3 | 2007-10-09 03:15:11 +0000 | [diff] [blame] | 1166 | Chain, DAG.getRegister(Mips::RA, MVT::i32), Flag); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1167 | else // Return Void |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 1168 | return DAG.getNode(MipsISD::Ret, dl, MVT::Other, |
Bruno Cardoso Lopes | 8262df3 | 2007-10-09 03:15:11 +0000 | [diff] [blame] | 1169 | Chain, DAG.getRegister(Mips::RA, MVT::i32)); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1170 | } |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 1171 | |
| 1172 | //===----------------------------------------------------------------------===// |
| 1173 | // Mips Inline Assembly Support |
| 1174 | //===----------------------------------------------------------------------===// |
| 1175 | |
| 1176 | /// getConstraintType - Given a constraint letter, return the type of |
| 1177 | /// constraint it is for this target. |
| 1178 | MipsTargetLowering::ConstraintType MipsTargetLowering:: |
| 1179 | getConstraintType(const std::string &Constraint) const |
| 1180 | { |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1181 | // Mips specific constrainy |
| 1182 | // GCC config/mips/constraints.md |
| 1183 | // |
| 1184 | // 'd' : An address register. Equivalent to r |
| 1185 | // unless generating MIPS16 code. |
| 1186 | // 'y' : Equivalent to r; retained for |
| 1187 | // backwards compatibility. |
Bruno Cardoso Lopes | 7b76da1 | 2008-07-09 04:45:36 +0000 | [diff] [blame] | 1188 | // 'f' : Floating Point registers. |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 1189 | if (Constraint.size() == 1) { |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 1190 | switch (Constraint[0]) { |
| 1191 | default : break; |
| 1192 | case 'd': |
| 1193 | case 'y': |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1194 | case 'f': |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 1195 | return C_RegisterClass; |
| 1196 | break; |
| 1197 | } |
| 1198 | } |
| 1199 | return TargetLowering::getConstraintType(Constraint); |
| 1200 | } |
| 1201 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1202 | /// getRegClassForInlineAsmConstraint - Given a constraint letter (e.g. "r"), |
| 1203 | /// return a list of registers that can be used to satisfy the constraint. |
| 1204 | /// This should only be used for C_RegisterClass constraints. |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 1205 | std::pair<unsigned, const TargetRegisterClass*> MipsTargetLowering:: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1206 | getRegForInlineAsmConstraint(const std::string &Constraint, MVT VT) const |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 1207 | { |
| 1208 | if (Constraint.size() == 1) { |
| 1209 | switch (Constraint[0]) { |
| 1210 | case 'r': |
| 1211 | return std::make_pair(0U, Mips::CPURegsRegisterClass); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1212 | case 'f': |
Bruno Cardoso Lopes | bdfbb74 | 2009-03-21 00:05:07 +0000 | [diff] [blame] | 1213 | if (VT == MVT::f32) |
| 1214 | return std::make_pair(0U, Mips::FGR32RegisterClass); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1215 | if (VT == MVT::f64) |
| 1216 | if ((!Subtarget->isSingleFloat()) && (!Subtarget->isFP64bit())) |
| 1217 | return std::make_pair(0U, Mips::AFGR64RegisterClass); |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 1218 | } |
| 1219 | } |
| 1220 | return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); |
| 1221 | } |
| 1222 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1223 | /// Given a register class constraint, like 'r', if this corresponds directly |
| 1224 | /// to an LLVM register class, return a register of 0 and the register class |
| 1225 | /// pointer. |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 1226 | std::vector<unsigned> MipsTargetLowering:: |
| 1227 | getRegClassForInlineAsmConstraint(const std::string &Constraint, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1228 | MVT VT) const |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 1229 | { |
| 1230 | if (Constraint.size() != 1) |
| 1231 | return std::vector<unsigned>(); |
| 1232 | |
| 1233 | switch (Constraint[0]) { |
| 1234 | default : break; |
| 1235 | case 'r': |
| 1236 | // GCC Mips Constraint Letters |
| 1237 | case 'd': |
| 1238 | case 'y': |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1239 | return make_vector<unsigned>(Mips::T0, Mips::T1, Mips::T2, Mips::T3, |
| 1240 | Mips::T4, Mips::T5, Mips::T6, Mips::T7, Mips::S0, Mips::S1, |
| 1241 | Mips::S2, Mips::S3, Mips::S4, Mips::S5, Mips::S6, Mips::S7, |
| 1242 | Mips::T8, 0); |
| 1243 | |
| 1244 | case 'f': |
Duncan Sands | 1512642 | 2008-07-08 09:33:14 +0000 | [diff] [blame] | 1245 | if (VT == MVT::f32) { |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1246 | if (Subtarget->isSingleFloat()) |
| 1247 | return make_vector<unsigned>(Mips::F2, Mips::F3, Mips::F4, Mips::F5, |
| 1248 | Mips::F6, Mips::F7, Mips::F8, Mips::F9, Mips::F10, Mips::F11, |
| 1249 | Mips::F20, Mips::F21, Mips::F22, Mips::F23, Mips::F24, |
| 1250 | Mips::F25, Mips::F26, Mips::F27, Mips::F28, Mips::F29, |
| 1251 | Mips::F30, Mips::F31, 0); |
| 1252 | else |
| 1253 | return make_vector<unsigned>(Mips::F2, Mips::F4, Mips::F6, Mips::F8, |
| 1254 | Mips::F10, Mips::F20, Mips::F22, Mips::F24, Mips::F26, |
| 1255 | Mips::F28, Mips::F30, 0); |
Duncan Sands | 1512642 | 2008-07-08 09:33:14 +0000 | [diff] [blame] | 1256 | } |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1257 | |
| 1258 | if (VT == MVT::f64) |
| 1259 | if ((!Subtarget->isSingleFloat()) && (!Subtarget->isFP64bit())) |
| 1260 | return make_vector<unsigned>(Mips::D1, Mips::D2, Mips::D3, Mips::D4, |
| 1261 | Mips::D5, Mips::D10, Mips::D11, Mips::D12, Mips::D13, |
| 1262 | Mips::D14, Mips::D15, 0); |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 1263 | } |
| 1264 | return std::vector<unsigned>(); |
| 1265 | } |
Dan Gohman | 6520e20 | 2008-10-18 02:06:02 +0000 | [diff] [blame] | 1266 | |
| 1267 | bool |
| 1268 | MipsTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { |
| 1269 | // The Mips target isn't yet aware of offsets. |
| 1270 | return false; |
| 1271 | } |