blob: 4c49212f2ded9cfda9e97c7ba90b54111fd92291 [file] [log] [blame]
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001//===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the ARM target.
11//
12//===----------------------------------------------------------------------===//
13
14#include "ARM.h"
Evan Chenge5ad88e2008-12-10 21:54:21 +000015#include "ARMAddressingModes.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000016#include "ARMTargetMachine.h"
Rafael Espindola84b19be2006-07-16 01:02:57 +000017#include "llvm/CallingConv.h"
Evan Chenga8e29892007-01-19 07:51:42 +000018#include "llvm/Constants.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000019#include "llvm/DerivedTypes.h"
20#include "llvm/Function.h"
21#include "llvm/Intrinsics.h"
Owen Anderson9adc0ab2009-07-14 23:09:55 +000022#include "llvm/LLVMContext.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000023#include "llvm/CodeGen/MachineFrameInfo.h"
24#include "llvm/CodeGen/MachineFunction.h"
25#include "llvm/CodeGen/MachineInstrBuilder.h"
26#include "llvm/CodeGen/SelectionDAG.h"
27#include "llvm/CodeGen/SelectionDAGISel.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000028#include "llvm/Target/TargetLowering.h"
Chris Lattner72939122007-05-03 00:32:00 +000029#include "llvm/Target/TargetOptions.h"
Evan Cheng94cc6d32010-05-04 20:39:49 +000030#include "llvm/Support/CommandLine.h"
Chris Lattner3d62d782008-02-03 05:43:57 +000031#include "llvm/Support/Compiler.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000032#include "llvm/Support/Debug.h"
Torok Edwindac237e2009-07-08 20:53:28 +000033#include "llvm/Support/ErrorHandling.h"
34#include "llvm/Support/raw_ostream.h"
35
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000036using namespace llvm;
37
Evan Cheng94cc6d32010-05-04 20:39:49 +000038static cl::opt<bool>
39UseRegSeq("neon-reg-sequence", cl::Hidden,
40 cl::desc("Use reg_sequence to model ld / st of multiple neon regs"));
41
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000042//===--------------------------------------------------------------------===//
43/// ARMDAGToDAGISel - ARM specific code to select ARM machine
44/// instructions for SelectionDAG operations.
45///
46namespace {
47class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000048 ARMBaseTargetMachine &TM;
Evan Cheng3f7eb8e2008-09-18 07:24:33 +000049
Evan Chenga8e29892007-01-19 07:51:42 +000050 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
51 /// make the right decision when generating code for different targets.
52 const ARMSubtarget *Subtarget;
53
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000054public:
Bob Wilson522ce972009-09-28 14:30:20 +000055 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
56 CodeGenOpt::Level OptLevel)
57 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Chenga8e29892007-01-19 07:51:42 +000058 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000059 }
60
Evan Chenga8e29892007-01-19 07:51:42 +000061 virtual const char *getPassName() const {
62 return "ARM Instruction Selection";
Anton Korobeynikov52237112009-06-17 18:13:58 +000063 }
64
Bob Wilsonaf4a8912009-10-08 18:51:31 +000065 /// getI32Imm - Return a target constant of type i32 with the specified
66 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000067 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000068 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000069 }
70
Dan Gohmaneeb3a002010-01-05 01:24:18 +000071 SDNode *Select(SDNode *N);
Evan Cheng014bf212010-02-15 19:41:07 +000072
Dan Gohmaneeb3a002010-01-05 01:24:18 +000073 bool SelectShifterOperandReg(SDNode *Op, SDValue N, SDValue &A,
Evan Cheng055b0312009-06-29 07:51:04 +000074 SDValue &B, SDValue &C);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000075 bool SelectAddrMode2(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000076 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000077 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +000078 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000079 bool SelectAddrMode3(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000080 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000081 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +000082 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000083 bool SelectAddrMode4(SDNode *Op, SDValue N, SDValue &Addr,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +000084 SDValue &Mode);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000085 bool SelectAddrMode5(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000086 SDValue &Offset);
Bob Wilson226036e2010-03-20 22:13:40 +000087 bool SelectAddrMode6(SDNode *Op, SDValue N, SDValue &Addr, SDValue &Align);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000088
Dan Gohmaneeb3a002010-01-05 01:24:18 +000089 bool SelectAddrModePC(SDNode *Op, SDValue N, SDValue &Offset,
Bob Wilson8b024a52009-07-01 23:16:05 +000090 SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +000091
Dan Gohmaneeb3a002010-01-05 01:24:18 +000092 bool SelectThumbAddrModeRR(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000093 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000094 bool SelectThumbAddrModeRI5(SDNode *Op, SDValue N, unsigned Scale,
Dan Gohman475871a2008-07-27 21:46:04 +000095 SDValue &Base, SDValue &OffImm,
96 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000097 bool SelectThumbAddrModeS1(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000098 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000099 bool SelectThumbAddrModeS2(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000100 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000101 bool SelectThumbAddrModeS4(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000102 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000103 bool SelectThumbAddrModeSP(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000104 SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000105
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000106 bool SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000107 SDValue &BaseReg, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000108 bool SelectT2AddrModeImm12(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000109 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000110 bool SelectT2AddrModeImm8(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000111 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000112 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000113 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000114 bool SelectT2AddrModeImm8s4(SDNode *Op, SDValue N, SDValue &Base,
David Goodwin6647cea2009-06-30 22:50:01 +0000115 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000116 bool SelectT2AddrModeSoReg(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000117 SDValue &OffReg, SDValue &ShImm);
118
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000119 // Include the pieces autogenerated from the target description.
120#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000121
122private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000123 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
124 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000125 SDNode *SelectARMIndexedLoad(SDNode *N);
126 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000127
Bob Wilson621f1952010-03-23 05:25:43 +0000128 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
129 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000130 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000131 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000132 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000133 unsigned *QOpcodes0, unsigned *QOpcodes1);
134
Bob Wilson24f995d2009-10-14 18:32:29 +0000135 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000136 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000137 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000138 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000139 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000140 unsigned *QOpcodes0, unsigned *QOpcodes1);
141
Bob Wilson96493442009-10-14 16:46:45 +0000142 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000143 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson96493442009-10-14 16:46:45 +0000144 /// load/store of D registers and even subregs and odd subregs of Q registers.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000145 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
Bob Wilson96493442009-10-14 16:46:45 +0000146 unsigned *DOpcodes, unsigned *QOpcodes0,
147 unsigned *QOpcodes1);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000148
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000149 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000150 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000151
Evan Cheng07ba9062009-11-19 21:45:22 +0000152 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000153 SDNode *SelectCMOVOp(SDNode *N);
154 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000155 ARMCC::CondCodes CCVal, SDValue CCR,
156 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000157 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000158 ARMCC::CondCodes CCVal, SDValue CCR,
159 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000160 SDNode *SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000161 ARMCC::CondCodes CCVal, SDValue CCR,
162 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000163 SDNode *SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000164 ARMCC::CondCodes CCVal, SDValue CCR,
165 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000166
Evan Chengde8aa4e2010-05-05 18:28:36 +0000167 SDNode *SelectConcatVector(SDNode *N);
168
Evan Chengaf4550f2009-07-02 01:23:32 +0000169 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
170 /// inline asm expressions.
171 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
172 char ConstraintCode,
173 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000174
Evan Cheng603afbf2010-05-10 17:34:18 +0000175 /// PairDRegs - Form a quad register from a pair of D registers.
176 ///
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000177 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000178
179 /// PairDRegs - Form a quad register pair from a pair of Q registers.
180 ///
181 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
182
183 /// QuadDRegs - Form a quad register pair from a quad of D registers.
184 ///
185 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng5c6aba22010-05-14 18:54:59 +0000186
187 /// OctoDRegs - Form 8 consecutive D registers.
188 ///
189 SDNode *OctoDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3,
190 SDValue V4, SDValue V5, SDValue V6, SDValue V7);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000191};
Evan Chenga8e29892007-01-19 07:51:42 +0000192}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000193
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000194/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
195/// operand. If so Imm will receive the 32-bit value.
196static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
197 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
198 Imm = cast<ConstantSDNode>(N)->getZExtValue();
199 return true;
200 }
201 return false;
202}
203
204// isInt32Immediate - This method tests to see if a constant operand.
205// If so Imm will receive the 32 bit value.
206static bool isInt32Immediate(SDValue N, unsigned &Imm) {
207 return isInt32Immediate(N.getNode(), Imm);
208}
209
210// isOpcWithIntImmediate - This method tests to see if the node is a specific
211// opcode and that it has a immediate integer right operand.
212// If so Imm will receive the 32 bit value.
213static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
214 return N->getOpcode() == Opc &&
215 isInt32Immediate(N->getOperand(1).getNode(), Imm);
216}
217
218
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000219bool ARMDAGToDAGISel::SelectShifterOperandReg(SDNode *Op,
Evan Cheng055b0312009-06-29 07:51:04 +0000220 SDValue N,
221 SDValue &BaseReg,
222 SDValue &ShReg,
223 SDValue &Opc) {
224 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
225
226 // Don't match base register only case. That is matched to a separate
227 // lower complexity pattern with explicit register operand.
228 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000229
Evan Cheng055b0312009-06-29 07:51:04 +0000230 BaseReg = N.getOperand(0);
231 unsigned ShImmVal = 0;
232 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000233 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000234 ShImmVal = RHS->getZExtValue() & 31;
235 } else {
236 ShReg = N.getOperand(1);
237 }
238 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000239 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000240 return true;
241}
242
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000243bool ARMDAGToDAGISel::SelectAddrMode2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000244 SDValue &Base, SDValue &Offset,
245 SDValue &Opc) {
Evan Chenga13fd102007-03-13 21:05:54 +0000246 if (N.getOpcode() == ISD::MUL) {
247 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
248 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000249 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000250 if (RHSC & 1) {
251 RHSC = RHSC & ~1;
252 ARM_AM::AddrOpc AddSub = ARM_AM::add;
253 if (RHSC < 0) {
254 AddSub = ARM_AM::sub;
255 RHSC = - RHSC;
256 }
257 if (isPowerOf2_32(RHSC)) {
258 unsigned ShAmt = Log2_32(RHSC);
259 Base = Offset = N.getOperand(0);
260 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
261 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000262 MVT::i32);
Evan Chenga13fd102007-03-13 21:05:54 +0000263 return true;
264 }
265 }
266 }
267 }
268
Evan Chenga8e29892007-01-19 07:51:42 +0000269 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
270 Base = N;
271 if (N.getOpcode() == ISD::FrameIndex) {
272 int FI = cast<FrameIndexSDNode>(N)->getIndex();
273 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000274 } else if (N.getOpcode() == ARMISD::Wrapper &&
275 !(Subtarget->useMovt() &&
276 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000277 Base = N.getOperand(0);
278 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000279 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000280 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
281 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000282 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000283 return true;
284 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000285
Evan Chenga8e29892007-01-19 07:51:42 +0000286 // Match simple R +/- imm12 operands.
287 if (N.getOpcode() == ISD::ADD)
288 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000289 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000290 if ((RHSC >= 0 && RHSC < 0x1000) ||
291 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000292 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000293 if (Base.getOpcode() == ISD::FrameIndex) {
294 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
295 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
296 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000297 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000298
299 ARM_AM::AddrOpc AddSub = ARM_AM::add;
300 if (RHSC < 0) {
301 AddSub = ARM_AM::sub;
302 RHSC = - RHSC;
303 }
304 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000305 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000306 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000307 return true;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000308 }
Evan Chenga8e29892007-01-19 07:51:42 +0000309 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000310
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000311 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000312 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
313 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
314 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000315
Evan Chenga8e29892007-01-19 07:51:42 +0000316 Base = N.getOperand(0);
317 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000318
Evan Chenga8e29892007-01-19 07:51:42 +0000319 if (ShOpcVal != ARM_AM::no_shift) {
320 // Check to see if the RHS of the shift is a constant, if not, we can't fold
321 // it.
322 if (ConstantSDNode *Sh =
323 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000324 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000325 Offset = N.getOperand(1).getOperand(0);
326 } else {
327 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000328 }
329 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000330
Evan Chenga8e29892007-01-19 07:51:42 +0000331 // Try matching (R shl C) + (R).
332 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
333 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
334 if (ShOpcVal != ARM_AM::no_shift) {
335 // Check to see if the RHS of the shift is a constant, if not, we can't
336 // fold it.
337 if (ConstantSDNode *Sh =
338 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000339 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000340 Offset = N.getOperand(0).getOperand(0);
341 Base = N.getOperand(1);
342 } else {
343 ShOpcVal = ARM_AM::no_shift;
344 }
345 }
346 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000347
Evan Chenga8e29892007-01-19 07:51:42 +0000348 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000349 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000350 return true;
351}
352
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000353bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000354 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000355 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000356 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
357 ? cast<LoadSDNode>(Op)->getAddressingMode()
358 : cast<StoreSDNode>(Op)->getAddressingMode();
359 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
360 ? ARM_AM::add : ARM_AM::sub;
361 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000362 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000363 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000364 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000365 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
366 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000367 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000368 return true;
369 }
370 }
371
372 Offset = N;
373 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
374 unsigned ShAmt = 0;
375 if (ShOpcVal != ARM_AM::no_shift) {
376 // Check to see if the RHS of the shift is a constant, if not, we can't fold
377 // it.
378 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000379 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000380 Offset = N.getOperand(0);
381 } else {
382 ShOpcVal = ARM_AM::no_shift;
383 }
384 }
385
386 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000387 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000388 return true;
389}
390
Evan Chenga8e29892007-01-19 07:51:42 +0000391
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000392bool ARMDAGToDAGISel::SelectAddrMode3(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000393 SDValue &Base, SDValue &Offset,
394 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000395 if (N.getOpcode() == ISD::SUB) {
396 // X - C is canonicalize to X + -C, no need to handle it here.
397 Base = N.getOperand(0);
398 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000399 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000400 return true;
401 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000402
Evan Chenga8e29892007-01-19 07:51:42 +0000403 if (N.getOpcode() != ISD::ADD) {
404 Base = N;
405 if (N.getOpcode() == ISD::FrameIndex) {
406 int FI = cast<FrameIndexSDNode>(N)->getIndex();
407 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
408 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000409 Offset = CurDAG->getRegister(0, MVT::i32);
410 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000411 return true;
412 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000413
Evan Chenga8e29892007-01-19 07:51:42 +0000414 // If the RHS is +/- imm8, fold into addr mode.
415 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000416 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000417 if ((RHSC >= 0 && RHSC < 256) ||
418 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000419 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000420 if (Base.getOpcode() == ISD::FrameIndex) {
421 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
422 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
423 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000424 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000425
426 ARM_AM::AddrOpc AddSub = ARM_AM::add;
427 if (RHSC < 0) {
428 AddSub = ARM_AM::sub;
429 RHSC = - RHSC;
430 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000431 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000432 return true;
433 }
434 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000435
Evan Chenga8e29892007-01-19 07:51:42 +0000436 Base = N.getOperand(0);
437 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000438 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000439 return true;
440}
441
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000442bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000443 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000444 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000445 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
446 ? cast<LoadSDNode>(Op)->getAddressingMode()
447 : cast<StoreSDNode>(Op)->getAddressingMode();
448 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
449 ? ARM_AM::add : ARM_AM::sub;
450 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000451 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000452 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000453 Offset = CurDAG->getRegister(0, MVT::i32);
454 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000455 return true;
456 }
457 }
458
459 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000460 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000461 return true;
462}
463
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000464bool ARMDAGToDAGISel::SelectAddrMode4(SDNode *Op, SDValue N,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000465 SDValue &Addr, SDValue &Mode) {
466 Addr = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000467 Mode = CurDAG->getTargetConstant(0, MVT::i32);
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000468 return true;
469}
Evan Chenga8e29892007-01-19 07:51:42 +0000470
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000471bool ARMDAGToDAGISel::SelectAddrMode5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000472 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000473 if (N.getOpcode() != ISD::ADD) {
474 Base = N;
475 if (N.getOpcode() == ISD::FrameIndex) {
476 int FI = cast<FrameIndexSDNode>(N)->getIndex();
477 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000478 } else if (N.getOpcode() == ARMISD::Wrapper &&
479 !(Subtarget->useMovt() &&
480 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000481 Base = N.getOperand(0);
482 }
483 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000484 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000485 return true;
486 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000487
Evan Chenga8e29892007-01-19 07:51:42 +0000488 // If the RHS is +/- imm8, fold into addr mode.
489 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000490 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000491 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
492 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000493 if ((RHSC >= 0 && RHSC < 256) ||
494 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000495 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000496 if (Base.getOpcode() == ISD::FrameIndex) {
497 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
498 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
499 }
500
501 ARM_AM::AddrOpc AddSub = ARM_AM::add;
502 if (RHSC < 0) {
503 AddSub = ARM_AM::sub;
504 RHSC = - RHSC;
505 }
506 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000507 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000508 return true;
509 }
510 }
511 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000512
Evan Chenga8e29892007-01-19 07:51:42 +0000513 Base = N;
514 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000515 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000516 return true;
517}
518
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000519bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Op, SDValue N,
Bob Wilson226036e2010-03-20 22:13:40 +0000520 SDValue &Addr, SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000521 Addr = N;
Jim Grosbach8a5ec862009-11-07 21:25:39 +0000522 // Default to no alignment.
523 Align = CurDAG->getTargetConstant(0, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000524 return true;
525}
526
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000527bool ARMDAGToDAGISel::SelectAddrModePC(SDNode *Op, SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000528 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000529 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
530 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000531 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000532 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000533 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000534 return true;
535 }
536 return false;
537}
538
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000539bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000540 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000541 // FIXME dl should come from the parent load or store, not the address
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000542 DebugLoc dl = Op->getDebugLoc();
Evan Chengc38f2bc2007-01-23 22:59:13 +0000543 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000544 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
545 if (!NC || NC->getZExtValue() != 0)
546 return false;
547
548 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000549 return true;
550 }
551
Evan Chenga8e29892007-01-19 07:51:42 +0000552 Base = N.getOperand(0);
553 Offset = N.getOperand(1);
554 return true;
555}
556
Evan Cheng79d43262007-01-24 02:21:22 +0000557bool
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000558ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000559 unsigned Scale, SDValue &Base,
560 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000561 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000562 SDValue TmpBase, TmpOffImm;
Evan Cheng79d43262007-01-24 02:21:22 +0000563 if (SelectThumbAddrModeSP(Op, N, TmpBase, TmpOffImm))
564 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000565 if (N.getOpcode() == ARMISD::Wrapper &&
566 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
567 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000568 }
569
Evan Chenga8e29892007-01-19 07:51:42 +0000570 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000571 if (N.getOpcode() == ARMISD::Wrapper &&
572 !(Subtarget->useMovt() &&
573 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
574 Base = N.getOperand(0);
575 } else
576 Base = N;
577
Owen Anderson825b72b2009-08-11 20:47:22 +0000578 Offset = CurDAG->getRegister(0, MVT::i32);
579 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000580 return true;
581 }
582
Evan Chengad0e4652007-02-06 00:22:06 +0000583 // Thumb does not have [sp, r] address mode.
584 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
585 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
586 if ((LHSR && LHSR->getReg() == ARM::SP) ||
587 (RHSR && RHSR->getReg() == ARM::SP)) {
588 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000589 Offset = CurDAG->getRegister(0, MVT::i32);
590 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000591 return true;
592 }
593
Evan Chenga8e29892007-01-19 07:51:42 +0000594 // If the RHS is + imm5 * scale, fold into addr mode.
595 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000596 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000597 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
598 RHSC /= Scale;
599 if (RHSC >= 0 && RHSC < 32) {
600 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000601 Offset = CurDAG->getRegister(0, MVT::i32);
602 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000603 return true;
604 }
605 }
606 }
607
Evan Chengc38f2bc2007-01-23 22:59:13 +0000608 Base = N.getOperand(0);
609 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000610 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000611 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000612}
613
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000614bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000615 SDValue &Base, SDValue &OffImm,
616 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000617 return SelectThumbAddrModeRI5(Op, N, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000618}
619
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000620bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000621 SDValue &Base, SDValue &OffImm,
622 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000623 return SelectThumbAddrModeRI5(Op, N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000624}
625
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000626bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000627 SDValue &Base, SDValue &OffImm,
628 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000629 return SelectThumbAddrModeRI5(Op, N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000630}
631
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000632bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000633 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000634 if (N.getOpcode() == ISD::FrameIndex) {
635 int FI = cast<FrameIndexSDNode>(N)->getIndex();
636 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000637 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000638 return true;
639 }
Evan Cheng79d43262007-01-24 02:21:22 +0000640
Evan Chengad0e4652007-02-06 00:22:06 +0000641 if (N.getOpcode() != ISD::ADD)
642 return false;
643
644 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000645 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
646 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000647 // If the RHS is + imm8 * scale, fold into addr mode.
648 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000649 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000650 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
651 RHSC >>= 2;
652 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000653 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000654 if (Base.getOpcode() == ISD::FrameIndex) {
655 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
656 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
657 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000658 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000659 return true;
660 }
661 }
662 }
663 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000664
Evan Chenga8e29892007-01-19 07:51:42 +0000665 return false;
666}
667
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000668bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000669 SDValue &BaseReg,
670 SDValue &Opc) {
671 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
672
673 // Don't match base register only case. That is matched to a separate
674 // lower complexity pattern with explicit register operand.
675 if (ShOpcVal == ARM_AM::no_shift) return false;
676
677 BaseReg = N.getOperand(0);
678 unsigned ShImmVal = 0;
679 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
680 ShImmVal = RHS->getZExtValue() & 31;
681 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
682 return true;
683 }
684
685 return false;
686}
687
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000688bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000689 SDValue &Base, SDValue &OffImm) {
690 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000691
Evan Cheng3a214252009-08-11 08:52:18 +0000692 // Base only.
693 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000694 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000695 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000696 int FI = cast<FrameIndexSDNode>(N)->getIndex();
697 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000698 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000699 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000700 } else if (N.getOpcode() == ARMISD::Wrapper &&
701 !(Subtarget->useMovt() &&
702 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000703 Base = N.getOperand(0);
704 if (Base.getOpcode() == ISD::TargetConstantPool)
705 return false; // We want to select t2LDRpci instead.
706 } else
707 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000708 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000709 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000710 }
Evan Cheng055b0312009-06-29 07:51:04 +0000711
712 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Evan Cheng3a214252009-08-11 08:52:18 +0000713 if (SelectT2AddrModeImm8(Op, N, Base, OffImm))
714 // Let t2LDRi8 handle (R - imm8).
715 return false;
716
Evan Cheng055b0312009-06-29 07:51:04 +0000717 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000718 if (N.getOpcode() == ISD::SUB)
719 RHSC = -RHSC;
720
721 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +0000722 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +0000723 if (Base.getOpcode() == ISD::FrameIndex) {
724 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
725 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
726 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000727 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000728 return true;
729 }
730 }
731
Evan Cheng3a214252009-08-11 08:52:18 +0000732 // Base only.
733 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000734 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000735 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000736}
737
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000738bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000739 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +0000740 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +0000741 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +0000742 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
743 int RHSC = (int)RHS->getSExtValue();
744 if (N.getOpcode() == ISD::SUB)
745 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +0000746
Evan Cheng3a214252009-08-11 08:52:18 +0000747 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
748 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +0000749 if (Base.getOpcode() == ISD::FrameIndex) {
750 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
751 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
752 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000753 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +0000754 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000755 }
Evan Cheng055b0312009-06-29 07:51:04 +0000756 }
757 }
758
759 return false;
760}
761
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000762bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000763 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000764 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +0000765 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
766 ? cast<LoadSDNode>(Op)->getAddressingMode()
767 : cast<StoreSDNode>(Op)->getAddressingMode();
768 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
769 int RHSC = (int)RHS->getZExtValue();
770 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +0000771 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +0000772 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
773 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000774 return true;
775 }
776 }
777
778 return false;
779}
780
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000781bool ARMDAGToDAGISel::SelectT2AddrModeImm8s4(SDNode *Op, SDValue N,
David Goodwin6647cea2009-06-30 22:50:01 +0000782 SDValue &Base, SDValue &OffImm) {
783 if (N.getOpcode() == ISD::ADD) {
784 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
785 int RHSC = (int)RHS->getZExtValue();
Evan Cheng5c874172009-07-09 22:21:59 +0000786 if (((RHSC & 0x3) == 0) &&
787 ((RHSC >= 0 && RHSC < 0x400) || (RHSC < 0 && RHSC > -0x400))) { // 8 bits.
David Goodwin6647cea2009-06-30 22:50:01 +0000788 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000789 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000790 return true;
791 }
792 }
793 } else if (N.getOpcode() == ISD::SUB) {
794 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
795 int RHSC = (int)RHS->getZExtValue();
796 if (((RHSC & 0x3) == 0) && (RHSC >= 0 && RHSC < 0x400)) { // 8 bits.
797 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000798 OffImm = CurDAG->getTargetConstant(-RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000799 return true;
800 }
801 }
802 }
803
804 return false;
805}
806
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000807bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000808 SDValue &Base,
809 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +0000810 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
811 if (N.getOpcode() != ISD::ADD)
812 return false;
Evan Cheng055b0312009-06-29 07:51:04 +0000813
Evan Cheng3a214252009-08-11 08:52:18 +0000814 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
815 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
816 int RHSC = (int)RHS->getZExtValue();
817 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
818 return false;
819 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +0000820 return false;
821 }
822
Evan Cheng055b0312009-06-29 07:51:04 +0000823 // Look for (R + R) or (R + (R << [1,2,3])).
824 unsigned ShAmt = 0;
825 Base = N.getOperand(0);
826 OffReg = N.getOperand(1);
827
828 // Swap if it is ((R << c) + R).
829 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
830 if (ShOpcVal != ARM_AM::lsl) {
831 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
832 if (ShOpcVal == ARM_AM::lsl)
833 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +0000834 }
835
Evan Cheng055b0312009-06-29 07:51:04 +0000836 if (ShOpcVal == ARM_AM::lsl) {
837 // Check to see if the RHS of the shift is a constant, if not, we can't fold
838 // it.
839 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
840 ShAmt = Sh->getZExtValue();
841 if (ShAmt >= 4) {
842 ShAmt = 0;
843 ShOpcVal = ARM_AM::no_shift;
844 } else
845 OffReg = OffReg.getOperand(0);
846 } else {
847 ShOpcVal = ARM_AM::no_shift;
848 }
David Goodwin7ecc8502009-07-15 15:50:19 +0000849 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000850
Owen Anderson825b72b2009-08-11 20:47:22 +0000851 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000852
853 return true;
854}
855
856//===--------------------------------------------------------------------===//
857
Evan Chengee568cf2007-07-05 07:15:27 +0000858/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +0000859static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000860 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +0000861}
862
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000863SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
864 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +0000865 ISD::MemIndexedMode AM = LD->getAddressingMode();
866 if (AM == ISD::UNINDEXED)
867 return NULL;
868
Owen Andersone50ed302009-08-10 22:56:29 +0000869 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +0000870 SDValue Offset, AMOpc;
871 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
872 unsigned Opcode = 0;
873 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000874 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000875 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000876 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
877 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +0000878 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000879 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000880 Match = true;
881 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
882 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
883 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +0000884 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000885 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000886 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000887 Match = true;
888 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
889 }
890 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000891 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000892 Match = true;
893 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
894 }
895 }
896 }
897
898 if (Match) {
899 SDValue Chain = LD->getChain();
900 SDValue Base = LD->getBasePtr();
901 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000902 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000903 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000904 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +0000905 }
906
907 return NULL;
908}
909
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000910SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
911 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000912 ISD::MemIndexedMode AM = LD->getAddressingMode();
913 if (AM == ISD::UNINDEXED)
914 return NULL;
915
Owen Andersone50ed302009-08-10 22:56:29 +0000916 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +0000917 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000918 SDValue Offset;
919 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
920 unsigned Opcode = 0;
921 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000922 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000923 switch (LoadedVT.getSimpleVT().SimpleTy) {
924 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000925 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
926 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000927 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000928 if (isSExtLd)
929 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
930 else
931 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000932 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000933 case MVT::i8:
934 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000935 if (isSExtLd)
936 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
937 else
938 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000939 break;
940 default:
941 return NULL;
942 }
943 Match = true;
944 }
945
946 if (Match) {
947 SDValue Chain = LD->getChain();
948 SDValue Base = LD->getBasePtr();
949 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000950 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000951 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000952 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000953 }
954
955 return NULL;
956}
957
Evan Cheng603afbf2010-05-10 17:34:18 +0000958/// PairDRegs - Form a quad register from a pair of D registers.
959///
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000960SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
961 DebugLoc dl = V0.getNode()->getDebugLoc();
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000962 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
963 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +0000964 if (llvm::ModelWithRegSequence()) {
Evan Cheng94cc6d32010-05-04 20:39:49 +0000965 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
966 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
967 }
968 SDValue Undef =
969 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0);
Chris Lattner518bb532010-02-09 19:54:29 +0000970 SDNode *Pair = CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000971 VT, Undef, V0, SubReg0);
Chris Lattner518bb532010-02-09 19:54:29 +0000972 return CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000973 VT, SDValue(Pair, 0), V1, SubReg1);
974}
975
Evan Cheng7f687192010-05-14 00:21:45 +0000976/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +0000977///
978SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
979 DebugLoc dl = V0.getNode()->getDebugLoc();
980 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::QSUBREG_0, MVT::i32);
981 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::QSUBREG_1, MVT::i32);
982 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
983 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
984}
985
Evan Cheng7f687192010-05-14 00:21:45 +0000986/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +0000987///
988SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
989 SDValue V2, SDValue V3) {
990 DebugLoc dl = V0.getNode()->getDebugLoc();
991 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
992 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
993 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::DSUBREG_2, MVT::i32);
994 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::DSUBREG_3, MVT::i32);
995 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
996 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
997}
998
Evan Cheng5c6aba22010-05-14 18:54:59 +0000999/// OctoDRegs - Form 8 consecutive D registers.
1000///
1001SDNode *ARMDAGToDAGISel::OctoDRegs(EVT VT, SDValue V0, SDValue V1,
1002 SDValue V2, SDValue V3,
1003 SDValue V4, SDValue V5,
1004 SDValue V6, SDValue V7) {
1005 DebugLoc dl = V0.getNode()->getDebugLoc();
1006 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
1007 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
1008 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::DSUBREG_2, MVT::i32);
1009 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::DSUBREG_3, MVT::i32);
1010 SDValue SubReg4 = CurDAG->getTargetConstant(ARM::DSUBREG_4, MVT::i32);
1011 SDValue SubReg5 = CurDAG->getTargetConstant(ARM::DSUBREG_5, MVT::i32);
1012 SDValue SubReg6 = CurDAG->getTargetConstant(ARM::DSUBREG_6, MVT::i32);
1013 SDValue SubReg7 = CurDAG->getTargetConstant(ARM::DSUBREG_7, MVT::i32);
1014 const SDValue Ops[] ={ V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3,
1015 V4, SubReg4, V5, SubReg5, V6, SubReg6, V7, SubReg7 };
1016 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 16);
1017}
1018
Bob Wilsona7c397c2009-10-14 16:19:03 +00001019/// GetNEONSubregVT - Given a type for a 128-bit NEON vector, return the type
1020/// for a 64-bit subregister of the vector.
1021static EVT GetNEONSubregVT(EVT VT) {
1022 switch (VT.getSimpleVT().SimpleTy) {
1023 default: llvm_unreachable("unhandled NEON type");
1024 case MVT::v16i8: return MVT::v8i8;
1025 case MVT::v8i16: return MVT::v4i16;
1026 case MVT::v4f32: return MVT::v2f32;
1027 case MVT::v4i32: return MVT::v2i32;
1028 case MVT::v2i64: return MVT::v1i64;
1029 }
1030}
1031
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001032SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001033 unsigned *DOpcodes, unsigned *QOpcodes0,
1034 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001035 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001036 DebugLoc dl = N->getDebugLoc();
1037
Bob Wilson226036e2010-03-20 22:13:40 +00001038 SDValue MemAddr, Align;
1039 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001040 return NULL;
1041
1042 SDValue Chain = N->getOperand(0);
1043 EVT VT = N->getValueType(0);
1044 bool is64BitVector = VT.is64BitVector();
1045
1046 unsigned OpcodeIndex;
1047 switch (VT.getSimpleVT().SimpleTy) {
1048 default: llvm_unreachable("unhandled vld type");
1049 // Double-register operations:
1050 case MVT::v8i8: OpcodeIndex = 0; break;
1051 case MVT::v4i16: OpcodeIndex = 1; break;
1052 case MVT::v2f32:
1053 case MVT::v2i32: OpcodeIndex = 2; break;
1054 case MVT::v1i64: OpcodeIndex = 3; break;
1055 // Quad-register operations:
1056 case MVT::v16i8: OpcodeIndex = 0; break;
1057 case MVT::v8i16: OpcodeIndex = 1; break;
1058 case MVT::v4f32:
1059 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001060 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001061 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001062 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001063 }
1064
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001065 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001066 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson3e36f132009-10-14 17:28:52 +00001067 if (is64BitVector) {
1068 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001069 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson3e36f132009-10-14 17:28:52 +00001070 std::vector<EVT> ResTys(NumVecs, VT);
1071 ResTys.push_back(MVT::Other);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001072 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
1073 if (!llvm::ModelWithRegSequence() || NumVecs < 2)
1074 return VLd;
1075
Evan Cheng0ce537a2010-05-11 01:19:40 +00001076 SDValue RegSeq;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001077 SDValue V0 = SDValue(VLd, 0);
1078 SDValue V1 = SDValue(VLd, 1);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001079
Evan Cheng0ce537a2010-05-11 01:19:40 +00001080 // Form a REG_SEQUENCE to force register allocation.
Evan Chenge9e2ba02010-05-10 21:26:24 +00001081 if (NumVecs == 2)
1082 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1083 else {
1084 SDValue V2 = SDValue(VLd, 2);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001085 // If it's a vld3, form a quad D-register but discard the last part.
Evan Chenge9e2ba02010-05-10 21:26:24 +00001086 SDValue V3 = (NumVecs == 3)
1087 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1088 : SDValue(VLd, 3);
1089 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1090 }
1091
Evan Cheng5c6aba22010-05-14 18:54:59 +00001092 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1093 SDValue D = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0+Vec,
1094 dl, VT, RegSeq);
1095 ReplaceUses(SDValue(N, Vec), D);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001096 }
1097 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, NumVecs));
1098 return NULL;
Bob Wilson3e36f132009-10-14 17:28:52 +00001099 }
1100
1101 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson621f1952010-03-23 05:25:43 +00001102 if (NumVecs <= 2) {
1103 // Quad registers are directly supported for VLD1 and VLD2,
1104 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001105 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001106 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson621f1952010-03-23 05:25:43 +00001107 std::vector<EVT> ResTys(2 * NumVecs, RegVT);
Bob Wilson3e36f132009-10-14 17:28:52 +00001108 ResTys.push_back(MVT::Other);
Bob Wilson226036e2010-03-20 22:13:40 +00001109 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson621f1952010-03-23 05:25:43 +00001110 Chain = SDValue(VLd, 2 * NumVecs);
Bob Wilson3e36f132009-10-14 17:28:52 +00001111
1112 // Combine the even and odd subregs to produce the result.
Evan Cheng603afbf2010-05-10 17:34:18 +00001113 if (llvm::ModelWithRegSequence()) {
1114 if (NumVecs == 1) {
1115 SDNode *Q = PairDRegs(VT, SDValue(VLd, 0), SDValue(VLd, 1));
1116 ReplaceUses(SDValue(N, 0), SDValue(Q, 0));
1117 } else {
1118 SDValue QQ = SDValue(QuadDRegs(MVT::v4i64,
1119 SDValue(VLd, 0), SDValue(VLd, 1),
1120 SDValue(VLd, 2), SDValue(VLd, 3)), 0);
1121 SDValue Q0 = CurDAG->getTargetExtractSubreg(ARM::QSUBREG_0, dl, VT, QQ);
1122 SDValue Q1 = CurDAG->getTargetExtractSubreg(ARM::QSUBREG_1, dl, VT, QQ);
1123 ReplaceUses(SDValue(N, 0), Q0);
1124 ReplaceUses(SDValue(N, 1), Q1);
1125 }
1126 } else {
1127 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1128 SDNode *Q = PairDRegs(VT, SDValue(VLd, 2*Vec), SDValue(VLd, 2*Vec+1));
1129 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1130 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001131 }
1132 } else {
1133 // Otherwise, quad registers are loaded with two separate instructions,
1134 // where one loads the even registers and the other loads the odd registers.
1135
Bob Wilson3e36f132009-10-14 17:28:52 +00001136 std::vector<EVT> ResTys(NumVecs, RegVT);
1137 ResTys.push_back(MemAddr.getValueType());
1138 ResTys.push_back(MVT::Other);
1139
Bob Wilson24f995d2009-10-14 18:32:29 +00001140 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001141 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001142 const SDValue OpsA[] = { MemAddr, Align, Reg0, Pred, Reg0, Chain };
1143 SDNode *VLdA = CurDAG->getMachineNode(Opc, dl, ResTys, OpsA, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001144 Chain = SDValue(VLdA, NumVecs+1);
1145
Bob Wilson24f995d2009-10-14 18:32:29 +00001146 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001147 Opc = QOpcodes1[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001148 const SDValue OpsB[] = { SDValue(VLdA, NumVecs),
1149 Align, Reg0, Pred, Reg0, Chain };
1150 SDNode *VLdB = CurDAG->getMachineNode(Opc, dl, ResTys, OpsB, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001151 Chain = SDValue(VLdB, NumVecs+1);
1152
Evan Cheng5c6aba22010-05-14 18:54:59 +00001153 if (llvm::ModelWithRegSequence()) {
1154 SDValue V0 = SDValue(VLdA, 0);
1155 SDValue V1 = SDValue(VLdB, 0);
1156 SDValue V2 = SDValue(VLdA, 1);
1157 SDValue V3 = SDValue(VLdB, 1);
1158 SDValue V4 = SDValue(VLdA, 2);
1159 SDValue V5 = SDValue(VLdB, 2);
1160 SDValue V6 = (NumVecs == 3)
1161 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,RegVT),
1162 0)
1163 : SDValue(VLdA, 3);
1164 SDValue V7 = (NumVecs == 3)
1165 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,RegVT),
1166 0)
1167 : SDValue(VLdB, 3);
1168 SDValue RegSeq = SDValue(OctoDRegs(MVT::v8i64, V0, V1, V2, V3,
1169 V4, V5, V6, V7), 0);
1170
1171 // Extract out the 3 / 4 Q registers.
1172 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1173 SDValue Q = CurDAG->getTargetExtractSubreg(ARM::QSUBREG_0+Vec,
1174 dl, VT, RegSeq);
1175 ReplaceUses(SDValue(N, Vec), Q);
1176 }
1177 } else {
1178 // Combine the even and odd subregs to produce the result.
1179 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1180 SDNode *Q = PairDRegs(VT, SDValue(VLdA, Vec), SDValue(VLdB, Vec));
1181 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1182 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001183 }
1184 }
1185 ReplaceUses(SDValue(N, NumVecs), Chain);
1186 return NULL;
1187}
1188
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001189SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001190 unsigned *DOpcodes, unsigned *QOpcodes0,
1191 unsigned *QOpcodes1) {
Bob Wilson11d98992010-03-23 06:20:33 +00001192 assert(NumVecs >=1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001193 DebugLoc dl = N->getDebugLoc();
1194
Bob Wilson226036e2010-03-20 22:13:40 +00001195 SDValue MemAddr, Align;
1196 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001197 return NULL;
1198
1199 SDValue Chain = N->getOperand(0);
1200 EVT VT = N->getOperand(3).getValueType();
1201 bool is64BitVector = VT.is64BitVector();
1202
1203 unsigned OpcodeIndex;
1204 switch (VT.getSimpleVT().SimpleTy) {
1205 default: llvm_unreachable("unhandled vst type");
1206 // Double-register operations:
1207 case MVT::v8i8: OpcodeIndex = 0; break;
1208 case MVT::v4i16: OpcodeIndex = 1; break;
1209 case MVT::v2f32:
1210 case MVT::v2i32: OpcodeIndex = 2; break;
1211 case MVT::v1i64: OpcodeIndex = 3; break;
1212 // Quad-register operations:
1213 case MVT::v16i8: OpcodeIndex = 0; break;
1214 case MVT::v8i16: OpcodeIndex = 1; break;
1215 case MVT::v4f32:
1216 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001217 case MVT::v2i64: OpcodeIndex = 3;
1218 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1219 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001220 }
1221
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001222 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001223 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001224
Bob Wilson226036e2010-03-20 22:13:40 +00001225 SmallVector<SDValue, 10> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001226 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001227 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001228
1229 if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001230 if (llvm::ModelWithRegSequence() && NumVecs >= 2) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001231 SDValue RegSeq;
1232 SDValue V0 = N->getOperand(0+3);
1233 SDValue V1 = N->getOperand(1+3);
1234
1235 // Form a REG_SEQUENCE to force register allocation.
1236 if (NumVecs == 2)
1237 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1238 else {
1239 SDValue V2 = N->getOperand(2+3);
1240 // If it's a vld3, form a quad D-register and leave the last part as
1241 // an undef.
1242 SDValue V3 = (NumVecs == 3)
1243 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1244 : N->getOperand(3+3);
1245 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1246 }
1247
1248 // Now extract the D registers back out.
1249 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, VT,
1250 RegSeq));
1251 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, VT,
1252 RegSeq));
1253 if (NumVecs > 2)
1254 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_2, dl, VT,
1255 RegSeq));
1256 if (NumVecs > 3)
1257 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_3, dl, VT,
1258 RegSeq));
1259 } else {
1260 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1261 Ops.push_back(N->getOperand(Vec+3));
1262 }
Evan Chengac0869d2009-11-21 06:21:52 +00001263 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001264 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001265 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001266 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001267 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+5);
Bob Wilson24f995d2009-10-14 18:32:29 +00001268 }
1269
1270 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson11d98992010-03-23 06:20:33 +00001271 if (NumVecs <= 2) {
1272 // Quad registers are directly supported for VST1 and VST2,
1273 // storing pairs of D regs.
Bob Wilson24f995d2009-10-14 18:32:29 +00001274 unsigned Opc = QOpcodes0[OpcodeIndex];
Evan Cheng603afbf2010-05-10 17:34:18 +00001275 if (llvm::ModelWithRegSequence() && NumVecs == 2) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001276 // First extract the pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001277 SDValue Q0 = N->getOperand(3);
1278 SDValue Q1 = N->getOperand(4);
1279
1280 // Form a QQ register.
1281 SDValue QQ = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
1282
1283 // Now extract the D registers back out.
Bob Wilson24f995d2009-10-14 18:32:29 +00001284 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001285 QQ));
Bob Wilson24f995d2009-10-14 18:32:29 +00001286 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001287 QQ));
1288 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_2, dl, RegVT,
1289 QQ));
1290 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_3, dl, RegVT,
1291 QQ));
1292 Ops.push_back(Pred);
1293 Ops.push_back(Reg0); // predicate register
1294 Ops.push_back(Chain);
1295 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 5 + 4);
1296 } else {
1297 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1298 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1299 N->getOperand(Vec+3)));
1300 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
1301 N->getOperand(Vec+3)));
1302 }
1303 Ops.push_back(Pred);
1304 Ops.push_back(Reg0); // predicate register
1305 Ops.push_back(Chain);
1306 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(),
1307 5 + 2 * NumVecs);
Bob Wilson24f995d2009-10-14 18:32:29 +00001308 }
Bob Wilson24f995d2009-10-14 18:32:29 +00001309 }
1310
1311 // Otherwise, quad registers are stored with two separate instructions,
1312 // where one stores the even registers and the other stores the odd registers.
Evan Cheng12c24692010-05-14 22:54:52 +00001313 if (llvm::ModelWithRegSequence()) {
Evan Cheng12c24692010-05-14 22:54:52 +00001314 // Form the QQQQ REG_SEQUENCE.
1315 SDValue V[8];
1316 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
1317 V[i] = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1318 N->getOperand(Vec+3));
1319 V[i+1] = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
1320 N->getOperand(Vec+3));
1321 }
1322 if (NumVecs == 3)
1323 V[6] = V[7] =
1324 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,RegVT), 0);
1325 SDValue RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1326 V[4], V[5], V[6], V[7]), 0);
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001327
Evan Cheng12c24692010-05-14 22:54:52 +00001328 // Store the even D registers.
1329 Ops.push_back(Reg0); // post-access address offset
1330 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1331 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0+Vec*2, dl,
1332 RegVT, RegSeq));
1333 Ops.push_back(Pred);
1334 Ops.push_back(Reg0); // predicate register
1335 Ops.push_back(Chain);
1336 unsigned Opc = QOpcodes0[OpcodeIndex];
1337 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1338 MVT::Other, Ops.data(), NumVecs+6);
1339 Chain = SDValue(VStA, 1);
Bob Wilson24f995d2009-10-14 18:32:29 +00001340
Evan Cheng12c24692010-05-14 22:54:52 +00001341 // Store the odd D registers.
1342 Ops[0] = SDValue(VStA, 0); // MemAddr
1343 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1344 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1+Vec*2, dl,
1345 RegVT, RegSeq);
1346 Ops[NumVecs+5] = Chain;
1347 Opc = QOpcodes1[OpcodeIndex];
1348 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1349 MVT::Other, Ops.data(), NumVecs+6);
1350 Chain = SDValue(VStB, 1);
1351 ReplaceUses(SDValue(N, 0), Chain);
1352 return NULL;
1353 } else {
1354 Ops.push_back(Reg0); // post-access address offset
1355
1356 // Store the even subregs.
1357 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1358 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1359 N->getOperand(Vec+3)));
1360 Ops.push_back(Pred);
1361 Ops.push_back(Reg0); // predicate register
1362 Ops.push_back(Chain);
1363 unsigned Opc = QOpcodes0[OpcodeIndex];
1364 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1365 MVT::Other, Ops.data(), NumVecs+6);
1366 Chain = SDValue(VStA, 1);
1367
1368 // Store the odd subregs.
1369 Ops[0] = SDValue(VStA, 0); // MemAddr
1370 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1371 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
1372 N->getOperand(Vec+3));
1373 Ops[NumVecs+5] = Chain;
1374 Opc = QOpcodes1[OpcodeIndex];
1375 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1376 MVT::Other, Ops.data(), NumVecs+6);
1377 Chain = SDValue(VStB, 1);
1378 ReplaceUses(SDValue(N, 0), Chain);
1379 return NULL;
1380 }
Bob Wilson24f995d2009-10-14 18:32:29 +00001381}
1382
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001383SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001384 unsigned NumVecs, unsigned *DOpcodes,
1385 unsigned *QOpcodes0,
1386 unsigned *QOpcodes1) {
1387 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001388 DebugLoc dl = N->getDebugLoc();
1389
Bob Wilson226036e2010-03-20 22:13:40 +00001390 SDValue MemAddr, Align;
1391 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001392 return NULL;
1393
1394 SDValue Chain = N->getOperand(0);
1395 unsigned Lane =
1396 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001397 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001398 bool is64BitVector = VT.is64BitVector();
1399
Bob Wilson96493442009-10-14 16:46:45 +00001400 // Quad registers are handled by load/store of subregs. Find the subreg info.
Bob Wilsona7c397c2009-10-14 16:19:03 +00001401 unsigned NumElts = 0;
1402 int SubregIdx = 0;
1403 EVT RegVT = VT;
1404 if (!is64BitVector) {
1405 RegVT = GetNEONSubregVT(VT);
1406 NumElts = RegVT.getVectorNumElements();
1407 SubregIdx = (Lane < NumElts) ? ARM::DSUBREG_0 : ARM::DSUBREG_1;
1408 }
1409
1410 unsigned OpcodeIndex;
1411 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001412 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001413 // Double-register operations:
1414 case MVT::v8i8: OpcodeIndex = 0; break;
1415 case MVT::v4i16: OpcodeIndex = 1; break;
1416 case MVT::v2f32:
1417 case MVT::v2i32: OpcodeIndex = 2; break;
1418 // Quad-register operations:
1419 case MVT::v8i16: OpcodeIndex = 0; break;
1420 case MVT::v4f32:
1421 case MVT::v4i32: OpcodeIndex = 1; break;
1422 }
1423
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001424 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001425 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001426
Bob Wilson226036e2010-03-20 22:13:40 +00001427 SmallVector<SDValue, 10> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001428 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001429 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001430
1431 unsigned Opc = 0;
1432 if (is64BitVector) {
1433 Opc = DOpcodes[OpcodeIndex];
1434 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1435 Ops.push_back(N->getOperand(Vec+3));
1436 } else {
1437 // Check if this is loading the even or odd subreg of a Q register.
1438 if (Lane < NumElts) {
1439 Opc = QOpcodes0[OpcodeIndex];
1440 } else {
1441 Lane -= NumElts;
1442 Opc = QOpcodes1[OpcodeIndex];
1443 }
1444 // Extract the subregs of the input vector.
1445 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1446 Ops.push_back(CurDAG->getTargetExtractSubreg(SubregIdx, dl, RegVT,
1447 N->getOperand(Vec+3)));
1448 }
1449 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001450 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001451 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001452 Ops.push_back(Chain);
1453
Bob Wilson96493442009-10-14 16:46:45 +00001454 if (!IsLoad)
Bob Wilson226036e2010-03-20 22:13:40 +00001455 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson96493442009-10-14 16:46:45 +00001456
Bob Wilsona7c397c2009-10-14 16:19:03 +00001457 std::vector<EVT> ResTys(NumVecs, RegVT);
1458 ResTys.push_back(MVT::Other);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001459 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(),NumVecs+6);
1460
1461 if (llvm::ModelWithRegSequence() && is64BitVector) {
1462 SDValue RegSeq;
1463 SDValue V0 = SDValue(VLdLn, 0);
1464 SDValue V1 = SDValue(VLdLn, 1);
1465
1466 // Form a REG_SEQUENCE to force register allocation.
1467 if (NumVecs == 2) {
1468 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1469 } else {
1470 SDValue V2 = SDValue(VLdLn, 2);
1471 // If it's a vld3, form a quad D-register but discard the last part.
1472 SDValue V3 = (NumVecs == 3)
1473 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1474 : SDValue(VLdLn, 3);
1475 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1476 }
1477
1478 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1479 SDValue D = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0+Vec, dl, VT,
1480 RegSeq);
1481 ReplaceUses(SDValue(N, Vec), D);
1482 }
1483 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, NumVecs));
1484 return NULL;
1485 }
1486
Bob Wilsona7c397c2009-10-14 16:19:03 +00001487 // For a 64-bit vector load to D registers, nothing more needs to be done.
1488 if (is64BitVector)
1489 return VLdLn;
1490
1491 // For 128-bit vectors, take the 64-bit results of the load and insert them
1492 // as subregs into the result.
1493 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1494 SDValue QuadVec = CurDAG->getTargetInsertSubreg(SubregIdx, dl, VT,
1495 N->getOperand(Vec+3),
1496 SDValue(VLdLn, Vec));
1497 ReplaceUses(SDValue(N, Vec), QuadVec);
1498 }
1499
1500 Chain = SDValue(VLdLn, NumVecs);
1501 ReplaceUses(SDValue(N, NumVecs), Chain);
1502 return NULL;
1503}
1504
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001505SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001506 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001507 if (!Subtarget->hasV6T2Ops())
1508 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001509
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001510 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1511 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1512
1513
1514 // For unsigned extracts, check for a shift right and mask
1515 unsigned And_imm = 0;
1516 if (N->getOpcode() == ISD::AND) {
1517 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1518
1519 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1520 if (And_imm & (And_imm + 1))
1521 return NULL;
1522
1523 unsigned Srl_imm = 0;
1524 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1525 Srl_imm)) {
1526 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1527
1528 unsigned Width = CountTrailingOnes_32(And_imm);
1529 unsigned LSB = Srl_imm;
1530 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1531 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1532 CurDAG->getTargetConstant(LSB, MVT::i32),
1533 CurDAG->getTargetConstant(Width, MVT::i32),
1534 getAL(CurDAG), Reg0 };
1535 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1536 }
1537 }
1538 return NULL;
1539 }
1540
1541 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001542 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001543 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001544 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1545 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001546 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001547 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1548 unsigned Width = 32 - Srl_imm;
1549 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001550 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001551 return NULL;
1552 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001553 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001554 CurDAG->getTargetConstant(LSB, MVT::i32),
1555 CurDAG->getTargetConstant(Width, MVT::i32),
1556 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001557 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001558 }
1559 }
1560 return NULL;
1561}
1562
Evan Cheng9ef48352009-11-20 00:54:03 +00001563SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001564SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001565 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1566 SDValue CPTmp0;
1567 SDValue CPTmp1;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001568 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001569 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1570 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1571 unsigned Opc = 0;
1572 switch (SOShOp) {
1573 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1574 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1575 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1576 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1577 default:
1578 llvm_unreachable("Unknown so_reg opcode!");
1579 break;
1580 }
1581 SDValue SOShImm =
1582 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1583 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1584 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001585 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001586 }
1587 return 0;
1588}
1589
1590SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001591SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001592 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1593 SDValue CPTmp0;
1594 SDValue CPTmp1;
1595 SDValue CPTmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001596 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001597 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1598 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001599 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001600 }
1601 return 0;
1602}
1603
1604SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001605SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001606 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1607 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1608 if (!T)
1609 return 0;
1610
1611 if (Predicate_t2_so_imm(TrueVal.getNode())) {
1612 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1613 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1614 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001615 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001616 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1617 }
1618 return 0;
1619}
1620
1621SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001622SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001623 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1624 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1625 if (!T)
1626 return 0;
1627
1628 if (Predicate_so_imm(TrueVal.getNode())) {
1629 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1630 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1631 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001632 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001633 ARM::MOVCCi, MVT::i32, Ops, 5);
1634 }
1635 return 0;
1636}
1637
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001638SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1639 EVT VT = N->getValueType(0);
1640 SDValue FalseVal = N->getOperand(0);
1641 SDValue TrueVal = N->getOperand(1);
1642 SDValue CC = N->getOperand(2);
1643 SDValue CCR = N->getOperand(3);
1644 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001645 assert(CC.getOpcode() == ISD::Constant);
1646 assert(CCR.getOpcode() == ISD::Register);
1647 ARMCC::CondCodes CCVal =
1648 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001649
1650 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1651 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1652 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1653 // Pattern complexity = 18 cost = 1 size = 0
1654 SDValue CPTmp0;
1655 SDValue CPTmp1;
1656 SDValue CPTmp2;
1657 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001658 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001659 CCVal, CCR, InFlag);
1660 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001661 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001662 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1663 if (Res)
1664 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001665 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001666 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001667 CCVal, CCR, InFlag);
1668 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001669 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001670 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1671 if (Res)
1672 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001673 }
1674
1675 // Pattern: (ARMcmov:i32 GPR:i32:$false,
1676 // (imm:i32)<<P:Predicate_so_imm>>:$true,
1677 // (imm:i32):$cc)
1678 // Emits: (MOVCCi:i32 GPR:i32:$false,
1679 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1680 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001681 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001682 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001683 CCVal, CCR, InFlag);
1684 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001685 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001686 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1687 if (Res)
1688 return Res;
1689 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001690 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001691 CCVal, CCR, InFlag);
1692 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001693 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001694 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1695 if (Res)
1696 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001697 }
1698 }
1699
1700 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1701 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1702 // Pattern complexity = 6 cost = 1 size = 0
1703 //
1704 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1705 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1706 // Pattern complexity = 6 cost = 11 size = 0
1707 //
1708 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001709 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1710 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001711 unsigned Opc = 0;
1712 switch (VT.getSimpleVT().SimpleTy) {
1713 default: assert(false && "Illegal conditional move type!");
1714 break;
1715 case MVT::i32:
1716 Opc = Subtarget->isThumb()
1717 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1718 : ARM::MOVCCr;
1719 break;
1720 case MVT::f32:
1721 Opc = ARM::VMOVScc;
1722 break;
1723 case MVT::f64:
1724 Opc = ARM::VMOVDcc;
1725 break;
1726 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001727 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001728}
1729
Evan Chengde8aa4e2010-05-05 18:28:36 +00001730SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
1731 // The only time a CONCAT_VECTORS operation can have legal types is when
1732 // two 64-bit vectors are concatenated to a 128-bit vector.
1733 EVT VT = N->getValueType(0);
1734 if (!VT.is128BitVector() || N->getNumOperands() != 2)
1735 llvm_unreachable("unexpected CONCAT_VECTORS");
1736 DebugLoc dl = N->getDebugLoc();
1737 SDValue V0 = N->getOperand(0);
1738 SDValue V1 = N->getOperand(1);
1739 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
1740 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
1741 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1742 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1743}
1744
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001745SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001746 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001747
Dan Gohmane8be6c62008-07-17 19:10:17 +00001748 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001749 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001750
1751 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001752 default: break;
1753 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001754 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001755 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001756 if (Subtarget->hasThumb2())
1757 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1758 // be done with MOV + MOVT, at worst.
1759 UseCP = 0;
1760 else {
1761 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001762 UseCP = (Val > 255 && // MOV
1763 ~Val > 255 && // MOV + MVN
1764 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001765 } else
1766 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1767 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1768 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1769 }
1770
Evan Chenga8e29892007-01-19 07:51:42 +00001771 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001772 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001773 CurDAG->getTargetConstantPool(ConstantInt::get(
1774 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001775 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001776
1777 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001778 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001779 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001780 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001781 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001782 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1783 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001784 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001785 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001786 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001787 CurDAG->getRegister(0, MVT::i32),
1788 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001789 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001790 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001791 CurDAG->getEntryNode()
1792 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001793 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1794 Ops, 6);
Evan Cheng012f2d92007-01-24 08:53:17 +00001795 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001796 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001797 return NULL;
1798 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001799
Evan Chenga8e29892007-01-19 07:51:42 +00001800 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001801 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001802 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001803 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001804 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001805 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001806 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001807 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001808 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1809 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001810 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001811 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1812 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001813 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1814 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1815 CurDAG->getRegister(0, MVT::i32) };
1816 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001817 }
Evan Chenga8e29892007-01-19 07:51:42 +00001818 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001819 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001820 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001821 return I;
1822 break;
1823 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001824 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001825 return I;
1826 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001827 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001828 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001829 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001830 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001831 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001832 if (!RHSV) break;
1833 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001834 unsigned ShImm = Log2_32(RHSV-1);
1835 if (ShImm >= 32)
1836 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001837 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001838 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001839 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1840 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001841 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001842 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001843 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001844 } else {
1845 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001846 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001847 }
Evan Chenga8e29892007-01-19 07:51:42 +00001848 }
1849 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001850 unsigned ShImm = Log2_32(RHSV+1);
1851 if (ShImm >= 32)
1852 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001853 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001854 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001855 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1856 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001857 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001858 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001859 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 5);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001860 } else {
1861 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001862 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001863 }
Evan Chenga8e29892007-01-19 07:51:42 +00001864 }
1865 }
1866 break;
Evan Cheng20956592009-10-21 08:15:52 +00001867 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001868 // Check for unsigned bitfield extract
1869 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1870 return I;
1871
Evan Cheng20956592009-10-21 08:15:52 +00001872 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1873 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1874 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1875 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1876 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001877 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001878 if (VT != MVT::i32)
1879 break;
1880 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1881 ? ARM::t2MOVTi16
1882 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1883 if (!Opc)
1884 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001885 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001886 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1887 if (!N1C)
1888 break;
1889 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1890 SDValue N2 = N0.getOperand(1);
1891 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1892 if (!N2C)
1893 break;
1894 unsigned N1CVal = N1C->getZExtValue();
1895 unsigned N2CVal = N2C->getZExtValue();
1896 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1897 (N1CVal & 0xffffU) == 0xffffU &&
1898 (N2CVal & 0xffffU) == 0x0U) {
1899 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1900 MVT::i32);
1901 SDValue Ops[] = { N0.getOperand(0), Imm16,
1902 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1903 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
1904 }
1905 }
1906 break;
1907 }
Jim Grosbache5165492009-11-09 00:11:35 +00001908 case ARMISD::VMOVRRD:
1909 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001910 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00001911 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00001912 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001913 if (Subtarget->isThumb1Only())
1914 break;
1915 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001916 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001917 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1918 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001919 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001920 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001921 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001922 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1923 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001924 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001925 }
Evan Chengee568cf2007-07-05 07:15:27 +00001926 }
Dan Gohman525178c2007-10-08 18:33:35 +00001927 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001928 if (Subtarget->isThumb1Only())
1929 break;
1930 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001931 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001932 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001933 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001934 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001935 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001936 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1937 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001938 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001939 }
Evan Chengee568cf2007-07-05 07:15:27 +00001940 }
Evan Chenga8e29892007-01-19 07:51:42 +00001941 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00001942 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001943 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001944 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001945 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001946 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001947 if (ResNode)
1948 return ResNode;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00001949
1950 // VLDMQ must be custom-selected for "v2f64 load" to set the AM5Opc value.
1951 if (Subtarget->hasVFP2() &&
1952 N->getValueType(0).getSimpleVT().SimpleTy == MVT::v2f64) {
1953 SDValue Chain = N->getOperand(0);
1954 SDValue AM5Opc =
1955 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001956 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00001957 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1958 SDValue Ops[] = { N->getOperand(1), AM5Opc, Pred, PredReg, Chain };
1959 return CurDAG->getMachineNode(ARM::VLDMQ, dl, MVT::v2f64, MVT::Other,
1960 Ops, 5);
1961 }
1962 // Other cases are autogenerated.
1963 break;
1964 }
1965 case ISD::STORE: {
1966 // VSTMQ must be custom-selected for "v2f64 store" to set the AM5Opc value.
1967 if (Subtarget->hasVFP2() &&
1968 N->getOperand(1).getValueType().getSimpleVT().SimpleTy == MVT::v2f64) {
1969 SDValue Chain = N->getOperand(0);
1970 SDValue AM5Opc =
1971 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001972 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00001973 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1974 SDValue Ops[] = { N->getOperand(1), N->getOperand(2),
1975 AM5Opc, Pred, PredReg, Chain };
1976 return CurDAG->getMachineNode(ARM::VSTMQ, dl, MVT::Other, Ops, 6);
1977 }
Evan Chenga8e29892007-01-19 07:51:42 +00001978 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001979 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001980 }
Evan Chengee568cf2007-07-05 07:15:27 +00001981 case ARMISD::BRCOND: {
1982 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1983 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1984 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001985
Evan Chengee568cf2007-07-05 07:15:27 +00001986 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1987 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
1988 // Pattern complexity = 6 cost = 1 size = 0
1989
David Goodwin5e47a9a2009-06-30 18:04:13 +00001990 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1991 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1992 // Pattern complexity = 6 cost = 1 size = 0
1993
Jim Grosbach764ab522009-08-11 15:33:49 +00001994 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00001995 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001996 SDValue Chain = N->getOperand(0);
1997 SDValue N1 = N->getOperand(1);
1998 SDValue N2 = N->getOperand(2);
1999 SDValue N3 = N->getOperand(3);
2000 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002001 assert(N1.getOpcode() == ISD::BasicBlock);
2002 assert(N2.getOpcode() == ISD::Constant);
2003 assert(N3.getOpcode() == ISD::Register);
2004
Dan Gohman475871a2008-07-27 21:46:04 +00002005 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002006 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002007 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002008 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002009 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
2010 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002011 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002012 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002013 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002014 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002015 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002016 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002017 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002018 return NULL;
2019 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002020 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002021 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002022 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002023 EVT VT = N->getValueType(0);
2024 SDValue N0 = N->getOperand(0);
2025 SDValue N1 = N->getOperand(1);
2026 SDValue N2 = N->getOperand(2);
2027 SDValue N3 = N->getOperand(3);
2028 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002029 assert(N2.getOpcode() == ISD::Constant);
2030 assert(N3.getOpcode() == ISD::Register);
2031
Dan Gohman475871a2008-07-27 21:46:04 +00002032 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002033 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002034 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002035 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002036 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002037 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002038 default: assert(false && "Illegal conditional move type!");
2039 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002040 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002041 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002042 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002043 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002044 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002045 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002046 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002047 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002048 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002049
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002050 case ARMISD::VZIP: {
2051 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002052 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002053 switch (VT.getSimpleVT().SimpleTy) {
2054 default: return NULL;
2055 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2056 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2057 case MVT::v2f32:
2058 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2059 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2060 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2061 case MVT::v4f32:
2062 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2063 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002064 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002065 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2066 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2067 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002068 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002069 case ARMISD::VUZP: {
2070 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002071 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002072 switch (VT.getSimpleVT().SimpleTy) {
2073 default: return NULL;
2074 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2075 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2076 case MVT::v2f32:
2077 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2078 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2079 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2080 case MVT::v4f32:
2081 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2082 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002083 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002084 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2085 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2086 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002087 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002088 case ARMISD::VTRN: {
2089 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002090 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002091 switch (VT.getSimpleVT().SimpleTy) {
2092 default: return NULL;
2093 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2094 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2095 case MVT::v2f32:
2096 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2097 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2098 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2099 case MVT::v4f32:
2100 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2101 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002102 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002103 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2104 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2105 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002106 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002107
2108 case ISD::INTRINSIC_VOID:
2109 case ISD::INTRINSIC_W_CHAIN: {
2110 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002111 switch (IntNo) {
2112 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002113 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002114
Bob Wilson621f1952010-03-23 05:25:43 +00002115 case Intrinsic::arm_neon_vld1: {
2116 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2117 ARM::VLD1d32, ARM::VLD1d64 };
2118 unsigned QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
2119 ARM::VLD1q32, ARM::VLD1q64 };
2120 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2121 }
2122
Bob Wilson31fb12f2009-08-26 17:39:53 +00002123 case Intrinsic::arm_neon_vld2: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002124 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
Bob Wilson621f1952010-03-23 05:25:43 +00002125 ARM::VLD2d32, ARM::VLD1q64 };
Bob Wilson3e36f132009-10-14 17:28:52 +00002126 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002127 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002128 }
2129
2130 case Intrinsic::arm_neon_vld3: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002131 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002132 ARM::VLD3d32, ARM::VLD1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002133 unsigned QOpcodes0[] = { ARM::VLD3q8_UPD,
2134 ARM::VLD3q16_UPD,
2135 ARM::VLD3q32_UPD };
2136 unsigned QOpcodes1[] = { ARM::VLD3q8odd_UPD,
2137 ARM::VLD3q16odd_UPD,
2138 ARM::VLD3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002139 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002140 }
2141
2142 case Intrinsic::arm_neon_vld4: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002143 unsigned DOpcodes[] = { ARM::VLD4d8, ARM::VLD4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002144 ARM::VLD4d32, ARM::VLD1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002145 unsigned QOpcodes0[] = { ARM::VLD4q8_UPD,
2146 ARM::VLD4q16_UPD,
2147 ARM::VLD4q32_UPD };
2148 unsigned QOpcodes1[] = { ARM::VLD4q8odd_UPD,
2149 ARM::VLD4q16odd_UPD,
2150 ARM::VLD4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002151 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002152 }
2153
Bob Wilson243fcc52009-09-01 04:26:28 +00002154 case Intrinsic::arm_neon_vld2lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002155 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002156 unsigned QOpcodes0[] = { ARM::VLD2LNq16, ARM::VLD2LNq32 };
2157 unsigned QOpcodes1[] = { ARM::VLD2LNq16odd, ARM::VLD2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002158 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002159 }
2160
2161 case Intrinsic::arm_neon_vld3lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002162 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002163 unsigned QOpcodes0[] = { ARM::VLD3LNq16, ARM::VLD3LNq32 };
2164 unsigned QOpcodes1[] = { ARM::VLD3LNq16odd, ARM::VLD3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002165 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002166 }
2167
2168 case Intrinsic::arm_neon_vld4lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002169 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002170 unsigned QOpcodes0[] = { ARM::VLD4LNq16, ARM::VLD4LNq32 };
2171 unsigned QOpcodes1[] = { ARM::VLD4LNq16odd, ARM::VLD4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002172 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002173 }
2174
Bob Wilson11d98992010-03-23 06:20:33 +00002175 case Intrinsic::arm_neon_vst1: {
2176 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2177 ARM::VST1d32, ARM::VST1d64 };
2178 unsigned QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
2179 ARM::VST1q32, ARM::VST1q64 };
2180 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2181 }
2182
Bob Wilson31fb12f2009-08-26 17:39:53 +00002183 case Intrinsic::arm_neon_vst2: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002184 unsigned DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
Bob Wilson11d98992010-03-23 06:20:33 +00002185 ARM::VST2d32, ARM::VST1q64 };
Bob Wilson24f995d2009-10-14 18:32:29 +00002186 unsigned QOpcodes[] = { ARM::VST2q8, ARM::VST2q16, ARM::VST2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002187 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002188 }
2189
2190 case Intrinsic::arm_neon_vst3: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002191 unsigned DOpcodes[] = { ARM::VST3d8, ARM::VST3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002192 ARM::VST3d32, ARM::VST1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002193 unsigned QOpcodes0[] = { ARM::VST3q8_UPD,
2194 ARM::VST3q16_UPD,
2195 ARM::VST3q32_UPD };
2196 unsigned QOpcodes1[] = { ARM::VST3q8odd_UPD,
2197 ARM::VST3q16odd_UPD,
2198 ARM::VST3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002199 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002200 }
2201
2202 case Intrinsic::arm_neon_vst4: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002203 unsigned DOpcodes[] = { ARM::VST4d8, ARM::VST4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002204 ARM::VST4d32, ARM::VST1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002205 unsigned QOpcodes0[] = { ARM::VST4q8_UPD,
2206 ARM::VST4q16_UPD,
2207 ARM::VST4q32_UPD };
2208 unsigned QOpcodes1[] = { ARM::VST4q8odd_UPD,
2209 ARM::VST4q16odd_UPD,
2210 ARM::VST4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002211 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002212 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002213
2214 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002215 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002216 unsigned QOpcodes0[] = { ARM::VST2LNq16, ARM::VST2LNq32 };
2217 unsigned QOpcodes1[] = { ARM::VST2LNq16odd, ARM::VST2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002218 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002219 }
2220
2221 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002222 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002223 unsigned QOpcodes0[] = { ARM::VST3LNq16, ARM::VST3LNq32 };
2224 unsigned QOpcodes1[] = { ARM::VST3LNq16odd, ARM::VST3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002225 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002226 }
2227
2228 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002229 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002230 unsigned QOpcodes0[] = { ARM::VST4LNq16, ARM::VST4LNq32 };
2231 unsigned QOpcodes1[] = { ARM::VST4LNq16odd, ARM::VST4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002232 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002233 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002234 }
Bob Wilson429009b2010-05-06 16:05:26 +00002235 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002236 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002237
Bob Wilson429009b2010-05-06 16:05:26 +00002238 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002239 return SelectConcatVector(N);
2240 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002241
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002242 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002243}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002244
Bob Wilson224c2442009-05-19 05:53:42 +00002245bool ARMDAGToDAGISel::
2246SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2247 std::vector<SDValue> &OutOps) {
2248 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002249 // Require the address to be in a register. That is safe for all ARM
2250 // variants and it is hard to do anything much smarter without knowing
2251 // how the operand is used.
2252 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002253 return false;
2254}
2255
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002256/// createARMISelDag - This pass converts a legalized DAG into a
2257/// ARM-specific DAG, ready for instruction scheduling.
2258///
Bob Wilson522ce972009-09-28 14:30:20 +00002259FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2260 CodeGenOpt::Level OptLevel) {
2261 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002262}
Evan Chengde8aa4e2010-05-05 18:28:36 +00002263
2264/// ModelWithRegSequence - Return true if isel should use REG_SEQUENCE to model
2265/// operations involving sub-registers.
2266bool llvm::ModelWithRegSequence() {
2267 return UseRegSeq;
2268}