Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 1 | //===-- MipsISelLowering.cpp - Mips DAG Lowering Implementation -----------===// |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 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 | // |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file defines the interfaces that Mips uses to lower LLVM code into a |
| 11 | // selection DAG. |
| 12 | // |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 13 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 14 | #define DEBUG_TYPE "mips-lower" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 15 | #include "MipsISelLowering.h" |
Craig Topper | 79aa341 | 2012-03-17 18:46:09 +0000 | [diff] [blame] | 16 | #include "InstPrinter/MipsInstPrinter.h" |
| 17 | #include "MCTargetDesc/MipsBaseInfo.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 18 | #include "MipsMachineFunction.h" |
| 19 | #include "MipsSubtarget.h" |
| 20 | #include "MipsTargetMachine.h" |
| 21 | #include "MipsTargetObjectFile.h" |
Akira Hatanaka | 2b861be | 2012-10-19 21:47:33 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/Statistic.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/CallingConvLower.h" |
| 24 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 25 | #include "llvm/CodeGen/MachineFunction.h" |
| 26 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 27 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/SelectionDAGISel.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/ValueTypes.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 30 | #include "llvm/IR/CallingConv.h" |
| 31 | #include "llvm/IR/DerivedTypes.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 32 | #include "llvm/IR/GlobalVariable.h" |
Akira Hatanaka | 2b861be | 2012-10-19 21:47:33 +0000 | [diff] [blame] | 33 | #include "llvm/Support/CommandLine.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 34 | #include "llvm/Support/Debug.h" |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 35 | #include "llvm/Support/ErrorHandling.h" |
NAKAMURA Takumi | 8959393 | 2012-04-21 15:31:45 +0000 | [diff] [blame] | 36 | #include "llvm/Support/raw_ostream.h" |
Akira Hatanaka | bfb07b1 | 2013-08-14 00:21:25 +0000 | [diff] [blame] | 37 | #include <cctype> |
NAKAMURA Takumi | 8959393 | 2012-04-21 15:31:45 +0000 | [diff] [blame] | 38 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 39 | using namespace llvm; |
| 40 | |
Akira Hatanaka | 2b861be | 2012-10-19 21:47:33 +0000 | [diff] [blame] | 41 | STATISTIC(NumTailCalls, "Number of tail calls"); |
| 42 | |
| 43 | static cl::opt<bool> |
Akira Hatanaka | 81784cb | 2012-11-21 20:21:11 +0000 | [diff] [blame] | 44 | LargeGOT("mxgot", cl::Hidden, |
| 45 | cl::desc("MIPS: Enable GOT larger than 64k."), cl::init(false)); |
| 46 | |
Akira Hatanaka | f894199 | 2013-05-20 18:07:43 +0000 | [diff] [blame] | 47 | static cl::opt<bool> |
Akira Hatanaka | 2591b5c | 2013-05-21 17:17:59 +0000 | [diff] [blame] | 48 | NoZeroDivCheck("mno-check-zero-division", cl::Hidden, |
Akira Hatanaka | f894199 | 2013-05-20 18:07:43 +0000 | [diff] [blame] | 49 | cl::desc("MIPS: Don't trap on integer division by zero."), |
| 50 | cl::init(false)); |
| 51 | |
Akira Hatanaka | fe30a9b | 2012-10-27 00:29:43 +0000 | [diff] [blame] | 52 | static const uint16_t O32IntRegs[4] = { |
| 53 | Mips::A0, Mips::A1, Mips::A2, Mips::A3 |
| 54 | }; |
| 55 | |
| 56 | static const uint16_t Mips64IntRegs[8] = { |
| 57 | Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64, |
| 58 | Mips::T0_64, Mips::T1_64, Mips::T2_64, Mips::T3_64 |
| 59 | }; |
| 60 | |
| 61 | static const uint16_t Mips64DPRegs[8] = { |
| 62 | Mips::D12_64, Mips::D13_64, Mips::D14_64, Mips::D15_64, |
| 63 | Mips::D16_64, Mips::D17_64, Mips::D18_64, Mips::D19_64 |
| 64 | }; |
| 65 | |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 66 | // If I is a shifted mask, set the size (Size) and the first bit of the |
Akira Hatanaka | dbe9a31 | 2011-08-18 20:07:42 +0000 | [diff] [blame] | 67 | // mask (Pos), and return true. |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 68 | // For example, if I is 0x003ff800, (Pos, Size) = (11, 11). |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 69 | static bool isShiftedMask(uint64_t I, uint64_t &Pos, uint64_t &Size) { |
Akira Hatanaka | d6bc523 | 2011-12-05 21:26:34 +0000 | [diff] [blame] | 70 | if (!isShiftedMask_64(I)) |
Akira Hatanaka | 854a7db | 2011-08-19 22:59:00 +0000 | [diff] [blame] | 71 | return false; |
Akira Hatanaka | bb15e11 | 2011-08-17 02:05:42 +0000 | [diff] [blame] | 72 | |
Akira Hatanaka | d6bc523 | 2011-12-05 21:26:34 +0000 | [diff] [blame] | 73 | Size = CountPopulation_64(I); |
Michael J. Spencer | c6af243 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 74 | Pos = countTrailingZeros(I); |
Akira Hatanaka | dbe9a31 | 2011-08-18 20:07:42 +0000 | [diff] [blame] | 75 | return true; |
Akira Hatanaka | bb15e11 | 2011-08-17 02:05:42 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Akira Hatanaka | 5ac065a | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 78 | SDValue MipsTargetLowering::getGlobalReg(SelectionDAG &DAG, EVT Ty) const { |
Akira Hatanaka | 648f00c | 2012-02-24 22:34:47 +0000 | [diff] [blame] | 79 | MipsFunctionInfo *FI = DAG.getMachineFunction().getInfo<MipsFunctionInfo>(); |
| 80 | return DAG.getRegister(FI->getGlobalBaseReg(), Ty); |
| 81 | } |
| 82 | |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 83 | template<class NodeTy> |
| 84 | static SDValue getTargetNode(NodeTy *Node, EVT Ty, SelectionDAG &DAG, |
| 85 | unsigned Flag) { |
Akira Hatanaka | 6b28b80 | 2012-11-21 20:26:38 +0000 | [diff] [blame] | 86 | llvm_unreachable("Unexpected node type."); |
| 87 | return SDValue(); |
| 88 | } |
| 89 | |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 90 | template<> |
| 91 | SDValue getTargetNode<GlobalAddressSDNode>(GlobalAddressSDNode *N, EVT Ty, |
| 92 | SelectionDAG &DAG, unsigned Flag) { |
| 93 | return DAG.getTargetGlobalAddress(N->getGlobal(), SDLoc(N), Ty, 0, Flag); |
| 94 | } |
| 95 | |
| 96 | template<> |
| 97 | SDValue getTargetNode<ExternalSymbolSDNode>(ExternalSymbolSDNode *N, EVT Ty, |
| 98 | SelectionDAG &DAG, unsigned Flag) { |
| 99 | return DAG.getTargetExternalSymbol(N->getSymbol(), Ty, Flag); |
| 100 | } |
| 101 | |
| 102 | template<> |
| 103 | SDValue getTargetNode<BlockAddressSDNode>(BlockAddressSDNode *N, EVT Ty, |
| 104 | SelectionDAG &DAG, unsigned Flag) { |
| 105 | return DAG.getTargetBlockAddress(N->getBlockAddress(), Ty, 0, Flag); |
| 106 | } |
| 107 | |
| 108 | template<> |
| 109 | SDValue getTargetNode<JumpTableSDNode>(JumpTableSDNode *N, EVT Ty, |
| 110 | SelectionDAG &DAG, unsigned Flag) { |
| 111 | return DAG.getTargetJumpTable(N->getIndex(), Ty, Flag); |
| 112 | } |
| 113 | |
| 114 | template<> |
| 115 | SDValue getTargetNode<ConstantPoolSDNode>(ConstantPoolSDNode *N, EVT Ty, |
| 116 | SelectionDAG &DAG, unsigned Flag) { |
| 117 | return DAG.getTargetConstantPool(N->getConstVal(), Ty, N->getAlignment(), |
| 118 | N->getOffset(), Flag); |
| 119 | } |
| 120 | |
| 121 | template<class NodeTy> |
| 122 | static SDValue getAddrNonPIC(NodeTy *N, EVT Ty, SelectionDAG &DAG) { |
| 123 | SDLoc DL(N); |
| 124 | SDValue Hi = getTargetNode(N, Ty, DAG, MipsII::MO_ABS_HI); |
| 125 | SDValue Lo = getTargetNode(N, Ty, DAG, MipsII::MO_ABS_LO); |
Akira Hatanaka | 6b28b80 | 2012-11-21 20:26:38 +0000 | [diff] [blame] | 126 | return DAG.getNode(ISD::ADD, DL, Ty, |
| 127 | DAG.getNode(MipsISD::Hi, DL, Ty, Hi), |
| 128 | DAG.getNode(MipsISD::Lo, DL, Ty, Lo)); |
| 129 | } |
| 130 | |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 131 | template<class NodeTy> |
| 132 | SDValue MipsTargetLowering::getAddrLocal(NodeTy *N, EVT Ty, SelectionDAG &DAG, |
Akira Hatanaka | 5ac065a | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 133 | bool HasMips64) const { |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 134 | SDLoc DL(N); |
Akira Hatanaka | 6b28b80 | 2012-11-21 20:26:38 +0000 | [diff] [blame] | 135 | unsigned GOTFlag = HasMips64 ? MipsII::MO_GOT_PAGE : MipsII::MO_GOT; |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 136 | SDValue GOT = DAG.getNode(MipsISD::Wrapper, DL, Ty, getGlobalReg(DAG, Ty), |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 137 | getTargetNode(N, Ty, DAG, GOTFlag)); |
Akira Hatanaka | 6b28b80 | 2012-11-21 20:26:38 +0000 | [diff] [blame] | 138 | SDValue Load = DAG.getLoad(Ty, DL, DAG.getEntryNode(), GOT, |
| 139 | MachinePointerInfo::getGOT(), false, false, false, |
| 140 | 0); |
| 141 | unsigned LoFlag = HasMips64 ? MipsII::MO_GOT_OFST : MipsII::MO_ABS_LO; |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 142 | SDValue Lo = DAG.getNode(MipsISD::Lo, DL, Ty, |
| 143 | getTargetNode(N, Ty, DAG, LoFlag)); |
Akira Hatanaka | 6b28b80 | 2012-11-21 20:26:38 +0000 | [diff] [blame] | 144 | return DAG.getNode(ISD::ADD, DL, Ty, Load, Lo); |
| 145 | } |
| 146 | |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 147 | template<class NodeTy> |
| 148 | SDValue MipsTargetLowering::getAddrGlobal(NodeTy *N, EVT Ty, SelectionDAG &DAG, |
Akira Hatanaka | 5ac065a | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 149 | unsigned Flag) const { |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 150 | SDLoc DL(N); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 151 | SDValue Tgt = DAG.getNode(MipsISD::Wrapper, DL, Ty, getGlobalReg(DAG, Ty), |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 152 | getTargetNode(N, Ty, DAG, Flag)); |
Akira Hatanaka | 6b28b80 | 2012-11-21 20:26:38 +0000 | [diff] [blame] | 153 | return DAG.getLoad(Ty, DL, DAG.getEntryNode(), Tgt, |
| 154 | MachinePointerInfo::getGOT(), false, false, false, 0); |
| 155 | } |
| 156 | |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 157 | template<class NodeTy> |
| 158 | SDValue MipsTargetLowering::getAddrGlobalLargeGOT(NodeTy *N, EVT Ty, |
| 159 | SelectionDAG &DAG, |
Akira Hatanaka | 5ac065a | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 160 | unsigned HiFlag, |
| 161 | unsigned LoFlag) const { |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 162 | SDLoc DL(N); |
| 163 | SDValue Hi = DAG.getNode(MipsISD::Hi, DL, Ty, |
| 164 | getTargetNode(N, Ty, DAG, HiFlag)); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 165 | Hi = DAG.getNode(ISD::ADD, DL, Ty, Hi, getGlobalReg(DAG, Ty)); |
Akira Hatanaka | 6b28b80 | 2012-11-21 20:26:38 +0000 | [diff] [blame] | 166 | SDValue Wrapper = DAG.getNode(MipsISD::Wrapper, DL, Ty, Hi, |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 167 | getTargetNode(N, Ty, DAG, LoFlag)); |
Akira Hatanaka | 6b28b80 | 2012-11-21 20:26:38 +0000 | [diff] [blame] | 168 | return DAG.getLoad(Ty, DL, DAG.getEntryNode(), Wrapper, |
| 169 | MachinePointerInfo::getGOT(), false, false, false, 0); |
| 170 | } |
| 171 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 172 | const char *MipsTargetLowering::getTargetNodeName(unsigned Opcode) const { |
| 173 | switch (Opcode) { |
Akira Hatanaka | bdd2ce9 | 2011-05-23 21:13:59 +0000 | [diff] [blame] | 174 | case MipsISD::JmpLink: return "MipsISD::JmpLink"; |
Akira Hatanaka | 58d1e3f | 2012-10-19 20:59:39 +0000 | [diff] [blame] | 175 | case MipsISD::TailCall: return "MipsISD::TailCall"; |
Akira Hatanaka | bdd2ce9 | 2011-05-23 21:13:59 +0000 | [diff] [blame] | 176 | case MipsISD::Hi: return "MipsISD::Hi"; |
| 177 | case MipsISD::Lo: return "MipsISD::Lo"; |
| 178 | case MipsISD::GPRel: return "MipsISD::GPRel"; |
Bruno Cardoso Lopes | d979686 | 2011-05-31 02:53:58 +0000 | [diff] [blame] | 179 | case MipsISD::ThreadPointer: return "MipsISD::ThreadPointer"; |
Akira Hatanaka | bdd2ce9 | 2011-05-23 21:13:59 +0000 | [diff] [blame] | 180 | case MipsISD::Ret: return "MipsISD::Ret"; |
Akira Hatanaka | 544cc21 | 2013-01-30 00:26:49 +0000 | [diff] [blame] | 181 | case MipsISD::EH_RETURN: return "MipsISD::EH_RETURN"; |
Akira Hatanaka | bdd2ce9 | 2011-05-23 21:13:59 +0000 | [diff] [blame] | 182 | case MipsISD::FPBrcond: return "MipsISD::FPBrcond"; |
| 183 | case MipsISD::FPCmp: return "MipsISD::FPCmp"; |
| 184 | case MipsISD::CMovFP_T: return "MipsISD::CMovFP_T"; |
| 185 | case MipsISD::CMovFP_F: return "MipsISD::CMovFP_F"; |
Akira Hatanaka | ae7e7cb | 2013-05-16 21:17:15 +0000 | [diff] [blame] | 186 | case MipsISD::TruncIntFP: return "MipsISD::TruncIntFP"; |
Akira Hatanaka | dd95892 | 2013-03-30 01:14:04 +0000 | [diff] [blame] | 187 | case MipsISD::ExtractLOHI: return "MipsISD::ExtractLOHI"; |
| 188 | case MipsISD::InsertLOHI: return "MipsISD::InsertLOHI"; |
| 189 | case MipsISD::Mult: return "MipsISD::Mult"; |
| 190 | case MipsISD::Multu: return "MipsISD::Multu"; |
Akira Hatanaka | bdd2ce9 | 2011-05-23 21:13:59 +0000 | [diff] [blame] | 191 | case MipsISD::MAdd: return "MipsISD::MAdd"; |
| 192 | case MipsISD::MAddu: return "MipsISD::MAddu"; |
| 193 | case MipsISD::MSub: return "MipsISD::MSub"; |
| 194 | case MipsISD::MSubu: return "MipsISD::MSubu"; |
| 195 | case MipsISD::DivRem: return "MipsISD::DivRem"; |
| 196 | case MipsISD::DivRemU: return "MipsISD::DivRemU"; |
Akira Hatanaka | dd95892 | 2013-03-30 01:14:04 +0000 | [diff] [blame] | 197 | case MipsISD::DivRem16: return "MipsISD::DivRem16"; |
| 198 | case MipsISD::DivRemU16: return "MipsISD::DivRemU16"; |
Akira Hatanaka | bdd2ce9 | 2011-05-23 21:13:59 +0000 | [diff] [blame] | 199 | case MipsISD::BuildPairF64: return "MipsISD::BuildPairF64"; |
| 200 | case MipsISD::ExtractElementF64: return "MipsISD::ExtractElementF64"; |
Akira Hatanaka | bfcb83f | 2011-12-12 22:38:19 +0000 | [diff] [blame] | 201 | case MipsISD::Wrapper: return "MipsISD::Wrapper"; |
Akira Hatanaka | db54826 | 2011-07-19 23:30:50 +0000 | [diff] [blame] | 202 | case MipsISD::Sync: return "MipsISD::Sync"; |
Akira Hatanaka | bb15e11 | 2011-08-17 02:05:42 +0000 | [diff] [blame] | 203 | case MipsISD::Ext: return "MipsISD::Ext"; |
| 204 | case MipsISD::Ins: return "MipsISD::Ins"; |
Akira Hatanaka | b6f1dc2 | 2012-06-02 00:03:12 +0000 | [diff] [blame] | 205 | case MipsISD::LWL: return "MipsISD::LWL"; |
| 206 | case MipsISD::LWR: return "MipsISD::LWR"; |
| 207 | case MipsISD::SWL: return "MipsISD::SWL"; |
| 208 | case MipsISD::SWR: return "MipsISD::SWR"; |
| 209 | case MipsISD::LDL: return "MipsISD::LDL"; |
| 210 | case MipsISD::LDR: return "MipsISD::LDR"; |
| 211 | case MipsISD::SDL: return "MipsISD::SDL"; |
| 212 | case MipsISD::SDR: return "MipsISD::SDR"; |
Akira Hatanaka | 6fad5e7 | 2012-09-21 23:52:47 +0000 | [diff] [blame] | 213 | case MipsISD::EXTP: return "MipsISD::EXTP"; |
| 214 | case MipsISD::EXTPDP: return "MipsISD::EXTPDP"; |
| 215 | case MipsISD::EXTR_S_H: return "MipsISD::EXTR_S_H"; |
| 216 | case MipsISD::EXTR_W: return "MipsISD::EXTR_W"; |
| 217 | case MipsISD::EXTR_R_W: return "MipsISD::EXTR_R_W"; |
| 218 | case MipsISD::EXTR_RS_W: return "MipsISD::EXTR_RS_W"; |
| 219 | case MipsISD::SHILO: return "MipsISD::SHILO"; |
| 220 | case MipsISD::MTHLIP: return "MipsISD::MTHLIP"; |
| 221 | case MipsISD::MULT: return "MipsISD::MULT"; |
| 222 | case MipsISD::MULTU: return "MipsISD::MULTU"; |
Jia Liu | b3ea880 | 2013-03-04 01:06:54 +0000 | [diff] [blame] | 223 | case MipsISD::MADD_DSP: return "MipsISD::MADD_DSP"; |
Akira Hatanaka | 6fad5e7 | 2012-09-21 23:52:47 +0000 | [diff] [blame] | 224 | case MipsISD::MADDU_DSP: return "MipsISD::MADDU_DSP"; |
| 225 | case MipsISD::MSUB_DSP: return "MipsISD::MSUB_DSP"; |
| 226 | case MipsISD::MSUBU_DSP: return "MipsISD::MSUBU_DSP"; |
Akira Hatanaka | 97a62bf | 2013-04-19 23:21:32 +0000 | [diff] [blame] | 227 | case MipsISD::SHLL_DSP: return "MipsISD::SHLL_DSP"; |
| 228 | case MipsISD::SHRA_DSP: return "MipsISD::SHRA_DSP"; |
| 229 | case MipsISD::SHRL_DSP: return "MipsISD::SHRL_DSP"; |
Akira Hatanaka | cd6c579 | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 230 | case MipsISD::SETCC_DSP: return "MipsISD::SETCC_DSP"; |
| 231 | case MipsISD::SELECT_CC_DSP: return "MipsISD::SELECT_CC_DSP"; |
Daniel Sanders | 3c380d5 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 232 | case MipsISD::VALL_ZERO: return "MipsISD::VALL_ZERO"; |
| 233 | case MipsISD::VANY_ZERO: return "MipsISD::VANY_ZERO"; |
| 234 | case MipsISD::VALL_NONZERO: return "MipsISD::VALL_NONZERO"; |
| 235 | case MipsISD::VANY_NONZERO: return "MipsISD::VANY_NONZERO"; |
Daniel Sanders | ae1fb8f | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 236 | case MipsISD::VCEQ: return "MipsISD::VCEQ"; |
| 237 | case MipsISD::VCLE_S: return "MipsISD::VCLE_S"; |
| 238 | case MipsISD::VCLE_U: return "MipsISD::VCLE_U"; |
| 239 | case MipsISD::VCLT_S: return "MipsISD::VCLT_S"; |
| 240 | case MipsISD::VCLT_U: return "MipsISD::VCLT_U"; |
Daniel Sanders | 89d13c1 | 2013-09-24 12:18:31 +0000 | [diff] [blame] | 241 | case MipsISD::VSMAX: return "MipsISD::VSMAX"; |
| 242 | case MipsISD::VSMIN: return "MipsISD::VSMIN"; |
| 243 | case MipsISD::VUMAX: return "MipsISD::VUMAX"; |
| 244 | case MipsISD::VUMIN: return "MipsISD::VUMIN"; |
Daniel Sanders | 9a1aaeb | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 245 | case MipsISD::VEXTRACT_SEXT_ELT: return "MipsISD::VEXTRACT_SEXT_ELT"; |
| 246 | case MipsISD::VEXTRACT_ZEXT_ELT: return "MipsISD::VEXTRACT_ZEXT_ELT"; |
Daniel Sanders | 915432c | 2013-09-23 13:22:24 +0000 | [diff] [blame] | 247 | case MipsISD::VNOR: return "MipsISD::VNOR"; |
Daniel Sanders | 7e0df9a | 2013-09-24 14:02:15 +0000 | [diff] [blame] | 248 | case MipsISD::VSHF: return "MipsISD::VSHF"; |
Daniel Sanders | 93d9957 | 2013-09-24 14:20:00 +0000 | [diff] [blame] | 249 | case MipsISD::SHF: return "MipsISD::SHF"; |
Daniel Sanders | f515964 | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 250 | case MipsISD::ILVEV: return "MipsISD::ILVEV"; |
| 251 | case MipsISD::ILVOD: return "MipsISD::ILVOD"; |
| 252 | case MipsISD::ILVL: return "MipsISD::ILVL"; |
| 253 | case MipsISD::ILVR: return "MipsISD::ILVR"; |
Daniel Sanders | 3706eda | 2013-09-24 14:53:25 +0000 | [diff] [blame] | 254 | case MipsISD::PCKEV: return "MipsISD::PCKEV"; |
| 255 | case MipsISD::PCKOD: return "MipsISD::PCKOD"; |
Akira Hatanaka | 0f84382 | 2011-06-07 18:58:42 +0000 | [diff] [blame] | 256 | default: return NULL; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | |
| 260 | MipsTargetLowering:: |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 261 | MipsTargetLowering(MipsTargetMachine &TM) |
Akira Hatanaka | 8b4198d | 2011-09-26 21:47:02 +0000 | [diff] [blame] | 262 | : TargetLowering(TM, new MipsTargetObjectFile()), |
| 263 | Subtarget(&TM.getSubtarget<MipsSubtarget>()), |
Akira Hatanaka | 2ec69fa | 2011-10-28 18:47:24 +0000 | [diff] [blame] | 264 | HasMips64(Subtarget->hasMips64()), IsN64(Subtarget->isABI_N64()), |
| 265 | IsO32(Subtarget->isABI_O32()) { |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 266 | // Mips does not have i1 type, so use i32 for |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 267 | // setcc operations results (slt, sgt, ...). |
Duncan Sands | 0322808 | 2008-11-23 15:47:28 +0000 | [diff] [blame] | 268 | setBooleanContents(ZeroOrOneBooleanContent); |
Akira Hatanaka | cd6c579 | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 269 | setBooleanVectorContents(ZeroOrNegativeOneBooleanContent); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 270 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 271 | // Load extented operations for i1 types must be promoted |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 272 | setLoadExtAction(ISD::EXTLOAD, MVT::i1, Promote); |
| 273 | setLoadExtAction(ISD::ZEXTLOAD, MVT::i1, Promote); |
| 274 | setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 275 | |
Eli Friedman | 6055a6a | 2009-07-17 04:07:24 +0000 | [diff] [blame] | 276 | // MIPS doesn't have extending float->double load/store |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 277 | setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand); |
| 278 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
Eli Friedman | 10a3659 | 2009-07-17 02:28:12 +0000 | [diff] [blame] | 279 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 280 | // Used by legalize types to correctly generate the setcc result. |
| 281 | // Without this, every float setcc comes with a AND/OR with the result, |
| 282 | // 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] | 283 | // which is used implicitly by brcond and select operations. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 284 | AddPromotedToType(ISD::SETCC, MVT::i1, MVT::i32); |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 285 | |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 286 | // Mips Custom Operations |
Akira Hatanaka | b7656a9 | 2013-03-06 21:32:03 +0000 | [diff] [blame] | 287 | setOperationAction(ISD::BR_JT, MVT::Other, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 288 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
Bruno Cardoso Lopes | ca8a2aa | 2011-03-04 20:01:52 +0000 | [diff] [blame] | 289 | setOperationAction(ISD::BlockAddress, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 290 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); |
| 291 | setOperationAction(ISD::JumpTable, MVT::i32, Custom); |
| 292 | setOperationAction(ISD::ConstantPool, MVT::i32, Custom); |
| 293 | setOperationAction(ISD::SELECT, MVT::f32, Custom); |
| 294 | setOperationAction(ISD::SELECT, MVT::f64, Custom); |
| 295 | setOperationAction(ISD::SELECT, MVT::i32, Custom); |
Akira Hatanaka | 3fef29d | 2012-07-11 19:32:27 +0000 | [diff] [blame] | 296 | setOperationAction(ISD::SELECT_CC, MVT::f32, Custom); |
| 297 | setOperationAction(ISD::SELECT_CC, MVT::f64, Custom); |
Akira Hatanaka | 0a40c23 | 2012-03-09 23:46:03 +0000 | [diff] [blame] | 298 | setOperationAction(ISD::SETCC, MVT::f32, Custom); |
| 299 | setOperationAction(ISD::SETCC, MVT::f64, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 300 | setOperationAction(ISD::BRCOND, MVT::Other, Custom); |
Bruno Cardoso Lopes | 6059b85 | 2010-02-06 21:00:02 +0000 | [diff] [blame] | 301 | setOperationAction(ISD::VASTART, MVT::Other, Custom); |
Akira Hatanaka | d229b7b | 2012-03-10 00:03:50 +0000 | [diff] [blame] | 302 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Custom); |
| 303 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Custom); |
Akira Hatanaka | ae7e7cb | 2013-05-16 21:17:15 +0000 | [diff] [blame] | 304 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); |
Akira Hatanaka | d229b7b | 2012-03-10 00:03:50 +0000 | [diff] [blame] | 305 | |
Akira Hatanaka | c12a6e6 | 2012-04-11 22:49:04 +0000 | [diff] [blame] | 306 | if (!TM.Options.NoNaNsFPMath) { |
| 307 | setOperationAction(ISD::FABS, MVT::f32, Custom); |
| 308 | setOperationAction(ISD::FABS, MVT::f64, Custom); |
| 309 | } |
| 310 | |
Akira Hatanaka | d229b7b | 2012-03-10 00:03:50 +0000 | [diff] [blame] | 311 | if (HasMips64) { |
| 312 | setOperationAction(ISD::GlobalAddress, MVT::i64, Custom); |
| 313 | setOperationAction(ISD::BlockAddress, MVT::i64, Custom); |
| 314 | setOperationAction(ISD::GlobalTLSAddress, MVT::i64, Custom); |
| 315 | setOperationAction(ISD::JumpTable, MVT::i64, Custom); |
| 316 | setOperationAction(ISD::ConstantPool, MVT::i64, Custom); |
| 317 | setOperationAction(ISD::SELECT, MVT::i64, Custom); |
Akira Hatanaka | 7664f05 | 2012-06-02 00:04:42 +0000 | [diff] [blame] | 318 | setOperationAction(ISD::LOAD, MVT::i64, Custom); |
| 319 | setOperationAction(ISD::STORE, MVT::i64, Custom); |
Akira Hatanaka | ae7e7cb | 2013-05-16 21:17:15 +0000 | [diff] [blame] | 320 | setOperationAction(ISD::FP_TO_SINT, MVT::i64, Custom); |
Akira Hatanaka | d229b7b | 2012-03-10 00:03:50 +0000 | [diff] [blame] | 321 | } |
Bruno Cardoso Lopes | 6059b85 | 2010-02-06 21:00:02 +0000 | [diff] [blame] | 322 | |
Akira Hatanaka | a284acb | 2012-05-09 00:55:21 +0000 | [diff] [blame] | 323 | if (!HasMips64) { |
| 324 | setOperationAction(ISD::SHL_PARTS, MVT::i32, Custom); |
| 325 | setOperationAction(ISD::SRA_PARTS, MVT::i32, Custom); |
| 326 | setOperationAction(ISD::SRL_PARTS, MVT::i32, Custom); |
| 327 | } |
| 328 | |
Akira Hatanaka | e90a3bc | 2012-11-07 19:10:58 +0000 | [diff] [blame] | 329 | setOperationAction(ISD::ADD, MVT::i32, Custom); |
| 330 | if (HasMips64) |
| 331 | setOperationAction(ISD::ADD, MVT::i64, Custom); |
| 332 | |
Bruno Cardoso Lopes | 38b5e86 | 2011-03-04 21:03:24 +0000 | [diff] [blame] | 333 | setOperationAction(ISD::SDIV, MVT::i32, Expand); |
| 334 | setOperationAction(ISD::SREM, MVT::i32, Expand); |
| 335 | setOperationAction(ISD::UDIV, MVT::i32, Expand); |
| 336 | setOperationAction(ISD::UREM, MVT::i32, Expand); |
Akira Hatanaka | dda4a07 | 2011-10-03 21:06:13 +0000 | [diff] [blame] | 337 | setOperationAction(ISD::SDIV, MVT::i64, Expand); |
| 338 | setOperationAction(ISD::SREM, MVT::i64, Expand); |
| 339 | setOperationAction(ISD::UDIV, MVT::i64, Expand); |
| 340 | setOperationAction(ISD::UREM, MVT::i64, Expand); |
Bruno Cardoso Lopes | 38b5e86 | 2011-03-04 21:03:24 +0000 | [diff] [blame] | 341 | |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 342 | // Operations not directly supported by Mips. |
Tom Stellard | 3ef5383 | 2013-03-08 15:36:57 +0000 | [diff] [blame] | 343 | setOperationAction(ISD::BR_CC, MVT::f32, Expand); |
| 344 | setOperationAction(ISD::BR_CC, MVT::f64, Expand); |
| 345 | setOperationAction(ISD::BR_CC, MVT::i32, Expand); |
| 346 | setOperationAction(ISD::BR_CC, MVT::i64, Expand); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 347 | setOperationAction(ISD::SELECT_CC, MVT::Other, Expand); |
| 348 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Expand); |
Akira Hatanaka | e1bcd6b | 2011-12-20 23:40:56 +0000 | [diff] [blame] | 349 | setOperationAction(ISD::UINT_TO_FP, MVT::i64, Expand); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 350 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Expand); |
Akira Hatanaka | e1bcd6b | 2011-12-20 23:40:56 +0000 | [diff] [blame] | 351 | setOperationAction(ISD::FP_TO_UINT, MVT::i64, Expand); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 352 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
| 353 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
Akira Hatanaka | 7f16274 | 2011-12-21 00:14:05 +0000 | [diff] [blame] | 354 | setOperationAction(ISD::CTPOP, MVT::i64, Expand); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 355 | setOperationAction(ISD::CTTZ, MVT::i32, Expand); |
Akira Hatanaka | 7f16274 | 2011-12-21 00:14:05 +0000 | [diff] [blame] | 356 | setOperationAction(ISD::CTTZ, MVT::i64, Expand); |
Chandler Carruth | 63974b2 | 2011-12-13 01:56:10 +0000 | [diff] [blame] | 357 | setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::i32, Expand); |
| 358 | setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::i64, Expand); |
| 359 | setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i32, Expand); |
| 360 | setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i64, Expand); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 361 | setOperationAction(ISD::ROTL, MVT::i32, Expand); |
Akira Hatanaka | c7bafe9 | 2011-09-30 18:51:46 +0000 | [diff] [blame] | 362 | setOperationAction(ISD::ROTL, MVT::i64, Expand); |
Akira Hatanaka | 1d165f1 | 2012-07-31 20:54:48 +0000 | [diff] [blame] | 363 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Expand); |
| 364 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i64, Expand); |
Bruno Cardoso Lopes | 908b6dd | 2010-12-09 17:32:30 +0000 | [diff] [blame] | 365 | |
Akira Hatanaka | 5663344 | 2011-09-20 23:53:09 +0000 | [diff] [blame] | 366 | if (!Subtarget->hasMips32r2()) |
Bruno Cardoso Lopes | 908b6dd | 2010-12-09 17:32:30 +0000 | [diff] [blame] | 367 | setOperationAction(ISD::ROTR, MVT::i32, Expand); |
| 368 | |
Akira Hatanaka | c7bafe9 | 2011-09-30 18:51:46 +0000 | [diff] [blame] | 369 | if (!Subtarget->hasMips64r2()) |
| 370 | setOperationAction(ISD::ROTR, MVT::i64, Expand); |
| 371 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 372 | setOperationAction(ISD::FSIN, MVT::f32, Expand); |
Bruno Cardoso Lopes | 5d6fb5d | 2011-03-04 18:54:14 +0000 | [diff] [blame] | 373 | setOperationAction(ISD::FSIN, MVT::f64, Expand); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 374 | setOperationAction(ISD::FCOS, MVT::f32, Expand); |
Bruno Cardoso Lopes | 5d6fb5d | 2011-03-04 18:54:14 +0000 | [diff] [blame] | 375 | setOperationAction(ISD::FCOS, MVT::f64, Expand); |
Evan Cheng | 8688a58 | 2013-01-29 02:32:37 +0000 | [diff] [blame] | 376 | setOperationAction(ISD::FSINCOS, MVT::f32, Expand); |
| 377 | setOperationAction(ISD::FSINCOS, MVT::f64, Expand); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 378 | setOperationAction(ISD::FPOWI, MVT::f32, Expand); |
| 379 | setOperationAction(ISD::FPOW, MVT::f32, Expand); |
Akira Hatanaka | 46da136 | 2011-05-23 22:23:58 +0000 | [diff] [blame] | 380 | setOperationAction(ISD::FPOW, MVT::f64, Expand); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 381 | setOperationAction(ISD::FLOG, MVT::f32, Expand); |
| 382 | setOperationAction(ISD::FLOG2, MVT::f32, Expand); |
| 383 | setOperationAction(ISD::FLOG10, MVT::f32, Expand); |
| 384 | setOperationAction(ISD::FEXP, MVT::f32, Expand); |
Cameron Zwarich | 3339084 | 2011-07-08 21:39:21 +0000 | [diff] [blame] | 385 | setOperationAction(ISD::FMA, MVT::f32, Expand); |
| 386 | setOperationAction(ISD::FMA, MVT::f64, Expand); |
Akira Hatanaka | 21ecc2f | 2012-03-29 18:43:11 +0000 | [diff] [blame] | 387 | setOperationAction(ISD::FREM, MVT::f32, Expand); |
| 388 | setOperationAction(ISD::FREM, MVT::f64, Expand); |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 389 | |
Akira Hatanaka | 1cc6333 | 2012-04-11 22:59:08 +0000 | [diff] [blame] | 390 | if (!TM.Options.NoNaNsFPMath) { |
| 391 | setOperationAction(ISD::FNEG, MVT::f32, Expand); |
| 392 | setOperationAction(ISD::FNEG, MVT::f64, Expand); |
| 393 | } |
| 394 | |
Akira Hatanaka | 544cc21 | 2013-01-30 00:26:49 +0000 | [diff] [blame] | 395 | setOperationAction(ISD::EH_RETURN, MVT::Other, Custom); |
| 396 | |
Bruno Cardoso Lopes | 954dac0 | 2011-03-09 19:22:22 +0000 | [diff] [blame] | 397 | setOperationAction(ISD::VAARG, MVT::Other, Expand); |
| 398 | setOperationAction(ISD::VACOPY, MVT::Other, Expand); |
| 399 | setOperationAction(ISD::VAEND, MVT::Other, Expand); |
| 400 | |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 401 | // Use the default for now |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 402 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
| 403 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 404 | |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 405 | setOperationAction(ISD::ATOMIC_LOAD, MVT::i32, Expand); |
| 406 | setOperationAction(ISD::ATOMIC_LOAD, MVT::i64, Expand); |
| 407 | setOperationAction(ISD::ATOMIC_STORE, MVT::i32, Expand); |
| 408 | setOperationAction(ISD::ATOMIC_STORE, MVT::i64, Expand); |
Eli Friedman | 4db5aca | 2011-08-29 18:23:02 +0000 | [diff] [blame] | 409 | |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 410 | setInsertFencesForAtomic(true); |
| 411 | |
Bruno Cardoso Lopes | 7728f7e | 2008-07-09 05:32:22 +0000 | [diff] [blame] | 412 | if (!Subtarget->hasSEInReg()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 413 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand); |
| 414 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Akira Hatanaka | c79507a | 2011-12-21 00:20:27 +0000 | [diff] [blame] | 417 | if (!Subtarget->hasBitCount()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 418 | setOperationAction(ISD::CTLZ, MVT::i32, Expand); |
Akira Hatanaka | c79507a | 2011-12-21 00:20:27 +0000 | [diff] [blame] | 419 | setOperationAction(ISD::CTLZ, MVT::i64, Expand); |
| 420 | } |
Bruno Cardoso Lopes | 65ad452 | 2008-08-08 06:16:31 +0000 | [diff] [blame] | 421 | |
Akira Hatanaka | c0ea043 | 2011-12-20 23:56:43 +0000 | [diff] [blame] | 422 | if (!Subtarget->hasSwap()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 423 | setOperationAction(ISD::BSWAP, MVT::i32, Expand); |
Akira Hatanaka | c0ea043 | 2011-12-20 23:56:43 +0000 | [diff] [blame] | 424 | setOperationAction(ISD::BSWAP, MVT::i64, Expand); |
| 425 | } |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 426 | |
Akira Hatanaka | 7664f05 | 2012-06-02 00:04:42 +0000 | [diff] [blame] | 427 | if (HasMips64) { |
| 428 | setLoadExtAction(ISD::SEXTLOAD, MVT::i32, Custom); |
| 429 | setLoadExtAction(ISD::ZEXTLOAD, MVT::i32, Custom); |
| 430 | setLoadExtAction(ISD::EXTLOAD, MVT::i32, Custom); |
| 431 | setTruncStoreAction(MVT::i64, MVT::i32, Custom); |
| 432 | } |
| 433 | |
Akira Hatanaka | 9758562 | 2013-07-26 20:58:55 +0000 | [diff] [blame] | 434 | setOperationAction(ISD::TRAP, MVT::Other, Legal); |
| 435 | |
Bruno Cardoso Lopes | 38b5e86 | 2011-03-04 21:03:24 +0000 | [diff] [blame] | 436 | setTargetDAGCombine(ISD::SDIVREM); |
| 437 | setTargetDAGCombine(ISD::UDIVREM); |
Akira Hatanaka | ee8c3b0 | 2012-03-08 03:26:37 +0000 | [diff] [blame] | 438 | setTargetDAGCombine(ISD::SELECT); |
Akira Hatanaka | 77b85b6 | 2011-08-17 17:45:08 +0000 | [diff] [blame] | 439 | setTargetDAGCombine(ISD::AND); |
| 440 | setTargetDAGCombine(ISD::OR); |
Akira Hatanaka | 8782707 | 2012-06-13 20:33:18 +0000 | [diff] [blame] | 441 | setTargetDAGCombine(ISD::ADD); |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 442 | |
Akira Hatanaka | 5fdf500 | 2012-03-08 01:59:33 +0000 | [diff] [blame] | 443 | setMinFunctionAlignment(HasMips64 ? 3 : 2); |
Eli Friedman | fc5d305 | 2011-05-06 20:34:06 +0000 | [diff] [blame] | 444 | |
Akira Hatanaka | 3f5b107 | 2012-02-02 03:17:04 +0000 | [diff] [blame] | 445 | setStackPointerRegisterToSaveRestore(IsN64 ? Mips::SP_64 : Mips::SP); |
Akira Hatanaka | cf0cd80 | 2011-05-26 18:59:03 +0000 | [diff] [blame] | 446 | |
Akira Hatanaka | 590baca | 2012-02-02 03:13:40 +0000 | [diff] [blame] | 447 | setExceptionPointerRegister(IsN64 ? Mips::A0_64 : Mips::A0); |
| 448 | setExceptionSelectorRegister(IsN64 ? Mips::A1_64 : Mips::A1); |
Akira Hatanaka | e193b32 | 2012-06-13 19:33:32 +0000 | [diff] [blame] | 449 | |
Jim Grosbach | 3450f80 | 2013-02-20 21:13:59 +0000 | [diff] [blame] | 450 | MaxStoresPerMemcpy = 16; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 451 | } |
| 452 | |
Akira Hatanaka | 5ac065a | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 453 | const MipsTargetLowering *MipsTargetLowering::create(MipsTargetMachine &TM) { |
| 454 | if (TM.getSubtargetImpl()->inMips16Mode()) |
| 455 | return llvm::createMips16TargetLowering(TM); |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 456 | |
Akira Hatanaka | 5ac065a | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 457 | return llvm::createMipsSETargetLowering(TM); |
Akira Hatanaka | 5c21c9e | 2011-08-12 21:30:06 +0000 | [diff] [blame] | 458 | } |
| 459 | |
Matt Arsenault | 225ed70 | 2013-05-18 00:21:46 +0000 | [diff] [blame] | 460 | EVT MipsTargetLowering::getSetCCResultType(LLVMContext &, EVT VT) const { |
Akira Hatanaka | e13f441 | 2013-01-04 20:06:01 +0000 | [diff] [blame] | 461 | if (!VT.isVector()) |
| 462 | return MVT::i32; |
| 463 | return VT.changeVectorElementTypeToInteger(); |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 466 | static SDValue performDivRemCombine(SDNode *N, SelectionDAG &DAG, |
Bruno Cardoso Lopes | 38b5e86 | 2011-03-04 21:03:24 +0000 | [diff] [blame] | 467 | TargetLowering::DAGCombinerInfo &DCI, |
Akira Hatanaka | 864f660 | 2012-06-14 21:10:56 +0000 | [diff] [blame] | 468 | const MipsSubtarget *Subtarget) { |
Bruno Cardoso Lopes | 38b5e86 | 2011-03-04 21:03:24 +0000 | [diff] [blame] | 469 | if (DCI.isBeforeLegalizeOps()) |
| 470 | return SDValue(); |
| 471 | |
Akira Hatanaka | dda4a07 | 2011-10-03 21:06:13 +0000 | [diff] [blame] | 472 | EVT Ty = N->getValueType(0); |
Akira Hatanaka | cbaf6d0 | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 473 | unsigned LO = (Ty == MVT::i32) ? Mips::LO0 : Mips::LO0_64; |
| 474 | unsigned HI = (Ty == MVT::i32) ? Mips::HI0 : Mips::HI0_64; |
Akira Hatanaka | f5926fd | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 475 | unsigned Opc = N->getOpcode() == ISD::SDIVREM ? MipsISD::DivRem16 : |
| 476 | MipsISD::DivRemU16; |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 477 | SDLoc DL(N); |
Bruno Cardoso Lopes | 38b5e86 | 2011-03-04 21:03:24 +0000 | [diff] [blame] | 478 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 479 | SDValue DivRem = DAG.getNode(Opc, DL, MVT::Glue, |
Bruno Cardoso Lopes | 38b5e86 | 2011-03-04 21:03:24 +0000 | [diff] [blame] | 480 | N->getOperand(0), N->getOperand(1)); |
| 481 | SDValue InChain = DAG.getEntryNode(); |
| 482 | SDValue InGlue = DivRem; |
| 483 | |
| 484 | // insert MFLO |
| 485 | if (N->hasAnyUseOfValue(0)) { |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 486 | SDValue CopyFromLo = DAG.getCopyFromReg(InChain, DL, LO, Ty, |
Bruno Cardoso Lopes | 38b5e86 | 2011-03-04 21:03:24 +0000 | [diff] [blame] | 487 | InGlue); |
| 488 | DAG.ReplaceAllUsesOfValueWith(SDValue(N, 0), CopyFromLo); |
| 489 | InChain = CopyFromLo.getValue(1); |
| 490 | InGlue = CopyFromLo.getValue(2); |
| 491 | } |
| 492 | |
| 493 | // insert MFHI |
| 494 | if (N->hasAnyUseOfValue(1)) { |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 495 | SDValue CopyFromHi = DAG.getCopyFromReg(InChain, DL, |
Akira Hatanaka | dda4a07 | 2011-10-03 21:06:13 +0000 | [diff] [blame] | 496 | HI, Ty, InGlue); |
Bruno Cardoso Lopes | 38b5e86 | 2011-03-04 21:03:24 +0000 | [diff] [blame] | 497 | DAG.ReplaceAllUsesOfValueWith(SDValue(N, 1), CopyFromHi); |
| 498 | } |
| 499 | |
| 500 | return SDValue(); |
| 501 | } |
| 502 | |
Akira Hatanaka | 2fbe90c | 2013-04-18 01:00:46 +0000 | [diff] [blame] | 503 | static Mips::CondCode condCodeToFCC(ISD::CondCode CC) { |
Akira Hatanaka | 1d6b38d | 2011-03-31 18:26:17 +0000 | [diff] [blame] | 504 | switch (CC) { |
| 505 | default: llvm_unreachable("Unknown fp condition code!"); |
| 506 | case ISD::SETEQ: |
| 507 | case ISD::SETOEQ: return Mips::FCOND_OEQ; |
| 508 | case ISD::SETUNE: return Mips::FCOND_UNE; |
| 509 | case ISD::SETLT: |
| 510 | case ISD::SETOLT: return Mips::FCOND_OLT; |
| 511 | case ISD::SETGT: |
| 512 | case ISD::SETOGT: return Mips::FCOND_OGT; |
| 513 | case ISD::SETLE: |
| 514 | case ISD::SETOLE: return Mips::FCOND_OLE; |
| 515 | case ISD::SETGE: |
| 516 | case ISD::SETOGE: return Mips::FCOND_OGE; |
| 517 | case ISD::SETULT: return Mips::FCOND_ULT; |
| 518 | case ISD::SETULE: return Mips::FCOND_ULE; |
| 519 | case ISD::SETUGT: return Mips::FCOND_UGT; |
| 520 | case ISD::SETUGE: return Mips::FCOND_UGE; |
| 521 | case ISD::SETUO: return Mips::FCOND_UN; |
| 522 | case ISD::SETO: return Mips::FCOND_OR; |
| 523 | case ISD::SETNE: |
| 524 | case ISD::SETONE: return Mips::FCOND_ONE; |
| 525 | case ISD::SETUEQ: return Mips::FCOND_UEQ; |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | |
Akira Hatanaka | 9cf0724 | 2013-03-30 01:16:38 +0000 | [diff] [blame] | 530 | /// This function returns true if the floating point conditional branches and |
| 531 | /// conditional moves which use condition code CC should be inverted. |
| 532 | static bool invertFPCondCodeUser(Mips::CondCode CC) { |
Akira Hatanaka | 1d6b38d | 2011-03-31 18:26:17 +0000 | [diff] [blame] | 533 | if (CC >= Mips::FCOND_F && CC <= Mips::FCOND_NGT) |
| 534 | return false; |
| 535 | |
Akira Hatanaka | 8209968 | 2011-12-19 19:52:25 +0000 | [diff] [blame] | 536 | assert((CC >= Mips::FCOND_T && CC <= Mips::FCOND_GT) && |
| 537 | "Illegal Condition Code"); |
Akira Hatanaka | 1d6b38d | 2011-03-31 18:26:17 +0000 | [diff] [blame] | 538 | |
Akira Hatanaka | 8209968 | 2011-12-19 19:52:25 +0000 | [diff] [blame] | 539 | return true; |
Akira Hatanaka | 1d6b38d | 2011-03-31 18:26:17 +0000 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | // Creates and returns an FPCmp node from a setcc node. |
| 543 | // Returns Op if setcc is not a floating point comparison. |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 544 | static SDValue createFPCmp(SelectionDAG &DAG, const SDValue &Op) { |
Akira Hatanaka | 1d6b38d | 2011-03-31 18:26:17 +0000 | [diff] [blame] | 545 | // must be a SETCC node |
| 546 | if (Op.getOpcode() != ISD::SETCC) |
| 547 | return Op; |
| 548 | |
| 549 | SDValue LHS = Op.getOperand(0); |
| 550 | |
| 551 | if (!LHS.getValueType().isFloatingPoint()) |
| 552 | return Op; |
| 553 | |
| 554 | SDValue RHS = Op.getOperand(1); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 555 | SDLoc DL(Op); |
Akira Hatanaka | 1d6b38d | 2011-03-31 18:26:17 +0000 | [diff] [blame] | 556 | |
Akira Hatanaka | 0bf3dfb | 2011-04-15 21:00:26 +0000 | [diff] [blame] | 557 | // Assume the 3rd operand is a CondCodeSDNode. Add code to check the type of |
| 558 | // node if necessary. |
Akira Hatanaka | 1d6b38d | 2011-03-31 18:26:17 +0000 | [diff] [blame] | 559 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get(); |
| 560 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 561 | return DAG.getNode(MipsISD::FPCmp, DL, MVT::Glue, LHS, RHS, |
Akira Hatanaka | 2fbe90c | 2013-04-18 01:00:46 +0000 | [diff] [blame] | 562 | DAG.getConstant(condCodeToFCC(CC), MVT::i32)); |
Akira Hatanaka | 1d6b38d | 2011-03-31 18:26:17 +0000 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | // Creates and returns a CMovFPT/F node. |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 566 | static SDValue createCMovFP(SelectionDAG &DAG, SDValue Cond, SDValue True, |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 567 | SDValue False, SDLoc DL) { |
Akira Hatanaka | 9cf0724 | 2013-03-30 01:16:38 +0000 | [diff] [blame] | 568 | ConstantSDNode *CC = cast<ConstantSDNode>(Cond.getOperand(2)); |
| 569 | bool invert = invertFPCondCodeUser((Mips::CondCode)CC->getSExtValue()); |
Akira Hatanaka | 407883b | 2013-07-26 20:51:20 +0000 | [diff] [blame] | 570 | SDValue FCC0 = DAG.getRegister(Mips::FCC0, MVT::i32); |
Akira Hatanaka | 1d6b38d | 2011-03-31 18:26:17 +0000 | [diff] [blame] | 571 | |
| 572 | return DAG.getNode((invert ? MipsISD::CMovFP_F : MipsISD::CMovFP_T), DL, |
Akira Hatanaka | 407883b | 2013-07-26 20:51:20 +0000 | [diff] [blame] | 573 | True.getValueType(), True, FCC0, False, Cond); |
Akira Hatanaka | 1d6b38d | 2011-03-31 18:26:17 +0000 | [diff] [blame] | 574 | } |
| 575 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 576 | static SDValue performSELECTCombine(SDNode *N, SelectionDAG &DAG, |
Akira Hatanaka | e2bdf7f | 2012-03-08 02:14:24 +0000 | [diff] [blame] | 577 | TargetLowering::DAGCombinerInfo &DCI, |
Akira Hatanaka | 864f660 | 2012-06-14 21:10:56 +0000 | [diff] [blame] | 578 | const MipsSubtarget *Subtarget) { |
Akira Hatanaka | e2bdf7f | 2012-03-08 02:14:24 +0000 | [diff] [blame] | 579 | if (DCI.isBeforeLegalizeOps()) |
| 580 | return SDValue(); |
| 581 | |
| 582 | SDValue SetCC = N->getOperand(0); |
| 583 | |
| 584 | if ((SetCC.getOpcode() != ISD::SETCC) || |
| 585 | !SetCC.getOperand(0).getValueType().isInteger()) |
| 586 | return SDValue(); |
| 587 | |
| 588 | SDValue False = N->getOperand(2); |
| 589 | EVT FalseTy = False.getValueType(); |
| 590 | |
| 591 | if (!FalseTy.isInteger()) |
| 592 | return SDValue(); |
| 593 | |
| 594 | ConstantSDNode *CN = dyn_cast<ConstantSDNode>(False); |
| 595 | |
| 596 | if (!CN || CN->getZExtValue()) |
| 597 | return SDValue(); |
| 598 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 599 | const SDLoc DL(N); |
Akira Hatanaka | e2bdf7f | 2012-03-08 02:14:24 +0000 | [diff] [blame] | 600 | ISD::CondCode CC = cast<CondCodeSDNode>(SetCC.getOperand(2))->get(); |
| 601 | SDValue True = N->getOperand(1); |
Akira Hatanaka | 864f660 | 2012-06-14 21:10:56 +0000 | [diff] [blame] | 602 | |
Akira Hatanaka | e2bdf7f | 2012-03-08 02:14:24 +0000 | [diff] [blame] | 603 | SetCC = DAG.getSetCC(DL, SetCC.getValueType(), SetCC.getOperand(0), |
| 604 | SetCC.getOperand(1), ISD::getSetCCInverse(CC, true)); |
Akira Hatanaka | 864f660 | 2012-06-14 21:10:56 +0000 | [diff] [blame] | 605 | |
Akira Hatanaka | e2bdf7f | 2012-03-08 02:14:24 +0000 | [diff] [blame] | 606 | return DAG.getNode(ISD::SELECT, DL, FalseTy, SetCC, False, True); |
| 607 | } |
| 608 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 609 | static SDValue performANDCombine(SDNode *N, SelectionDAG &DAG, |
Akira Hatanaka | 77b85b6 | 2011-08-17 17:45:08 +0000 | [diff] [blame] | 610 | TargetLowering::DAGCombinerInfo &DCI, |
Akira Hatanaka | 864f660 | 2012-06-14 21:10:56 +0000 | [diff] [blame] | 611 | const MipsSubtarget *Subtarget) { |
Akira Hatanaka | 77b85b6 | 2011-08-17 17:45:08 +0000 | [diff] [blame] | 612 | // Pattern match EXT. |
| 613 | // $dst = and ((sra or srl) $src , pos), (2**size - 1) |
| 614 | // => ext $dst, $src, size, pos |
Akira Hatanaka | 5663344 | 2011-09-20 23:53:09 +0000 | [diff] [blame] | 615 | if (DCI.isBeforeLegalizeOps() || !Subtarget->hasMips32r2()) |
Akira Hatanaka | 77b85b6 | 2011-08-17 17:45:08 +0000 | [diff] [blame] | 616 | return SDValue(); |
| 617 | |
| 618 | SDValue ShiftRight = N->getOperand(0), Mask = N->getOperand(1); |
Akira Hatanaka | d6bc523 | 2011-12-05 21:26:34 +0000 | [diff] [blame] | 619 | unsigned ShiftRightOpc = ShiftRight.getOpcode(); |
| 620 | |
Akira Hatanaka | 77b85b6 | 2011-08-17 17:45:08 +0000 | [diff] [blame] | 621 | // Op's first operand must be a shift right. |
Akira Hatanaka | d6bc523 | 2011-12-05 21:26:34 +0000 | [diff] [blame] | 622 | if (ShiftRightOpc != ISD::SRA && ShiftRightOpc != ISD::SRL) |
Akira Hatanaka | 77b85b6 | 2011-08-17 17:45:08 +0000 | [diff] [blame] | 623 | return SDValue(); |
| 624 | |
| 625 | // The second operand of the shift must be an immediate. |
Akira Hatanaka | 77b85b6 | 2011-08-17 17:45:08 +0000 | [diff] [blame] | 626 | ConstantSDNode *CN; |
| 627 | if (!(CN = dyn_cast<ConstantSDNode>(ShiftRight.getOperand(1)))) |
| 628 | return SDValue(); |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 629 | |
Akira Hatanaka | d6bc523 | 2011-12-05 21:26:34 +0000 | [diff] [blame] | 630 | uint64_t Pos = CN->getZExtValue(); |
Akira Hatanaka | 77b85b6 | 2011-08-17 17:45:08 +0000 | [diff] [blame] | 631 | uint64_t SMPos, SMSize; |
Akira Hatanaka | d6bc523 | 2011-12-05 21:26:34 +0000 | [diff] [blame] | 632 | |
Akira Hatanaka | 77b85b6 | 2011-08-17 17:45:08 +0000 | [diff] [blame] | 633 | // Op's second operand must be a shifted mask. |
| 634 | if (!(CN = dyn_cast<ConstantSDNode>(Mask)) || |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 635 | !isShiftedMask(CN->getZExtValue(), SMPos, SMSize)) |
Akira Hatanaka | 77b85b6 | 2011-08-17 17:45:08 +0000 | [diff] [blame] | 636 | return SDValue(); |
| 637 | |
| 638 | // Return if the shifted mask does not start at bit 0 or the sum of its size |
| 639 | // and Pos exceeds the word's size. |
Akira Hatanaka | d6bc523 | 2011-12-05 21:26:34 +0000 | [diff] [blame] | 640 | EVT ValTy = N->getValueType(0); |
| 641 | if (SMPos != 0 || Pos + SMSize > ValTy.getSizeInBits()) |
Akira Hatanaka | 77b85b6 | 2011-08-17 17:45:08 +0000 | [diff] [blame] | 642 | return SDValue(); |
| 643 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 644 | return DAG.getNode(MipsISD::Ext, SDLoc(N), ValTy, |
Akira Hatanaka | 8209968 | 2011-12-19 19:52:25 +0000 | [diff] [blame] | 645 | ShiftRight.getOperand(0), DAG.getConstant(Pos, MVT::i32), |
Akira Hatanaka | 667645f | 2011-08-17 22:59:46 +0000 | [diff] [blame] | 646 | DAG.getConstant(SMSize, MVT::i32)); |
Akira Hatanaka | 77b85b6 | 2011-08-17 17:45:08 +0000 | [diff] [blame] | 647 | } |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 648 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 649 | static SDValue performORCombine(SDNode *N, SelectionDAG &DAG, |
Akira Hatanaka | 77b85b6 | 2011-08-17 17:45:08 +0000 | [diff] [blame] | 650 | TargetLowering::DAGCombinerInfo &DCI, |
Akira Hatanaka | 864f660 | 2012-06-14 21:10:56 +0000 | [diff] [blame] | 651 | const MipsSubtarget *Subtarget) { |
Akira Hatanaka | 77b85b6 | 2011-08-17 17:45:08 +0000 | [diff] [blame] | 652 | // Pattern match INS. |
| 653 | // $dst = or (and $src1 , mask0), (and (shl $src, pos), mask1), |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 654 | // where mask1 = (2**size - 1) << pos, mask0 = ~mask1 |
Akira Hatanaka | 77b85b6 | 2011-08-17 17:45:08 +0000 | [diff] [blame] | 655 | // => ins $dst, $src, size, pos, $src1 |
Akira Hatanaka | 5663344 | 2011-09-20 23:53:09 +0000 | [diff] [blame] | 656 | if (DCI.isBeforeLegalizeOps() || !Subtarget->hasMips32r2()) |
Akira Hatanaka | 77b85b6 | 2011-08-17 17:45:08 +0000 | [diff] [blame] | 657 | return SDValue(); |
| 658 | |
| 659 | SDValue And0 = N->getOperand(0), And1 = N->getOperand(1); |
| 660 | uint64_t SMPos0, SMSize0, SMPos1, SMSize1; |
| 661 | ConstantSDNode *CN; |
| 662 | |
| 663 | // See if Op's first operand matches (and $src1 , mask0). |
| 664 | if (And0.getOpcode() != ISD::AND) |
| 665 | return SDValue(); |
| 666 | |
| 667 | if (!(CN = dyn_cast<ConstantSDNode>(And0.getOperand(1))) || |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 668 | !isShiftedMask(~CN->getSExtValue(), SMPos0, SMSize0)) |
Akira Hatanaka | 77b85b6 | 2011-08-17 17:45:08 +0000 | [diff] [blame] | 669 | return SDValue(); |
| 670 | |
| 671 | // See if Op's second operand matches (and (shl $src, pos), mask1). |
| 672 | if (And1.getOpcode() != ISD::AND) |
| 673 | return SDValue(); |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 674 | |
Akira Hatanaka | 77b85b6 | 2011-08-17 17:45:08 +0000 | [diff] [blame] | 675 | if (!(CN = dyn_cast<ConstantSDNode>(And1.getOperand(1))) || |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 676 | !isShiftedMask(CN->getZExtValue(), SMPos1, SMSize1)) |
Akira Hatanaka | 77b85b6 | 2011-08-17 17:45:08 +0000 | [diff] [blame] | 677 | return SDValue(); |
| 678 | |
| 679 | // The shift masks must have the same position and size. |
| 680 | if (SMPos0 != SMPos1 || SMSize0 != SMSize1) |
| 681 | return SDValue(); |
| 682 | |
| 683 | SDValue Shl = And1.getOperand(0); |
| 684 | if (Shl.getOpcode() != ISD::SHL) |
| 685 | return SDValue(); |
| 686 | |
| 687 | if (!(CN = dyn_cast<ConstantSDNode>(Shl.getOperand(1)))) |
| 688 | return SDValue(); |
| 689 | |
| 690 | unsigned Shamt = CN->getZExtValue(); |
| 691 | |
| 692 | // Return if the shift amount and the first bit position of mask are not the |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 693 | // same. |
Akira Hatanaka | d6bc523 | 2011-12-05 21:26:34 +0000 | [diff] [blame] | 694 | EVT ValTy = N->getValueType(0); |
| 695 | if ((Shamt != SMPos0) || (SMPos0 + SMSize0 > ValTy.getSizeInBits())) |
Akira Hatanaka | 77b85b6 | 2011-08-17 17:45:08 +0000 | [diff] [blame] | 696 | return SDValue(); |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 697 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 698 | return DAG.getNode(MipsISD::Ins, SDLoc(N), ValTy, Shl.getOperand(0), |
Akira Hatanaka | 77b85b6 | 2011-08-17 17:45:08 +0000 | [diff] [blame] | 699 | DAG.getConstant(SMPos0, MVT::i32), |
Akira Hatanaka | 8209968 | 2011-12-19 19:52:25 +0000 | [diff] [blame] | 700 | DAG.getConstant(SMSize0, MVT::i32), And0.getOperand(0)); |
Akira Hatanaka | 77b85b6 | 2011-08-17 17:45:08 +0000 | [diff] [blame] | 701 | } |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 702 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 703 | static SDValue performADDCombine(SDNode *N, SelectionDAG &DAG, |
Akira Hatanaka | 8782707 | 2012-06-13 20:33:18 +0000 | [diff] [blame] | 704 | TargetLowering::DAGCombinerInfo &DCI, |
Akira Hatanaka | 864f660 | 2012-06-14 21:10:56 +0000 | [diff] [blame] | 705 | const MipsSubtarget *Subtarget) { |
Akira Hatanaka | 8782707 | 2012-06-13 20:33:18 +0000 | [diff] [blame] | 706 | // (add v0, (add v1, abs_lo(tjt))) => (add (add v0, v1), abs_lo(tjt)) |
| 707 | |
| 708 | if (DCI.isBeforeLegalizeOps()) |
| 709 | return SDValue(); |
| 710 | |
| 711 | SDValue Add = N->getOperand(1); |
| 712 | |
| 713 | if (Add.getOpcode() != ISD::ADD) |
| 714 | return SDValue(); |
| 715 | |
| 716 | SDValue Lo = Add.getOperand(1); |
| 717 | |
| 718 | if ((Lo.getOpcode() != MipsISD::Lo) || |
| 719 | (Lo.getOperand(0).getOpcode() != ISD::TargetJumpTable)) |
| 720 | return SDValue(); |
| 721 | |
| 722 | EVT ValTy = N->getValueType(0); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 723 | SDLoc DL(N); |
Akira Hatanaka | 8782707 | 2012-06-13 20:33:18 +0000 | [diff] [blame] | 724 | |
| 725 | SDValue Add1 = DAG.getNode(ISD::ADD, DL, ValTy, N->getOperand(0), |
| 726 | Add.getOperand(0)); |
| 727 | return DAG.getNode(ISD::ADD, DL, ValTy, Add1, Lo); |
| 728 | } |
| 729 | |
Bruno Cardoso Lopes | 8e826e6 | 2011-02-10 18:05:10 +0000 | [diff] [blame] | 730 | SDValue MipsTargetLowering::PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 731 | const { |
| 732 | SelectionDAG &DAG = DCI.DAG; |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 733 | unsigned Opc = N->getOpcode(); |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 734 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 735 | switch (Opc) { |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 736 | default: break; |
Bruno Cardoso Lopes | 38b5e86 | 2011-03-04 21:03:24 +0000 | [diff] [blame] | 737 | case ISD::SDIVREM: |
| 738 | case ISD::UDIVREM: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 739 | return performDivRemCombine(N, DAG, DCI, Subtarget); |
Akira Hatanaka | e2bdf7f | 2012-03-08 02:14:24 +0000 | [diff] [blame] | 740 | case ISD::SELECT: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 741 | return performSELECTCombine(N, DAG, DCI, Subtarget); |
Akira Hatanaka | 77b85b6 | 2011-08-17 17:45:08 +0000 | [diff] [blame] | 742 | case ISD::AND: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 743 | return performANDCombine(N, DAG, DCI, Subtarget); |
Akira Hatanaka | 77b85b6 | 2011-08-17 17:45:08 +0000 | [diff] [blame] | 744 | case ISD::OR: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 745 | return performORCombine(N, DAG, DCI, Subtarget); |
Akira Hatanaka | 8782707 | 2012-06-13 20:33:18 +0000 | [diff] [blame] | 746 | case ISD::ADD: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 747 | return performADDCombine(N, DAG, DCI, Subtarget); |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | return SDValue(); |
| 751 | } |
| 752 | |
Akira Hatanaka | b430cec | 2012-09-21 23:58:31 +0000 | [diff] [blame] | 753 | void |
| 754 | MipsTargetLowering::LowerOperationWrapper(SDNode *N, |
| 755 | SmallVectorImpl<SDValue> &Results, |
| 756 | SelectionDAG &DAG) const { |
| 757 | SDValue Res = LowerOperation(SDValue(N, 0), DAG); |
| 758 | |
| 759 | for (unsigned I = 0, E = Res->getNumValues(); I != E; ++I) |
| 760 | Results.push_back(Res.getValue(I)); |
| 761 | } |
| 762 | |
| 763 | void |
| 764 | MipsTargetLowering::ReplaceNodeResults(SDNode *N, |
| 765 | SmallVectorImpl<SDValue> &Results, |
| 766 | SelectionDAG &DAG) const { |
Akira Hatanaka | 13ec481 | 2013-04-30 21:17:07 +0000 | [diff] [blame] | 767 | return LowerOperationWrapper(N, Results, DAG); |
Akira Hatanaka | b430cec | 2012-09-21 23:58:31 +0000 | [diff] [blame] | 768 | } |
| 769 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 770 | SDValue MipsTargetLowering:: |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 771 | LowerOperation(SDValue Op, SelectionDAG &DAG) const |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 772 | { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 773 | switch (Op.getOpcode()) |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 774 | { |
Akira Hatanaka | 2459afe | 2013-03-30 01:15:17 +0000 | [diff] [blame] | 775 | case ISD::BR_JT: return lowerBR_JT(Op, DAG); |
| 776 | case ISD::BRCOND: return lowerBRCOND(Op, DAG); |
| 777 | case ISD::ConstantPool: return lowerConstantPool(Op, DAG); |
| 778 | case ISD::GlobalAddress: return lowerGlobalAddress(Op, DAG); |
| 779 | case ISD::BlockAddress: return lowerBlockAddress(Op, DAG); |
| 780 | case ISD::GlobalTLSAddress: return lowerGlobalTLSAddress(Op, DAG); |
| 781 | case ISD::JumpTable: return lowerJumpTable(Op, DAG); |
| 782 | case ISD::SELECT: return lowerSELECT(Op, DAG); |
| 783 | case ISD::SELECT_CC: return lowerSELECT_CC(Op, DAG); |
| 784 | case ISD::SETCC: return lowerSETCC(Op, DAG); |
| 785 | case ISD::VASTART: return lowerVASTART(Op, DAG); |
| 786 | case ISD::FCOPYSIGN: return lowerFCOPYSIGN(Op, DAG); |
| 787 | case ISD::FABS: return lowerFABS(Op, DAG); |
| 788 | case ISD::FRAMEADDR: return lowerFRAMEADDR(Op, DAG); |
| 789 | case ISD::RETURNADDR: return lowerRETURNADDR(Op, DAG); |
| 790 | case ISD::EH_RETURN: return lowerEH_RETURN(Op, DAG); |
Akira Hatanaka | 2459afe | 2013-03-30 01:15:17 +0000 | [diff] [blame] | 791 | case ISD::ATOMIC_FENCE: return lowerATOMIC_FENCE(Op, DAG); |
| 792 | case ISD::SHL_PARTS: return lowerShiftLeftParts(Op, DAG); |
| 793 | case ISD::SRA_PARTS: return lowerShiftRightParts(Op, DAG, true); |
| 794 | case ISD::SRL_PARTS: return lowerShiftRightParts(Op, DAG, false); |
| 795 | case ISD::LOAD: return lowerLOAD(Op, DAG); |
| 796 | case ISD::STORE: return lowerSTORE(Op, DAG); |
Akira Hatanaka | 2459afe | 2013-03-30 01:15:17 +0000 | [diff] [blame] | 797 | case ISD::ADD: return lowerADD(Op, DAG); |
Akira Hatanaka | ae7e7cb | 2013-05-16 21:17:15 +0000 | [diff] [blame] | 798 | case ISD::FP_TO_SINT: return lowerFP_TO_SINT(Op, DAG); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 799 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 800 | return SDValue(); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 801 | } |
| 802 | |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 803 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 804 | // Lower helper functions |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 805 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 806 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 807 | // addLiveIn - This helper function adds the specified physical register to the |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 808 | // MachineFunction as a live in value. It also creates a corresponding |
| 809 | // virtual register for it. |
| 810 | static unsigned |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 811 | addLiveIn(MachineFunction &MF, unsigned PReg, const TargetRegisterClass *RC) |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 812 | { |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 813 | unsigned VReg = MF.getRegInfo().createVirtualRegister(RC); |
| 814 | MF.getRegInfo().addLiveIn(PReg, VReg); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 815 | return VReg; |
| 816 | } |
| 817 | |
Akira Hatanaka | f894199 | 2013-05-20 18:07:43 +0000 | [diff] [blame] | 818 | static MachineBasicBlock *expandPseudoDIV(MachineInstr *MI, |
| 819 | MachineBasicBlock &MBB, |
| 820 | const TargetInstrInfo &TII, |
| 821 | bool Is64Bit) { |
| 822 | if (NoZeroDivCheck) |
| 823 | return &MBB; |
| 824 | |
| 825 | // Insert instruction "teq $divisor_reg, $zero, 7". |
| 826 | MachineBasicBlock::iterator I(MI); |
| 827 | MachineInstrBuilder MIB; |
| 828 | MIB = BuildMI(MBB, llvm::next(I), MI->getDebugLoc(), TII.get(Mips::TEQ)) |
| 829 | .addOperand(MI->getOperand(2)).addReg(Mips::ZERO).addImm(7); |
| 830 | |
| 831 | // Use the 32-bit sub-register if this is a 64-bit division. |
| 832 | if (Is64Bit) |
| 833 | MIB->getOperand(0).setSubReg(Mips::sub_32); |
| 834 | |
| 835 | return &MBB; |
| 836 | } |
| 837 | |
Akira Hatanaka | 01f7089 | 2012-09-27 02:15:57 +0000 | [diff] [blame] | 838 | MachineBasicBlock * |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 839 | MipsTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
Dan Gohman | af1d8ca | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 840 | MachineBasicBlock *BB) const { |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 841 | switch (MI->getOpcode()) { |
Reed Kotler | ffbe432 | 2013-02-21 04:22:38 +0000 | [diff] [blame] | 842 | default: |
| 843 | llvm_unreachable("Unexpected instr type to insert"); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 844 | case Mips::ATOMIC_LOAD_ADD_I8: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 845 | return emitAtomicBinaryPartword(MI, BB, 1, Mips::ADDu); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 846 | case Mips::ATOMIC_LOAD_ADD_I16: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 847 | return emitAtomicBinaryPartword(MI, BB, 2, Mips::ADDu); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 848 | case Mips::ATOMIC_LOAD_ADD_I32: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 849 | return emitAtomicBinary(MI, BB, 4, Mips::ADDu); |
Akira Hatanaka | 5906806 | 2011-11-11 04:14:30 +0000 | [diff] [blame] | 850 | case Mips::ATOMIC_LOAD_ADD_I64: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 851 | return emitAtomicBinary(MI, BB, 8, Mips::DADDu); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 852 | |
| 853 | case Mips::ATOMIC_LOAD_AND_I8: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 854 | return emitAtomicBinaryPartword(MI, BB, 1, Mips::AND); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 855 | case Mips::ATOMIC_LOAD_AND_I16: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 856 | return emitAtomicBinaryPartword(MI, BB, 2, Mips::AND); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 857 | case Mips::ATOMIC_LOAD_AND_I32: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 858 | return emitAtomicBinary(MI, BB, 4, Mips::AND); |
Akira Hatanaka | 5906806 | 2011-11-11 04:14:30 +0000 | [diff] [blame] | 859 | case Mips::ATOMIC_LOAD_AND_I64: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 860 | return emitAtomicBinary(MI, BB, 8, Mips::AND64); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 861 | |
| 862 | case Mips::ATOMIC_LOAD_OR_I8: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 863 | return emitAtomicBinaryPartword(MI, BB, 1, Mips::OR); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 864 | case Mips::ATOMIC_LOAD_OR_I16: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 865 | return emitAtomicBinaryPartword(MI, BB, 2, Mips::OR); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 866 | case Mips::ATOMIC_LOAD_OR_I32: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 867 | return emitAtomicBinary(MI, BB, 4, Mips::OR); |
Akira Hatanaka | 5906806 | 2011-11-11 04:14:30 +0000 | [diff] [blame] | 868 | case Mips::ATOMIC_LOAD_OR_I64: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 869 | return emitAtomicBinary(MI, BB, 8, Mips::OR64); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 870 | |
| 871 | case Mips::ATOMIC_LOAD_XOR_I8: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 872 | return emitAtomicBinaryPartword(MI, BB, 1, Mips::XOR); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 873 | case Mips::ATOMIC_LOAD_XOR_I16: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 874 | return emitAtomicBinaryPartword(MI, BB, 2, Mips::XOR); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 875 | case Mips::ATOMIC_LOAD_XOR_I32: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 876 | return emitAtomicBinary(MI, BB, 4, Mips::XOR); |
Akira Hatanaka | 5906806 | 2011-11-11 04:14:30 +0000 | [diff] [blame] | 877 | case Mips::ATOMIC_LOAD_XOR_I64: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 878 | return emitAtomicBinary(MI, BB, 8, Mips::XOR64); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 879 | |
| 880 | case Mips::ATOMIC_LOAD_NAND_I8: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 881 | return emitAtomicBinaryPartword(MI, BB, 1, 0, true); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 882 | case Mips::ATOMIC_LOAD_NAND_I16: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 883 | return emitAtomicBinaryPartword(MI, BB, 2, 0, true); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 884 | case Mips::ATOMIC_LOAD_NAND_I32: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 885 | return emitAtomicBinary(MI, BB, 4, 0, true); |
Akira Hatanaka | 5906806 | 2011-11-11 04:14:30 +0000 | [diff] [blame] | 886 | case Mips::ATOMIC_LOAD_NAND_I64: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 887 | return emitAtomicBinary(MI, BB, 8, 0, true); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 888 | |
| 889 | case Mips::ATOMIC_LOAD_SUB_I8: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 890 | return emitAtomicBinaryPartword(MI, BB, 1, Mips::SUBu); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 891 | case Mips::ATOMIC_LOAD_SUB_I16: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 892 | return emitAtomicBinaryPartword(MI, BB, 2, Mips::SUBu); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 893 | case Mips::ATOMIC_LOAD_SUB_I32: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 894 | return emitAtomicBinary(MI, BB, 4, Mips::SUBu); |
Akira Hatanaka | 5906806 | 2011-11-11 04:14:30 +0000 | [diff] [blame] | 895 | case Mips::ATOMIC_LOAD_SUB_I64: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 896 | return emitAtomicBinary(MI, BB, 8, Mips::DSUBu); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 897 | |
| 898 | case Mips::ATOMIC_SWAP_I8: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 899 | return emitAtomicBinaryPartword(MI, BB, 1, 0); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 900 | case Mips::ATOMIC_SWAP_I16: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 901 | return emitAtomicBinaryPartword(MI, BB, 2, 0); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 902 | case Mips::ATOMIC_SWAP_I32: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 903 | return emitAtomicBinary(MI, BB, 4, 0); |
Akira Hatanaka | 5906806 | 2011-11-11 04:14:30 +0000 | [diff] [blame] | 904 | case Mips::ATOMIC_SWAP_I64: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 905 | return emitAtomicBinary(MI, BB, 8, 0); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 906 | |
| 907 | case Mips::ATOMIC_CMP_SWAP_I8: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 908 | return emitAtomicCmpSwapPartword(MI, BB, 1); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 909 | case Mips::ATOMIC_CMP_SWAP_I16: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 910 | return emitAtomicCmpSwapPartword(MI, BB, 2); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 911 | case Mips::ATOMIC_CMP_SWAP_I32: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 912 | return emitAtomicCmpSwap(MI, BB, 4); |
Akira Hatanaka | 5906806 | 2011-11-11 04:14:30 +0000 | [diff] [blame] | 913 | case Mips::ATOMIC_CMP_SWAP_I64: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 914 | return emitAtomicCmpSwap(MI, BB, 8); |
Akira Hatanaka | f894199 | 2013-05-20 18:07:43 +0000 | [diff] [blame] | 915 | case Mips::PseudoSDIV: |
| 916 | case Mips::PseudoUDIV: |
| 917 | return expandPseudoDIV(MI, *BB, *getTargetMachine().getInstrInfo(), false); |
| 918 | case Mips::PseudoDSDIV: |
| 919 | case Mips::PseudoDUDIV: |
| 920 | return expandPseudoDIV(MI, *BB, *getTargetMachine().getInstrInfo(), true); |
Akira Hatanaka | 1d6b38d | 2011-03-31 18:26:17 +0000 | [diff] [blame] | 921 | } |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 922 | } |
| 923 | |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 924 | // This function also handles Mips::ATOMIC_SWAP_I32 (when BinOpcode == 0), and |
| 925 | // Mips::ATOMIC_LOAD_NAND_I32 (when Nand == true) |
| 926 | MachineBasicBlock * |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 927 | MipsTargetLowering::emitAtomicBinary(MachineInstr *MI, MachineBasicBlock *BB, |
Eric Christopher | 471e422 | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 928 | unsigned Size, unsigned BinOpcode, |
Akira Hatanaka | 0f84382 | 2011-06-07 18:58:42 +0000 | [diff] [blame] | 929 | bool Nand) const { |
Akira Hatanaka | 5906806 | 2011-11-11 04:14:30 +0000 | [diff] [blame] | 930 | assert((Size == 4 || Size == 8) && "Unsupported size for EmitAtomicBinary."); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 931 | |
| 932 | MachineFunction *MF = BB->getParent(); |
| 933 | MachineRegisterInfo &RegInfo = MF->getRegInfo(); |
Akira Hatanaka | 5906806 | 2011-11-11 04:14:30 +0000 | [diff] [blame] | 934 | const TargetRegisterClass *RC = getRegClassFor(MVT::getIntegerVT(Size * 8)); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 935 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 936 | DebugLoc DL = MI->getDebugLoc(); |
Akira Hatanaka | 5906806 | 2011-11-11 04:14:30 +0000 | [diff] [blame] | 937 | unsigned LL, SC, AND, NOR, ZERO, BEQ; |
| 938 | |
| 939 | if (Size == 4) { |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame] | 940 | LL = Mips::LL; |
| 941 | SC = Mips::SC; |
Akira Hatanaka | 5906806 | 2011-11-11 04:14:30 +0000 | [diff] [blame] | 942 | AND = Mips::AND; |
| 943 | NOR = Mips::NOR; |
| 944 | ZERO = Mips::ZERO; |
| 945 | BEQ = Mips::BEQ; |
| 946 | } |
| 947 | else { |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame] | 948 | LL = Mips::LLD; |
| 949 | SC = Mips::SCD; |
Akira Hatanaka | 5906806 | 2011-11-11 04:14:30 +0000 | [diff] [blame] | 950 | AND = Mips::AND64; |
| 951 | NOR = Mips::NOR64; |
| 952 | ZERO = Mips::ZERO_64; |
| 953 | BEQ = Mips::BEQ64; |
| 954 | } |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 955 | |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 956 | unsigned OldVal = MI->getOperand(0).getReg(); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 957 | unsigned Ptr = MI->getOperand(1).getReg(); |
| 958 | unsigned Incr = MI->getOperand(2).getReg(); |
| 959 | |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 960 | unsigned StoreVal = RegInfo.createVirtualRegister(RC); |
| 961 | unsigned AndRes = RegInfo.createVirtualRegister(RC); |
| 962 | unsigned Success = RegInfo.createVirtualRegister(RC); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 963 | |
| 964 | // insert new blocks after the current block |
| 965 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 966 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 967 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 968 | MachineFunction::iterator It = BB; |
| 969 | ++It; |
| 970 | MF->insert(It, loopMBB); |
| 971 | MF->insert(It, exitMBB); |
| 972 | |
| 973 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 974 | exitMBB->splice(exitMBB->begin(), BB, |
| 975 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 976 | BB->end()); |
| 977 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 978 | |
| 979 | // thisMBB: |
| 980 | // ... |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 981 | // fallthrough --> loopMBB |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 982 | BB->addSuccessor(loopMBB); |
Akira Hatanaka | 81b4411 | 2011-07-19 17:09:53 +0000 | [diff] [blame] | 983 | loopMBB->addSuccessor(loopMBB); |
| 984 | loopMBB->addSuccessor(exitMBB); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 985 | |
| 986 | // loopMBB: |
| 987 | // ll oldval, 0(ptr) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 988 | // <binop> storeval, oldval, incr |
| 989 | // sc success, storeval, 0(ptr) |
| 990 | // beq success, $0, loopMBB |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 991 | BB = loopMBB; |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 992 | BuildMI(BB, DL, TII->get(LL), OldVal).addReg(Ptr).addImm(0); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 993 | if (Nand) { |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 994 | // and andres, oldval, incr |
| 995 | // nor storeval, $0, andres |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 996 | BuildMI(BB, DL, TII->get(AND), AndRes).addReg(OldVal).addReg(Incr); |
| 997 | BuildMI(BB, DL, TII->get(NOR), StoreVal).addReg(ZERO).addReg(AndRes); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 998 | } else if (BinOpcode) { |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 999 | // <binop> storeval, oldval, incr |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1000 | BuildMI(BB, DL, TII->get(BinOpcode), StoreVal).addReg(OldVal).addReg(Incr); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1001 | } else { |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1002 | StoreVal = Incr; |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1003 | } |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1004 | BuildMI(BB, DL, TII->get(SC), Success).addReg(StoreVal).addReg(Ptr).addImm(0); |
| 1005 | BuildMI(BB, DL, TII->get(BEQ)).addReg(Success).addReg(ZERO).addMBB(loopMBB); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1006 | |
| 1007 | MI->eraseFromParent(); // The instruction is gone now. |
| 1008 | |
Akira Hatanaka | 939ece1 | 2011-07-19 03:42:13 +0000 | [diff] [blame] | 1009 | return exitMBB; |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | MachineBasicBlock * |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1013 | MipsTargetLowering::emitAtomicBinaryPartword(MachineInstr *MI, |
Akira Hatanaka | 0f84382 | 2011-06-07 18:58:42 +0000 | [diff] [blame] | 1014 | MachineBasicBlock *BB, |
| 1015 | unsigned Size, unsigned BinOpcode, |
| 1016 | bool Nand) const { |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1017 | assert((Size == 1 || Size == 2) && |
| 1018 | "Unsupported size for EmitAtomicBinaryPartial."); |
| 1019 | |
| 1020 | MachineFunction *MF = BB->getParent(); |
| 1021 | MachineRegisterInfo &RegInfo = MF->getRegInfo(); |
| 1022 | const TargetRegisterClass *RC = getRegClassFor(MVT::i32); |
| 1023 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1024 | DebugLoc DL = MI->getDebugLoc(); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1025 | |
| 1026 | unsigned Dest = MI->getOperand(0).getReg(); |
| 1027 | unsigned Ptr = MI->getOperand(1).getReg(); |
| 1028 | unsigned Incr = MI->getOperand(2).getReg(); |
| 1029 | |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1030 | unsigned AlignedAddr = RegInfo.createVirtualRegister(RC); |
| 1031 | unsigned ShiftAmt = RegInfo.createVirtualRegister(RC); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1032 | unsigned Mask = RegInfo.createVirtualRegister(RC); |
| 1033 | unsigned Mask2 = RegInfo.createVirtualRegister(RC); |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1034 | unsigned NewVal = RegInfo.createVirtualRegister(RC); |
| 1035 | unsigned OldVal = RegInfo.createVirtualRegister(RC); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1036 | unsigned Incr2 = RegInfo.createVirtualRegister(RC); |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1037 | unsigned MaskLSB2 = RegInfo.createVirtualRegister(RC); |
| 1038 | unsigned PtrLSB2 = RegInfo.createVirtualRegister(RC); |
| 1039 | unsigned MaskUpper = RegInfo.createVirtualRegister(RC); |
| 1040 | unsigned AndRes = RegInfo.createVirtualRegister(RC); |
| 1041 | unsigned BinOpRes = RegInfo.createVirtualRegister(RC); |
Akira Hatanaka | bdd83fe | 2011-07-19 20:56:53 +0000 | [diff] [blame] | 1042 | unsigned MaskedOldVal0 = RegInfo.createVirtualRegister(RC); |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1043 | unsigned StoreVal = RegInfo.createVirtualRegister(RC); |
| 1044 | unsigned MaskedOldVal1 = RegInfo.createVirtualRegister(RC); |
| 1045 | unsigned SrlRes = RegInfo.createVirtualRegister(RC); |
| 1046 | unsigned SllRes = RegInfo.createVirtualRegister(RC); |
| 1047 | unsigned Success = RegInfo.createVirtualRegister(RC); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1048 | |
| 1049 | // insert new blocks after the current block |
| 1050 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 1051 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
Akira Hatanaka | 939ece1 | 2011-07-19 03:42:13 +0000 | [diff] [blame] | 1052 | MachineBasicBlock *sinkMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1053 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 1054 | MachineFunction::iterator It = BB; |
| 1055 | ++It; |
| 1056 | MF->insert(It, loopMBB); |
Akira Hatanaka | 939ece1 | 2011-07-19 03:42:13 +0000 | [diff] [blame] | 1057 | MF->insert(It, sinkMBB); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1058 | MF->insert(It, exitMBB); |
| 1059 | |
| 1060 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 1061 | exitMBB->splice(exitMBB->begin(), BB, |
Akira Hatanaka | 8209968 | 2011-12-19 19:52:25 +0000 | [diff] [blame] | 1062 | llvm::next(MachineBasicBlock::iterator(MI)), BB->end()); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1063 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 1064 | |
Akira Hatanaka | 81b4411 | 2011-07-19 17:09:53 +0000 | [diff] [blame] | 1065 | BB->addSuccessor(loopMBB); |
| 1066 | loopMBB->addSuccessor(loopMBB); |
| 1067 | loopMBB->addSuccessor(sinkMBB); |
| 1068 | sinkMBB->addSuccessor(exitMBB); |
| 1069 | |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1070 | // thisMBB: |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1071 | // addiu masklsb2,$0,-4 # 0xfffffffc |
| 1072 | // and alignedaddr,ptr,masklsb2 |
| 1073 | // andi ptrlsb2,ptr,3 |
| 1074 | // sll shiftamt,ptrlsb2,3 |
| 1075 | // ori maskupper,$0,255 # 0xff |
| 1076 | // sll mask,maskupper,shiftamt |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1077 | // nor mask2,$0,mask |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1078 | // sll incr2,incr,shiftamt |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1079 | |
| 1080 | int64_t MaskImm = (Size == 1) ? 255 : 65535; |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1081 | BuildMI(BB, DL, TII->get(Mips::ADDiu), MaskLSB2) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1082 | .addReg(Mips::ZERO).addImm(-4); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1083 | BuildMI(BB, DL, TII->get(Mips::AND), AlignedAddr) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1084 | .addReg(Ptr).addReg(MaskLSB2); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1085 | BuildMI(BB, DL, TII->get(Mips::ANDi), PtrLSB2).addReg(Ptr).addImm(3); |
Akira Hatanaka | affed7e | 2013-05-31 03:25:44 +0000 | [diff] [blame] | 1086 | if (Subtarget->isLittle()) { |
| 1087 | BuildMI(BB, DL, TII->get(Mips::SLL), ShiftAmt).addReg(PtrLSB2).addImm(3); |
| 1088 | } else { |
| 1089 | unsigned Off = RegInfo.createVirtualRegister(RC); |
| 1090 | BuildMI(BB, DL, TII->get(Mips::XORi), Off) |
| 1091 | .addReg(PtrLSB2).addImm((Size == 1) ? 3 : 2); |
| 1092 | BuildMI(BB, DL, TII->get(Mips::SLL), ShiftAmt).addReg(Off).addImm(3); |
| 1093 | } |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1094 | BuildMI(BB, DL, TII->get(Mips::ORi), MaskUpper) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1095 | .addReg(Mips::ZERO).addImm(MaskImm); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1096 | BuildMI(BB, DL, TII->get(Mips::SLLV), Mask) |
Akira Hatanaka | 5112243 | 2013-07-01 20:39:53 +0000 | [diff] [blame] | 1097 | .addReg(MaskUpper).addReg(ShiftAmt); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1098 | BuildMI(BB, DL, TII->get(Mips::NOR), Mask2).addReg(Mips::ZERO).addReg(Mask); |
Akira Hatanaka | 5112243 | 2013-07-01 20:39:53 +0000 | [diff] [blame] | 1099 | BuildMI(BB, DL, TII->get(Mips::SLLV), Incr2).addReg(Incr).addReg(ShiftAmt); |
Bruno Cardoso Lopes | cada2d0 | 2011-05-31 20:25:26 +0000 | [diff] [blame] | 1100 | |
Akira Hatanaka | 0d7d0b5 | 2011-07-18 18:52:12 +0000 | [diff] [blame] | 1101 | // atomic.load.binop |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1102 | // loopMBB: |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1103 | // ll oldval,0(alignedaddr) |
| 1104 | // binop binopres,oldval,incr2 |
| 1105 | // and newval,binopres,mask |
| 1106 | // and maskedoldval0,oldval,mask2 |
| 1107 | // or storeval,maskedoldval0,newval |
| 1108 | // sc success,storeval,0(alignedaddr) |
| 1109 | // beq success,$0,loopMBB |
| 1110 | |
Akira Hatanaka | 0d7d0b5 | 2011-07-18 18:52:12 +0000 | [diff] [blame] | 1111 | // atomic.swap |
| 1112 | // loopMBB: |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1113 | // ll oldval,0(alignedaddr) |
Akira Hatanaka | 70564a9 | 2011-07-19 18:14:26 +0000 | [diff] [blame] | 1114 | // and newval,incr2,mask |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1115 | // and maskedoldval0,oldval,mask2 |
| 1116 | // or storeval,maskedoldval0,newval |
| 1117 | // sc success,storeval,0(alignedaddr) |
| 1118 | // beq success,$0,loopMBB |
Akira Hatanaka | 0d7d0b5 | 2011-07-18 18:52:12 +0000 | [diff] [blame] | 1119 | |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1120 | BB = loopMBB; |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame] | 1121 | BuildMI(BB, DL, TII->get(Mips::LL), OldVal).addReg(AlignedAddr).addImm(0); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1122 | if (Nand) { |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1123 | // and andres, oldval, incr2 |
| 1124 | // nor binopres, $0, andres |
| 1125 | // and newval, binopres, mask |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1126 | BuildMI(BB, DL, TII->get(Mips::AND), AndRes).addReg(OldVal).addReg(Incr2); |
| 1127 | BuildMI(BB, DL, TII->get(Mips::NOR), BinOpRes) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1128 | .addReg(Mips::ZERO).addReg(AndRes); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1129 | BuildMI(BB, DL, TII->get(Mips::AND), NewVal).addReg(BinOpRes).addReg(Mask); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1130 | } else if (BinOpcode) { |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1131 | // <binop> binopres, oldval, incr2 |
| 1132 | // and newval, binopres, mask |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1133 | BuildMI(BB, DL, TII->get(BinOpcode), BinOpRes).addReg(OldVal).addReg(Incr2); |
| 1134 | BuildMI(BB, DL, TII->get(Mips::AND), NewVal).addReg(BinOpRes).addReg(Mask); |
Akira Hatanaka | 70564a9 | 2011-07-19 18:14:26 +0000 | [diff] [blame] | 1135 | } else {// atomic.swap |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1136 | // and newval, incr2, mask |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1137 | BuildMI(BB, DL, TII->get(Mips::AND), NewVal).addReg(Incr2).addReg(Mask); |
Akira Hatanaka | 70564a9 | 2011-07-19 18:14:26 +0000 | [diff] [blame] | 1138 | } |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 1139 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1140 | BuildMI(BB, DL, TII->get(Mips::AND), MaskedOldVal0) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1141 | .addReg(OldVal).addReg(Mask2); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1142 | BuildMI(BB, DL, TII->get(Mips::OR), StoreVal) |
Akira Hatanaka | bdd83fe | 2011-07-19 20:56:53 +0000 | [diff] [blame] | 1143 | .addReg(MaskedOldVal0).addReg(NewVal); |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame] | 1144 | BuildMI(BB, DL, TII->get(Mips::SC), Success) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1145 | .addReg(StoreVal).addReg(AlignedAddr).addImm(0); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1146 | BuildMI(BB, DL, TII->get(Mips::BEQ)) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1147 | .addReg(Success).addReg(Mips::ZERO).addMBB(loopMBB); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1148 | |
Akira Hatanaka | 939ece1 | 2011-07-19 03:42:13 +0000 | [diff] [blame] | 1149 | // sinkMBB: |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1150 | // and maskedoldval1,oldval,mask |
| 1151 | // srl srlres,maskedoldval1,shiftamt |
| 1152 | // sll sllres,srlres,24 |
| 1153 | // sra dest,sllres,24 |
Akira Hatanaka | 939ece1 | 2011-07-19 03:42:13 +0000 | [diff] [blame] | 1154 | BB = sinkMBB; |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1155 | int64_t ShiftImm = (Size == 1) ? 24 : 16; |
Akira Hatanaka | a308c67 | 2011-07-19 03:14:58 +0000 | [diff] [blame] | 1156 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1157 | BuildMI(BB, DL, TII->get(Mips::AND), MaskedOldVal1) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1158 | .addReg(OldVal).addReg(Mask); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1159 | BuildMI(BB, DL, TII->get(Mips::SRLV), SrlRes) |
Akira Hatanaka | 5112243 | 2013-07-01 20:39:53 +0000 | [diff] [blame] | 1160 | .addReg(MaskedOldVal1).addReg(ShiftAmt); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1161 | BuildMI(BB, DL, TII->get(Mips::SLL), SllRes) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1162 | .addReg(SrlRes).addImm(ShiftImm); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1163 | BuildMI(BB, DL, TII->get(Mips::SRA), Dest) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1164 | .addReg(SllRes).addImm(ShiftImm); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1165 | |
| 1166 | MI->eraseFromParent(); // The instruction is gone now. |
| 1167 | |
Akira Hatanaka | 939ece1 | 2011-07-19 03:42:13 +0000 | [diff] [blame] | 1168 | return exitMBB; |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | MachineBasicBlock * |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1172 | MipsTargetLowering::emitAtomicCmpSwap(MachineInstr *MI, |
Akira Hatanaka | 0f84382 | 2011-06-07 18:58:42 +0000 | [diff] [blame] | 1173 | MachineBasicBlock *BB, |
| 1174 | unsigned Size) const { |
Akira Hatanaka | 5906806 | 2011-11-11 04:14:30 +0000 | [diff] [blame] | 1175 | assert((Size == 4 || Size == 8) && "Unsupported size for EmitAtomicCmpSwap."); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1176 | |
| 1177 | MachineFunction *MF = BB->getParent(); |
| 1178 | MachineRegisterInfo &RegInfo = MF->getRegInfo(); |
Akira Hatanaka | 5906806 | 2011-11-11 04:14:30 +0000 | [diff] [blame] | 1179 | const TargetRegisterClass *RC = getRegClassFor(MVT::getIntegerVT(Size * 8)); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1180 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1181 | DebugLoc DL = MI->getDebugLoc(); |
Akira Hatanaka | 5906806 | 2011-11-11 04:14:30 +0000 | [diff] [blame] | 1182 | unsigned LL, SC, ZERO, BNE, BEQ; |
| 1183 | |
| 1184 | if (Size == 4) { |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame] | 1185 | LL = Mips::LL; |
| 1186 | SC = Mips::SC; |
Akira Hatanaka | 5906806 | 2011-11-11 04:14:30 +0000 | [diff] [blame] | 1187 | ZERO = Mips::ZERO; |
| 1188 | BNE = Mips::BNE; |
| 1189 | BEQ = Mips::BEQ; |
| 1190 | } |
| 1191 | else { |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame] | 1192 | LL = Mips::LLD; |
| 1193 | SC = Mips::SCD; |
Akira Hatanaka | 5906806 | 2011-11-11 04:14:30 +0000 | [diff] [blame] | 1194 | ZERO = Mips::ZERO_64; |
| 1195 | BNE = Mips::BNE64; |
| 1196 | BEQ = Mips::BEQ64; |
| 1197 | } |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1198 | |
| 1199 | unsigned Dest = MI->getOperand(0).getReg(); |
| 1200 | unsigned Ptr = MI->getOperand(1).getReg(); |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1201 | unsigned OldVal = MI->getOperand(2).getReg(); |
| 1202 | unsigned NewVal = MI->getOperand(3).getReg(); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1203 | |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1204 | unsigned Success = RegInfo.createVirtualRegister(RC); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1205 | |
| 1206 | // insert new blocks after the current block |
| 1207 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 1208 | MachineBasicBlock *loop1MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 1209 | MachineBasicBlock *loop2MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 1210 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 1211 | MachineFunction::iterator It = BB; |
| 1212 | ++It; |
| 1213 | MF->insert(It, loop1MBB); |
| 1214 | MF->insert(It, loop2MBB); |
| 1215 | MF->insert(It, exitMBB); |
| 1216 | |
| 1217 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 1218 | exitMBB->splice(exitMBB->begin(), BB, |
Akira Hatanaka | 8209968 | 2011-12-19 19:52:25 +0000 | [diff] [blame] | 1219 | llvm::next(MachineBasicBlock::iterator(MI)), BB->end()); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1220 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 1221 | |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1222 | // thisMBB: |
| 1223 | // ... |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1224 | // fallthrough --> loop1MBB |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1225 | BB->addSuccessor(loop1MBB); |
Akira Hatanaka | 81b4411 | 2011-07-19 17:09:53 +0000 | [diff] [blame] | 1226 | loop1MBB->addSuccessor(exitMBB); |
| 1227 | loop1MBB->addSuccessor(loop2MBB); |
| 1228 | loop2MBB->addSuccessor(loop1MBB); |
| 1229 | loop2MBB->addSuccessor(exitMBB); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1230 | |
| 1231 | // loop1MBB: |
| 1232 | // ll dest, 0(ptr) |
| 1233 | // bne dest, oldval, exitMBB |
| 1234 | BB = loop1MBB; |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1235 | BuildMI(BB, DL, TII->get(LL), Dest).addReg(Ptr).addImm(0); |
| 1236 | BuildMI(BB, DL, TII->get(BNE)) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1237 | .addReg(Dest).addReg(OldVal).addMBB(exitMBB); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1238 | |
| 1239 | // loop2MBB: |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1240 | // sc success, newval, 0(ptr) |
| 1241 | // beq success, $0, loop1MBB |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1242 | BB = loop2MBB; |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1243 | BuildMI(BB, DL, TII->get(SC), Success) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1244 | .addReg(NewVal).addReg(Ptr).addImm(0); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1245 | BuildMI(BB, DL, TII->get(BEQ)) |
Akira Hatanaka | 5906806 | 2011-11-11 04:14:30 +0000 | [diff] [blame] | 1246 | .addReg(Success).addReg(ZERO).addMBB(loop1MBB); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1247 | |
| 1248 | MI->eraseFromParent(); // The instruction is gone now. |
| 1249 | |
Akira Hatanaka | 939ece1 | 2011-07-19 03:42:13 +0000 | [diff] [blame] | 1250 | return exitMBB; |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | MachineBasicBlock * |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1254 | MipsTargetLowering::emitAtomicCmpSwapPartword(MachineInstr *MI, |
Akira Hatanaka | 0f84382 | 2011-06-07 18:58:42 +0000 | [diff] [blame] | 1255 | MachineBasicBlock *BB, |
| 1256 | unsigned Size) const { |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1257 | assert((Size == 1 || Size == 2) && |
| 1258 | "Unsupported size for EmitAtomicCmpSwapPartial."); |
| 1259 | |
| 1260 | MachineFunction *MF = BB->getParent(); |
| 1261 | MachineRegisterInfo &RegInfo = MF->getRegInfo(); |
| 1262 | const TargetRegisterClass *RC = getRegClassFor(MVT::i32); |
| 1263 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1264 | DebugLoc DL = MI->getDebugLoc(); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1265 | |
| 1266 | unsigned Dest = MI->getOperand(0).getReg(); |
| 1267 | unsigned Ptr = MI->getOperand(1).getReg(); |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1268 | unsigned CmpVal = MI->getOperand(2).getReg(); |
| 1269 | unsigned NewVal = MI->getOperand(3).getReg(); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1270 | |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1271 | unsigned AlignedAddr = RegInfo.createVirtualRegister(RC); |
| 1272 | unsigned ShiftAmt = RegInfo.createVirtualRegister(RC); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1273 | unsigned Mask = RegInfo.createVirtualRegister(RC); |
| 1274 | unsigned Mask2 = RegInfo.createVirtualRegister(RC); |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1275 | unsigned ShiftedCmpVal = RegInfo.createVirtualRegister(RC); |
| 1276 | unsigned OldVal = RegInfo.createVirtualRegister(RC); |
| 1277 | unsigned MaskedOldVal0 = RegInfo.createVirtualRegister(RC); |
| 1278 | unsigned ShiftedNewVal = RegInfo.createVirtualRegister(RC); |
| 1279 | unsigned MaskLSB2 = RegInfo.createVirtualRegister(RC); |
| 1280 | unsigned PtrLSB2 = RegInfo.createVirtualRegister(RC); |
| 1281 | unsigned MaskUpper = RegInfo.createVirtualRegister(RC); |
| 1282 | unsigned MaskedCmpVal = RegInfo.createVirtualRegister(RC); |
| 1283 | unsigned MaskedNewVal = RegInfo.createVirtualRegister(RC); |
| 1284 | unsigned MaskedOldVal1 = RegInfo.createVirtualRegister(RC); |
| 1285 | unsigned StoreVal = RegInfo.createVirtualRegister(RC); |
| 1286 | unsigned SrlRes = RegInfo.createVirtualRegister(RC); |
| 1287 | unsigned SllRes = RegInfo.createVirtualRegister(RC); |
| 1288 | unsigned Success = RegInfo.createVirtualRegister(RC); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1289 | |
| 1290 | // insert new blocks after the current block |
| 1291 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 1292 | MachineBasicBlock *loop1MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 1293 | MachineBasicBlock *loop2MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
Akira Hatanaka | 939ece1 | 2011-07-19 03:42:13 +0000 | [diff] [blame] | 1294 | MachineBasicBlock *sinkMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1295 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 1296 | MachineFunction::iterator It = BB; |
| 1297 | ++It; |
| 1298 | MF->insert(It, loop1MBB); |
| 1299 | MF->insert(It, loop2MBB); |
Akira Hatanaka | 939ece1 | 2011-07-19 03:42:13 +0000 | [diff] [blame] | 1300 | MF->insert(It, sinkMBB); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1301 | MF->insert(It, exitMBB); |
| 1302 | |
| 1303 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 1304 | exitMBB->splice(exitMBB->begin(), BB, |
Akira Hatanaka | 8209968 | 2011-12-19 19:52:25 +0000 | [diff] [blame] | 1305 | llvm::next(MachineBasicBlock::iterator(MI)), BB->end()); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1306 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 1307 | |
Akira Hatanaka | 81b4411 | 2011-07-19 17:09:53 +0000 | [diff] [blame] | 1308 | BB->addSuccessor(loop1MBB); |
| 1309 | loop1MBB->addSuccessor(sinkMBB); |
| 1310 | loop1MBB->addSuccessor(loop2MBB); |
| 1311 | loop2MBB->addSuccessor(loop1MBB); |
| 1312 | loop2MBB->addSuccessor(sinkMBB); |
| 1313 | sinkMBB->addSuccessor(exitMBB); |
| 1314 | |
Akira Hatanaka | 70564a9 | 2011-07-19 18:14:26 +0000 | [diff] [blame] | 1315 | // FIXME: computation of newval2 can be moved to loop2MBB. |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1316 | // thisMBB: |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1317 | // addiu masklsb2,$0,-4 # 0xfffffffc |
| 1318 | // and alignedaddr,ptr,masklsb2 |
| 1319 | // andi ptrlsb2,ptr,3 |
| 1320 | // sll shiftamt,ptrlsb2,3 |
| 1321 | // ori maskupper,$0,255 # 0xff |
| 1322 | // sll mask,maskupper,shiftamt |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1323 | // nor mask2,$0,mask |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1324 | // andi maskedcmpval,cmpval,255 |
| 1325 | // sll shiftedcmpval,maskedcmpval,shiftamt |
| 1326 | // andi maskednewval,newval,255 |
| 1327 | // sll shiftednewval,maskednewval,shiftamt |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1328 | int64_t MaskImm = (Size == 1) ? 255 : 65535; |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1329 | BuildMI(BB, DL, TII->get(Mips::ADDiu), MaskLSB2) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1330 | .addReg(Mips::ZERO).addImm(-4); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1331 | BuildMI(BB, DL, TII->get(Mips::AND), AlignedAddr) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1332 | .addReg(Ptr).addReg(MaskLSB2); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1333 | BuildMI(BB, DL, TII->get(Mips::ANDi), PtrLSB2).addReg(Ptr).addImm(3); |
Akira Hatanaka | affed7e | 2013-05-31 03:25:44 +0000 | [diff] [blame] | 1334 | if (Subtarget->isLittle()) { |
| 1335 | BuildMI(BB, DL, TII->get(Mips::SLL), ShiftAmt).addReg(PtrLSB2).addImm(3); |
| 1336 | } else { |
| 1337 | unsigned Off = RegInfo.createVirtualRegister(RC); |
| 1338 | BuildMI(BB, DL, TII->get(Mips::XORi), Off) |
| 1339 | .addReg(PtrLSB2).addImm((Size == 1) ? 3 : 2); |
| 1340 | BuildMI(BB, DL, TII->get(Mips::SLL), ShiftAmt).addReg(Off).addImm(3); |
| 1341 | } |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1342 | BuildMI(BB, DL, TII->get(Mips::ORi), MaskUpper) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1343 | .addReg(Mips::ZERO).addImm(MaskImm); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1344 | BuildMI(BB, DL, TII->get(Mips::SLLV), Mask) |
Akira Hatanaka | 5112243 | 2013-07-01 20:39:53 +0000 | [diff] [blame] | 1345 | .addReg(MaskUpper).addReg(ShiftAmt); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1346 | BuildMI(BB, DL, TII->get(Mips::NOR), Mask2).addReg(Mips::ZERO).addReg(Mask); |
| 1347 | BuildMI(BB, DL, TII->get(Mips::ANDi), MaskedCmpVal) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1348 | .addReg(CmpVal).addImm(MaskImm); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1349 | BuildMI(BB, DL, TII->get(Mips::SLLV), ShiftedCmpVal) |
Akira Hatanaka | 5112243 | 2013-07-01 20:39:53 +0000 | [diff] [blame] | 1350 | .addReg(MaskedCmpVal).addReg(ShiftAmt); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1351 | BuildMI(BB, DL, TII->get(Mips::ANDi), MaskedNewVal) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1352 | .addReg(NewVal).addImm(MaskImm); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1353 | BuildMI(BB, DL, TII->get(Mips::SLLV), ShiftedNewVal) |
Akira Hatanaka | 5112243 | 2013-07-01 20:39:53 +0000 | [diff] [blame] | 1354 | .addReg(MaskedNewVal).addReg(ShiftAmt); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1355 | |
| 1356 | // loop1MBB: |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1357 | // ll oldval,0(alginedaddr) |
| 1358 | // and maskedoldval0,oldval,mask |
| 1359 | // bne maskedoldval0,shiftedcmpval,sinkMBB |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1360 | BB = loop1MBB; |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame] | 1361 | BuildMI(BB, DL, TII->get(Mips::LL), OldVal).addReg(AlignedAddr).addImm(0); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1362 | BuildMI(BB, DL, TII->get(Mips::AND), MaskedOldVal0) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1363 | .addReg(OldVal).addReg(Mask); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1364 | BuildMI(BB, DL, TII->get(Mips::BNE)) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1365 | .addReg(MaskedOldVal0).addReg(ShiftedCmpVal).addMBB(sinkMBB); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1366 | |
| 1367 | // loop2MBB: |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1368 | // and maskedoldval1,oldval,mask2 |
| 1369 | // or storeval,maskedoldval1,shiftednewval |
| 1370 | // sc success,storeval,0(alignedaddr) |
| 1371 | // beq success,$0,loop1MBB |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1372 | BB = loop2MBB; |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1373 | BuildMI(BB, DL, TII->get(Mips::AND), MaskedOldVal1) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1374 | .addReg(OldVal).addReg(Mask2); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1375 | BuildMI(BB, DL, TII->get(Mips::OR), StoreVal) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1376 | .addReg(MaskedOldVal1).addReg(ShiftedNewVal); |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame] | 1377 | BuildMI(BB, DL, TII->get(Mips::SC), Success) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1378 | .addReg(StoreVal).addReg(AlignedAddr).addImm(0); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1379 | BuildMI(BB, DL, TII->get(Mips::BEQ)) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1380 | .addReg(Success).addReg(Mips::ZERO).addMBB(loop1MBB); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1381 | |
Akira Hatanaka | 939ece1 | 2011-07-19 03:42:13 +0000 | [diff] [blame] | 1382 | // sinkMBB: |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1383 | // srl srlres,maskedoldval0,shiftamt |
| 1384 | // sll sllres,srlres,24 |
| 1385 | // sra dest,sllres,24 |
Akira Hatanaka | 939ece1 | 2011-07-19 03:42:13 +0000 | [diff] [blame] | 1386 | BB = sinkMBB; |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1387 | int64_t ShiftImm = (Size == 1) ? 24 : 16; |
Akira Hatanaka | a308c67 | 2011-07-19 03:14:58 +0000 | [diff] [blame] | 1388 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1389 | BuildMI(BB, DL, TII->get(Mips::SRLV), SrlRes) |
Akira Hatanaka | 5112243 | 2013-07-01 20:39:53 +0000 | [diff] [blame] | 1390 | .addReg(MaskedOldVal0).addReg(ShiftAmt); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1391 | BuildMI(BB, DL, TII->get(Mips::SLL), SllRes) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1392 | .addReg(SrlRes).addImm(ShiftImm); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1393 | BuildMI(BB, DL, TII->get(Mips::SRA), Dest) |
Akira Hatanaka | 4061da1 | 2011-07-19 20:11:17 +0000 | [diff] [blame] | 1394 | .addReg(SllRes).addImm(ShiftImm); |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1395 | |
| 1396 | MI->eraseFromParent(); // The instruction is gone now. |
| 1397 | |
Akira Hatanaka | 939ece1 | 2011-07-19 03:42:13 +0000 | [diff] [blame] | 1398 | return exitMBB; |
Bruno Cardoso Lopes | 4e694c9 | 2011-05-31 02:54:07 +0000 | [diff] [blame] | 1399 | } |
| 1400 | |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 1401 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1402 | // Misc Lower Operation implementation |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 1403 | //===----------------------------------------------------------------------===// |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1404 | SDValue MipsTargetLowering::lowerBR_JT(SDValue Op, SelectionDAG &DAG) const { |
Akira Hatanaka | b7656a9 | 2013-03-06 21:32:03 +0000 | [diff] [blame] | 1405 | SDValue Chain = Op.getOperand(0); |
| 1406 | SDValue Table = Op.getOperand(1); |
| 1407 | SDValue Index = Op.getOperand(2); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1408 | SDLoc DL(Op); |
Akira Hatanaka | b7656a9 | 2013-03-06 21:32:03 +0000 | [diff] [blame] | 1409 | EVT PTy = getPointerTy(); |
| 1410 | unsigned EntrySize = |
| 1411 | DAG.getMachineFunction().getJumpTableInfo()->getEntrySize(*getDataLayout()); |
| 1412 | |
| 1413 | Index = DAG.getNode(ISD::MUL, DL, PTy, Index, |
| 1414 | DAG.getConstant(EntrySize, PTy)); |
| 1415 | SDValue Addr = DAG.getNode(ISD::ADD, DL, PTy, Index, Table); |
| 1416 | |
| 1417 | EVT MemVT = EVT::getIntegerVT(*DAG.getContext(), EntrySize * 8); |
| 1418 | Addr = DAG.getExtLoad(ISD::SEXTLOAD, DL, PTy, Chain, Addr, |
| 1419 | MachinePointerInfo::getJumpTable(), MemVT, false, false, |
| 1420 | 0); |
| 1421 | Chain = Addr.getValue(1); |
| 1422 | |
| 1423 | if ((getTargetMachine().getRelocationModel() == Reloc::PIC_) || IsN64) { |
| 1424 | // For PIC, the sequence is: |
| 1425 | // BRIND(load(Jumptable + index) + RelocBase) |
| 1426 | // RelocBase can be JumpTable, GOT or some sort of global base. |
| 1427 | Addr = DAG.getNode(ISD::ADD, DL, PTy, Addr, |
| 1428 | getPICJumpTableRelocBase(Table, DAG)); |
| 1429 | } |
| 1430 | |
| 1431 | return DAG.getNode(ISD::BRIND, DL, MVT::Other, Chain, Addr); |
| 1432 | } |
| 1433 | |
Bruno Cardoso Lopes | d3bdf19 | 2009-05-27 17:23:44 +0000 | [diff] [blame] | 1434 | SDValue MipsTargetLowering:: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1435 | lowerBRCOND(SDValue Op, SelectionDAG &DAG) const |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 1436 | { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1437 | // 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] | 1438 | // the block to branch to if the condition is true. |
| 1439 | SDValue Chain = Op.getOperand(0); |
| 1440 | SDValue Dest = Op.getOperand(2); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1441 | SDLoc DL(Op); |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 1442 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1443 | SDValue CondRes = createFPCmp(DAG, Op.getOperand(1)); |
Akira Hatanaka | 1d6b38d | 2011-03-31 18:26:17 +0000 | [diff] [blame] | 1444 | |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 1445 | // Return if flag is not set by a floating point comparison. |
Akira Hatanaka | 1d6b38d | 2011-03-31 18:26:17 +0000 | [diff] [blame] | 1446 | if (CondRes.getOpcode() != MipsISD::FPCmp) |
Bruno Cardoso Lopes | 4b877ca | 2008-07-30 17:06:13 +0000 | [diff] [blame] | 1447 | return Op; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1448 | |
Bruno Cardoso Lopes | 7728377 | 2008-07-31 18:31:28 +0000 | [diff] [blame] | 1449 | SDValue CCNode = CondRes.getOperand(2); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1450 | Mips::CondCode CC = |
| 1451 | (Mips::CondCode)cast<ConstantSDNode>(CCNode)->getZExtValue(); |
Akira Hatanaka | 9cf0724 | 2013-03-30 01:16:38 +0000 | [diff] [blame] | 1452 | unsigned Opc = invertFPCondCodeUser(CC) ? Mips::BRANCH_F : Mips::BRANCH_T; |
| 1453 | SDValue BrCode = DAG.getConstant(Opc, MVT::i32); |
Akira Hatanaka | 83d8ef1 | 2013-07-26 20:13:47 +0000 | [diff] [blame] | 1454 | SDValue FCC0 = DAG.getRegister(Mips::FCC0, MVT::i32); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1455 | return DAG.getNode(MipsISD::FPBrcond, DL, Op.getValueType(), Chain, BrCode, |
Akira Hatanaka | 83d8ef1 | 2013-07-26 20:13:47 +0000 | [diff] [blame] | 1456 | FCC0, Dest, CondRes); |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 1457 | } |
| 1458 | |
| 1459 | SDValue MipsTargetLowering:: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1460 | lowerSELECT(SDValue Op, SelectionDAG &DAG) const |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 1461 | { |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1462 | SDValue Cond = createFPCmp(DAG, Op.getOperand(0)); |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 1463 | |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 1464 | // Return if flag is not set by a floating point comparison. |
Akira Hatanaka | 1d6b38d | 2011-03-31 18:26:17 +0000 | [diff] [blame] | 1465 | if (Cond.getOpcode() != MipsISD::FPCmp) |
| 1466 | return Op; |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 1467 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1468 | return createCMovFP(DAG, Cond, Op.getOperand(1), Op.getOperand(2), |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1469 | SDLoc(Op)); |
Bruno Cardoso Lopes | 6d399bd | 2008-07-29 19:05:28 +0000 | [diff] [blame] | 1470 | } |
| 1471 | |
Akira Hatanaka | 3fef29d | 2012-07-11 19:32:27 +0000 | [diff] [blame] | 1472 | SDValue MipsTargetLowering:: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1473 | lowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const |
Akira Hatanaka | 3fef29d | 2012-07-11 19:32:27 +0000 | [diff] [blame] | 1474 | { |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1475 | SDLoc DL(Op); |
Akira Hatanaka | 3fef29d | 2012-07-11 19:32:27 +0000 | [diff] [blame] | 1476 | EVT Ty = Op.getOperand(0).getValueType(); |
Matt Arsenault | 225ed70 | 2013-05-18 00:21:46 +0000 | [diff] [blame] | 1477 | SDValue Cond = DAG.getNode(ISD::SETCC, DL, |
| 1478 | getSetCCResultType(*DAG.getContext(), Ty), |
Akira Hatanaka | 3fef29d | 2012-07-11 19:32:27 +0000 | [diff] [blame] | 1479 | Op.getOperand(0), Op.getOperand(1), |
| 1480 | Op.getOperand(4)); |
| 1481 | |
| 1482 | return DAG.getNode(ISD::SELECT, DL, Op.getValueType(), Cond, Op.getOperand(2), |
| 1483 | Op.getOperand(3)); |
| 1484 | } |
| 1485 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1486 | SDValue MipsTargetLowering::lowerSETCC(SDValue Op, SelectionDAG &DAG) const { |
| 1487 | SDValue Cond = createFPCmp(DAG, Op); |
Akira Hatanaka | 0a40c23 | 2012-03-09 23:46:03 +0000 | [diff] [blame] | 1488 | |
| 1489 | assert(Cond.getOpcode() == MipsISD::FPCmp && |
| 1490 | "Floating point operand expected."); |
| 1491 | |
| 1492 | SDValue True = DAG.getConstant(1, MVT::i32); |
| 1493 | SDValue False = DAG.getConstant(0, MVT::i32); |
| 1494 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1495 | return createCMovFP(DAG, Cond, True, False, SDLoc(Op)); |
Akira Hatanaka | 0a40c23 | 2012-03-09 23:46:03 +0000 | [diff] [blame] | 1496 | } |
| 1497 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1498 | SDValue MipsTargetLowering::lowerGlobalAddress(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1499 | SelectionDAG &DAG) const { |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 1500 | // FIXME there isn't actually debug info here |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1501 | SDLoc DL(Op); |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 1502 | EVT Ty = Op.getValueType(); |
| 1503 | GlobalAddressSDNode *N = cast<GlobalAddressSDNode>(Op); |
| 1504 | const GlobalValue *GV = N->getGlobal(); |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 1505 | |
Akira Hatanaka | a5903ac | 2011-10-11 00:55:05 +0000 | [diff] [blame] | 1506 | if (getTargetMachine().getRelocationModel() != Reloc::PIC_ && !IsN64) { |
Akira Hatanaka | afc945b | 2012-09-12 23:27:55 +0000 | [diff] [blame] | 1507 | const MipsTargetObjectFile &TLOF = |
| 1508 | (const MipsTargetObjectFile&)getObjFileLowering(); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1509 | |
Chris Lattner | e3736f8 | 2009-08-13 05:41:27 +0000 | [diff] [blame] | 1510 | // %gp_rel relocation |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1511 | if (TLOF.IsGlobalInSmallSection(GV, getTargetMachine())) { |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1512 | SDValue GA = DAG.getTargetGlobalAddress(GV, DL, MVT::i32, 0, |
Bruno Cardoso Lopes | c517cb0 | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 1513 | MipsII::MO_GPREL); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1514 | SDValue GPRelNode = DAG.getNode(MipsISD::GPRel, DL, |
Akira Hatanaka | d43e06d | 2012-11-21 20:30:40 +0000 | [diff] [blame] | 1515 | DAG.getVTList(MVT::i32), &GA, 1); |
Akira Hatanaka | e7338cd | 2012-08-22 03:18:13 +0000 | [diff] [blame] | 1516 | SDValue GPReg = DAG.getRegister(Mips::GP, MVT::i32); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1517 | return DAG.getNode(ISD::ADD, DL, MVT::i32, GPReg, GPRelNode); |
Chris Lattner | e3736f8 | 2009-08-13 05:41:27 +0000 | [diff] [blame] | 1518 | } |
Akira Hatanaka | d43e06d | 2012-11-21 20:30:40 +0000 | [diff] [blame] | 1519 | |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 1520 | // %hi/%lo relocation |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 1521 | return getAddrNonPIC(N, Ty, DAG); |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 1522 | } |
| 1523 | |
Akira Hatanaka | d43e06d | 2012-11-21 20:30:40 +0000 | [diff] [blame] | 1524 | if (GV->hasInternalLinkage() || (GV->hasLocalLinkage() && !isa<Function>(GV))) |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 1525 | return getAddrLocal(N, Ty, DAG, HasMips64); |
Akira Hatanaka | d43e06d | 2012-11-21 20:30:40 +0000 | [diff] [blame] | 1526 | |
Akira Hatanaka | f09a037 | 2012-11-21 20:40:38 +0000 | [diff] [blame] | 1527 | if (LargeGOT) |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 1528 | return getAddrGlobalLargeGOT(N, Ty, DAG, MipsII::MO_GOT_HI16, |
Akira Hatanaka | f09a037 | 2012-11-21 20:40:38 +0000 | [diff] [blame] | 1529 | MipsII::MO_GOT_LO16); |
| 1530 | |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 1531 | return getAddrGlobal(N, Ty, DAG, |
Akira Hatanaka | d43e06d | 2012-11-21 20:30:40 +0000 | [diff] [blame] | 1532 | HasMips64 ? MipsII::MO_GOT_DISP : MipsII::MO_GOT16); |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 1533 | } |
| 1534 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1535 | SDValue MipsTargetLowering::lowerBlockAddress(SDValue Op, |
Bruno Cardoso Lopes | ca8a2aa | 2011-03-04 20:01:52 +0000 | [diff] [blame] | 1536 | SelectionDAG &DAG) const { |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 1537 | BlockAddressSDNode *N = cast<BlockAddressSDNode>(Op); |
| 1538 | EVT Ty = Op.getValueType(); |
Akira Hatanaka | f48eb53 | 2011-04-25 17:10:45 +0000 | [diff] [blame] | 1539 | |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 1540 | if (getTargetMachine().getRelocationModel() != Reloc::PIC_ && !IsN64) |
| 1541 | return getAddrNonPIC(N, Ty, DAG); |
| 1542 | |
| 1543 | return getAddrLocal(N, Ty, DAG, HasMips64); |
Bruno Cardoso Lopes | ca8a2aa | 2011-03-04 20:01:52 +0000 | [diff] [blame] | 1544 | } |
| 1545 | |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 1546 | SDValue MipsTargetLowering:: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1547 | lowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 1548 | { |
Akira Hatanaka | 3faac0a | 2011-12-14 18:26:41 +0000 | [diff] [blame] | 1549 | // If the relocation model is PIC, use the General Dynamic TLS Model or |
| 1550 | // Local Dynamic TLS model, otherwise use the Initial Exec or |
| 1551 | // Local Exec TLS Model. |
Bruno Cardoso Lopes | d979686 | 2011-05-31 02:53:58 +0000 | [diff] [blame] | 1552 | |
| 1553 | GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1554 | SDLoc DL(GA); |
Bruno Cardoso Lopes | d979686 | 2011-05-31 02:53:58 +0000 | [diff] [blame] | 1555 | const GlobalValue *GV = GA->getGlobal(); |
| 1556 | EVT PtrVT = getPointerTy(); |
| 1557 | |
Hans Wennborg | fd5abd5 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 1558 | TLSModel::Model model = getTargetMachine().getTLSModel(GV); |
| 1559 | |
| 1560 | if (model == TLSModel::GeneralDynamic || model == TLSModel::LocalDynamic) { |
Hans Wennborg | 70a07c7 | 2012-06-04 14:02:08 +0000 | [diff] [blame] | 1561 | // General Dynamic and Local Dynamic TLS Model. |
| 1562 | unsigned Flag = (model == TLSModel::LocalDynamic) ? MipsII::MO_TLSLDM |
| 1563 | : MipsII::MO_TLSGD; |
| 1564 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1565 | SDValue TGA = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, Flag); |
| 1566 | SDValue Argument = DAG.getNode(MipsISD::Wrapper, DL, PtrVT, |
| 1567 | getGlobalReg(DAG, PtrVT), TGA); |
Akira Hatanaka | 7a7194b | 2011-12-08 21:05:38 +0000 | [diff] [blame] | 1568 | unsigned PtrSize = PtrVT.getSizeInBits(); |
| 1569 | IntegerType *PtrTy = Type::getIntNTy(*DAG.getContext(), PtrSize); |
| 1570 | |
Benjamin Kramer | 5eccf67 | 2011-12-11 12:21:34 +0000 | [diff] [blame] | 1571 | SDValue TlsGetAddr = DAG.getExternalSymbol("__tls_get_addr", PtrVT); |
Bruno Cardoso Lopes | d979686 | 2011-05-31 02:53:58 +0000 | [diff] [blame] | 1572 | |
| 1573 | ArgListTy Args; |
| 1574 | ArgListEntry Entry; |
| 1575 | Entry.Node = Argument; |
Akira Hatanaka | ca07479 | 2011-12-08 20:34:32 +0000 | [diff] [blame] | 1576 | Entry.Ty = PtrTy; |
Bruno Cardoso Lopes | d979686 | 2011-05-31 02:53:58 +0000 | [diff] [blame] | 1577 | Args.push_back(Entry); |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 1578 | |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 1579 | TargetLowering::CallLoweringInfo CLI(DAG.getEntryNode(), PtrTy, |
Evan Cheng | 4bfcd4a | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 1580 | false, false, false, false, 0, CallingConv::C, |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1581 | /*IsTailCall=*/false, /*doesNotRet=*/false, |
Evan Cheng | 4bfcd4a | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 1582 | /*isReturnValueUsed=*/true, |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1583 | TlsGetAddr, Args, DAG, DL); |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 1584 | std::pair<SDValue, SDValue> CallResult = LowerCallTo(CLI); |
Bruno Cardoso Lopes | d979686 | 2011-05-31 02:53:58 +0000 | [diff] [blame] | 1585 | |
Akira Hatanaka | 3faac0a | 2011-12-14 18:26:41 +0000 | [diff] [blame] | 1586 | SDValue Ret = CallResult.first; |
| 1587 | |
Hans Wennborg | fd5abd5 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 1588 | if (model != TLSModel::LocalDynamic) |
Akira Hatanaka | 3faac0a | 2011-12-14 18:26:41 +0000 | [diff] [blame] | 1589 | return Ret; |
| 1590 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1591 | SDValue TGAHi = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, |
Akira Hatanaka | 3faac0a | 2011-12-14 18:26:41 +0000 | [diff] [blame] | 1592 | MipsII::MO_DTPREL_HI); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1593 | SDValue Hi = DAG.getNode(MipsISD::Hi, DL, PtrVT, TGAHi); |
| 1594 | SDValue TGALo = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, |
Akira Hatanaka | 3faac0a | 2011-12-14 18:26:41 +0000 | [diff] [blame] | 1595 | MipsII::MO_DTPREL_LO); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1596 | SDValue Lo = DAG.getNode(MipsISD::Lo, DL, PtrVT, TGALo); |
| 1597 | SDValue Add = DAG.getNode(ISD::ADD, DL, PtrVT, Hi, Ret); |
| 1598 | return DAG.getNode(ISD::ADD, DL, PtrVT, Add, Lo); |
Bruno Cardoso Lopes | d979686 | 2011-05-31 02:53:58 +0000 | [diff] [blame] | 1599 | } |
Akira Hatanaka | 5f7451f | 2011-06-21 01:02:03 +0000 | [diff] [blame] | 1600 | |
| 1601 | SDValue Offset; |
Hans Wennborg | fd5abd5 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 1602 | if (model == TLSModel::InitialExec) { |
Akira Hatanaka | 5f7451f | 2011-06-21 01:02:03 +0000 | [diff] [blame] | 1603 | // Initial Exec TLS Model |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1604 | SDValue TGA = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, |
Akira Hatanaka | 5f7451f | 2011-06-21 01:02:03 +0000 | [diff] [blame] | 1605 | MipsII::MO_GOTTPREL); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1606 | TGA = DAG.getNode(MipsISD::Wrapper, DL, PtrVT, getGlobalReg(DAG, PtrVT), |
Akira Hatanaka | 648f00c | 2012-02-24 22:34:47 +0000 | [diff] [blame] | 1607 | TGA); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1608 | Offset = DAG.getLoad(PtrVT, DL, |
Akira Hatanaka | 5f7451f | 2011-06-21 01:02:03 +0000 | [diff] [blame] | 1609 | DAG.getEntryNode(), TGA, MachinePointerInfo(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1610 | false, false, false, 0); |
Akira Hatanaka | 5f7451f | 2011-06-21 01:02:03 +0000 | [diff] [blame] | 1611 | } else { |
| 1612 | // Local Exec TLS Model |
Hans Wennborg | fd5abd5 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 1613 | assert(model == TLSModel::LocalExec); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1614 | SDValue TGAHi = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, |
Akira Hatanaka | 5f7451f | 2011-06-21 01:02:03 +0000 | [diff] [blame] | 1615 | MipsII::MO_TPREL_HI); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1616 | SDValue TGALo = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, |
Akira Hatanaka | 5f7451f | 2011-06-21 01:02:03 +0000 | [diff] [blame] | 1617 | MipsII::MO_TPREL_LO); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1618 | SDValue Hi = DAG.getNode(MipsISD::Hi, DL, PtrVT, TGAHi); |
| 1619 | SDValue Lo = DAG.getNode(MipsISD::Lo, DL, PtrVT, TGALo); |
| 1620 | Offset = DAG.getNode(ISD::ADD, DL, PtrVT, Hi, Lo); |
Akira Hatanaka | 5f7451f | 2011-06-21 01:02:03 +0000 | [diff] [blame] | 1621 | } |
| 1622 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1623 | SDValue ThreadPointer = DAG.getNode(MipsISD::ThreadPointer, DL, PtrVT); |
| 1624 | return DAG.getNode(ISD::ADD, DL, PtrVT, ThreadPointer, Offset); |
Bruno Cardoso Lopes | 97843cd | 2008-07-29 19:29:50 +0000 | [diff] [blame] | 1625 | } |
| 1626 | |
| 1627 | SDValue MipsTargetLowering:: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1628 | lowerJumpTable(SDValue Op, SelectionDAG &DAG) const |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 1629 | { |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 1630 | JumpTableSDNode *N = cast<JumpTableSDNode>(Op); |
| 1631 | EVT Ty = Op.getValueType(); |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 1632 | |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 1633 | if (getTargetMachine().getRelocationModel() != Reloc::PIC_ && !IsN64) |
| 1634 | return getAddrNonPIC(N, Ty, DAG); |
| 1635 | |
| 1636 | return getAddrLocal(N, Ty, DAG, HasMips64); |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 1637 | } |
| 1638 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1639 | SDValue MipsTargetLowering:: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1640 | lowerConstantPool(SDValue Op, SelectionDAG &DAG) const |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 1641 | { |
Bruno Cardoso Lopes | 92e87f2 | 2008-07-23 16:01:50 +0000 | [diff] [blame] | 1642 | // gp_rel relocation |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1643 | // FIXME: we should reference the constant pool using small data sections, |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 1644 | // but the asm printer currently doesn't support this feature without |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1645 | // 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] | 1646 | // stuff below. |
Eli Friedman | e2c7408 | 2009-08-03 02:22:28 +0000 | [diff] [blame] | 1647 | //if (IsInSmallSection(C->getType())) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1648 | // SDValue GPRelNode = DAG.getNode(MipsISD::GPRel, MVT::i32, CP); |
| 1649 | // SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(MVT::i32); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1650 | // ResNode = DAG.getNode(ISD::ADD, MVT::i32, GOT, GPRelNode); |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 1651 | ConstantPoolSDNode *N = cast<ConstantPoolSDNode>(Op); |
| 1652 | EVT Ty = Op.getValueType(); |
Bruno Cardoso Lopes | d71cebf | 2009-11-25 12:17:58 +0000 | [diff] [blame] | 1653 | |
Akira Hatanaka | d43e06d | 2012-11-21 20:30:40 +0000 | [diff] [blame] | 1654 | if (getTargetMachine().getRelocationModel() != Reloc::PIC_ && !IsN64) |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 1655 | return getAddrNonPIC(N, Ty, DAG); |
Bruno Cardoso Lopes | 92e87f2 | 2008-07-23 16:01:50 +0000 | [diff] [blame] | 1656 | |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 1657 | return getAddrLocal(N, Ty, DAG, HasMips64); |
Bruno Cardoso Lopes | 97c2537 | 2008-07-09 04:15:08 +0000 | [diff] [blame] | 1658 | } |
| 1659 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1660 | SDValue MipsTargetLowering::lowerVASTART(SDValue Op, SelectionDAG &DAG) const { |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 1661 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1662 | MipsFunctionInfo *FuncInfo = MF.getInfo<MipsFunctionInfo>(); |
| 1663 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1664 | SDLoc DL(Op); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 1665 | SDValue FI = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), |
| 1666 | getPointerTy()); |
Bruno Cardoso Lopes | 6059b85 | 2010-02-06 21:00:02 +0000 | [diff] [blame] | 1667 | |
| 1668 | // vastart just stores the address of the VarArgsFrameIndex slot into the |
| 1669 | // memory location argument. |
| 1670 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1671 | return DAG.getStore(Op.getOperand(0), DL, FI, Op.getOperand(1), |
Akira Hatanaka | 8209968 | 2011-12-19 19:52:25 +0000 | [diff] [blame] | 1672 | MachinePointerInfo(SV), false, false, 0); |
Bruno Cardoso Lopes | 6059b85 | 2010-02-06 21:00:02 +0000 | [diff] [blame] | 1673 | } |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 1674 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1675 | static SDValue lowerFCOPYSIGN32(SDValue Op, SelectionDAG &DAG, bool HasR2) { |
Akira Hatanaka | 056c51e | 2012-04-11 22:13:04 +0000 | [diff] [blame] | 1676 | EVT TyX = Op.getOperand(0).getValueType(); |
| 1677 | EVT TyY = Op.getOperand(1).getValueType(); |
| 1678 | SDValue Const1 = DAG.getConstant(1, MVT::i32); |
| 1679 | SDValue Const31 = DAG.getConstant(31, MVT::i32); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1680 | SDLoc DL(Op); |
Akira Hatanaka | 056c51e | 2012-04-11 22:13:04 +0000 | [diff] [blame] | 1681 | SDValue Res; |
| 1682 | |
| 1683 | // If operand is of type f64, extract the upper 32-bit. Otherwise, bitcast it |
| 1684 | // to i32. |
| 1685 | SDValue X = (TyX == MVT::f32) ? |
| 1686 | DAG.getNode(ISD::BITCAST, DL, MVT::i32, Op.getOperand(0)) : |
| 1687 | DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, Op.getOperand(0), |
| 1688 | Const1); |
| 1689 | SDValue Y = (TyY == MVT::f32) ? |
| 1690 | DAG.getNode(ISD::BITCAST, DL, MVT::i32, Op.getOperand(1)) : |
| 1691 | DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, Op.getOperand(1), |
| 1692 | Const1); |
| 1693 | |
| 1694 | if (HasR2) { |
| 1695 | // ext E, Y, 31, 1 ; extract bit31 of Y |
| 1696 | // ins X, E, 31, 1 ; insert extracted bit at bit31 of X |
| 1697 | SDValue E = DAG.getNode(MipsISD::Ext, DL, MVT::i32, Y, Const31, Const1); |
| 1698 | Res = DAG.getNode(MipsISD::Ins, DL, MVT::i32, E, Const31, Const1, X); |
| 1699 | } else { |
| 1700 | // sll SllX, X, 1 |
| 1701 | // srl SrlX, SllX, 1 |
| 1702 | // srl SrlY, Y, 31 |
| 1703 | // sll SllY, SrlX, 31 |
| 1704 | // or Or, SrlX, SllY |
| 1705 | SDValue SllX = DAG.getNode(ISD::SHL, DL, MVT::i32, X, Const1); |
| 1706 | SDValue SrlX = DAG.getNode(ISD::SRL, DL, MVT::i32, SllX, Const1); |
| 1707 | SDValue SrlY = DAG.getNode(ISD::SRL, DL, MVT::i32, Y, Const31); |
| 1708 | SDValue SllY = DAG.getNode(ISD::SHL, DL, MVT::i32, SrlY, Const31); |
| 1709 | Res = DAG.getNode(ISD::OR, DL, MVT::i32, SrlX, SllY); |
| 1710 | } |
| 1711 | |
| 1712 | if (TyX == MVT::f32) |
| 1713 | return DAG.getNode(ISD::BITCAST, DL, Op.getOperand(0).getValueType(), Res); |
| 1714 | |
| 1715 | SDValue LowX = DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, |
| 1716 | Op.getOperand(0), DAG.getConstant(0, MVT::i32)); |
| 1717 | return DAG.getNode(MipsISD::BuildPairF64, DL, MVT::f64, LowX, Res); |
Akira Hatanaka | 9c3d57c | 2011-05-25 19:32:07 +0000 | [diff] [blame] | 1718 | } |
| 1719 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1720 | static SDValue lowerFCOPYSIGN64(SDValue Op, SelectionDAG &DAG, bool HasR2) { |
Akira Hatanaka | 056c51e | 2012-04-11 22:13:04 +0000 | [diff] [blame] | 1721 | unsigned WidthX = Op.getOperand(0).getValueSizeInBits(); |
| 1722 | unsigned WidthY = Op.getOperand(1).getValueSizeInBits(); |
| 1723 | EVT TyX = MVT::getIntegerVT(WidthX), TyY = MVT::getIntegerVT(WidthY); |
| 1724 | SDValue Const1 = DAG.getConstant(1, MVT::i32); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1725 | SDLoc DL(Op); |
Eric Christopher | 471e422 | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 1726 | |
Akira Hatanaka | 056c51e | 2012-04-11 22:13:04 +0000 | [diff] [blame] | 1727 | // Bitcast to integer nodes. |
| 1728 | SDValue X = DAG.getNode(ISD::BITCAST, DL, TyX, Op.getOperand(0)); |
| 1729 | SDValue Y = DAG.getNode(ISD::BITCAST, DL, TyY, Op.getOperand(1)); |
Akira Hatanaka | 9c3d57c | 2011-05-25 19:32:07 +0000 | [diff] [blame] | 1730 | |
Akira Hatanaka | 056c51e | 2012-04-11 22:13:04 +0000 | [diff] [blame] | 1731 | if (HasR2) { |
| 1732 | // ext E, Y, width(Y) - 1, 1 ; extract bit width(Y)-1 of Y |
| 1733 | // ins X, E, width(X) - 1, 1 ; insert extracted bit at bit width(X)-1 of X |
| 1734 | SDValue E = DAG.getNode(MipsISD::Ext, DL, TyY, Y, |
| 1735 | DAG.getConstant(WidthY - 1, MVT::i32), Const1); |
Akira Hatanaka | 9c3d57c | 2011-05-25 19:32:07 +0000 | [diff] [blame] | 1736 | |
Akira Hatanaka | 056c51e | 2012-04-11 22:13:04 +0000 | [diff] [blame] | 1737 | if (WidthX > WidthY) |
| 1738 | E = DAG.getNode(ISD::ZERO_EXTEND, DL, TyX, E); |
| 1739 | else if (WidthY > WidthX) |
| 1740 | E = DAG.getNode(ISD::TRUNCATE, DL, TyX, E); |
Akira Hatanaka | 9c3d57c | 2011-05-25 19:32:07 +0000 | [diff] [blame] | 1741 | |
Akira Hatanaka | 056c51e | 2012-04-11 22:13:04 +0000 | [diff] [blame] | 1742 | SDValue I = DAG.getNode(MipsISD::Ins, DL, TyX, E, |
| 1743 | DAG.getConstant(WidthX - 1, MVT::i32), Const1, X); |
| 1744 | return DAG.getNode(ISD::BITCAST, DL, Op.getOperand(0).getValueType(), I); |
| 1745 | } |
| 1746 | |
| 1747 | // (d)sll SllX, X, 1 |
| 1748 | // (d)srl SrlX, SllX, 1 |
| 1749 | // (d)srl SrlY, Y, width(Y)-1 |
| 1750 | // (d)sll SllY, SrlX, width(Y)-1 |
| 1751 | // or Or, SrlX, SllY |
| 1752 | SDValue SllX = DAG.getNode(ISD::SHL, DL, TyX, X, Const1); |
| 1753 | SDValue SrlX = DAG.getNode(ISD::SRL, DL, TyX, SllX, Const1); |
| 1754 | SDValue SrlY = DAG.getNode(ISD::SRL, DL, TyY, Y, |
| 1755 | DAG.getConstant(WidthY - 1, MVT::i32)); |
| 1756 | |
| 1757 | if (WidthX > WidthY) |
| 1758 | SrlY = DAG.getNode(ISD::ZERO_EXTEND, DL, TyX, SrlY); |
| 1759 | else if (WidthY > WidthX) |
| 1760 | SrlY = DAG.getNode(ISD::TRUNCATE, DL, TyX, SrlY); |
| 1761 | |
| 1762 | SDValue SllY = DAG.getNode(ISD::SHL, DL, TyX, SrlY, |
| 1763 | DAG.getConstant(WidthX - 1, MVT::i32)); |
| 1764 | SDValue Or = DAG.getNode(ISD::OR, DL, TyX, SrlX, SllY); |
| 1765 | return DAG.getNode(ISD::BITCAST, DL, Op.getOperand(0).getValueType(), Or); |
Akira Hatanaka | 9c3d57c | 2011-05-25 19:32:07 +0000 | [diff] [blame] | 1766 | } |
| 1767 | |
Akira Hatanaka | 8209968 | 2011-12-19 19:52:25 +0000 | [diff] [blame] | 1768 | SDValue |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1769 | MipsTargetLowering::lowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const { |
Akira Hatanaka | 056c51e | 2012-04-11 22:13:04 +0000 | [diff] [blame] | 1770 | if (Subtarget->hasMips64()) |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1771 | return lowerFCOPYSIGN64(Op, DAG, Subtarget->hasMips32r2()); |
Akira Hatanaka | 9c3d57c | 2011-05-25 19:32:07 +0000 | [diff] [blame] | 1772 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1773 | return lowerFCOPYSIGN32(Op, DAG, Subtarget->hasMips32r2()); |
Akira Hatanaka | 9c3d57c | 2011-05-25 19:32:07 +0000 | [diff] [blame] | 1774 | } |
| 1775 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1776 | static SDValue lowerFABS32(SDValue Op, SelectionDAG &DAG, bool HasR2) { |
Akira Hatanaka | c12a6e6 | 2012-04-11 22:49:04 +0000 | [diff] [blame] | 1777 | SDValue Res, Const1 = DAG.getConstant(1, MVT::i32); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1778 | SDLoc DL(Op); |
Akira Hatanaka | c12a6e6 | 2012-04-11 22:49:04 +0000 | [diff] [blame] | 1779 | |
| 1780 | // If operand is of type f64, extract the upper 32-bit. Otherwise, bitcast it |
| 1781 | // to i32. |
| 1782 | SDValue X = (Op.getValueType() == MVT::f32) ? |
| 1783 | DAG.getNode(ISD::BITCAST, DL, MVT::i32, Op.getOperand(0)) : |
| 1784 | DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, Op.getOperand(0), |
| 1785 | Const1); |
| 1786 | |
| 1787 | // Clear MSB. |
| 1788 | if (HasR2) |
| 1789 | Res = DAG.getNode(MipsISD::Ins, DL, MVT::i32, |
| 1790 | DAG.getRegister(Mips::ZERO, MVT::i32), |
| 1791 | DAG.getConstant(31, MVT::i32), Const1, X); |
| 1792 | else { |
| 1793 | SDValue SllX = DAG.getNode(ISD::SHL, DL, MVT::i32, X, Const1); |
| 1794 | Res = DAG.getNode(ISD::SRL, DL, MVT::i32, SllX, Const1); |
| 1795 | } |
| 1796 | |
| 1797 | if (Op.getValueType() == MVT::f32) |
| 1798 | return DAG.getNode(ISD::BITCAST, DL, MVT::f32, Res); |
| 1799 | |
| 1800 | SDValue LowX = DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, |
| 1801 | Op.getOperand(0), DAG.getConstant(0, MVT::i32)); |
| 1802 | return DAG.getNode(MipsISD::BuildPairF64, DL, MVT::f64, LowX, Res); |
| 1803 | } |
| 1804 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1805 | static SDValue lowerFABS64(SDValue Op, SelectionDAG &DAG, bool HasR2) { |
Akira Hatanaka | c12a6e6 | 2012-04-11 22:49:04 +0000 | [diff] [blame] | 1806 | SDValue Res, Const1 = DAG.getConstant(1, MVT::i32); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1807 | SDLoc DL(Op); |
Akira Hatanaka | c12a6e6 | 2012-04-11 22:49:04 +0000 | [diff] [blame] | 1808 | |
| 1809 | // Bitcast to integer node. |
| 1810 | SDValue X = DAG.getNode(ISD::BITCAST, DL, MVT::i64, Op.getOperand(0)); |
| 1811 | |
| 1812 | // Clear MSB. |
| 1813 | if (HasR2) |
| 1814 | Res = DAG.getNode(MipsISD::Ins, DL, MVT::i64, |
| 1815 | DAG.getRegister(Mips::ZERO_64, MVT::i64), |
| 1816 | DAG.getConstant(63, MVT::i32), Const1, X); |
| 1817 | else { |
| 1818 | SDValue SllX = DAG.getNode(ISD::SHL, DL, MVT::i64, X, Const1); |
| 1819 | Res = DAG.getNode(ISD::SRL, DL, MVT::i64, SllX, Const1); |
| 1820 | } |
| 1821 | |
| 1822 | return DAG.getNode(ISD::BITCAST, DL, MVT::f64, Res); |
| 1823 | } |
| 1824 | |
| 1825 | SDValue |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1826 | MipsTargetLowering::lowerFABS(SDValue Op, SelectionDAG &DAG) const { |
Akira Hatanaka | c12a6e6 | 2012-04-11 22:49:04 +0000 | [diff] [blame] | 1827 | if (Subtarget->hasMips64() && (Op.getValueType() == MVT::f64)) |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1828 | return lowerFABS64(Op, DAG, Subtarget->hasMips32r2()); |
Akira Hatanaka | c12a6e6 | 2012-04-11 22:49:04 +0000 | [diff] [blame] | 1829 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1830 | return lowerFABS32(Op, DAG, Subtarget->hasMips32r2()); |
Akira Hatanaka | c12a6e6 | 2012-04-11 22:49:04 +0000 | [diff] [blame] | 1831 | } |
| 1832 | |
Akira Hatanaka | 2e59147 | 2011-06-02 00:24:44 +0000 | [diff] [blame] | 1833 | SDValue MipsTargetLowering:: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1834 | lowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const { |
Bruno Cardoso Lopes | e0b5cfc | 2011-06-16 00:40:02 +0000 | [diff] [blame] | 1835 | // check the depth |
| 1836 | assert((cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue() == 0) && |
Akira Hatanaka | 0f84382 | 2011-06-07 18:58:42 +0000 | [diff] [blame] | 1837 | "Frame address can only be determined for current frame."); |
Akira Hatanaka | 2e59147 | 2011-06-02 00:24:44 +0000 | [diff] [blame] | 1838 | |
| 1839 | MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); |
| 1840 | MFI->setFrameAddressIsTaken(true); |
| 1841 | EVT VT = Op.getValueType(); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1842 | SDLoc DL(Op); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1843 | SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), DL, |
Akira Hatanaka | 46ac439 | 2011-11-11 04:11:56 +0000 | [diff] [blame] | 1844 | IsN64 ? Mips::FP_64 : Mips::FP, VT); |
Akira Hatanaka | 2e59147 | 2011-06-02 00:24:44 +0000 | [diff] [blame] | 1845 | return FrameAddr; |
| 1846 | } |
| 1847 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1848 | SDValue MipsTargetLowering::lowerRETURNADDR(SDValue Op, |
Akira Hatanaka | ba584fe | 2012-07-11 00:53:32 +0000 | [diff] [blame] | 1849 | SelectionDAG &DAG) const { |
| 1850 | // check the depth |
| 1851 | assert((cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue() == 0) && |
| 1852 | "Return address can be determined only for current frame."); |
| 1853 | |
| 1854 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1855 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Patrik Hagglund | a61b17c | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 1856 | MVT VT = Op.getSimpleValueType(); |
Akira Hatanaka | ba584fe | 2012-07-11 00:53:32 +0000 | [diff] [blame] | 1857 | unsigned RA = IsN64 ? Mips::RA_64 : Mips::RA; |
| 1858 | MFI->setReturnAddressIsTaken(true); |
| 1859 | |
| 1860 | // Return RA, which contains the return address. Mark it an implicit live-in. |
| 1861 | unsigned Reg = MF.addLiveIn(RA, getRegClassFor(VT)); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1862 | return DAG.getCopyFromReg(DAG.getEntryNode(), SDLoc(Op), Reg, VT); |
Akira Hatanaka | ba584fe | 2012-07-11 00:53:32 +0000 | [diff] [blame] | 1863 | } |
| 1864 | |
Akira Hatanaka | 544cc21 | 2013-01-30 00:26:49 +0000 | [diff] [blame] | 1865 | // An EH_RETURN is the result of lowering llvm.eh.return which in turn is |
| 1866 | // generated from __builtin_eh_return (offset, handler) |
| 1867 | // The effect of this is to adjust the stack pointer by "offset" |
| 1868 | // and then branch to "handler". |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1869 | SDValue MipsTargetLowering::lowerEH_RETURN(SDValue Op, SelectionDAG &DAG) |
Akira Hatanaka | 544cc21 | 2013-01-30 00:26:49 +0000 | [diff] [blame] | 1870 | const { |
| 1871 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1872 | MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>(); |
| 1873 | |
| 1874 | MipsFI->setCallsEhReturn(); |
| 1875 | SDValue Chain = Op.getOperand(0); |
| 1876 | SDValue Offset = Op.getOperand(1); |
| 1877 | SDValue Handler = Op.getOperand(2); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1878 | SDLoc DL(Op); |
Akira Hatanaka | 544cc21 | 2013-01-30 00:26:49 +0000 | [diff] [blame] | 1879 | EVT Ty = IsN64 ? MVT::i64 : MVT::i32; |
| 1880 | |
| 1881 | // Store stack offset in V1, store jump target in V0. Glue CopyToReg and |
| 1882 | // EH_RETURN nodes, so that instructions are emitted back-to-back. |
| 1883 | unsigned OffsetReg = IsN64 ? Mips::V1_64 : Mips::V1; |
| 1884 | unsigned AddrReg = IsN64 ? Mips::V0_64 : Mips::V0; |
| 1885 | Chain = DAG.getCopyToReg(Chain, DL, OffsetReg, Offset, SDValue()); |
| 1886 | Chain = DAG.getCopyToReg(Chain, DL, AddrReg, Handler, Chain.getValue(1)); |
| 1887 | return DAG.getNode(MipsISD::EH_RETURN, DL, MVT::Other, Chain, |
| 1888 | DAG.getRegister(OffsetReg, Ty), |
| 1889 | DAG.getRegister(AddrReg, getPointerTy()), |
| 1890 | Chain.getValue(1)); |
| 1891 | } |
| 1892 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1893 | SDValue MipsTargetLowering::lowerATOMIC_FENCE(SDValue Op, |
Akira Hatanaka | 864f660 | 2012-06-14 21:10:56 +0000 | [diff] [blame] | 1894 | SelectionDAG &DAG) const { |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 1895 | // FIXME: Need pseudo-fence for 'singlethread' fences |
| 1896 | // FIXME: Set SType for weaker fences where supported/appropriate. |
| 1897 | unsigned SType = 0; |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1898 | SDLoc DL(Op); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1899 | return DAG.getNode(MipsISD::Sync, DL, MVT::Other, Op.getOperand(0), |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 1900 | DAG.getConstant(SType, MVT::i32)); |
| 1901 | } |
| 1902 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1903 | SDValue MipsTargetLowering::lowerShiftLeftParts(SDValue Op, |
Akira Hatanaka | 864f660 | 2012-06-14 21:10:56 +0000 | [diff] [blame] | 1904 | SelectionDAG &DAG) const { |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1905 | SDLoc DL(Op); |
Akira Hatanaka | a284acb | 2012-05-09 00:55:21 +0000 | [diff] [blame] | 1906 | SDValue Lo = Op.getOperand(0), Hi = Op.getOperand(1); |
| 1907 | SDValue Shamt = Op.getOperand(2); |
| 1908 | |
| 1909 | // if shamt < 32: |
| 1910 | // lo = (shl lo, shamt) |
| 1911 | // hi = (or (shl hi, shamt) (srl (srl lo, 1), ~shamt)) |
| 1912 | // else: |
| 1913 | // lo = 0 |
| 1914 | // hi = (shl lo, shamt[4:0]) |
| 1915 | SDValue Not = DAG.getNode(ISD::XOR, DL, MVT::i32, Shamt, |
| 1916 | DAG.getConstant(-1, MVT::i32)); |
| 1917 | SDValue ShiftRight1Lo = DAG.getNode(ISD::SRL, DL, MVT::i32, Lo, |
| 1918 | DAG.getConstant(1, MVT::i32)); |
| 1919 | SDValue ShiftRightLo = DAG.getNode(ISD::SRL, DL, MVT::i32, ShiftRight1Lo, |
| 1920 | Not); |
| 1921 | SDValue ShiftLeftHi = DAG.getNode(ISD::SHL, DL, MVT::i32, Hi, Shamt); |
| 1922 | SDValue Or = DAG.getNode(ISD::OR, DL, MVT::i32, ShiftLeftHi, ShiftRightLo); |
| 1923 | SDValue ShiftLeftLo = DAG.getNode(ISD::SHL, DL, MVT::i32, Lo, Shamt); |
| 1924 | SDValue Cond = DAG.getNode(ISD::AND, DL, MVT::i32, Shamt, |
| 1925 | DAG.getConstant(0x20, MVT::i32)); |
Akira Hatanaka | 864f660 | 2012-06-14 21:10:56 +0000 | [diff] [blame] | 1926 | Lo = DAG.getNode(ISD::SELECT, DL, MVT::i32, Cond, |
| 1927 | DAG.getConstant(0, MVT::i32), ShiftLeftLo); |
Akira Hatanaka | a284acb | 2012-05-09 00:55:21 +0000 | [diff] [blame] | 1928 | Hi = DAG.getNode(ISD::SELECT, DL, MVT::i32, Cond, ShiftLeftLo, Or); |
| 1929 | |
| 1930 | SDValue Ops[2] = {Lo, Hi}; |
| 1931 | return DAG.getMergeValues(Ops, 2, DL); |
| 1932 | } |
| 1933 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1934 | SDValue MipsTargetLowering::lowerShiftRightParts(SDValue Op, SelectionDAG &DAG, |
Akira Hatanaka | a284acb | 2012-05-09 00:55:21 +0000 | [diff] [blame] | 1935 | bool IsSRA) const { |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1936 | SDLoc DL(Op); |
Akira Hatanaka | a284acb | 2012-05-09 00:55:21 +0000 | [diff] [blame] | 1937 | SDValue Lo = Op.getOperand(0), Hi = Op.getOperand(1); |
| 1938 | SDValue Shamt = Op.getOperand(2); |
| 1939 | |
| 1940 | // if shamt < 32: |
| 1941 | // lo = (or (shl (shl hi, 1), ~shamt) (srl lo, shamt)) |
| 1942 | // if isSRA: |
| 1943 | // hi = (sra hi, shamt) |
| 1944 | // else: |
| 1945 | // hi = (srl hi, shamt) |
| 1946 | // else: |
| 1947 | // if isSRA: |
| 1948 | // lo = (sra hi, shamt[4:0]) |
| 1949 | // hi = (sra hi, 31) |
| 1950 | // else: |
| 1951 | // lo = (srl hi, shamt[4:0]) |
| 1952 | // hi = 0 |
| 1953 | SDValue Not = DAG.getNode(ISD::XOR, DL, MVT::i32, Shamt, |
| 1954 | DAG.getConstant(-1, MVT::i32)); |
| 1955 | SDValue ShiftLeft1Hi = DAG.getNode(ISD::SHL, DL, MVT::i32, Hi, |
| 1956 | DAG.getConstant(1, MVT::i32)); |
| 1957 | SDValue ShiftLeftHi = DAG.getNode(ISD::SHL, DL, MVT::i32, ShiftLeft1Hi, Not); |
| 1958 | SDValue ShiftRightLo = DAG.getNode(ISD::SRL, DL, MVT::i32, Lo, Shamt); |
| 1959 | SDValue Or = DAG.getNode(ISD::OR, DL, MVT::i32, ShiftLeftHi, ShiftRightLo); |
| 1960 | SDValue ShiftRightHi = DAG.getNode(IsSRA ? ISD::SRA : ISD::SRL, DL, MVT::i32, |
| 1961 | Hi, Shamt); |
| 1962 | SDValue Cond = DAG.getNode(ISD::AND, DL, MVT::i32, Shamt, |
| 1963 | DAG.getConstant(0x20, MVT::i32)); |
| 1964 | SDValue Shift31 = DAG.getNode(ISD::SRA, DL, MVT::i32, Hi, |
| 1965 | DAG.getConstant(31, MVT::i32)); |
| 1966 | Lo = DAG.getNode(ISD::SELECT, DL, MVT::i32, Cond, ShiftRightHi, Or); |
| 1967 | Hi = DAG.getNode(ISD::SELECT, DL, MVT::i32, Cond, |
| 1968 | IsSRA ? Shift31 : DAG.getConstant(0, MVT::i32), |
| 1969 | ShiftRightHi); |
| 1970 | |
| 1971 | SDValue Ops[2] = {Lo, Hi}; |
| 1972 | return DAG.getMergeValues(Ops, 2, DL); |
| 1973 | } |
| 1974 | |
Akira Hatanaka | fee62c1 | 2013-04-11 19:07:14 +0000 | [diff] [blame] | 1975 | static SDValue createLoadLR(unsigned Opc, SelectionDAG &DAG, LoadSDNode *LD, |
Akira Hatanaka | 1cd0ec0 | 2012-06-02 00:03:49 +0000 | [diff] [blame] | 1976 | SDValue Chain, SDValue Src, unsigned Offset) { |
Akira Hatanaka | 2bd7e53 | 2012-06-13 19:06:08 +0000 | [diff] [blame] | 1977 | SDValue Ptr = LD->getBasePtr(); |
Akira Hatanaka | 1cd0ec0 | 2012-06-02 00:03:49 +0000 | [diff] [blame] | 1978 | EVT VT = LD->getValueType(0), MemVT = LD->getMemoryVT(); |
Akira Hatanaka | 2bd7e53 | 2012-06-13 19:06:08 +0000 | [diff] [blame] | 1979 | EVT BasePtrVT = Ptr.getValueType(); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1980 | SDLoc DL(LD); |
Akira Hatanaka | 1cd0ec0 | 2012-06-02 00:03:49 +0000 | [diff] [blame] | 1981 | SDVTList VTList = DAG.getVTList(VT, MVT::Other); |
| 1982 | |
| 1983 | if (Offset) |
Akira Hatanaka | 2bd7e53 | 2012-06-13 19:06:08 +0000 | [diff] [blame] | 1984 | Ptr = DAG.getNode(ISD::ADD, DL, BasePtrVT, Ptr, |
Akira Hatanaka | 1cd0ec0 | 2012-06-02 00:03:49 +0000 | [diff] [blame] | 1985 | DAG.getConstant(Offset, BasePtrVT)); |
Akira Hatanaka | 1cd0ec0 | 2012-06-02 00:03:49 +0000 | [diff] [blame] | 1986 | |
| 1987 | SDValue Ops[] = { Chain, Ptr, Src }; |
| 1988 | return DAG.getMemIntrinsicNode(Opc, DL, VTList, Ops, 3, MemVT, |
| 1989 | LD->getMemOperand()); |
| 1990 | } |
| 1991 | |
| 1992 | // Expand an unaligned 32 or 64-bit integer load node. |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 1993 | SDValue MipsTargetLowering::lowerLOAD(SDValue Op, SelectionDAG &DAG) const { |
Akira Hatanaka | 1cd0ec0 | 2012-06-02 00:03:49 +0000 | [diff] [blame] | 1994 | LoadSDNode *LD = cast<LoadSDNode>(Op); |
| 1995 | EVT MemVT = LD->getMemoryVT(); |
| 1996 | |
| 1997 | // Return if load is aligned or if MemVT is neither i32 nor i64. |
| 1998 | if ((LD->getAlignment() >= MemVT.getSizeInBits() / 8) || |
| 1999 | ((MemVT != MVT::i32) && (MemVT != MVT::i64))) |
| 2000 | return SDValue(); |
| 2001 | |
| 2002 | bool IsLittle = Subtarget->isLittle(); |
| 2003 | EVT VT = Op.getValueType(); |
| 2004 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
| 2005 | SDValue Chain = LD->getChain(), Undef = DAG.getUNDEF(VT); |
| 2006 | |
| 2007 | assert((VT == MVT::i32) || (VT == MVT::i64)); |
| 2008 | |
| 2009 | // Expand |
| 2010 | // (set dst, (i64 (load baseptr))) |
| 2011 | // to |
| 2012 | // (set tmp, (ldl (add baseptr, 7), undef)) |
| 2013 | // (set dst, (ldr baseptr, tmp)) |
| 2014 | if ((VT == MVT::i64) && (ExtType == ISD::NON_EXTLOAD)) { |
Akira Hatanaka | fee62c1 | 2013-04-11 19:07:14 +0000 | [diff] [blame] | 2015 | SDValue LDL = createLoadLR(MipsISD::LDL, DAG, LD, Chain, Undef, |
Akira Hatanaka | 1cd0ec0 | 2012-06-02 00:03:49 +0000 | [diff] [blame] | 2016 | IsLittle ? 7 : 0); |
Akira Hatanaka | fee62c1 | 2013-04-11 19:07:14 +0000 | [diff] [blame] | 2017 | return createLoadLR(MipsISD::LDR, DAG, LD, LDL.getValue(1), LDL, |
Akira Hatanaka | 1cd0ec0 | 2012-06-02 00:03:49 +0000 | [diff] [blame] | 2018 | IsLittle ? 0 : 7); |
| 2019 | } |
| 2020 | |
Akira Hatanaka | fee62c1 | 2013-04-11 19:07:14 +0000 | [diff] [blame] | 2021 | SDValue LWL = createLoadLR(MipsISD::LWL, DAG, LD, Chain, Undef, |
Akira Hatanaka | 1cd0ec0 | 2012-06-02 00:03:49 +0000 | [diff] [blame] | 2022 | IsLittle ? 3 : 0); |
Akira Hatanaka | fee62c1 | 2013-04-11 19:07:14 +0000 | [diff] [blame] | 2023 | SDValue LWR = createLoadLR(MipsISD::LWR, DAG, LD, LWL.getValue(1), LWL, |
Akira Hatanaka | 1cd0ec0 | 2012-06-02 00:03:49 +0000 | [diff] [blame] | 2024 | IsLittle ? 0 : 3); |
| 2025 | |
| 2026 | // Expand |
| 2027 | // (set dst, (i32 (load baseptr))) or |
| 2028 | // (set dst, (i64 (sextload baseptr))) or |
| 2029 | // (set dst, (i64 (extload baseptr))) |
| 2030 | // to |
| 2031 | // (set tmp, (lwl (add baseptr, 3), undef)) |
| 2032 | // (set dst, (lwr baseptr, tmp)) |
| 2033 | if ((VT == MVT::i32) || (ExtType == ISD::SEXTLOAD) || |
| 2034 | (ExtType == ISD::EXTLOAD)) |
| 2035 | return LWR; |
| 2036 | |
| 2037 | assert((VT == MVT::i64) && (ExtType == ISD::ZEXTLOAD)); |
| 2038 | |
| 2039 | // Expand |
| 2040 | // (set dst, (i64 (zextload baseptr))) |
| 2041 | // to |
| 2042 | // (set tmp0, (lwl (add baseptr, 3), undef)) |
| 2043 | // (set tmp1, (lwr baseptr, tmp0)) |
| 2044 | // (set tmp2, (shl tmp1, 32)) |
| 2045 | // (set dst, (srl tmp2, 32)) |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2046 | SDLoc DL(LD); |
Akira Hatanaka | 1cd0ec0 | 2012-06-02 00:03:49 +0000 | [diff] [blame] | 2047 | SDValue Const32 = DAG.getConstant(32, MVT::i32); |
| 2048 | SDValue SLL = DAG.getNode(ISD::SHL, DL, MVT::i64, LWR, Const32); |
Akira Hatanaka | 94ccee2 | 2012-06-04 17:46:29 +0000 | [diff] [blame] | 2049 | SDValue SRL = DAG.getNode(ISD::SRL, DL, MVT::i64, SLL, Const32); |
| 2050 | SDValue Ops[] = { SRL, LWR.getValue(1) }; |
Akira Hatanaka | 1cd0ec0 | 2012-06-02 00:03:49 +0000 | [diff] [blame] | 2051 | return DAG.getMergeValues(Ops, 2, DL); |
| 2052 | } |
| 2053 | |
Akira Hatanaka | fee62c1 | 2013-04-11 19:07:14 +0000 | [diff] [blame] | 2054 | static SDValue createStoreLR(unsigned Opc, SelectionDAG &DAG, StoreSDNode *SD, |
Akira Hatanaka | 1cd0ec0 | 2012-06-02 00:03:49 +0000 | [diff] [blame] | 2055 | SDValue Chain, unsigned Offset) { |
Akira Hatanaka | 2bd7e53 | 2012-06-13 19:06:08 +0000 | [diff] [blame] | 2056 | SDValue Ptr = SD->getBasePtr(), Value = SD->getValue(); |
| 2057 | EVT MemVT = SD->getMemoryVT(), BasePtrVT = Ptr.getValueType(); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2058 | SDLoc DL(SD); |
Akira Hatanaka | 1cd0ec0 | 2012-06-02 00:03:49 +0000 | [diff] [blame] | 2059 | SDVTList VTList = DAG.getVTList(MVT::Other); |
| 2060 | |
| 2061 | if (Offset) |
Akira Hatanaka | 2bd7e53 | 2012-06-13 19:06:08 +0000 | [diff] [blame] | 2062 | Ptr = DAG.getNode(ISD::ADD, DL, BasePtrVT, Ptr, |
Akira Hatanaka | 1cd0ec0 | 2012-06-02 00:03:49 +0000 | [diff] [blame] | 2063 | DAG.getConstant(Offset, BasePtrVT)); |
Akira Hatanaka | 1cd0ec0 | 2012-06-02 00:03:49 +0000 | [diff] [blame] | 2064 | |
| 2065 | SDValue Ops[] = { Chain, Value, Ptr }; |
| 2066 | return DAG.getMemIntrinsicNode(Opc, DL, VTList, Ops, 3, MemVT, |
| 2067 | SD->getMemOperand()); |
| 2068 | } |
| 2069 | |
| 2070 | // Expand an unaligned 32 or 64-bit integer store node. |
Akira Hatanaka | 6345143 | 2013-05-16 20:45:17 +0000 | [diff] [blame] | 2071 | static SDValue lowerUnalignedIntStore(StoreSDNode *SD, SelectionDAG &DAG, |
| 2072 | bool IsLittle) { |
Akira Hatanaka | 1cd0ec0 | 2012-06-02 00:03:49 +0000 | [diff] [blame] | 2073 | SDValue Value = SD->getValue(), Chain = SD->getChain(); |
| 2074 | EVT VT = Value.getValueType(); |
| 2075 | |
| 2076 | // Expand |
| 2077 | // (store val, baseptr) or |
| 2078 | // (truncstore val, baseptr) |
| 2079 | // to |
| 2080 | // (swl val, (add baseptr, 3)) |
| 2081 | // (swr val, baseptr) |
| 2082 | if ((VT == MVT::i32) || SD->isTruncatingStore()) { |
Akira Hatanaka | fee62c1 | 2013-04-11 19:07:14 +0000 | [diff] [blame] | 2083 | SDValue SWL = createStoreLR(MipsISD::SWL, DAG, SD, Chain, |
Akira Hatanaka | 1cd0ec0 | 2012-06-02 00:03:49 +0000 | [diff] [blame] | 2084 | IsLittle ? 3 : 0); |
Akira Hatanaka | fee62c1 | 2013-04-11 19:07:14 +0000 | [diff] [blame] | 2085 | return createStoreLR(MipsISD::SWR, DAG, SD, SWL, IsLittle ? 0 : 3); |
Akira Hatanaka | 1cd0ec0 | 2012-06-02 00:03:49 +0000 | [diff] [blame] | 2086 | } |
| 2087 | |
| 2088 | assert(VT == MVT::i64); |
| 2089 | |
| 2090 | // Expand |
| 2091 | // (store val, baseptr) |
| 2092 | // to |
| 2093 | // (sdl val, (add baseptr, 7)) |
| 2094 | // (sdr val, baseptr) |
Akira Hatanaka | fee62c1 | 2013-04-11 19:07:14 +0000 | [diff] [blame] | 2095 | SDValue SDL = createStoreLR(MipsISD::SDL, DAG, SD, Chain, IsLittle ? 7 : 0); |
| 2096 | return createStoreLR(MipsISD::SDR, DAG, SD, SDL, IsLittle ? 0 : 7); |
Akira Hatanaka | 1cd0ec0 | 2012-06-02 00:03:49 +0000 | [diff] [blame] | 2097 | } |
| 2098 | |
Akira Hatanaka | ae7e7cb | 2013-05-16 21:17:15 +0000 | [diff] [blame] | 2099 | // Lower (store (fp_to_sint $fp) $ptr) to (store (TruncIntFP $fp), $ptr). |
| 2100 | static SDValue lowerFP_TO_SINT_STORE(StoreSDNode *SD, SelectionDAG &DAG) { |
| 2101 | SDValue Val = SD->getValue(); |
| 2102 | |
| 2103 | if (Val.getOpcode() != ISD::FP_TO_SINT) |
| 2104 | return SDValue(); |
| 2105 | |
| 2106 | EVT FPTy = EVT::getFloatingPointVT(Val.getValueSizeInBits()); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2107 | SDValue Tr = DAG.getNode(MipsISD::TruncIntFP, SDLoc(Val), FPTy, |
Akira Hatanaka | ae7e7cb | 2013-05-16 21:17:15 +0000 | [diff] [blame] | 2108 | Val.getOperand(0)); |
| 2109 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2110 | return DAG.getStore(SD->getChain(), SDLoc(SD), Tr, SD->getBasePtr(), |
Akira Hatanaka | ae7e7cb | 2013-05-16 21:17:15 +0000 | [diff] [blame] | 2111 | SD->getPointerInfo(), SD->isVolatile(), |
| 2112 | SD->isNonTemporal(), SD->getAlignment()); |
| 2113 | } |
| 2114 | |
Akira Hatanaka | 6345143 | 2013-05-16 20:45:17 +0000 | [diff] [blame] | 2115 | SDValue MipsTargetLowering::lowerSTORE(SDValue Op, SelectionDAG &DAG) const { |
| 2116 | StoreSDNode *SD = cast<StoreSDNode>(Op); |
| 2117 | EVT MemVT = SD->getMemoryVT(); |
| 2118 | |
| 2119 | // Lower unaligned integer stores. |
| 2120 | if ((SD->getAlignment() < MemVT.getSizeInBits() / 8) && |
| 2121 | ((MemVT == MVT::i32) || (MemVT == MVT::i64))) |
| 2122 | return lowerUnalignedIntStore(SD, DAG, Subtarget->isLittle()); |
| 2123 | |
Akira Hatanaka | ae7e7cb | 2013-05-16 21:17:15 +0000 | [diff] [blame] | 2124 | return lowerFP_TO_SINT_STORE(SD, DAG); |
Akira Hatanaka | 6345143 | 2013-05-16 20:45:17 +0000 | [diff] [blame] | 2125 | } |
| 2126 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2127 | SDValue MipsTargetLowering::lowerADD(SDValue Op, SelectionDAG &DAG) const { |
Akira Hatanaka | e90a3bc | 2012-11-07 19:10:58 +0000 | [diff] [blame] | 2128 | if (Op->getOperand(0).getOpcode() != ISD::FRAMEADDR |
| 2129 | || cast<ConstantSDNode> |
| 2130 | (Op->getOperand(0).getOperand(0))->getZExtValue() != 0 |
| 2131 | || Op->getOperand(1).getOpcode() != ISD::FRAME_TO_ARGS_OFFSET) |
| 2132 | return SDValue(); |
| 2133 | |
| 2134 | // The pattern |
| 2135 | // (add (frameaddr 0), (frame_to_args_offset)) |
| 2136 | // results from lowering llvm.eh.dwarf.cfa intrinsic. Transform it to |
| 2137 | // (add FrameObject, 0) |
| 2138 | // where FrameObject is a fixed StackObject with offset 0 which points to |
| 2139 | // the old stack pointer. |
| 2140 | MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); |
| 2141 | EVT ValTy = Op->getValueType(0); |
| 2142 | int FI = MFI->CreateFixedObject(Op.getValueSizeInBits() / 8, 0, false); |
| 2143 | SDValue InArgsAddr = DAG.getFrameIndex(FI, ValTy); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2144 | return DAG.getNode(ISD::ADD, SDLoc(Op), ValTy, InArgsAddr, |
Akira Hatanaka | e90a3bc | 2012-11-07 19:10:58 +0000 | [diff] [blame] | 2145 | DAG.getConstant(0, ValTy)); |
| 2146 | } |
| 2147 | |
Akira Hatanaka | ae7e7cb | 2013-05-16 21:17:15 +0000 | [diff] [blame] | 2148 | SDValue MipsTargetLowering::lowerFP_TO_SINT(SDValue Op, |
| 2149 | SelectionDAG &DAG) const { |
| 2150 | EVT FPTy = EVT::getFloatingPointVT(Op.getValueSizeInBits()); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2151 | SDValue Trunc = DAG.getNode(MipsISD::TruncIntFP, SDLoc(Op), FPTy, |
Akira Hatanaka | ae7e7cb | 2013-05-16 21:17:15 +0000 | [diff] [blame] | 2152 | Op.getOperand(0)); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2153 | return DAG.getNode(ISD::BITCAST, SDLoc(Op), Op.getValueType(), Trunc); |
Akira Hatanaka | ae7e7cb | 2013-05-16 21:17:15 +0000 | [diff] [blame] | 2154 | } |
| 2155 | |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 2156 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2157 | // Calling Convention Implementation |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 2158 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2159 | |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 2160 | //===----------------------------------------------------------------------===// |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2161 | // TODO: Implement a generic logic using tblgen that can support this. |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 2162 | // Mips O32 ABI rules: |
| 2163 | // --- |
| 2164 | // i32 - Passed in A0, A1, A2, A3 and stack |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2165 | // 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] | 2166 | // an argument. Otherwise, passed in A1, A2, A3 and stack. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2167 | // f64 - Only passed in two aliased f32 registers if no int reg has been used |
| 2168 | // 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] | 2169 | // not used, it must be shadowed. If only A3 is avaiable, shadow it and |
| 2170 | // go to stack. |
Akira Hatanaka | 95b8ae1 | 2011-05-19 18:06:05 +0000 | [diff] [blame] | 2171 | // |
| 2172 | // For vararg functions, all arguments are passed in A0, A1, A2, A3 and stack. |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 2173 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 2174 | |
Duncan Sands | 1e96bab | 2010-11-04 10:49:57 +0000 | [diff] [blame] | 2175 | static bool CC_MipsO32(unsigned ValNo, MVT ValVT, |
Duncan Sands | 1440e8b | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 2176 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
Akira Hatanaka | ad341d4 | 2013-08-20 23:38:40 +0000 | [diff] [blame] | 2177 | ISD::ArgFlagsTy ArgFlags, CCState &State, |
| 2178 | const uint16_t *F64Regs) { |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 2179 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2180 | static const unsigned IntRegsSize=4, FloatRegsSize=2; |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 2181 | |
Craig Topper | c5eaae4 | 2012-03-11 07:57:25 +0000 | [diff] [blame] | 2182 | static const uint16_t IntRegs[] = { |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 2183 | Mips::A0, Mips::A1, Mips::A2, Mips::A3 |
| 2184 | }; |
Craig Topper | c5eaae4 | 2012-03-11 07:57:25 +0000 | [diff] [blame] | 2185 | static const uint16_t F32Regs[] = { |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 2186 | Mips::F12, Mips::F14 |
| 2187 | }; |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 2188 | |
Akira Hatanaka | fe30a9b | 2012-10-27 00:29:43 +0000 | [diff] [blame] | 2189 | // Do not process byval args here. |
| 2190 | if (ArgFlags.isByVal()) |
| 2191 | return true; |
Akira Hatanaka | 4231c7e | 2011-05-24 19:18:33 +0000 | [diff] [blame] | 2192 | |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 2193 | // Promote i8 and i16 |
| 2194 | if (LocVT == MVT::i8 || LocVT == MVT::i16) { |
| 2195 | LocVT = MVT::i32; |
| 2196 | if (ArgFlags.isSExt()) |
| 2197 | LocInfo = CCValAssign::SExt; |
| 2198 | else if (ArgFlags.isZExt()) |
| 2199 | LocInfo = CCValAssign::ZExt; |
| 2200 | else |
| 2201 | LocInfo = CCValAssign::AExt; |
| 2202 | } |
| 2203 | |
Bruno Cardoso Lopes | c42fb5f | 2011-03-04 20:27:44 +0000 | [diff] [blame] | 2204 | unsigned Reg; |
| 2205 | |
Akira Hatanaka | 95b8ae1 | 2011-05-19 18:06:05 +0000 | [diff] [blame] | 2206 | // f32 and f64 are allocated in A0, A1, A2, A3 when either of the following |
| 2207 | // is true: function is vararg, argument is 3rd or higher, there is previous |
| 2208 | // argument which is not f32 or f64. |
| 2209 | bool AllocateFloatsInIntReg = State.isVarArg() || ValNo > 1 |
| 2210 | || State.getFirstUnallocated(F32Regs, FloatRegsSize) != ValNo; |
Akira Hatanaka | a1a7ba8 | 2011-05-19 20:29:48 +0000 | [diff] [blame] | 2211 | unsigned OrigAlign = ArgFlags.getOrigAlign(); |
| 2212 | bool isI64 = (ValVT == MVT::i32 && OrigAlign == 8); |
Akira Hatanaka | 95b8ae1 | 2011-05-19 18:06:05 +0000 | [diff] [blame] | 2213 | |
| 2214 | if (ValVT == MVT::i32 || (ValVT == MVT::f32 && AllocateFloatsInIntReg)) { |
Bruno Cardoso Lopes | c42fb5f | 2011-03-04 20:27:44 +0000 | [diff] [blame] | 2215 | Reg = State.AllocateReg(IntRegs, IntRegsSize); |
Akira Hatanaka | a1a7ba8 | 2011-05-19 20:29:48 +0000 | [diff] [blame] | 2216 | // If this is the first part of an i64 arg, |
| 2217 | // the allocated register must be either A0 or A2. |
| 2218 | if (isI64 && (Reg == Mips::A1 || Reg == Mips::A3)) |
| 2219 | Reg = State.AllocateReg(IntRegs, IntRegsSize); |
Bruno Cardoso Lopes | c42fb5f | 2011-03-04 20:27:44 +0000 | [diff] [blame] | 2220 | LocVT = MVT::i32; |
Akira Hatanaka | 95b8ae1 | 2011-05-19 18:06:05 +0000 | [diff] [blame] | 2221 | } else if (ValVT == MVT::f64 && AllocateFloatsInIntReg) { |
| 2222 | // Allocate int register and shadow next int register. If first |
| 2223 | // available register is Mips::A1 or Mips::A3, shadow it too. |
Bruno Cardoso Lopes | c42fb5f | 2011-03-04 20:27:44 +0000 | [diff] [blame] | 2224 | Reg = State.AllocateReg(IntRegs, IntRegsSize); |
| 2225 | if (Reg == Mips::A1 || Reg == Mips::A3) |
| 2226 | Reg = State.AllocateReg(IntRegs, IntRegsSize); |
| 2227 | State.AllocateReg(IntRegs, IntRegsSize); |
| 2228 | LocVT = MVT::i32; |
Akira Hatanaka | 95b8ae1 | 2011-05-19 18:06:05 +0000 | [diff] [blame] | 2229 | } else if (ValVT.isFloatingPoint() && !AllocateFloatsInIntReg) { |
| 2230 | // we are guaranteed to find an available float register |
| 2231 | if (ValVT == MVT::f32) { |
| 2232 | Reg = State.AllocateReg(F32Regs, FloatRegsSize); |
| 2233 | // Shadow int register |
| 2234 | State.AllocateReg(IntRegs, IntRegsSize); |
| 2235 | } else { |
| 2236 | Reg = State.AllocateReg(F64Regs, FloatRegsSize); |
| 2237 | // Shadow int registers |
| 2238 | unsigned Reg2 = State.AllocateReg(IntRegs, IntRegsSize); |
| 2239 | if (Reg2 == Mips::A1 || Reg2 == Mips::A3) |
| 2240 | State.AllocateReg(IntRegs, IntRegsSize); |
| 2241 | State.AllocateReg(IntRegs, IntRegsSize); |
| 2242 | } |
Bruno Cardoso Lopes | c42fb5f | 2011-03-04 20:27:44 +0000 | [diff] [blame] | 2243 | } else |
| 2244 | llvm_unreachable("Cannot handle this ValVT."); |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 2245 | |
Akira Hatanaka | fe30a9b | 2012-10-27 00:29:43 +0000 | [diff] [blame] | 2246 | if (!Reg) { |
| 2247 | unsigned Offset = State.AllocateStack(ValVT.getSizeInBits() >> 3, |
| 2248 | OrigAlign); |
Bruno Cardoso Lopes | c42fb5f | 2011-03-04 20:27:44 +0000 | [diff] [blame] | 2249 | State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo)); |
Akira Hatanaka | fe30a9b | 2012-10-27 00:29:43 +0000 | [diff] [blame] | 2250 | } else |
Bruno Cardoso Lopes | c42fb5f | 2011-03-04 20:27:44 +0000 | [diff] [blame] | 2251 | State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo)); |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 2252 | |
Akira Hatanaka | fe30a9b | 2012-10-27 00:29:43 +0000 | [diff] [blame] | 2253 | return false; |
Akira Hatanaka | 2c5d652 | 2011-11-12 02:20:46 +0000 | [diff] [blame] | 2254 | } |
| 2255 | |
Akira Hatanaka | ad341d4 | 2013-08-20 23:38:40 +0000 | [diff] [blame] | 2256 | static bool CC_MipsO32_FP32(unsigned ValNo, MVT ValVT, |
| 2257 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 2258 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
| 2259 | static const uint16_t F64Regs[] = { Mips::D6, Mips::D7 }; |
| 2260 | |
| 2261 | return CC_MipsO32(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State, F64Regs); |
| 2262 | } |
| 2263 | |
| 2264 | static bool CC_MipsO32_FP64(unsigned ValNo, MVT ValVT, |
| 2265 | MVT LocVT, CCValAssign::LocInfo LocInfo, |
| 2266 | ISD::ArgFlagsTy ArgFlags, CCState &State) { |
| 2267 | static const uint16_t F64Regs[] = { Mips::D12_64, Mips::D12_64 }; |
| 2268 | |
| 2269 | return CC_MipsO32(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State, F64Regs); |
| 2270 | } |
| 2271 | |
Akira Hatanaka | 2c5d652 | 2011-11-12 02:20:46 +0000 | [diff] [blame] | 2272 | #include "MipsGenCallingConv.inc" |
| 2273 | |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 2274 | //===----------------------------------------------------------------------===// |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2275 | // Call Calling Convention Implementation |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 2276 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2277 | |
Akira Hatanaka | 373e3a4 | 2011-09-23 00:58:33 +0000 | [diff] [blame] | 2278 | // Return next O32 integer argument register. |
| 2279 | static unsigned getNextIntArgReg(unsigned Reg) { |
| 2280 | assert((Reg == Mips::A0) || (Reg == Mips::A2)); |
| 2281 | return (Reg == Mips::A0) ? Mips::A1 : Mips::A3; |
| 2282 | } |
| 2283 | |
Akira Hatanaka | 7d71209 | 2012-10-30 19:23:25 +0000 | [diff] [blame] | 2284 | SDValue |
| 2285 | MipsTargetLowering::passArgOnStack(SDValue StackPtr, unsigned Offset, |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2286 | SDValue Chain, SDValue Arg, SDLoc DL, |
Akira Hatanaka | 7d71209 | 2012-10-30 19:23:25 +0000 | [diff] [blame] | 2287 | bool IsTailCall, SelectionDAG &DAG) const { |
| 2288 | if (!IsTailCall) { |
| 2289 | SDValue PtrOff = DAG.getNode(ISD::ADD, DL, getPointerTy(), StackPtr, |
| 2290 | DAG.getIntPtrConstant(Offset)); |
| 2291 | return DAG.getStore(Chain, DL, Arg, PtrOff, MachinePointerInfo(), false, |
| 2292 | false, 0); |
| 2293 | } |
| 2294 | |
| 2295 | MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); |
| 2296 | int FI = MFI->CreateFixedObject(Arg.getValueSizeInBits() / 8, Offset, false); |
| 2297 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 2298 | return DAG.getStore(Chain, DL, Arg, FIN, MachinePointerInfo(), |
| 2299 | /*isVolatile=*/ true, false, 0); |
| 2300 | } |
| 2301 | |
Akira Hatanaka | 5ac065a | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 2302 | void MipsTargetLowering:: |
| 2303 | getOpndList(SmallVectorImpl<SDValue> &Ops, |
| 2304 | std::deque< std::pair<unsigned, SDValue> > &RegsToPass, |
| 2305 | bool IsPICCall, bool GlobalOrExternal, bool InternalLinkage, |
| 2306 | CallLoweringInfo &CLI, SDValue Callee, SDValue Chain) const { |
| 2307 | // Insert node "GP copy globalreg" before call to function. |
| 2308 | // |
| 2309 | // R_MIPS_CALL* operators (emitted when non-internal functions are called |
| 2310 | // in PIC mode) allow symbols to be resolved via lazy binding. |
| 2311 | // The lazy binding stub requires GP to point to the GOT. |
| 2312 | if (IsPICCall && !InternalLinkage) { |
| 2313 | unsigned GPReg = IsN64 ? Mips::GP_64 : Mips::GP; |
| 2314 | EVT Ty = IsN64 ? MVT::i64 : MVT::i32; |
| 2315 | RegsToPass.push_back(std::make_pair(GPReg, getGlobalReg(CLI.DAG, Ty))); |
| 2316 | } |
Reed Kotler | 8453b3f | 2013-01-24 04:24:02 +0000 | [diff] [blame] | 2317 | |
Akira Hatanaka | 5ac065a | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 2318 | // Build a sequence of copy-to-reg nodes chained together with token |
| 2319 | // chain and flag operands which copy the outgoing args into registers. |
| 2320 | // The InFlag in necessary since all emitted instructions must be |
| 2321 | // stuck together. |
| 2322 | SDValue InFlag; |
Reed Kotler | 8453b3f | 2013-01-24 04:24:02 +0000 | [diff] [blame] | 2323 | |
Akira Hatanaka | 5ac065a | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 2324 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 2325 | Chain = CLI.DAG.getCopyToReg(Chain, CLI.DL, RegsToPass[i].first, |
| 2326 | RegsToPass[i].second, InFlag); |
| 2327 | InFlag = Chain.getValue(1); |
| 2328 | } |
Reed Kotler | 8453b3f | 2013-01-24 04:24:02 +0000 | [diff] [blame] | 2329 | |
Akira Hatanaka | 5ac065a | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 2330 | // Add argument registers to the end of the list so that they are |
| 2331 | // known live into the call. |
| 2332 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) |
| 2333 | Ops.push_back(CLI.DAG.getRegister(RegsToPass[i].first, |
| 2334 | RegsToPass[i].second.getValueType())); |
Reed Kotler | 8453b3f | 2013-01-24 04:24:02 +0000 | [diff] [blame] | 2335 | |
Akira Hatanaka | 5ac065a | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 2336 | // Add a register mask operand representing the call-preserved registers. |
| 2337 | const TargetRegisterInfo *TRI = getTargetMachine().getRegisterInfo(); |
| 2338 | const uint32_t *Mask = TRI->getCallPreservedMask(CLI.CallConv); |
| 2339 | assert(Mask && "Missing call preserved mask for calling convention"); |
Reed Kotler | 4609091 | 2013-05-10 22:25:39 +0000 | [diff] [blame] | 2340 | if (Subtarget->inMips16HardFloat()) { |
| 2341 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(CLI.Callee)) { |
| 2342 | llvm::StringRef Sym = G->getGlobal()->getName(); |
| 2343 | Function *F = G->getGlobal()->getParent()->getFunction(Sym); |
| 2344 | if (F->hasFnAttribute("__Mips16RetHelper")) { |
| 2345 | Mask = MipsRegisterInfo::getMips16RetHelperMask(); |
| 2346 | } |
| 2347 | } |
| 2348 | } |
Akira Hatanaka | 5ac065a | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 2349 | Ops.push_back(CLI.DAG.getRegisterMask(Mask)); |
| 2350 | |
| 2351 | if (InFlag.getNode()) |
| 2352 | Ops.push_back(InFlag); |
Reed Kotler | 8453b3f | 2013-01-24 04:24:02 +0000 | [diff] [blame] | 2353 | } |
| 2354 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2355 | /// LowerCall - functions arguments are copied from virtual regs to |
Nate Begeman | 5bf4b75 | 2009-01-26 03:15:54 +0000 | [diff] [blame] | 2356 | /// (physical regs)/(stack frame), CALLSEQ_START and CALLSEQ_END are emitted. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2357 | SDValue |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 2358 | MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2359 | SmallVectorImpl<SDValue> &InVals) const { |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 2360 | SelectionDAG &DAG = CLI.DAG; |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2361 | SDLoc DL = CLI.DL; |
Craig Topper | a0ec3f9 | 2013-07-14 04:42:23 +0000 | [diff] [blame] | 2362 | SmallVectorImpl<ISD::OutputArg> &Outs = CLI.Outs; |
| 2363 | SmallVectorImpl<SDValue> &OutVals = CLI.OutVals; |
| 2364 | SmallVectorImpl<ISD::InputArg> &Ins = CLI.Ins; |
Akira Hatanaka | e2d529a | 2012-07-31 18:46:41 +0000 | [diff] [blame] | 2365 | SDValue Chain = CLI.Chain; |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 2366 | SDValue Callee = CLI.Callee; |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2367 | bool &IsTailCall = CLI.IsTailCall; |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 2368 | CallingConv::ID CallConv = CLI.CallConv; |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2369 | bool IsVarArg = CLI.IsVarArg; |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 2370 | |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 2371 | MachineFunction &MF = DAG.getMachineFunction(); |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 2372 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Akira Hatanaka | d37776d | 2011-05-20 21:39:54 +0000 | [diff] [blame] | 2373 | const TargetFrameLowering *TFL = MF.getTarget().getFrameLowering(); |
Bruno Cardoso Lopes | c517cb0 | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 2374 | bool IsPIC = getTargetMachine().getRelocationModel() == Reloc::PIC_; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2375 | |
| 2376 | // Analyze operands of the call, assigning locations to each operand. |
| 2377 | SmallVector<CCValAssign, 16> ArgLocs; |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2378 | CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), |
Akira Hatanaka | 8209968 | 2011-12-19 19:52:25 +0000 | [diff] [blame] | 2379 | getTargetMachine(), ArgLocs, *DAG.getContext()); |
Reed Kotler | 4609091 | 2013-05-10 22:25:39 +0000 | [diff] [blame] | 2380 | MipsCC::SpecialCallingConvType SpecialCallingConv = |
| 2381 | getSpecialCallingConv(Callee); |
Akira Hatanaka | ad341d4 | 2013-08-20 23:38:40 +0000 | [diff] [blame] | 2382 | MipsCC MipsCCInfo(CallConv, IsO32, Subtarget->isFP64bit(), CCInfo, |
| 2383 | SpecialCallingConv); |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 2384 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2385 | MipsCCInfo.analyzeCallOperands(Outs, IsVarArg, |
Reed Kotler | c673f9c | 2013-08-30 19:40:56 +0000 | [diff] [blame] | 2386 | Subtarget->mipsSEUsesSoftFloat(), |
Akira Hatanaka | cb2eafd | 2013-03-05 22:20:28 +0000 | [diff] [blame] | 2387 | Callee.getNode(), CLI.Args); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2388 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2389 | // Get a count of how many bytes are to be pushed on the stack. |
Akira Hatanaka | 3d21c24 | 2011-06-08 17:39:33 +0000 | [diff] [blame] | 2390 | unsigned NextStackOffset = CCInfo.getNextStackOffset(); |
Akira Hatanaka | 480eeb5 | 2012-07-26 23:27:01 +0000 | [diff] [blame] | 2391 | |
Akira Hatanaka | 2b861be | 2012-10-19 21:47:33 +0000 | [diff] [blame] | 2392 | // Check if it's really possible to do a tail call. |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2393 | if (IsTailCall) |
| 2394 | IsTailCall = |
| 2395 | isEligibleForTailCallOptimization(MipsCCInfo, NextStackOffset, |
Akira Hatanaka | 2f34d75 | 2012-10-30 20:16:31 +0000 | [diff] [blame] | 2396 | *MF.getInfo<MipsFunctionInfo>()); |
Akira Hatanaka | 2b861be | 2012-10-19 21:47:33 +0000 | [diff] [blame] | 2397 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2398 | if (IsTailCall) |
Akira Hatanaka | 2b861be | 2012-10-19 21:47:33 +0000 | [diff] [blame] | 2399 | ++NumTailCalls; |
| 2400 | |
Akira Hatanaka | da7f5f1 | 2011-09-19 20:26:02 +0000 | [diff] [blame] | 2401 | // Chain is the output chain of the last Load/Store or CopyToReg node. |
| 2402 | // ByValChain is the output chain of the last Memcpy node created for copying |
| 2403 | // byval arguments to the stack. |
Akira Hatanaka | 2f34d75 | 2012-10-30 20:16:31 +0000 | [diff] [blame] | 2404 | unsigned StackAlignment = TFL->getStackAlignment(); |
| 2405 | NextStackOffset = RoundUpToAlignment(NextStackOffset, StackAlignment); |
Akira Hatanaka | da7f5f1 | 2011-09-19 20:26:02 +0000 | [diff] [blame] | 2406 | SDValue NextStackOffsetVal = DAG.getIntPtrConstant(NextStackOffset, true); |
Akira Hatanaka | 2b861be | 2012-10-19 21:47:33 +0000 | [diff] [blame] | 2407 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2408 | if (!IsTailCall) |
Andrew Trick | 6e0b2a0 | 2013-05-29 22:03:55 +0000 | [diff] [blame] | 2409 | Chain = DAG.getCALLSEQ_START(Chain, NextStackOffsetVal, DL); |
Akira Hatanaka | e2d529a | 2012-07-31 18:46:41 +0000 | [diff] [blame] | 2410 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2411 | SDValue StackPtr = DAG.getCopyFromReg(Chain, DL, |
Akira Hatanaka | e2d529a | 2012-07-31 18:46:41 +0000 | [diff] [blame] | 2412 | IsN64 ? Mips::SP_64 : Mips::SP, |
| 2413 | getPointerTy()); |
Akira Hatanaka | 3d21c24 | 2011-06-08 17:39:33 +0000 | [diff] [blame] | 2414 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 2415 | // With EABI is it possible to have 16 args on registers. |
Akira Hatanaka | bf6a77b | 2013-01-22 20:05:56 +0000 | [diff] [blame] | 2416 | std::deque< std::pair<unsigned, SDValue> > RegsToPass; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2417 | SmallVector<SDValue, 8> MemOpChains; |
Akira Hatanaka | fe30a9b | 2012-10-27 00:29:43 +0000 | [diff] [blame] | 2418 | MipsCC::byval_iterator ByValArg = MipsCCInfo.byval_begin(); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2419 | |
| 2420 | // Walk the register/memloc assignments, inserting copies/loads. |
| 2421 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 2422 | SDValue Arg = OutVals[i]; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2423 | CCValAssign &VA = ArgLocs[i]; |
Akira Hatanaka | e42f33b | 2011-10-28 19:49:00 +0000 | [diff] [blame] | 2424 | MVT ValVT = VA.getValVT(), LocVT = VA.getLocVT(); |
Akira Hatanaka | 6df3e7b | 2011-11-12 02:34:50 +0000 | [diff] [blame] | 2425 | ISD::ArgFlagsTy Flags = Outs[i].Flags; |
| 2426 | |
| 2427 | // ByVal Arg. |
| 2428 | if (Flags.isByVal()) { |
| 2429 | assert(Flags.getByValSize() && |
| 2430 | "ByVal args of size 0 should have been ignored by front-end."); |
Akira Hatanaka | fe30a9b | 2012-10-27 00:29:43 +0000 | [diff] [blame] | 2431 | assert(ByValArg != MipsCCInfo.byval_end()); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2432 | assert(!IsTailCall && |
Akira Hatanaka | 2f34d75 | 2012-10-30 20:16:31 +0000 | [diff] [blame] | 2433 | "Do not tail-call optimize if there is a byval argument."); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2434 | passByValArg(Chain, DL, RegsToPass, MemOpChains, StackPtr, MFI, DAG, Arg, |
Akira Hatanaka | fe30a9b | 2012-10-27 00:29:43 +0000 | [diff] [blame] | 2435 | MipsCCInfo, *ByValArg, Flags, Subtarget->isLittle()); |
| 2436 | ++ByValArg; |
Akira Hatanaka | 6df3e7b | 2011-11-12 02:34:50 +0000 | [diff] [blame] | 2437 | continue; |
| 2438 | } |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 2439 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2440 | // Promote the value if needed. |
| 2441 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2442 | default: llvm_unreachable("Unknown loc info!"); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2443 | case CCValAssign::Full: |
Akira Hatanaka | e42f33b | 2011-10-28 19:49:00 +0000 | [diff] [blame] | 2444 | if (VA.isRegLoc()) { |
| 2445 | if ((ValVT == MVT::f32 && LocVT == MVT::i32) || |
Akira Hatanaka | cb2eafd | 2013-03-05 22:20:28 +0000 | [diff] [blame] | 2446 | (ValVT == MVT::f64 && LocVT == MVT::i64) || |
| 2447 | (ValVT == MVT::i64 && LocVT == MVT::f64)) |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2448 | Arg = DAG.getNode(ISD::BITCAST, DL, LocVT, Arg); |
Akira Hatanaka | e42f33b | 2011-10-28 19:49:00 +0000 | [diff] [blame] | 2449 | else if (ValVT == MVT::f64 && LocVT == MVT::i32) { |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2450 | SDValue Lo = DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 2451 | Arg, DAG.getConstant(0, MVT::i32)); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2452 | SDValue Hi = DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, |
Akira Hatanaka | 0bf3dfb | 2011-04-15 21:00:26 +0000 | [diff] [blame] | 2453 | Arg, DAG.getConstant(1, MVT::i32)); |
Akira Hatanaka | 99a2e98 | 2011-04-15 19:52:08 +0000 | [diff] [blame] | 2454 | if (!Subtarget->isLittle()) |
| 2455 | std::swap(Lo, Hi); |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 2456 | unsigned LocRegLo = VA.getLocReg(); |
Akira Hatanaka | 373e3a4 | 2011-09-23 00:58:33 +0000 | [diff] [blame] | 2457 | unsigned LocRegHigh = getNextIntArgReg(LocRegLo); |
| 2458 | RegsToPass.push_back(std::make_pair(LocRegLo, Lo)); |
| 2459 | RegsToPass.push_back(std::make_pair(LocRegHigh, Hi)); |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 2460 | continue; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2461 | } |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 2462 | } |
| 2463 | break; |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 2464 | case CCValAssign::SExt: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2465 | Arg = DAG.getNode(ISD::SIGN_EXTEND, DL, LocVT, Arg); |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 2466 | break; |
| 2467 | case CCValAssign::ZExt: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2468 | Arg = DAG.getNode(ISD::ZERO_EXTEND, DL, LocVT, Arg); |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 2469 | break; |
| 2470 | case CCValAssign::AExt: |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2471 | Arg = DAG.getNode(ISD::ANY_EXTEND, DL, LocVT, Arg); |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 2472 | break; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2473 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2474 | |
| 2475 | // Arguments that can be passed on register must be kept at |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 2476 | // RegsToPass vector |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2477 | if (VA.isRegLoc()) { |
| 2478 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 2479 | continue; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2480 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2481 | |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 2482 | // Register can't get to this point... |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 2483 | assert(VA.isMemLoc()); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2484 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2485 | // emit ISD::STORE whichs stores the |
Chris Lattner | e0b1215 | 2008-03-17 06:57:02 +0000 | [diff] [blame] | 2486 | // parameter value to a stack Location |
Akira Hatanaka | 2f34d75 | 2012-10-30 20:16:31 +0000 | [diff] [blame] | 2487 | MemOpChains.push_back(passArgOnStack(StackPtr, VA.getLocMemOffset(), |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2488 | Chain, Arg, DL, IsTailCall, DAG)); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2489 | } |
| 2490 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 2491 | // Transform all store nodes into one single node because all store |
| 2492 | // nodes are independent of each other. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2493 | if (!MemOpChains.empty()) |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2494 | Chain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2495 | &MemOpChains[0], MemOpChains.size()); |
| 2496 | |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 2497 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2498 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 2499 | // node so that legalize doesn't hack it. |
Akira Hatanaka | e42f33b | 2011-10-28 19:49:00 +0000 | [diff] [blame] | 2500 | bool IsPICCall = (IsN64 || IsPIC); // true if calls are translated to jalr $25 |
Akira Hatanaka | ed185da | 2012-12-13 03:17:29 +0000 | [diff] [blame] | 2501 | bool GlobalOrExternal = false, InternalLinkage = false; |
Akira Hatanaka | 9777e7a | 2011-04-07 19:51:44 +0000 | [diff] [blame] | 2502 | SDValue CalleeLo; |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 2503 | EVT Ty = Callee.getValueType(); |
Akira Hatanaka | f49fde2 | 2011-04-04 17:11:07 +0000 | [diff] [blame] | 2504 | |
| 2505 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Akira Hatanaka | d43e06d | 2012-11-21 20:30:40 +0000 | [diff] [blame] | 2506 | if (IsPICCall) { |
Akira Hatanaka | ed185da | 2012-12-13 03:17:29 +0000 | [diff] [blame] | 2507 | InternalLinkage = G->getGlobal()->hasInternalLinkage(); |
| 2508 | |
| 2509 | if (InternalLinkage) |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 2510 | Callee = getAddrLocal(G, Ty, DAG, HasMips64); |
Akira Hatanaka | f09a037 | 2012-11-21 20:40:38 +0000 | [diff] [blame] | 2511 | else if (LargeGOT) |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 2512 | Callee = getAddrGlobalLargeGOT(G, Ty, DAG, MipsII::MO_CALL_HI16, |
Akira Hatanaka | f09a037 | 2012-11-21 20:40:38 +0000 | [diff] [blame] | 2513 | MipsII::MO_CALL_LO16); |
Akira Hatanaka | d43e06d | 2012-11-21 20:30:40 +0000 | [diff] [blame] | 2514 | else |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 2515 | Callee = getAddrGlobal(G, Ty, DAG, MipsII::MO_GOT_CALL); |
Akira Hatanaka | d43e06d | 2012-11-21 20:30:40 +0000 | [diff] [blame] | 2516 | } else |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2517 | Callee = DAG.getTargetGlobalAddress(G->getGlobal(), DL, getPointerTy(), 0, |
Akira Hatanaka | d43e06d | 2012-11-21 20:30:40 +0000 | [diff] [blame] | 2518 | MipsII::MO_NO_FLAG); |
Akira Hatanaka | 0dca945 | 2011-12-09 01:45:12 +0000 | [diff] [blame] | 2519 | GlobalOrExternal = true; |
Akira Hatanaka | f49fde2 | 2011-04-04 17:11:07 +0000 | [diff] [blame] | 2520 | } |
| 2521 | else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) { |
Akira Hatanaka | f09a037 | 2012-11-21 20:40:38 +0000 | [diff] [blame] | 2522 | if (!IsN64 && !IsPIC) // !N64 && static |
Akira Hatanaka | d43e06d | 2012-11-21 20:30:40 +0000 | [diff] [blame] | 2523 | Callee = DAG.getTargetExternalSymbol(S->getSymbol(), getPointerTy(), |
| 2524 | MipsII::MO_NO_FLAG); |
Akira Hatanaka | f09a037 | 2012-11-21 20:40:38 +0000 | [diff] [blame] | 2525 | else if (LargeGOT) |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 2526 | Callee = getAddrGlobalLargeGOT(S, Ty, DAG, MipsII::MO_CALL_HI16, |
Akira Hatanaka | f09a037 | 2012-11-21 20:40:38 +0000 | [diff] [blame] | 2527 | MipsII::MO_CALL_LO16); |
Akira Hatanaka | 6068932 | 2013-02-22 21:10:03 +0000 | [diff] [blame] | 2528 | else // N64 || PIC |
Akira Hatanaka | 7938034 | 2013-09-25 00:30:25 +0000 | [diff] [blame^] | 2529 | Callee = getAddrGlobal(S, Ty, DAG, MipsII::MO_GOT_CALL); |
Akira Hatanaka | d43e06d | 2012-11-21 20:30:40 +0000 | [diff] [blame] | 2530 | |
Akira Hatanaka | 0dca945 | 2011-12-09 01:45:12 +0000 | [diff] [blame] | 2531 | GlobalOrExternal = true; |
Akira Hatanaka | f49fde2 | 2011-04-04 17:11:07 +0000 | [diff] [blame] | 2532 | } |
| 2533 | |
Akira Hatanaka | bf6a77b | 2013-01-22 20:05:56 +0000 | [diff] [blame] | 2534 | SmallVector<SDValue, 8> Ops(1, Chain); |
Akira Hatanaka | 5ac065a | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 2535 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
Akira Hatanaka | bf6a77b | 2013-01-22 20:05:56 +0000 | [diff] [blame] | 2536 | |
Akira Hatanaka | 5ac065a | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 2537 | getOpndList(Ops, RegsToPass, IsPICCall, GlobalOrExternal, InternalLinkage, |
| 2538 | CLI, Callee, Chain); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2539 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2540 | if (IsTailCall) |
| 2541 | return DAG.getNode(MipsISD::TailCall, DL, MVT::Other, &Ops[0], Ops.size()); |
Akira Hatanaka | 2b861be | 2012-10-19 21:47:33 +0000 | [diff] [blame] | 2542 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2543 | Chain = DAG.getNode(MipsISD::JmpLink, DL, NodeTys, &Ops[0], Ops.size()); |
Akira Hatanaka | 5ac065a | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 2544 | SDValue InFlag = Chain.getValue(1); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2545 | |
Bruno Cardoso Lopes | 3ed6f87 | 2010-01-30 18:32:07 +0000 | [diff] [blame] | 2546 | // Create the CALLSEQ_END node. |
Akira Hatanaka | 480eeb5 | 2012-07-26 23:27:01 +0000 | [diff] [blame] | 2547 | Chain = DAG.getCALLSEQ_END(Chain, NextStackOffsetVal, |
Andrew Trick | 6e0b2a0 | 2013-05-29 22:03:55 +0000 | [diff] [blame] | 2548 | DAG.getIntPtrConstant(0, true), InFlag, DL); |
Bruno Cardoso Lopes | 3ed6f87 | 2010-01-30 18:32:07 +0000 | [diff] [blame] | 2549 | InFlag = Chain.getValue(1); |
| 2550 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2551 | // Handle result values, copying them out of physregs into vregs that we |
| 2552 | // return. |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2553 | return LowerCallResult(Chain, InFlag, CallConv, IsVarArg, |
| 2554 | Ins, DL, DAG, InVals, CLI.Callee.getNode(), CLI.RetTy); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2555 | } |
| 2556 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2557 | /// LowerCallResult - Lower the result values of a call into the |
| 2558 | /// appropriate copies out of appropriate physical registers. |
| 2559 | SDValue |
| 2560 | MipsTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag, |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2561 | CallingConv::ID CallConv, bool IsVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2562 | const SmallVectorImpl<ISD::InputArg> &Ins, |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2563 | SDLoc DL, SelectionDAG &DAG, |
Akira Hatanaka | 7433b2e | 2013-03-05 22:41:55 +0000 | [diff] [blame] | 2564 | SmallVectorImpl<SDValue> &InVals, |
| 2565 | const SDNode *CallNode, |
| 2566 | const Type *RetTy) const { |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2567 | // Assign locations to each value returned by this call. |
| 2568 | SmallVector<CCValAssign, 16> RVLocs; |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2569 | CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), |
Akira Hatanaka | 864f660 | 2012-06-14 21:10:56 +0000 | [diff] [blame] | 2570 | getTargetMachine(), RVLocs, *DAG.getContext()); |
Akira Hatanaka | ad341d4 | 2013-08-20 23:38:40 +0000 | [diff] [blame] | 2571 | MipsCC MipsCCInfo(CallConv, IsO32, Subtarget->isFP64bit(), CCInfo); |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 2572 | |
Reed Kotler | c673f9c | 2013-08-30 19:40:56 +0000 | [diff] [blame] | 2573 | MipsCCInfo.analyzeCallResult(Ins, Subtarget->mipsSEUsesSoftFloat(), |
Akira Hatanaka | 7433b2e | 2013-03-05 22:41:55 +0000 | [diff] [blame] | 2574 | CallNode, RetTy); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2575 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2576 | // Copy all of the result registers out of their specified physreg. |
| 2577 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2578 | SDValue Val = DAG.getCopyFromReg(Chain, DL, RVLocs[i].getLocReg(), |
Akira Hatanaka | 7433b2e | 2013-03-05 22:41:55 +0000 | [diff] [blame] | 2579 | RVLocs[i].getLocVT(), InFlag); |
| 2580 | Chain = Val.getValue(1); |
| 2581 | InFlag = Val.getValue(2); |
| 2582 | |
| 2583 | if (RVLocs[i].getValVT() != RVLocs[i].getLocVT()) |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2584 | Val = DAG.getNode(ISD::BITCAST, DL, RVLocs[i].getValVT(), Val); |
Akira Hatanaka | 7433b2e | 2013-03-05 22:41:55 +0000 | [diff] [blame] | 2585 | |
| 2586 | InVals.push_back(Val); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2587 | } |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 2588 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2589 | return Chain; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2590 | } |
| 2591 | |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 2592 | //===----------------------------------------------------------------------===// |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2593 | // Formal Arguments Calling Convention Implementation |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 2594 | //===----------------------------------------------------------------------===// |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2595 | /// LowerFormalArguments - transform physical registers into virtual registers |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 2596 | /// and generate load operations for arguments places on the stack. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2597 | SDValue |
| 2598 | MipsTargetLowering::LowerFormalArguments(SDValue Chain, |
Akira Hatanaka | 0bf3dfb | 2011-04-15 21:00:26 +0000 | [diff] [blame] | 2599 | CallingConv::ID CallConv, |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2600 | bool IsVarArg, |
Akira Hatanaka | 8209968 | 2011-12-19 19:52:25 +0000 | [diff] [blame] | 2601 | const SmallVectorImpl<ISD::InputArg> &Ins, |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2602 | SDLoc DL, SelectionDAG &DAG, |
Akira Hatanaka | 0bf3dfb | 2011-04-15 21:00:26 +0000 | [diff] [blame] | 2603 | SmallVectorImpl<SDValue> &InVals) |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 2604 | const { |
Bruno Cardoso Lopes | f7f3b50 | 2008-08-04 07:12:52 +0000 | [diff] [blame] | 2605 | MachineFunction &MF = DAG.getMachineFunction(); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2606 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Bruno Cardoso Lopes | a2b1bb5 | 2007-08-28 05:08:16 +0000 | [diff] [blame] | 2607 | MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>(); |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 2608 | |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2609 | MipsFI->setVarArgsFrameIndex(0); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2610 | |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 2611 | // Used with vargs to acumulate store chains. |
| 2612 | std::vector<SDValue> OutChains; |
| 2613 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2614 | // Assign locations to all of the incoming arguments. |
| 2615 | SmallVector<CCValAssign, 16> ArgLocs; |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2616 | CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), |
Akira Hatanaka | 8209968 | 2011-12-19 19:52:25 +0000 | [diff] [blame] | 2617 | getTargetMachine(), ArgLocs, *DAG.getContext()); |
Akira Hatanaka | ad341d4 | 2013-08-20 23:38:40 +0000 | [diff] [blame] | 2618 | MipsCC MipsCCInfo(CallConv, IsO32, Subtarget->isFP64bit(), CCInfo); |
Akira Hatanaka | 5fdee6d | 2013-03-05 22:13:04 +0000 | [diff] [blame] | 2619 | Function::const_arg_iterator FuncArg = |
| 2620 | DAG.getMachineFunction().getFunction()->arg_begin(); |
Reed Kotler | c673f9c | 2013-08-30 19:40:56 +0000 | [diff] [blame] | 2621 | bool UseSoftFloat = Subtarget->mipsSEUsesSoftFloat(); |
Bruno Cardoso Lopes | 2ab22d1 | 2007-07-11 23:16:16 +0000 | [diff] [blame] | 2622 | |
Akira Hatanaka | 5fdee6d | 2013-03-05 22:13:04 +0000 | [diff] [blame] | 2623 | MipsCCInfo.analyzeFormalArguments(Ins, UseSoftFloat, FuncArg); |
Akira Hatanaka | b33b34a | 2012-10-30 19:37:25 +0000 | [diff] [blame] | 2624 | MipsFI->setFormalArgInfo(CCInfo.getNextStackOffset(), |
| 2625 | MipsCCInfo.hasByValArg()); |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 2626 | |
Akira Hatanaka | 4618e0b | 2012-10-27 00:44:39 +0000 | [diff] [blame] | 2627 | unsigned CurArgIdx = 0; |
Akira Hatanaka | fe30a9b | 2012-10-27 00:29:43 +0000 | [diff] [blame] | 2628 | MipsCC::byval_iterator ByValArg = MipsCCInfo.byval_begin(); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 2629 | |
Akira Hatanaka | 4618e0b | 2012-10-27 00:44:39 +0000 | [diff] [blame] | 2630 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2631 | CCValAssign &VA = ArgLocs[i]; |
Akira Hatanaka | 4618e0b | 2012-10-27 00:44:39 +0000 | [diff] [blame] | 2632 | std::advance(FuncArg, Ins[i].OrigArgIndex - CurArgIdx); |
| 2633 | CurArgIdx = Ins[i].OrigArgIndex; |
Akira Hatanaka | feaa4c3 | 2011-10-28 19:55:48 +0000 | [diff] [blame] | 2634 | EVT ValVT = VA.getValVT(); |
Akira Hatanaka | 3a5257d | 2011-11-12 02:29:58 +0000 | [diff] [blame] | 2635 | ISD::ArgFlagsTy Flags = Ins[i].Flags; |
| 2636 | bool IsRegLoc = VA.isRegLoc(); |
| 2637 | |
| 2638 | if (Flags.isByVal()) { |
| 2639 | assert(Flags.getByValSize() && |
| 2640 | "ByVal args of size 0 should have been ignored by front-end."); |
Akira Hatanaka | fe30a9b | 2012-10-27 00:29:43 +0000 | [diff] [blame] | 2641 | assert(ByValArg != MipsCCInfo.byval_end()); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2642 | copyByValRegs(Chain, DL, OutChains, DAG, Flags, InVals, &*FuncArg, |
Akira Hatanaka | fe30a9b | 2012-10-27 00:29:43 +0000 | [diff] [blame] | 2643 | MipsCCInfo, *ByValArg); |
| 2644 | ++ByValArg; |
Akira Hatanaka | 3a5257d | 2011-11-12 02:29:58 +0000 | [diff] [blame] | 2645 | continue; |
| 2646 | } |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2647 | |
| 2648 | // Arguments stored on registers |
Akira Hatanaka | 3a5257d | 2011-11-12 02:29:58 +0000 | [diff] [blame] | 2649 | if (IsRegLoc) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2650 | EVT RegVT = VA.getLocVT(); |
Akira Hatanaka | b4d8d31 | 2011-05-24 00:23:52 +0000 | [diff] [blame] | 2651 | unsigned ArgReg = VA.getLocReg(); |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2652 | const TargetRegisterClass *RC; |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 2653 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2654 | if (RegVT == MVT::i32) |
Reed Kotler | bacbf1c | 2012-12-20 06:06:35 +0000 | [diff] [blame] | 2655 | RC = Subtarget->inMips16Mode()? &Mips::CPU16RegsRegClass : |
Akira Hatanaka | 1858786 | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 2656 | &Mips::GPR32RegClass; |
Akira Hatanaka | 9593484 | 2011-09-24 01:34:44 +0000 | [diff] [blame] | 2657 | else if (RegVT == MVT::i64) |
Akira Hatanaka | 1858786 | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 2658 | RC = &Mips::GPR64RegClass; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2659 | else if (RegVT == MVT::f32) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2660 | RC = &Mips::FGR32RegClass; |
Akira Hatanaka | 09dd60f | 2011-09-26 21:37:50 +0000 | [diff] [blame] | 2661 | else if (RegVT == MVT::f64) |
Akira Hatanaka | ad341d4 | 2013-08-20 23:38:40 +0000 | [diff] [blame] | 2662 | RC = Subtarget->isFP64bit() ? &Mips::FGR64RegClass : |
| 2663 | &Mips::AFGR64RegClass; |
Akira Hatanaka | 09dd60f | 2011-09-26 21:37:50 +0000 | [diff] [blame] | 2664 | else |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 2665 | llvm_unreachable("RegVT not supported by FormalArguments Lowering"); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2666 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2667 | // Transform the arguments stored on |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2668 | // physical registers into virtual ones |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2669 | unsigned Reg = addLiveIn(DAG.getMachineFunction(), ArgReg, RC); |
| 2670 | SDValue ArgValue = DAG.getCopyFromReg(Chain, DL, Reg, RegVT); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2671 | |
| 2672 | // If this is an 8 or 16-bit value, it has been passed promoted |
| 2673 | // 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] | 2674 | // truncate to the right size. |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 2675 | if (VA.getLocInfo() != CCValAssign::Full) { |
Chris Lattner | d401507 | 2009-03-26 05:28:14 +0000 | [diff] [blame] | 2676 | unsigned Opcode = 0; |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 2677 | if (VA.getLocInfo() == CCValAssign::SExt) |
| 2678 | Opcode = ISD::AssertSext; |
| 2679 | else if (VA.getLocInfo() == CCValAssign::ZExt) |
| 2680 | Opcode = ISD::AssertZext; |
Chris Lattner | d401507 | 2009-03-26 05:28:14 +0000 | [diff] [blame] | 2681 | if (Opcode) |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2682 | ArgValue = DAG.getNode(Opcode, DL, RegVT, ArgValue, |
Akira Hatanaka | feaa4c3 | 2011-10-28 19:55:48 +0000 | [diff] [blame] | 2683 | DAG.getValueType(ValVT)); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2684 | ArgValue = DAG.getNode(ISD::TRUNCATE, DL, ValVT, ArgValue); |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 2685 | } |
| 2686 | |
Akira Hatanaka | 5fdee6d | 2013-03-05 22:13:04 +0000 | [diff] [blame] | 2687 | // Handle floating point arguments passed in integer registers and |
| 2688 | // long double arguments passed in floating point registers. |
Akira Hatanaka | feaa4c3 | 2011-10-28 19:55:48 +0000 | [diff] [blame] | 2689 | if ((RegVT == MVT::i32 && ValVT == MVT::f32) || |
Akira Hatanaka | 5fdee6d | 2013-03-05 22:13:04 +0000 | [diff] [blame] | 2690 | (RegVT == MVT::i64 && ValVT == MVT::f64) || |
| 2691 | (RegVT == MVT::f64 && ValVT == MVT::i64)) |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2692 | ArgValue = DAG.getNode(ISD::BITCAST, DL, ValVT, ArgValue); |
Akira Hatanaka | feaa4c3 | 2011-10-28 19:55:48 +0000 | [diff] [blame] | 2693 | else if (IsO32 && RegVT == MVT::i32 && ValVT == MVT::f64) { |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2694 | unsigned Reg2 = addLiveIn(DAG.getMachineFunction(), |
Akira Hatanaka | feaa4c3 | 2011-10-28 19:55:48 +0000 | [diff] [blame] | 2695 | getNextIntArgReg(ArgReg), RC); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2696 | SDValue ArgValue2 = DAG.getCopyFromReg(Chain, DL, Reg2, RegVT); |
Akira Hatanaka | feaa4c3 | 2011-10-28 19:55:48 +0000 | [diff] [blame] | 2697 | if (!Subtarget->isLittle()) |
| 2698 | std::swap(ArgValue, ArgValue2); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2699 | ArgValue = DAG.getNode(MipsISD::BuildPairF64, DL, MVT::f64, |
Akira Hatanaka | feaa4c3 | 2011-10-28 19:55:48 +0000 | [diff] [blame] | 2700 | ArgValue, ArgValue2); |
Bruno Cardoso Lopes | b53db4f | 2009-03-19 02:12:28 +0000 | [diff] [blame] | 2701 | } |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2702 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2703 | InVals.push_back(ArgValue); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 2704 | } else { // VA.isRegLoc() |
| 2705 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2706 | // sanity check |
| 2707 | assert(VA.isMemLoc()); |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 2708 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2709 | // The stack pointer offset is relative to the caller stack frame. |
Akira Hatanaka | fe30a9b | 2012-10-27 00:29:43 +0000 | [diff] [blame] | 2710 | int FI = MFI->CreateFixedObject(ValVT.getSizeInBits()/8, |
Akira Hatanaka | b4d8d31 | 2011-05-24 00:23:52 +0000 | [diff] [blame] | 2711 | VA.getLocMemOffset(), true); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2712 | |
| 2713 | // Create load nodes to retrieve arguments from the stack |
Akira Hatanaka | fe30a9b | 2012-10-27 00:29:43 +0000 | [diff] [blame] | 2714 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2715 | InVals.push_back(DAG.getLoad(ValVT, DL, Chain, FIN, |
Akira Hatanaka | fe30a9b | 2012-10-27 00:29:43 +0000 | [diff] [blame] | 2716 | MachinePointerInfo::getFixedStack(FI), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2717 | false, false, false, 0)); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2718 | } |
| 2719 | } |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 2720 | |
| 2721 | // The mips ABIs for returning structs by value requires that we copy |
| 2722 | // the sret argument into $v0 for the return. Save the argument into |
| 2723 | // a virtual register so that we can access it from the return points. |
| 2724 | if (DAG.getMachineFunction().getFunction()->hasStructRetAttr()) { |
| 2725 | unsigned Reg = MipsFI->getSRetReturnReg(); |
| 2726 | if (!Reg) { |
Akira Hatanaka | 30580ce | 2012-10-19 22:11:40 +0000 | [diff] [blame] | 2727 | Reg = MF.getRegInfo(). |
| 2728 | createVirtualRegister(getRegClassFor(IsN64 ? MVT::i64 : MVT::i32)); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 2729 | MipsFI->setSRetReturnReg(Reg); |
| 2730 | } |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2731 | SDValue Copy = DAG.getCopyToReg(DAG.getEntryNode(), DL, Reg, InVals[0]); |
| 2732 | Chain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, Copy, Chain); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 2733 | } |
| 2734 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2735 | if (IsVarArg) |
| 2736 | writeVarArgRegs(OutChains, MipsCCInfo, Chain, DL, DAG); |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 2737 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2738 | // 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] | 2739 | // the size of Ins and InVals. This only happens when on varg functions |
| 2740 | if (!OutChains.empty()) { |
| 2741 | OutChains.push_back(Chain); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2742 | Chain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, |
Bruno Cardoso Lopes | b37a742 | 2010-02-06 19:20:49 +0000 | [diff] [blame] | 2743 | &OutChains[0], OutChains.size()); |
| 2744 | } |
| 2745 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2746 | return Chain; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2747 | } |
| 2748 | |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 2749 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2750 | // Return Value Calling Convention Implementation |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 2751 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2752 | |
Akira Hatanaka | 97d9f08 | 2012-10-10 01:27:09 +0000 | [diff] [blame] | 2753 | bool |
| 2754 | MipsTargetLowering::CanLowerReturn(CallingConv::ID CallConv, |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2755 | MachineFunction &MF, bool IsVarArg, |
Akira Hatanaka | 97d9f08 | 2012-10-10 01:27:09 +0000 | [diff] [blame] | 2756 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 2757 | LLVMContext &Context) const { |
| 2758 | SmallVector<CCValAssign, 16> RVLocs; |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2759 | CCState CCInfo(CallConv, IsVarArg, MF, getTargetMachine(), |
Akira Hatanaka | 97d9f08 | 2012-10-10 01:27:09 +0000 | [diff] [blame] | 2760 | RVLocs, Context); |
| 2761 | return CCInfo.CheckReturn(Outs, RetCC_Mips); |
| 2762 | } |
| 2763 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2764 | SDValue |
| 2765 | MipsTargetLowering::LowerReturn(SDValue Chain, |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2766 | CallingConv::ID CallConv, bool IsVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2767 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 2768 | const SmallVectorImpl<SDValue> &OutVals, |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2769 | SDLoc DL, SelectionDAG &DAG) const { |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2770 | // CCValAssign - represent the assignment of |
| 2771 | // the return value to a location |
| 2772 | SmallVector<CCValAssign, 16> RVLocs; |
Akira Hatanaka | 7433b2e | 2013-03-05 22:41:55 +0000 | [diff] [blame] | 2773 | MachineFunction &MF = DAG.getMachineFunction(); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2774 | |
| 2775 | // CCState - Info about the registers and stack slot. |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2776 | CCState CCInfo(CallConv, IsVarArg, MF, getTargetMachine(), RVLocs, |
Akira Hatanaka | 7433b2e | 2013-03-05 22:41:55 +0000 | [diff] [blame] | 2777 | *DAG.getContext()); |
Akira Hatanaka | ad341d4 | 2013-08-20 23:38:40 +0000 | [diff] [blame] | 2778 | MipsCC MipsCCInfo(CallConv, IsO32, Subtarget->isFP64bit(), CCInfo); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2779 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2780 | // Analyze return values. |
Reed Kotler | c673f9c | 2013-08-30 19:40:56 +0000 | [diff] [blame] | 2781 | MipsCCInfo.analyzeReturn(Outs, Subtarget->mipsSEUsesSoftFloat(), |
Akira Hatanaka | 7433b2e | 2013-03-05 22:41:55 +0000 | [diff] [blame] | 2782 | MF.getFunction()->getReturnType()); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2783 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2784 | SDValue Flag; |
Jakob Stoklund Olesen | d073596 | 2013-02-05 18:12:03 +0000 | [diff] [blame] | 2785 | SmallVector<SDValue, 4> RetOps(1, Chain); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2786 | |
| 2787 | // Copy the result values into the output registers. |
| 2788 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
Akira Hatanaka | 7433b2e | 2013-03-05 22:41:55 +0000 | [diff] [blame] | 2789 | SDValue Val = OutVals[i]; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2790 | CCValAssign &VA = RVLocs[i]; |
| 2791 | assert(VA.isRegLoc() && "Can only return in registers!"); |
| 2792 | |
Akira Hatanaka | 7433b2e | 2013-03-05 22:41:55 +0000 | [diff] [blame] | 2793 | if (RVLocs[i].getValVT() != RVLocs[i].getLocVT()) |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2794 | Val = DAG.getNode(ISD::BITCAST, DL, RVLocs[i].getLocVT(), Val); |
Akira Hatanaka | 7433b2e | 2013-03-05 22:41:55 +0000 | [diff] [blame] | 2795 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2796 | Chain = DAG.getCopyToReg(Chain, DL, VA.getLocReg(), Val, Flag); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2797 | |
Jakob Stoklund Olesen | d073596 | 2013-02-05 18:12:03 +0000 | [diff] [blame] | 2798 | // Guarantee that all emitted copies are stuck together with flags. |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2799 | Flag = Chain.getValue(1); |
Jakob Stoklund Olesen | d073596 | 2013-02-05 18:12:03 +0000 | [diff] [blame] | 2800 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2801 | } |
| 2802 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 2803 | // The mips ABIs for returning structs by value requires that we copy |
| 2804 | // the sret argument into $v0 for the return. We saved the argument into |
| 2805 | // a virtual register in the entry block, so now we copy the value out |
| 2806 | // and into $v0. |
Akira Hatanaka | 7433b2e | 2013-03-05 22:41:55 +0000 | [diff] [blame] | 2807 | if (MF.getFunction()->hasStructRetAttr()) { |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 2808 | MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>(); |
| 2809 | unsigned Reg = MipsFI->getSRetReturnReg(); |
| 2810 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2811 | if (!Reg) |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2812 | llvm_unreachable("sret virtual register not created in the entry block"); |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2813 | SDValue Val = DAG.getCopyFromReg(Chain, DL, Reg, getPointerTy()); |
Akira Hatanaka | 2ef5bd3 | 2012-10-24 02:10:54 +0000 | [diff] [blame] | 2814 | unsigned V0 = IsN64 ? Mips::V0_64 : Mips::V0; |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 2815 | |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2816 | Chain = DAG.getCopyToReg(Chain, DL, V0, Val, Flag); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 2817 | Flag = Chain.getValue(1); |
Jakob Stoklund Olesen | d073596 | 2013-02-05 18:12:03 +0000 | [diff] [blame] | 2818 | RetOps.push_back(DAG.getRegister(V0, getPointerTy())); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 2819 | } |
| 2820 | |
Jakob Stoklund Olesen | d073596 | 2013-02-05 18:12:03 +0000 | [diff] [blame] | 2821 | RetOps[0] = Chain; // Update chain. |
Akira Hatanaka | 182ef6f | 2012-07-10 00:19:06 +0000 | [diff] [blame] | 2822 | |
Jakob Stoklund Olesen | d073596 | 2013-02-05 18:12:03 +0000 | [diff] [blame] | 2823 | // Add the flag if we have it. |
| 2824 | if (Flag.getNode()) |
| 2825 | RetOps.push_back(Flag); |
| 2826 | |
| 2827 | // Return on Mips is always a "jr $ra" |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 2828 | return DAG.getNode(MipsISD::Ret, DL, MVT::Other, &RetOps[0], RetOps.size()); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2829 | } |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 2830 | |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 2831 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 2832 | // Mips Inline Assembly Support |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 2833 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 2834 | |
| 2835 | /// getConstraintType - Given a constraint letter, return the type of |
| 2836 | /// constraint it is for this target. |
| 2837 | MipsTargetLowering::ConstraintType MipsTargetLowering:: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2838 | getConstraintType(const std::string &Constraint) const |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 2839 | { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2840 | // Mips specific constrainy |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 2841 | // GCC config/mips/constraints.md |
| 2842 | // |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2843 | // 'd' : An address register. Equivalent to r |
| 2844 | // unless generating MIPS16 code. |
| 2845 | // 'y' : Equivalent to r; retained for |
| 2846 | // backwards compatibility. |
Eric Christopher | 1d5a392 | 2012-05-07 06:25:10 +0000 | [diff] [blame] | 2847 | // 'c' : A register suitable for use in an indirect |
| 2848 | // jump. This will always be $25 for -mabicalls. |
Eric Christopher | af97f73 | 2012-05-07 06:25:19 +0000 | [diff] [blame] | 2849 | // 'l' : The lo register. 1 word storage. |
| 2850 | // 'x' : The hilo register pair. Double word storage. |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 2851 | if (Constraint.size() == 1) { |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 2852 | switch (Constraint[0]) { |
| 2853 | default : break; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2854 | case 'd': |
| 2855 | case 'y': |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 2856 | case 'f': |
Eric Christopher | 1d5a392 | 2012-05-07 06:25:10 +0000 | [diff] [blame] | 2857 | case 'c': |
Eric Christopher | 4adbefe | 2012-05-07 06:25:15 +0000 | [diff] [blame] | 2858 | case 'l': |
Eric Christopher | af97f73 | 2012-05-07 06:25:19 +0000 | [diff] [blame] | 2859 | case 'x': |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 2860 | return C_RegisterClass; |
Jack Carter | 0b9675d | 2013-03-04 21:33:15 +0000 | [diff] [blame] | 2861 | case 'R': |
| 2862 | return C_Memory; |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 2863 | } |
| 2864 | } |
| 2865 | return TargetLowering::getConstraintType(Constraint); |
| 2866 | } |
| 2867 | |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 2868 | /// Examine constraint type and operand type and determine a weight value. |
| 2869 | /// This object must already have been set up with the operand type |
| 2870 | /// and the current alternative constraint selected. |
| 2871 | TargetLowering::ConstraintWeight |
| 2872 | MipsTargetLowering::getSingleConstraintMatchWeight( |
| 2873 | AsmOperandInfo &info, const char *constraint) const { |
| 2874 | ConstraintWeight weight = CW_Invalid; |
| 2875 | Value *CallOperandVal = info.CallOperandVal; |
| 2876 | // If we don't have a value, we can't do a match, |
| 2877 | // but allow it at the lowest weight. |
| 2878 | if (CallOperandVal == NULL) |
| 2879 | return CW_Default; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2880 | Type *type = CallOperandVal->getType(); |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 2881 | // Look at the constraint type. |
| 2882 | switch (*constraint) { |
| 2883 | default: |
| 2884 | weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint); |
| 2885 | break; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2886 | case 'd': |
| 2887 | case 'y': |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 2888 | if (type->isIntegerTy()) |
| 2889 | weight = CW_Register; |
| 2890 | break; |
| 2891 | case 'f': |
| 2892 | if (type->isFloatTy()) |
| 2893 | weight = CW_Register; |
| 2894 | break; |
Eric Christopher | 1d5a392 | 2012-05-07 06:25:10 +0000 | [diff] [blame] | 2895 | case 'c': // $25 for indirect jumps |
Eric Christopher | 4adbefe | 2012-05-07 06:25:15 +0000 | [diff] [blame] | 2896 | case 'l': // lo register |
Eric Christopher | af97f73 | 2012-05-07 06:25:19 +0000 | [diff] [blame] | 2897 | case 'x': // hilo register pair |
Eric Christopher | 1d5a392 | 2012-05-07 06:25:10 +0000 | [diff] [blame] | 2898 | if (type->isIntegerTy()) |
| 2899 | weight = CW_SpecificReg; |
| 2900 | break; |
Eric Christopher | 50ab039 | 2012-05-07 03:13:32 +0000 | [diff] [blame] | 2901 | case 'I': // signed 16 bit immediate |
Eric Christopher | e5076d4 | 2012-05-07 03:13:42 +0000 | [diff] [blame] | 2902 | case 'J': // integer zero |
Eric Christopher | f49f846 | 2012-05-07 05:46:29 +0000 | [diff] [blame] | 2903 | case 'K': // unsigned 16 bit immediate |
Eric Christopher | 5ac47bb | 2012-05-07 05:46:37 +0000 | [diff] [blame] | 2904 | case 'L': // signed 32 bit immediate where lower 16 bits are 0 |
Eric Christopher | 60cfc79 | 2012-05-07 05:46:43 +0000 | [diff] [blame] | 2905 | case 'N': // immediate in the range of -65535 to -1 (inclusive) |
Eric Christopher | 1ce2034 | 2012-05-07 05:46:48 +0000 | [diff] [blame] | 2906 | case 'O': // signed 15 bit immediate (+- 16383) |
Eric Christopher | 54412a7 | 2012-05-07 06:25:02 +0000 | [diff] [blame] | 2907 | case 'P': // immediate in the range of 65535 to 1 (inclusive) |
Eric Christopher | 50ab039 | 2012-05-07 03:13:32 +0000 | [diff] [blame] | 2908 | if (isa<ConstantInt>(CallOperandVal)) |
| 2909 | weight = CW_Constant; |
| 2910 | break; |
Jack Carter | 0b9675d | 2013-03-04 21:33:15 +0000 | [diff] [blame] | 2911 | case 'R': |
| 2912 | weight = CW_Memory; |
| 2913 | break; |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 2914 | } |
| 2915 | return weight; |
| 2916 | } |
| 2917 | |
Akira Hatanaka | bfb07b1 | 2013-08-14 00:21:25 +0000 | [diff] [blame] | 2918 | /// This is a helper function to parse a physical register string and split it |
| 2919 | /// into non-numeric and numeric parts (Prefix and Reg). The first boolean flag |
| 2920 | /// that is returned indicates whether parsing was successful. The second flag |
| 2921 | /// is true if the numeric part exists. |
| 2922 | static std::pair<bool, bool> |
| 2923 | parsePhysicalReg(const StringRef &C, std::string &Prefix, |
| 2924 | unsigned long long &Reg) { |
| 2925 | if (C.front() != '{' || C.back() != '}') |
| 2926 | return std::make_pair(false, false); |
| 2927 | |
| 2928 | // Search for the first numeric character. |
| 2929 | StringRef::const_iterator I, B = C.begin() + 1, E = C.end() - 1; |
| 2930 | I = std::find_if(B, E, std::ptr_fun(isdigit)); |
| 2931 | |
| 2932 | Prefix.assign(B, I - B); |
| 2933 | |
| 2934 | // The second flag is set to false if no numeric characters were found. |
| 2935 | if (I == E) |
| 2936 | return std::make_pair(true, false); |
| 2937 | |
| 2938 | // Parse the numeric characters. |
| 2939 | return std::make_pair(!getAsUnsignedInteger(StringRef(I, E - I), 10, Reg), |
| 2940 | true); |
| 2941 | } |
| 2942 | |
| 2943 | std::pair<unsigned, const TargetRegisterClass *> MipsTargetLowering:: |
| 2944 | parseRegForInlineAsmConstraint(const StringRef &C, MVT VT) const { |
| 2945 | const TargetRegisterInfo *TRI = getTargetMachine().getRegisterInfo(); |
| 2946 | const TargetRegisterClass *RC; |
| 2947 | std::string Prefix; |
| 2948 | unsigned long long Reg; |
| 2949 | |
| 2950 | std::pair<bool, bool> R = parsePhysicalReg(C, Prefix, Reg); |
| 2951 | |
| 2952 | if (!R.first) |
| 2953 | return std::make_pair((unsigned)0, (const TargetRegisterClass*)0); |
| 2954 | |
| 2955 | if ((Prefix == "hi" || Prefix == "lo")) { // Parse hi/lo. |
| 2956 | // No numeric characters follow "hi" or "lo". |
| 2957 | if (R.second) |
| 2958 | return std::make_pair((unsigned)0, (const TargetRegisterClass*)0); |
| 2959 | |
| 2960 | RC = TRI->getRegClass(Prefix == "hi" ? |
Akira Hatanaka | cbaf6d0 | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 2961 | Mips::HI32RegClassID : Mips::LO32RegClassID); |
Akira Hatanaka | bfb07b1 | 2013-08-14 00:21:25 +0000 | [diff] [blame] | 2962 | return std::make_pair(*(RC->begin()), RC); |
| 2963 | } |
| 2964 | |
| 2965 | if (!R.second) |
| 2966 | return std::make_pair((unsigned)0, (const TargetRegisterClass*)0); |
| 2967 | |
| 2968 | if (Prefix == "$f") { // Parse $f0-$f31. |
| 2969 | // If the size of FP registers is 64-bit or Reg is an even number, select |
| 2970 | // the 64-bit register class. Otherwise, select the 32-bit register class. |
| 2971 | if (VT == MVT::Other) |
| 2972 | VT = (Subtarget->isFP64bit() || !(Reg % 2)) ? MVT::f64 : MVT::f32; |
| 2973 | |
| 2974 | RC= getRegClassFor(VT); |
| 2975 | |
| 2976 | if (RC == &Mips::AFGR64RegClass) { |
| 2977 | assert(Reg % 2 == 0); |
| 2978 | Reg >>= 1; |
| 2979 | } |
| 2980 | } else if (Prefix == "$fcc") { // Parse $fcc0-$fcc7. |
| 2981 | RC = TRI->getRegClass(Mips::FCCRegClassID); |
| 2982 | } else { // Parse $0-$31. |
| 2983 | assert(Prefix == "$"); |
| 2984 | RC = getRegClassFor((VT == MVT::Other) ? MVT::i32 : VT); |
| 2985 | } |
| 2986 | |
| 2987 | assert(Reg < RC->getNumRegs()); |
| 2988 | return std::make_pair(*(RC->begin() + Reg), RC); |
| 2989 | } |
| 2990 | |
Eric Christopher | 38d6426 | 2011-06-29 19:33:04 +0000 | [diff] [blame] | 2991 | /// Given a register class constraint, like 'r', if this corresponds directly |
| 2992 | /// to an LLVM register class, return a register of 0 and the register class |
| 2993 | /// pointer. |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 2994 | std::pair<unsigned, const TargetRegisterClass*> MipsTargetLowering:: |
Chad Rosier | 5b3fca5 | 2013-06-22 18:37:38 +0000 | [diff] [blame] | 2995 | getRegForInlineAsmConstraint(const std::string &Constraint, MVT VT) const |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 2996 | { |
| 2997 | if (Constraint.size() == 1) { |
| 2998 | switch (Constraint[0]) { |
Eric Christopher | 314aff1 | 2011-06-29 19:04:31 +0000 | [diff] [blame] | 2999 | case 'd': // Address register. Same as 'r' unless generating MIPS16 code. |
| 3000 | case 'y': // Same as 'r'. Exists for compatibility. |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 3001 | case 'r': |
Akira Hatanaka | afc945b | 2012-09-12 23:27:55 +0000 | [diff] [blame] | 3002 | if (VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8) { |
| 3003 | if (Subtarget->inMips16Mode()) |
| 3004 | return std::make_pair(0U, &Mips::CPU16RegsRegClass); |
Akira Hatanaka | 1858786 | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 3005 | return std::make_pair(0U, &Mips::GPR32RegClass); |
Akira Hatanaka | afc945b | 2012-09-12 23:27:55 +0000 | [diff] [blame] | 3006 | } |
Jack Carter | 10de025 | 2012-07-02 23:35:23 +0000 | [diff] [blame] | 3007 | if (VT == MVT::i64 && !HasMips64) |
Akira Hatanaka | 1858786 | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 3008 | return std::make_pair(0U, &Mips::GPR32RegClass); |
Eric Christopher | 0ed1f76 | 2012-05-07 03:13:22 +0000 | [diff] [blame] | 3009 | if (VT == MVT::i64 && HasMips64) |
Akira Hatanaka | 1858786 | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 3010 | return std::make_pair(0U, &Mips::GPR64RegClass); |
Eric Christopher | 0ed1f76 | 2012-05-07 03:13:22 +0000 | [diff] [blame] | 3011 | // This will generate an error message |
| 3012 | return std::make_pair(0u, static_cast<const TargetRegisterClass*>(0)); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 3013 | case 'f': |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3014 | if (VT == MVT::f32) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 3015 | return std::make_pair(0U, &Mips::FGR32RegClass); |
Akira Hatanaka | cb9dd72 | 2012-01-04 02:45:01 +0000 | [diff] [blame] | 3016 | if ((VT == MVT::f64) && (!Subtarget->isSingleFloat())) { |
| 3017 | if (Subtarget->isFP64bit()) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 3018 | return std::make_pair(0U, &Mips::FGR64RegClass); |
| 3019 | return std::make_pair(0U, &Mips::AFGR64RegClass); |
Akira Hatanaka | cb9dd72 | 2012-01-04 02:45:01 +0000 | [diff] [blame] | 3020 | } |
Eric Christopher | 1d5a392 | 2012-05-07 06:25:10 +0000 | [diff] [blame] | 3021 | break; |
| 3022 | case 'c': // register suitable for indirect jump |
| 3023 | if (VT == MVT::i32) |
Akira Hatanaka | 1858786 | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 3024 | return std::make_pair((unsigned)Mips::T9, &Mips::GPR32RegClass); |
Eric Christopher | 1d5a392 | 2012-05-07 06:25:10 +0000 | [diff] [blame] | 3025 | assert(VT == MVT::i64 && "Unexpected type."); |
Akira Hatanaka | 1858786 | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 3026 | return std::make_pair((unsigned)Mips::T9_64, &Mips::GPR64RegClass); |
Eric Christopher | 4adbefe | 2012-05-07 06:25:15 +0000 | [diff] [blame] | 3027 | case 'l': // register suitable for indirect jump |
| 3028 | if (VT == MVT::i32) |
Akira Hatanaka | cbaf6d0 | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 3029 | return std::make_pair((unsigned)Mips::LO0, &Mips::LO32RegClass); |
| 3030 | return std::make_pair((unsigned)Mips::LO0_64, &Mips::LO64RegClass); |
Eric Christopher | af97f73 | 2012-05-07 06:25:19 +0000 | [diff] [blame] | 3031 | case 'x': // register suitable for indirect jump |
| 3032 | // Fixme: Not triggering the use of both hi and low |
| 3033 | // This will generate an error message |
| 3034 | return std::make_pair(0u, static_cast<const TargetRegisterClass*>(0)); |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 3035 | } |
| 3036 | } |
Akira Hatanaka | bfb07b1 | 2013-08-14 00:21:25 +0000 | [diff] [blame] | 3037 | |
| 3038 | std::pair<unsigned, const TargetRegisterClass *> R; |
| 3039 | R = parseRegForInlineAsmConstraint(Constraint, VT); |
| 3040 | |
| 3041 | if (R.second) |
| 3042 | return R; |
| 3043 | |
Bruno Cardoso Lopes | 84f47c5 | 2007-08-21 16:09:25 +0000 | [diff] [blame] | 3044 | return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); |
| 3045 | } |
| 3046 | |
Eric Christopher | 50ab039 | 2012-05-07 03:13:32 +0000 | [diff] [blame] | 3047 | /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops |
| 3048 | /// vector. If it is invalid, don't add anything to Ops. |
| 3049 | void MipsTargetLowering::LowerAsmOperandForConstraint(SDValue Op, |
| 3050 | std::string &Constraint, |
| 3051 | std::vector<SDValue>&Ops, |
| 3052 | SelectionDAG &DAG) const { |
| 3053 | SDValue Result(0, 0); |
| 3054 | |
| 3055 | // Only support length 1 constraints for now. |
| 3056 | if (Constraint.length() > 1) return; |
| 3057 | |
| 3058 | char ConstraintLetter = Constraint[0]; |
| 3059 | switch (ConstraintLetter) { |
| 3060 | default: break; // This will fall through to the generic implementation |
| 3061 | case 'I': // Signed 16 bit constant |
| 3062 | // If this fails, the parent routine will give an error |
| 3063 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { |
| 3064 | EVT Type = Op.getValueType(); |
| 3065 | int64_t Val = C->getSExtValue(); |
| 3066 | if (isInt<16>(Val)) { |
| 3067 | Result = DAG.getTargetConstant(Val, Type); |
| 3068 | break; |
| 3069 | } |
| 3070 | } |
| 3071 | return; |
Eric Christopher | e5076d4 | 2012-05-07 03:13:42 +0000 | [diff] [blame] | 3072 | case 'J': // integer zero |
| 3073 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { |
| 3074 | EVT Type = Op.getValueType(); |
| 3075 | int64_t Val = C->getZExtValue(); |
| 3076 | if (Val == 0) { |
| 3077 | Result = DAG.getTargetConstant(0, Type); |
| 3078 | break; |
| 3079 | } |
| 3080 | } |
| 3081 | return; |
Eric Christopher | f49f846 | 2012-05-07 05:46:29 +0000 | [diff] [blame] | 3082 | case 'K': // unsigned 16 bit immediate |
| 3083 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { |
| 3084 | EVT Type = Op.getValueType(); |
| 3085 | uint64_t Val = (uint64_t)C->getZExtValue(); |
| 3086 | if (isUInt<16>(Val)) { |
| 3087 | Result = DAG.getTargetConstant(Val, Type); |
| 3088 | break; |
| 3089 | } |
| 3090 | } |
| 3091 | return; |
Eric Christopher | 5ac47bb | 2012-05-07 05:46:37 +0000 | [diff] [blame] | 3092 | case 'L': // signed 32 bit immediate where lower 16 bits are 0 |
| 3093 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { |
| 3094 | EVT Type = Op.getValueType(); |
| 3095 | int64_t Val = C->getSExtValue(); |
| 3096 | if ((isInt<32>(Val)) && ((Val & 0xffff) == 0)){ |
| 3097 | Result = DAG.getTargetConstant(Val, Type); |
| 3098 | break; |
| 3099 | } |
| 3100 | } |
| 3101 | return; |
Eric Christopher | 60cfc79 | 2012-05-07 05:46:43 +0000 | [diff] [blame] | 3102 | case 'N': // immediate in the range of -65535 to -1 (inclusive) |
| 3103 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { |
| 3104 | EVT Type = Op.getValueType(); |
| 3105 | int64_t Val = C->getSExtValue(); |
| 3106 | if ((Val >= -65535) && (Val <= -1)) { |
| 3107 | Result = DAG.getTargetConstant(Val, Type); |
| 3108 | break; |
| 3109 | } |
| 3110 | } |
| 3111 | return; |
Eric Christopher | 1ce2034 | 2012-05-07 05:46:48 +0000 | [diff] [blame] | 3112 | case 'O': // signed 15 bit immediate |
| 3113 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { |
| 3114 | EVT Type = Op.getValueType(); |
| 3115 | int64_t Val = C->getSExtValue(); |
| 3116 | if ((isInt<15>(Val))) { |
| 3117 | Result = DAG.getTargetConstant(Val, Type); |
| 3118 | break; |
| 3119 | } |
| 3120 | } |
| 3121 | return; |
Eric Christopher | 54412a7 | 2012-05-07 06:25:02 +0000 | [diff] [blame] | 3122 | case 'P': // immediate in the range of 1 to 65535 (inclusive) |
| 3123 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { |
| 3124 | EVT Type = Op.getValueType(); |
| 3125 | int64_t Val = C->getSExtValue(); |
| 3126 | if ((Val <= 65535) && (Val >= 1)) { |
| 3127 | Result = DAG.getTargetConstant(Val, Type); |
| 3128 | break; |
| 3129 | } |
| 3130 | } |
| 3131 | return; |
Eric Christopher | 50ab039 | 2012-05-07 03:13:32 +0000 | [diff] [blame] | 3132 | } |
| 3133 | |
| 3134 | if (Result.getNode()) { |
| 3135 | Ops.push_back(Result); |
| 3136 | return; |
| 3137 | } |
| 3138 | |
| 3139 | TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG); |
| 3140 | } |
| 3141 | |
Dan Gohman | 6520e20 | 2008-10-18 02:06:02 +0000 | [diff] [blame] | 3142 | bool |
Akira Hatanaka | 94e4728 | 2012-11-17 00:25:41 +0000 | [diff] [blame] | 3143 | MipsTargetLowering::isLegalAddressingMode(const AddrMode &AM, Type *Ty) const { |
| 3144 | // No global is ever allowed as a base. |
| 3145 | if (AM.BaseGV) |
| 3146 | return false; |
| 3147 | |
| 3148 | switch (AM.Scale) { |
| 3149 | case 0: // "r+i" or just "i", depending on HasBaseReg. |
| 3150 | break; |
| 3151 | case 1: |
| 3152 | if (!AM.HasBaseReg) // allow "r+i". |
| 3153 | break; |
| 3154 | return false; // disallow "r+r" or "r+r+i". |
| 3155 | default: |
| 3156 | return false; |
| 3157 | } |
| 3158 | |
| 3159 | return true; |
| 3160 | } |
| 3161 | |
| 3162 | bool |
Dan Gohman | 6520e20 | 2008-10-18 02:06:02 +0000 | [diff] [blame] | 3163 | MipsTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { |
| 3164 | // The Mips target isn't yet aware of offsets. |
| 3165 | return false; |
| 3166 | } |
Evan Cheng | eb2f969 | 2009-10-27 19:56:55 +0000 | [diff] [blame] | 3167 | |
Akira Hatanaka | e193b32 | 2012-06-13 19:33:32 +0000 | [diff] [blame] | 3168 | EVT MipsTargetLowering::getOptimalMemOpType(uint64_t Size, unsigned DstAlign, |
Evan Cheng | 946a3a9 | 2012-12-12 02:34:41 +0000 | [diff] [blame] | 3169 | unsigned SrcAlign, |
| 3170 | bool IsMemset, bool ZeroMemset, |
Akira Hatanaka | e193b32 | 2012-06-13 19:33:32 +0000 | [diff] [blame] | 3171 | bool MemcpyStrSrc, |
| 3172 | MachineFunction &MF) const { |
| 3173 | if (Subtarget->hasMips64()) |
| 3174 | return MVT::i64; |
| 3175 | |
| 3176 | return MVT::i32; |
| 3177 | } |
| 3178 | |
Evan Cheng | a1eaa3c | 2009-10-28 01:43:28 +0000 | [diff] [blame] | 3179 | bool MipsTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const { |
| 3180 | if (VT != MVT::f32 && VT != MVT::f64) |
| 3181 | return false; |
Bruno Cardoso Lopes | 6b90282 | 2011-01-18 19:41:41 +0000 | [diff] [blame] | 3182 | if (Imm.isNegZero()) |
| 3183 | return false; |
Evan Cheng | eb2f969 | 2009-10-27 19:56:55 +0000 | [diff] [blame] | 3184 | return Imm.isZero(); |
| 3185 | } |
Akira Hatanaka | 6c2cf8b | 2012-02-03 04:33:00 +0000 | [diff] [blame] | 3186 | |
| 3187 | unsigned MipsTargetLowering::getJumpTableEncoding() const { |
| 3188 | if (IsN64) |
| 3189 | return MachineJumpTableInfo::EK_GPRel64BlockAddress; |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 3190 | |
Akira Hatanaka | 6c2cf8b | 2012-02-03 04:33:00 +0000 | [diff] [blame] | 3191 | return TargetLowering::getJumpTableEncoding(); |
| 3192 | } |
Akira Hatanaka | 7887c90 | 2012-10-26 23:56:38 +0000 | [diff] [blame] | 3193 | |
Akira Hatanaka | 1e3e869 | 2013-03-05 22:54:59 +0000 | [diff] [blame] | 3194 | /// This function returns true if CallSym is a long double emulation routine. |
| 3195 | static bool isF128SoftLibCall(const char *CallSym) { |
| 3196 | const char *const LibCalls[] = |
| 3197 | {"__addtf3", "__divtf3", "__eqtf2", "__extenddftf2", "__extendsftf2", |
| 3198 | "__fixtfdi", "__fixtfsi", "__fixtfti", "__fixunstfdi", "__fixunstfsi", |
| 3199 | "__fixunstfti", "__floatditf", "__floatsitf", "__floattitf", |
| 3200 | "__floatunditf", "__floatunsitf", "__floatuntitf", "__getf2", "__gttf2", |
| 3201 | "__letf2", "__lttf2", "__multf3", "__netf2", "__powitf2", "__subtf3", |
| 3202 | "__trunctfdf2", "__trunctfsf2", "__unordtf2", |
| 3203 | "ceill", "copysignl", "cosl", "exp2l", "expl", "floorl", "fmal", "fmodl", |
| 3204 | "log10l", "log2l", "logl", "nearbyintl", "powl", "rintl", "sinl", "sqrtl", |
| 3205 | "truncl"}; |
| 3206 | |
| 3207 | const char * const *End = LibCalls + array_lengthof(LibCalls); |
| 3208 | |
| 3209 | // Check that LibCalls is sorted alphabetically. |
Akira Hatanaka | 5ac065a | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 3210 | MipsTargetLowering::LTStr Comp; |
Akira Hatanaka | 1e3e869 | 2013-03-05 22:54:59 +0000 | [diff] [blame] | 3211 | |
Akira Hatanaka | 5ac065a | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 3212 | #ifndef NDEBUG |
Akira Hatanaka | 1e3e869 | 2013-03-05 22:54:59 +0000 | [diff] [blame] | 3213 | for (const char * const *I = LibCalls; I < End - 1; ++I) |
| 3214 | assert(Comp(*I, *(I + 1))); |
| 3215 | #endif |
| 3216 | |
Akira Hatanaka | 5ac065a | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 3217 | return std::binary_search(LibCalls, End, CallSym, Comp); |
Akira Hatanaka | 1e3e869 | 2013-03-05 22:54:59 +0000 | [diff] [blame] | 3218 | } |
| 3219 | |
| 3220 | /// This function returns true if Ty is fp128 or i128 which was originally a |
| 3221 | /// fp128. |
| 3222 | static bool originalTypeIsF128(const Type *Ty, const SDNode *CallNode) { |
| 3223 | if (Ty->isFP128Ty()) |
| 3224 | return true; |
| 3225 | |
| 3226 | const ExternalSymbolSDNode *ES = |
| 3227 | dyn_cast_or_null<const ExternalSymbolSDNode>(CallNode); |
| 3228 | |
| 3229 | // If the Ty is i128 and the function being called is a long double emulation |
| 3230 | // routine, then the original type is f128. |
| 3231 | return (ES && Ty->isIntegerTy(128) && isF128SoftLibCall(ES->getSymbol())); |
| 3232 | } |
| 3233 | |
Reed Kotler | 4609091 | 2013-05-10 22:25:39 +0000 | [diff] [blame] | 3234 | MipsTargetLowering::MipsCC::SpecialCallingConvType |
| 3235 | MipsTargetLowering::getSpecialCallingConv(SDValue Callee) const { |
| 3236 | MipsCC::SpecialCallingConvType SpecialCallingConv = |
| 3237 | MipsCC::NoSpecialCallingConv;; |
| 3238 | if (Subtarget->inMips16HardFloat()) { |
| 3239 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
| 3240 | llvm::StringRef Sym = G->getGlobal()->getName(); |
| 3241 | Function *F = G->getGlobal()->getParent()->getFunction(Sym); |
| 3242 | if (F->hasFnAttribute("__Mips16RetHelper")) { |
| 3243 | SpecialCallingConv = MipsCC::Mips16RetHelperConv; |
| 3244 | } |
| 3245 | } |
| 3246 | } |
| 3247 | return SpecialCallingConv; |
| 3248 | } |
| 3249 | |
| 3250 | MipsTargetLowering::MipsCC::MipsCC( |
Akira Hatanaka | ad341d4 | 2013-08-20 23:38:40 +0000 | [diff] [blame] | 3251 | CallingConv::ID CC, bool IsO32_, bool IsFP64_, CCState &Info, |
Reed Kotler | 4609091 | 2013-05-10 22:25:39 +0000 | [diff] [blame] | 3252 | MipsCC::SpecialCallingConvType SpecialCallingConv_) |
Akira Hatanaka | ad341d4 | 2013-08-20 23:38:40 +0000 | [diff] [blame] | 3253 | : CCInfo(Info), CallConv(CC), IsO32(IsO32_), IsFP64(IsFP64_), |
Reed Kotler | 4609091 | 2013-05-10 22:25:39 +0000 | [diff] [blame] | 3254 | SpecialCallingConv(SpecialCallingConv_){ |
Akira Hatanaka | 7887c90 | 2012-10-26 23:56:38 +0000 | [diff] [blame] | 3255 | // Pre-allocate reserved argument area. |
Akira Hatanaka | ffd28a4 | 2013-02-15 21:45:11 +0000 | [diff] [blame] | 3256 | CCInfo.AllocateStack(reservedArgArea(), 1); |
Akira Hatanaka | 7887c90 | 2012-10-26 23:56:38 +0000 | [diff] [blame] | 3257 | } |
| 3258 | |
Reed Kotler | 4609091 | 2013-05-10 22:25:39 +0000 | [diff] [blame] | 3259 | |
Akira Hatanaka | 7887c90 | 2012-10-26 23:56:38 +0000 | [diff] [blame] | 3260 | void MipsTargetLowering::MipsCC:: |
Akira Hatanaka | ffd28a4 | 2013-02-15 21:45:11 +0000 | [diff] [blame] | 3261 | analyzeCallOperands(const SmallVectorImpl<ISD::OutputArg> &Args, |
Akira Hatanaka | cb2eafd | 2013-03-05 22:20:28 +0000 | [diff] [blame] | 3262 | bool IsVarArg, bool IsSoftFloat, const SDNode *CallNode, |
| 3263 | std::vector<ArgListEntry> &FuncArgs) { |
Akira Hatanaka | ffd28a4 | 2013-02-15 21:45:11 +0000 | [diff] [blame] | 3264 | assert((CallConv != CallingConv::Fast || !IsVarArg) && |
| 3265 | "CallingConv::Fast shouldn't be used for vararg functions."); |
| 3266 | |
Akira Hatanaka | 7887c90 | 2012-10-26 23:56:38 +0000 | [diff] [blame] | 3267 | unsigned NumOpnds = Args.size(); |
Akira Hatanaka | ffd28a4 | 2013-02-15 21:45:11 +0000 | [diff] [blame] | 3268 | llvm::CCAssignFn *FixedFn = fixedArgFn(), *VarFn = varArgFn(); |
Akira Hatanaka | 7887c90 | 2012-10-26 23:56:38 +0000 | [diff] [blame] | 3269 | |
| 3270 | for (unsigned I = 0; I != NumOpnds; ++I) { |
| 3271 | MVT ArgVT = Args[I].VT; |
| 3272 | ISD::ArgFlagsTy ArgFlags = Args[I].Flags; |
| 3273 | bool R; |
| 3274 | |
| 3275 | if (ArgFlags.isByVal()) { |
| 3276 | handleByValArg(I, ArgVT, ArgVT, CCValAssign::Full, ArgFlags); |
| 3277 | continue; |
| 3278 | } |
| 3279 | |
Akira Hatanaka | ffd28a4 | 2013-02-15 21:45:11 +0000 | [diff] [blame] | 3280 | if (IsVarArg && !Args[I].IsFixed) |
Akira Hatanaka | 7887c90 | 2012-10-26 23:56:38 +0000 | [diff] [blame] | 3281 | R = VarFn(I, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, CCInfo); |
Akira Hatanaka | cb2eafd | 2013-03-05 22:20:28 +0000 | [diff] [blame] | 3282 | else { |
| 3283 | MVT RegVT = getRegVT(ArgVT, FuncArgs[Args[I].OrigArgIndex].Ty, CallNode, |
| 3284 | IsSoftFloat); |
| 3285 | R = FixedFn(I, ArgVT, RegVT, CCValAssign::Full, ArgFlags, CCInfo); |
| 3286 | } |
Akira Hatanaka | 7887c90 | 2012-10-26 23:56:38 +0000 | [diff] [blame] | 3287 | |
| 3288 | if (R) { |
| 3289 | #ifndef NDEBUG |
| 3290 | dbgs() << "Call operand #" << I << " has unhandled type " |
| 3291 | << EVT(ArgVT).getEVTString(); |
| 3292 | #endif |
| 3293 | llvm_unreachable(0); |
| 3294 | } |
| 3295 | } |
| 3296 | } |
| 3297 | |
| 3298 | void MipsTargetLowering::MipsCC:: |
Akira Hatanaka | 5fdee6d | 2013-03-05 22:13:04 +0000 | [diff] [blame] | 3299 | analyzeFormalArguments(const SmallVectorImpl<ISD::InputArg> &Args, |
| 3300 | bool IsSoftFloat, Function::const_arg_iterator FuncArg) { |
Akira Hatanaka | 7887c90 | 2012-10-26 23:56:38 +0000 | [diff] [blame] | 3301 | unsigned NumArgs = Args.size(); |
Akira Hatanaka | ffd28a4 | 2013-02-15 21:45:11 +0000 | [diff] [blame] | 3302 | llvm::CCAssignFn *FixedFn = fixedArgFn(); |
Akira Hatanaka | 5fdee6d | 2013-03-05 22:13:04 +0000 | [diff] [blame] | 3303 | unsigned CurArgIdx = 0; |
Akira Hatanaka | 7887c90 | 2012-10-26 23:56:38 +0000 | [diff] [blame] | 3304 | |
| 3305 | for (unsigned I = 0; I != NumArgs; ++I) { |
| 3306 | MVT ArgVT = Args[I].VT; |
| 3307 | ISD::ArgFlagsTy ArgFlags = Args[I].Flags; |
Akira Hatanaka | 5fdee6d | 2013-03-05 22:13:04 +0000 | [diff] [blame] | 3308 | std::advance(FuncArg, Args[I].OrigArgIndex - CurArgIdx); |
| 3309 | CurArgIdx = Args[I].OrigArgIndex; |
Akira Hatanaka | 7887c90 | 2012-10-26 23:56:38 +0000 | [diff] [blame] | 3310 | |
| 3311 | if (ArgFlags.isByVal()) { |
| 3312 | handleByValArg(I, ArgVT, ArgVT, CCValAssign::Full, ArgFlags); |
| 3313 | continue; |
| 3314 | } |
| 3315 | |
Akira Hatanaka | 5fdee6d | 2013-03-05 22:13:04 +0000 | [diff] [blame] | 3316 | MVT RegVT = getRegVT(ArgVT, FuncArg->getType(), 0, IsSoftFloat); |
| 3317 | |
| 3318 | if (!FixedFn(I, ArgVT, RegVT, CCValAssign::Full, ArgFlags, CCInfo)) |
Akira Hatanaka | 7887c90 | 2012-10-26 23:56:38 +0000 | [diff] [blame] | 3319 | continue; |
| 3320 | |
| 3321 | #ifndef NDEBUG |
| 3322 | dbgs() << "Formal Arg #" << I << " has unhandled type " |
| 3323 | << EVT(ArgVT).getEVTString(); |
| 3324 | #endif |
| 3325 | llvm_unreachable(0); |
| 3326 | } |
| 3327 | } |
| 3328 | |
Akira Hatanaka | 7433b2e | 2013-03-05 22:41:55 +0000 | [diff] [blame] | 3329 | template<typename Ty> |
| 3330 | void MipsTargetLowering::MipsCC:: |
| 3331 | analyzeReturn(const SmallVectorImpl<Ty> &RetVals, bool IsSoftFloat, |
| 3332 | const SDNode *CallNode, const Type *RetTy) const { |
Akira Hatanaka | 1e3e869 | 2013-03-05 22:54:59 +0000 | [diff] [blame] | 3333 | CCAssignFn *Fn; |
| 3334 | |
| 3335 | if (IsSoftFloat && originalTypeIsF128(RetTy, CallNode)) |
| 3336 | Fn = RetCC_F128Soft; |
| 3337 | else |
| 3338 | Fn = RetCC_Mips; |
| 3339 | |
Akira Hatanaka | 7433b2e | 2013-03-05 22:41:55 +0000 | [diff] [blame] | 3340 | for (unsigned I = 0, E = RetVals.size(); I < E; ++I) { |
| 3341 | MVT VT = RetVals[I].VT; |
| 3342 | ISD::ArgFlagsTy Flags = RetVals[I].Flags; |
| 3343 | MVT RegVT = this->getRegVT(VT, RetTy, CallNode, IsSoftFloat); |
| 3344 | |
Akira Hatanaka | 1e3e869 | 2013-03-05 22:54:59 +0000 | [diff] [blame] | 3345 | if (Fn(I, VT, RegVT, CCValAssign::Full, Flags, this->CCInfo)) { |
Akira Hatanaka | 7433b2e | 2013-03-05 22:41:55 +0000 | [diff] [blame] | 3346 | #ifndef NDEBUG |
| 3347 | dbgs() << "Call result #" << I << " has unhandled type " |
| 3348 | << EVT(VT).getEVTString() << '\n'; |
| 3349 | #endif |
| 3350 | llvm_unreachable(0); |
| 3351 | } |
| 3352 | } |
| 3353 | } |
| 3354 | |
| 3355 | void MipsTargetLowering::MipsCC:: |
| 3356 | analyzeCallResult(const SmallVectorImpl<ISD::InputArg> &Ins, bool IsSoftFloat, |
| 3357 | const SDNode *CallNode, const Type *RetTy) const { |
| 3358 | analyzeReturn(Ins, IsSoftFloat, CallNode, RetTy); |
| 3359 | } |
| 3360 | |
| 3361 | void MipsTargetLowering::MipsCC:: |
| 3362 | analyzeReturn(const SmallVectorImpl<ISD::OutputArg> &Outs, bool IsSoftFloat, |
| 3363 | const Type *RetTy) const { |
| 3364 | analyzeReturn(Outs, IsSoftFloat, 0, RetTy); |
| 3365 | } |
| 3366 | |
Akira Hatanaka | 7887c90 | 2012-10-26 23:56:38 +0000 | [diff] [blame] | 3367 | void |
| 3368 | MipsTargetLowering::MipsCC::handleByValArg(unsigned ValNo, MVT ValVT, |
| 3369 | MVT LocVT, |
| 3370 | CCValAssign::LocInfo LocInfo, |
| 3371 | ISD::ArgFlagsTy ArgFlags) { |
| 3372 | assert(ArgFlags.getByValSize() && "Byval argument's size shouldn't be 0."); |
| 3373 | |
| 3374 | struct ByValArgInfo ByVal; |
Akira Hatanaka | ffd28a4 | 2013-02-15 21:45:11 +0000 | [diff] [blame] | 3375 | unsigned RegSize = regSize(); |
Akira Hatanaka | 7887c90 | 2012-10-26 23:56:38 +0000 | [diff] [blame] | 3376 | unsigned ByValSize = RoundUpToAlignment(ArgFlags.getByValSize(), RegSize); |
| 3377 | unsigned Align = std::min(std::max(ArgFlags.getByValAlign(), RegSize), |
| 3378 | RegSize * 2); |
| 3379 | |
Akira Hatanaka | ffd28a4 | 2013-02-15 21:45:11 +0000 | [diff] [blame] | 3380 | if (useRegsForByval()) |
Akira Hatanaka | 7887c90 | 2012-10-26 23:56:38 +0000 | [diff] [blame] | 3381 | allocateRegs(ByVal, ByValSize, Align); |
| 3382 | |
| 3383 | // Allocate space on caller's stack. |
| 3384 | ByVal.Address = CCInfo.AllocateStack(ByValSize - RegSize * ByVal.NumRegs, |
| 3385 | Align); |
| 3386 | CCInfo.addLoc(CCValAssign::getMem(ValNo, ValVT, ByVal.Address, LocVT, |
| 3387 | LocInfo)); |
| 3388 | ByValArgs.push_back(ByVal); |
| 3389 | } |
| 3390 | |
Akira Hatanaka | ffd28a4 | 2013-02-15 21:45:11 +0000 | [diff] [blame] | 3391 | unsigned MipsTargetLowering::MipsCC::numIntArgRegs() const { |
| 3392 | return IsO32 ? array_lengthof(O32IntRegs) : array_lengthof(Mips64IntRegs); |
| 3393 | } |
| 3394 | |
| 3395 | unsigned MipsTargetLowering::MipsCC::reservedArgArea() const { |
| 3396 | return (IsO32 && (CallConv != CallingConv::Fast)) ? 16 : 0; |
| 3397 | } |
| 3398 | |
| 3399 | const uint16_t *MipsTargetLowering::MipsCC::intArgRegs() const { |
| 3400 | return IsO32 ? O32IntRegs : Mips64IntRegs; |
| 3401 | } |
| 3402 | |
| 3403 | llvm::CCAssignFn *MipsTargetLowering::MipsCC::fixedArgFn() const { |
| 3404 | if (CallConv == CallingConv::Fast) |
| 3405 | return CC_Mips_FastCC; |
| 3406 | |
Reed Kotler | 4609091 | 2013-05-10 22:25:39 +0000 | [diff] [blame] | 3407 | if (SpecialCallingConv == Mips16RetHelperConv) |
| 3408 | return CC_Mips16RetHelper; |
Akira Hatanaka | ad341d4 | 2013-08-20 23:38:40 +0000 | [diff] [blame] | 3409 | return IsO32 ? (IsFP64 ? CC_MipsO32_FP64 : CC_MipsO32_FP32) : CC_MipsN; |
Akira Hatanaka | ffd28a4 | 2013-02-15 21:45:11 +0000 | [diff] [blame] | 3410 | } |
| 3411 | |
| 3412 | llvm::CCAssignFn *MipsTargetLowering::MipsCC::varArgFn() const { |
Akira Hatanaka | ad341d4 | 2013-08-20 23:38:40 +0000 | [diff] [blame] | 3413 | return IsO32 ? (IsFP64 ? CC_MipsO32_FP64 : CC_MipsO32_FP32) : CC_MipsN_VarArg; |
Akira Hatanaka | ffd28a4 | 2013-02-15 21:45:11 +0000 | [diff] [blame] | 3414 | } |
| 3415 | |
| 3416 | const uint16_t *MipsTargetLowering::MipsCC::shadowRegs() const { |
| 3417 | return IsO32 ? O32IntRegs : Mips64DPRegs; |
| 3418 | } |
| 3419 | |
Akira Hatanaka | 7887c90 | 2012-10-26 23:56:38 +0000 | [diff] [blame] | 3420 | void MipsTargetLowering::MipsCC::allocateRegs(ByValArgInfo &ByVal, |
| 3421 | unsigned ByValSize, |
| 3422 | unsigned Align) { |
Akira Hatanaka | ffd28a4 | 2013-02-15 21:45:11 +0000 | [diff] [blame] | 3423 | unsigned RegSize = regSize(), NumIntArgRegs = numIntArgRegs(); |
| 3424 | const uint16_t *IntArgRegs = intArgRegs(), *ShadowRegs = shadowRegs(); |
Akira Hatanaka | 7887c90 | 2012-10-26 23:56:38 +0000 | [diff] [blame] | 3425 | assert(!(ByValSize % RegSize) && !(Align % RegSize) && |
| 3426 | "Byval argument's size and alignment should be a multiple of" |
| 3427 | "RegSize."); |
| 3428 | |
| 3429 | ByVal.FirstIdx = CCInfo.getFirstUnallocated(IntArgRegs, NumIntArgRegs); |
| 3430 | |
| 3431 | // If Align > RegSize, the first arg register must be even. |
| 3432 | if ((Align > RegSize) && (ByVal.FirstIdx % 2)) { |
| 3433 | CCInfo.AllocateReg(IntArgRegs[ByVal.FirstIdx], ShadowRegs[ByVal.FirstIdx]); |
| 3434 | ++ByVal.FirstIdx; |
| 3435 | } |
| 3436 | |
| 3437 | // Mark the registers allocated. |
| 3438 | for (unsigned I = ByVal.FirstIdx; ByValSize && (I < NumIntArgRegs); |
| 3439 | ByValSize -= RegSize, ++I, ++ByVal.NumRegs) |
| 3440 | CCInfo.AllocateReg(IntArgRegs[I], ShadowRegs[I]); |
| 3441 | } |
Akira Hatanaka | eb98ae4 | 2012-10-27 00:10:18 +0000 | [diff] [blame] | 3442 | |
Akira Hatanaka | 5fdee6d | 2013-03-05 22:13:04 +0000 | [diff] [blame] | 3443 | MVT MipsTargetLowering::MipsCC::getRegVT(MVT VT, const Type *OrigTy, |
| 3444 | const SDNode *CallNode, |
| 3445 | bool IsSoftFloat) const { |
| 3446 | if (IsSoftFloat || IsO32) |
| 3447 | return VT; |
| 3448 | |
| 3449 | // Check if the original type was fp128. |
Akira Hatanaka | 1e3e869 | 2013-03-05 22:54:59 +0000 | [diff] [blame] | 3450 | if (originalTypeIsF128(OrigTy, CallNode)) { |
Akira Hatanaka | 5fdee6d | 2013-03-05 22:13:04 +0000 | [diff] [blame] | 3451 | assert(VT == MVT::i64); |
| 3452 | return MVT::f64; |
| 3453 | } |
| 3454 | |
| 3455 | return VT; |
| 3456 | } |
| 3457 | |
Akira Hatanaka | eb98ae4 | 2012-10-27 00:10:18 +0000 | [diff] [blame] | 3458 | void MipsTargetLowering:: |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3459 | copyByValRegs(SDValue Chain, SDLoc DL, std::vector<SDValue> &OutChains, |
Akira Hatanaka | eb98ae4 | 2012-10-27 00:10:18 +0000 | [diff] [blame] | 3460 | SelectionDAG &DAG, const ISD::ArgFlagsTy &Flags, |
| 3461 | SmallVectorImpl<SDValue> &InVals, const Argument *FuncArg, |
| 3462 | const MipsCC &CC, const ByValArgInfo &ByVal) const { |
| 3463 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3464 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 3465 | unsigned RegAreaSize = ByVal.NumRegs * CC.regSize(); |
| 3466 | unsigned FrameObjSize = std::max(Flags.getByValSize(), RegAreaSize); |
| 3467 | int FrameObjOffset; |
| 3468 | |
| 3469 | if (RegAreaSize) |
| 3470 | FrameObjOffset = (int)CC.reservedArgArea() - |
| 3471 | (int)((CC.numIntArgRegs() - ByVal.FirstIdx) * CC.regSize()); |
| 3472 | else |
| 3473 | FrameObjOffset = ByVal.Address; |
| 3474 | |
| 3475 | // Create frame object. |
| 3476 | EVT PtrTy = getPointerTy(); |
| 3477 | int FI = MFI->CreateFixedObject(FrameObjSize, FrameObjOffset, true); |
| 3478 | SDValue FIN = DAG.getFrameIndex(FI, PtrTy); |
| 3479 | InVals.push_back(FIN); |
| 3480 | |
| 3481 | if (!ByVal.NumRegs) |
| 3482 | return; |
| 3483 | |
| 3484 | // Copy arg registers. |
Patrik Hagglund | a61b17c | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 3485 | MVT RegTy = MVT::getIntegerVT(CC.regSize() * 8); |
Akira Hatanaka | eb98ae4 | 2012-10-27 00:10:18 +0000 | [diff] [blame] | 3486 | const TargetRegisterClass *RC = getRegClassFor(RegTy); |
| 3487 | |
| 3488 | for (unsigned I = 0; I < ByVal.NumRegs; ++I) { |
| 3489 | unsigned ArgReg = CC.intArgRegs()[ByVal.FirstIdx + I]; |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 3490 | unsigned VReg = addLiveIn(MF, ArgReg, RC); |
Akira Hatanaka | eb98ae4 | 2012-10-27 00:10:18 +0000 | [diff] [blame] | 3491 | unsigned Offset = I * CC.regSize(); |
| 3492 | SDValue StorePtr = DAG.getNode(ISD::ADD, DL, PtrTy, FIN, |
| 3493 | DAG.getConstant(Offset, PtrTy)); |
| 3494 | SDValue Store = DAG.getStore(Chain, DL, DAG.getRegister(VReg, RegTy), |
| 3495 | StorePtr, MachinePointerInfo(FuncArg, Offset), |
| 3496 | false, false, 0); |
| 3497 | OutChains.push_back(Store); |
| 3498 | } |
| 3499 | } |
Akira Hatanaka | db40ede | 2012-10-27 00:16:36 +0000 | [diff] [blame] | 3500 | |
| 3501 | // Copy byVal arg to registers and stack. |
| 3502 | void MipsTargetLowering:: |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3503 | passByValArg(SDValue Chain, SDLoc DL, |
Akira Hatanaka | bf6a77b | 2013-01-22 20:05:56 +0000 | [diff] [blame] | 3504 | std::deque< std::pair<unsigned, SDValue> > &RegsToPass, |
Craig Topper | a0ec3f9 | 2013-07-14 04:42:23 +0000 | [diff] [blame] | 3505 | SmallVectorImpl<SDValue> &MemOpChains, SDValue StackPtr, |
Akira Hatanaka | db40ede | 2012-10-27 00:16:36 +0000 | [diff] [blame] | 3506 | MachineFrameInfo *MFI, SelectionDAG &DAG, SDValue Arg, |
| 3507 | const MipsCC &CC, const ByValArgInfo &ByVal, |
| 3508 | const ISD::ArgFlagsTy &Flags, bool isLittle) const { |
| 3509 | unsigned ByValSize = Flags.getByValSize(); |
| 3510 | unsigned Offset = 0; // Offset in # of bytes from the beginning of struct. |
| 3511 | unsigned RegSize = CC.regSize(); |
| 3512 | unsigned Alignment = std::min(Flags.getByValAlign(), RegSize); |
| 3513 | EVT PtrTy = getPointerTy(), RegTy = MVT::getIntegerVT(RegSize * 8); |
| 3514 | |
| 3515 | if (ByVal.NumRegs) { |
| 3516 | const uint16_t *ArgRegs = CC.intArgRegs(); |
| 3517 | bool LeftoverBytes = (ByVal.NumRegs * RegSize > ByValSize); |
| 3518 | unsigned I = 0; |
| 3519 | |
| 3520 | // Copy words to registers. |
| 3521 | for (; I < ByVal.NumRegs - LeftoverBytes; ++I, Offset += RegSize) { |
| 3522 | SDValue LoadPtr = DAG.getNode(ISD::ADD, DL, PtrTy, Arg, |
| 3523 | DAG.getConstant(Offset, PtrTy)); |
| 3524 | SDValue LoadVal = DAG.getLoad(RegTy, DL, Chain, LoadPtr, |
| 3525 | MachinePointerInfo(), false, false, false, |
| 3526 | Alignment); |
| 3527 | MemOpChains.push_back(LoadVal.getValue(1)); |
| 3528 | unsigned ArgReg = ArgRegs[ByVal.FirstIdx + I]; |
| 3529 | RegsToPass.push_back(std::make_pair(ArgReg, LoadVal)); |
| 3530 | } |
| 3531 | |
| 3532 | // Return if the struct has been fully copied. |
| 3533 | if (ByValSize == Offset) |
| 3534 | return; |
| 3535 | |
| 3536 | // Copy the remainder of the byval argument with sub-word loads and shifts. |
| 3537 | if (LeftoverBytes) { |
| 3538 | assert((ByValSize > Offset) && (ByValSize < Offset + RegSize) && |
| 3539 | "Size of the remainder should be smaller than RegSize."); |
| 3540 | SDValue Val; |
| 3541 | |
| 3542 | for (unsigned LoadSize = RegSize / 2, TotalSizeLoaded = 0; |
| 3543 | Offset < ByValSize; LoadSize /= 2) { |
| 3544 | unsigned RemSize = ByValSize - Offset; |
| 3545 | |
| 3546 | if (RemSize < LoadSize) |
| 3547 | continue; |
| 3548 | |
| 3549 | // Load subword. |
| 3550 | SDValue LoadPtr = DAG.getNode(ISD::ADD, DL, PtrTy, Arg, |
| 3551 | DAG.getConstant(Offset, PtrTy)); |
| 3552 | SDValue LoadVal = |
| 3553 | DAG.getExtLoad(ISD::ZEXTLOAD, DL, RegTy, Chain, LoadPtr, |
| 3554 | MachinePointerInfo(), MVT::getIntegerVT(LoadSize * 8), |
| 3555 | false, false, Alignment); |
| 3556 | MemOpChains.push_back(LoadVal.getValue(1)); |
| 3557 | |
| 3558 | // Shift the loaded value. |
| 3559 | unsigned Shamt; |
| 3560 | |
| 3561 | if (isLittle) |
| 3562 | Shamt = TotalSizeLoaded; |
| 3563 | else |
| 3564 | Shamt = (RegSize - (TotalSizeLoaded + LoadSize)) * 8; |
| 3565 | |
| 3566 | SDValue Shift = DAG.getNode(ISD::SHL, DL, RegTy, LoadVal, |
| 3567 | DAG.getConstant(Shamt, MVT::i32)); |
| 3568 | |
| 3569 | if (Val.getNode()) |
| 3570 | Val = DAG.getNode(ISD::OR, DL, RegTy, Val, Shift); |
| 3571 | else |
| 3572 | Val = Shift; |
| 3573 | |
| 3574 | Offset += LoadSize; |
| 3575 | TotalSizeLoaded += LoadSize; |
| 3576 | Alignment = std::min(Alignment, LoadSize); |
| 3577 | } |
| 3578 | |
| 3579 | unsigned ArgReg = ArgRegs[ByVal.FirstIdx + I]; |
| 3580 | RegsToPass.push_back(std::make_pair(ArgReg, Val)); |
| 3581 | return; |
| 3582 | } |
| 3583 | } |
| 3584 | |
| 3585 | // Copy remainder of byval arg to it with memcpy. |
| 3586 | unsigned MemCpySize = ByValSize - Offset; |
| 3587 | SDValue Src = DAG.getNode(ISD::ADD, DL, PtrTy, Arg, |
| 3588 | DAG.getConstant(Offset, PtrTy)); |
| 3589 | SDValue Dst = DAG.getNode(ISD::ADD, DL, PtrTy, StackPtr, |
| 3590 | DAG.getIntPtrConstant(ByVal.Address)); |
| 3591 | Chain = DAG.getMemcpy(Chain, DL, Dst, Src, |
| 3592 | DAG.getConstant(MemCpySize, PtrTy), Alignment, |
| 3593 | /*isVolatile=*/false, /*AlwaysInline=*/false, |
| 3594 | MachinePointerInfo(0), MachinePointerInfo(0)); |
| 3595 | MemOpChains.push_back(Chain); |
| 3596 | } |
Akira Hatanaka | f084847 | 2012-10-27 00:21:13 +0000 | [diff] [blame] | 3597 | |
| 3598 | void |
| 3599 | MipsTargetLowering::writeVarArgRegs(std::vector<SDValue> &OutChains, |
| 3600 | const MipsCC &CC, SDValue Chain, |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3601 | SDLoc DL, SelectionDAG &DAG) const { |
Akira Hatanaka | f084847 | 2012-10-27 00:21:13 +0000 | [diff] [blame] | 3602 | unsigned NumRegs = CC.numIntArgRegs(); |
| 3603 | const uint16_t *ArgRegs = CC.intArgRegs(); |
| 3604 | const CCState &CCInfo = CC.getCCInfo(); |
| 3605 | unsigned Idx = CCInfo.getFirstUnallocated(ArgRegs, NumRegs); |
| 3606 | unsigned RegSize = CC.regSize(); |
Patrik Hagglund | a61b17c | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 3607 | MVT RegTy = MVT::getIntegerVT(RegSize * 8); |
Akira Hatanaka | f084847 | 2012-10-27 00:21:13 +0000 | [diff] [blame] | 3608 | const TargetRegisterClass *RC = getRegClassFor(RegTy); |
| 3609 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3610 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 3611 | MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>(); |
| 3612 | |
| 3613 | // Offset of the first variable argument from stack pointer. |
| 3614 | int VaArgOffset; |
| 3615 | |
| 3616 | if (NumRegs == Idx) |
| 3617 | VaArgOffset = RoundUpToAlignment(CCInfo.getNextStackOffset(), RegSize); |
| 3618 | else |
| 3619 | VaArgOffset = |
| 3620 | (int)CC.reservedArgArea() - (int)(RegSize * (NumRegs - Idx)); |
| 3621 | |
| 3622 | // Record the frame index of the first variable argument |
| 3623 | // which is a value necessary to VASTART. |
| 3624 | int FI = MFI->CreateFixedObject(RegSize, VaArgOffset, true); |
| 3625 | MipsFI->setVarArgsFrameIndex(FI); |
| 3626 | |
| 3627 | // Copy the integer registers that have not been used for argument passing |
| 3628 | // to the argument register save area. For O32, the save area is allocated |
| 3629 | // in the caller's stack frame, while for N32/64, it is allocated in the |
| 3630 | // callee's stack frame. |
| 3631 | for (unsigned I = Idx; I < NumRegs; ++I, VaArgOffset += RegSize) { |
Akira Hatanaka | f635ef4 | 2013-03-12 00:16:36 +0000 | [diff] [blame] | 3632 | unsigned Reg = addLiveIn(MF, ArgRegs[I], RC); |
Akira Hatanaka | f084847 | 2012-10-27 00:21:13 +0000 | [diff] [blame] | 3633 | SDValue ArgValue = DAG.getCopyFromReg(Chain, DL, Reg, RegTy); |
| 3634 | FI = MFI->CreateFixedObject(RegSize, VaArgOffset, true); |
| 3635 | SDValue PtrOff = DAG.getFrameIndex(FI, getPointerTy()); |
| 3636 | SDValue Store = DAG.getStore(Chain, DL, ArgValue, PtrOff, |
| 3637 | MachinePointerInfo(), false, false, 0); |
| 3638 | cast<StoreSDNode>(Store.getNode())->getMemOperand()->setValue(0); |
| 3639 | OutChains.push_back(Store); |
| 3640 | } |
| 3641 | } |