Jia Liu | 9f61011 | 2012-02-17 08:55:11 +0000 | [diff] [blame] | 1 | //===-- MipsISelDAGToDAG.cpp - A Dag to Dag Inst Selector for Mips --------===// |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 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 | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 7 | // |
Akira Hatanaka | e248912 | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file defines an instruction selector for the MIPS target. |
| 11 | // |
Akira Hatanaka | e248912 | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 13 | |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 14 | #include "MipsISelDAGToDAG.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 15 | #include "MCTargetDesc/MipsBaseInfo.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 16 | #include "Mips.h" |
| 17 | #include "Mips16ISelDAGToDAG.h" |
Bruno Cardoso Lopes | 3e0d030 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 18 | #include "MipsMachineFunction.h" |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 19 | #include "MipsRegisterInfo.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 20 | #include "MipsSEISelDAGToDAG.h" |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineConstantPool.h" |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/MachineFunction.h" |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Chris Lattner | a10fff5 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Akira Hatanaka | 330d901 | 2012-02-28 02:55:02 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/SelectionDAGNodes.h" |
Chandler Carruth | 1305dc3 | 2014-03-04 11:45:46 +0000 | [diff] [blame] | 27 | #include "llvm/IR/CFG.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 28 | #include "llvm/IR/GlobalValue.h" |
| 29 | #include "llvm/IR/Instructions.h" |
| 30 | #include "llvm/IR/Intrinsics.h" |
| 31 | #include "llvm/IR/Type.h" |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 32 | #include "llvm/Support/Debug.h" |
Torok Edwin | fb8d6d5 | 2009-07-08 20:53:28 +0000 | [diff] [blame] | 33 | #include "llvm/Support/ErrorHandling.h" |
| 34 | #include "llvm/Support/raw_ostream.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 35 | #include "llvm/Target/TargetMachine.h" |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 36 | using namespace llvm; |
| 37 | |
Chandler Carruth | 84e68b2 | 2014-04-22 02:41:26 +0000 | [diff] [blame] | 38 | #define DEBUG_TYPE "mips-isel" |
| 39 | |
Akira Hatanaka | e248912 | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 40 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 41 | // Instruction Selector Implementation |
Akira Hatanaka | e248912 | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 42 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 43 | |
Akira Hatanaka | e248912 | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 44 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 45 | // MipsDAGToDAGISel - MIPS specific code to select MIPS machine |
| 46 | // instructions for SelectionDAG operations. |
Akira Hatanaka | e248912 | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 47 | //===----------------------------------------------------------------------===// |
Akira Hatanaka | 0b2fa91 | 2012-03-08 01:51:59 +0000 | [diff] [blame] | 48 | |
Akira Hatanaka | b049aef | 2012-02-24 22:34:47 +0000 | [diff] [blame] | 49 | bool MipsDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) { |
Eric Christopher | 96e72c6 | 2015-01-29 23:27:36 +0000 | [diff] [blame] | 50 | Subtarget = &static_cast<const MipsSubtarget &>(MF.getSubtarget()); |
Akira Hatanaka | b049aef | 2012-02-24 22:34:47 +0000 | [diff] [blame] | 51 | bool Ret = SelectionDAGISel::runOnMachineFunction(MF); |
Jia Liu | f54f60f | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 52 | |
Akira Hatanaka | 040d225 | 2013-03-14 18:33:23 +0000 | [diff] [blame] | 53 | processFunctionAfterISel(MF); |
Akira Hatanaka | b049aef | 2012-02-24 22:34:47 +0000 | [diff] [blame] | 54 | |
| 55 | return Ret; |
| 56 | } |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 57 | |
Bruno Cardoso Lopes | b439132 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 58 | /// getGlobalBaseReg - Output the instructions required to put the |
| 59 | /// GOT address into a register. |
Dan Gohman | d5ca7064 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 60 | SDNode *MipsDAGToDAGISel::getGlobalBaseReg() { |
Akira Hatanaka | b049aef | 2012-02-24 22:34:47 +0000 | [diff] [blame] | 61 | unsigned GlobalBaseReg = MF->getInfo<MipsFunctionInfo>()->getGlobalBaseReg(); |
Bill Wendling | a3cd350 | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 62 | return CurDAG->getRegister(GlobalBaseReg, |
| 63 | getTargetLowering()->getPointerTy()).getNode(); |
Bruno Cardoso Lopes | b439132 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 66 | /// ComplexPattern used on MipsInstrInfo |
| 67 | /// Used on Mips Load/Store instructions |
Akira Hatanaka | a35bc83 | 2013-02-16 00:14:37 +0000 | [diff] [blame] | 68 | bool MipsDAGToDAGISel::selectAddrRegImm(SDValue Addr, SDValue &Base, |
| 69 | SDValue &Offset) const { |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 70 | llvm_unreachable("Unimplemented function."); |
Akira Hatanaka | 69fb3d1 | 2013-02-15 21:20:45 +0000 | [diff] [blame] | 71 | return false; |
| 72 | } |
| 73 | |
Daniel Sanders | e6ed5b7 | 2013-08-28 12:04:29 +0000 | [diff] [blame] | 74 | bool MipsDAGToDAGISel::selectAddrRegReg(SDValue Addr, SDValue &Base, |
| 75 | SDValue &Offset) const { |
| 76 | llvm_unreachable("Unimplemented function."); |
| 77 | return false; |
| 78 | } |
| 79 | |
Akira Hatanaka | a35bc83 | 2013-02-16 00:14:37 +0000 | [diff] [blame] | 80 | bool MipsDAGToDAGISel::selectAddrDefault(SDValue Addr, SDValue &Base, |
| 81 | SDValue &Offset) const { |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 82 | llvm_unreachable("Unimplemented function."); |
| 83 | return false; |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Akira Hatanaka | a35bc83 | 2013-02-16 00:14:37 +0000 | [diff] [blame] | 86 | bool MipsDAGToDAGISel::selectIntAddr(SDValue Addr, SDValue &Base, |
| 87 | SDValue &Offset) const { |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 88 | llvm_unreachable("Unimplemented function."); |
| 89 | return false; |
Akira Hatanaka | 69fb3d1 | 2013-02-15 21:20:45 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Jack Carter | 9770097 | 2013-08-13 20:19:16 +0000 | [diff] [blame] | 92 | bool MipsDAGToDAGISel::selectIntAddrMM(SDValue Addr, SDValue &Base, |
| 93 | SDValue &Offset) const { |
| 94 | llvm_unreachable("Unimplemented function."); |
| 95 | return false; |
| 96 | } |
| 97 | |
Zoran Jovanovic | 5a1a780 | 2015-02-04 15:43:17 +0000 | [diff] [blame] | 98 | bool MipsDAGToDAGISel::selectIntAddrLSL2MM(SDValue Addr, SDValue &Base, |
| 99 | SDValue &Offset) const { |
| 100 | llvm_unreachable("Unimplemented function."); |
| 101 | return false; |
| 102 | } |
| 103 | |
Daniel Sanders | fa961d7 | 2014-03-03 14:31:21 +0000 | [diff] [blame] | 104 | bool MipsDAGToDAGISel::selectIntAddrMSA(SDValue Addr, SDValue &Base, |
| 105 | SDValue &Offset) const { |
| 106 | llvm_unreachable("Unimplemented function."); |
| 107 | return false; |
| 108 | } |
| 109 | |
Akira Hatanaka | 040d225 | 2013-03-14 18:33:23 +0000 | [diff] [blame] | 110 | bool MipsDAGToDAGISel::selectAddr16(SDNode *Parent, SDValue N, SDValue &Base, |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 111 | SDValue &Offset, SDValue &Alias) { |
| 112 | llvm_unreachable("Unimplemented function."); |
| 113 | return false; |
Reed Kotler | 3589dd7 | 2012-10-28 06:02:37 +0000 | [diff] [blame] | 114 | } |
Akira Hatanaka | cb2a85b | 2011-12-20 23:10:57 +0000 | [diff] [blame] | 115 | |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 116 | bool MipsDAGToDAGISel::selectVSplat(SDNode *N, APInt &Imm) const { |
| 117 | llvm_unreachable("Unimplemented function."); |
| 118 | return false; |
| 119 | } |
| 120 | |
Daniel Sanders | 7e51fe1 | 2013-09-27 11:48:57 +0000 | [diff] [blame] | 121 | bool MipsDAGToDAGISel::selectVSplatUimm1(SDValue N, SDValue &Imm) const { |
| 122 | llvm_unreachable("Unimplemented function."); |
| 123 | return false; |
| 124 | } |
| 125 | |
| 126 | bool MipsDAGToDAGISel::selectVSplatUimm2(SDValue N, SDValue &Imm) const { |
| 127 | llvm_unreachable("Unimplemented function."); |
| 128 | return false; |
| 129 | } |
| 130 | |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 131 | bool MipsDAGToDAGISel::selectVSplatUimm3(SDValue N, SDValue &Imm) const { |
| 132 | llvm_unreachable("Unimplemented function."); |
| 133 | return false; |
| 134 | } |
| 135 | |
| 136 | bool MipsDAGToDAGISel::selectVSplatUimm4(SDValue N, SDValue &Imm) const { |
| 137 | llvm_unreachable("Unimplemented function."); |
| 138 | return false; |
| 139 | } |
| 140 | |
| 141 | bool MipsDAGToDAGISel::selectVSplatUimm5(SDValue N, SDValue &Imm) const { |
| 142 | llvm_unreachable("Unimplemented function."); |
| 143 | return false; |
| 144 | } |
| 145 | |
| 146 | bool MipsDAGToDAGISel::selectVSplatUimm6(SDValue N, SDValue &Imm) const { |
| 147 | llvm_unreachable("Unimplemented function."); |
| 148 | return false; |
| 149 | } |
| 150 | |
| 151 | bool MipsDAGToDAGISel::selectVSplatUimm8(SDValue N, SDValue &Imm) const { |
| 152 | llvm_unreachable("Unimplemented function."); |
| 153 | return false; |
| 154 | } |
| 155 | |
| 156 | bool MipsDAGToDAGISel::selectVSplatSimm5(SDValue N, SDValue &Imm) const { |
| 157 | llvm_unreachable("Unimplemented function."); |
| 158 | return false; |
| 159 | } |
| 160 | |
| 161 | bool MipsDAGToDAGISel::selectVSplatUimmPow2(SDValue N, SDValue &Imm) const { |
| 162 | llvm_unreachable("Unimplemented function."); |
| 163 | return false; |
| 164 | } |
| 165 | |
Daniel Sanders | 3f6eb54 | 2013-11-12 10:45:18 +0000 | [diff] [blame] | 166 | bool MipsDAGToDAGISel::selectVSplatUimmInvPow2(SDValue N, SDValue &Imm) const { |
| 167 | llvm_unreachable("Unimplemented function."); |
| 168 | return false; |
| 169 | } |
| 170 | |
Daniel Sanders | d74b130 | 2013-10-30 14:45:14 +0000 | [diff] [blame] | 171 | bool MipsDAGToDAGISel::selectVSplatMaskL(SDValue N, SDValue &Imm) const { |
| 172 | llvm_unreachable("Unimplemented function."); |
| 173 | return false; |
| 174 | } |
| 175 | |
| 176 | bool MipsDAGToDAGISel::selectVSplatMaskR(SDValue N, SDValue &Imm) const { |
| 177 | llvm_unreachable("Unimplemented function."); |
| 178 | return false; |
| 179 | } |
| 180 | |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 181 | /// Select instructions not customized! Used for |
| 182 | /// expanded, promoted and normal instructions |
Dan Gohman | ea6f91f | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 183 | SDNode* MipsDAGToDAGISel::Select(SDNode *Node) { |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 184 | unsigned Opcode = Node->getOpcode(); |
| 185 | |
| 186 | // Dump information about the Node being selected |
Chris Lattner | f98f124 | 2010-03-02 06:34:30 +0000 | [diff] [blame] | 187 | DEBUG(errs() << "Selecting: "; Node->dump(CurDAG); errs() << "\n"); |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 188 | |
| 189 | // If we have a custom node, we already have selected! |
Dan Gohman | 1705968 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 190 | if (Node->isMachineOpcode()) { |
Chris Lattner | f98f124 | 2010-03-02 06:34:30 +0000 | [diff] [blame] | 191 | DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n"); |
Tim Northover | 31d093c | 2013-09-22 08:21:56 +0000 | [diff] [blame] | 192 | Node->setNodeId(-1); |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 193 | return nullptr; |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 196 | // See if subclasses can handle this node. |
Akira Hatanaka | 040d225 | 2013-03-14 18:33:23 +0000 | [diff] [blame] | 197 | std::pair<bool, SDNode*> Ret = selectNode(Node); |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 198 | |
| 199 | if (Ret.first) |
| 200 | return Ret.second; |
Akira Hatanaka | cb2a85b | 2011-12-20 23:10:57 +0000 | [diff] [blame] | 201 | |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 202 | switch(Opcode) { |
Akira Hatanaka | 2c8d1734 | 2011-12-20 22:58:01 +0000 | [diff] [blame] | 203 | default: break; |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 204 | |
Akira Hatanaka | 2c8d1734 | 2011-12-20 22:58:01 +0000 | [diff] [blame] | 205 | // Get target GOT address. |
| 206 | case ISD::GLOBAL_OFFSET_TABLE: |
| 207 | return getGlobalBaseReg(); |
Akira Hatanaka | dee6c82 | 2011-12-08 20:34:32 +0000 | [diff] [blame] | 208 | |
Akira Hatanaka | 3e7ba76 | 2012-09-15 01:52:08 +0000 | [diff] [blame] | 209 | #ifndef NDEBUG |
| 210 | case ISD::LOAD: |
| 211 | case ISD::STORE: |
Eric Christopher | 22405e4 | 2014-07-10 17:26:51 +0000 | [diff] [blame] | 212 | assert((Subtarget->systemSupportsUnalignedAccess() || |
Daniel Sanders | ac27263 | 2014-05-23 13:18:02 +0000 | [diff] [blame] | 213 | cast<MemSDNode>(Node)->getMemoryVT().getSizeInBits() / 8 <= |
| 214 | cast<MemSDNode>(Node)->getAlignment()) && |
Akira Hatanaka | 3e7ba76 | 2012-09-15 01:52:08 +0000 | [diff] [blame] | 215 | "Unexpected unaligned loads/stores."); |
| 216 | break; |
| 217 | #endif |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | // Select the default instruction |
Dan Gohman | ea6f91f | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 221 | SDNode *ResNode = SelectCode(Node); |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 222 | |
Chris Lattner | f98f124 | 2010-03-02 06:34:30 +0000 | [diff] [blame] | 223 | DEBUG(errs() << "=> "); |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 224 | if (ResNode == nullptr || ResNode == Node) |
Dan Gohman | ea6f91f | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 225 | DEBUG(Node->dump(CurDAG)); |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 226 | else |
| 227 | DEBUG(ResNode->dump(CurDAG)); |
Chris Lattner | af29ea6 | 2009-08-23 06:49:22 +0000 | [diff] [blame] | 228 | DEBUG(errs() << "\n"); |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 229 | return ResNode; |
| 230 | } |
| 231 | |
Akira Hatanaka | 4c406e7 | 2011-06-21 00:40:49 +0000 | [diff] [blame] | 232 | bool MipsDAGToDAGISel:: |
Daniel Sanders | 60f1db0 | 2015-03-13 12:45:09 +0000 | [diff] [blame^] | 233 | SelectInlineAsmMemoryOperand(const SDValue &Op, unsigned ConstraintID, |
Akira Hatanaka | 4c406e7 | 2011-06-21 00:40:49 +0000 | [diff] [blame] | 234 | std::vector<SDValue> &OutOps) { |
Daniel Sanders | 60f1db0 | 2015-03-13 12:45:09 +0000 | [diff] [blame^] | 235 | assert(ConstraintID == InlineAsm::Constraint_m && |
| 236 | "unexpected asm memory constraint"); |
Akira Hatanaka | 4c406e7 | 2011-06-21 00:40:49 +0000 | [diff] [blame] | 237 | OutOps.push_back(Op); |
| 238 | return false; |
| 239 | } |