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