Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1 | //===-- MipsISelDAGToDAG.cpp - A dag to dag inst selector for Mips --------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines an instruction selector for the MIPS target. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #define DEBUG_TYPE "mips-isel" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 15 | #include "Mips.h" |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 16 | #include "MipsMachineFunction.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 17 | #include "MipsRegisterInfo.h" |
| 18 | #include "MipsSubtarget.h" |
| 19 | #include "MipsTargetMachine.h" |
| 20 | #include "llvm/GlobalValue.h" |
| 21 | #include "llvm/Instructions.h" |
| 22 | #include "llvm/Intrinsics.h" |
| 23 | #include "llvm/Support/CFG.h" |
| 24 | #include "llvm/Type.h" |
| 25 | #include "llvm/CodeGen/MachineConstantPool.h" |
| 26 | #include "llvm/CodeGen/MachineFunction.h" |
| 27 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 28 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/SelectionDAGISel.h" |
| 31 | #include "llvm/Target/TargetMachine.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 32 | #include "llvm/Support/Debug.h" |
Torok Edwin | dac237e | 2009-07-08 20:53:28 +0000 | [diff] [blame] | 33 | #include "llvm/Support/ErrorHandling.h" |
| 34 | #include "llvm/Support/raw_ostream.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 35 | using namespace llvm; |
| 36 | |
| 37 | //===----------------------------------------------------------------------===// |
| 38 | // Instruction Selector Implementation |
| 39 | //===----------------------------------------------------------------------===// |
| 40 | |
| 41 | //===----------------------------------------------------------------------===// |
| 42 | // MipsDAGToDAGISel - MIPS specific code to select MIPS machine |
| 43 | // instructions for SelectionDAG operations. |
| 44 | //===----------------------------------------------------------------------===// |
| 45 | namespace { |
| 46 | |
Nick Lewycky | 6726b6d | 2009-10-25 06:33:48 +0000 | [diff] [blame] | 47 | class MipsDAGToDAGISel : public SelectionDAGISel { |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 48 | |
| 49 | /// TM - Keep a reference to MipsTargetMachine. |
| 50 | MipsTargetMachine &TM; |
| 51 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 52 | /// Subtarget - Keep a pointer to the MipsSubtarget around so that we can |
| 53 | /// make the right decision when generating code for different targets. |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 54 | const MipsSubtarget &Subtarget; |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 55 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 56 | public: |
Dan Gohman | 1002c02 | 2008-07-07 18:00:37 +0000 | [diff] [blame] | 57 | explicit MipsDAGToDAGISel(MipsTargetMachine &tm) : |
Dan Gohman | 79ce276 | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 58 | SelectionDAGISel(tm), |
Dan Gohman | da8ac5f | 2008-10-03 16:55:19 +0000 | [diff] [blame] | 59 | TM(tm), Subtarget(tm.getSubtarget<MipsSubtarget>()) {} |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 60 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 61 | // Pass Name |
| 62 | virtual const char *getPassName() const { |
| 63 | return "MIPS DAG->DAG Pattern Instruction Selection"; |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 64 | } |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 65 | |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 66 | |
| 67 | private: |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 68 | // Include the pieces autogenerated from the target description. |
| 69 | #include "MipsGenDAGISel.inc" |
| 70 | |
Dan Gohman | 9911405 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 71 | /// getTargetMachine - Return a reference to the TargetMachine, casted |
| 72 | /// to the target-specific type. |
| 73 | const MipsTargetMachine &getTargetMachine() { |
| 74 | return static_cast<const MipsTargetMachine &>(TM); |
| 75 | } |
| 76 | |
| 77 | /// getInstrInfo - Return a reference to the TargetInstrInfo, casted |
| 78 | /// to the target-specific type. |
| 79 | const MipsInstrInfo *getInstrInfo() { |
| 80 | return getTargetMachine().getInstrInfo(); |
| 81 | } |
| 82 | |
| 83 | SDNode *getGlobalBaseReg(); |
Dan Gohman | eeb3a00 | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 84 | SDNode *Select(SDNode *N); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 85 | |
| 86 | // Complex Pattern. |
Chris Lattner | 52a261b | 2010-09-21 20:31:19 +0000 | [diff] [blame] | 87 | bool SelectAddr(SDValue N, SDValue &Base, SDValue &Offset); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 88 | |
Dan Gohman | eeb3a00 | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 89 | SDNode *SelectLoadFp64(SDNode *N); |
| 90 | SDNode *SelectStoreFp64(SDNode *N); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 91 | |
| 92 | // getI32Imm - Return a target constant with the specified |
| 93 | // value, of type i32. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 94 | inline SDValue getI32Imm(unsigned Imm) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 95 | return CurDAG->getTargetConstant(Imm, MVT::i32); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 96 | } |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | } |
| 100 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 101 | |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 102 | /// getGlobalBaseReg - Output the instructions required to put the |
| 103 | /// GOT address into a register. |
Dan Gohman | 9911405 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 104 | SDNode *MipsDAGToDAGISel::getGlobalBaseReg() { |
Dan Gohman | 9911405 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 105 | unsigned GlobalBaseReg = getInstrInfo()->getGlobalBaseReg(MF); |
| 106 | return CurDAG->getRegister(GlobalBaseReg, TLI.getPointerTy()).getNode(); |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 109 | /// ComplexPattern used on MipsInstrInfo |
| 110 | /// Used on Mips Load/Store instructions |
| 111 | bool MipsDAGToDAGISel:: |
Chris Lattner | 52a261b | 2010-09-21 20:31:19 +0000 | [diff] [blame] | 112 | SelectAddr(SDValue Addr, SDValue &Offset, SDValue &Base) { |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 113 | // if Address is FI, get the TargetFrameIndex. |
| 114 | if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 115 | Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i32); |
| 116 | Offset = CurDAG->getTargetConstant(0, MVT::i32); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 117 | return true; |
| 118 | } |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 119 | |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 120 | // on PIC code Load GA |
| 121 | if (TM.getRelocationModel() == Reloc::PIC_) { |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 122 | if ((Addr.getOpcode() == ISD::TargetGlobalAddress) || |
| 123 | (Addr.getOpcode() == ISD::TargetConstantPool) || |
Bruno Cardoso Lopes | ca8a2aa | 2011-03-04 20:01:52 +0000 | [diff] [blame] | 124 | (Addr.getOpcode() == ISD::TargetJumpTable) || |
| 125 | (Addr.getOpcode() == ISD::TargetBlockAddress)) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 126 | Base = CurDAG->getRegister(Mips::GP, MVT::i32); |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 127 | Offset = Addr; |
| 128 | return true; |
| 129 | } |
| 130 | } else { |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 131 | if ((Addr.getOpcode() == ISD::TargetExternalSymbol || |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 132 | Addr.getOpcode() == ISD::TargetGlobalAddress)) |
| 133 | return false; |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Bruno Cardoso Lopes | 7ff6fa2 | 2007-08-18 02:16:30 +0000 | [diff] [blame] | 136 | // Operand is a result from an ADD. |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 137 | if (Addr.getOpcode() == ISD::ADD) { |
| 138 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1))) { |
Jakob Stoklund Olesen | 7552a3d | 2010-08-18 23:56:46 +0000 | [diff] [blame] | 139 | if (isInt<16>(CN->getSExtValue())) { |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 140 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 141 | // If the first operand is a FI, get the TargetFI Node |
| 142 | if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode> |
| 143 | (Addr.getOperand(0))) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 144 | Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i32); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 145 | } else { |
| 146 | Base = Addr.getOperand(0); |
| 147 | } |
| 148 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 149 | Offset = CurDAG->getTargetConstant(CN->getZExtValue(), MVT::i32); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 150 | return true; |
| 151 | } |
| 152 | } |
Bruno Cardoso Lopes | 6e0b658 | 2009-11-16 04:33:42 +0000 | [diff] [blame] | 153 | |
| 154 | // When loading from constant pools, load the lower address part in |
Bruno Cardoso Lopes | d71cebf | 2009-11-25 12:17:58 +0000 | [diff] [blame] | 155 | // the instruction itself. Example, instead of: |
Bruno Cardoso Lopes | 6e0b658 | 2009-11-16 04:33:42 +0000 | [diff] [blame] | 156 | // lui $2, %hi($CPI1_0) |
| 157 | // addiu $2, $2, %lo($CPI1_0) |
| 158 | // lwc1 $f0, 0($2) |
| 159 | // Generate: |
| 160 | // lui $2, %hi($CPI1_0) |
| 161 | // lwc1 $f0, %lo($CPI1_0)($2) |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 162 | if ((Addr.getOperand(0).getOpcode() == MipsISD::Hi || |
Bruno Cardoso Lopes | d71cebf | 2009-11-25 12:17:58 +0000 | [diff] [blame] | 163 | Addr.getOperand(0).getOpcode() == ISD::LOAD) && |
Bruno Cardoso Lopes | 6e0b658 | 2009-11-16 04:33:42 +0000 | [diff] [blame] | 164 | Addr.getOperand(1).getOpcode() == MipsISD::Lo) { |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 165 | SDValue LoVal = Addr.getOperand(1); |
Bruno Cardoso Lopes | d71cebf | 2009-11-25 12:17:58 +0000 | [diff] [blame] | 166 | if (dyn_cast<ConstantPoolSDNode>(LoVal.getOperand(0))) { |
| 167 | Base = Addr.getOperand(0); |
| 168 | Offset = LoVal.getOperand(0); |
| 169 | return true; |
Bruno Cardoso Lopes | 6e0b658 | 2009-11-16 04:33:42 +0000 | [diff] [blame] | 170 | } |
| 171 | } |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Bruno Cardoso Lopes | ca8a2aa | 2011-03-04 20:01:52 +0000 | [diff] [blame] | 174 | if (isa<BlockAddressSDNode>(Addr.getOperand(1))) { |
| 175 | Base = Addr.getOperand(0); |
| 176 | Offset = Addr.getOperand(1); |
| 177 | } |
| 178 | |
Bruno Cardoso Lopes | a4e8200 | 2007-07-11 23:24:41 +0000 | [diff] [blame] | 179 | Base = Addr; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 180 | Offset = CurDAG->getTargetConstant(0, MVT::i32); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 181 | return true; |
| 182 | } |
| 183 | |
Dan Gohman | eeb3a00 | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 184 | SDNode *MipsDAGToDAGISel::SelectLoadFp64(SDNode *N) { |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 185 | MVT::SimpleValueType NVT = |
Dan Gohman | eeb3a00 | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 186 | N->getValueType(0).getSimpleVT().SimpleTy; |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 187 | |
| 188 | if (!Subtarget.isMips1() || NVT != MVT::f64) |
| 189 | return NULL; |
| 190 | |
Jakob Stoklund Olesen | 7fa846f | 2010-09-03 00:35:13 +0000 | [diff] [blame] | 191 | LoadSDNode *LN = cast<LoadSDNode>(N); |
| 192 | if (LN->getExtensionType() != ISD::NON_EXTLOAD || |
| 193 | LN->getAddressingMode() != ISD::UNINDEXED) |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 194 | return NULL; |
| 195 | |
Dan Gohman | eeb3a00 | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 196 | SDValue Chain = N->getOperand(0); |
| 197 | SDValue N1 = N->getOperand(1); |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 198 | SDValue Offset0, Offset1, Base; |
| 199 | |
Chris Lattner | 52a261b | 2010-09-21 20:31:19 +0000 | [diff] [blame] | 200 | if (!SelectAddr(N1, Offset0, Base) || |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 201 | N1.getValueType() != MVT::i32) |
| 202 | return NULL; |
| 203 | |
| 204 | MachineSDNode::mmo_iterator MemRefs0 = MF->allocateMemRefsArray(1); |
| 205 | MemRefs0[0] = cast<MemSDNode>(N)->getMemOperand(); |
Dan Gohman | eeb3a00 | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 206 | DebugLoc dl = N->getDebugLoc(); |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 207 | |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 208 | // The second load should start after for 4 bytes. |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 209 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Offset0)) |
| 210 | Offset1 = CurDAG->getTargetConstant(C->getSExtValue()+4, MVT::i32); |
| 211 | else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Offset0)) |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 212 | Offset1 = CurDAG->getTargetConstantPool(CP->getConstVal(), |
| 213 | MVT::i32, |
| 214 | CP->getAlignment(), |
| 215 | CP->getOffset()+4, |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 216 | CP->getTargetFlags()); |
| 217 | else |
| 218 | return NULL; |
| 219 | |
Bruno Cardoso Lopes | 37fd537 | 2009-11-25 01:05:25 +0000 | [diff] [blame] | 220 | // Choose the offsets depending on the endianess |
| 221 | if (TM.getTargetData()->isBigEndian()) |
| 222 | std::swap(Offset0, Offset1); |
| 223 | |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 224 | // Instead of: |
| 225 | // ldc $f0, X($3) |
| 226 | // Generate: |
| 227 | // lwc $f0, X($3) |
| 228 | // lwc $f1, X+4($3) |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 229 | SDNode *LD0 = CurDAG->getMachineNode(Mips::LWC1, dl, MVT::f32, |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 230 | MVT::Other, Offset0, Base, Chain); |
Chris Lattner | 518bb53 | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 231 | SDValue Undef = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 232 | dl, NVT), 0); |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 233 | SDValue I0 = CurDAG->getTargetInsertSubreg(Mips::sub_fpeven, dl, |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 234 | MVT::f64, Undef, SDValue(LD0, 0)); |
| 235 | |
| 236 | SDNode *LD1 = CurDAG->getMachineNode(Mips::LWC1, dl, MVT::f32, |
| 237 | MVT::Other, Offset1, Base, SDValue(LD0, 1)); |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 238 | SDValue I1 = CurDAG->getTargetInsertSubreg(Mips::sub_fpodd, dl, |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 239 | MVT::f64, I0, SDValue(LD1, 0)); |
| 240 | |
Dan Gohman | eeb3a00 | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 241 | ReplaceUses(SDValue(N, 0), I1); |
| 242 | ReplaceUses(SDValue(N, 1), Chain); |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 243 | cast<MachineSDNode>(LD0)->setMemRefs(MemRefs0, MemRefs0 + 1); |
| 244 | cast<MachineSDNode>(LD1)->setMemRefs(MemRefs0, MemRefs0 + 1); |
| 245 | return I1.getNode(); |
| 246 | } |
| 247 | |
Dan Gohman | eeb3a00 | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 248 | SDNode *MipsDAGToDAGISel::SelectStoreFp64(SDNode *N) { |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 249 | |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 250 | if (!Subtarget.isMips1() || |
Dan Gohman | eeb3a00 | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 251 | N->getOperand(1).getValueType() != MVT::f64) |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 252 | return NULL; |
| 253 | |
Dan Gohman | eeb3a00 | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 254 | SDValue Chain = N->getOperand(0); |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 255 | |
Jakob Stoklund Olesen | 7552a3d | 2010-08-18 23:56:46 +0000 | [diff] [blame] | 256 | StoreSDNode *SN = cast<StoreSDNode>(N); |
| 257 | if (SN->isTruncatingStore() || SN->getAddressingMode() != ISD::UNINDEXED) |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 258 | return NULL; |
| 259 | |
Dan Gohman | eeb3a00 | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 260 | SDValue N1 = N->getOperand(1); |
| 261 | SDValue N2 = N->getOperand(2); |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 262 | SDValue Offset0, Offset1, Base; |
| 263 | |
Chris Lattner | 52a261b | 2010-09-21 20:31:19 +0000 | [diff] [blame] | 264 | if (!SelectAddr(N2, Offset0, Base) || |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 265 | N1.getValueType() != MVT::f64 || |
| 266 | N2.getValueType() != MVT::i32) |
| 267 | return NULL; |
| 268 | |
| 269 | MachineSDNode::mmo_iterator MemRefs0 = MF->allocateMemRefsArray(1); |
| 270 | MemRefs0[0] = cast<MemSDNode>(N)->getMemOperand(); |
Dan Gohman | eeb3a00 | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 271 | DebugLoc dl = N->getDebugLoc(); |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 272 | |
| 273 | // Get the even and odd part from the f64 register |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 274 | SDValue FPOdd = CurDAG->getTargetExtractSubreg(Mips::sub_fpodd, |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 275 | dl, MVT::f32, N1); |
Jakob Stoklund Olesen | fff916a | 2010-05-24 17:42:58 +0000 | [diff] [blame] | 276 | SDValue FPEven = CurDAG->getTargetExtractSubreg(Mips::sub_fpeven, |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 277 | dl, MVT::f32, N1); |
| 278 | |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 279 | // The second store should start after for 4 bytes. |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 280 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Offset0)) |
| 281 | Offset1 = CurDAG->getTargetConstant(C->getSExtValue()+4, MVT::i32); |
| 282 | else |
| 283 | return NULL; |
| 284 | |
Bruno Cardoso Lopes | 37fd537 | 2009-11-25 01:05:25 +0000 | [diff] [blame] | 285 | // Choose the offsets depending on the endianess |
| 286 | if (TM.getTargetData()->isBigEndian()) |
| 287 | std::swap(Offset0, Offset1); |
| 288 | |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 289 | // Instead of: |
| 290 | // sdc $f0, X($3) |
| 291 | // Generate: |
| 292 | // swc $f0, X($3) |
| 293 | // swc $f1, X+4($3) |
| 294 | SDValue Ops0[] = { FPEven, Offset0, Base, Chain }; |
| 295 | Chain = SDValue(CurDAG->getMachineNode(Mips::SWC1, dl, |
| 296 | MVT::Other, Ops0, 4), 0); |
| 297 | cast<MachineSDNode>(Chain.getNode())->setMemRefs(MemRefs0, MemRefs0 + 1); |
| 298 | |
| 299 | SDValue Ops1[] = { FPOdd, Offset1, Base, Chain }; |
| 300 | Chain = SDValue(CurDAG->getMachineNode(Mips::SWC1, dl, |
| 301 | MVT::Other, Ops1, 4), 0); |
| 302 | cast<MachineSDNode>(Chain.getNode())->setMemRefs(MemRefs0, MemRefs0 + 1); |
| 303 | |
Dan Gohman | eeb3a00 | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 304 | ReplaceUses(SDValue(N, 0), Chain); |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 305 | return Chain.getNode(); |
| 306 | } |
| 307 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 308 | /// Select instructions not customized! Used for |
| 309 | /// expanded, promoted and normal instructions |
Dan Gohman | eeb3a00 | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 310 | SDNode* MipsDAGToDAGISel::Select(SDNode *Node) { |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 311 | unsigned Opcode = Node->getOpcode(); |
Dale Johannesen | a05dca4 | 2009-02-04 23:02:30 +0000 | [diff] [blame] | 312 | DebugLoc dl = Node->getDebugLoc(); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 313 | |
| 314 | // Dump information about the Node being selected |
Chris Lattner | 7c306da | 2010-03-02 06:34:30 +0000 | [diff] [blame] | 315 | DEBUG(errs() << "Selecting: "; Node->dump(CurDAG); errs() << "\n"); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 316 | |
| 317 | // If we have a custom node, we already have selected! |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 318 | if (Node->isMachineOpcode()) { |
Chris Lattner | 7c306da | 2010-03-02 06:34:30 +0000 | [diff] [blame] | 319 | DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n"); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 320 | return NULL; |
| 321 | } |
| 322 | |
| 323 | /// |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 324 | // Instruction Selection not handled by the auto-generated |
Bruno Cardoso Lopes | b42abeb | 2007-09-24 20:15:11 +0000 | [diff] [blame] | 325 | // tablegen selection should be handled here. |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 326 | /// |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 327 | switch(Opcode) { |
| 328 | |
| 329 | default: break; |
| 330 | |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 331 | case ISD::SUBE: |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 332 | case ISD::ADDE: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 333 | SDValue InFlag = Node->getOperand(2), CmpLHS; |
Jeffrey Yasskin | 8e68c38 | 2010-12-23 00:58:24 +0000 | [diff] [blame] | 334 | unsigned Opc = InFlag.getOpcode(); (void)Opc; |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 335 | assert(((Opc == ISD::ADDC || Opc == ISD::ADDE) || |
| 336 | (Opc == ISD::SUBC || Opc == ISD::SUBE)) && |
Bruno Cardoso Lopes | 0af5e09 | 2008-06-06 06:37:31 +0000 | [diff] [blame] | 337 | "(ADD|SUB)E flag operand must come from (ADD|SUB)C/E insn"); |
| 338 | |
Chris Lattner | 30baa95 | 2008-12-14 21:38:24 +0000 | [diff] [blame] | 339 | unsigned MOp; |
Bruno Cardoso Lopes | 0af5e09 | 2008-06-06 06:37:31 +0000 | [diff] [blame] | 340 | if (Opcode == ISD::ADDE) { |
| 341 | CmpLHS = InFlag.getValue(0); |
| 342 | MOp = Mips::ADDu; |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 343 | } else { |
Bruno Cardoso Lopes | 0af5e09 | 2008-06-06 06:37:31 +0000 | [diff] [blame] | 344 | CmpLHS = InFlag.getOperand(0); |
| 345 | MOp = Mips::SUBu; |
| 346 | } |
| 347 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 348 | SDValue Ops[] = { CmpLHS, InFlag.getOperand(1) }; |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 349 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 350 | SDValue LHS = Node->getOperand(0); |
| 351 | SDValue RHS = Node->getOperand(1); |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 352 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 353 | EVT VT = LHS.getValueType(); |
Dan Gohman | 602b0c8 | 2009-09-25 18:54:59 +0000 | [diff] [blame] | 354 | SDNode *Carry = CurDAG->getMachineNode(Mips::SLTu, dl, VT, Ops, 2); |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 355 | SDNode *AddCarry = CurDAG->getMachineNode(Mips::ADDu, dl, VT, |
Dan Gohman | 602b0c8 | 2009-09-25 18:54:59 +0000 | [diff] [blame] | 356 | SDValue(Carry,0), RHS); |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 357 | |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 358 | return CurDAG->SelectNodeTo(Node, MOp, VT, MVT::Glue, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 359 | LHS, SDValue(AddCarry,0)); |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 360 | } |
| 361 | |
Bruno Cardoso Lopes | 0af5e09 | 2008-06-06 06:37:31 +0000 | [diff] [blame] | 362 | /// Mul/Div with two results |
| 363 | case ISD::SDIVREM: |
| 364 | case ISD::UDIVREM: |
| 365 | case ISD::SMUL_LOHI: |
| 366 | case ISD::UMUL_LOHI: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 367 | SDValue Op1 = Node->getOperand(0); |
| 368 | SDValue Op2 = Node->getOperand(1); |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 369 | |
Bruno Cardoso Lopes | 0af5e09 | 2008-06-06 06:37:31 +0000 | [diff] [blame] | 370 | unsigned Op; |
| 371 | if (Opcode == ISD::UMUL_LOHI || Opcode == ISD::SMUL_LOHI) |
| 372 | Op = (Opcode == ISD::UMUL_LOHI ? Mips::MULTu : Mips::MULT); |
| 373 | else |
| 374 | Op = (Opcode == ISD::UDIVREM ? Mips::DIVu : Mips::DIV); |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 375 | |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 376 | SDNode *MulDiv = CurDAG->getMachineNode(Op, dl, MVT::Glue, Op1, Op2); |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 377 | |
Bruno Cardoso Lopes | 8c5ee71 | 2010-01-19 19:57:07 +0000 | [diff] [blame] | 378 | SDValue InFlag = SDValue(MulDiv, 0); |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 379 | SDNode *Lo = CurDAG->getMachineNode(Mips::MFLO, dl, MVT::i32, |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 380 | MVT::Glue, InFlag); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 381 | InFlag = SDValue(Lo,1); |
Dan Gohman | 602b0c8 | 2009-09-25 18:54:59 +0000 | [diff] [blame] | 382 | SDNode *Hi = CurDAG->getMachineNode(Mips::MFHI, dl, MVT::i32, InFlag); |
Bruno Cardoso Lopes | 0af5e09 | 2008-06-06 06:37:31 +0000 | [diff] [blame] | 383 | |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 384 | if (!SDValue(Node, 0).use_empty()) |
Dan Gohman | eeb3a00 | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 385 | ReplaceUses(SDValue(Node, 0), SDValue(Lo,0)); |
Bruno Cardoso Lopes | 0af5e09 | 2008-06-06 06:37:31 +0000 | [diff] [blame] | 386 | |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 387 | if (!SDValue(Node, 1).use_empty()) |
Dan Gohman | eeb3a00 | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 388 | ReplaceUses(SDValue(Node, 1), SDValue(Hi,0)); |
Bruno Cardoso Lopes | 0af5e09 | 2008-06-06 06:37:31 +0000 | [diff] [blame] | 389 | |
| 390 | return NULL; |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 391 | } |
| 392 | |
Bruno Cardoso Lopes | 0af5e09 | 2008-06-06 06:37:31 +0000 | [diff] [blame] | 393 | /// Special Muls |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 394 | case ISD::MUL: |
Bruno Cardoso Lopes | 7d5652d | 2010-11-12 00:38:32 +0000 | [diff] [blame] | 395 | if (Subtarget.isMips32()) |
| 396 | break; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 397 | case ISD::MULHS: |
| 398 | case ISD::MULHU: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 399 | SDValue MulOp1 = Node->getOperand(0); |
| 400 | SDValue MulOp2 = Node->getOperand(1); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 401 | |
| 402 | unsigned MulOp = (Opcode == ISD::MULHU ? Mips::MULTu : Mips::MULT); |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 403 | SDNode *MulNode = CurDAG->getMachineNode(MulOp, dl, |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 404 | MVT::Glue, MulOp1, MulOp2); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 405 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 406 | SDValue InFlag = SDValue(MulNode, 0); |
Bruno Cardoso Lopes | 0af5e09 | 2008-06-06 06:37:31 +0000 | [diff] [blame] | 407 | |
Bruno Cardoso Lopes | 9a720b0 | 2010-02-01 12:16:39 +0000 | [diff] [blame] | 408 | if (Opcode == ISD::MUL) |
Dan Gohman | 602b0c8 | 2009-09-25 18:54:59 +0000 | [diff] [blame] | 409 | return CurDAG->getMachineNode(Mips::MFLO, dl, MVT::i32, InFlag); |
Bruno Cardoso Lopes | 0af5e09 | 2008-06-06 06:37:31 +0000 | [diff] [blame] | 410 | else |
Dan Gohman | 602b0c8 | 2009-09-25 18:54:59 +0000 | [diff] [blame] | 411 | return CurDAG->getMachineNode(Mips::MFHI, dl, MVT::i32, InFlag); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 412 | } |
| 413 | |
Bruno Cardoso Lopes | 0af5e09 | 2008-06-06 06:37:31 +0000 | [diff] [blame] | 414 | /// Div/Rem operations |
| 415 | case ISD::SREM: |
| 416 | case ISD::UREM: |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 417 | case ISD::SDIV: |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 418 | case ISD::UDIV: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 419 | SDValue Op1 = Node->getOperand(0); |
| 420 | SDValue Op2 = Node->getOperand(1); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 421 | |
Bruno Cardoso Lopes | 0af5e09 | 2008-06-06 06:37:31 +0000 | [diff] [blame] | 422 | unsigned Op, MOp; |
| 423 | if (Opcode == ISD::SDIV || Opcode == ISD::UDIV) { |
| 424 | Op = (Opcode == ISD::SDIV ? Mips::DIV : Mips::DIVu); |
| 425 | MOp = Mips::MFLO; |
| 426 | } else { |
| 427 | Op = (Opcode == ISD::SREM ? Mips::DIV : Mips::DIVu); |
| 428 | MOp = Mips::MFHI; |
| 429 | } |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 430 | SDNode *Node = CurDAG->getMachineNode(Op, dl, MVT::Glue, Op1, Op2); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 431 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 432 | SDValue InFlag = SDValue(Node, 0); |
Dan Gohman | 602b0c8 | 2009-09-25 18:54:59 +0000 | [diff] [blame] | 433 | return CurDAG->getMachineNode(MOp, dl, MVT::i32, InFlag); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 434 | } |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 435 | |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 436 | // Get target GOT address. |
Dan Gohman | 9911405 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 437 | case ISD::GLOBAL_OFFSET_TABLE: |
| 438 | return getGlobalBaseReg(); |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 439 | |
Bruno Cardoso Lopes | a8173b9 | 2009-11-13 18:49:59 +0000 | [diff] [blame] | 440 | case ISD::ConstantFP: { |
Dan Gohman | eeb3a00 | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 441 | ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(Node); |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 442 | if (Node->getValueType(0) == MVT::f64 && CN->isExactlyValue(+0.0)) { |
| 443 | SDValue Zero = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl, |
Bruno Cardoso Lopes | ea98278 | 2010-01-19 12:53:04 +0000 | [diff] [blame] | 444 | Mips::ZERO, MVT::i32); |
| 445 | SDValue Undef = SDValue( |
Chris Lattner | 518bb53 | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 446 | CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, MVT::f64), 0); |
Bruno Cardoso Lopes | ea98278 | 2010-01-19 12:53:04 +0000 | [diff] [blame] | 447 | SDNode *MTC = CurDAG->getMachineNode(Mips::MTC1, dl, MVT::f32, Zero); |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 448 | SDValue I0 = CurDAG->getTargetInsertSubreg(Mips::sub_fpeven, dl, |
Bruno Cardoso Lopes | ea98278 | 2010-01-19 12:53:04 +0000 | [diff] [blame] | 449 | MVT::f64, Undef, SDValue(MTC, 0)); |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 450 | SDValue I1 = CurDAG->getTargetInsertSubreg(Mips::sub_fpodd, dl, |
Bruno Cardoso Lopes | ea98278 | 2010-01-19 12:53:04 +0000 | [diff] [blame] | 451 | MVT::f64, I0, SDValue(MTC, 0)); |
| 452 | ReplaceUses(SDValue(Node, 0), I1); |
| 453 | return I1.getNode(); |
Bruno Cardoso Lopes | a8173b9 | 2009-11-13 18:49:59 +0000 | [diff] [blame] | 454 | } |
| 455 | break; |
| 456 | } |
| 457 | |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 458 | case ISD::LOAD: |
Dan Gohman | eeb3a00 | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 459 | if (SDNode *ResNode = SelectLoadFp64(Node)) |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 460 | return ResNode; |
| 461 | // Other cases are autogenerated. |
| 462 | break; |
| 463 | |
| 464 | case ISD::STORE: |
Dan Gohman | eeb3a00 | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 465 | if (SDNode *ResNode = SelectStoreFp64(Node)) |
Bruno Cardoso Lopes | 2045c47 | 2009-11-19 06:06:13 +0000 | [diff] [blame] | 466 | return ResNode; |
| 467 | // Other cases are autogenerated. |
| 468 | break; |
| 469 | |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 470 | /// Handle direct and indirect calls when using PIC. On PIC, when |
| 471 | /// GOT is smaller than about 64k (small code) the GA target is |
| 472 | /// loaded with only one instruction. Otherwise GA's target must |
| 473 | /// be loaded with 3 instructions. |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 474 | case MipsISD::JmpLink: { |
| 475 | if (TM.getRelocationModel() == Reloc::PIC_) { |
Bruno Cardoso Lopes | 9201b10 | 2010-01-19 17:00:43 +0000 | [diff] [blame] | 476 | unsigned LastOpNum = Node->getNumOperands()-1; |
| 477 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 478 | SDValue Chain = Node->getOperand(0); |
| 479 | SDValue Callee = Node->getOperand(1); |
Bruno Cardoso Lopes | 9201b10 | 2010-01-19 17:00:43 +0000 | [diff] [blame] | 480 | SDValue InFlag; |
| 481 | |
| 482 | // Skip the incomming flag if present |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 483 | if (Node->getOperand(LastOpNum).getValueType() == MVT::Glue) |
Bruno Cardoso Lopes | 9201b10 | 2010-01-19 17:00:43 +0000 | [diff] [blame] | 484 | LastOpNum--; |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 485 | |
| 486 | if ( (isa<GlobalAddressSDNode>(Callee)) || |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 487 | (isa<ExternalSymbolSDNode>(Callee)) ) |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 488 | { |
| 489 | /// Direct call for global addresses and external symbols |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 490 | SDValue GPReg = CurDAG->getRegister(Mips::GP, MVT::i32); |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 491 | |
| 492 | // Use load to get GOT target |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 493 | SDValue Ops[] = { Callee, GPReg, Chain }; |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 494 | SDValue Load = SDValue(CurDAG->getMachineNode(Mips::LW, dl, MVT::i32, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 495 | MVT::Other, Ops, 3), 0); |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 496 | Chain = Load.getValue(1); |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 497 | |
| 498 | // Call target must be on T9 |
Bruno Cardoso Lopes | 9201b10 | 2010-01-19 17:00:43 +0000 | [diff] [blame] | 499 | Chain = CurDAG->getCopyToReg(Chain, dl, Mips::T9, Load, InFlag); |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 500 | } else |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 501 | /// Indirect call |
Bruno Cardoso Lopes | 9201b10 | 2010-01-19 17:00:43 +0000 | [diff] [blame] | 502 | Chain = CurDAG->getCopyToReg(Chain, dl, Mips::T9, Callee, InFlag); |
| 503 | |
| 504 | // Map the JmpLink operands to JALR |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 505 | SDVTList NodeTys = CurDAG->getVTList(MVT::Other, MVT::Glue); |
Bruno Cardoso Lopes | 9201b10 | 2010-01-19 17:00:43 +0000 | [diff] [blame] | 506 | SmallVector<SDValue, 8> Ops; |
| 507 | Ops.push_back(CurDAG->getRegister(Mips::T9, MVT::i32)); |
| 508 | |
| 509 | for (unsigned i = 2, e = LastOpNum+1; i != e; ++i) |
| 510 | Ops.push_back(Node->getOperand(i)); |
| 511 | Ops.push_back(Chain); |
| 512 | Ops.push_back(Chain.getValue(1)); |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 513 | |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 514 | // Emit Jump and Link Register |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 515 | SDNode *ResNode = CurDAG->getMachineNode(Mips::JALR, dl, NodeTys, |
Bruno Cardoso Lopes | 9201b10 | 2010-01-19 17:00:43 +0000 | [diff] [blame] | 516 | &Ops[0], Ops.size()); |
| 517 | |
| 518 | // Replace Chain and InFlag |
| 519 | ReplaceUses(SDValue(Node, 0), SDValue(ResNode, 0)); |
| 520 | ReplaceUses(SDValue(Node, 1), SDValue(ResNode, 1)); |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 521 | return ResNode; |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 522 | } |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 523 | } |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | // Select the default instruction |
Dan Gohman | eeb3a00 | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 527 | SDNode *ResNode = SelectCode(Node); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 528 | |
Chris Lattner | 7c306da | 2010-03-02 06:34:30 +0000 | [diff] [blame] | 529 | DEBUG(errs() << "=> "); |
Dan Gohman | eeb3a00 | 2010-01-05 01:24:18 +0000 | [diff] [blame] | 530 | if (ResNode == NULL || ResNode == Node) |
| 531 | DEBUG(Node->dump(CurDAG)); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 532 | else |
| 533 | DEBUG(ResNode->dump(CurDAG)); |
Chris Lattner | 893e1c9 | 2009-08-23 06:49:22 +0000 | [diff] [blame] | 534 | DEBUG(errs() << "\n"); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 535 | return ResNode; |
| 536 | } |
| 537 | |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 538 | /// createMipsISelDag - This pass converts a legalized DAG into a |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 539 | /// MIPS-specific DAG, ready for instruction scheduling. |
| 540 | FunctionPass *llvm::createMipsISelDag(MipsTargetMachine &TM) { |
| 541 | return new MipsDAGToDAGISel(TM); |
| 542 | } |