Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 1 | //===-- MipsSEISelDAGToDAG.cpp - A Dag to Dag Inst Selector for MipsSE ----===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Subclass of MipsDAGToDAGISel specialized for mips32/64. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 14 | #include "MipsSEISelDAGToDAG.h" |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 15 | #include "MCTargetDesc/MipsBaseInfo.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 16 | #include "Mips.h" |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 17 | #include "MipsAnalyzeImmediate.h" |
| 18 | #include "MipsMachineFunction.h" |
| 19 | #include "MipsRegisterInfo.h" |
| 20 | #include "llvm/CodeGen/MachineConstantPool.h" |
| 21 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 22 | #include "llvm/CodeGen/MachineFunction.h" |
| 23 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 24 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| 25 | #include "llvm/CodeGen/SelectionDAGNodes.h" |
Chandler Carruth | 1305dc3 | 2014-03-04 11:45:46 +0000 | [diff] [blame] | 26 | #include "llvm/IR/CFG.h" |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 27 | #include "llvm/IR/GlobalValue.h" |
| 28 | #include "llvm/IR/Instructions.h" |
| 29 | #include "llvm/IR/Intrinsics.h" |
| 30 | #include "llvm/IR/Type.h" |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 31 | #include "llvm/Support/Debug.h" |
| 32 | #include "llvm/Support/ErrorHandling.h" |
| 33 | #include "llvm/Support/raw_ostream.h" |
| 34 | #include "llvm/Target/TargetMachine.h" |
| 35 | using namespace llvm; |
| 36 | |
Chandler Carruth | 84e68b2 | 2014-04-22 02:41:26 +0000 | [diff] [blame] | 37 | #define DEBUG_TYPE "mips-isel" |
| 38 | |
Reed Kotler | 1595f36 | 2013-04-09 19:46:01 +0000 | [diff] [blame] | 39 | bool MipsSEDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) { |
Eric Christopher | 96e72c6 | 2015-01-29 23:27:36 +0000 | [diff] [blame] | 40 | Subtarget = &static_cast<const MipsSubtarget &>(MF.getSubtarget()); |
Eric Christopher | 22405e4 | 2014-07-10 17:26:51 +0000 | [diff] [blame] | 41 | if (Subtarget->inMips16Mode()) |
Reed Kotler | 1595f36 | 2013-04-09 19:46:01 +0000 | [diff] [blame] | 42 | return false; |
| 43 | return MipsDAGToDAGISel::runOnMachineFunction(MF); |
| 44 | } |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 45 | |
Akira Hatanaka | e86bd4f | 2013-05-03 18:37:49 +0000 | [diff] [blame] | 46 | void MipsSEDAGToDAGISel::addDSPCtrlRegOperands(bool IsDef, MachineInstr &MI, |
| 47 | MachineFunction &MF) { |
| 48 | MachineInstrBuilder MIB(MF, &MI); |
| 49 | unsigned Mask = MI.getOperand(1).getImm(); |
Daniel Sanders | 435a653 | 2016-06-14 09:29:46 +0000 | [diff] [blame] | 50 | unsigned Flag = |
| 51 | IsDef ? RegState::ImplicitDefine : RegState::Implicit | RegState::Undef; |
Akira Hatanaka | e86bd4f | 2013-05-03 18:37:49 +0000 | [diff] [blame] | 52 | |
| 53 | if (Mask & 1) |
| 54 | MIB.addReg(Mips::DSPPos, Flag); |
| 55 | |
| 56 | if (Mask & 2) |
| 57 | MIB.addReg(Mips::DSPSCount, Flag); |
| 58 | |
| 59 | if (Mask & 4) |
| 60 | MIB.addReg(Mips::DSPCarry, Flag); |
| 61 | |
| 62 | if (Mask & 8) |
| 63 | MIB.addReg(Mips::DSPOutFlag, Flag); |
| 64 | |
| 65 | if (Mask & 16) |
| 66 | MIB.addReg(Mips::DSPCCond, Flag); |
| 67 | |
| 68 | if (Mask & 32) |
| 69 | MIB.addReg(Mips::DSPEFI, Flag); |
| 70 | } |
| 71 | |
Daniel Sanders | f9aa1d1 | 2013-08-28 10:26:24 +0000 | [diff] [blame] | 72 | unsigned MipsSEDAGToDAGISel::getMSACtrlReg(const SDValue RegIdx) const { |
| 73 | switch (cast<ConstantSDNode>(RegIdx)->getZExtValue()) { |
| 74 | default: |
| 75 | llvm_unreachable("Could not map int to register"); |
| 76 | case 0: return Mips::MSAIR; |
| 77 | case 1: return Mips::MSACSR; |
| 78 | case 2: return Mips::MSAAccess; |
| 79 | case 3: return Mips::MSASave; |
| 80 | case 4: return Mips::MSAModify; |
| 81 | case 5: return Mips::MSARequest; |
| 82 | case 6: return Mips::MSAMap; |
| 83 | case 7: return Mips::MSAUnmap; |
| 84 | } |
| 85 | } |
| 86 | |
Akira Hatanaka | 040d225 | 2013-03-14 18:33:23 +0000 | [diff] [blame] | 87 | bool MipsSEDAGToDAGISel::replaceUsesWithZeroReg(MachineRegisterInfo *MRI, |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 88 | const MachineInstr& MI) { |
| 89 | unsigned DstReg = 0, ZeroReg = 0; |
| 90 | |
| 91 | // Check if MI is "addiu $dst, $zero, 0" or "daddiu $dst, $zero, 0". |
| 92 | if ((MI.getOpcode() == Mips::ADDiu) && |
| 93 | (MI.getOperand(1).getReg() == Mips::ZERO) && |
| 94 | (MI.getOperand(2).getImm() == 0)) { |
| 95 | DstReg = MI.getOperand(0).getReg(); |
| 96 | ZeroReg = Mips::ZERO; |
| 97 | } else if ((MI.getOpcode() == Mips::DADDiu) && |
| 98 | (MI.getOperand(1).getReg() == Mips::ZERO_64) && |
| 99 | (MI.getOperand(2).getImm() == 0)) { |
| 100 | DstReg = MI.getOperand(0).getReg(); |
| 101 | ZeroReg = Mips::ZERO_64; |
| 102 | } |
| 103 | |
| 104 | if (!DstReg) |
| 105 | return false; |
| 106 | |
| 107 | // Replace uses with ZeroReg. |
| 108 | for (MachineRegisterInfo::use_iterator U = MRI->use_begin(DstReg), |
| 109 | E = MRI->use_end(); U != E;) { |
Owen Anderson | 16c6bf4 | 2014-03-13 23:12:04 +0000 | [diff] [blame] | 110 | MachineOperand &MO = *U; |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 111 | unsigned OpNo = U.getOperandNo(); |
| 112 | MachineInstr *MI = MO.getParent(); |
| 113 | ++U; |
| 114 | |
| 115 | // Do not replace if it is a phi's operand or is tied to def operand. |
| 116 | if (MI->isPHI() || MI->isRegTiedToDefOperand(OpNo) || MI->isPseudo()) |
| 117 | continue; |
| 118 | |
Vasileios Kalintiris | 2f41268 | 2015-10-29 10:17:16 +0000 | [diff] [blame] | 119 | // Also, we have to check that the register class of the operand |
| 120 | // contains the zero register. |
| 121 | if (!MRI->getRegClass(MO.getReg())->contains(ZeroReg)) |
| 122 | continue; |
| 123 | |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 124 | MO.setReg(ZeroReg); |
| 125 | } |
| 126 | |
| 127 | return true; |
| 128 | } |
| 129 | |
Akira Hatanaka | 040d225 | 2013-03-14 18:33:23 +0000 | [diff] [blame] | 130 | void MipsSEDAGToDAGISel::initGlobalBaseReg(MachineFunction &MF) { |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 131 | MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>(); |
| 132 | |
| 133 | if (!MipsFI->globalBaseRegSet()) |
| 134 | return; |
| 135 | |
| 136 | MachineBasicBlock &MBB = MF.front(); |
| 137 | MachineBasicBlock::iterator I = MBB.begin(); |
| 138 | MachineRegisterInfo &RegInfo = MF.getRegInfo(); |
Eric Christopher | 96e72c6 | 2015-01-29 23:27:36 +0000 | [diff] [blame] | 139 | const TargetInstrInfo &TII = *Subtarget->getInstrInfo(); |
Petar Jovanovic | 28e2b71 | 2015-08-28 17:53:26 +0000 | [diff] [blame] | 140 | DebugLoc DL; |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 141 | unsigned V0, V1, GlobalBaseReg = MipsFI->getGlobalBaseReg(); |
| 142 | const TargetRegisterClass *RC; |
Eric Christopher | d86af63 | 2015-01-29 23:27:45 +0000 | [diff] [blame] | 143 | const MipsABIInfo &ABI = static_cast<const MipsTargetMachine &>(TM).getABI(); |
| 144 | RC = (ABI.IsN64()) ? &Mips::GPR64RegClass : &Mips::GPR32RegClass; |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 145 | |
| 146 | V0 = RegInfo.createVirtualRegister(RC); |
| 147 | V1 = RegInfo.createVirtualRegister(RC); |
| 148 | |
Eric Christopher | d86af63 | 2015-01-29 23:27:45 +0000 | [diff] [blame] | 149 | if (ABI.IsN64()) { |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 150 | MF.getRegInfo().addLiveIn(Mips::T9_64); |
| 151 | MBB.addLiveIn(Mips::T9_64); |
| 152 | |
| 153 | // lui $v0, %hi(%neg(%gp_rel(fname))) |
| 154 | // daddu $v1, $v0, $t9 |
| 155 | // daddiu $globalbasereg, $v1, %lo(%neg(%gp_rel(fname))) |
| 156 | const GlobalValue *FName = MF.getFunction(); |
| 157 | BuildMI(MBB, I, DL, TII.get(Mips::LUi64), V0) |
| 158 | .addGlobalAddress(FName, 0, MipsII::MO_GPOFF_HI); |
| 159 | BuildMI(MBB, I, DL, TII.get(Mips::DADDu), V1).addReg(V0) |
| 160 | .addReg(Mips::T9_64); |
| 161 | BuildMI(MBB, I, DL, TII.get(Mips::DADDiu), GlobalBaseReg).addReg(V1) |
| 162 | .addGlobalAddress(FName, 0, MipsII::MO_GPOFF_LO); |
| 163 | return; |
| 164 | } |
| 165 | |
Rafael Espindola | b30e66b | 2016-06-28 14:33:28 +0000 | [diff] [blame] | 166 | if (!MF.getTarget().isPositionIndependent()) { |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 167 | // Set global register to __gnu_local_gp. |
| 168 | // |
| 169 | // lui $v0, %hi(__gnu_local_gp) |
| 170 | // addiu $globalbasereg, $v0, %lo(__gnu_local_gp) |
| 171 | BuildMI(MBB, I, DL, TII.get(Mips::LUi), V0) |
| 172 | .addExternalSymbol("__gnu_local_gp", MipsII::MO_ABS_HI); |
| 173 | BuildMI(MBB, I, DL, TII.get(Mips::ADDiu), GlobalBaseReg).addReg(V0) |
| 174 | .addExternalSymbol("__gnu_local_gp", MipsII::MO_ABS_LO); |
| 175 | return; |
| 176 | } |
| 177 | |
| 178 | MF.getRegInfo().addLiveIn(Mips::T9); |
| 179 | MBB.addLiveIn(Mips::T9); |
| 180 | |
Eric Christopher | d86af63 | 2015-01-29 23:27:45 +0000 | [diff] [blame] | 181 | if (ABI.IsN32()) { |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 182 | // lui $v0, %hi(%neg(%gp_rel(fname))) |
| 183 | // addu $v1, $v0, $t9 |
| 184 | // addiu $globalbasereg, $v1, %lo(%neg(%gp_rel(fname))) |
| 185 | const GlobalValue *FName = MF.getFunction(); |
| 186 | BuildMI(MBB, I, DL, TII.get(Mips::LUi), V0) |
| 187 | .addGlobalAddress(FName, 0, MipsII::MO_GPOFF_HI); |
| 188 | BuildMI(MBB, I, DL, TII.get(Mips::ADDu), V1).addReg(V0).addReg(Mips::T9); |
| 189 | BuildMI(MBB, I, DL, TII.get(Mips::ADDiu), GlobalBaseReg).addReg(V1) |
| 190 | .addGlobalAddress(FName, 0, MipsII::MO_GPOFF_LO); |
| 191 | return; |
| 192 | } |
| 193 | |
Eric Christopher | d86af63 | 2015-01-29 23:27:45 +0000 | [diff] [blame] | 194 | assert(ABI.IsO32()); |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 195 | |
| 196 | // For O32 ABI, the following instruction sequence is emitted to initialize |
| 197 | // the global base register: |
| 198 | // |
| 199 | // 0. lui $2, %hi(_gp_disp) |
| 200 | // 1. addiu $2, $2, %lo(_gp_disp) |
| 201 | // 2. addu $globalbasereg, $2, $t9 |
| 202 | // |
| 203 | // We emit only the last instruction here. |
| 204 | // |
| 205 | // GNU linker requires that the first two instructions appear at the beginning |
| 206 | // of a function and no instructions be inserted before or between them. |
| 207 | // The two instructions are emitted during lowering to MC layer in order to |
| 208 | // avoid any reordering. |
| 209 | // |
| 210 | // Register $2 (Mips::V0) is added to the list of live-in registers to ensure |
| 211 | // the value instruction 1 (addiu) defines is valid when instruction 2 (addu) |
| 212 | // reads it. |
| 213 | MF.getRegInfo().addLiveIn(Mips::V0); |
| 214 | MBB.addLiveIn(Mips::V0); |
| 215 | BuildMI(MBB, I, DL, TII.get(Mips::ADDu), GlobalBaseReg) |
| 216 | .addReg(Mips::V0).addReg(Mips::T9); |
| 217 | } |
| 218 | |
Akira Hatanaka | 040d225 | 2013-03-14 18:33:23 +0000 | [diff] [blame] | 219 | void MipsSEDAGToDAGISel::processFunctionAfterISel(MachineFunction &MF) { |
| 220 | initGlobalBaseReg(MF); |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 221 | |
| 222 | MachineRegisterInfo *MRI = &MF.getRegInfo(); |
| 223 | |
Vasileios Kalintiris | 3631139 | 2016-04-15 20:18:48 +0000 | [diff] [blame] | 224 | for (auto &MBB: MF) { |
| 225 | for (auto &MI: MBB) { |
| 226 | switch (MI.getOpcode()) { |
| 227 | case Mips::RDDSP: |
| 228 | addDSPCtrlRegOperands(false, MI, MF); |
| 229 | break; |
| 230 | case Mips::WRDSP: |
| 231 | addDSPCtrlRegOperands(true, MI, MF); |
| 232 | break; |
| 233 | default: |
| 234 | replaceUsesWithZeroReg(MRI, MI); |
| 235 | } |
Akira Hatanaka | e86bd4f | 2013-05-03 18:37:49 +0000 | [diff] [blame] | 236 | } |
Vasileios Kalintiris | 3631139 | 2016-04-15 20:18:48 +0000 | [diff] [blame] | 237 | } |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 238 | } |
| 239 | |
Justin Bogner | eeae751 | 2016-05-13 23:55:59 +0000 | [diff] [blame] | 240 | void MipsSEDAGToDAGISel::selectAddESubE(unsigned MOp, SDValue InFlag, |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 241 | SDValue CmpLHS, const SDLoc &DL, |
| 242 | SDNode *Node) const { |
Akira Hatanaka | b8835b8 | 2013-03-14 18:39:25 +0000 | [diff] [blame] | 243 | unsigned Opc = InFlag.getOpcode(); (void)Opc; |
| 244 | |
| 245 | assert(((Opc == ISD::ADDC || Opc == ISD::ADDE) || |
| 246 | (Opc == ISD::SUBC || Opc == ISD::SUBE)) && |
| 247 | "(ADD|SUB)E flag operand must come from (ADD|SUB)C/E insn"); |
| 248 | |
Vasileios Kalintiris | ef96a8e | 2015-01-26 12:33:22 +0000 | [diff] [blame] | 249 | unsigned SLTuOp = Mips::SLTu, ADDuOp = Mips::ADDu; |
| 250 | if (Subtarget->isGP64bit()) { |
| 251 | SLTuOp = Mips::SLTu64; |
| 252 | ADDuOp = Mips::DADDu; |
| 253 | } |
| 254 | |
Akira Hatanaka | b8835b8 | 2013-03-14 18:39:25 +0000 | [diff] [blame] | 255 | SDValue Ops[] = { CmpLHS, InFlag.getOperand(1) }; |
| 256 | SDValue LHS = Node->getOperand(0), RHS = Node->getOperand(1); |
| 257 | EVT VT = LHS.getValueType(); |
| 258 | |
Vasileios Kalintiris | 36901dd | 2016-03-01 20:25:43 +0000 | [diff] [blame] | 259 | SDNode *Carry = CurDAG->getMachineNode(SLTuOp, DL, VT, Ops); |
| 260 | |
| 261 | if (Subtarget->isGP64bit()) { |
| 262 | // On 64-bit targets, sltu produces an i64 but our backend currently says |
| 263 | // that SLTu64 produces an i32. We need to fix this in the long run but for |
| 264 | // now, just make the DAG type-correct by asserting the upper bits are zero. |
| 265 | Carry = CurDAG->getMachineNode(Mips::SUBREG_TO_REG, DL, VT, |
| 266 | CurDAG->getTargetConstant(0, DL, VT), |
| 267 | SDValue(Carry, 0), |
| 268 | CurDAG->getTargetConstant(Mips::sub_32, DL, |
| 269 | VT)); |
| 270 | } |
| 271 | |
Vasileios Kalintiris | 18581f1 | 2015-02-27 09:01:39 +0000 | [diff] [blame] | 272 | // Generate a second addition only if we know that RHS is not a |
| 273 | // constant-zero node. |
Vasileios Kalintiris | 36901dd | 2016-03-01 20:25:43 +0000 | [diff] [blame] | 274 | SDNode *AddCarry = Carry; |
Vasileios Kalintiris | 18581f1 | 2015-02-27 09:01:39 +0000 | [diff] [blame] | 275 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(RHS); |
| 276 | if (!C || C->getZExtValue()) |
Vasileios Kalintiris | 36901dd | 2016-03-01 20:25:43 +0000 | [diff] [blame] | 277 | AddCarry = CurDAG->getMachineNode(ADDuOp, DL, VT, SDValue(Carry, 0), RHS); |
Vasileios Kalintiris | ef96a8e | 2015-01-26 12:33:22 +0000 | [diff] [blame] | 278 | |
Justin Bogner | eeae751 | 2016-05-13 23:55:59 +0000 | [diff] [blame] | 279 | CurDAG->SelectNodeTo(Node, MOp, VT, MVT::Glue, LHS, SDValue(AddCarry, 0)); |
Akira Hatanaka | b8835b8 | 2013-03-14 18:39:25 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Daniel Sanders | fa961d7 | 2014-03-03 14:31:21 +0000 | [diff] [blame] | 282 | /// Match frameindex |
| 283 | bool MipsSEDAGToDAGISel::selectAddrFrameIndex(SDValue Addr, SDValue &Base, |
| 284 | SDValue &Offset) const { |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 285 | if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) { |
Daniel Sanders | fa961d7 | 2014-03-03 14:31:21 +0000 | [diff] [blame] | 286 | EVT ValTy = Addr.getValueType(); |
| 287 | |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 288 | Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), ValTy); |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 289 | Offset = CurDAG->getTargetConstant(0, SDLoc(Addr), ValTy); |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 290 | return true; |
| 291 | } |
Daniel Sanders | fa961d7 | 2014-03-03 14:31:21 +0000 | [diff] [blame] | 292 | return false; |
| 293 | } |
| 294 | |
| 295 | /// Match frameindex+offset and frameindex|offset |
Hrvoje Varga | 00d96ee | 2016-08-01 06:46:20 +0000 | [diff] [blame] | 296 | bool MipsSEDAGToDAGISel::selectAddrFrameIndexOffset( |
| 297 | SDValue Addr, SDValue &Base, SDValue &Offset, unsigned OffsetBits, |
| 298 | unsigned ShiftAmount = 0) const { |
Daniel Sanders | fa961d7 | 2014-03-03 14:31:21 +0000 | [diff] [blame] | 299 | if (CurDAG->isBaseWithConstantOffset(Addr)) { |
| 300 | ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1)); |
Hrvoje Varga | 00d96ee | 2016-08-01 06:46:20 +0000 | [diff] [blame] | 301 | if (isIntN(OffsetBits + ShiftAmount, CN->getSExtValue())) { |
Daniel Sanders | fa961d7 | 2014-03-03 14:31:21 +0000 | [diff] [blame] | 302 | EVT ValTy = Addr.getValueType(); |
| 303 | |
| 304 | // If the first operand is a FI, get the TargetFI Node |
Hrvoje Varga | 00d96ee | 2016-08-01 06:46:20 +0000 | [diff] [blame] | 305 | if (FrameIndexSDNode *FIN = |
| 306 | dyn_cast<FrameIndexSDNode>(Addr.getOperand(0))) |
Daniel Sanders | fa961d7 | 2014-03-03 14:31:21 +0000 | [diff] [blame] | 307 | Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), ValTy); |
Hrvoje Varga | 00d96ee | 2016-08-01 06:46:20 +0000 | [diff] [blame] | 308 | else { |
Daniel Sanders | fa961d7 | 2014-03-03 14:31:21 +0000 | [diff] [blame] | 309 | Base = Addr.getOperand(0); |
Hrvoje Varga | 00d96ee | 2016-08-01 06:46:20 +0000 | [diff] [blame] | 310 | // If base is a FI, additional offset calculation is done in |
| 311 | // eliminateFrameIndex, otherwise we need to check the alignment |
Simon Pilgrim | 2ddeee1 | 2016-08-01 09:40:38 +0000 | [diff] [blame] | 312 | if (OffsetToAlignment(CN->getZExtValue(), 1ull << ShiftAmount) != 0) |
Hrvoje Varga | 00d96ee | 2016-08-01 06:46:20 +0000 | [diff] [blame] | 313 | return false; |
| 314 | } |
Daniel Sanders | fa961d7 | 2014-03-03 14:31:21 +0000 | [diff] [blame] | 315 | |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 316 | Offset = CurDAG->getTargetConstant(CN->getZExtValue(), SDLoc(Addr), |
| 317 | ValTy); |
Daniel Sanders | fa961d7 | 2014-03-03 14:31:21 +0000 | [diff] [blame] | 318 | return true; |
| 319 | } |
| 320 | } |
| 321 | return false; |
| 322 | } |
| 323 | |
| 324 | /// ComplexPattern used on MipsInstrInfo |
| 325 | /// Used on Mips Load/Store instructions |
| 326 | bool MipsSEDAGToDAGISel::selectAddrRegImm(SDValue Addr, SDValue &Base, |
| 327 | SDValue &Offset) const { |
| 328 | // if Address is FI, get the TargetFrameIndex. |
| 329 | if (selectAddrFrameIndex(Addr, Base, Offset)) |
| 330 | return true; |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 331 | |
| 332 | // on PIC code Load GA |
| 333 | if (Addr.getOpcode() == MipsISD::Wrapper) { |
| 334 | Base = Addr.getOperand(0); |
| 335 | Offset = Addr.getOperand(1); |
| 336 | return true; |
| 337 | } |
| 338 | |
Rafael Espindola | b30e66b | 2016-06-28 14:33:28 +0000 | [diff] [blame] | 339 | if (!TM.isPositionIndependent()) { |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 340 | if ((Addr.getOpcode() == ISD::TargetExternalSymbol || |
| 341 | Addr.getOpcode() == ISD::TargetGlobalAddress)) |
| 342 | return false; |
| 343 | } |
| 344 | |
| 345 | // Addresses of the form FI+const or FI|const |
Daniel Sanders | fa961d7 | 2014-03-03 14:31:21 +0000 | [diff] [blame] | 346 | if (selectAddrFrameIndexOffset(Addr, Base, Offset, 16)) |
| 347 | return true; |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 348 | |
| 349 | // Operand is a result from an ADD. |
| 350 | if (Addr.getOpcode() == ISD::ADD) { |
| 351 | // When loading from constant pools, load the lower address part in |
| 352 | // the instruction itself. Example, instead of: |
| 353 | // lui $2, %hi($CPI1_0) |
| 354 | // addiu $2, $2, %lo($CPI1_0) |
| 355 | // lwc1 $f0, 0($2) |
| 356 | // Generate: |
| 357 | // lui $2, %hi($CPI1_0) |
| 358 | // lwc1 $f0, %lo($CPI1_0)($2) |
| 359 | if (Addr.getOperand(1).getOpcode() == MipsISD::Lo || |
| 360 | Addr.getOperand(1).getOpcode() == MipsISD::GPRel) { |
| 361 | SDValue Opnd0 = Addr.getOperand(1).getOperand(0); |
| 362 | if (isa<ConstantPoolSDNode>(Opnd0) || isa<GlobalAddressSDNode>(Opnd0) || |
| 363 | isa<JumpTableSDNode>(Opnd0)) { |
| 364 | Base = Addr.getOperand(0); |
| 365 | Offset = Opnd0; |
| 366 | return true; |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | return false; |
| 372 | } |
| 373 | |
Daniel Sanders | e6ed5b7 | 2013-08-28 12:04:29 +0000 | [diff] [blame] | 374 | /// ComplexPattern used on MipsInstrInfo |
| 375 | /// Used on Mips Load/Store instructions |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 376 | bool MipsSEDAGToDAGISel::selectAddrDefault(SDValue Addr, SDValue &Base, |
| 377 | SDValue &Offset) const { |
| 378 | Base = Addr; |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 379 | Offset = CurDAG->getTargetConstant(0, SDLoc(Addr), Addr.getValueType()); |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 380 | return true; |
| 381 | } |
| 382 | |
| 383 | bool MipsSEDAGToDAGISel::selectIntAddr(SDValue Addr, SDValue &Base, |
| 384 | SDValue &Offset) const { |
| 385 | return selectAddrRegImm(Addr, Base, Offset) || |
| 386 | selectAddrDefault(Addr, Base, Offset); |
| 387 | } |
| 388 | |
Daniel Sanders | a73d8fe | 2015-03-24 11:26:34 +0000 | [diff] [blame] | 389 | bool MipsSEDAGToDAGISel::selectAddrRegImm9(SDValue Addr, SDValue &Base, |
| 390 | SDValue &Offset) const { |
| 391 | if (selectAddrFrameIndex(Addr, Base, Offset)) |
| 392 | return true; |
| 393 | |
| 394 | if (selectAddrFrameIndexOffset(Addr, Base, Offset, 9)) |
| 395 | return true; |
| 396 | |
| 397 | return false; |
| 398 | } |
| 399 | |
Zlatko Buljan | cba9f80 | 2016-07-11 07:41:56 +0000 | [diff] [blame] | 400 | /// Used on microMIPS LWC2, LDC2, SWC2 and SDC2 instructions (11-bit offset) |
| 401 | bool MipsSEDAGToDAGISel::selectAddrRegImm11(SDValue Addr, SDValue &Base, |
| 402 | SDValue &Offset) const { |
| 403 | if (selectAddrFrameIndex(Addr, Base, Offset)) |
| 404 | return true; |
| 405 | |
| 406 | if (selectAddrFrameIndexOffset(Addr, Base, Offset, 11)) |
| 407 | return true; |
| 408 | |
| 409 | return false; |
| 410 | } |
| 411 | |
Jack Carter | 9770097 | 2013-08-13 20:19:16 +0000 | [diff] [blame] | 412 | /// Used on microMIPS Load/Store unaligned instructions (12-bit offset) |
| 413 | bool MipsSEDAGToDAGISel::selectAddrRegImm12(SDValue Addr, SDValue &Base, |
| 414 | SDValue &Offset) const { |
Daniel Sanders | fa961d7 | 2014-03-03 14:31:21 +0000 | [diff] [blame] | 415 | if (selectAddrFrameIndex(Addr, Base, Offset)) |
| 416 | return true; |
Jack Carter | 9770097 | 2013-08-13 20:19:16 +0000 | [diff] [blame] | 417 | |
Daniel Sanders | fa961d7 | 2014-03-03 14:31:21 +0000 | [diff] [blame] | 418 | if (selectAddrFrameIndexOffset(Addr, Base, Offset, 12)) |
| 419 | return true; |
Jack Carter | 9770097 | 2013-08-13 20:19:16 +0000 | [diff] [blame] | 420 | |
| 421 | return false; |
| 422 | } |
| 423 | |
Daniel Sanders | a73d8fe | 2015-03-24 11:26:34 +0000 | [diff] [blame] | 424 | bool MipsSEDAGToDAGISel::selectAddrRegImm16(SDValue Addr, SDValue &Base, |
| 425 | SDValue &Offset) const { |
| 426 | if (selectAddrFrameIndex(Addr, Base, Offset)) |
| 427 | return true; |
| 428 | |
| 429 | if (selectAddrFrameIndexOffset(Addr, Base, Offset, 16)) |
| 430 | return true; |
| 431 | |
| 432 | return false; |
| 433 | } |
| 434 | |
Zlatko Buljan | cba9f80 | 2016-07-11 07:41:56 +0000 | [diff] [blame] | 435 | bool MipsSEDAGToDAGISel::selectIntAddr11MM(SDValue Addr, SDValue &Base, |
| 436 | SDValue &Offset) const { |
| 437 | return selectAddrRegImm11(Addr, Base, Offset) || |
| 438 | selectAddrDefault(Addr, Base, Offset); |
| 439 | } |
| 440 | |
| 441 | bool MipsSEDAGToDAGISel::selectIntAddr12MM(SDValue Addr, SDValue &Base, |
Jack Carter | 9770097 | 2013-08-13 20:19:16 +0000 | [diff] [blame] | 442 | SDValue &Offset) const { |
| 443 | return selectAddrRegImm12(Addr, Base, Offset) || |
| 444 | selectAddrDefault(Addr, Base, Offset); |
| 445 | } |
| 446 | |
Zlatko Buljan | cba9f80 | 2016-07-11 07:41:56 +0000 | [diff] [blame] | 447 | bool MipsSEDAGToDAGISel::selectIntAddr16MM(SDValue Addr, SDValue &Base, |
| 448 | SDValue &Offset) const { |
| 449 | return selectAddrRegImm16(Addr, Base, Offset) || |
| 450 | selectAddrDefault(Addr, Base, Offset); |
| 451 | } |
| 452 | |
Zoran Jovanovic | 5a1a780 | 2015-02-04 15:43:17 +0000 | [diff] [blame] | 453 | bool MipsSEDAGToDAGISel::selectIntAddrLSL2MM(SDValue Addr, SDValue &Base, |
| 454 | SDValue &Offset) const { |
| 455 | if (selectAddrFrameIndexOffset(Addr, Base, Offset, 7)) { |
Vasileios Kalintiris | 99eeb8a | 2015-02-13 19:14:22 +0000 | [diff] [blame] | 456 | if (isa<FrameIndexSDNode>(Base)) |
Zoran Jovanovic | 5a1a780 | 2015-02-04 15:43:17 +0000 | [diff] [blame] | 457 | return false; |
Zoran Jovanovic | 5a1a780 | 2015-02-04 15:43:17 +0000 | [diff] [blame] | 458 | |
Vasileios Kalintiris | 99eeb8a | 2015-02-13 19:14:22 +0000 | [diff] [blame] | 459 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Offset)) { |
| 460 | unsigned CnstOff = CN->getZExtValue(); |
| 461 | return (CnstOff == (CnstOff & 0x3c)); |
Zoran Jovanovic | 5a1a780 | 2015-02-04 15:43:17 +0000 | [diff] [blame] | 462 | } |
Vasileios Kalintiris | 99eeb8a | 2015-02-13 19:14:22 +0000 | [diff] [blame] | 463 | |
| 464 | return false; |
Zoran Jovanovic | 5a1a780 | 2015-02-04 15:43:17 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | // For all other cases where "lw" would be selected, don't select "lw16" |
| 468 | // because it would result in additional instructions to prepare operands. |
| 469 | if (selectAddrRegImm(Addr, Base, Offset)) |
| 470 | return false; |
| 471 | |
| 472 | return selectAddrDefault(Addr, Base, Offset); |
| 473 | } |
| 474 | |
Hrvoje Varga | 00d96ee | 2016-08-01 06:46:20 +0000 | [diff] [blame] | 475 | bool MipsSEDAGToDAGISel::selectIntAddrSImm10(SDValue Addr, SDValue &Base, |
| 476 | SDValue &Offset) const { |
| 477 | |
| 478 | if (selectAddrFrameIndex(Addr, Base, Offset)) |
Daniel Sanders | fa961d7 | 2014-03-03 14:31:21 +0000 | [diff] [blame] | 479 | return true; |
| 480 | |
Hrvoje Varga | 00d96ee | 2016-08-01 06:46:20 +0000 | [diff] [blame] | 481 | if (selectAddrFrameIndexOffset(Addr, Base, Offset, 10)) |
Daniel Sanders | fa961d7 | 2014-03-03 14:31:21 +0000 | [diff] [blame] | 482 | return true; |
| 483 | |
Hrvoje Varga | 00d96ee | 2016-08-01 06:46:20 +0000 | [diff] [blame] | 484 | return selectAddrDefault(Addr, Base, Offset); |
| 485 | } |
| 486 | |
| 487 | bool MipsSEDAGToDAGISel::selectIntAddrSImm10Lsl1(SDValue Addr, SDValue &Base, |
| 488 | SDValue &Offset) const { |
| 489 | if (selectAddrFrameIndex(Addr, Base, Offset)) |
| 490 | return true; |
| 491 | |
| 492 | if (selectAddrFrameIndexOffset(Addr, Base, Offset, 10, 1)) |
| 493 | return true; |
| 494 | |
| 495 | return selectAddrDefault(Addr, Base, Offset); |
| 496 | } |
| 497 | |
| 498 | bool MipsSEDAGToDAGISel::selectIntAddrSImm10Lsl2(SDValue Addr, SDValue &Base, |
| 499 | SDValue &Offset) const { |
| 500 | if (selectAddrFrameIndex(Addr, Base, Offset)) |
| 501 | return true; |
| 502 | |
| 503 | if (selectAddrFrameIndexOffset(Addr, Base, Offset, 10, 2)) |
| 504 | return true; |
| 505 | |
| 506 | return selectAddrDefault(Addr, Base, Offset); |
| 507 | } |
| 508 | |
| 509 | bool MipsSEDAGToDAGISel::selectIntAddrSImm10Lsl3(SDValue Addr, SDValue &Base, |
| 510 | SDValue &Offset) const { |
| 511 | if (selectAddrFrameIndex(Addr, Base, Offset)) |
| 512 | return true; |
| 513 | |
| 514 | if (selectAddrFrameIndexOffset(Addr, Base, Offset, 10, 3)) |
| 515 | return true; |
| 516 | |
| 517 | return selectAddrDefault(Addr, Base, Offset); |
Daniel Sanders | fa961d7 | 2014-03-03 14:31:21 +0000 | [diff] [blame] | 518 | } |
| 519 | |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 520 | // Select constant vector splats. |
| 521 | // |
| 522 | // Returns true and sets Imm if: |
| 523 | // * MSA is enabled |
| 524 | // * N is a ISD::BUILD_VECTOR representing a constant splat |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 525 | bool MipsSEDAGToDAGISel::selectVSplat(SDNode *N, APInt &Imm, |
| 526 | unsigned MinSizeInBits) const { |
Eric Christopher | 22405e4 | 2014-07-10 17:26:51 +0000 | [diff] [blame] | 527 | if (!Subtarget->hasMSA()) |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 528 | return false; |
| 529 | |
| 530 | BuildVectorSDNode *Node = dyn_cast<BuildVectorSDNode>(N); |
| 531 | |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 532 | if (!Node) |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 533 | return false; |
| 534 | |
| 535 | APInt SplatValue, SplatUndef; |
| 536 | unsigned SplatBitSize; |
| 537 | bool HasAnyUndefs; |
| 538 | |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 539 | if (!Node->isConstantSplat(SplatValue, SplatUndef, SplatBitSize, HasAnyUndefs, |
| 540 | MinSizeInBits, !Subtarget->isLittle())) |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 541 | return false; |
| 542 | |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 543 | Imm = SplatValue; |
| 544 | |
| 545 | return true; |
| 546 | } |
| 547 | |
| 548 | // Select constant vector splats. |
| 549 | // |
| 550 | // In addition to the requirements of selectVSplat(), this function returns |
| 551 | // true and sets Imm if: |
| 552 | // * The splat value is the same width as the elements of the vector |
| 553 | // * The splat value fits in an integer with the specified signed-ness and |
| 554 | // width. |
| 555 | // |
| 556 | // This function looks through ISD::BITCAST nodes. |
| 557 | // TODO: This might not be appropriate for big-endian MSA since BITCAST is |
| 558 | // sometimes a shuffle in big-endian mode. |
| 559 | // |
| 560 | // It's worth noting that this function is not used as part of the selection |
| 561 | // of ldi.[bhwd] since it does not permit using the wrong-typed ldi.[bhwd] |
| 562 | // instruction to achieve the desired bit pattern. ldi.[bhwd] is selected in |
| 563 | // MipsSEDAGToDAGISel::selectNode. |
| 564 | bool MipsSEDAGToDAGISel:: |
| 565 | selectVSplatCommon(SDValue N, SDValue &Imm, bool Signed, |
| 566 | unsigned ImmBitSize) const { |
| 567 | APInt ImmValue; |
| 568 | EVT EltTy = N->getValueType(0).getVectorElementType(); |
| 569 | |
| 570 | if (N->getOpcode() == ISD::BITCAST) |
| 571 | N = N->getOperand(0); |
| 572 | |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 573 | if (selectVSplat(N.getNode(), ImmValue, EltTy.getSizeInBits()) && |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 574 | ImmValue.getBitWidth() == EltTy.getSizeInBits()) { |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 575 | |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 576 | if (( Signed && ImmValue.isSignedIntN(ImmBitSize)) || |
| 577 | (!Signed && ImmValue.isIntN(ImmBitSize))) { |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 578 | Imm = CurDAG->getTargetConstant(ImmValue, SDLoc(N), EltTy); |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 579 | return true; |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | return false; |
| 584 | } |
| 585 | |
| 586 | // Select constant vector splats. |
| 587 | bool MipsSEDAGToDAGISel:: |
Daniel Sanders | 7e51fe1 | 2013-09-27 11:48:57 +0000 | [diff] [blame] | 588 | selectVSplatUimm1(SDValue N, SDValue &Imm) const { |
| 589 | return selectVSplatCommon(N, Imm, false, 1); |
| 590 | } |
| 591 | |
| 592 | bool MipsSEDAGToDAGISel:: |
| 593 | selectVSplatUimm2(SDValue N, SDValue &Imm) const { |
| 594 | return selectVSplatCommon(N, Imm, false, 2); |
| 595 | } |
| 596 | |
| 597 | bool MipsSEDAGToDAGISel:: |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 598 | selectVSplatUimm3(SDValue N, SDValue &Imm) const { |
| 599 | return selectVSplatCommon(N, Imm, false, 3); |
| 600 | } |
| 601 | |
| 602 | // Select constant vector splats. |
| 603 | bool MipsSEDAGToDAGISel:: |
| 604 | selectVSplatUimm4(SDValue N, SDValue &Imm) const { |
| 605 | return selectVSplatCommon(N, Imm, false, 4); |
| 606 | } |
| 607 | |
| 608 | // Select constant vector splats. |
| 609 | bool MipsSEDAGToDAGISel:: |
| 610 | selectVSplatUimm5(SDValue N, SDValue &Imm) const { |
| 611 | return selectVSplatCommon(N, Imm, false, 5); |
| 612 | } |
| 613 | |
| 614 | // Select constant vector splats. |
| 615 | bool MipsSEDAGToDAGISel:: |
| 616 | selectVSplatUimm6(SDValue N, SDValue &Imm) const { |
| 617 | return selectVSplatCommon(N, Imm, false, 6); |
| 618 | } |
| 619 | |
| 620 | // Select constant vector splats. |
| 621 | bool MipsSEDAGToDAGISel:: |
| 622 | selectVSplatUimm8(SDValue N, SDValue &Imm) const { |
| 623 | return selectVSplatCommon(N, Imm, false, 8); |
| 624 | } |
| 625 | |
| 626 | // Select constant vector splats. |
| 627 | bool MipsSEDAGToDAGISel:: |
| 628 | selectVSplatSimm5(SDValue N, SDValue &Imm) const { |
| 629 | return selectVSplatCommon(N, Imm, true, 5); |
| 630 | } |
| 631 | |
| 632 | // Select constant vector splats whose value is a power of 2. |
| 633 | // |
| 634 | // In addition to the requirements of selectVSplat(), this function returns |
| 635 | // true and sets Imm if: |
| 636 | // * The splat value is the same width as the elements of the vector |
| 637 | // * The splat value is a power of two. |
| 638 | // |
| 639 | // This function looks through ISD::BITCAST nodes. |
| 640 | // TODO: This might not be appropriate for big-endian MSA since BITCAST is |
| 641 | // sometimes a shuffle in big-endian mode. |
| 642 | bool MipsSEDAGToDAGISel::selectVSplatUimmPow2(SDValue N, SDValue &Imm) const { |
| 643 | APInt ImmValue; |
| 644 | EVT EltTy = N->getValueType(0).getVectorElementType(); |
| 645 | |
| 646 | if (N->getOpcode() == ISD::BITCAST) |
| 647 | N = N->getOperand(0); |
| 648 | |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 649 | if (selectVSplat(N.getNode(), ImmValue, EltTy.getSizeInBits()) && |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 650 | ImmValue.getBitWidth() == EltTy.getSizeInBits()) { |
| 651 | int32_t Log2 = ImmValue.exactLogBase2(); |
| 652 | |
| 653 | if (Log2 != -1) { |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 654 | Imm = CurDAG->getTargetConstant(Log2, SDLoc(N), EltTy); |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 655 | return true; |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | return false; |
| 660 | } |
| 661 | |
Daniel Sanders | d74b130 | 2013-10-30 14:45:14 +0000 | [diff] [blame] | 662 | // Select constant vector splats whose value only has a consecutive sequence |
| 663 | // of left-most bits set (e.g. 0b11...1100...00). |
| 664 | // |
| 665 | // In addition to the requirements of selectVSplat(), this function returns |
| 666 | // true and sets Imm if: |
| 667 | // * The splat value is the same width as the elements of the vector |
| 668 | // * The splat value is a consecutive sequence of left-most bits. |
| 669 | // |
| 670 | // This function looks through ISD::BITCAST nodes. |
| 671 | // TODO: This might not be appropriate for big-endian MSA since BITCAST is |
| 672 | // sometimes a shuffle in big-endian mode. |
| 673 | bool MipsSEDAGToDAGISel::selectVSplatMaskL(SDValue N, SDValue &Imm) const { |
| 674 | APInt ImmValue; |
| 675 | EVT EltTy = N->getValueType(0).getVectorElementType(); |
| 676 | |
| 677 | if (N->getOpcode() == ISD::BITCAST) |
| 678 | N = N->getOperand(0); |
| 679 | |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 680 | if (selectVSplat(N.getNode(), ImmValue, EltTy.getSizeInBits()) && |
Daniel Sanders | d74b130 | 2013-10-30 14:45:14 +0000 | [diff] [blame] | 681 | ImmValue.getBitWidth() == EltTy.getSizeInBits()) { |
| 682 | // Extract the run of set bits starting with bit zero from the bitwise |
| 683 | // inverse of ImmValue, and test that the inverse of this is the same |
| 684 | // as the original value. |
| 685 | if (ImmValue == ~(~ImmValue & ~(~ImmValue + 1))) { |
| 686 | |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 687 | Imm = CurDAG->getTargetConstant(ImmValue.countPopulation(), SDLoc(N), |
| 688 | EltTy); |
Daniel Sanders | d74b130 | 2013-10-30 14:45:14 +0000 | [diff] [blame] | 689 | return true; |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | return false; |
| 694 | } |
| 695 | |
| 696 | // Select constant vector splats whose value only has a consecutive sequence |
| 697 | // of right-most bits set (e.g. 0b00...0011...11). |
| 698 | // |
| 699 | // In addition to the requirements of selectVSplat(), this function returns |
| 700 | // true and sets Imm if: |
| 701 | // * The splat value is the same width as the elements of the vector |
| 702 | // * The splat value is a consecutive sequence of right-most bits. |
| 703 | // |
| 704 | // This function looks through ISD::BITCAST nodes. |
| 705 | // TODO: This might not be appropriate for big-endian MSA since BITCAST is |
| 706 | // sometimes a shuffle in big-endian mode. |
| 707 | bool MipsSEDAGToDAGISel::selectVSplatMaskR(SDValue N, SDValue &Imm) const { |
| 708 | APInt ImmValue; |
| 709 | EVT EltTy = N->getValueType(0).getVectorElementType(); |
| 710 | |
| 711 | if (N->getOpcode() == ISD::BITCAST) |
| 712 | N = N->getOperand(0); |
| 713 | |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 714 | if (selectVSplat(N.getNode(), ImmValue, EltTy.getSizeInBits()) && |
Daniel Sanders | d74b130 | 2013-10-30 14:45:14 +0000 | [diff] [blame] | 715 | ImmValue.getBitWidth() == EltTy.getSizeInBits()) { |
| 716 | // Extract the run of set bits starting with bit zero, and test that the |
| 717 | // result is the same as the original value |
| 718 | if (ImmValue == (ImmValue & ~(ImmValue + 1))) { |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 719 | Imm = CurDAG->getTargetConstant(ImmValue.countPopulation(), SDLoc(N), |
| 720 | EltTy); |
Daniel Sanders | d74b130 | 2013-10-30 14:45:14 +0000 | [diff] [blame] | 721 | return true; |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | return false; |
| 726 | } |
| 727 | |
Daniel Sanders | 3f6eb54 | 2013-11-12 10:45:18 +0000 | [diff] [blame] | 728 | bool MipsSEDAGToDAGISel::selectVSplatUimmInvPow2(SDValue N, |
| 729 | SDValue &Imm) const { |
| 730 | APInt ImmValue; |
| 731 | EVT EltTy = N->getValueType(0).getVectorElementType(); |
| 732 | |
| 733 | if (N->getOpcode() == ISD::BITCAST) |
| 734 | N = N->getOperand(0); |
| 735 | |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 736 | if (selectVSplat(N.getNode(), ImmValue, EltTy.getSizeInBits()) && |
Daniel Sanders | 3f6eb54 | 2013-11-12 10:45:18 +0000 | [diff] [blame] | 737 | ImmValue.getBitWidth() == EltTy.getSizeInBits()) { |
| 738 | int32_t Log2 = (~ImmValue).exactLogBase2(); |
| 739 | |
| 740 | if (Log2 != -1) { |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 741 | Imm = CurDAG->getTargetConstant(Log2, SDLoc(N), EltTy); |
Daniel Sanders | 3f6eb54 | 2013-11-12 10:45:18 +0000 | [diff] [blame] | 742 | return true; |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | return false; |
| 747 | } |
| 748 | |
Justin Bogner | eeae751 | 2016-05-13 23:55:59 +0000 | [diff] [blame] | 749 | bool MipsSEDAGToDAGISel::trySelect(SDNode *Node) { |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 750 | unsigned Opcode = Node->getOpcode(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 751 | SDLoc DL(Node); |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 752 | |
| 753 | /// |
| 754 | // Instruction Selection not handled by the auto-generated |
| 755 | // tablegen selection should be handled here. |
| 756 | /// |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 757 | switch(Opcode) { |
| 758 | default: break; |
| 759 | |
Akira Hatanaka | b8835b8 | 2013-03-14 18:39:25 +0000 | [diff] [blame] | 760 | case ISD::SUBE: { |
| 761 | SDValue InFlag = Node->getOperand(2); |
Vasileios Kalintiris | ef96a8e | 2015-01-26 12:33:22 +0000 | [diff] [blame] | 762 | unsigned Opc = Subtarget->isGP64bit() ? Mips::DSUBu : Mips::SUBu; |
Justin Bogner | eeae751 | 2016-05-13 23:55:59 +0000 | [diff] [blame] | 763 | selectAddESubE(Opc, InFlag, InFlag.getOperand(0), DL, Node); |
| 764 | return true; |
Akira Hatanaka | b8835b8 | 2013-03-14 18:39:25 +0000 | [diff] [blame] | 765 | } |
| 766 | |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 767 | case ISD::ADDE: { |
Eric Christopher | 22405e4 | 2014-07-10 17:26:51 +0000 | [diff] [blame] | 768 | if (Subtarget->hasDSP()) // Select DSP instructions, ADDSC and ADDWC. |
Akira Hatanaka | 2f08822 | 2013-04-13 00:55:41 +0000 | [diff] [blame] | 769 | break; |
Akira Hatanaka | b8835b8 | 2013-03-14 18:39:25 +0000 | [diff] [blame] | 770 | SDValue InFlag = Node->getOperand(2); |
Vasileios Kalintiris | ef96a8e | 2015-01-26 12:33:22 +0000 | [diff] [blame] | 771 | unsigned Opc = Subtarget->isGP64bit() ? Mips::DADDu : Mips::ADDu; |
Justin Bogner | eeae751 | 2016-05-13 23:55:59 +0000 | [diff] [blame] | 772 | selectAddESubE(Opc, InFlag, InFlag.getValue(0), DL, Node); |
| 773 | return true; |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 774 | } |
| 775 | |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 776 | case ISD::ConstantFP: { |
| 777 | ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(Node); |
| 778 | if (Node->getValueType(0) == MVT::f64 && CN->isExactlyValue(+0.0)) { |
Eric Christopher | 22405e4 | 2014-07-10 17:26:51 +0000 | [diff] [blame] | 779 | if (Subtarget->isGP64bit()) { |
Akira Hatanaka | 040d225 | 2013-03-14 18:33:23 +0000 | [diff] [blame] | 780 | SDValue Zero = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), DL, |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 781 | Mips::ZERO_64, MVT::i64); |
Justin Bogner | eeae751 | 2016-05-13 23:55:59 +0000 | [diff] [blame] | 782 | ReplaceNode(Node, |
| 783 | CurDAG->getMachineNode(Mips::DMTC1, DL, MVT::f64, Zero)); |
Eric Christopher | 22405e4 | 2014-07-10 17:26:51 +0000 | [diff] [blame] | 784 | } else if (Subtarget->isFP64bit()) { |
Daniel Sanders | 08d3cd1 | 2013-11-18 13:12:43 +0000 | [diff] [blame] | 785 | SDValue Zero = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), DL, |
| 786 | Mips::ZERO, MVT::i32); |
Justin Bogner | eeae751 | 2016-05-13 23:55:59 +0000 | [diff] [blame] | 787 | ReplaceNode(Node, CurDAG->getMachineNode(Mips::BuildPairF64_64, DL, |
| 788 | MVT::f64, Zero, Zero)); |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 789 | } else { |
Akira Hatanaka | 040d225 | 2013-03-14 18:33:23 +0000 | [diff] [blame] | 790 | SDValue Zero = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), DL, |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 791 | Mips::ZERO, MVT::i32); |
Justin Bogner | eeae751 | 2016-05-13 23:55:59 +0000 | [diff] [blame] | 792 | ReplaceNode(Node, CurDAG->getMachineNode(Mips::BuildPairF64, DL, |
| 793 | MVT::f64, Zero, Zero)); |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 794 | } |
Justin Bogner | eeae751 | 2016-05-13 23:55:59 +0000 | [diff] [blame] | 795 | return true; |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 796 | } |
| 797 | break; |
| 798 | } |
| 799 | |
| 800 | case ISD::Constant: { |
| 801 | const ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Node); |
Simon Dardis | 6189752 | 2016-07-25 09:57:28 +0000 | [diff] [blame] | 802 | int64_t Imm = CN->getSExtValue(); |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 803 | unsigned Size = CN->getValueSizeInBits(0); |
| 804 | |
Simon Dardis | 6189752 | 2016-07-25 09:57:28 +0000 | [diff] [blame] | 805 | if (isInt<32>(Imm)) |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 806 | break; |
| 807 | |
| 808 | MipsAnalyzeImmediate AnalyzeImm; |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 809 | |
| 810 | const MipsAnalyzeImmediate::InstSeq &Seq = |
| 811 | AnalyzeImm.Analyze(Imm, Size, false); |
| 812 | |
| 813 | MipsAnalyzeImmediate::InstSeq::const_iterator Inst = Seq.begin(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 814 | SDLoc DL(CN); |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 815 | SDNode *RegOpnd; |
| 816 | SDValue ImmOpnd = CurDAG->getTargetConstant(SignExtend64<16>(Inst->ImmOpnd), |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 817 | DL, MVT::i64); |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 818 | |
| 819 | // The first instruction can be a LUi which is different from other |
| 820 | // instructions (ADDiu, ORI and SLL) in that it does not have a register |
| 821 | // operand. |
| 822 | if (Inst->Opc == Mips::LUi64) |
| 823 | RegOpnd = CurDAG->getMachineNode(Inst->Opc, DL, MVT::i64, ImmOpnd); |
| 824 | else |
| 825 | RegOpnd = |
| 826 | CurDAG->getMachineNode(Inst->Opc, DL, MVT::i64, |
| 827 | CurDAG->getRegister(Mips::ZERO_64, MVT::i64), |
| 828 | ImmOpnd); |
| 829 | |
| 830 | // The remaining instructions in the sequence are handled here. |
| 831 | for (++Inst; Inst != Seq.end(); ++Inst) { |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 832 | ImmOpnd = CurDAG->getTargetConstant(SignExtend64<16>(Inst->ImmOpnd), DL, |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 833 | MVT::i64); |
| 834 | RegOpnd = CurDAG->getMachineNode(Inst->Opc, DL, MVT::i64, |
| 835 | SDValue(RegOpnd, 0), ImmOpnd); |
| 836 | } |
| 837 | |
Justin Bogner | eeae751 | 2016-05-13 23:55:59 +0000 | [diff] [blame] | 838 | ReplaceNode(Node, RegOpnd); |
| 839 | return true; |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 840 | } |
| 841 | |
Daniel Sanders | f9aa1d1 | 2013-08-28 10:26:24 +0000 | [diff] [blame] | 842 | case ISD::INTRINSIC_W_CHAIN: { |
| 843 | switch (cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue()) { |
| 844 | default: |
| 845 | break; |
| 846 | |
| 847 | case Intrinsic::mips_cfcmsa: { |
| 848 | SDValue ChainIn = Node->getOperand(0); |
| 849 | SDValue RegIdx = Node->getOperand(2); |
| 850 | SDValue Reg = CurDAG->getCopyFromReg(ChainIn, DL, |
| 851 | getMSACtrlReg(RegIdx), MVT::i32); |
Justin Bogner | eeae751 | 2016-05-13 23:55:59 +0000 | [diff] [blame] | 852 | ReplaceNode(Node, Reg.getNode()); |
| 853 | return true; |
Daniel Sanders | f9aa1d1 | 2013-08-28 10:26:24 +0000 | [diff] [blame] | 854 | } |
| 855 | } |
| 856 | break; |
| 857 | } |
| 858 | |
Daniel Sanders | ba9c850 | 2013-08-28 10:44:47 +0000 | [diff] [blame] | 859 | case ISD::INTRINSIC_WO_CHAIN: { |
| 860 | switch (cast<ConstantSDNode>(Node->getOperand(0))->getZExtValue()) { |
| 861 | default: |
| 862 | break; |
| 863 | |
| 864 | case Intrinsic::mips_move_v: |
| 865 | // Like an assignment but will always produce a move.v even if |
| 866 | // unnecessary. |
Justin Bogner | eeae751 | 2016-05-13 23:55:59 +0000 | [diff] [blame] | 867 | ReplaceNode(Node, CurDAG->getMachineNode(Mips::MOVE_V, DL, |
| 868 | Node->getValueType(0), |
| 869 | Node->getOperand(1))); |
| 870 | return true; |
Daniel Sanders | ba9c850 | 2013-08-28 10:44:47 +0000 | [diff] [blame] | 871 | } |
| 872 | break; |
| 873 | } |
| 874 | |
Daniel Sanders | f9aa1d1 | 2013-08-28 10:26:24 +0000 | [diff] [blame] | 875 | case ISD::INTRINSIC_VOID: { |
| 876 | switch (cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue()) { |
| 877 | default: |
| 878 | break; |
| 879 | |
| 880 | case Intrinsic::mips_ctcmsa: { |
| 881 | SDValue ChainIn = Node->getOperand(0); |
| 882 | SDValue RegIdx = Node->getOperand(2); |
| 883 | SDValue Value = Node->getOperand(3); |
| 884 | SDValue ChainOut = CurDAG->getCopyToReg(ChainIn, DL, |
| 885 | getMSACtrlReg(RegIdx), Value); |
Justin Bogner | eeae751 | 2016-05-13 23:55:59 +0000 | [diff] [blame] | 886 | ReplaceNode(Node, ChainOut.getNode()); |
| 887 | return true; |
Daniel Sanders | f9aa1d1 | 2013-08-28 10:26:24 +0000 | [diff] [blame] | 888 | } |
| 889 | } |
| 890 | break; |
| 891 | } |
| 892 | |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 893 | case MipsISD::ThreadPointer: { |
Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 894 | EVT PtrVT = getTargetLowering()->getPointerTy(CurDAG->getDataLayout()); |
Akira Hatanaka | 85ccf23 | 2013-08-08 21:37:32 +0000 | [diff] [blame] | 895 | unsigned RdhwrOpc, DestReg; |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 896 | |
| 897 | if (PtrVT == MVT::i32) { |
| 898 | RdhwrOpc = Mips::RDHWR; |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 899 | DestReg = Mips::V1; |
| 900 | } else { |
| 901 | RdhwrOpc = Mips::RDHWR64; |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 902 | DestReg = Mips::V1_64; |
| 903 | } |
| 904 | |
| 905 | SDNode *Rdhwr = |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 906 | CurDAG->getMachineNode(RdhwrOpc, DL, |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 907 | Node->getValueType(0), |
Akira Hatanaka | 85ccf23 | 2013-08-08 21:37:32 +0000 | [diff] [blame] | 908 | CurDAG->getRegister(Mips::HWR29, MVT::i32)); |
Akira Hatanaka | 040d225 | 2013-03-14 18:33:23 +0000 | [diff] [blame] | 909 | SDValue Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), DL, DestReg, |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 910 | SDValue(Rdhwr, 0)); |
Akira Hatanaka | 040d225 | 2013-03-14 18:33:23 +0000 | [diff] [blame] | 911 | SDValue ResNode = CurDAG->getCopyFromReg(Chain, DL, DestReg, PtrVT); |
Justin Bogner | eeae751 | 2016-05-13 23:55:59 +0000 | [diff] [blame] | 912 | ReplaceNode(Node, ResNode.getNode()); |
| 913 | return true; |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 914 | } |
Akira Hatanaka | be8612f | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 915 | |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 916 | case ISD::BUILD_VECTOR: { |
| 917 | // Select appropriate ldi.[bhwd] instructions for constant splats of |
| 918 | // 128-bit when MSA is enabled. Fixup any register class mismatches that |
| 919 | // occur as a result. |
| 920 | // |
| 921 | // This allows the compiler to use a wider range of immediates than would |
| 922 | // otherwise be allowed. If, for example, v4i32 could only use ldi.h then |
| 923 | // it would not be possible to load { 0x01010101, 0x01010101, 0x01010101, |
| 924 | // 0x01010101 } without using a constant pool. This would be sub-optimal |
| 925 | // when // 'ldi.b wd, 1' is capable of producing that bit-pattern in the |
| 926 | // same set/ of registers. Similarly, ldi.h isn't capable of producing { |
| 927 | // 0x00000000, 0x00000001, 0x00000000, 0x00000001 } but 'ldi.d wd, 1' can. |
| 928 | |
| 929 | BuildVectorSDNode *BVN = cast<BuildVectorSDNode>(Node); |
| 930 | APInt SplatValue, SplatUndef; |
| 931 | unsigned SplatBitSize; |
| 932 | bool HasAnyUndefs; |
| 933 | unsigned LdiOp; |
| 934 | EVT ResVecTy = BVN->getValueType(0); |
| 935 | EVT ViaVecTy; |
| 936 | |
Eric Christopher | 22405e4 | 2014-07-10 17:26:51 +0000 | [diff] [blame] | 937 | if (!Subtarget->hasMSA() || !BVN->getValueType(0).is128BitVector()) |
Justin Bogner | eeae751 | 2016-05-13 23:55:59 +0000 | [diff] [blame] | 938 | return false; |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 939 | |
| 940 | if (!BVN->isConstantSplat(SplatValue, SplatUndef, SplatBitSize, |
| 941 | HasAnyUndefs, 8, |
Eric Christopher | 22405e4 | 2014-07-10 17:26:51 +0000 | [diff] [blame] | 942 | !Subtarget->isLittle())) |
Justin Bogner | eeae751 | 2016-05-13 23:55:59 +0000 | [diff] [blame] | 943 | return false; |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 944 | |
| 945 | switch (SplatBitSize) { |
| 946 | default: |
Justin Bogner | eeae751 | 2016-05-13 23:55:59 +0000 | [diff] [blame] | 947 | return false; |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 948 | case 8: |
| 949 | LdiOp = Mips::LDI_B; |
| 950 | ViaVecTy = MVT::v16i8; |
| 951 | break; |
| 952 | case 16: |
| 953 | LdiOp = Mips::LDI_H; |
| 954 | ViaVecTy = MVT::v8i16; |
| 955 | break; |
| 956 | case 32: |
| 957 | LdiOp = Mips::LDI_W; |
| 958 | ViaVecTy = MVT::v4i32; |
| 959 | break; |
| 960 | case 64: |
| 961 | LdiOp = Mips::LDI_D; |
| 962 | ViaVecTy = MVT::v2i64; |
| 963 | break; |
| 964 | } |
| 965 | |
| 966 | if (!SplatValue.isSignedIntN(10)) |
Justin Bogner | eeae751 | 2016-05-13 23:55:59 +0000 | [diff] [blame] | 967 | return false; |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 968 | |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 969 | SDValue Imm = CurDAG->getTargetConstant(SplatValue, DL, |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 970 | ViaVecTy.getVectorElementType()); |
| 971 | |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 972 | SDNode *Res = CurDAG->getMachineNode(LdiOp, DL, ViaVecTy, Imm); |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 973 | |
| 974 | if (ResVecTy != ViaVecTy) { |
| 975 | // If LdiOp is writing to a different register class to ResVecTy, then |
| 976 | // fix it up here. This COPY_TO_REGCLASS should never cause a move.v |
| 977 | // since the source and destination register sets contain the same |
| 978 | // registers. |
| 979 | const TargetLowering *TLI = getTargetLowering(); |
| 980 | MVT ResVecTySimple = ResVecTy.getSimpleVT(); |
| 981 | const TargetRegisterClass *RC = TLI->getRegClassFor(ResVecTySimple); |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 982 | Res = CurDAG->getMachineNode(Mips::COPY_TO_REGCLASS, DL, |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 983 | ResVecTy, SDValue(Res, 0), |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 984 | CurDAG->getTargetConstant(RC->getID(), DL, |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 985 | MVT::i32)); |
| 986 | } |
| 987 | |
Justin Bogner | eeae751 | 2016-05-13 23:55:59 +0000 | [diff] [blame] | 988 | ReplaceNode(Node, Res); |
| 989 | return true; |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 990 | } |
| 991 | |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 992 | } |
| 993 | |
Justin Bogner | eeae751 | 2016-05-13 23:55:59 +0000 | [diff] [blame] | 994 | return false; |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 995 | } |
| 996 | |
Daniel Sanders | a73d8fe | 2015-03-24 11:26:34 +0000 | [diff] [blame] | 997 | bool MipsSEDAGToDAGISel:: |
| 998 | SelectInlineAsmMemoryOperand(const SDValue &Op, unsigned ConstraintID, |
| 999 | std::vector<SDValue> &OutOps) { |
| 1000 | SDValue Base, Offset; |
| 1001 | |
| 1002 | switch(ConstraintID) { |
| 1003 | default: |
| 1004 | llvm_unreachable("Unexpected asm memory constraint"); |
| 1005 | // All memory constraints can at least accept raw pointers. |
| 1006 | case InlineAsm::Constraint_i: |
Daniel Sanders | a73d8fe | 2015-03-24 11:26:34 +0000 | [diff] [blame] | 1007 | OutOps.push_back(Op); |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1008 | OutOps.push_back(CurDAG->getTargetConstant(0, SDLoc(Op), MVT::i32)); |
Daniel Sanders | a73d8fe | 2015-03-24 11:26:34 +0000 | [diff] [blame] | 1009 | return false; |
Daniel Sanders | c676f2a | 2015-03-24 15:19:14 +0000 | [diff] [blame] | 1010 | case InlineAsm::Constraint_m: |
| 1011 | if (selectAddrRegImm16(Op, Base, Offset)) { |
| 1012 | OutOps.push_back(Base); |
| 1013 | OutOps.push_back(Offset); |
| 1014 | return false; |
| 1015 | } |
| 1016 | OutOps.push_back(Op); |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1017 | OutOps.push_back(CurDAG->getTargetConstant(0, SDLoc(Op), MVT::i32)); |
Daniel Sanders | c676f2a | 2015-03-24 15:19:14 +0000 | [diff] [blame] | 1018 | return false; |
Daniel Sanders | 82df616 | 2015-03-30 13:27:25 +0000 | [diff] [blame] | 1019 | case InlineAsm::Constraint_R: |
| 1020 | // The 'R' constraint is supposed to be much more complicated than this. |
| 1021 | // However, it's becoming less useful due to architectural changes and |
| 1022 | // ought to be replaced by other constraints such as 'ZC'. |
| 1023 | // For now, support 9-bit signed offsets which is supportable by all |
| 1024 | // subtargets for all instructions. |
| 1025 | if (selectAddrRegImm9(Op, Base, Offset)) { |
| 1026 | OutOps.push_back(Base); |
| 1027 | OutOps.push_back(Offset); |
| 1028 | return false; |
| 1029 | } |
| 1030 | OutOps.push_back(Op); |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1031 | OutOps.push_back(CurDAG->getTargetConstant(0, SDLoc(Op), MVT::i32)); |
Daniel Sanders | 82df616 | 2015-03-30 13:27:25 +0000 | [diff] [blame] | 1032 | return false; |
Daniel Sanders | a73d8fe | 2015-03-24 11:26:34 +0000 | [diff] [blame] | 1033 | case InlineAsm::Constraint_ZC: |
| 1034 | // ZC matches whatever the pref, ll, and sc instructions can handle for the |
| 1035 | // given subtarget. |
| 1036 | if (Subtarget->inMicroMipsMode()) { |
| 1037 | // On microMIPS, they can handle 12-bit offsets. |
| 1038 | if (selectAddrRegImm12(Op, Base, Offset)) { |
| 1039 | OutOps.push_back(Base); |
| 1040 | OutOps.push_back(Offset); |
| 1041 | return false; |
| 1042 | } |
| 1043 | } else if (Subtarget->hasMips32r6()) { |
| 1044 | // On MIPS32r6/MIPS64r6, they can only handle 9-bit offsets. |
| 1045 | if (selectAddrRegImm9(Op, Base, Offset)) { |
| 1046 | OutOps.push_back(Base); |
| 1047 | OutOps.push_back(Offset); |
| 1048 | return false; |
| 1049 | } |
| 1050 | } else if (selectAddrRegImm16(Op, Base, Offset)) { |
| 1051 | // Prior to MIPS32r6/MIPS64r6, they can handle 16-bit offsets. |
| 1052 | OutOps.push_back(Base); |
| 1053 | OutOps.push_back(Offset); |
| 1054 | return false; |
| 1055 | } |
| 1056 | // In all cases, 0-bit offsets are acceptable. |
| 1057 | OutOps.push_back(Op); |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1058 | OutOps.push_back(CurDAG->getTargetConstant(0, SDLoc(Op), MVT::i32)); |
Daniel Sanders | a73d8fe | 2015-03-24 11:26:34 +0000 | [diff] [blame] | 1059 | return false; |
| 1060 | } |
| 1061 | return true; |
| 1062 | } |
| 1063 | |
Daniel Sanders | 46fe655 | 2016-07-14 13:25:22 +0000 | [diff] [blame] | 1064 | FunctionPass *llvm::createMipsSEISelDag(MipsTargetMachine &TM, |
| 1065 | CodeGenOpt::Level OptLevel) { |
| 1066 | return new MipsSEDAGToDAGISel(TM, OptLevel); |
Akira Hatanaka | 30a8478 | 2013-03-14 18:27:31 +0000 | [diff] [blame] | 1067 | } |