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" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 16 | #include "MipsISelLowering.h" |
Bruno Cardoso Lopes | a2b1bb5 | 2007-08-28 05:08:16 +0000 | [diff] [blame] | 17 | #include "MipsMachineFunction.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 18 | #include "MipsTargetMachine.h" |
Chris Lattner | b71b909 | 2009-08-13 06:28:06 +0000 | [diff] [blame] | 19 | #include "MipsTargetObjectFile.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 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 37 | const char *MipsTargetLowering::getTargetNodeName(unsigned Opcode) const { |
| 38 | switch (Opcode) { |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 39 | case MipsISD::JmpLink : return "MipsISD::JmpLink"; |
| 40 | case MipsISD::Hi : return "MipsISD::Hi"; |
| 41 | case MipsISD::Lo : return "MipsISD::Lo"; |
| 42 | case MipsISD::GPRel : return "MipsISD::GPRel"; |
| 43 | case MipsISD::Ret : return "MipsISD::Ret"; |
| 44 | case MipsISD::SelectCC : return "MipsISD::SelectCC"; |
| 45 | case MipsISD::FPSelectCC : return "MipsISD::FPSelectCC"; |
| 46 | case MipsISD::FPBrcond : return "MipsISD::FPBrcond"; |
| 47 | case MipsISD::FPCmp : return "MipsISD::FPCmp"; |
Bruno Cardoso Lopes | d3bdf19 | 2009-05-27 17:23:44 +0000 | [diff] [blame] | 48 | case MipsISD::FPRound : return "MipsISD::FPRound"; |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 49 | case MipsISD::MAdd : return "MipsISD::MAdd"; |
| 50 | case MipsISD::MAddu : return "MipsISD::MAddu"; |
| 51 | case MipsISD::MSub : return "MipsISD::MSub"; |
| 52 | case MipsISD::MSubu : return "MipsISD::MSubu"; |
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:: |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 58 | MipsTargetLowering(MipsTargetMachine &TM) |
Chris Lattner | b71b909 | 2009-08-13 06:28:06 +0000 | [diff] [blame] | 59 | : TargetLowering(TM, new MipsTargetObjectFile()) { |
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 |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 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 | |
| 66 | // Set up the register classes |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 67 | addRegisterClass(MVT::i32, Mips::CPURegsRegisterClass); |
| 68 | addRegisterClass(MVT::f32, Mips::FGR32RegisterClass); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 69 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 70 | // When dealing with single precision only, use libcalls |
Bruno Cardoso Lopes | bdfbb74 | 2009-03-21 00:05:07 +0000 | [diff] [blame] | 71 | if (!Subtarget->isSingleFloat()) |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 72 | if (!Subtarget->isFP64bit()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 73 | addRegisterClass(MVT::f64, Mips::AFGR64RegisterClass); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 74 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 75 | // Load extented operations for i1 types must be promoted |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 76 | setLoadExtAction(ISD::EXTLOAD, MVT::i1, Promote); |
| 77 | setLoadExtAction(ISD::ZEXTLOAD, MVT::i1, Promote); |
| 78 | setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 79 | |
Eli Friedman | 6055a6a | 2009-07-17 04:07:24 +0000 | [diff] [blame] | 80 | // MIPS doesn't have extending float->double load/store |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 81 | setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand); |
| 82 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
Eli Friedman | 10a3659 | 2009-07-17 02:28:12 +0000 | [diff] [blame] | 83 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 84 | // Used by legalize types to correctly generate the setcc result. |
| 85 | // Without this, every float setcc comes with a AND/OR with the result, |
| 86 | // we don't want this, since the fpcmp result goes to a flag register, |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 87 | // which is used implicitly by brcond and select operations. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 88 | AddPromotedToType(ISD::SETCC, MVT::i1, MVT::i32); |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 89 | |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 90 | // Mips Custom Operations |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 91 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
Bruno Cardoso Lopes | ca8a2aa | 2011-03-04 20:01:52 +0000 | [diff] [blame] | 92 | setOperationAction(ISD::BlockAddress, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 93 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); |
| 94 | setOperationAction(ISD::JumpTable, MVT::i32, Custom); |
| 95 | setOperationAction(ISD::ConstantPool, MVT::i32, Custom); |
| 96 | setOperationAction(ISD::SELECT, MVT::f32, Custom); |
| 97 | setOperationAction(ISD::SELECT, MVT::f64, Custom); |
| 98 | setOperationAction(ISD::SELECT, MVT::i32, Custom); |
| 99 | setOperationAction(ISD::SETCC, MVT::f32, Custom); |
| 100 | setOperationAction(ISD::SETCC, MVT::f64, Custom); |
| 101 | setOperationAction(ISD::BRCOND, MVT::Other, Custom); |
| 102 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Custom); |
| 103 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); |
Bruno Cardoso Lopes | 6059b85 | 2010-02-06 21:00:02 +0000 | [diff] [blame] | 104 | setOperationAction(ISD::VASTART, MVT::Other, Custom); |
| 105 | |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 106 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +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 |
Bruno Cardoso Lopes | 1906c5a | 2008-08-02 19:37:33 +0000 | [diff] [blame] | 109 | // the result from these setcc are in a flag registers (FCR31). |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 110 | setOperationAction(ISD::AND, MVT::i32, Custom); |
| 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. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +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); |
| 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); |
| 120 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
| 121 | setOperationAction(ISD::CTTZ, MVT::i32, Expand); |
| 122 | setOperationAction(ISD::ROTL, MVT::i32, Expand); |
Bruno Cardoso Lopes | 908b6dd | 2010-12-09 17:32:30 +0000 | [diff] [blame] | 123 | |
| 124 | if (!Subtarget->isMips32r2()) |
| 125 | setOperationAction(ISD::ROTR, MVT::i32, Expand); |
| 126 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 127 | setOperationAction(ISD::SHL_PARTS, MVT::i32, Expand); |
| 128 | setOperationAction(ISD::SRA_PARTS, MVT::i32, Expand); |
| 129 | setOperationAction(ISD::SRL_PARTS, MVT::i32, Expand); |
| 130 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Expand); |
| 131 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Expand); |
| 132 | setOperationAction(ISD::FSIN, MVT::f32, Expand); |
Bruno Cardoso Lopes | 5d6fb5d | 2011-03-04 18:54:14 +0000 | [diff] [blame] | 133 | setOperationAction(ISD::FSIN, MVT::f64, Expand); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 134 | setOperationAction(ISD::FCOS, MVT::f32, Expand); |
Bruno Cardoso Lopes | 5d6fb5d | 2011-03-04 18:54:14 +0000 | [diff] [blame] | 135 | setOperationAction(ISD::FCOS, MVT::f64, Expand); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 136 | setOperationAction(ISD::FPOWI, MVT::f32, Expand); |
| 137 | setOperationAction(ISD::FPOW, MVT::f32, Expand); |
| 138 | setOperationAction(ISD::FLOG, MVT::f32, Expand); |
| 139 | setOperationAction(ISD::FLOG2, MVT::f32, Expand); |
| 140 | setOperationAction(ISD::FLOG10, MVT::f32, Expand); |
| 141 | setOperationAction(ISD::FEXP, MVT::f32, Expand); |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 142 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 143 | setOperationAction(ISD::EH_LABEL, MVT::Other, Expand); |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 144 | |
| 145 | // Use the default for now |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 146 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
| 147 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
| 148 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Expand); |
Bruno Cardoso Lopes | 85e9212 | 2008-07-07 19:11:24 +0000 | [diff] [blame] | 149 | |
Bruno Cardoso Lopes | ea9d4d6 | 2008-08-04 06:44:31 +0000 | [diff] [blame] | 150 | if (Subtarget->isSingleFloat()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 151 | setOperationAction(ISD::SELECT_CC, MVT::f64, Expand); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 152 | |
Bruno Cardoso Lopes | 7728f7e | 2008-07-09 05:32:22 +0000 | [diff] [blame] | 153 | if (!Subtarget->hasSEInReg()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 154 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand); |
| 155 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Bruno Cardoso Lopes | 65ad452 | 2008-08-08 06:16:31 +0000 | [diff] [blame] | 158 | if (!Subtarget->hasBitCount()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 159 | setOperationAction(ISD::CTLZ, MVT::i32, Expand); |
Bruno Cardoso Lopes | 65ad452 | 2008-08-08 06:16:31 +0000 | [diff] [blame] | 160 | |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 161 | if (!Subtarget->hasSwap()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 162 | setOperationAction(ISD::BSWAP, MVT::i32, Expand); |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 163 | |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 164 | setTargetDAGCombine(ISD::ADDE); |
| 165 | setTargetDAGCombine(ISD::SUBE); |
| 166 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 167 | setStackPointerRegisterToSaveRestore(Mips::SP); |
| 168 | computeRegisterProperties(); |
| 169 | } |
| 170 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 171 | MVT::SimpleValueType MipsTargetLowering::getSetCCResultType(EVT VT) const { |
| 172 | return MVT::i32; |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Bill Wendling | b4202b8 | 2009-07-01 18:50:55 +0000 | [diff] [blame] | 175 | /// getFunctionAlignment - Return the Log2 alignment of this function. |
Bill Wendling | 20c568f | 2009-06-30 22:38:32 +0000 | [diff] [blame] | 176 | unsigned MipsTargetLowering::getFunctionAlignment(const Function *) const { |
| 177 | return 2; |
| 178 | } |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 179 | |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 180 | // SelectMadd - |
| 181 | // Transforms a subgraph in CurDAG if the following pattern is found: |
| 182 | // (addc multLo, Lo0), (adde multHi, Hi0), |
| 183 | // where, |
| 184 | // multHi/Lo: product of multiplication |
Bruno Cardoso Lopes | 8e826e6 | 2011-02-10 18:05:10 +0000 | [diff] [blame] | 185 | // Lo0: initial value of Lo register |
| 186 | // Hi0: initial value of Hi register |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 187 | // Return true if mattern matching was successful. |
| 188 | static bool SelectMadd(SDNode* ADDENode, SelectionDAG* CurDAG) { |
Bruno Cardoso Lopes | 8e826e6 | 2011-02-10 18:05:10 +0000 | [diff] [blame] | 189 | // ADDENode's second operand must be a flag output of an ADDC node in order |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 190 | // for the matching to be successful. |
| 191 | SDNode* ADDCNode = ADDENode->getOperand(2).getNode(); |
| 192 | |
| 193 | if (ADDCNode->getOpcode() != ISD::ADDC) |
| 194 | return false; |
| 195 | |
| 196 | SDValue MultHi = ADDENode->getOperand(0); |
| 197 | SDValue MultLo = ADDCNode->getOperand(0); |
Bruno Cardoso Lopes | 8e826e6 | 2011-02-10 18:05:10 +0000 | [diff] [blame] | 198 | SDNode* MultNode = MultHi.getNode(); |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 199 | unsigned MultOpc = MultHi.getOpcode(); |
| 200 | |
| 201 | // MultHi and MultLo must be generated by the same node, |
| 202 | if (MultLo.getNode() != MultNode) |
| 203 | return false; |
| 204 | |
| 205 | // and it must be a multiplication. |
| 206 | if (MultOpc != ISD::SMUL_LOHI && MultOpc != ISD::UMUL_LOHI) |
| 207 | return false; |
Bruno Cardoso Lopes | 8e826e6 | 2011-02-10 18:05:10 +0000 | [diff] [blame] | 208 | |
| 209 | // MultLo amd MultHi must be the first and second output of MultNode |
| 210 | // respectively. |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 211 | if (MultHi.getResNo() != 1 || MultLo.getResNo() != 0) |
| 212 | return false; |
| 213 | |
Bruno Cardoso Lopes | 8e826e6 | 2011-02-10 18:05:10 +0000 | [diff] [blame] | 214 | // Transform this to a MADD only if ADDENode and ADDCNode are the only users |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 215 | // of the values of MultNode, in which case MultNode will be removed in later |
| 216 | // phases. |
| 217 | // If there exist users other than ADDENode or ADDCNode, this function returns |
Bruno Cardoso Lopes | 8e826e6 | 2011-02-10 18:05:10 +0000 | [diff] [blame] | 218 | // here, which will result in MultNode being mapped to a single MULT |
| 219 | // instruction node rather than a pair of MULT and MADD instructions being |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 220 | // produced. |
| 221 | if (!MultHi.hasOneUse() || !MultLo.hasOneUse()) |
| 222 | return false; |
| 223 | |
Bruno Cardoso Lopes | 8e826e6 | 2011-02-10 18:05:10 +0000 | [diff] [blame] | 224 | SDValue Chain = CurDAG->getEntryNode(); |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 225 | DebugLoc dl = ADDENode->getDebugLoc(); |
| 226 | |
| 227 | // create MipsMAdd(u) node |
| 228 | MultOpc = MultOpc == ISD::UMUL_LOHI ? MipsISD::MAddu : MipsISD::MAdd; |
Bruno Cardoso Lopes | 8e826e6 | 2011-02-10 18:05:10 +0000 | [diff] [blame] | 229 | |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 230 | SDValue MAdd = CurDAG->getNode(MultOpc, dl, |
| 231 | MVT::Glue, |
| 232 | MultNode->getOperand(0),// Factor 0 |
| 233 | MultNode->getOperand(1),// Factor 1 |
Bruno Cardoso Lopes | 8e826e6 | 2011-02-10 18:05:10 +0000 | [diff] [blame] | 234 | ADDCNode->getOperand(1),// Lo0 |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 235 | ADDENode->getOperand(1));// Hi0 |
| 236 | |
| 237 | // create CopyFromReg nodes |
| 238 | SDValue CopyFromLo = CurDAG->getCopyFromReg(Chain, dl, Mips::LO, MVT::i32, |
| 239 | MAdd); |
Bruno Cardoso Lopes | 8e826e6 | 2011-02-10 18:05:10 +0000 | [diff] [blame] | 240 | SDValue CopyFromHi = CurDAG->getCopyFromReg(CopyFromLo.getValue(1), dl, |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 241 | Mips::HI, MVT::i32, |
| 242 | CopyFromLo.getValue(2)); |
| 243 | |
| 244 | // replace uses of adde and addc here |
| 245 | if (!SDValue(ADDCNode, 0).use_empty()) |
| 246 | CurDAG->ReplaceAllUsesOfValueWith(SDValue(ADDCNode, 0), CopyFromLo); |
| 247 | |
| 248 | if (!SDValue(ADDENode, 0).use_empty()) |
| 249 | CurDAG->ReplaceAllUsesOfValueWith(SDValue(ADDENode, 0), CopyFromHi); |
| 250 | |
Bruno Cardoso Lopes | 8e826e6 | 2011-02-10 18:05:10 +0000 | [diff] [blame] | 251 | return true; |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | // SelectMsub - |
| 255 | // Transforms a subgraph in CurDAG if the following pattern is found: |
| 256 | // (addc Lo0, multLo), (sube Hi0, multHi), |
| 257 | // where, |
| 258 | // multHi/Lo: product of multiplication |
Bruno Cardoso Lopes | 8e826e6 | 2011-02-10 18:05:10 +0000 | [diff] [blame] | 259 | // Lo0: initial value of Lo register |
| 260 | // Hi0: initial value of Hi register |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 261 | // Return true if mattern matching was successful. |
| 262 | static bool SelectMsub(SDNode* SUBENode, SelectionDAG* CurDAG) { |
Bruno Cardoso Lopes | 8e826e6 | 2011-02-10 18:05:10 +0000 | [diff] [blame] | 263 | // SUBENode's second operand must be a flag output of an SUBC node in order |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 264 | // for the matching to be successful. |
| 265 | SDNode* SUBCNode = SUBENode->getOperand(2).getNode(); |
| 266 | |
| 267 | if (SUBCNode->getOpcode() != ISD::SUBC) |
| 268 | return false; |
| 269 | |
| 270 | SDValue MultHi = SUBENode->getOperand(1); |
| 271 | SDValue MultLo = SUBCNode->getOperand(1); |
Bruno Cardoso Lopes | 8e826e6 | 2011-02-10 18:05:10 +0000 | [diff] [blame] | 272 | SDNode* MultNode = MultHi.getNode(); |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 273 | unsigned MultOpc = MultHi.getOpcode(); |
| 274 | |
| 275 | // MultHi and MultLo must be generated by the same node, |
| 276 | if (MultLo.getNode() != MultNode) |
| 277 | return false; |
| 278 | |
| 279 | // and it must be a multiplication. |
| 280 | if (MultOpc != ISD::SMUL_LOHI && MultOpc != ISD::UMUL_LOHI) |
| 281 | return false; |
| 282 | |
| 283 | // MultLo amd MultHi must be the first and second output of MultNode |
| 284 | // respectively. |
| 285 | if (MultHi.getResNo() != 1 || MultLo.getResNo() != 0) |
| 286 | return false; |
| 287 | |
| 288 | // Transform this to a MSUB only if SUBENode and SUBCNode are the only users |
| 289 | // of the values of MultNode, in which case MultNode will be removed in later |
| 290 | // phases. |
| 291 | // If there exist users other than SUBENode or SUBCNode, this function returns |
| 292 | // here, which will result in MultNode being mapped to a single MULT |
| 293 | // instruction node rather than a pair of MULT and MSUB instructions being |
| 294 | // produced. |
| 295 | if (!MultHi.hasOneUse() || !MultLo.hasOneUse()) |
| 296 | return false; |
| 297 | |
| 298 | SDValue Chain = CurDAG->getEntryNode(); |
| 299 | DebugLoc dl = SUBENode->getDebugLoc(); |
| 300 | |
| 301 | // create MipsSub(u) node |
| 302 | MultOpc = MultOpc == ISD::UMUL_LOHI ? MipsISD::MSubu : MipsISD::MSub; |
| 303 | |
| 304 | SDValue MSub = CurDAG->getNode(MultOpc, dl, |
| 305 | MVT::Glue, |
| 306 | MultNode->getOperand(0),// Factor 0 |
| 307 | MultNode->getOperand(1),// Factor 1 |
| 308 | SUBCNode->getOperand(0),// Lo0 |
| 309 | SUBENode->getOperand(0));// Hi0 |
| 310 | |
| 311 | // create CopyFromReg nodes |
| 312 | SDValue CopyFromLo = CurDAG->getCopyFromReg(Chain, dl, Mips::LO, MVT::i32, |
| 313 | MSub); |
| 314 | SDValue CopyFromHi = CurDAG->getCopyFromReg(CopyFromLo.getValue(1), dl, |
| 315 | Mips::HI, MVT::i32, |
| 316 | CopyFromLo.getValue(2)); |
| 317 | |
| 318 | // replace uses of sube and subc here |
| 319 | if (!SDValue(SUBCNode, 0).use_empty()) |
| 320 | CurDAG->ReplaceAllUsesOfValueWith(SDValue(SUBCNode, 0), CopyFromLo); |
| 321 | |
| 322 | if (!SDValue(SUBENode, 0).use_empty()) |
| 323 | CurDAG->ReplaceAllUsesOfValueWith(SDValue(SUBENode, 0), CopyFromHi); |
| 324 | |
| 325 | return true; |
| 326 | } |
| 327 | |
| 328 | static SDValue PerformADDECombine(SDNode *N, SelectionDAG& DAG, |
| 329 | TargetLowering::DAGCombinerInfo &DCI, |
| 330 | const MipsSubtarget* Subtarget) { |
| 331 | if (DCI.isBeforeLegalize()) |
| 332 | return SDValue(); |
| 333 | |
| 334 | if (Subtarget->isMips32() && SelectMadd(N, &DAG)) |
| 335 | return SDValue(N, 0); |
Bruno Cardoso Lopes | 8e826e6 | 2011-02-10 18:05:10 +0000 | [diff] [blame] | 336 | |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 337 | return SDValue(); |
Bruno Cardoso Lopes | 8e826e6 | 2011-02-10 18:05:10 +0000 | [diff] [blame] | 338 | } |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 339 | |
| 340 | static SDValue PerformSUBECombine(SDNode *N, SelectionDAG& DAG, |
| 341 | TargetLowering::DAGCombinerInfo &DCI, |
| 342 | const MipsSubtarget* Subtarget) { |
| 343 | if (DCI.isBeforeLegalize()) |
| 344 | return SDValue(); |
| 345 | |
| 346 | if (Subtarget->isMips32() && SelectMsub(N, &DAG)) |
| 347 | return SDValue(N, 0); |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 348 | |
Bruno Cardoso Lopes | 8e826e6 | 2011-02-10 18:05:10 +0000 | [diff] [blame] | 349 | return SDValue(); |
| 350 | } |
| 351 | |
| 352 | SDValue MipsTargetLowering::PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 353 | const { |
| 354 | SelectionDAG &DAG = DCI.DAG; |
| 355 | unsigned opc = N->getOpcode(); |
| 356 | |
| 357 | switch (opc) { |
| 358 | default: break; |
| 359 | case ISD::ADDE: |
| 360 | return PerformADDECombine(N, DAG, DCI, Subtarget); |
| 361 | case ISD::SUBE: |
| 362 | return PerformSUBECombine(N, DAG, DCI, Subtarget); |
| 363 | } |
| 364 | |
| 365 | return SDValue(); |
| 366 | } |
| 367 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 368 | SDValue MipsTargetLowering:: |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 369 | LowerOperation(SDValue Op, SelectionDAG &DAG) const |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 370 | { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 371 | switch (Op.getOpcode()) |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 372 | { |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 373 | case ISD::AND: return LowerANDOR(Op, DAG); |
| 374 | case ISD::BRCOND: return LowerBRCOND(Op, DAG); |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 375 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
| 376 | case ISD::DYNAMIC_STACKALLOC: return LowerDYNAMIC_STACKALLOC(Op, DAG); |
Bruno Cardoso Lopes | d3bdf19 | 2009-05-27 17:23:44 +0000 | [diff] [blame] | 377 | case ISD::FP_TO_SINT: return LowerFP_TO_SINT(Op, DAG); |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 378 | case ISD::GlobalAddress: return LowerGlobalAddress(Op, DAG); |
Bruno Cardoso Lopes | ca8a2aa | 2011-03-04 20:01:52 +0000 | [diff] [blame] | 379 | case ISD::BlockAddress: return LowerBlockAddress(Op, DAG); |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 380 | case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); |
| 381 | case ISD::JumpTable: return LowerJumpTable(Op, DAG); |
| 382 | case ISD::OR: return LowerANDOR(Op, DAG); |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 383 | case ISD::SELECT: return LowerSELECT(Op, DAG); |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 384 | case ISD::SETCC: return LowerSETCC(Op, DAG); |
Bruno Cardoso Lopes | 6059b85 | 2010-02-06 21:00:02 +0000 | [diff] [blame] | 385 | case ISD::VASTART: return LowerVASTART(Op, DAG); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 386 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 387 | return SDValue(); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | //===----------------------------------------------------------------------===// |
| 391 | // Lower helper functions |
| 392 | //===----------------------------------------------------------------------===// |
| 393 | |
| 394 | // AddLiveIn - This helper function adds the specified physical register to the |
| 395 | // MachineFunction as a live in value. It also creates a corresponding |
| 396 | // virtual register for it. |
| 397 | static unsigned |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 398 | AddLiveIn(MachineFunction &MF, unsigned PReg, TargetRegisterClass *RC) |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 399 | { |
| 400 | assert(RC->contains(PReg) && "Not the correct regclass!"); |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 401 | unsigned VReg = MF.getRegInfo().createVirtualRegister(RC); |
| 402 | MF.getRegInfo().addLiveIn(PReg, VReg); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 403 | return VReg; |
| 404 | } |
| 405 | |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 406 | // Get fp branch code (not opcode) from condition code. |
| 407 | static Mips::FPBranchCode GetFPBranchCodeFromCond(Mips::CondCode CC) { |
| 408 | if (CC >= Mips::FCOND_F && CC <= Mips::FCOND_NGT) |
| 409 | return Mips::BRANCH_T; |
| 410 | |
| 411 | if (CC >= Mips::FCOND_T && CC <= Mips::FCOND_GT) |
| 412 | return Mips::BRANCH_F; |
| 413 | |
| 414 | return Mips::BRANCH_INVALID; |
| 415 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 416 | |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 417 | static unsigned FPBranchCodeToOpc(Mips::FPBranchCode BC) { |
| 418 | switch(BC) { |
| 419 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 420 | llvm_unreachable("Unknown branch code"); |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 421 | case Mips::BRANCH_T : return Mips::BC1T; |
| 422 | case Mips::BRANCH_F : return Mips::BC1F; |
| 423 | case Mips::BRANCH_TL : return Mips::BC1TL; |
| 424 | case Mips::BRANCH_FL : return Mips::BC1FL; |
| 425 | } |
| 426 | } |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 427 | |
| 428 | static Mips::CondCode FPCondCCodeToFCC(ISD::CondCode CC) { |
| 429 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 430 | default: llvm_unreachable("Unknown fp condition code!"); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 431 | case ISD::SETEQ: |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 432 | case ISD::SETOEQ: return Mips::FCOND_EQ; |
| 433 | case ISD::SETUNE: return Mips::FCOND_OGL; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 434 | case ISD::SETLT: |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 435 | case ISD::SETOLT: return Mips::FCOND_OLT; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 436 | case ISD::SETGT: |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 437 | case ISD::SETOGT: return Mips::FCOND_OGT; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 438 | case ISD::SETLE: |
| 439 | case ISD::SETOLE: return Mips::FCOND_OLE; |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 440 | case ISD::SETGE: |
| 441 | case ISD::SETOGE: return Mips::FCOND_OGE; |
| 442 | case ISD::SETULT: return Mips::FCOND_ULT; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 443 | case ISD::SETULE: return Mips::FCOND_ULE; |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 444 | case ISD::SETUGT: return Mips::FCOND_UGT; |
| 445 | case ISD::SETUGE: return Mips::FCOND_UGE; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 446 | case ISD::SETUO: return Mips::FCOND_UN; |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 447 | case ISD::SETO: return Mips::FCOND_OR; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 448 | case ISD::SETNE: |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 449 | case ISD::SETONE: return Mips::FCOND_NEQ; |
| 450 | case ISD::SETUEQ: return Mips::FCOND_UEQ; |
| 451 | } |
| 452 | } |
| 453 | |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 454 | MachineBasicBlock * |
| 455 | MipsTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
Dan Gohman | af1d8ca | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 456 | MachineBasicBlock *BB) const { |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 457 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 458 | bool isFPCmp = false; |
Dale Johannesen | 9481757 | 2009-02-13 02:34:39 +0000 | [diff] [blame] | 459 | DebugLoc dl = MI->getDebugLoc(); |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 460 | |
| 461 | switch (MI->getOpcode()) { |
| 462 | default: assert(false && "Unexpected instr type to insert"); |
| 463 | case Mips::Select_FCC: |
Bruno Cardoso Lopes | bdfbb74 | 2009-03-21 00:05:07 +0000 | [diff] [blame] | 464 | case Mips::Select_FCC_S32: |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 465 | case Mips::Select_FCC_D32: |
| 466 | isFPCmp = true; // FALL THROUGH |
| 467 | case Mips::Select_CC: |
Bruno Cardoso Lopes | bdfbb74 | 2009-03-21 00:05:07 +0000 | [diff] [blame] | 468 | case Mips::Select_CC_S32: |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 469 | case Mips::Select_CC_D32: { |
| 470 | // To "insert" a SELECT_CC instruction, we actually have to insert the |
| 471 | // diamond control-flow pattern. The incoming instruction knows the |
| 472 | // destination vreg to set, the condition code register to branch on, the |
| 473 | // true/false values to select between, and a branch opcode to use. |
| 474 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 475 | MachineFunction::iterator It = BB; |
| 476 | ++It; |
| 477 | |
| 478 | // thisMBB: |
| 479 | // ... |
| 480 | // TrueVal = ... |
| 481 | // setcc r1, r2, r3 |
| 482 | // bNE r1, r0, copy1MBB |
| 483 | // fallthrough --> copy0MBB |
| 484 | MachineBasicBlock *thisMBB = BB; |
| 485 | MachineFunction *F = BB->getParent(); |
| 486 | MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 487 | MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 488 | F->insert(It, copy0MBB); |
| 489 | F->insert(It, sinkMBB); |
| 490 | |
| 491 | // Transfer the remainder of BB and its successor edges to sinkMBB. |
| 492 | sinkMBB->splice(sinkMBB->begin(), BB, |
| 493 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 494 | BB->end()); |
| 495 | sinkMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 496 | |
| 497 | // Next, add the true and fallthrough blocks as its successors. |
| 498 | BB->addSuccessor(copy0MBB); |
| 499 | BB->addSuccessor(sinkMBB); |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 500 | |
| 501 | // Emit the right instruction according to the type of the operands compared |
| 502 | if (isFPCmp) { |
| 503 | // Find the condiction code present in the setcc operation. |
| 504 | Mips::CondCode CC = (Mips::CondCode)MI->getOperand(4).getImm(); |
| 505 | // Get the branch opcode from the branch code. |
| 506 | unsigned Opc = FPBranchCodeToOpc(GetFPBranchCodeFromCond(CC)); |
Dale Johannesen | 9481757 | 2009-02-13 02:34:39 +0000 | [diff] [blame] | 507 | BuildMI(BB, dl, TII->get(Opc)).addMBB(sinkMBB); |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 508 | } else |
Dale Johannesen | 9481757 | 2009-02-13 02:34:39 +0000 | [diff] [blame] | 509 | 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] | 510 | .addReg(Mips::ZERO).addMBB(sinkMBB); |
| 511 | |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 512 | // copy0MBB: |
| 513 | // %FalseValue = ... |
| 514 | // # fallthrough to sinkMBB |
| 515 | BB = copy0MBB; |
| 516 | |
| 517 | // Update machine-CFG edges |
| 518 | BB->addSuccessor(sinkMBB); |
| 519 | |
| 520 | // sinkMBB: |
Bruno Cardoso Lopes | 29e9daa | 2010-07-20 07:58:51 +0000 | [diff] [blame] | 521 | // %Result = phi [ %TrueValue, thisMBB ], [ %FalseValue, copy0MBB ] |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 522 | // ... |
| 523 | BB = sinkMBB; |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 524 | BuildMI(*BB, BB->begin(), dl, |
| 525 | TII->get(Mips::PHI), MI->getOperand(0).getReg()) |
Bruno Cardoso Lopes | 29e9daa | 2010-07-20 07:58:51 +0000 | [diff] [blame] | 526 | .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB) |
| 527 | .addReg(MI->getOperand(3).getReg()).addMBB(copy0MBB); |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 528 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 529 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 530 | return BB; |
| 531 | } |
| 532 | } |
| 533 | } |
| 534 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 535 | //===----------------------------------------------------------------------===// |
| 536 | // Misc Lower Operation implementation |
| 537 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 538 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 539 | SDValue MipsTargetLowering:: |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 540 | LowerFP_TO_SINT(SDValue Op, SelectionDAG &DAG) const |
Bruno Cardoso Lopes | d3bdf19 | 2009-05-27 17:23:44 +0000 | [diff] [blame] | 541 | { |
| 542 | if (!Subtarget->isMips1()) |
| 543 | return Op; |
| 544 | |
| 545 | MachineFunction &MF = DAG.getMachineFunction(); |
| 546 | unsigned CCReg = AddLiveIn(MF, Mips::FCR31, Mips::CCRRegisterClass); |
| 547 | |
| 548 | SDValue Chain = DAG.getEntryNode(); |
| 549 | DebugLoc dl = Op.getDebugLoc(); |
| 550 | SDValue Src = Op.getOperand(0); |
| 551 | |
| 552 | // Set the condition register |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 553 | SDValue CondReg = DAG.getCopyFromReg(Chain, dl, CCReg, MVT::i32); |
Bruno Cardoso Lopes | d3bdf19 | 2009-05-27 17:23:44 +0000 | [diff] [blame] | 554 | CondReg = DAG.getCopyToReg(Chain, dl, Mips::AT, CondReg); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 555 | CondReg = DAG.getCopyFromReg(CondReg, dl, Mips::AT, MVT::i32); |
Bruno Cardoso Lopes | d3bdf19 | 2009-05-27 17:23:44 +0000 | [diff] [blame] | 556 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 557 | SDValue Cst = DAG.getConstant(3, MVT::i32); |
| 558 | SDValue Or = DAG.getNode(ISD::OR, dl, MVT::i32, CondReg, Cst); |
| 559 | Cst = DAG.getConstant(2, MVT::i32); |
| 560 | SDValue Xor = DAG.getNode(ISD::XOR, dl, MVT::i32, Or, Cst); |
Bruno Cardoso Lopes | d3bdf19 | 2009-05-27 17:23:44 +0000 | [diff] [blame] | 561 | |
| 562 | SDValue InFlag(0, 0); |
| 563 | CondReg = DAG.getCopyToReg(Chain, dl, Mips::FCR31, Xor, InFlag); |
| 564 | |
| 565 | // Emit the round instruction and bit convert to integer |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 566 | SDValue Trunc = DAG.getNode(MipsISD::FPRound, dl, MVT::f32, |
Bruno Cardoso Lopes | d3bdf19 | 2009-05-27 17:23:44 +0000 | [diff] [blame] | 567 | Src, CondReg.getValue(1)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 568 | SDValue BitCvt = DAG.getNode(ISD::BITCAST, dl, MVT::i32, Trunc); |
Bruno Cardoso Lopes | d3bdf19 | 2009-05-27 17:23:44 +0000 | [diff] [blame] | 569 | return BitCvt; |
| 570 | } |
| 571 | |
| 572 | SDValue MipsTargetLowering:: |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 573 | LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 574 | { |
| 575 | SDValue Chain = Op.getOperand(0); |
| 576 | SDValue Size = Op.getOperand(1); |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 577 | DebugLoc dl = Op.getDebugLoc(); |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 578 | |
| 579 | // Get a reference from Mips stack pointer |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 580 | SDValue StackPointer = DAG.getCopyFromReg(Chain, dl, Mips::SP, MVT::i32); |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 581 | |
| 582 | // Subtract the dynamic size from the actual stack size to |
| 583 | // obtain the new stack size. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 584 | SDValue Sub = DAG.getNode(ISD::SUB, dl, MVT::i32, StackPointer, Size); |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 585 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 586 | // The Sub result contains the new stack start address, so it |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 587 | // must be placed in the stack pointer register. |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 588 | Chain = DAG.getCopyToReg(StackPointer.getValue(1), dl, Mips::SP, Sub); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 589 | |
| 590 | // This node always has two return values: a new stack pointer |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 591 | // value and a chain |
| 592 | SDValue Ops[2] = { Sub, Chain }; |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 593 | return DAG.getMergeValues(Ops, 2, dl); |
Bruno Cardoso Lopes | 7da151c | 2008-08-07 19:08:11 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | SDValue MipsTargetLowering:: |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 597 | LowerANDOR(SDValue Op, SelectionDAG &DAG) const |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 598 | { |
| 599 | SDValue LHS = Op.getOperand(0); |
| 600 | SDValue RHS = Op.getOperand(1); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 601 | DebugLoc dl = Op.getDebugLoc(); |
| 602 | |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 603 | if (LHS.getOpcode() != MipsISD::FPCmp || RHS.getOpcode() != MipsISD::FPCmp) |
| 604 | return Op; |
| 605 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 606 | SDValue True = DAG.getConstant(1, MVT::i32); |
| 607 | SDValue False = DAG.getConstant(0, MVT::i32); |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 608 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 609 | SDValue LSEL = DAG.getNode(MipsISD::FPSelectCC, dl, True.getValueType(), |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 610 | LHS, True, False, LHS.getOperand(2)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 611 | SDValue RSEL = DAG.getNode(MipsISD::FPSelectCC, dl, True.getValueType(), |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 612 | RHS, True, False, RHS.getOperand(2)); |
| 613 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 614 | return DAG.getNode(Op.getOpcode(), dl, MVT::i32, LSEL, RSEL); |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | SDValue MipsTargetLowering:: |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 618 | LowerBRCOND(SDValue Op, SelectionDAG &DAG) const |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 619 | { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 620 | // The first operand is the chain, the second is the condition, the third is |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 621 | // the block to branch to if the condition is true. |
| 622 | SDValue Chain = Op.getOperand(0); |
| 623 | SDValue Dest = Op.getOperand(2); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 624 | DebugLoc dl = Op.getDebugLoc(); |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 625 | |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 626 | if (Op.getOperand(1).getOpcode() != MipsISD::FPCmp) |
Bruno Cardoso Lopes | 4b877ca | 2008-07-30 17:06:13 +0000 | [diff] [blame] | 627 | return Op; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 628 | |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 629 | SDValue CondRes = Op.getOperand(1); |
| 630 | SDValue CCNode = CondRes.getOperand(2); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 631 | Mips::CondCode CC = |
| 632 | (Mips::CondCode)cast<ConstantSDNode>(CCNode)->getZExtValue(); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 633 | SDValue BrCode = DAG.getConstant(GetFPBranchCodeFromCond(CC), MVT::i32); |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 634 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 635 | return DAG.getNode(MipsISD::FPBrcond, dl, Op.getValueType(), Chain, BrCode, |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 636 | Dest, CondRes); |
| 637 | } |
| 638 | |
| 639 | SDValue MipsTargetLowering:: |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 640 | LowerSETCC(SDValue Op, SelectionDAG &DAG) const |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 641 | { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 642 | // The operands to this are the left and right operands to compare (ops #0, |
| 643 | // and #1) and the condition code to compare them with (op #2) as a |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 644 | // CondCodeSDNode. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 645 | SDValue LHS = Op.getOperand(0); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 646 | SDValue RHS = Op.getOperand(1); |
| 647 | DebugLoc dl = Op.getDebugLoc(); |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 648 | |
| 649 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get(); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 650 | |
| 651 | return DAG.getNode(MipsISD::FPCmp, dl, Op.getValueType(), LHS, RHS, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 652 | DAG.getConstant(FPCondCCodeToFCC(CC), MVT::i32)); |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | SDValue MipsTargetLowering:: |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 656 | LowerSELECT(SDValue Op, SelectionDAG &DAG) const |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 657 | { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 658 | SDValue Cond = Op.getOperand(0); |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 659 | SDValue True = Op.getOperand(1); |
| 660 | SDValue False = Op.getOperand(2); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 661 | DebugLoc dl = Op.getDebugLoc(); |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 662 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 663 | // if the incomming condition comes from a integer compare, the select |
| 664 | // operation must be SelectCC or a conditional move if the subtarget |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 665 | // supports it. |
| 666 | if (Cond.getOpcode() != MipsISD::FPCmp) { |
| 667 | if (Subtarget->hasCondMov() && !True.getValueType().isFloatingPoint()) |
| 668 | return Op; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 669 | return DAG.getNode(MipsISD::SelectCC, dl, True.getValueType(), |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 670 | Cond, True, False); |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | // if the incomming condition comes from fpcmp, the select |
| 674 | // operation must use FPSelectCC. |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 675 | SDValue CCNode = Cond.getOperand(2); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 676 | return DAG.getNode(MipsISD::FPSelectCC, dl, True.getValueType(), |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 677 | Cond, True, False, CCNode); |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 678 | } |
| 679 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 680 | SDValue MipsTargetLowering::LowerGlobalAddress(SDValue Op, |
| 681 | SelectionDAG &DAG) const { |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 682 | // FIXME there isn't actually debug info here |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 683 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 684 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 685 | |
Eli Friedman | e2c7408 | 2009-08-03 02:22:28 +0000 | [diff] [blame] | 686 | if (getTargetMachine().getRelocationModel() != Reloc::PIC_) { |
Chris Lattner | e3736f8 | 2009-08-13 05:41:27 +0000 | [diff] [blame] | 687 | SDVTList VTs = DAG.getVTList(MVT::i32); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 688 | |
Chris Lattner | b71b909 | 2009-08-13 06:28:06 +0000 | [diff] [blame] | 689 | MipsTargetObjectFile &TLOF = (MipsTargetObjectFile&)getObjFileLowering(); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 690 | |
Chris Lattner | e3736f8 | 2009-08-13 05:41:27 +0000 | [diff] [blame] | 691 | // %gp_rel relocation |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 692 | if (TLOF.IsGlobalInSmallSection(GV, getTargetMachine())) { |
| 693 | SDValue GA = DAG.getTargetGlobalAddress(GV, dl, MVT::i32, 0, |
Bruno Cardoso Lopes | c517cb0 | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 694 | MipsII::MO_GPREL); |
Chris Lattner | e3736f8 | 2009-08-13 05:41:27 +0000 | [diff] [blame] | 695 | SDValue GPRelNode = DAG.getNode(MipsISD::GPRel, dl, VTs, &GA, 1); |
| 696 | SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(MVT::i32); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 697 | return DAG.getNode(ISD::ADD, dl, MVT::i32, GOT, GPRelNode); |
Chris Lattner | e3736f8 | 2009-08-13 05:41:27 +0000 | [diff] [blame] | 698 | } |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 699 | // %hi/%lo relocation |
Devang Patel | 0d881da | 2010-07-06 22:08:15 +0000 | [diff] [blame] | 700 | SDValue GA = DAG.getTargetGlobalAddress(GV, dl, MVT::i32, 0, |
Bruno Cardoso Lopes | c517cb0 | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 701 | MipsII::MO_ABS_HILO); |
Chris Lattner | e3736f8 | 2009-08-13 05:41:27 +0000 | [diff] [blame] | 702 | SDValue HiPart = DAG.getNode(MipsISD::Hi, dl, VTs, &GA, 1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 703 | SDValue Lo = DAG.getNode(MipsISD::Lo, dl, MVT::i32, GA); |
| 704 | return DAG.getNode(ISD::ADD, dl, MVT::i32, HiPart, Lo); |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 705 | |
Bruno Cardoso Lopes | c517cb0 | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 706 | } else { |
Devang Patel | 0d881da | 2010-07-06 22:08:15 +0000 | [diff] [blame] | 707 | SDValue GA = DAG.getTargetGlobalAddress(GV, dl, MVT::i32, 0, |
Bruno Cardoso Lopes | c517cb0 | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 708 | MipsII::MO_GOT); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 709 | SDValue ResNode = DAG.getLoad(MVT::i32, dl, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 710 | DAG.getEntryNode(), GA, MachinePointerInfo(), |
David Greene | f6fa186 | 2010-02-15 16:56:10 +0000 | [diff] [blame] | 711 | false, false, 0); |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 712 | // On functions and global targets not internal linked only |
| 713 | // a load from got/GP is necessary for PIC to work. |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 714 | if (!GV->hasLocalLinkage() || isa<Function>(GV)) |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 715 | return ResNode; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 716 | SDValue Lo = DAG.getNode(MipsISD::Lo, dl, MVT::i32, GA); |
| 717 | return DAG.getNode(ISD::ADD, dl, MVT::i32, ResNode, Lo); |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 718 | } |
| 719 | |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 720 | llvm_unreachable("Dont know how to handle GlobalAddress"); |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 721 | return SDValue(0,0); |
| 722 | } |
| 723 | |
Bruno Cardoso Lopes | ca8a2aa | 2011-03-04 20:01:52 +0000 | [diff] [blame] | 724 | SDValue MipsTargetLowering::LowerBlockAddress(SDValue Op, |
| 725 | SelectionDAG &DAG) const { |
| 726 | if (getTargetMachine().getRelocationModel() != Reloc::PIC_) { |
| 727 | assert(false && "implement LowerBlockAddress for -static"); |
| 728 | return SDValue(0, 0); |
| 729 | } |
| 730 | else { |
| 731 | // FIXME there isn't actually debug info here |
| 732 | DebugLoc dl = Op.getDebugLoc(); |
| 733 | const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress(); |
| 734 | SDValue BAGOTOffset = DAG.getBlockAddress(BA, MVT::i32, true, |
| 735 | MipsII::MO_GOT); |
| 736 | SDValue BALOOffset = DAG.getBlockAddress(BA, MVT::i32, true, |
| 737 | MipsII::MO_ABS_HILO); |
| 738 | SDValue Load = DAG.getLoad(MVT::i32, dl, |
| 739 | DAG.getEntryNode(), BAGOTOffset, |
| 740 | MachinePointerInfo(), false, false, 0); |
| 741 | SDValue Lo = DAG.getNode(MipsISD::Lo, dl, MVT::i32, BALOOffset); |
| 742 | return DAG.getNode(ISD::ADD, dl, MVT::i32, Load, Lo); |
| 743 | } |
| 744 | } |
| 745 | |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 746 | SDValue MipsTargetLowering:: |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 747 | LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 748 | { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 749 | llvm_unreachable("TLS not implemented for MIPS."); |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 750 | return SDValue(); // Not reached |
| 751 | } |
| 752 | |
| 753 | SDValue MipsTargetLowering:: |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 754 | LowerJumpTable(SDValue Op, SelectionDAG &DAG) const |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 755 | { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 756 | SDValue ResNode; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 757 | SDValue HiPart; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 758 | // FIXME there isn't actually debug info here |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 759 | DebugLoc dl = Op.getDebugLoc(); |
Bruno Cardoso Lopes | c517cb0 | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 760 | bool IsPIC = getTargetMachine().getRelocationModel() == Reloc::PIC_; |
| 761 | unsigned char OpFlag = IsPIC ? MipsII::MO_GOT : MipsII::MO_ABS_HILO; |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 762 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 763 | EVT PtrVT = Op.getValueType(); |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 764 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Op); |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 765 | |
Bruno Cardoso Lopes | c517cb0 | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 766 | SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PtrVT, OpFlag); |
| 767 | |
Bruno Cardoso Lopes | 4677379 | 2010-07-20 08:37:04 +0000 | [diff] [blame] | 768 | if (!IsPIC) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 769 | SDValue Ops[] = { JTI }; |
Bruno Cardoso Lopes | c517cb0 | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 770 | HiPart = DAG.getNode(MipsISD::Hi, dl, DAG.getVTList(MVT::i32), Ops, 1); |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 771 | } else // Emit Load from Global Pointer |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 772 | HiPart = DAG.getLoad(MVT::i32, dl, DAG.getEntryNode(), JTI, |
| 773 | MachinePointerInfo(), |
David Greene | f6fa186 | 2010-02-15 16:56:10 +0000 | [diff] [blame] | 774 | false, false, 0); |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 775 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 776 | SDValue Lo = DAG.getNode(MipsISD::Lo, dl, MVT::i32, JTI); |
| 777 | ResNode = DAG.getNode(ISD::ADD, dl, MVT::i32, HiPart, Lo); |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 778 | |
| 779 | return ResNode; |
| 780 | } |
| 781 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 782 | SDValue MipsTargetLowering:: |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 783 | LowerConstantPool(SDValue Op, SelectionDAG &DAG) const |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 784 | { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 785 | SDValue ResNode; |
Bruno Cardoso Lopes | 92e87f2 | 2008-07-23 16:01:50 +0000 | [diff] [blame] | 786 | ConstantPoolSDNode *N = cast<ConstantPoolSDNode>(Op); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 787 | const Constant *C = N->getConstVal(); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 788 | // FIXME there isn't actually debug info here |
| 789 | DebugLoc dl = Op.getDebugLoc(); |
Bruno Cardoso Lopes | 92e87f2 | 2008-07-23 16:01:50 +0000 | [diff] [blame] | 790 | |
| 791 | // gp_rel relocation |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 792 | // FIXME: we should reference the constant pool using small data sections, |
Bruno Cardoso Lopes | f33bc43 | 2008-07-28 19:26:25 +0000 | [diff] [blame] | 793 | // but the asm printer currently doens't support this feature without |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 794 | // hacking it. This feature should come soon so we can uncomment the |
Bruno Cardoso Lopes | f33bc43 | 2008-07-28 19:26:25 +0000 | [diff] [blame] | 795 | // stuff below. |
Eli Friedman | e2c7408 | 2009-08-03 02:22:28 +0000 | [diff] [blame] | 796 | //if (IsInSmallSection(C->getType())) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 797 | // SDValue GPRelNode = DAG.getNode(MipsISD::GPRel, MVT::i32, CP); |
| 798 | // SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(MVT::i32); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 799 | // ResNode = DAG.getNode(ISD::ADD, MVT::i32, GOT, GPRelNode); |
Bruno Cardoso Lopes | d71cebf | 2009-11-25 12:17:58 +0000 | [diff] [blame] | 800 | |
| 801 | if (getTargetMachine().getRelocationModel() != Reloc::PIC_) { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 802 | SDValue CP = DAG.getTargetConstantPool(C, MVT::i32, N->getAlignment(), |
Bruno Cardoso Lopes | d71cebf | 2009-11-25 12:17:58 +0000 | [diff] [blame] | 803 | N->getOffset(), MipsII::MO_ABS_HILO); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 804 | SDValue HiPart = DAG.getNode(MipsISD::Hi, dl, MVT::i32, CP); |
| 805 | SDValue Lo = DAG.getNode(MipsISD::Lo, dl, MVT::i32, CP); |
| 806 | ResNode = DAG.getNode(ISD::ADD, dl, MVT::i32, HiPart, Lo); |
Bruno Cardoso Lopes | d71cebf | 2009-11-25 12:17:58 +0000 | [diff] [blame] | 807 | } else { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 808 | SDValue CP = DAG.getTargetConstantPool(C, MVT::i32, N->getAlignment(), |
Bruno Cardoso Lopes | d71cebf | 2009-11-25 12:17:58 +0000 | [diff] [blame] | 809 | N->getOffset(), MipsII::MO_GOT); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 810 | SDValue Load = DAG.getLoad(MVT::i32, dl, DAG.getEntryNode(), |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 811 | CP, MachinePointerInfo::getConstantPool(), |
| 812 | false, false, 0); |
Bruno Cardoso Lopes | d71cebf | 2009-11-25 12:17:58 +0000 | [diff] [blame] | 813 | SDValue Lo = DAG.getNode(MipsISD::Lo, dl, MVT::i32, CP); |
| 814 | ResNode = DAG.getNode(ISD::ADD, dl, MVT::i32, Load, Lo); |
| 815 | } |
Bruno Cardoso Lopes | 92e87f2 | 2008-07-23 16:01:50 +0000 | [diff] [blame] | 816 | |
| 817 | return ResNode; |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 818 | } |
| 819 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 820 | SDValue MipsTargetLowering::LowerVASTART(SDValue Op, SelectionDAG &DAG) const { |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 821 | MachineFunction &MF = DAG.getMachineFunction(); |
| 822 | MipsFunctionInfo *FuncInfo = MF.getInfo<MipsFunctionInfo>(); |
| 823 | |
Bruno Cardoso Lopes | 6059b85 | 2010-02-06 21:00:02 +0000 | [diff] [blame] | 824 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 825 | SDValue FI = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), |
| 826 | getPointerTy()); |
Bruno Cardoso Lopes | 6059b85 | 2010-02-06 21:00:02 +0000 | [diff] [blame] | 827 | |
| 828 | // vastart just stores the address of the VarArgsFrameIndex slot into the |
| 829 | // memory location argument. |
| 830 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
Chris Lattner | 8026a9d | 2010-09-21 17:50:43 +0000 | [diff] [blame] | 831 | return DAG.getStore(Op.getOperand(0), dl, FI, Op.getOperand(1), |
| 832 | MachinePointerInfo(SV), |
David Greene | f6fa186 | 2010-02-15 16:56:10 +0000 | [diff] [blame] | 833 | false, false, 0); |
Bruno Cardoso Lopes | 6059b85 | 2010-02-06 21:00:02 +0000 | [diff] [blame] | 834 | } |
| 835 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 836 | //===----------------------------------------------------------------------===// |
| 837 | // Calling Convention Implementation |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 838 | //===----------------------------------------------------------------------===// |
| 839 | |
| 840 | #include "MipsGenCallingConv.inc" |
| 841 | |
| 842 | //===----------------------------------------------------------------------===// |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 843 | // TODO: Implement a generic logic using tblgen that can support this. |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 844 | // Mips O32 ABI rules: |
| 845 | // --- |
| 846 | // i32 - Passed in A0, A1, A2, A3 and stack |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 847 | // f32 - Only passed in f32 registers if no int reg has been used yet to hold |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 848 | // an argument. Otherwise, passed in A1, A2, A3 and stack. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 849 | // f64 - Only passed in two aliased f32 registers if no int reg has been used |
| 850 | // yet to hold an argument. Otherwise, use A2, A3 and stack. If A1 is |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 851 | // not used, it must be shadowed. If only A3 is avaiable, shadow it and |
| 852 | // go to stack. |
| 853 | //===----------------------------------------------------------------------===// |
| 854 | |
Duncan Sands | 1e96bab | 2010-11-04 10:49:57 +0000 | [diff] [blame] | 855 | static bool CC_MipsO32(unsigned ValNo, MVT ValVT, |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 856 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 857 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
| 858 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 859 | static const unsigned IntRegsSize=4, FloatRegsSize=2; |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 860 | |
| 861 | static const unsigned IntRegs[] = { |
| 862 | Mips::A0, Mips::A1, Mips::A2, Mips::A3 |
| 863 | }; |
| 864 | static const unsigned F32Regs[] = { |
| 865 | Mips::F12, Mips::F14 |
| 866 | }; |
| 867 | static const unsigned F64Regs[] = { |
| 868 | Mips::D6, Mips::D7 |
| 869 | }; |
| 870 | |
Bruno Cardoso Lopes | 8e826e6 | 2011-02-10 18:05:10 +0000 | [diff] [blame] | 871 | unsigned Reg = 0; |
| 872 | static bool IntRegUsed = false; |
| 873 | |
| 874 | // This must be the first arg of the call if no regs have been allocated. |
| 875 | // Initialize IntRegUsed in that case. |
| 876 | if (IntRegs[State.getFirstUnallocated(IntRegs, IntRegsSize)] == Mips::A0 && |
| 877 | F32Regs[State.getFirstUnallocated(F32Regs, FloatRegsSize)] == Mips::F12 && |
| 878 | F64Regs[State.getFirstUnallocated(F64Regs, FloatRegsSize)] == Mips::D6) |
| 879 | IntRegUsed = false; |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 880 | |
| 881 | // Promote i8 and i16 |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 882 | if (LocVT == MVT::i8 || LocVT == MVT::i16) { |
| 883 | LocVT = MVT::i32; |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 884 | if (ArgFlags.isSExt()) |
| 885 | LocInfo = CCValAssign::SExt; |
| 886 | else if (ArgFlags.isZExt()) |
| 887 | LocInfo = CCValAssign::ZExt; |
| 888 | else |
| 889 | LocInfo = CCValAssign::AExt; |
| 890 | } |
| 891 | |
Bruno Cardoso Lopes | 8e826e6 | 2011-02-10 18:05:10 +0000 | [diff] [blame] | 892 | if (ValVT == MVT::i32) { |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 893 | Reg = State.AllocateReg(IntRegs, IntRegsSize); |
| 894 | IntRegUsed = true; |
Bruno Cardoso Lopes | 8e826e6 | 2011-02-10 18:05:10 +0000 | [diff] [blame] | 895 | } else if (ValVT == MVT::f32) { |
| 896 | // An int reg has to be marked allocated regardless of whether or not |
| 897 | // IntRegUsed is true. |
| 898 | Reg = State.AllocateReg(IntRegs, IntRegsSize); |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 899 | |
Bruno Cardoso Lopes | 8e826e6 | 2011-02-10 18:05:10 +0000 | [diff] [blame] | 900 | if (IntRegUsed) { |
| 901 | if (Reg) // Int reg is available |
| 902 | LocVT = MVT::i32; |
| 903 | } else { |
| 904 | unsigned FReg = State.AllocateReg(F32Regs, FloatRegsSize); |
| 905 | if (FReg) // F32 reg is available |
| 906 | Reg = FReg; |
| 907 | else if (Reg) // No F32 regs are available, but an int reg is available. |
| 908 | LocVT = MVT::i32; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 909 | } |
Bruno Cardoso Lopes | 8e826e6 | 2011-02-10 18:05:10 +0000 | [diff] [blame] | 910 | } else if (ValVT == MVT::f64) { |
| 911 | // Int regs have to be marked allocated regardless of whether or not |
| 912 | // IntRegUsed is true. |
| 913 | Reg = State.AllocateReg(IntRegs, IntRegsSize); |
| 914 | if (Reg == Mips::A1) |
| 915 | Reg = State.AllocateReg(IntRegs, IntRegsSize); |
| 916 | else if (Reg == Mips::A3) |
| 917 | Reg = 0; |
| 918 | State.AllocateReg(IntRegs, IntRegsSize); |
| 919 | |
| 920 | // At this point, Reg is A0, A2 or 0, and all the unavailable integer regs |
| 921 | // are marked as allocated. |
| 922 | if (IntRegUsed) { |
| 923 | if (Reg)// if int reg is available |
| 924 | LocVT = MVT::i32; |
| 925 | } else { |
| 926 | unsigned FReg = State.AllocateReg(F64Regs, FloatRegsSize); |
| 927 | if (FReg) // F64 reg is available. |
| 928 | Reg = FReg; |
| 929 | else if (Reg) // No F64 regs are available, but an int reg is available. |
| 930 | LocVT = MVT::i32; |
| 931 | } |
| 932 | } else |
| 933 | assert(false && "cannot handle this ValVT"); |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 934 | |
| 935 | if (!Reg) { |
| 936 | unsigned SizeInBytes = ValVT.getSizeInBits() >> 3; |
| 937 | unsigned Offset = State.AllocateStack(SizeInBytes, SizeInBytes); |
| 938 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
| 939 | } else |
| 940 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
| 941 | |
| 942 | return false; // CC must always match |
| 943 | } |
| 944 | |
Duncan Sands | 1e96bab | 2010-11-04 10:49:57 +0000 | [diff] [blame] | 945 | static bool CC_MipsO32_VarArgs(unsigned ValNo, MVT ValVT, |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 946 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 947 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
| 948 | |
| 949 | static const unsigned IntRegsSize=4; |
| 950 | |
| 951 | static const unsigned IntRegs[] = { |
| 952 | Mips::A0, Mips::A1, Mips::A2, Mips::A3 |
| 953 | }; |
| 954 | |
| 955 | // Promote i8 and i16 |
| 956 | if (LocVT == MVT::i8 || LocVT == MVT::i16) { |
| 957 | LocVT = MVT::i32; |
| 958 | if (ArgFlags.isSExt()) |
| 959 | LocInfo = CCValAssign::SExt; |
| 960 | else if (ArgFlags.isZExt()) |
| 961 | LocInfo = CCValAssign::ZExt; |
| 962 | else |
| 963 | LocInfo = CCValAssign::AExt; |
| 964 | } |
| 965 | |
Bruno Cardoso Lopes | c42fb5f | 2011-03-04 20:27:44 +0000 | [diff] [blame^] | 966 | unsigned Reg; |
| 967 | |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 968 | if (ValVT == MVT::i32 || ValVT == MVT::f32) { |
Bruno Cardoso Lopes | c42fb5f | 2011-03-04 20:27:44 +0000 | [diff] [blame^] | 969 | Reg = State.AllocateReg(IntRegs, IntRegsSize); |
| 970 | LocVT = MVT::i32; |
| 971 | } else if (ValVT == MVT::f64) { |
| 972 | Reg = State.AllocateReg(IntRegs, IntRegsSize); |
| 973 | if (Reg == Mips::A1 || Reg == Mips::A3) |
| 974 | Reg = State.AllocateReg(IntRegs, IntRegsSize); |
| 975 | State.AllocateReg(IntRegs, IntRegsSize); |
| 976 | LocVT = MVT::i32; |
| 977 | } else |
| 978 | llvm_unreachable("Cannot handle this ValVT."); |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 979 | |
Bruno Cardoso Lopes | c42fb5f | 2011-03-04 20:27:44 +0000 | [diff] [blame^] | 980 | if (!Reg) { |
| 981 | unsigned SizeInBytes = ValVT.getSizeInBits() >> 3; |
| 982 | unsigned Offset = State.AllocateStack(SizeInBytes, SizeInBytes); |
| 983 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
| 984 | } else |
| 985 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 986 | |
Bruno Cardoso Lopes | c42fb5f | 2011-03-04 20:27:44 +0000 | [diff] [blame^] | 987 | return false; // CC must always match |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 988 | } |
| 989 | |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 990 | //===----------------------------------------------------------------------===// |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 991 | // Call Calling Convention Implementation |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 992 | //===----------------------------------------------------------------------===// |
| 993 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 994 | /// LowerCall - functions arguments are copied from virtual regs to |
Nate Begeman | 5bf4b75 | 2009-01-26 03:15:54 +0000 | [diff] [blame] | 995 | /// (physical regs)/(stack frame), CALLSEQ_START and CALLSEQ_END are emitted. |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 996 | /// TODO: isTailCall. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 997 | SDValue |
Evan Cheng | 022d9e1 | 2010-02-02 23:55:14 +0000 | [diff] [blame] | 998 | MipsTargetLowering::LowerCall(SDValue Chain, SDValue Callee, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 999 | CallingConv::ID CallConv, bool isVarArg, |
Evan Cheng | 0c439eb | 2010-01-27 00:07:07 +0000 | [diff] [blame] | 1000 | bool &isTailCall, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1001 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1002 | const SmallVectorImpl<SDValue> &OutVals, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1003 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1004 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1005 | SmallVectorImpl<SDValue> &InVals) const { |
Evan Cheng | 0c439eb | 2010-01-27 00:07:07 +0000 | [diff] [blame] | 1006 | // MIPs target does not yet support tail call optimization. |
| 1007 | isTailCall = false; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1008 | |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 1009 | MachineFunction &MF = DAG.getMachineFunction(); |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 1010 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Bruno Cardoso Lopes | c517cb0 | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 1011 | bool IsPIC = getTargetMachine().getRelocationModel() == Reloc::PIC_; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1012 | |
| 1013 | // Analyze operands of the call, assigning locations to each operand. |
| 1014 | SmallVector<CCValAssign, 16> ArgLocs; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1015 | CCState CCInfo(CallConv, isVarArg, getTargetMachine(), ArgLocs, |
| 1016 | *DAG.getContext()); |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 1017 | |
Bruno Cardoso Lopes | b27cb55 | 2008-07-15 02:03:36 +0000 | [diff] [blame] | 1018 | // To meet O32 ABI, Mips must always allocate 16 bytes on |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 1019 | // the stack (even if less than 4 are used as arguments) |
Bruno Cardoso Lopes | b27cb55 | 2008-07-15 02:03:36 +0000 | [diff] [blame] | 1020 | if (Subtarget->isABI_O32()) { |
Duncan Sands | 1e96bab | 2010-11-04 10:49:57 +0000 | [diff] [blame] | 1021 | int VTsize = MVT(MVT::i32).getSizeInBits()/8; |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 1022 | MFI->CreateFixedObject(VTsize, (VTsize*3), true); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1023 | CCInfo.AnalyzeCallOperands(Outs, |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 1024 | isVarArg ? CC_MipsO32_VarArgs : CC_MipsO32); |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 1025 | } else |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1026 | CCInfo.AnalyzeCallOperands(Outs, CC_Mips); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1027 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1028 | // Get a count of how many bytes are to be pushed on the stack. |
| 1029 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1030 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumBytes, true)); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1031 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1032 | // With EABI is it possible to have 16 args on registers. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1033 | SmallVector<std::pair<unsigned, SDValue>, 16> RegsToPass; |
| 1034 | SmallVector<SDValue, 8> MemOpChains; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1035 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1036 | // First/LastArgStackLoc contains the first/last |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1037 | // "at stack" argument location. |
| 1038 | int LastArgStackLoc = 0; |
| 1039 | unsigned FirstStackArgLoc = (Subtarget->isABI_EABI() ? 0 : 16); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1040 | |
| 1041 | // Walk the register/memloc assignments, inserting copies/loads. |
| 1042 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1043 | SDValue Arg = OutVals[i]; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1044 | CCValAssign &VA = ArgLocs[i]; |
| 1045 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1046 | // Promote the value if needed. |
| 1047 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1048 | default: llvm_unreachable("Unknown loc info!"); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1049 | case CCValAssign::Full: |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 1050 | if (Subtarget->isABI_O32() && VA.isRegLoc()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1051 | if (VA.getValVT() == MVT::f32 && VA.getLocVT() == MVT::i32) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1052 | Arg = DAG.getNode(ISD::BITCAST, dl, MVT::i32, Arg); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1053 | if (VA.getValVT() == MVT::f64 && VA.getLocVT() == MVT::i32) { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1054 | Arg = DAG.getNode(ISD::BITCAST, dl, MVT::i64, Arg); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1055 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Arg, |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 1056 | DAG.getConstant(0, getPointerTy())); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1057 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Arg, |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 1058 | DAG.getConstant(1, getPointerTy())); |
| 1059 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Lo)); |
| 1060 | RegsToPass.push_back(std::make_pair(VA.getLocReg()+1, Hi)); |
| 1061 | continue; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1062 | } |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 1063 | } |
| 1064 | break; |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 1065 | case CCValAssign::SExt: |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1066 | Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 1067 | break; |
| 1068 | case CCValAssign::ZExt: |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1069 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 1070 | break; |
| 1071 | case CCValAssign::AExt: |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1072 | Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 1073 | break; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1074 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1075 | |
| 1076 | // Arguments that can be passed on register must be kept at |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 1077 | // RegsToPass vector |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1078 | if (VA.isRegLoc()) { |
| 1079 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 1080 | continue; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1081 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1082 | |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 1083 | // Register can't get to this point... |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 1084 | assert(VA.isMemLoc()); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1085 | |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 1086 | // Create the frame index object for this incoming parameter |
| 1087 | // This guarantees that when allocating Local Area the firsts |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1088 | // 16 bytes which are alwayes reserved won't be overwritten |
| 1089 | // if O32 ABI is used. For EABI the first address is zero. |
| 1090 | LastArgStackLoc = (FirstStackArgLoc + VA.getLocMemOffset()); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1091 | int FI = MFI->CreateFixedObject(VA.getValVT().getSizeInBits()/8, |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 1092 | LastArgStackLoc, true); |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 1093 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1094 | SDValue PtrOff = DAG.getFrameIndex(FI,getPointerTy()); |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 1095 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1096 | // emit ISD::STORE whichs stores the |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 1097 | // parameter value to a stack Location |
Chris Lattner | 8026a9d | 2010-09-21 17:50:43 +0000 | [diff] [blame] | 1098 | MemOpChains.push_back(DAG.getStore(Chain, dl, Arg, PtrOff, |
| 1099 | MachinePointerInfo(), |
David Greene | f6fa186 | 2010-02-15 16:56:10 +0000 | [diff] [blame] | 1100 | false, false, 0)); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1101 | } |
| 1102 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1103 | // Transform all store nodes into one single node because all store |
| 1104 | // nodes are independent of each other. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1105 | if (!MemOpChains.empty()) |
| 1106 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1107 | &MemOpChains[0], MemOpChains.size()); |
| 1108 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1109 | // Build a sequence of copy-to-reg nodes chained together with token |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1110 | // chain and flag operands which copy the outgoing args into registers. |
| 1111 | // The InFlag in necessary since all emited instructions must be |
| 1112 | // stuck together. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1113 | SDValue InFlag; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1114 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1115 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1116 | RegsToPass[i].second, InFlag); |
| 1117 | InFlag = Chain.getValue(1); |
| 1118 | } |
| 1119 | |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1120 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1121 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 1122 | // node so that legalize doesn't hack it. |
Bruno Cardoso Lopes | c517cb0 | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 1123 | unsigned char OpFlag = IsPIC ? MipsII::MO_GOT_CALL : MipsII::MO_NO_FLAG; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1124 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) |
| 1125 | Callee = DAG.getTargetGlobalAddress(G->getGlobal(), dl, |
Bruno Cardoso Lopes | c517cb0 | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 1126 | getPointerTy(), 0, OpFlag); |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1127 | else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1128 | Callee = DAG.getTargetExternalSymbol(S->getSymbol(), |
Bruno Cardoso Lopes | c517cb0 | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 1129 | getPointerTy(), OpFlag); |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1130 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1131 | // MipsJmpLink = #chain, #target_address, #opt_in_flags... |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1132 | // = Chain, Callee, Reg#1, Reg#2, ... |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1133 | // |
| 1134 | // Returns a chain & a flag for retval copy to use. |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1135 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1136 | SmallVector<SDValue, 8> Ops; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1137 | Ops.push_back(Chain); |
| 1138 | Ops.push_back(Callee); |
| 1139 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1140 | // Add argument registers to the end of the list so that they are |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1141 | // known live into the call. |
| 1142 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) |
| 1143 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 1144 | RegsToPass[i].second.getValueType())); |
| 1145 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1146 | if (InFlag.getNode()) |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1147 | Ops.push_back(InFlag); |
| 1148 | |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1149 | Chain = DAG.getNode(MipsISD::JmpLink, dl, NodeTys, &Ops[0], Ops.size()); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1150 | InFlag = Chain.getValue(1); |
| 1151 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1152 | // Create a stack location to hold GP when PIC is used. This stack |
| 1153 | // location is used on function prologue to save GP and also after all |
| 1154 | // emited CALL's to restore GP. |
Bruno Cardoso Lopes | c517cb0 | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 1155 | if (IsPIC) { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1156 | // Function can have an arbitrary number of calls, so |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1157 | // hold the LastArgStackLoc with the biggest offset. |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 1158 | int FI; |
| 1159 | MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>(); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1160 | if (LastArgStackLoc >= MipsFI->getGPStackOffset()) { |
| 1161 | LastArgStackLoc = (!LastArgStackLoc) ? (16) : (LastArgStackLoc+4); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1162 | // Create the frame index only once. SPOffset here can be anything |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 1163 | // (this will be fixed on processFunctionBeforeFrameFinalized) |
| 1164 | if (MipsFI->getGPStackOffset() == -1) { |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 1165 | FI = MFI->CreateFixedObject(4, 0, true); |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 1166 | MipsFI->setGPFI(FI); |
| 1167 | } |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1168 | MipsFI->setGPStackOffset(LastArgStackLoc); |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 1171 | // Reload GP value. |
| 1172 | FI = MipsFI->getGPFI(); |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1173 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 1174 | SDValue GPLoad = DAG.getLoad(MVT::i32, dl, Chain, FIN, |
| 1175 | MachinePointerInfo::getFixedStack(FI), |
David Greene | f6fa186 | 2010-02-15 16:56:10 +0000 | [diff] [blame] | 1176 | false, false, 0); |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 1177 | Chain = GPLoad.getValue(1); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1178 | Chain = DAG.getCopyToReg(Chain, dl, DAG.getRegister(Mips::GP, MVT::i32), |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1179 | GPLoad, SDValue(0,0)); |
Bruno Cardoso Lopes | bdbb750 | 2008-06-01 03:49:39 +0000 | [diff] [blame] | 1180 | InFlag = Chain.getValue(1); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1181 | } |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 1182 | |
Bruno Cardoso Lopes | 3ed6f87 | 2010-01-30 18:32:07 +0000 | [diff] [blame] | 1183 | // Create the CALLSEQ_END node. |
| 1184 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, true), |
| 1185 | DAG.getIntPtrConstant(0, true), InFlag); |
| 1186 | InFlag = Chain.getValue(1); |
| 1187 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1188 | // Handle result values, copying them out of physregs into vregs that we |
| 1189 | // return. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1190 | return LowerCallResult(Chain, InFlag, CallConv, isVarArg, |
| 1191 | Ins, dl, DAG, InVals); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1192 | } |
| 1193 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1194 | /// LowerCallResult - Lower the result values of a call into the |
| 1195 | /// appropriate copies out of appropriate physical registers. |
| 1196 | SDValue |
| 1197 | MipsTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1198 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1199 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1200 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1201 | SmallVectorImpl<SDValue> &InVals) const { |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 1202 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1203 | // Assign locations to each value returned by this call. |
| 1204 | SmallVector<CCValAssign, 16> RVLocs; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1205 | CCState CCInfo(CallConv, isVarArg, getTargetMachine(), |
Owen Anderson | e922c02 | 2009-07-22 00:24:57 +0000 | [diff] [blame] | 1206 | RVLocs, *DAG.getContext()); |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 1207 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1208 | CCInfo.AnalyzeCallResult(Ins, RetCC_Mips); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1209 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1210 | // Copy all of the result registers out of their specified physreg. |
| 1211 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1212 | Chain = DAG.getCopyFromReg(Chain, dl, RVLocs[i].getLocReg(), |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1213 | RVLocs[i].getValVT(), InFlag).getValue(1); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1214 | InFlag = Chain.getValue(2); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1215 | InVals.push_back(Chain.getValue(0)); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1216 | } |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 1217 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1218 | return Chain; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | //===----------------------------------------------------------------------===// |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1222 | // Formal Arguments Calling Convention Implementation |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1223 | //===----------------------------------------------------------------------===// |
| 1224 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1225 | /// LowerFormalArguments - transform physical registers into virtual registers |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 1226 | /// and generate load operations for arguments places on the stack. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1227 | SDValue |
| 1228 | MipsTargetLowering::LowerFormalArguments(SDValue Chain, |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 1229 | CallingConv::ID CallConv, bool isVarArg, |
| 1230 | const SmallVectorImpl<ISD::InputArg> |
| 1231 | &Ins, |
| 1232 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1233 | SmallVectorImpl<SDValue> &InVals) |
| 1234 | const { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1235 | |
Bruno Cardoso Lopes | f7f3b50 | 2008-08-04 07:12:52 +0000 | [diff] [blame] | 1236 | MachineFunction &MF = DAG.getMachineFunction(); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1237 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Bruno Cardoso Lopes | a2b1bb5 | 2007-08-28 05:08:16 +0000 | [diff] [blame] | 1238 | MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>(); |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 1239 | |
| 1240 | unsigned StackReg = MF.getTarget().getRegisterInfo()->getFrameRegister(MF); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 1241 | MipsFI->setVarArgsFrameIndex(0); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1242 | |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 1243 | // Used with vargs to acumulate store chains. |
| 1244 | std::vector<SDValue> OutChains; |
| 1245 | |
| 1246 | // Keep track of the last register used for arguments |
| 1247 | unsigned ArgRegEnd = 0; |
| 1248 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1249 | // Assign locations to all of the incoming arguments. |
| 1250 | SmallVector<CCValAssign, 16> ArgLocs; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1251 | CCState CCInfo(CallConv, isVarArg, getTargetMachine(), |
| 1252 | ArgLocs, *DAG.getContext()); |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 1253 | |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 1254 | if (Subtarget->isABI_O32()) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1255 | CCInfo.AnalyzeFormalArguments(Ins, |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 1256 | isVarArg ? CC_MipsO32_VarArgs : CC_MipsO32); |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 1257 | else |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1258 | CCInfo.AnalyzeFormalArguments(Ins, CC_Mips); |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 1259 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1260 | SDValue StackPtr; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1261 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1262 | unsigned FirstStackArgLoc = (Subtarget->isABI_EABI() ? 0 : 16); |
| 1263 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1264 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1265 | CCValAssign &VA = ArgLocs[i]; |
| 1266 | |
| 1267 | // Arguments stored on registers |
| 1268 | if (VA.isRegLoc()) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1269 | EVT RegVT = VA.getLocVT(); |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 1270 | ArgRegEnd = VA.getLocReg(); |
Bill Wendling | 06b8c19 | 2008-07-09 05:55:53 +0000 | [diff] [blame] | 1271 | TargetRegisterClass *RC = 0; |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 1272 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1273 | if (RegVT == MVT::i32) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1274 | RC = Mips::CPURegsRegisterClass; |
| 1275 | else if (RegVT == MVT::f32) |
Bruno Cardoso Lopes | bdfbb74 | 2009-03-21 00:05:07 +0000 | [diff] [blame] | 1276 | RC = Mips::FGR32RegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1277 | else if (RegVT == MVT::f64) { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1278 | if (!Subtarget->isSingleFloat()) |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1279 | RC = Mips::AFGR64RegisterClass; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1280 | } else |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 1281 | llvm_unreachable("RegVT not supported by FormalArguments Lowering"); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1282 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1283 | // Transform the arguments stored on |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1284 | // physical registers into virtual ones |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 1285 | unsigned Reg = AddLiveIn(DAG.getMachineFunction(), ArgRegEnd, RC); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1286 | SDValue ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, RegVT); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1287 | |
| 1288 | // If this is an 8 or 16-bit value, it has been passed promoted |
| 1289 | // to 32 bits. Insert an assert[sz]ext to capture this, then |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1290 | // truncate to the right size. |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 1291 | if (VA.getLocInfo() != CCValAssign::Full) { |
Chris Lattner | d401507 | 2009-03-26 05:28:14 +0000 | [diff] [blame] | 1292 | unsigned Opcode = 0; |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 1293 | if (VA.getLocInfo() == CCValAssign::SExt) |
| 1294 | Opcode = ISD::AssertSext; |
| 1295 | else if (VA.getLocInfo() == CCValAssign::ZExt) |
| 1296 | Opcode = ISD::AssertZext; |
Chris Lattner | d401507 | 2009-03-26 05:28:14 +0000 | [diff] [blame] | 1297 | if (Opcode) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1298 | ArgValue = DAG.getNode(Opcode, dl, RegVT, ArgValue, |
Chris Lattner | d401507 | 2009-03-26 05:28:14 +0000 | [diff] [blame] | 1299 | DAG.getValueType(VA.getValVT())); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1300 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 1301 | } |
| 1302 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1303 | // Handle O32 ABI cases: i32->f32 and (i32,i32)->f64 |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 1304 | if (Subtarget->isABI_O32()) { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1305 | if (RegVT == MVT::i32 && VA.getValVT() == MVT::f32) |
| 1306 | ArgValue = DAG.getNode(ISD::BITCAST, dl, MVT::f32, ArgValue); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1307 | if (RegVT == MVT::i32 && VA.getValVT() == MVT::f64) { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1308 | unsigned Reg2 = AddLiveIn(DAG.getMachineFunction(), |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 1309 | VA.getLocReg()+1, RC); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1310 | SDValue ArgValue2 = DAG.getCopyFromReg(Chain, dl, Reg2, RegVT); |
Bruno Cardoso Lopes | b1fce0a | 2011-01-18 19:38:25 +0000 | [diff] [blame] | 1311 | SDValue Pair = DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, ArgValue2, ArgValue); |
| 1312 | ArgValue = DAG.getNode(ISD::BITCAST, dl, MVT::f64, Pair); |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 1313 | } |
| 1314 | } |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1315 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1316 | InVals.push_back(ArgValue); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1317 | } else { // VA.isRegLoc() |
| 1318 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1319 | // sanity check |
| 1320 | assert(VA.isMemLoc()); |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 1321 | |
| 1322 | // The last argument is not a register anymore |
| 1323 | ArgRegEnd = 0; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1324 | |
| 1325 | // The stack pointer offset is relative to the caller stack frame. |
| 1326 | // Since the real stack size is unknown here, a negative SPOffset |
Bruno Cardoso Lopes | a2b1bb5 | 2007-08-28 05:08:16 +0000 | [diff] [blame] | 1327 | // is used so there's a way to adjust these offsets when the stack |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1328 | // size get known (on EliminateFrameIndex). A dummy SPOffset is |
Bruno Cardoso Lopes | a2b1bb5 | 2007-08-28 05:08:16 +0000 | [diff] [blame] | 1329 | // used instead of a direct negative address (which is recorded to |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1330 | // be used on emitPrologue) to avoid mis-calc of the first stack |
Bruno Cardoso Lopes | a2b1bb5 | 2007-08-28 05:08:16 +0000 | [diff] [blame] | 1331 | // offset on PEI::calculateFrameObjectOffsets. |
| 1332 | // Arguments are always 32-bit. |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1333 | unsigned ArgSize = VA.getLocVT().getSizeInBits()/8; |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 1334 | int FI = MFI->CreateFixedObject(ArgSize, 0, true); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1335 | MipsFI->recordLoadArgsFI(FI, -(ArgSize+ |
| 1336 | (FirstStackArgLoc + VA.getLocMemOffset()))); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1337 | |
| 1338 | // Create load nodes to retrieve arguments from the stack |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1339 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1340 | InVals.push_back(DAG.getLoad(VA.getValVT(), dl, Chain, FIN, |
| 1341 | MachinePointerInfo::getFixedStack(FI), |
David Greene | f6fa186 | 2010-02-15 16:56:10 +0000 | [diff] [blame] | 1342 | false, false, 0)); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1343 | } |
| 1344 | } |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1345 | |
| 1346 | // The mips ABIs for returning structs by value requires that we copy |
| 1347 | // the sret argument into $v0 for the return. Save the argument into |
| 1348 | // a virtual register so that we can access it from the return points. |
| 1349 | if (DAG.getMachineFunction().getFunction()->hasStructRetAttr()) { |
| 1350 | unsigned Reg = MipsFI->getSRetReturnReg(); |
| 1351 | if (!Reg) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1352 | Reg = MF.getRegInfo().createVirtualRegister(getRegClassFor(MVT::i32)); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1353 | MipsFI->setSRetReturnReg(Reg); |
| 1354 | } |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1355 | SDValue Copy = DAG.getCopyToReg(DAG.getEntryNode(), dl, Reg, InVals[0]); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1356 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Copy, Chain); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1357 | } |
| 1358 | |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 1359 | // To meet ABI, when VARARGS are passed on registers, the registers |
| 1360 | // must have their values written to the caller stack frame. If the last |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1361 | // argument was placed in the stack, there's no need to save any register. |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 1362 | if ((isVarArg) && (Subtarget->isABI_O32() && ArgRegEnd)) { |
| 1363 | if (StackPtr.getNode() == 0) |
| 1364 | StackPtr = DAG.getRegister(StackReg, getPointerTy()); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1365 | |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 1366 | // The last register argument that must be saved is Mips::A3 |
| 1367 | TargetRegisterClass *RC = Mips::CPURegsRegisterClass; |
| 1368 | unsigned StackLoc = ArgLocs.size()-1; |
| 1369 | |
| 1370 | for (++ArgRegEnd; ArgRegEnd <= Mips::A3; ++ArgRegEnd, ++StackLoc) { |
| 1371 | unsigned Reg = AddLiveIn(DAG.getMachineFunction(), ArgRegEnd, RC); |
| 1372 | SDValue ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, MVT::i32); |
| 1373 | |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 1374 | int FI = MFI->CreateFixedObject(4, 0, true); |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 1375 | MipsFI->recordStoreVarArgsFI(FI, -(4+(StackLoc*4))); |
| 1376 | SDValue PtrOff = DAG.getFrameIndex(FI, getPointerTy()); |
Chris Lattner | 8026a9d | 2010-09-21 17:50:43 +0000 | [diff] [blame] | 1377 | OutChains.push_back(DAG.getStore(Chain, dl, ArgValue, PtrOff, |
| 1378 | MachinePointerInfo(), |
David Greene | f6fa186 | 2010-02-15 16:56:10 +0000 | [diff] [blame] | 1379 | false, false, 0)); |
Bruno Cardoso Lopes | 6059b85 | 2010-02-06 21:00:02 +0000 | [diff] [blame] | 1380 | |
| 1381 | // Record the frame index of the first variable argument |
| 1382 | // which is a value necessary to VASTART. |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 1383 | if (!MipsFI->getVarArgsFrameIndex()) |
| 1384 | MipsFI->setVarArgsFrameIndex(FI); |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 1385 | } |
| 1386 | } |
| 1387 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1388 | // All stores are grouped in one node to allow the matching between |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 1389 | // the size of Ins and InVals. This only happens when on varg functions |
| 1390 | if (!OutChains.empty()) { |
| 1391 | OutChains.push_back(Chain); |
| 1392 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
| 1393 | &OutChains[0], OutChains.size()); |
| 1394 | } |
| 1395 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1396 | return Chain; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | //===----------------------------------------------------------------------===// |
| 1400 | // Return Value Calling Convention Implementation |
| 1401 | //===----------------------------------------------------------------------===// |
| 1402 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1403 | SDValue |
| 1404 | MipsTargetLowering::LowerReturn(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1405 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1406 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1407 | const SmallVectorImpl<SDValue> &OutVals, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1408 | DebugLoc dl, SelectionDAG &DAG) const { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1409 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1410 | // CCValAssign - represent the assignment of |
| 1411 | // the return value to a location |
| 1412 | SmallVector<CCValAssign, 16> RVLocs; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1413 | |
| 1414 | // CCState - Info about the registers and stack slot. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1415 | CCState CCInfo(CallConv, isVarArg, getTargetMachine(), |
| 1416 | RVLocs, *DAG.getContext()); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1417 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1418 | // Analize return values. |
| 1419 | CCInfo.AnalyzeReturn(Outs, RetCC_Mips); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1420 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1421 | // If this is the first return lowered for this function, add |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1422 | // the regs to the liveout set for the function. |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 1423 | if (DAG.getMachineFunction().getRegInfo().liveout_empty()) { |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1424 | for (unsigned i = 0; i != RVLocs.size(); ++i) |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 1425 | if (RVLocs[i].isRegLoc()) |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 1426 | DAG.getMachineFunction().getRegInfo().addLiveOut(RVLocs[i].getLocReg()); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1427 | } |
| 1428 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1429 | SDValue Flag; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1430 | |
| 1431 | // Copy the result values into the output registers. |
| 1432 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 1433 | CCValAssign &VA = RVLocs[i]; |
| 1434 | assert(VA.isRegLoc() && "Can only return in registers!"); |
| 1435 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1436 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1437 | OutVals[i], Flag); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1438 | |
| 1439 | // guarantee that all emitted copies are |
| 1440 | // stuck together, avoiding something bad |
| 1441 | Flag = Chain.getValue(1); |
| 1442 | } |
| 1443 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1444 | // The mips ABIs for returning structs by value requires that we copy |
| 1445 | // the sret argument into $v0 for the return. We saved the argument into |
| 1446 | // a virtual register in the entry block, so now we copy the value out |
| 1447 | // and into $v0. |
| 1448 | if (DAG.getMachineFunction().getFunction()->hasStructRetAttr()) { |
| 1449 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1450 | MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>(); |
| 1451 | unsigned Reg = MipsFI->getSRetReturnReg(); |
| 1452 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1453 | if (!Reg) |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1454 | llvm_unreachable("sret virtual register not created in the entry block"); |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 1455 | SDValue Val = DAG.getCopyFromReg(Chain, dl, Reg, getPointerTy()); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1456 | |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 1457 | Chain = DAG.getCopyToReg(Chain, dl, Mips::V0, Val, Flag); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1458 | Flag = Chain.getValue(1); |
| 1459 | } |
| 1460 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1461 | // Return on Mips is always a "jr $ra" |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1462 | if (Flag.getNode()) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1463 | return DAG.getNode(MipsISD::Ret, dl, MVT::Other, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1464 | Chain, DAG.getRegister(Mips::RA, MVT::i32), Flag); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1465 | else // Return Void |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1466 | return DAG.getNode(MipsISD::Ret, dl, MVT::Other, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1467 | Chain, DAG.getRegister(Mips::RA, MVT::i32)); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1468 | } |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 1469 | |
| 1470 | //===----------------------------------------------------------------------===// |
| 1471 | // Mips Inline Assembly Support |
| 1472 | //===----------------------------------------------------------------------===// |
| 1473 | |
| 1474 | /// getConstraintType - Given a constraint letter, return the type of |
| 1475 | /// constraint it is for this target. |
| 1476 | MipsTargetLowering::ConstraintType MipsTargetLowering:: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1477 | getConstraintType(const std::string &Constraint) const |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 1478 | { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1479 | // Mips specific constrainy |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1480 | // GCC config/mips/constraints.md |
| 1481 | // |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1482 | // 'd' : An address register. Equivalent to r |
| 1483 | // unless generating MIPS16 code. |
| 1484 | // 'y' : Equivalent to r; retained for |
| 1485 | // backwards compatibility. |
| 1486 | // 'f' : Floating Point registers. |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 1487 | if (Constraint.size() == 1) { |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 1488 | switch (Constraint[0]) { |
| 1489 | default : break; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1490 | case 'd': |
| 1491 | case 'y': |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1492 | case 'f': |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 1493 | return C_RegisterClass; |
| 1494 | break; |
| 1495 | } |
| 1496 | } |
| 1497 | return TargetLowering::getConstraintType(Constraint); |
| 1498 | } |
| 1499 | |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 1500 | /// Examine constraint type and operand type and determine a weight value. |
| 1501 | /// This object must already have been set up with the operand type |
| 1502 | /// and the current alternative constraint selected. |
| 1503 | TargetLowering::ConstraintWeight |
| 1504 | MipsTargetLowering::getSingleConstraintMatchWeight( |
| 1505 | AsmOperandInfo &info, const char *constraint) const { |
| 1506 | ConstraintWeight weight = CW_Invalid; |
| 1507 | Value *CallOperandVal = info.CallOperandVal; |
| 1508 | // If we don't have a value, we can't do a match, |
| 1509 | // but allow it at the lowest weight. |
| 1510 | if (CallOperandVal == NULL) |
| 1511 | return CW_Default; |
| 1512 | const Type *type = CallOperandVal->getType(); |
| 1513 | // Look at the constraint type. |
| 1514 | switch (*constraint) { |
| 1515 | default: |
| 1516 | weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint); |
| 1517 | break; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1518 | case 'd': |
| 1519 | case 'y': |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 1520 | if (type->isIntegerTy()) |
| 1521 | weight = CW_Register; |
| 1522 | break; |
| 1523 | case 'f': |
| 1524 | if (type->isFloatTy()) |
| 1525 | weight = CW_Register; |
| 1526 | break; |
| 1527 | } |
| 1528 | return weight; |
| 1529 | } |
| 1530 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1531 | /// getRegClassForInlineAsmConstraint - Given a constraint letter (e.g. "r"), |
| 1532 | /// return a list of registers that can be used to satisfy the constraint. |
| 1533 | /// This should only be used for C_RegisterClass constraints. |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 1534 | std::pair<unsigned, const TargetRegisterClass*> MipsTargetLowering:: |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1535 | getRegForInlineAsmConstraint(const std::string &Constraint, EVT VT) const |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 1536 | { |
| 1537 | if (Constraint.size() == 1) { |
| 1538 | switch (Constraint[0]) { |
| 1539 | case 'r': |
| 1540 | return std::make_pair(0U, Mips::CPURegsRegisterClass); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1541 | case 'f': |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1542 | if (VT == MVT::f32) |
Bruno Cardoso Lopes | bdfbb74 | 2009-03-21 00:05:07 +0000 | [diff] [blame] | 1543 | return std::make_pair(0U, Mips::FGR32RegisterClass); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1544 | if (VT == MVT::f64) |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1545 | if ((!Subtarget->isSingleFloat()) && (!Subtarget->isFP64bit())) |
| 1546 | return std::make_pair(0U, Mips::AFGR64RegisterClass); |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 1547 | } |
| 1548 | } |
| 1549 | return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); |
| 1550 | } |
| 1551 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1552 | /// Given a register class constraint, like 'r', if this corresponds directly |
| 1553 | /// to an LLVM register class, return a register of 0 and the register class |
| 1554 | /// pointer. |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 1555 | std::vector<unsigned> MipsTargetLowering:: |
| 1556 | getRegClassForInlineAsmConstraint(const std::string &Constraint, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1557 | EVT VT) const |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 1558 | { |
| 1559 | if (Constraint.size() != 1) |
| 1560 | return std::vector<unsigned>(); |
| 1561 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1562 | switch (Constraint[0]) { |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 1563 | default : break; |
| 1564 | case 'r': |
| 1565 | // GCC Mips Constraint Letters |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1566 | case 'd': |
| 1567 | case 'y': |
| 1568 | return make_vector<unsigned>(Mips::T0, Mips::T1, Mips::T2, Mips::T3, |
| 1569 | Mips::T4, Mips::T5, Mips::T6, Mips::T7, Mips::S0, Mips::S1, |
| 1570 | Mips::S2, Mips::S3, Mips::S4, Mips::S5, Mips::S6, Mips::S7, |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1571 | Mips::T8, 0); |
| 1572 | |
| 1573 | case 'f': |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1574 | if (VT == MVT::f32) { |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1575 | if (Subtarget->isSingleFloat()) |
| 1576 | return make_vector<unsigned>(Mips::F2, Mips::F3, Mips::F4, Mips::F5, |
| 1577 | Mips::F6, Mips::F7, Mips::F8, Mips::F9, Mips::F10, Mips::F11, |
| 1578 | Mips::F20, Mips::F21, Mips::F22, Mips::F23, Mips::F24, |
| 1579 | Mips::F25, Mips::F26, Mips::F27, Mips::F28, Mips::F29, |
| 1580 | Mips::F30, Mips::F31, 0); |
| 1581 | else |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1582 | return make_vector<unsigned>(Mips::F2, Mips::F4, Mips::F6, Mips::F8, |
| 1583 | Mips::F10, Mips::F20, Mips::F22, Mips::F24, Mips::F26, |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1584 | Mips::F28, Mips::F30, 0); |
Duncan Sands | 1512642 | 2008-07-08 09:33:14 +0000 | [diff] [blame] | 1585 | } |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1586 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1587 | if (VT == MVT::f64) |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1588 | if ((!Subtarget->isSingleFloat()) && (!Subtarget->isFP64bit())) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1589 | return make_vector<unsigned>(Mips::D1, Mips::D2, Mips::D3, Mips::D4, |
| 1590 | Mips::D5, Mips::D10, Mips::D11, Mips::D12, Mips::D13, |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 1591 | Mips::D14, Mips::D15, 0); |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 1592 | } |
| 1593 | return std::vector<unsigned>(); |
| 1594 | } |
Dan Gohman | 6520e20 | 2008-10-18 02:06:02 +0000 | [diff] [blame] | 1595 | |
| 1596 | bool |
| 1597 | MipsTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { |
| 1598 | // The Mips target isn't yet aware of offsets. |
| 1599 | return false; |
| 1600 | } |
Evan Cheng | eb2f969 | 2009-10-27 19:56:55 +0000 | [diff] [blame] | 1601 | |
Evan Cheng | a1eaa3c | 2009-10-28 01:43:28 +0000 | [diff] [blame] | 1602 | bool MipsTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const { |
| 1603 | if (VT != MVT::f32 && VT != MVT::f64) |
| 1604 | return false; |
Bruno Cardoso Lopes | 6b90282 | 2011-01-18 19:41:41 +0000 | [diff] [blame] | 1605 | if (Imm.isNegZero()) |
| 1606 | return false; |
Evan Cheng | eb2f969 | 2009-10-27 19:56:55 +0000 | [diff] [blame] | 1607 | return Imm.isZero(); |
| 1608 | } |