blob: a598c3f1db5070222560956ef7c0547fcaa4f4b5 [file] [log] [blame]
Akira Hatanaka30a84782013-03-14 18:27:31 +00001//===-- 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 Hatanaka30a84782013-03-14 18:27:31 +000014#include "MipsSEISelDAGToDAG.h"
Akira Hatanaka30a84782013-03-14 18:27:31 +000015#include "MCTargetDesc/MipsBaseInfo.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000016#include "Mips.h"
Akira Hatanaka30a84782013-03-14 18:27:31 +000017#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 Carruth1305dc32014-03-04 11:45:46 +000026#include "llvm/IR/CFG.h"
Akira Hatanaka30a84782013-03-14 18:27:31 +000027#include "llvm/IR/GlobalValue.h"
28#include "llvm/IR/Instructions.h"
29#include "llvm/IR/Intrinsics.h"
30#include "llvm/IR/Type.h"
Akira Hatanaka30a84782013-03-14 18:27:31 +000031#include "llvm/Support/Debug.h"
32#include "llvm/Support/ErrorHandling.h"
33#include "llvm/Support/raw_ostream.h"
34#include "llvm/Target/TargetMachine.h"
35using namespace llvm;
36
Chandler Carruth84e68b22014-04-22 02:41:26 +000037#define DEBUG_TYPE "mips-isel"
38
Reed Kotler1595f362013-04-09 19:46:01 +000039bool MipsSEDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) {
Eric Christopher96e72c62015-01-29 23:27:36 +000040 Subtarget = &static_cast<const MipsSubtarget &>(MF.getSubtarget());
Eric Christopher22405e42014-07-10 17:26:51 +000041 if (Subtarget->inMips16Mode())
Reed Kotler1595f362013-04-09 19:46:01 +000042 return false;
43 return MipsDAGToDAGISel::runOnMachineFunction(MF);
44}
Akira Hatanaka30a84782013-03-14 18:27:31 +000045
Akira Hatanakae86bd4f2013-05-03 18:37:49 +000046void MipsSEDAGToDAGISel::addDSPCtrlRegOperands(bool IsDef, MachineInstr &MI,
47 MachineFunction &MF) {
48 MachineInstrBuilder MIB(MF, &MI);
49 unsigned Mask = MI.getOperand(1).getImm();
50 unsigned Flag = IsDef ? RegState::ImplicitDefine : RegState::Implicit;
51
52 if (Mask & 1)
53 MIB.addReg(Mips::DSPPos, Flag);
54
55 if (Mask & 2)
56 MIB.addReg(Mips::DSPSCount, Flag);
57
58 if (Mask & 4)
59 MIB.addReg(Mips::DSPCarry, Flag);
60
61 if (Mask & 8)
62 MIB.addReg(Mips::DSPOutFlag, Flag);
63
64 if (Mask & 16)
65 MIB.addReg(Mips::DSPCCond, Flag);
66
67 if (Mask & 32)
68 MIB.addReg(Mips::DSPEFI, Flag);
69}
70
Daniel Sandersf9aa1d12013-08-28 10:26:24 +000071unsigned MipsSEDAGToDAGISel::getMSACtrlReg(const SDValue RegIdx) const {
72 switch (cast<ConstantSDNode>(RegIdx)->getZExtValue()) {
73 default:
74 llvm_unreachable("Could not map int to register");
75 case 0: return Mips::MSAIR;
76 case 1: return Mips::MSACSR;
77 case 2: return Mips::MSAAccess;
78 case 3: return Mips::MSASave;
79 case 4: return Mips::MSAModify;
80 case 5: return Mips::MSARequest;
81 case 6: return Mips::MSAMap;
82 case 7: return Mips::MSAUnmap;
83 }
84}
85
Akira Hatanaka040d2252013-03-14 18:33:23 +000086bool MipsSEDAGToDAGISel::replaceUsesWithZeroReg(MachineRegisterInfo *MRI,
Akira Hatanaka30a84782013-03-14 18:27:31 +000087 const MachineInstr& MI) {
88 unsigned DstReg = 0, ZeroReg = 0;
89
90 // Check if MI is "addiu $dst, $zero, 0" or "daddiu $dst, $zero, 0".
91 if ((MI.getOpcode() == Mips::ADDiu) &&
92 (MI.getOperand(1).getReg() == Mips::ZERO) &&
93 (MI.getOperand(2).getImm() == 0)) {
94 DstReg = MI.getOperand(0).getReg();
95 ZeroReg = Mips::ZERO;
96 } else if ((MI.getOpcode() == Mips::DADDiu) &&
97 (MI.getOperand(1).getReg() == Mips::ZERO_64) &&
98 (MI.getOperand(2).getImm() == 0)) {
99 DstReg = MI.getOperand(0).getReg();
100 ZeroReg = Mips::ZERO_64;
101 }
102
103 if (!DstReg)
104 return false;
105
106 // Replace uses with ZeroReg.
107 for (MachineRegisterInfo::use_iterator U = MRI->use_begin(DstReg),
108 E = MRI->use_end(); U != E;) {
Owen Anderson16c6bf42014-03-13 23:12:04 +0000109 MachineOperand &MO = *U;
Akira Hatanaka30a84782013-03-14 18:27:31 +0000110 unsigned OpNo = U.getOperandNo();
111 MachineInstr *MI = MO.getParent();
112 ++U;
113
114 // Do not replace if it is a phi's operand or is tied to def operand.
115 if (MI->isPHI() || MI->isRegTiedToDefOperand(OpNo) || MI->isPseudo())
116 continue;
117
118 MO.setReg(ZeroReg);
119 }
120
121 return true;
122}
123
Akira Hatanaka040d2252013-03-14 18:33:23 +0000124void MipsSEDAGToDAGISel::initGlobalBaseReg(MachineFunction &MF) {
Akira Hatanaka30a84782013-03-14 18:27:31 +0000125 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
126
127 if (!MipsFI->globalBaseRegSet())
128 return;
129
130 MachineBasicBlock &MBB = MF.front();
131 MachineBasicBlock::iterator I = MBB.begin();
132 MachineRegisterInfo &RegInfo = MF.getRegInfo();
Eric Christopher96e72c62015-01-29 23:27:36 +0000133 const TargetInstrInfo &TII = *Subtarget->getInstrInfo();
Akira Hatanaka30a84782013-03-14 18:27:31 +0000134 DebugLoc DL = I != MBB.end() ? I->getDebugLoc() : DebugLoc();
135 unsigned V0, V1, GlobalBaseReg = MipsFI->getGlobalBaseReg();
136 const TargetRegisterClass *RC;
Eric Christopherd86af632015-01-29 23:27:45 +0000137 const MipsABIInfo &ABI = static_cast<const MipsTargetMachine &>(TM).getABI();
138 RC = (ABI.IsN64()) ? &Mips::GPR64RegClass : &Mips::GPR32RegClass;
Akira Hatanaka30a84782013-03-14 18:27:31 +0000139
140 V0 = RegInfo.createVirtualRegister(RC);
141 V1 = RegInfo.createVirtualRegister(RC);
142
Eric Christopherd86af632015-01-29 23:27:45 +0000143 if (ABI.IsN64()) {
Akira Hatanaka30a84782013-03-14 18:27:31 +0000144 MF.getRegInfo().addLiveIn(Mips::T9_64);
145 MBB.addLiveIn(Mips::T9_64);
146
147 // lui $v0, %hi(%neg(%gp_rel(fname)))
148 // daddu $v1, $v0, $t9
149 // daddiu $globalbasereg, $v1, %lo(%neg(%gp_rel(fname)))
150 const GlobalValue *FName = MF.getFunction();
151 BuildMI(MBB, I, DL, TII.get(Mips::LUi64), V0)
152 .addGlobalAddress(FName, 0, MipsII::MO_GPOFF_HI);
153 BuildMI(MBB, I, DL, TII.get(Mips::DADDu), V1).addReg(V0)
154 .addReg(Mips::T9_64);
155 BuildMI(MBB, I, DL, TII.get(Mips::DADDiu), GlobalBaseReg).addReg(V1)
156 .addGlobalAddress(FName, 0, MipsII::MO_GPOFF_LO);
157 return;
158 }
159
160 if (MF.getTarget().getRelocationModel() == Reloc::Static) {
161 // Set global register to __gnu_local_gp.
162 //
163 // lui $v0, %hi(__gnu_local_gp)
164 // addiu $globalbasereg, $v0, %lo(__gnu_local_gp)
165 BuildMI(MBB, I, DL, TII.get(Mips::LUi), V0)
166 .addExternalSymbol("__gnu_local_gp", MipsII::MO_ABS_HI);
167 BuildMI(MBB, I, DL, TII.get(Mips::ADDiu), GlobalBaseReg).addReg(V0)
168 .addExternalSymbol("__gnu_local_gp", MipsII::MO_ABS_LO);
169 return;
170 }
171
172 MF.getRegInfo().addLiveIn(Mips::T9);
173 MBB.addLiveIn(Mips::T9);
174
Eric Christopherd86af632015-01-29 23:27:45 +0000175 if (ABI.IsN32()) {
Akira Hatanaka30a84782013-03-14 18:27:31 +0000176 // lui $v0, %hi(%neg(%gp_rel(fname)))
177 // addu $v1, $v0, $t9
178 // addiu $globalbasereg, $v1, %lo(%neg(%gp_rel(fname)))
179 const GlobalValue *FName = MF.getFunction();
180 BuildMI(MBB, I, DL, TII.get(Mips::LUi), V0)
181 .addGlobalAddress(FName, 0, MipsII::MO_GPOFF_HI);
182 BuildMI(MBB, I, DL, TII.get(Mips::ADDu), V1).addReg(V0).addReg(Mips::T9);
183 BuildMI(MBB, I, DL, TII.get(Mips::ADDiu), GlobalBaseReg).addReg(V1)
184 .addGlobalAddress(FName, 0, MipsII::MO_GPOFF_LO);
185 return;
186 }
187
Eric Christopherd86af632015-01-29 23:27:45 +0000188 assert(ABI.IsO32());
Akira Hatanaka30a84782013-03-14 18:27:31 +0000189
190 // For O32 ABI, the following instruction sequence is emitted to initialize
191 // the global base register:
192 //
193 // 0. lui $2, %hi(_gp_disp)
194 // 1. addiu $2, $2, %lo(_gp_disp)
195 // 2. addu $globalbasereg, $2, $t9
196 //
197 // We emit only the last instruction here.
198 //
199 // GNU linker requires that the first two instructions appear at the beginning
200 // of a function and no instructions be inserted before or between them.
201 // The two instructions are emitted during lowering to MC layer in order to
202 // avoid any reordering.
203 //
204 // Register $2 (Mips::V0) is added to the list of live-in registers to ensure
205 // the value instruction 1 (addiu) defines is valid when instruction 2 (addu)
206 // reads it.
207 MF.getRegInfo().addLiveIn(Mips::V0);
208 MBB.addLiveIn(Mips::V0);
209 BuildMI(MBB, I, DL, TII.get(Mips::ADDu), GlobalBaseReg)
210 .addReg(Mips::V0).addReg(Mips::T9);
211}
212
Akira Hatanaka040d2252013-03-14 18:33:23 +0000213void MipsSEDAGToDAGISel::processFunctionAfterISel(MachineFunction &MF) {
214 initGlobalBaseReg(MF);
Akira Hatanaka30a84782013-03-14 18:27:31 +0000215
216 MachineRegisterInfo *MRI = &MF.getRegInfo();
217
218 for (MachineFunction::iterator MFI = MF.begin(), MFE = MF.end(); MFI != MFE;
219 ++MFI)
Akira Hatanakae86bd4f2013-05-03 18:37:49 +0000220 for (MachineBasicBlock::iterator I = MFI->begin(); I != MFI->end(); ++I) {
221 if (I->getOpcode() == Mips::RDDSP)
222 addDSPCtrlRegOperands(false, *I, MF);
223 else if (I->getOpcode() == Mips::WRDSP)
224 addDSPCtrlRegOperands(true, *I, MF);
225 else
226 replaceUsesWithZeroReg(MRI, *I);
227 }
Akira Hatanaka30a84782013-03-14 18:27:31 +0000228}
229
Akira Hatanakab8835b82013-03-14 18:39:25 +0000230SDNode *MipsSEDAGToDAGISel::selectAddESubE(unsigned MOp, SDValue InFlag,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000231 SDValue CmpLHS, SDLoc DL,
Akira Hatanakab8835b82013-03-14 18:39:25 +0000232 SDNode *Node) const {
233 unsigned Opc = InFlag.getOpcode(); (void)Opc;
234
235 assert(((Opc == ISD::ADDC || Opc == ISD::ADDE) ||
236 (Opc == ISD::SUBC || Opc == ISD::SUBE)) &&
237 "(ADD|SUB)E flag operand must come from (ADD|SUB)C/E insn");
238
Vasileios Kalintirisef96a8e2015-01-26 12:33:22 +0000239 unsigned SLTuOp = Mips::SLTu, ADDuOp = Mips::ADDu;
240 if (Subtarget->isGP64bit()) {
241 SLTuOp = Mips::SLTu64;
242 ADDuOp = Mips::DADDu;
243 }
244
Akira Hatanakab8835b82013-03-14 18:39:25 +0000245 SDValue Ops[] = { CmpLHS, InFlag.getOperand(1) };
246 SDValue LHS = Node->getOperand(0), RHS = Node->getOperand(1);
247 EVT VT = LHS.getValueType();
248
Vasileios Kalintirisef96a8e2015-01-26 12:33:22 +0000249 SDNode *Carry = CurDAG->getMachineNode(SLTuOp, DL, VT, Ops);
250
251 if (Subtarget->isGP64bit()) {
252 // On 64-bit targets, sltu produces an i64 but our backend currently says
253 // that SLTu64 produces an i32. We need to fix this in the long run but for
254 // now, just make the DAG type-correct by asserting the upper bits are zero.
255 Carry = CurDAG->getMachineNode(Mips::SUBREG_TO_REG, DL, VT,
256 CurDAG->getTargetConstant(0, VT),
257 SDValue(Carry, 0),
258 CurDAG->getTargetConstant(Mips::sub_32, VT));
259 }
260
Vasileios Kalintiris18581f12015-02-27 09:01:39 +0000261 // Generate a second addition only if we know that RHS is not a
262 // constant-zero node.
263 SDNode *AddCarry = Carry;
264 ConstantSDNode *C = dyn_cast<ConstantSDNode>(RHS);
265 if (!C || C->getZExtValue())
266 AddCarry = CurDAG->getMachineNode(ADDuOp, DL, VT, SDValue(Carry, 0), RHS);
Vasileios Kalintirisef96a8e2015-01-26 12:33:22 +0000267
Akira Hatanakab8835b82013-03-14 18:39:25 +0000268 return CurDAG->SelectNodeTo(Node, MOp, VT, MVT::Glue, LHS,
269 SDValue(AddCarry, 0));
270}
271
Daniel Sandersfa961d72014-03-03 14:31:21 +0000272/// Match frameindex
273bool MipsSEDAGToDAGISel::selectAddrFrameIndex(SDValue Addr, SDValue &Base,
274 SDValue &Offset) const {
Akira Hatanaka30a84782013-03-14 18:27:31 +0000275 if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
Daniel Sandersfa961d72014-03-03 14:31:21 +0000276 EVT ValTy = Addr.getValueType();
277
Akira Hatanaka30a84782013-03-14 18:27:31 +0000278 Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), ValTy);
279 Offset = CurDAG->getTargetConstant(0, ValTy);
280 return true;
281 }
Daniel Sandersfa961d72014-03-03 14:31:21 +0000282 return false;
283}
284
285/// Match frameindex+offset and frameindex|offset
286bool MipsSEDAGToDAGISel::selectAddrFrameIndexOffset(SDValue Addr, SDValue &Base,
287 SDValue &Offset,
288 unsigned OffsetBits) const {
289 if (CurDAG->isBaseWithConstantOffset(Addr)) {
290 ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1));
291 if (isIntN(OffsetBits, CN->getSExtValue())) {
292 EVT ValTy = Addr.getValueType();
293
294 // If the first operand is a FI, get the TargetFI Node
295 if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>
296 (Addr.getOperand(0)))
297 Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), ValTy);
298 else
299 Base = Addr.getOperand(0);
300
301 Offset = CurDAG->getTargetConstant(CN->getZExtValue(), ValTy);
302 return true;
303 }
304 }
305 return false;
306}
307
308/// ComplexPattern used on MipsInstrInfo
309/// Used on Mips Load/Store instructions
310bool MipsSEDAGToDAGISel::selectAddrRegImm(SDValue Addr, SDValue &Base,
311 SDValue &Offset) const {
312 // if Address is FI, get the TargetFrameIndex.
313 if (selectAddrFrameIndex(Addr, Base, Offset))
314 return true;
Akira Hatanaka30a84782013-03-14 18:27:31 +0000315
316 // on PIC code Load GA
317 if (Addr.getOpcode() == MipsISD::Wrapper) {
318 Base = Addr.getOperand(0);
319 Offset = Addr.getOperand(1);
320 return true;
321 }
322
323 if (TM.getRelocationModel() != Reloc::PIC_) {
324 if ((Addr.getOpcode() == ISD::TargetExternalSymbol ||
325 Addr.getOpcode() == ISD::TargetGlobalAddress))
326 return false;
327 }
328
329 // Addresses of the form FI+const or FI|const
Daniel Sandersfa961d72014-03-03 14:31:21 +0000330 if (selectAddrFrameIndexOffset(Addr, Base, Offset, 16))
331 return true;
Akira Hatanaka30a84782013-03-14 18:27:31 +0000332
333 // Operand is a result from an ADD.
334 if (Addr.getOpcode() == ISD::ADD) {
335 // When loading from constant pools, load the lower address part in
336 // the instruction itself. Example, instead of:
337 // lui $2, %hi($CPI1_0)
338 // addiu $2, $2, %lo($CPI1_0)
339 // lwc1 $f0, 0($2)
340 // Generate:
341 // lui $2, %hi($CPI1_0)
342 // lwc1 $f0, %lo($CPI1_0)($2)
343 if (Addr.getOperand(1).getOpcode() == MipsISD::Lo ||
344 Addr.getOperand(1).getOpcode() == MipsISD::GPRel) {
345 SDValue Opnd0 = Addr.getOperand(1).getOperand(0);
346 if (isa<ConstantPoolSDNode>(Opnd0) || isa<GlobalAddressSDNode>(Opnd0) ||
347 isa<JumpTableSDNode>(Opnd0)) {
348 Base = Addr.getOperand(0);
349 Offset = Opnd0;
350 return true;
351 }
352 }
353 }
354
355 return false;
356}
357
Daniel Sanderse6ed5b72013-08-28 12:04:29 +0000358/// ComplexPattern used on MipsInstrInfo
359/// Used on Mips Load/Store instructions
360bool MipsSEDAGToDAGISel::selectAddrRegReg(SDValue Addr, SDValue &Base,
361 SDValue &Offset) const {
362 // Operand is a result from an ADD.
363 if (Addr.getOpcode() == ISD::ADD) {
364 Base = Addr.getOperand(0);
365 Offset = Addr.getOperand(1);
366 return true;
367 }
368
369 return false;
370}
371
Akira Hatanaka30a84782013-03-14 18:27:31 +0000372bool MipsSEDAGToDAGISel::selectAddrDefault(SDValue Addr, SDValue &Base,
373 SDValue &Offset) const {
374 Base = Addr;
375 Offset = CurDAG->getTargetConstant(0, Addr.getValueType());
376 return true;
377}
378
379bool MipsSEDAGToDAGISel::selectIntAddr(SDValue Addr, SDValue &Base,
380 SDValue &Offset) const {
381 return selectAddrRegImm(Addr, Base, Offset) ||
382 selectAddrDefault(Addr, Base, Offset);
383}
384
Daniel Sandersa73d8fe2015-03-24 11:26:34 +0000385bool MipsSEDAGToDAGISel::selectAddrRegImm9(SDValue Addr, SDValue &Base,
386 SDValue &Offset) const {
387 if (selectAddrFrameIndex(Addr, Base, Offset))
388 return true;
389
390 if (selectAddrFrameIndexOffset(Addr, Base, Offset, 9))
391 return true;
392
393 return false;
394}
395
Daniel Sandersfa961d72014-03-03 14:31:21 +0000396bool MipsSEDAGToDAGISel::selectAddrRegImm10(SDValue Addr, SDValue &Base,
397 SDValue &Offset) const {
398 if (selectAddrFrameIndex(Addr, Base, Offset))
399 return true;
400
401 if (selectAddrFrameIndexOffset(Addr, Base, Offset, 10))
402 return true;
403
404 return false;
405}
406
Jack Carter97700972013-08-13 20:19:16 +0000407/// Used on microMIPS Load/Store unaligned instructions (12-bit offset)
408bool MipsSEDAGToDAGISel::selectAddrRegImm12(SDValue Addr, SDValue &Base,
409 SDValue &Offset) const {
Daniel Sandersfa961d72014-03-03 14:31:21 +0000410 if (selectAddrFrameIndex(Addr, Base, Offset))
411 return true;
Jack Carter97700972013-08-13 20:19:16 +0000412
Daniel Sandersfa961d72014-03-03 14:31:21 +0000413 if (selectAddrFrameIndexOffset(Addr, Base, Offset, 12))
414 return true;
Jack Carter97700972013-08-13 20:19:16 +0000415
416 return false;
417}
418
Daniel Sandersa73d8fe2015-03-24 11:26:34 +0000419bool MipsSEDAGToDAGISel::selectAddrRegImm16(SDValue Addr, SDValue &Base,
420 SDValue &Offset) const {
421 if (selectAddrFrameIndex(Addr, Base, Offset))
422 return true;
423
424 if (selectAddrFrameIndexOffset(Addr, Base, Offset, 16))
425 return true;
426
427 return false;
428}
429
Jack Carter97700972013-08-13 20:19:16 +0000430bool MipsSEDAGToDAGISel::selectIntAddrMM(SDValue Addr, SDValue &Base,
431 SDValue &Offset) const {
432 return selectAddrRegImm12(Addr, Base, Offset) ||
433 selectAddrDefault(Addr, Base, Offset);
434}
435
Zoran Jovanovic5a1a7802015-02-04 15:43:17 +0000436bool MipsSEDAGToDAGISel::selectIntAddrLSL2MM(SDValue Addr, SDValue &Base,
437 SDValue &Offset) const {
438 if (selectAddrFrameIndexOffset(Addr, Base, Offset, 7)) {
Vasileios Kalintiris99eeb8a2015-02-13 19:14:22 +0000439 if (isa<FrameIndexSDNode>(Base))
Zoran Jovanovic5a1a7802015-02-04 15:43:17 +0000440 return false;
Zoran Jovanovic5a1a7802015-02-04 15:43:17 +0000441
Vasileios Kalintiris99eeb8a2015-02-13 19:14:22 +0000442 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Offset)) {
443 unsigned CnstOff = CN->getZExtValue();
444 return (CnstOff == (CnstOff & 0x3c));
Zoran Jovanovic5a1a7802015-02-04 15:43:17 +0000445 }
Vasileios Kalintiris99eeb8a2015-02-13 19:14:22 +0000446
447 return false;
Zoran Jovanovic5a1a7802015-02-04 15:43:17 +0000448 }
449
450 // For all other cases where "lw" would be selected, don't select "lw16"
451 // because it would result in additional instructions to prepare operands.
452 if (selectAddrRegImm(Addr, Base, Offset))
453 return false;
454
455 return selectAddrDefault(Addr, Base, Offset);
456}
457
Daniel Sandersfa961d72014-03-03 14:31:21 +0000458bool MipsSEDAGToDAGISel::selectIntAddrMSA(SDValue Addr, SDValue &Base,
459 SDValue &Offset) const {
460 if (selectAddrRegImm10(Addr, Base, Offset))
461 return true;
462
463 if (selectAddrDefault(Addr, Base, Offset))
464 return true;
465
466 return false;
467}
468
Daniel Sandersf49dd822013-09-24 13:33:07 +0000469// Select constant vector splats.
470//
471// Returns true and sets Imm if:
472// * MSA is enabled
473// * N is a ISD::BUILD_VECTOR representing a constant splat
Daniel Sandersf49dd822013-09-24 13:33:07 +0000474bool MipsSEDAGToDAGISel::selectVSplat(SDNode *N, APInt &Imm) const {
Eric Christopher22405e42014-07-10 17:26:51 +0000475 if (!Subtarget->hasMSA())
Daniel Sandersf49dd822013-09-24 13:33:07 +0000476 return false;
477
478 BuildVectorSDNode *Node = dyn_cast<BuildVectorSDNode>(N);
479
Craig Topper062a2ba2014-04-25 05:30:21 +0000480 if (!Node)
Daniel Sandersf49dd822013-09-24 13:33:07 +0000481 return false;
482
483 APInt SplatValue, SplatUndef;
484 unsigned SplatBitSize;
485 bool HasAnyUndefs;
486
487 if (!Node->isConstantSplat(SplatValue, SplatUndef, SplatBitSize,
488 HasAnyUndefs, 8,
Eric Christopher22405e42014-07-10 17:26:51 +0000489 !Subtarget->isLittle()))
Daniel Sandersf49dd822013-09-24 13:33:07 +0000490 return false;
491
Daniel Sandersf49dd822013-09-24 13:33:07 +0000492 Imm = SplatValue;
493
494 return true;
495}
496
497// Select constant vector splats.
498//
499// In addition to the requirements of selectVSplat(), this function returns
500// true and sets Imm if:
501// * The splat value is the same width as the elements of the vector
502// * The splat value fits in an integer with the specified signed-ness and
503// width.
504//
505// This function looks through ISD::BITCAST nodes.
506// TODO: This might not be appropriate for big-endian MSA since BITCAST is
507// sometimes a shuffle in big-endian mode.
508//
509// It's worth noting that this function is not used as part of the selection
510// of ldi.[bhwd] since it does not permit using the wrong-typed ldi.[bhwd]
511// instruction to achieve the desired bit pattern. ldi.[bhwd] is selected in
512// MipsSEDAGToDAGISel::selectNode.
513bool MipsSEDAGToDAGISel::
514selectVSplatCommon(SDValue N, SDValue &Imm, bool Signed,
515 unsigned ImmBitSize) const {
516 APInt ImmValue;
517 EVT EltTy = N->getValueType(0).getVectorElementType();
518
519 if (N->getOpcode() == ISD::BITCAST)
520 N = N->getOperand(0);
521
522 if (selectVSplat (N.getNode(), ImmValue) &&
523 ImmValue.getBitWidth() == EltTy.getSizeInBits()) {
524 if (( Signed && ImmValue.isSignedIntN(ImmBitSize)) ||
525 (!Signed && ImmValue.isIntN(ImmBitSize))) {
526 Imm = CurDAG->getTargetConstant(ImmValue, EltTy);
527 return true;
528 }
529 }
530
531 return false;
532}
533
534// Select constant vector splats.
535bool MipsSEDAGToDAGISel::
Daniel Sanders7e51fe12013-09-27 11:48:57 +0000536selectVSplatUimm1(SDValue N, SDValue &Imm) const {
537 return selectVSplatCommon(N, Imm, false, 1);
538}
539
540bool MipsSEDAGToDAGISel::
541selectVSplatUimm2(SDValue N, SDValue &Imm) const {
542 return selectVSplatCommon(N, Imm, false, 2);
543}
544
545bool MipsSEDAGToDAGISel::
Daniel Sandersf49dd822013-09-24 13:33:07 +0000546selectVSplatUimm3(SDValue N, SDValue &Imm) const {
547 return selectVSplatCommon(N, Imm, false, 3);
548}
549
550// Select constant vector splats.
551bool MipsSEDAGToDAGISel::
552selectVSplatUimm4(SDValue N, SDValue &Imm) const {
553 return selectVSplatCommon(N, Imm, false, 4);
554}
555
556// Select constant vector splats.
557bool MipsSEDAGToDAGISel::
558selectVSplatUimm5(SDValue N, SDValue &Imm) const {
559 return selectVSplatCommon(N, Imm, false, 5);
560}
561
562// Select constant vector splats.
563bool MipsSEDAGToDAGISel::
564selectVSplatUimm6(SDValue N, SDValue &Imm) const {
565 return selectVSplatCommon(N, Imm, false, 6);
566}
567
568// Select constant vector splats.
569bool MipsSEDAGToDAGISel::
570selectVSplatUimm8(SDValue N, SDValue &Imm) const {
571 return selectVSplatCommon(N, Imm, false, 8);
572}
573
574// Select constant vector splats.
575bool MipsSEDAGToDAGISel::
576selectVSplatSimm5(SDValue N, SDValue &Imm) const {
577 return selectVSplatCommon(N, Imm, true, 5);
578}
579
580// Select constant vector splats whose value is a power of 2.
581//
582// In addition to the requirements of selectVSplat(), this function returns
583// true and sets Imm if:
584// * The splat value is the same width as the elements of the vector
585// * The splat value is a power of two.
586//
587// This function looks through ISD::BITCAST nodes.
588// TODO: This might not be appropriate for big-endian MSA since BITCAST is
589// sometimes a shuffle in big-endian mode.
590bool MipsSEDAGToDAGISel::selectVSplatUimmPow2(SDValue N, SDValue &Imm) const {
591 APInt ImmValue;
592 EVT EltTy = N->getValueType(0).getVectorElementType();
593
594 if (N->getOpcode() == ISD::BITCAST)
595 N = N->getOperand(0);
596
597 if (selectVSplat (N.getNode(), ImmValue) &&
598 ImmValue.getBitWidth() == EltTy.getSizeInBits()) {
599 int32_t Log2 = ImmValue.exactLogBase2();
600
601 if (Log2 != -1) {
602 Imm = CurDAG->getTargetConstant(Log2, EltTy);
603 return true;
604 }
605 }
606
607 return false;
608}
609
Daniel Sandersd74b1302013-10-30 14:45:14 +0000610// Select constant vector splats whose value only has a consecutive sequence
611// of left-most bits set (e.g. 0b11...1100...00).
612//
613// In addition to the requirements of selectVSplat(), this function returns
614// true and sets Imm if:
615// * The splat value is the same width as the elements of the vector
616// * The splat value is a consecutive sequence of left-most bits.
617//
618// This function looks through ISD::BITCAST nodes.
619// TODO: This might not be appropriate for big-endian MSA since BITCAST is
620// sometimes a shuffle in big-endian mode.
621bool MipsSEDAGToDAGISel::selectVSplatMaskL(SDValue N, SDValue &Imm) const {
622 APInt ImmValue;
623 EVT EltTy = N->getValueType(0).getVectorElementType();
624
625 if (N->getOpcode() == ISD::BITCAST)
626 N = N->getOperand(0);
627
628 if (selectVSplat(N.getNode(), ImmValue) &&
629 ImmValue.getBitWidth() == EltTy.getSizeInBits()) {
630 // Extract the run of set bits starting with bit zero from the bitwise
631 // inverse of ImmValue, and test that the inverse of this is the same
632 // as the original value.
633 if (ImmValue == ~(~ImmValue & ~(~ImmValue + 1))) {
634
635 Imm = CurDAG->getTargetConstant(ImmValue.countPopulation(), EltTy);
636 return true;
637 }
638 }
639
640 return false;
641}
642
643// Select constant vector splats whose value only has a consecutive sequence
644// of right-most bits set (e.g. 0b00...0011...11).
645//
646// In addition to the requirements of selectVSplat(), this function returns
647// true and sets Imm if:
648// * The splat value is the same width as the elements of the vector
649// * The splat value is a consecutive sequence of right-most bits.
650//
651// This function looks through ISD::BITCAST nodes.
652// TODO: This might not be appropriate for big-endian MSA since BITCAST is
653// sometimes a shuffle in big-endian mode.
654bool MipsSEDAGToDAGISel::selectVSplatMaskR(SDValue N, SDValue &Imm) const {
655 APInt ImmValue;
656 EVT EltTy = N->getValueType(0).getVectorElementType();
657
658 if (N->getOpcode() == ISD::BITCAST)
659 N = N->getOperand(0);
660
661 if (selectVSplat(N.getNode(), ImmValue) &&
662 ImmValue.getBitWidth() == EltTy.getSizeInBits()) {
663 // Extract the run of set bits starting with bit zero, and test that the
664 // result is the same as the original value
665 if (ImmValue == (ImmValue & ~(ImmValue + 1))) {
666 Imm = CurDAG->getTargetConstant(ImmValue.countPopulation(), EltTy);
667 return true;
668 }
669 }
670
671 return false;
672}
673
Daniel Sanders3f6eb542013-11-12 10:45:18 +0000674bool MipsSEDAGToDAGISel::selectVSplatUimmInvPow2(SDValue N,
675 SDValue &Imm) const {
676 APInt ImmValue;
677 EVT EltTy = N->getValueType(0).getVectorElementType();
678
679 if (N->getOpcode() == ISD::BITCAST)
680 N = N->getOperand(0);
681
682 if (selectVSplat(N.getNode(), ImmValue) &&
683 ImmValue.getBitWidth() == EltTy.getSizeInBits()) {
684 int32_t Log2 = (~ImmValue).exactLogBase2();
685
686 if (Log2 != -1) {
687 Imm = CurDAG->getTargetConstant(Log2, EltTy);
688 return true;
689 }
690 }
691
692 return false;
693}
694
Akira Hatanaka040d2252013-03-14 18:33:23 +0000695std::pair<bool, SDNode*> MipsSEDAGToDAGISel::selectNode(SDNode *Node) {
Akira Hatanaka30a84782013-03-14 18:27:31 +0000696 unsigned Opcode = Node->getOpcode();
Andrew Trickef9de2a2013-05-25 02:42:55 +0000697 SDLoc DL(Node);
Akira Hatanaka30a84782013-03-14 18:27:31 +0000698
699 ///
700 // Instruction Selection not handled by the auto-generated
701 // tablegen selection should be handled here.
702 ///
Akira Hatanaka30a84782013-03-14 18:27:31 +0000703 SDNode *Result;
Akira Hatanaka30a84782013-03-14 18:27:31 +0000704
705 switch(Opcode) {
706 default: break;
707
Akira Hatanakab8835b82013-03-14 18:39:25 +0000708 case ISD::SUBE: {
709 SDValue InFlag = Node->getOperand(2);
Vasileios Kalintirisef96a8e2015-01-26 12:33:22 +0000710 unsigned Opc = Subtarget->isGP64bit() ? Mips::DSUBu : Mips::SUBu;
711 Result = selectAddESubE(Opc, InFlag, InFlag.getOperand(0), DL, Node);
Akira Hatanakab8835b82013-03-14 18:39:25 +0000712 return std::make_pair(true, Result);
713 }
714
Akira Hatanaka30a84782013-03-14 18:27:31 +0000715 case ISD::ADDE: {
Eric Christopher22405e42014-07-10 17:26:51 +0000716 if (Subtarget->hasDSP()) // Select DSP instructions, ADDSC and ADDWC.
Akira Hatanaka2f088222013-04-13 00:55:41 +0000717 break;
Akira Hatanakab8835b82013-03-14 18:39:25 +0000718 SDValue InFlag = Node->getOperand(2);
Vasileios Kalintirisef96a8e2015-01-26 12:33:22 +0000719 unsigned Opc = Subtarget->isGP64bit() ? Mips::DADDu : Mips::ADDu;
720 Result = selectAddESubE(Opc, InFlag, InFlag.getValue(0), DL, Node);
Akira Hatanaka30a84782013-03-14 18:27:31 +0000721 return std::make_pair(true, Result);
722 }
723
Akira Hatanaka30a84782013-03-14 18:27:31 +0000724 case ISD::ConstantFP: {
725 ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(Node);
726 if (Node->getValueType(0) == MVT::f64 && CN->isExactlyValue(+0.0)) {
Eric Christopher22405e42014-07-10 17:26:51 +0000727 if (Subtarget->isGP64bit()) {
Akira Hatanaka040d2252013-03-14 18:33:23 +0000728 SDValue Zero = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), DL,
Akira Hatanaka30a84782013-03-14 18:27:31 +0000729 Mips::ZERO_64, MVT::i64);
Akira Hatanaka040d2252013-03-14 18:33:23 +0000730 Result = CurDAG->getMachineNode(Mips::DMTC1, DL, MVT::f64, Zero);
Eric Christopher22405e42014-07-10 17:26:51 +0000731 } else if (Subtarget->isFP64bit()) {
Daniel Sanders08d3cd12013-11-18 13:12:43 +0000732 SDValue Zero = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), DL,
733 Mips::ZERO, MVT::i32);
734 Result = CurDAG->getMachineNode(Mips::BuildPairF64_64, DL, MVT::f64,
735 Zero, Zero);
Akira Hatanaka30a84782013-03-14 18:27:31 +0000736 } else {
Akira Hatanaka040d2252013-03-14 18:33:23 +0000737 SDValue Zero = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), DL,
Akira Hatanaka30a84782013-03-14 18:27:31 +0000738 Mips::ZERO, MVT::i32);
Akira Hatanaka040d2252013-03-14 18:33:23 +0000739 Result = CurDAG->getMachineNode(Mips::BuildPairF64, DL, MVT::f64, Zero,
Akira Hatanaka30a84782013-03-14 18:27:31 +0000740 Zero);
741 }
742
743 return std::make_pair(true, Result);
744 }
745 break;
746 }
747
748 case ISD::Constant: {
749 const ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Node);
750 unsigned Size = CN->getValueSizeInBits(0);
751
752 if (Size == 32)
753 break;
754
755 MipsAnalyzeImmediate AnalyzeImm;
756 int64_t Imm = CN->getSExtValue();
757
758 const MipsAnalyzeImmediate::InstSeq &Seq =
759 AnalyzeImm.Analyze(Imm, Size, false);
760
761 MipsAnalyzeImmediate::InstSeq::const_iterator Inst = Seq.begin();
Andrew Trickef9de2a2013-05-25 02:42:55 +0000762 SDLoc DL(CN);
Akira Hatanaka30a84782013-03-14 18:27:31 +0000763 SDNode *RegOpnd;
764 SDValue ImmOpnd = CurDAG->getTargetConstant(SignExtend64<16>(Inst->ImmOpnd),
765 MVT::i64);
766
767 // The first instruction can be a LUi which is different from other
768 // instructions (ADDiu, ORI and SLL) in that it does not have a register
769 // operand.
770 if (Inst->Opc == Mips::LUi64)
771 RegOpnd = CurDAG->getMachineNode(Inst->Opc, DL, MVT::i64, ImmOpnd);
772 else
773 RegOpnd =
774 CurDAG->getMachineNode(Inst->Opc, DL, MVT::i64,
775 CurDAG->getRegister(Mips::ZERO_64, MVT::i64),
776 ImmOpnd);
777
778 // The remaining instructions in the sequence are handled here.
779 for (++Inst; Inst != Seq.end(); ++Inst) {
780 ImmOpnd = CurDAG->getTargetConstant(SignExtend64<16>(Inst->ImmOpnd),
781 MVT::i64);
782 RegOpnd = CurDAG->getMachineNode(Inst->Opc, DL, MVT::i64,
783 SDValue(RegOpnd, 0), ImmOpnd);
784 }
785
786 return std::make_pair(true, RegOpnd);
787 }
788
Daniel Sandersf9aa1d12013-08-28 10:26:24 +0000789 case ISD::INTRINSIC_W_CHAIN: {
790 switch (cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue()) {
791 default:
792 break;
793
794 case Intrinsic::mips_cfcmsa: {
795 SDValue ChainIn = Node->getOperand(0);
796 SDValue RegIdx = Node->getOperand(2);
797 SDValue Reg = CurDAG->getCopyFromReg(ChainIn, DL,
798 getMSACtrlReg(RegIdx), MVT::i32);
799 return std::make_pair(true, Reg.getNode());
800 }
801 }
802 break;
803 }
804
Daniel Sandersba9c8502013-08-28 10:44:47 +0000805 case ISD::INTRINSIC_WO_CHAIN: {
806 switch (cast<ConstantSDNode>(Node->getOperand(0))->getZExtValue()) {
807 default:
808 break;
809
810 case Intrinsic::mips_move_v:
811 // Like an assignment but will always produce a move.v even if
812 // unnecessary.
813 return std::make_pair(true,
814 CurDAG->getMachineNode(Mips::MOVE_V, DL,
815 Node->getValueType(0),
816 Node->getOperand(1)));
817 }
818 break;
819 }
820
Daniel Sandersf9aa1d12013-08-28 10:26:24 +0000821 case ISD::INTRINSIC_VOID: {
822 switch (cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue()) {
823 default:
824 break;
825
826 case Intrinsic::mips_ctcmsa: {
827 SDValue ChainIn = Node->getOperand(0);
828 SDValue RegIdx = Node->getOperand(2);
829 SDValue Value = Node->getOperand(3);
830 SDValue ChainOut = CurDAG->getCopyToReg(ChainIn, DL,
831 getMSACtrlReg(RegIdx), Value);
832 return std::make_pair(true, ChainOut.getNode());
833 }
834 }
835 break;
836 }
837
Akira Hatanaka30a84782013-03-14 18:27:31 +0000838 case MipsISD::ThreadPointer: {
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000839 EVT PtrVT = getTargetLowering()->getPointerTy();
Akira Hatanaka85ccf232013-08-08 21:37:32 +0000840 unsigned RdhwrOpc, DestReg;
Akira Hatanaka30a84782013-03-14 18:27:31 +0000841
842 if (PtrVT == MVT::i32) {
843 RdhwrOpc = Mips::RDHWR;
Akira Hatanaka30a84782013-03-14 18:27:31 +0000844 DestReg = Mips::V1;
845 } else {
846 RdhwrOpc = Mips::RDHWR64;
Akira Hatanaka30a84782013-03-14 18:27:31 +0000847 DestReg = Mips::V1_64;
848 }
849
850 SDNode *Rdhwr =
Andrew Trickef9de2a2013-05-25 02:42:55 +0000851 CurDAG->getMachineNode(RdhwrOpc, SDLoc(Node),
Akira Hatanaka30a84782013-03-14 18:27:31 +0000852 Node->getValueType(0),
Akira Hatanaka85ccf232013-08-08 21:37:32 +0000853 CurDAG->getRegister(Mips::HWR29, MVT::i32));
Akira Hatanaka040d2252013-03-14 18:33:23 +0000854 SDValue Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), DL, DestReg,
Akira Hatanaka30a84782013-03-14 18:27:31 +0000855 SDValue(Rdhwr, 0));
Akira Hatanaka040d2252013-03-14 18:33:23 +0000856 SDValue ResNode = CurDAG->getCopyFromReg(Chain, DL, DestReg, PtrVT);
Akira Hatanaka30a84782013-03-14 18:27:31 +0000857 ReplaceUses(SDValue(Node, 0), ResNode);
858 return std::make_pair(true, ResNode.getNode());
859 }
Akira Hatanakabe8612f2013-03-30 01:36:35 +0000860
Daniel Sandersf49dd822013-09-24 13:33:07 +0000861 case ISD::BUILD_VECTOR: {
862 // Select appropriate ldi.[bhwd] instructions for constant splats of
863 // 128-bit when MSA is enabled. Fixup any register class mismatches that
864 // occur as a result.
865 //
866 // This allows the compiler to use a wider range of immediates than would
867 // otherwise be allowed. If, for example, v4i32 could only use ldi.h then
868 // it would not be possible to load { 0x01010101, 0x01010101, 0x01010101,
869 // 0x01010101 } without using a constant pool. This would be sub-optimal
870 // when // 'ldi.b wd, 1' is capable of producing that bit-pattern in the
871 // same set/ of registers. Similarly, ldi.h isn't capable of producing {
872 // 0x00000000, 0x00000001, 0x00000000, 0x00000001 } but 'ldi.d wd, 1' can.
873
874 BuildVectorSDNode *BVN = cast<BuildVectorSDNode>(Node);
875 APInt SplatValue, SplatUndef;
876 unsigned SplatBitSize;
877 bool HasAnyUndefs;
878 unsigned LdiOp;
879 EVT ResVecTy = BVN->getValueType(0);
880 EVT ViaVecTy;
881
Eric Christopher22405e42014-07-10 17:26:51 +0000882 if (!Subtarget->hasMSA() || !BVN->getValueType(0).is128BitVector())
Craig Topper062a2ba2014-04-25 05:30:21 +0000883 return std::make_pair(false, nullptr);
Daniel Sandersf49dd822013-09-24 13:33:07 +0000884
885 if (!BVN->isConstantSplat(SplatValue, SplatUndef, SplatBitSize,
886 HasAnyUndefs, 8,
Eric Christopher22405e42014-07-10 17:26:51 +0000887 !Subtarget->isLittle()))
Craig Topper062a2ba2014-04-25 05:30:21 +0000888 return std::make_pair(false, nullptr);
Daniel Sandersf49dd822013-09-24 13:33:07 +0000889
890 switch (SplatBitSize) {
891 default:
Craig Topper062a2ba2014-04-25 05:30:21 +0000892 return std::make_pair(false, nullptr);
Daniel Sandersf49dd822013-09-24 13:33:07 +0000893 case 8:
894 LdiOp = Mips::LDI_B;
895 ViaVecTy = MVT::v16i8;
896 break;
897 case 16:
898 LdiOp = Mips::LDI_H;
899 ViaVecTy = MVT::v8i16;
900 break;
901 case 32:
902 LdiOp = Mips::LDI_W;
903 ViaVecTy = MVT::v4i32;
904 break;
905 case 64:
906 LdiOp = Mips::LDI_D;
907 ViaVecTy = MVT::v2i64;
908 break;
909 }
910
911 if (!SplatValue.isSignedIntN(10))
Craig Topper062a2ba2014-04-25 05:30:21 +0000912 return std::make_pair(false, nullptr);
Daniel Sandersf49dd822013-09-24 13:33:07 +0000913
914 SDValue Imm = CurDAG->getTargetConstant(SplatValue,
915 ViaVecTy.getVectorElementType());
916
917 SDNode *Res = CurDAG->getMachineNode(LdiOp, SDLoc(Node), ViaVecTy, Imm);
918
919 if (ResVecTy != ViaVecTy) {
920 // If LdiOp is writing to a different register class to ResVecTy, then
921 // fix it up here. This COPY_TO_REGCLASS should never cause a move.v
922 // since the source and destination register sets contain the same
923 // registers.
924 const TargetLowering *TLI = getTargetLowering();
925 MVT ResVecTySimple = ResVecTy.getSimpleVT();
926 const TargetRegisterClass *RC = TLI->getRegClassFor(ResVecTySimple);
927 Res = CurDAG->getMachineNode(Mips::COPY_TO_REGCLASS, SDLoc(Node),
928 ResVecTy, SDValue(Res, 0),
929 CurDAG->getTargetConstant(RC->getID(),
930 MVT::i32));
931 }
932
933 return std::make_pair(true, Res);
934 }
935
Akira Hatanaka30a84782013-03-14 18:27:31 +0000936 }
937
Craig Topper062a2ba2014-04-25 05:30:21 +0000938 return std::make_pair(false, nullptr);
Akira Hatanaka30a84782013-03-14 18:27:31 +0000939}
940
Daniel Sandersa73d8fe2015-03-24 11:26:34 +0000941bool MipsSEDAGToDAGISel::
942SelectInlineAsmMemoryOperand(const SDValue &Op, unsigned ConstraintID,
943 std::vector<SDValue> &OutOps) {
944 SDValue Base, Offset;
945
946 switch(ConstraintID) {
947 default:
948 llvm_unreachable("Unexpected asm memory constraint");
949 // All memory constraints can at least accept raw pointers.
950 case InlineAsm::Constraint_i:
Daniel Sandersa73d8fe2015-03-24 11:26:34 +0000951 case InlineAsm::Constraint_R:
952 OutOps.push_back(Op);
953 OutOps.push_back(CurDAG->getTargetConstant(0, MVT::i32));
954 return false;
Daniel Sandersc676f2a2015-03-24 15:19:14 +0000955 case InlineAsm::Constraint_m:
956 if (selectAddrRegImm16(Op, Base, Offset)) {
957 OutOps.push_back(Base);
958 OutOps.push_back(Offset);
959 return false;
960 }
961 OutOps.push_back(Op);
962 OutOps.push_back(CurDAG->getTargetConstant(0, MVT::i32));
963 return false;
Daniel Sandersa73d8fe2015-03-24 11:26:34 +0000964 case InlineAsm::Constraint_ZC:
965 // ZC matches whatever the pref, ll, and sc instructions can handle for the
966 // given subtarget.
967 if (Subtarget->inMicroMipsMode()) {
968 // On microMIPS, they can handle 12-bit offsets.
969 if (selectAddrRegImm12(Op, Base, Offset)) {
970 OutOps.push_back(Base);
971 OutOps.push_back(Offset);
972 return false;
973 }
974 } else if (Subtarget->hasMips32r6()) {
975 // On MIPS32r6/MIPS64r6, they can only handle 9-bit offsets.
976 if (selectAddrRegImm9(Op, Base, Offset)) {
977 OutOps.push_back(Base);
978 OutOps.push_back(Offset);
979 return false;
980 }
981 } else if (selectAddrRegImm16(Op, Base, Offset)) {
982 // Prior to MIPS32r6/MIPS64r6, they can handle 16-bit offsets.
983 OutOps.push_back(Base);
984 OutOps.push_back(Offset);
985 return false;
986 }
987 // In all cases, 0-bit offsets are acceptable.
988 OutOps.push_back(Op);
989 OutOps.push_back(CurDAG->getTargetConstant(0, MVT::i32));
990 return false;
991 }
992 return true;
993}
994
Akira Hatanaka30a84782013-03-14 18:27:31 +0000995FunctionPass *llvm::createMipsSEISelDag(MipsTargetMachine &TM) {
996 return new MipsSEDAGToDAGISel(TM);
997}