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