1 //===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines an instruction selector for the ARM target.
12 //===----------------------------------------------------------------------===//
15 #include "ARMAddressingModes.h"
16 #include "ARMISelLowering.h"
17 #include "ARMTargetMachine.h"
18 #include "llvm/CallingConv.h"
19 #include "llvm/Constants.h"
20 #include "llvm/DerivedTypes.h"
21 #include "llvm/Function.h"
22 #include "llvm/Intrinsics.h"
23 #include "llvm/LLVMContext.h"
24 #include "llvm/CodeGen/MachineFrameInfo.h"
25 #include "llvm/CodeGen/MachineFunction.h"
26 #include "llvm/CodeGen/MachineInstrBuilder.h"
27 #include "llvm/CodeGen/SelectionDAG.h"
28 #include "llvm/CodeGen/SelectionDAGISel.h"
29 #include "llvm/Target/TargetLowering.h"
30 #include "llvm/Target/TargetOptions.h"
31 #include "llvm/Support/Compiler.h"
32 #include "llvm/Support/Debug.h"
33 #include "llvm/Support/ErrorHandling.h"
34 #include "llvm/Support/raw_ostream.h"
38 //===--------------------------------------------------------------------===//
39 /// ARMDAGToDAGISel - ARM specific code to select ARM machine
40 /// instructions for SelectionDAG operations.
43 class ARMDAGToDAGISel : public SelectionDAGISel {
44 ARMBaseTargetMachine &TM;
46 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
47 /// make the right decision when generating code for different targets.
48 const ARMSubtarget *Subtarget;
51 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
52 CodeGenOpt::Level OptLevel)
53 : SelectionDAGISel(tm, OptLevel), TM(tm),
54 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
57 virtual const char *getPassName() const {
58 return "ARM Instruction Selection";
61 /// getI32Imm - Return a target constant of type i32 with the specified
63 inline SDValue getI32Imm(unsigned Imm) {
64 return CurDAG->getTargetConstant(Imm, MVT::i32);
67 SDNode *Select(SDValue Op);
68 virtual void InstructionSelect();
69 bool SelectShifterOperandReg(SDValue Op, SDValue N, SDValue &A,
70 SDValue &B, SDValue &C);
71 bool SelectAddrMode2(SDValue Op, SDValue N, SDValue &Base,
72 SDValue &Offset, SDValue &Opc);
73 bool SelectAddrMode2Offset(SDValue Op, SDValue N,
74 SDValue &Offset, SDValue &Opc);
75 bool SelectAddrMode3(SDValue Op, SDValue N, SDValue &Base,
76 SDValue &Offset, SDValue &Opc);
77 bool SelectAddrMode3Offset(SDValue Op, SDValue N,
78 SDValue &Offset, SDValue &Opc);
79 bool SelectAddrMode4(SDValue Op, SDValue N, SDValue &Addr,
81 bool SelectAddrMode5(SDValue Op, SDValue N, SDValue &Base,
83 bool SelectAddrMode6(SDValue Op, SDValue N, SDValue &Addr, SDValue &Update,
86 bool SelectAddrModePC(SDValue Op, SDValue N, SDValue &Offset,
89 bool SelectThumbAddrModeRR(SDValue Op, SDValue N, SDValue &Base,
91 bool SelectThumbAddrModeRI5(SDValue Op, SDValue N, unsigned Scale,
92 SDValue &Base, SDValue &OffImm,
94 bool SelectThumbAddrModeS1(SDValue Op, SDValue N, SDValue &Base,
95 SDValue &OffImm, SDValue &Offset);
96 bool SelectThumbAddrModeS2(SDValue Op, SDValue N, SDValue &Base,
97 SDValue &OffImm, SDValue &Offset);
98 bool SelectThumbAddrModeS4(SDValue Op, SDValue N, SDValue &Base,
99 SDValue &OffImm, SDValue &Offset);
100 bool SelectThumbAddrModeSP(SDValue Op, SDValue N, SDValue &Base,
103 bool SelectT2ShifterOperandReg(SDValue Op, SDValue N,
104 SDValue &BaseReg, SDValue &Opc);
105 bool SelectT2AddrModeImm12(SDValue Op, SDValue N, SDValue &Base,
107 bool SelectT2AddrModeImm8(SDValue Op, SDValue N, SDValue &Base,
109 bool SelectT2AddrModeImm8Offset(SDValue Op, SDValue N,
111 bool SelectT2AddrModeImm8s4(SDValue Op, SDValue N, SDValue &Base,
113 bool SelectT2AddrModeSoReg(SDValue Op, SDValue N, SDValue &Base,
114 SDValue &OffReg, SDValue &ShImm);
116 // Include the pieces autogenerated from the target description.
117 #include "ARMGenDAGISel.inc"
120 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
122 SDNode *SelectARMIndexedLoad(SDValue Op);
123 SDNode *SelectT2IndexedLoad(SDValue Op);
125 /// SelectDYN_ALLOC - Select dynamic alloc for Thumb.
126 SDNode *SelectDYN_ALLOC(SDValue Op);
128 /// SelectVLD - Select NEON load intrinsics. NumVecs should
129 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
130 /// loads of D registers and even subregs and odd subregs of Q registers.
131 /// For NumVecs == 2, QOpcodes1 is not used.
132 SDNode *SelectVLD(SDValue Op, unsigned NumVecs, unsigned *DOpcodes,
133 unsigned *QOpcodes0, unsigned *QOpcodes1);
135 /// SelectVST - Select NEON store intrinsics. NumVecs should
136 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
137 /// stores of D registers and even subregs and odd subregs of Q registers.
138 /// For NumVecs == 2, QOpcodes1 is not used.
139 SDNode *SelectVST(SDValue Op, unsigned NumVecs, unsigned *DOpcodes,
140 unsigned *QOpcodes0, unsigned *QOpcodes1);
142 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
143 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
144 /// load/store of D registers and even subregs and odd subregs of Q registers.
145 SDNode *SelectVLDSTLane(SDValue Op, bool IsLoad, unsigned NumVecs,
146 unsigned *DOpcodes, unsigned *QOpcodes0,
147 unsigned *QOpcodes1);
149 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
150 SDNode *SelectV6T2BitfieldExtractOp(SDValue Op, unsigned Opc);
152 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
153 /// inline asm expressions.
154 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
156 std::vector<SDValue> &OutOps);
158 /// PairDRegs - Insert a pair of double registers into an implicit def to
159 /// form a quad register.
160 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
164 /// isInt32Immediate - This method tests to see if the node is a 32-bit constant
165 /// operand. If so Imm will receive the 32-bit value.
166 static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
167 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
168 Imm = cast<ConstantSDNode>(N)->getZExtValue();
174 // isInt32Immediate - This method tests to see if a constant operand.
175 // If so Imm will receive the 32 bit value.
176 static bool isInt32Immediate(SDValue N, unsigned &Imm) {
177 return isInt32Immediate(N.getNode(), Imm);
180 // isOpcWithIntImmediate - This method tests to see if the node is a specific
181 // opcode and that it has a immediate integer right operand.
182 // If so Imm will receive the 32 bit value.
183 static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
184 return N->getOpcode() == Opc &&
185 isInt32Immediate(N->getOperand(1).getNode(), Imm);
189 void ARMDAGToDAGISel::InstructionSelect() {
193 CurDAG->RemoveDeadNodes();
196 bool ARMDAGToDAGISel::SelectShifterOperandReg(SDValue Op,
201 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
203 // Don't match base register only case. That is matched to a separate
204 // lower complexity pattern with explicit register operand.
205 if (ShOpcVal == ARM_AM::no_shift) return false;
207 BaseReg = N.getOperand(0);
208 unsigned ShImmVal = 0;
209 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
210 ShReg = CurDAG->getRegister(0, MVT::i32);
211 ShImmVal = RHS->getZExtValue() & 31;
213 ShReg = N.getOperand(1);
215 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
220 bool ARMDAGToDAGISel::SelectAddrMode2(SDValue Op, SDValue N,
221 SDValue &Base, SDValue &Offset,
223 if (N.getOpcode() == ISD::MUL) {
224 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
225 // X * [3,5,9] -> X + X * [2,4,8] etc.
226 int RHSC = (int)RHS->getZExtValue();
229 ARM_AM::AddrOpc AddSub = ARM_AM::add;
231 AddSub = ARM_AM::sub;
234 if (isPowerOf2_32(RHSC)) {
235 unsigned ShAmt = Log2_32(RHSC);
236 Base = Offset = N.getOperand(0);
237 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
246 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
248 if (N.getOpcode() == ISD::FrameIndex) {
249 int FI = cast<FrameIndexSDNode>(N)->getIndex();
250 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
251 } else if (N.getOpcode() == ARMISD::Wrapper) {
252 Base = N.getOperand(0);
254 Offset = CurDAG->getRegister(0, MVT::i32);
255 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
261 // Match simple R +/- imm12 operands.
262 if (N.getOpcode() == ISD::ADD)
263 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
264 int RHSC = (int)RHS->getZExtValue();
265 if ((RHSC >= 0 && RHSC < 0x1000) ||
266 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
267 Base = N.getOperand(0);
268 if (Base.getOpcode() == ISD::FrameIndex) {
269 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
270 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
272 Offset = CurDAG->getRegister(0, MVT::i32);
274 ARM_AM::AddrOpc AddSub = ARM_AM::add;
276 AddSub = ARM_AM::sub;
279 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
286 // Otherwise this is R +/- [possibly shifted] R.
287 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
288 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
291 Base = N.getOperand(0);
292 Offset = N.getOperand(1);
294 if (ShOpcVal != ARM_AM::no_shift) {
295 // Check to see if the RHS of the shift is a constant, if not, we can't fold
297 if (ConstantSDNode *Sh =
298 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
299 ShAmt = Sh->getZExtValue();
300 Offset = N.getOperand(1).getOperand(0);
302 ShOpcVal = ARM_AM::no_shift;
306 // Try matching (R shl C) + (R).
307 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
308 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
309 if (ShOpcVal != ARM_AM::no_shift) {
310 // Check to see if the RHS of the shift is a constant, if not, we can't
312 if (ConstantSDNode *Sh =
313 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
314 ShAmt = Sh->getZExtValue();
315 Offset = N.getOperand(0).getOperand(0);
316 Base = N.getOperand(1);
318 ShOpcVal = ARM_AM::no_shift;
323 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
328 bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDValue Op, SDValue N,
329 SDValue &Offset, SDValue &Opc) {
330 unsigned Opcode = Op.getOpcode();
331 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
332 ? cast<LoadSDNode>(Op)->getAddressingMode()
333 : cast<StoreSDNode>(Op)->getAddressingMode();
334 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
335 ? ARM_AM::add : ARM_AM::sub;
336 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
337 int Val = (int)C->getZExtValue();
338 if (Val >= 0 && Val < 0x1000) { // 12 bits.
339 Offset = CurDAG->getRegister(0, MVT::i32);
340 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
348 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
350 if (ShOpcVal != ARM_AM::no_shift) {
351 // Check to see if the RHS of the shift is a constant, if not, we can't fold
353 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
354 ShAmt = Sh->getZExtValue();
355 Offset = N.getOperand(0);
357 ShOpcVal = ARM_AM::no_shift;
361 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
367 bool ARMDAGToDAGISel::SelectAddrMode3(SDValue Op, SDValue N,
368 SDValue &Base, SDValue &Offset,
370 if (N.getOpcode() == ISD::SUB) {
371 // X - C is canonicalize to X + -C, no need to handle it here.
372 Base = N.getOperand(0);
373 Offset = N.getOperand(1);
374 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
378 if (N.getOpcode() != ISD::ADD) {
380 if (N.getOpcode() == ISD::FrameIndex) {
381 int FI = cast<FrameIndexSDNode>(N)->getIndex();
382 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
384 Offset = CurDAG->getRegister(0, MVT::i32);
385 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
389 // If the RHS is +/- imm8, fold into addr mode.
390 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
391 int RHSC = (int)RHS->getZExtValue();
392 if ((RHSC >= 0 && RHSC < 256) ||
393 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
394 Base = N.getOperand(0);
395 if (Base.getOpcode() == ISD::FrameIndex) {
396 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
397 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
399 Offset = CurDAG->getRegister(0, MVT::i32);
401 ARM_AM::AddrOpc AddSub = ARM_AM::add;
403 AddSub = ARM_AM::sub;
406 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
411 Base = N.getOperand(0);
412 Offset = N.getOperand(1);
413 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
417 bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDValue Op, SDValue N,
418 SDValue &Offset, SDValue &Opc) {
419 unsigned Opcode = Op.getOpcode();
420 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
421 ? cast<LoadSDNode>(Op)->getAddressingMode()
422 : cast<StoreSDNode>(Op)->getAddressingMode();
423 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
424 ? ARM_AM::add : ARM_AM::sub;
425 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
426 int Val = (int)C->getZExtValue();
427 if (Val >= 0 && Val < 256) {
428 Offset = CurDAG->getRegister(0, MVT::i32);
429 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
435 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
439 bool ARMDAGToDAGISel::SelectAddrMode4(SDValue Op, SDValue N,
440 SDValue &Addr, SDValue &Mode) {
442 Mode = CurDAG->getTargetConstant(0, MVT::i32);
446 bool ARMDAGToDAGISel::SelectAddrMode5(SDValue Op, SDValue N,
447 SDValue &Base, SDValue &Offset) {
448 if (N.getOpcode() != ISD::ADD) {
450 if (N.getOpcode() == ISD::FrameIndex) {
451 int FI = cast<FrameIndexSDNode>(N)->getIndex();
452 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
453 } else if (N.getOpcode() == ARMISD::Wrapper) {
454 Base = N.getOperand(0);
456 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
461 // If the RHS is +/- imm8, fold into addr mode.
462 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
463 int RHSC = (int)RHS->getZExtValue();
464 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
466 if ((RHSC >= 0 && RHSC < 256) ||
467 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
468 Base = N.getOperand(0);
469 if (Base.getOpcode() == ISD::FrameIndex) {
470 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
471 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
474 ARM_AM::AddrOpc AddSub = ARM_AM::add;
476 AddSub = ARM_AM::sub;
479 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
487 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
492 bool ARMDAGToDAGISel::SelectAddrMode6(SDValue Op, SDValue N,
493 SDValue &Addr, SDValue &Update,
496 // Default to no writeback.
497 Update = CurDAG->getRegister(0, MVT::i32);
498 Opc = CurDAG->getTargetConstant(ARM_AM::getAM6Opc(false), MVT::i32);
502 bool ARMDAGToDAGISel::SelectAddrModePC(SDValue Op, SDValue N,
503 SDValue &Offset, SDValue &Label) {
504 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
505 Offset = N.getOperand(0);
506 SDValue N1 = N.getOperand(1);
507 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
514 bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue Op, SDValue N,
515 SDValue &Base, SDValue &Offset){
516 // FIXME dl should come from the parent load or store, not the address
517 DebugLoc dl = Op.getDebugLoc();
518 if (N.getOpcode() != ISD::ADD) {
519 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
520 if (!NC || NC->getZExtValue() != 0)
527 Base = N.getOperand(0);
528 Offset = N.getOperand(1);
533 ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDValue Op, SDValue N,
534 unsigned Scale, SDValue &Base,
535 SDValue &OffImm, SDValue &Offset) {
537 SDValue TmpBase, TmpOffImm;
538 if (SelectThumbAddrModeSP(Op, N, TmpBase, TmpOffImm))
539 return false; // We want to select tLDRspi / tSTRspi instead.
540 if (N.getOpcode() == ARMISD::Wrapper &&
541 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
542 return false; // We want to select tLDRpci instead.
545 if (N.getOpcode() != ISD::ADD) {
546 Base = (N.getOpcode() == ARMISD::Wrapper) ? N.getOperand(0) : N;
547 Offset = CurDAG->getRegister(0, MVT::i32);
548 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
552 // Thumb does not have [sp, r] address mode.
553 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
554 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
555 if ((LHSR && LHSR->getReg() == ARM::SP) ||
556 (RHSR && RHSR->getReg() == ARM::SP)) {
558 Offset = CurDAG->getRegister(0, MVT::i32);
559 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
563 // If the RHS is + imm5 * scale, fold into addr mode.
564 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
565 int RHSC = (int)RHS->getZExtValue();
566 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
568 if (RHSC >= 0 && RHSC < 32) {
569 Base = N.getOperand(0);
570 Offset = CurDAG->getRegister(0, MVT::i32);
571 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
577 Base = N.getOperand(0);
578 Offset = N.getOperand(1);
579 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
583 bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDValue Op, SDValue N,
584 SDValue &Base, SDValue &OffImm,
586 return SelectThumbAddrModeRI5(Op, N, 1, Base, OffImm, Offset);
589 bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDValue Op, SDValue N,
590 SDValue &Base, SDValue &OffImm,
592 return SelectThumbAddrModeRI5(Op, N, 2, Base, OffImm, Offset);
595 bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDValue Op, SDValue N,
596 SDValue &Base, SDValue &OffImm,
598 return SelectThumbAddrModeRI5(Op, N, 4, Base, OffImm, Offset);
601 bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue Op, SDValue N,
602 SDValue &Base, SDValue &OffImm) {
603 if (N.getOpcode() == ISD::FrameIndex) {
604 int FI = cast<FrameIndexSDNode>(N)->getIndex();
605 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
606 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
610 if (N.getOpcode() != ISD::ADD)
613 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
614 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
615 (LHSR && LHSR->getReg() == ARM::SP)) {
616 // If the RHS is + imm8 * scale, fold into addr mode.
617 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
618 int RHSC = (int)RHS->getZExtValue();
619 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
621 if (RHSC >= 0 && RHSC < 256) {
622 Base = N.getOperand(0);
623 if (Base.getOpcode() == ISD::FrameIndex) {
624 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
625 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
627 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
637 bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue Op, SDValue N,
640 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
642 // Don't match base register only case. That is matched to a separate
643 // lower complexity pattern with explicit register operand.
644 if (ShOpcVal == ARM_AM::no_shift) return false;
646 BaseReg = N.getOperand(0);
647 unsigned ShImmVal = 0;
648 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
649 ShImmVal = RHS->getZExtValue() & 31;
650 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
657 bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue Op, SDValue N,
658 SDValue &Base, SDValue &OffImm) {
659 // Match simple R + imm12 operands.
662 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
663 if (N.getOpcode() == ISD::FrameIndex) {
664 // Match frame index...
665 int FI = cast<FrameIndexSDNode>(N)->getIndex();
666 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
667 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
669 } else if (N.getOpcode() == ARMISD::Wrapper) {
670 Base = N.getOperand(0);
671 if (Base.getOpcode() == ISD::TargetConstantPool)
672 return false; // We want to select t2LDRpci instead.
675 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
679 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
680 if (SelectT2AddrModeImm8(Op, N, Base, OffImm))
681 // Let t2LDRi8 handle (R - imm8).
684 int RHSC = (int)RHS->getZExtValue();
685 if (N.getOpcode() == ISD::SUB)
688 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
689 Base = N.getOperand(0);
690 if (Base.getOpcode() == ISD::FrameIndex) {
691 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
692 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
694 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
701 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
705 bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue Op, SDValue N,
706 SDValue &Base, SDValue &OffImm) {
707 // Match simple R - imm8 operands.
708 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
709 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
710 int RHSC = (int)RHS->getSExtValue();
711 if (N.getOpcode() == ISD::SUB)
714 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
715 Base = N.getOperand(0);
716 if (Base.getOpcode() == ISD::FrameIndex) {
717 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
718 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
720 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
729 bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDValue Op, SDValue N,
731 unsigned Opcode = Op.getOpcode();
732 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
733 ? cast<LoadSDNode>(Op)->getAddressingMode()
734 : cast<StoreSDNode>(Op)->getAddressingMode();
735 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
736 int RHSC = (int)RHS->getZExtValue();
737 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
738 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
739 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
740 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
748 bool ARMDAGToDAGISel::SelectT2AddrModeImm8s4(SDValue Op, SDValue N,
749 SDValue &Base, SDValue &OffImm) {
750 if (N.getOpcode() == ISD::ADD) {
751 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
752 int RHSC = (int)RHS->getZExtValue();
753 if (((RHSC & 0x3) == 0) &&
754 ((RHSC >= 0 && RHSC < 0x400) || (RHSC < 0 && RHSC > -0x400))) { // 8 bits.
755 Base = N.getOperand(0);
756 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
760 } else if (N.getOpcode() == ISD::SUB) {
761 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
762 int RHSC = (int)RHS->getZExtValue();
763 if (((RHSC & 0x3) == 0) && (RHSC >= 0 && RHSC < 0x400)) { // 8 bits.
764 Base = N.getOperand(0);
765 OffImm = CurDAG->getTargetConstant(-RHSC, MVT::i32);
774 bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue Op, SDValue N,
776 SDValue &OffReg, SDValue &ShImm) {
777 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
778 if (N.getOpcode() != ISD::ADD)
781 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
782 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
783 int RHSC = (int)RHS->getZExtValue();
784 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
786 else if (RHSC < 0 && RHSC >= -255) // 8 bits
790 // Look for (R + R) or (R + (R << [1,2,3])).
792 Base = N.getOperand(0);
793 OffReg = N.getOperand(1);
795 // Swap if it is ((R << c) + R).
796 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
797 if (ShOpcVal != ARM_AM::lsl) {
798 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
799 if (ShOpcVal == ARM_AM::lsl)
800 std::swap(Base, OffReg);
803 if (ShOpcVal == ARM_AM::lsl) {
804 // Check to see if the RHS of the shift is a constant, if not, we can't fold
806 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
807 ShAmt = Sh->getZExtValue();
810 ShOpcVal = ARM_AM::no_shift;
812 OffReg = OffReg.getOperand(0);
814 ShOpcVal = ARM_AM::no_shift;
818 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
823 //===--------------------------------------------------------------------===//
825 /// getAL - Returns a ARMCC::AL immediate node.
826 static inline SDValue getAL(SelectionDAG *CurDAG) {
827 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
830 SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDValue Op) {
831 LoadSDNode *LD = cast<LoadSDNode>(Op);
832 ISD::MemIndexedMode AM = LD->getAddressingMode();
833 if (AM == ISD::UNINDEXED)
836 EVT LoadedVT = LD->getMemoryVT();
837 SDValue Offset, AMOpc;
838 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
841 if (LoadedVT == MVT::i32 &&
842 SelectAddrMode2Offset(Op, LD->getOffset(), Offset, AMOpc)) {
843 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
845 } else if (LoadedVT == MVT::i16 &&
846 SelectAddrMode3Offset(Op, LD->getOffset(), Offset, AMOpc)) {
848 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
849 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
850 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
851 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
852 if (LD->getExtensionType() == ISD::SEXTLOAD) {
853 if (SelectAddrMode3Offset(Op, LD->getOffset(), Offset, AMOpc)) {
855 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
858 if (SelectAddrMode2Offset(Op, LD->getOffset(), Offset, AMOpc)) {
860 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
866 SDValue Chain = LD->getChain();
867 SDValue Base = LD->getBasePtr();
868 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
869 CurDAG->getRegister(0, MVT::i32), Chain };
870 return CurDAG->getMachineNode(Opcode, Op.getDebugLoc(), MVT::i32, MVT::i32,
877 SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDValue Op) {
878 LoadSDNode *LD = cast<LoadSDNode>(Op);
879 ISD::MemIndexedMode AM = LD->getAddressingMode();
880 if (AM == ISD::UNINDEXED)
883 EVT LoadedVT = LD->getMemoryVT();
884 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
886 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
889 if (SelectT2AddrModeImm8Offset(Op, LD->getOffset(), Offset)) {
890 switch (LoadedVT.getSimpleVT().SimpleTy) {
892 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
896 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
898 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
903 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
905 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
914 SDValue Chain = LD->getChain();
915 SDValue Base = LD->getBasePtr();
916 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
917 CurDAG->getRegister(0, MVT::i32), Chain };
918 return CurDAG->getMachineNode(Opcode, Op.getDebugLoc(), MVT::i32, MVT::i32,
925 SDNode *ARMDAGToDAGISel::SelectDYN_ALLOC(SDValue Op) {
926 SDNode *N = Op.getNode();
927 DebugLoc dl = N->getDebugLoc();
928 EVT VT = Op.getValueType();
929 SDValue Chain = Op.getOperand(0);
930 SDValue Size = Op.getOperand(1);
931 SDValue Align = Op.getOperand(2);
932 SDValue SP = CurDAG->getRegister(ARM::SP, MVT::i32);
933 int32_t AlignVal = cast<ConstantSDNode>(Align)->getSExtValue();
935 // We need to align the stack. Use Thumb1 tAND which is the only thumb
936 // instruction that can read and write SP. This matches to a pseudo
937 // instruction that has a chain to ensure the result is written back to
938 // the stack pointer.
939 SP = SDValue(CurDAG->getMachineNode(ARM::tANDsp, dl, VT, SP, Align), 0);
941 bool isC = isa<ConstantSDNode>(Size);
942 uint32_t C = isC ? cast<ConstantSDNode>(Size)->getZExtValue() : ~0UL;
943 // Handle the most common case for both Thumb1 and Thumb2:
944 // tSUBspi - immediate is between 0 ... 508 inclusive.
945 if (C <= 508 && ((C & 3) == 0))
946 // FIXME: tSUBspi encode scale 4 implicitly.
947 return CurDAG->SelectNodeTo(N, ARM::tSUBspi_, VT, MVT::Other, SP,
948 CurDAG->getTargetConstant(C/4, MVT::i32),
951 if (Subtarget->isThumb1Only()) {
952 // Use tADDspr since Thumb1 does not have a sub r, sp, r. ARMISelLowering
953 // should have negated the size operand already. FIXME: We can't insert
954 // new target independent node at this stage so we are forced to negate
955 // it earlier. Is there a better solution?
956 return CurDAG->SelectNodeTo(N, ARM::tADDspr_, VT, MVT::Other, SP, Size,
958 } else if (Subtarget->isThumb2()) {
959 if (isC && Predicate_t2_so_imm(Size.getNode())) {
961 SDValue Ops[] = { SP, CurDAG->getTargetConstant(C, MVT::i32), Chain };
962 return CurDAG->SelectNodeTo(N, ARM::t2SUBrSPi_, VT, MVT::Other, Ops, 3);
963 } else if (isC && Predicate_imm0_4095(Size.getNode())) {
965 SDValue Ops[] = { SP, CurDAG->getTargetConstant(C, MVT::i32), Chain };
966 return CurDAG->SelectNodeTo(N, ARM::t2SUBrSPi12_, VT, MVT::Other, Ops, 3);
969 SDValue Ops[] = { SP, Size,
970 getI32Imm(ARM_AM::getSORegOpc(ARM_AM::lsl,0)), Chain };
971 return CurDAG->SelectNodeTo(N, ARM::t2SUBrSPs_, VT, MVT::Other, Ops, 4);
975 // FIXME: Add ADD / SUB sp instructions for ARM.
979 /// PairDRegs - Insert a pair of double registers into an implicit def to
980 /// form a quad register.
981 SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
982 DebugLoc dl = V0.getNode()->getDebugLoc();
984 SDValue(CurDAG->getMachineNode(TargetInstrInfo::IMPLICIT_DEF, dl, VT), 0);
985 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
986 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
987 SDNode *Pair = CurDAG->getMachineNode(TargetInstrInfo::INSERT_SUBREG, dl,
988 VT, Undef, V0, SubReg0);
989 return CurDAG->getMachineNode(TargetInstrInfo::INSERT_SUBREG, dl,
990 VT, SDValue(Pair, 0), V1, SubReg1);
993 /// GetNEONSubregVT - Given a type for a 128-bit NEON vector, return the type
994 /// for a 64-bit subregister of the vector.
995 static EVT GetNEONSubregVT(EVT VT) {
996 switch (VT.getSimpleVT().SimpleTy) {
997 default: llvm_unreachable("unhandled NEON type");
998 case MVT::v16i8: return MVT::v8i8;
999 case MVT::v8i16: return MVT::v4i16;
1000 case MVT::v4f32: return MVT::v2f32;
1001 case MVT::v4i32: return MVT::v2i32;
1002 case MVT::v2i64: return MVT::v1i64;
1006 SDNode *ARMDAGToDAGISel::SelectVLD(SDValue Op, unsigned NumVecs,
1007 unsigned *DOpcodes, unsigned *QOpcodes0,
1008 unsigned *QOpcodes1) {
1009 assert(NumVecs >=2 && NumVecs <= 4 && "VLD NumVecs out-of-range");
1010 SDNode *N = Op.getNode();
1011 DebugLoc dl = N->getDebugLoc();
1013 SDValue MemAddr, MemUpdate, MemOpc;
1014 if (!SelectAddrMode6(Op, N->getOperand(2), MemAddr, MemUpdate, MemOpc))
1017 SDValue Chain = N->getOperand(0);
1018 EVT VT = N->getValueType(0);
1019 bool is64BitVector = VT.is64BitVector();
1021 unsigned OpcodeIndex;
1022 switch (VT.getSimpleVT().SimpleTy) {
1023 default: llvm_unreachable("unhandled vld type");
1024 // Double-register operations:
1025 case MVT::v8i8: OpcodeIndex = 0; break;
1026 case MVT::v4i16: OpcodeIndex = 1; break;
1028 case MVT::v2i32: OpcodeIndex = 2; break;
1029 case MVT::v1i64: OpcodeIndex = 3; break;
1030 // Quad-register operations:
1031 case MVT::v16i8: OpcodeIndex = 0; break;
1032 case MVT::v8i16: OpcodeIndex = 1; break;
1034 case MVT::v4i32: OpcodeIndex = 2; break;
1037 if (is64BitVector) {
1038 unsigned Opc = DOpcodes[OpcodeIndex];
1039 const SDValue Ops[] = { MemAddr, MemUpdate, MemOpc, Chain };
1040 std::vector<EVT> ResTys(NumVecs, VT);
1041 ResTys.push_back(MVT::Other);
1042 return CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 4);
1045 EVT RegVT = GetNEONSubregVT(VT);
1047 // Quad registers are directly supported for VLD2,
1048 // loading 2 pairs of D regs.
1049 unsigned Opc = QOpcodes0[OpcodeIndex];
1050 const SDValue Ops[] = { MemAddr, MemUpdate, MemOpc, Chain };
1051 std::vector<EVT> ResTys(4, VT);
1052 ResTys.push_back(MVT::Other);
1053 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 4);
1054 Chain = SDValue(VLd, 4);
1056 // Combine the even and odd subregs to produce the result.
1057 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1058 SDNode *Q = PairDRegs(VT, SDValue(VLd, 2*Vec), SDValue(VLd, 2*Vec+1));
1059 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1062 // Otherwise, quad registers are loaded with two separate instructions,
1063 // where one loads the even registers and the other loads the odd registers.
1065 // Enable writeback to the address register.
1066 MemOpc = CurDAG->getTargetConstant(ARM_AM::getAM6Opc(true), MVT::i32);
1068 std::vector<EVT> ResTys(NumVecs, RegVT);
1069 ResTys.push_back(MemAddr.getValueType());
1070 ResTys.push_back(MVT::Other);
1072 // Load the even subregs.
1073 unsigned Opc = QOpcodes0[OpcodeIndex];
1074 const SDValue OpsA[] = { MemAddr, MemUpdate, MemOpc, Chain };
1075 SDNode *VLdA = CurDAG->getMachineNode(Opc, dl, ResTys, OpsA, 4);
1076 Chain = SDValue(VLdA, NumVecs+1);
1078 // Load the odd subregs.
1079 Opc = QOpcodes1[OpcodeIndex];
1080 const SDValue OpsB[] = { SDValue(VLdA, NumVecs), MemUpdate, MemOpc, Chain };
1081 SDNode *VLdB = CurDAG->getMachineNode(Opc, dl, ResTys, OpsB, 4);
1082 Chain = SDValue(VLdB, NumVecs+1);
1084 // Combine the even and odd subregs to produce the result.
1085 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1086 SDNode *Q = PairDRegs(VT, SDValue(VLdA, Vec), SDValue(VLdB, Vec));
1087 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1090 ReplaceUses(SDValue(N, NumVecs), Chain);
1094 SDNode *ARMDAGToDAGISel::SelectVST(SDValue Op, unsigned NumVecs,
1095 unsigned *DOpcodes, unsigned *QOpcodes0,
1096 unsigned *QOpcodes1) {
1097 assert(NumVecs >=2 && NumVecs <= 4 && "VST NumVecs out-of-range");
1098 SDNode *N = Op.getNode();
1099 DebugLoc dl = N->getDebugLoc();
1101 SDValue MemAddr, MemUpdate, MemOpc;
1102 if (!SelectAddrMode6(Op, N->getOperand(2), MemAddr, MemUpdate, MemOpc))
1105 SDValue Chain = N->getOperand(0);
1106 EVT VT = N->getOperand(3).getValueType();
1107 bool is64BitVector = VT.is64BitVector();
1109 unsigned OpcodeIndex;
1110 switch (VT.getSimpleVT().SimpleTy) {
1111 default: llvm_unreachable("unhandled vst type");
1112 // Double-register operations:
1113 case MVT::v8i8: OpcodeIndex = 0; break;
1114 case MVT::v4i16: OpcodeIndex = 1; break;
1116 case MVT::v2i32: OpcodeIndex = 2; break;
1117 case MVT::v1i64: OpcodeIndex = 3; break;
1118 // Quad-register operations:
1119 case MVT::v16i8: OpcodeIndex = 0; break;
1120 case MVT::v8i16: OpcodeIndex = 1; break;
1122 case MVT::v4i32: OpcodeIndex = 2; break;
1125 SmallVector<SDValue, 8> Ops;
1126 Ops.push_back(MemAddr);
1127 Ops.push_back(MemUpdate);
1128 Ops.push_back(MemOpc);
1130 if (is64BitVector) {
1131 unsigned Opc = DOpcodes[OpcodeIndex];
1132 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1133 Ops.push_back(N->getOperand(Vec+3));
1134 Ops.push_back(Chain);
1135 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+4);
1138 EVT RegVT = GetNEONSubregVT(VT);
1140 // Quad registers are directly supported for VST2,
1141 // storing 2 pairs of D regs.
1142 unsigned Opc = QOpcodes0[OpcodeIndex];
1143 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1144 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1145 N->getOperand(Vec+3)));
1146 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
1147 N->getOperand(Vec+3)));
1149 Ops.push_back(Chain);
1150 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 8);
1153 // Otherwise, quad registers are stored with two separate instructions,
1154 // where one stores the even registers and the other stores the odd registers.
1156 // Enable writeback to the address register.
1157 MemOpc = CurDAG->getTargetConstant(ARM_AM::getAM6Opc(true), MVT::i32);
1159 // Store the even subregs.
1160 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1161 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1162 N->getOperand(Vec+3)));
1163 Ops.push_back(Chain);
1164 unsigned Opc = QOpcodes0[OpcodeIndex];
1165 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1166 MVT::Other, Ops.data(), NumVecs+4);
1167 Chain = SDValue(VStA, 1);
1169 // Store the odd subregs.
1170 Ops[0] = SDValue(VStA, 0); // MemAddr
1171 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1172 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
1173 N->getOperand(Vec+3));
1174 Ops[NumVecs+3] = Chain;
1175 Opc = QOpcodes1[OpcodeIndex];
1176 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1177 MVT::Other, Ops.data(), NumVecs+4);
1178 Chain = SDValue(VStB, 1);
1179 ReplaceUses(SDValue(N, 0), Chain);
1183 SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDValue Op, bool IsLoad,
1184 unsigned NumVecs, unsigned *DOpcodes,
1185 unsigned *QOpcodes0,
1186 unsigned *QOpcodes1) {
1187 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
1188 SDNode *N = Op.getNode();
1189 DebugLoc dl = N->getDebugLoc();
1191 SDValue MemAddr, MemUpdate, MemOpc;
1192 if (!SelectAddrMode6(Op, N->getOperand(2), MemAddr, MemUpdate, MemOpc))
1195 SDValue Chain = N->getOperand(0);
1197 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
1198 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
1199 bool is64BitVector = VT.is64BitVector();
1201 // Quad registers are handled by load/store of subregs. Find the subreg info.
1202 unsigned NumElts = 0;
1205 if (!is64BitVector) {
1206 RegVT = GetNEONSubregVT(VT);
1207 NumElts = RegVT.getVectorNumElements();
1208 SubregIdx = (Lane < NumElts) ? ARM::DSUBREG_0 : ARM::DSUBREG_1;
1211 unsigned OpcodeIndex;
1212 switch (VT.getSimpleVT().SimpleTy) {
1213 default: llvm_unreachable("unhandled vld/vst lane type");
1214 // Double-register operations:
1215 case MVT::v8i8: OpcodeIndex = 0; break;
1216 case MVT::v4i16: OpcodeIndex = 1; break;
1218 case MVT::v2i32: OpcodeIndex = 2; break;
1219 // Quad-register operations:
1220 case MVT::v8i16: OpcodeIndex = 0; break;
1222 case MVT::v4i32: OpcodeIndex = 1; break;
1225 SmallVector<SDValue, 9> Ops;
1226 Ops.push_back(MemAddr);
1227 Ops.push_back(MemUpdate);
1228 Ops.push_back(MemOpc);
1231 if (is64BitVector) {
1232 Opc = DOpcodes[OpcodeIndex];
1233 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1234 Ops.push_back(N->getOperand(Vec+3));
1236 // Check if this is loading the even or odd subreg of a Q register.
1237 if (Lane < NumElts) {
1238 Opc = QOpcodes0[OpcodeIndex];
1241 Opc = QOpcodes1[OpcodeIndex];
1243 // Extract the subregs of the input vector.
1244 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1245 Ops.push_back(CurDAG->getTargetExtractSubreg(SubregIdx, dl, RegVT,
1246 N->getOperand(Vec+3)));
1248 Ops.push_back(getI32Imm(Lane));
1249 Ops.push_back(Chain);
1252 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+5);
1254 std::vector<EVT> ResTys(NumVecs, RegVT);
1255 ResTys.push_back(MVT::Other);
1257 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), NumVecs+5);
1258 // For a 64-bit vector load to D registers, nothing more needs to be done.
1262 // For 128-bit vectors, take the 64-bit results of the load and insert them
1263 // as subregs into the result.
1264 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1265 SDValue QuadVec = CurDAG->getTargetInsertSubreg(SubregIdx, dl, VT,
1266 N->getOperand(Vec+3),
1267 SDValue(VLdLn, Vec));
1268 ReplaceUses(SDValue(N, Vec), QuadVec);
1271 Chain = SDValue(VLdLn, NumVecs);
1272 ReplaceUses(SDValue(N, NumVecs), Chain);
1276 SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDValue Op,
1278 if (!Subtarget->hasV6T2Ops())
1281 unsigned Shl_imm = 0;
1282 if (isOpcWithIntImmediate(Op.getOperand(0).getNode(), ISD::SHL, Shl_imm)){
1283 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1284 unsigned Srl_imm = 0;
1285 if (isInt32Immediate(Op.getOperand(1), Srl_imm)) {
1286 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1287 unsigned Width = 32 - Srl_imm;
1288 int LSB = Srl_imm - Shl_imm;
1291 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1292 SDValue Ops[] = { Op.getOperand(0).getOperand(0),
1293 CurDAG->getTargetConstant(LSB, MVT::i32),
1294 CurDAG->getTargetConstant(Width, MVT::i32),
1295 getAL(CurDAG), Reg0 };
1296 return CurDAG->SelectNodeTo(Op.getNode(), Opc, MVT::i32, Ops, 5);
1302 SDNode *ARMDAGToDAGISel::Select(SDValue Op) {
1303 SDNode *N = Op.getNode();
1304 DebugLoc dl = N->getDebugLoc();
1306 if (N->isMachineOpcode())
1307 return NULL; // Already selected.
1309 switch (N->getOpcode()) {
1311 case ISD::Constant: {
1312 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
1314 if (Subtarget->hasThumb2())
1315 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1316 // be done with MOV + MOVT, at worst.
1319 if (Subtarget->isThumb()) {
1320 UseCP = (Val > 255 && // MOV
1321 ~Val > 255 && // MOV + MVN
1322 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
1324 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1325 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1326 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1331 CurDAG->getTargetConstantPool(ConstantInt::get(
1332 Type::getInt32Ty(*CurDAG->getContext()), Val),
1333 TLI.getPointerTy());
1336 if (Subtarget->isThumb1Only()) {
1337 SDValue Pred = CurDAG->getTargetConstant(0xEULL, MVT::i32);
1338 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1339 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
1340 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1345 CurDAG->getRegister(0, MVT::i32),
1346 CurDAG->getTargetConstant(0, MVT::i32),
1348 CurDAG->getRegister(0, MVT::i32),
1349 CurDAG->getEntryNode()
1351 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1354 ReplaceUses(Op, SDValue(ResNode, 0));
1358 // Other cases are autogenerated.
1361 case ISD::FrameIndex: {
1362 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
1363 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1364 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1365 if (Subtarget->isThumb1Only()) {
1366 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1367 CurDAG->getTargetConstant(0, MVT::i32));
1369 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1370 ARM::t2ADDri : ARM::ADDri);
1371 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1372 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1373 CurDAG->getRegister(0, MVT::i32) };
1374 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1377 case ARMISD::DYN_ALLOC:
1378 return SelectDYN_ALLOC(Op);
1380 if (SDNode *I = SelectV6T2BitfieldExtractOp(Op,
1381 Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX))
1385 if (SDNode *I = SelectV6T2BitfieldExtractOp(Op,
1386 Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX))
1390 if (Subtarget->isThumb1Only())
1392 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op.getOperand(1))) {
1393 unsigned RHSV = C->getZExtValue();
1395 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
1396 unsigned ShImm = Log2_32(RHSV-1);
1399 SDValue V = Op.getOperand(0);
1400 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
1401 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1402 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1403 if (Subtarget->isThumb()) {
1404 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1405 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
1407 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1408 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
1411 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
1412 unsigned ShImm = Log2_32(RHSV+1);
1415 SDValue V = Op.getOperand(0);
1416 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
1417 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1418 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1419 if (Subtarget->isThumb()) {
1420 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0 };
1421 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 5);
1423 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1424 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
1430 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1431 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1432 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1433 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1434 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
1435 EVT VT = Op.getValueType();
1438 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1440 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1443 SDValue N0 = Op.getOperand(0), N1 = Op.getOperand(1);
1444 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1447 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1448 SDValue N2 = N0.getOperand(1);
1449 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1452 unsigned N1CVal = N1C->getZExtValue();
1453 unsigned N2CVal = N2C->getZExtValue();
1454 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1455 (N1CVal & 0xffffU) == 0xffffU &&
1456 (N2CVal & 0xffffU) == 0x0U) {
1457 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1459 SDValue Ops[] = { N0.getOperand(0), Imm16,
1460 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1461 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
1467 return CurDAG->getMachineNode(ARM::FMRRD, dl, MVT::i32, MVT::i32,
1468 Op.getOperand(0), getAL(CurDAG),
1469 CurDAG->getRegister(0, MVT::i32));
1470 case ISD::UMUL_LOHI: {
1471 if (Subtarget->isThumb1Only())
1473 if (Subtarget->isThumb()) {
1474 SDValue Ops[] = { Op.getOperand(0), Op.getOperand(1),
1475 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1476 CurDAG->getRegister(0, MVT::i32) };
1477 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32, Ops,4);
1479 SDValue Ops[] = { Op.getOperand(0), Op.getOperand(1),
1480 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1481 CurDAG->getRegister(0, MVT::i32) };
1482 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
1485 case ISD::SMUL_LOHI: {
1486 if (Subtarget->isThumb1Only())
1488 if (Subtarget->isThumb()) {
1489 SDValue Ops[] = { Op.getOperand(0), Op.getOperand(1),
1490 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1491 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32, Ops,4);
1493 SDValue Ops[] = { Op.getOperand(0), Op.getOperand(1),
1494 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1495 CurDAG->getRegister(0, MVT::i32) };
1496 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
1500 SDNode *ResNode = 0;
1501 if (Subtarget->isThumb() && Subtarget->hasThumb2())
1502 ResNode = SelectT2IndexedLoad(Op);
1504 ResNode = SelectARMIndexedLoad(Op);
1507 // Other cases are autogenerated.
1510 case ARMISD::BRCOND: {
1511 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1512 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1513 // Pattern complexity = 6 cost = 1 size = 0
1515 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1516 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
1517 // Pattern complexity = 6 cost = 1 size = 0
1519 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1520 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1521 // Pattern complexity = 6 cost = 1 size = 0
1523 unsigned Opc = Subtarget->isThumb() ?
1524 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
1525 SDValue Chain = Op.getOperand(0);
1526 SDValue N1 = Op.getOperand(1);
1527 SDValue N2 = Op.getOperand(2);
1528 SDValue N3 = Op.getOperand(3);
1529 SDValue InFlag = Op.getOperand(4);
1530 assert(N1.getOpcode() == ISD::BasicBlock);
1531 assert(N2.getOpcode() == ISD::Constant);
1532 assert(N3.getOpcode() == ISD::Register);
1534 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
1535 cast<ConstantSDNode>(N2)->getZExtValue()),
1537 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
1538 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
1540 Chain = SDValue(ResNode, 0);
1541 if (Op.getNode()->getNumValues() == 2) {
1542 InFlag = SDValue(ResNode, 1);
1543 ReplaceUses(SDValue(Op.getNode(), 1), InFlag);
1545 ReplaceUses(SDValue(Op.getNode(), 0), SDValue(Chain.getNode(), Chain.getResNo()));
1548 case ARMISD::CMOV: {
1549 EVT VT = Op.getValueType();
1550 SDValue N0 = Op.getOperand(0);
1551 SDValue N1 = Op.getOperand(1);
1552 SDValue N2 = Op.getOperand(2);
1553 SDValue N3 = Op.getOperand(3);
1554 SDValue InFlag = Op.getOperand(4);
1555 assert(N2.getOpcode() == ISD::Constant);
1556 assert(N3.getOpcode() == ISD::Register);
1558 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1559 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1560 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1561 // Pattern complexity = 18 cost = 1 size = 0
1565 if (Subtarget->isThumb()) {
1566 if (SelectT2ShifterOperandReg(Op, N1, CPTmp0, CPTmp1)) {
1567 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1568 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1571 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1572 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1573 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1574 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1576 llvm_unreachable("Unknown so_reg opcode!");
1580 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1581 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
1582 cast<ConstantSDNode>(N2)->getZExtValue()),
1584 SDValue Ops[] = { N0, CPTmp0, SOShImm, Tmp2, N3, InFlag };
1585 return CurDAG->SelectNodeTo(Op.getNode(), Opc, MVT::i32,Ops, 6);
1588 if (SelectShifterOperandReg(Op, N1, CPTmp0, CPTmp1, CPTmp2)) {
1589 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
1590 cast<ConstantSDNode>(N2)->getZExtValue()),
1592 SDValue Ops[] = { N0, CPTmp0, CPTmp1, CPTmp2, Tmp2, N3, InFlag };
1593 return CurDAG->SelectNodeTo(Op.getNode(),
1594 ARM::MOVCCs, MVT::i32, Ops, 7);
1598 // Pattern: (ARMcmov:i32 GPR:i32:$false,
1599 // (imm:i32)<<P:Predicate_so_imm>>:$true,
1601 // Emits: (MOVCCi:i32 GPR:i32:$false,
1602 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1603 // Pattern complexity = 10 cost = 1 size = 0
1604 if (N3.getOpcode() == ISD::Constant) {
1605 if (Subtarget->isThumb()) {
1606 if (Predicate_t2_so_imm(N3.getNode())) {
1607 SDValue Tmp1 = CurDAG->getTargetConstant(((unsigned)
1608 cast<ConstantSDNode>(N1)->getZExtValue()),
1610 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
1611 cast<ConstantSDNode>(N2)->getZExtValue()),
1613 SDValue Ops[] = { N0, Tmp1, Tmp2, N3, InFlag };
1614 return CurDAG->SelectNodeTo(Op.getNode(),
1615 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1618 if (Predicate_so_imm(N3.getNode())) {
1619 SDValue Tmp1 = CurDAG->getTargetConstant(((unsigned)
1620 cast<ConstantSDNode>(N1)->getZExtValue()),
1622 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
1623 cast<ConstantSDNode>(N2)->getZExtValue()),
1625 SDValue Ops[] = { N0, Tmp1, Tmp2, N3, InFlag };
1626 return CurDAG->SelectNodeTo(Op.getNode(),
1627 ARM::MOVCCi, MVT::i32, Ops, 5);
1633 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1634 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1635 // Pattern complexity = 6 cost = 1 size = 0
1637 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1638 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1639 // Pattern complexity = 6 cost = 11 size = 0
1641 // Also FCPYScc and FCPYDcc.
1642 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
1643 cast<ConstantSDNode>(N2)->getZExtValue()),
1645 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
1647 switch (VT.getSimpleVT().SimpleTy) {
1648 default: assert(false && "Illegal conditional move type!");
1651 Opc = Subtarget->isThumb()
1652 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1662 return CurDAG->SelectNodeTo(Op.getNode(), Opc, VT, Ops, 5);
1664 case ARMISD::CNEG: {
1665 EVT VT = Op.getValueType();
1666 SDValue N0 = Op.getOperand(0);
1667 SDValue N1 = Op.getOperand(1);
1668 SDValue N2 = Op.getOperand(2);
1669 SDValue N3 = Op.getOperand(3);
1670 SDValue InFlag = Op.getOperand(4);
1671 assert(N2.getOpcode() == ISD::Constant);
1672 assert(N3.getOpcode() == ISD::Register);
1674 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
1675 cast<ConstantSDNode>(N2)->getZExtValue()),
1677 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
1679 switch (VT.getSimpleVT().SimpleTy) {
1680 default: assert(false && "Illegal conditional move type!");
1689 return CurDAG->SelectNodeTo(Op.getNode(), Opc, VT, Ops, 5);
1692 case ARMISD::VZIP: {
1694 EVT VT = N->getValueType(0);
1695 switch (VT.getSimpleVT().SimpleTy) {
1696 default: return NULL;
1697 case MVT::v8i8: Opc = ARM::VZIPd8; break;
1698 case MVT::v4i16: Opc = ARM::VZIPd16; break;
1700 case MVT::v2i32: Opc = ARM::VZIPd32; break;
1701 case MVT::v16i8: Opc = ARM::VZIPq8; break;
1702 case MVT::v8i16: Opc = ARM::VZIPq16; break;
1704 case MVT::v4i32: Opc = ARM::VZIPq32; break;
1706 return CurDAG->getMachineNode(Opc, dl, VT, VT,
1707 N->getOperand(0), N->getOperand(1));
1709 case ARMISD::VUZP: {
1711 EVT VT = N->getValueType(0);
1712 switch (VT.getSimpleVT().SimpleTy) {
1713 default: return NULL;
1714 case MVT::v8i8: Opc = ARM::VUZPd8; break;
1715 case MVT::v4i16: Opc = ARM::VUZPd16; break;
1717 case MVT::v2i32: Opc = ARM::VUZPd32; break;
1718 case MVT::v16i8: Opc = ARM::VUZPq8; break;
1719 case MVT::v8i16: Opc = ARM::VUZPq16; break;
1721 case MVT::v4i32: Opc = ARM::VUZPq32; break;
1723 return CurDAG->getMachineNode(Opc, dl, VT, VT,
1724 N->getOperand(0), N->getOperand(1));
1726 case ARMISD::VTRN: {
1728 EVT VT = N->getValueType(0);
1729 switch (VT.getSimpleVT().SimpleTy) {
1730 default: return NULL;
1731 case MVT::v8i8: Opc = ARM::VTRNd8; break;
1732 case MVT::v4i16: Opc = ARM::VTRNd16; break;
1734 case MVT::v2i32: Opc = ARM::VTRNd32; break;
1735 case MVT::v16i8: Opc = ARM::VTRNq8; break;
1736 case MVT::v8i16: Opc = ARM::VTRNq16; break;
1738 case MVT::v4i32: Opc = ARM::VTRNq32; break;
1740 return CurDAG->getMachineNode(Opc, dl, VT, VT,
1741 N->getOperand(0), N->getOperand(1));
1744 case ISD::INTRINSIC_VOID:
1745 case ISD::INTRINSIC_W_CHAIN: {
1746 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
1751 case Intrinsic::arm_neon_vld2: {
1752 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
1753 ARM::VLD2d32, ARM::VLD2d64 };
1754 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
1755 return SelectVLD(Op, 2, DOpcodes, QOpcodes, 0);
1758 case Intrinsic::arm_neon_vld3: {
1759 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
1760 ARM::VLD3d32, ARM::VLD3d64 };
1761 unsigned QOpcodes0[] = { ARM::VLD3q8a, ARM::VLD3q16a, ARM::VLD3q32a };
1762 unsigned QOpcodes1[] = { ARM::VLD3q8b, ARM::VLD3q16b, ARM::VLD3q32b };
1763 return SelectVLD(Op, 3, DOpcodes, QOpcodes0, QOpcodes1);
1766 case Intrinsic::arm_neon_vld4: {
1767 unsigned DOpcodes[] = { ARM::VLD4d8, ARM::VLD4d16,
1768 ARM::VLD4d32, ARM::VLD4d64 };
1769 unsigned QOpcodes0[] = { ARM::VLD4q8a, ARM::VLD4q16a, ARM::VLD4q32a };
1770 unsigned QOpcodes1[] = { ARM::VLD4q8b, ARM::VLD4q16b, ARM::VLD4q32b };
1771 return SelectVLD(Op, 4, DOpcodes, QOpcodes0, QOpcodes1);
1774 case Intrinsic::arm_neon_vld2lane: {
1775 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
1776 unsigned QOpcodes0[] = { ARM::VLD2LNq16a, ARM::VLD2LNq32a };
1777 unsigned QOpcodes1[] = { ARM::VLD2LNq16b, ARM::VLD2LNq32b };
1778 return SelectVLDSTLane(Op, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
1781 case Intrinsic::arm_neon_vld3lane: {
1782 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
1783 unsigned QOpcodes0[] = { ARM::VLD3LNq16a, ARM::VLD3LNq32a };
1784 unsigned QOpcodes1[] = { ARM::VLD3LNq16b, ARM::VLD3LNq32b };
1785 return SelectVLDSTLane(Op, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
1788 case Intrinsic::arm_neon_vld4lane: {
1789 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
1790 unsigned QOpcodes0[] = { ARM::VLD4LNq16a, ARM::VLD4LNq32a };
1791 unsigned QOpcodes1[] = { ARM::VLD4LNq16b, ARM::VLD4LNq32b };
1792 return SelectVLDSTLane(Op, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
1795 case Intrinsic::arm_neon_vst2: {
1796 unsigned DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
1797 ARM::VST2d32, ARM::VST2d64 };
1798 unsigned QOpcodes[] = { ARM::VST2q8, ARM::VST2q16, ARM::VST2q32 };
1799 return SelectVST(Op, 2, DOpcodes, QOpcodes, 0);
1802 case Intrinsic::arm_neon_vst3: {
1803 unsigned DOpcodes[] = { ARM::VST3d8, ARM::VST3d16,
1804 ARM::VST3d32, ARM::VST3d64 };
1805 unsigned QOpcodes0[] = { ARM::VST3q8a, ARM::VST3q16a, ARM::VST3q32a };
1806 unsigned QOpcodes1[] = { ARM::VST3q8b, ARM::VST3q16b, ARM::VST3q32b };
1807 return SelectVST(Op, 3, DOpcodes, QOpcodes0, QOpcodes1);
1810 case Intrinsic::arm_neon_vst4: {
1811 unsigned DOpcodes[] = { ARM::VST4d8, ARM::VST4d16,
1812 ARM::VST4d32, ARM::VST4d64 };
1813 unsigned QOpcodes0[] = { ARM::VST4q8a, ARM::VST4q16a, ARM::VST4q32a };
1814 unsigned QOpcodes1[] = { ARM::VST4q8b, ARM::VST4q16b, ARM::VST4q32b };
1815 return SelectVST(Op, 4, DOpcodes, QOpcodes0, QOpcodes1);
1818 case Intrinsic::arm_neon_vst2lane: {
1819 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
1820 unsigned QOpcodes0[] = { ARM::VST2LNq16a, ARM::VST2LNq32a };
1821 unsigned QOpcodes1[] = { ARM::VST2LNq16b, ARM::VST2LNq32b };
1822 return SelectVLDSTLane(Op, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
1825 case Intrinsic::arm_neon_vst3lane: {
1826 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
1827 unsigned QOpcodes0[] = { ARM::VST3LNq16a, ARM::VST3LNq32a };
1828 unsigned QOpcodes1[] = { ARM::VST3LNq16b, ARM::VST3LNq32b };
1829 return SelectVLDSTLane(Op, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
1832 case Intrinsic::arm_neon_vst4lane: {
1833 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
1834 unsigned QOpcodes0[] = { ARM::VST4LNq16a, ARM::VST4LNq32a };
1835 unsigned QOpcodes1[] = { ARM::VST4LNq16b, ARM::VST4LNq32b };
1836 return SelectVLDSTLane(Op, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
1842 return SelectCode(Op);
1845 bool ARMDAGToDAGISel::
1846 SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
1847 std::vector<SDValue> &OutOps) {
1848 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
1849 // Require the address to be in a register. That is safe for all ARM
1850 // variants and it is hard to do anything much smarter without knowing
1851 // how the operand is used.
1852 OutOps.push_back(Op);
1856 /// createARMISelDag - This pass converts a legalized DAG into a
1857 /// ARM-specific DAG, ready for instruction scheduling.
1859 FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
1860 CodeGenOpt::Level OptLevel) {
1861 return new ARMDAGToDAGISel(TM, OptLevel);