blob: ecc647f8ac14aa92476d885f4a1b6abfd7320993 [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
Evan Cheng8f6de382010-05-16 03:27:48 +0000187 /// QuadQRegs - Form 4 consecutive Q registers.
188 ///
189 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
190
Evan Cheng5c6aba22010-05-14 18:54:59 +0000191 /// OctoDRegs - Form 8 consecutive D registers.
192 ///
193 SDNode *OctoDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3,
194 SDValue V4, SDValue V5, SDValue V6, SDValue V7);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000195};
Evan Chenga8e29892007-01-19 07:51:42 +0000196}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000197
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000198/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
199/// operand. If so Imm will receive the 32-bit value.
200static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
201 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
202 Imm = cast<ConstantSDNode>(N)->getZExtValue();
203 return true;
204 }
205 return false;
206}
207
208// isInt32Immediate - This method tests to see if a constant operand.
209// If so Imm will receive the 32 bit value.
210static bool isInt32Immediate(SDValue N, unsigned &Imm) {
211 return isInt32Immediate(N.getNode(), Imm);
212}
213
214// isOpcWithIntImmediate - This method tests to see if the node is a specific
215// opcode and that it has a immediate integer right operand.
216// If so Imm will receive the 32 bit value.
217static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
218 return N->getOpcode() == Opc &&
219 isInt32Immediate(N->getOperand(1).getNode(), Imm);
220}
221
222
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000223bool ARMDAGToDAGISel::SelectShifterOperandReg(SDNode *Op,
Evan Cheng055b0312009-06-29 07:51:04 +0000224 SDValue N,
225 SDValue &BaseReg,
226 SDValue &ShReg,
227 SDValue &Opc) {
228 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
229
230 // Don't match base register only case. That is matched to a separate
231 // lower complexity pattern with explicit register operand.
232 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000233
Evan Cheng055b0312009-06-29 07:51:04 +0000234 BaseReg = N.getOperand(0);
235 unsigned ShImmVal = 0;
236 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000237 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000238 ShImmVal = RHS->getZExtValue() & 31;
239 } else {
240 ShReg = N.getOperand(1);
241 }
242 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000243 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000244 return true;
245}
246
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000247bool ARMDAGToDAGISel::SelectAddrMode2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000248 SDValue &Base, SDValue &Offset,
249 SDValue &Opc) {
Evan Chenga13fd102007-03-13 21:05:54 +0000250 if (N.getOpcode() == ISD::MUL) {
251 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
252 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000253 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000254 if (RHSC & 1) {
255 RHSC = RHSC & ~1;
256 ARM_AM::AddrOpc AddSub = ARM_AM::add;
257 if (RHSC < 0) {
258 AddSub = ARM_AM::sub;
259 RHSC = - RHSC;
260 }
261 if (isPowerOf2_32(RHSC)) {
262 unsigned ShAmt = Log2_32(RHSC);
263 Base = Offset = N.getOperand(0);
264 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
265 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000266 MVT::i32);
Evan Chenga13fd102007-03-13 21:05:54 +0000267 return true;
268 }
269 }
270 }
271 }
272
Evan Chenga8e29892007-01-19 07:51:42 +0000273 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
274 Base = N;
275 if (N.getOpcode() == ISD::FrameIndex) {
276 int FI = cast<FrameIndexSDNode>(N)->getIndex();
277 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000278 } else if (N.getOpcode() == ARMISD::Wrapper &&
279 !(Subtarget->useMovt() &&
280 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000281 Base = N.getOperand(0);
282 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000283 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000284 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
285 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000286 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000287 return true;
288 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000289
Evan Chenga8e29892007-01-19 07:51:42 +0000290 // Match simple R +/- imm12 operands.
291 if (N.getOpcode() == ISD::ADD)
292 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000293 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000294 if ((RHSC >= 0 && RHSC < 0x1000) ||
295 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000296 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000297 if (Base.getOpcode() == ISD::FrameIndex) {
298 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
299 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
300 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000301 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000302
303 ARM_AM::AddrOpc AddSub = ARM_AM::add;
304 if (RHSC < 0) {
305 AddSub = ARM_AM::sub;
306 RHSC = - RHSC;
307 }
308 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000309 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000310 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000311 return true;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000312 }
Evan Chenga8e29892007-01-19 07:51:42 +0000313 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000314
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000315 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000316 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
317 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
318 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000319
Evan Chenga8e29892007-01-19 07:51:42 +0000320 Base = N.getOperand(0);
321 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000322
Evan Chenga8e29892007-01-19 07:51:42 +0000323 if (ShOpcVal != ARM_AM::no_shift) {
324 // Check to see if the RHS of the shift is a constant, if not, we can't fold
325 // it.
326 if (ConstantSDNode *Sh =
327 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000328 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000329 Offset = N.getOperand(1).getOperand(0);
330 } else {
331 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000332 }
333 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000334
Evan Chenga8e29892007-01-19 07:51:42 +0000335 // Try matching (R shl C) + (R).
336 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
337 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
338 if (ShOpcVal != ARM_AM::no_shift) {
339 // Check to see if the RHS of the shift is a constant, if not, we can't
340 // fold it.
341 if (ConstantSDNode *Sh =
342 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000343 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000344 Offset = N.getOperand(0).getOperand(0);
345 Base = N.getOperand(1);
346 } else {
347 ShOpcVal = ARM_AM::no_shift;
348 }
349 }
350 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000351
Evan Chenga8e29892007-01-19 07:51:42 +0000352 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000353 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000354 return true;
355}
356
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000357bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000358 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000359 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000360 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
361 ? cast<LoadSDNode>(Op)->getAddressingMode()
362 : cast<StoreSDNode>(Op)->getAddressingMode();
363 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
364 ? ARM_AM::add : ARM_AM::sub;
365 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000366 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000367 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000368 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000369 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
370 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000371 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000372 return true;
373 }
374 }
375
376 Offset = N;
377 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
378 unsigned ShAmt = 0;
379 if (ShOpcVal != ARM_AM::no_shift) {
380 // Check to see if the RHS of the shift is a constant, if not, we can't fold
381 // it.
382 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000383 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000384 Offset = N.getOperand(0);
385 } else {
386 ShOpcVal = ARM_AM::no_shift;
387 }
388 }
389
390 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000391 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000392 return true;
393}
394
Evan Chenga8e29892007-01-19 07:51:42 +0000395
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000396bool ARMDAGToDAGISel::SelectAddrMode3(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000397 SDValue &Base, SDValue &Offset,
398 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000399 if (N.getOpcode() == ISD::SUB) {
400 // X - C is canonicalize to X + -C, no need to handle it here.
401 Base = N.getOperand(0);
402 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000403 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000404 return true;
405 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000406
Evan Chenga8e29892007-01-19 07:51:42 +0000407 if (N.getOpcode() != ISD::ADD) {
408 Base = N;
409 if (N.getOpcode() == ISD::FrameIndex) {
410 int FI = cast<FrameIndexSDNode>(N)->getIndex();
411 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
412 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000413 Offset = CurDAG->getRegister(0, MVT::i32);
414 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000415 return true;
416 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000417
Evan Chenga8e29892007-01-19 07:51:42 +0000418 // If the RHS is +/- imm8, fold into addr mode.
419 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000420 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000421 if ((RHSC >= 0 && RHSC < 256) ||
422 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000423 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000424 if (Base.getOpcode() == ISD::FrameIndex) {
425 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
426 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
427 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000428 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000429
430 ARM_AM::AddrOpc AddSub = ARM_AM::add;
431 if (RHSC < 0) {
432 AddSub = ARM_AM::sub;
433 RHSC = - RHSC;
434 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000435 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000436 return true;
437 }
438 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000439
Evan Chenga8e29892007-01-19 07:51:42 +0000440 Base = N.getOperand(0);
441 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000442 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000443 return true;
444}
445
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000446bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000447 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000448 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000449 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
450 ? cast<LoadSDNode>(Op)->getAddressingMode()
451 : cast<StoreSDNode>(Op)->getAddressingMode();
452 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
453 ? ARM_AM::add : ARM_AM::sub;
454 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000455 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000456 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000457 Offset = CurDAG->getRegister(0, MVT::i32);
458 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000459 return true;
460 }
461 }
462
463 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000464 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000465 return true;
466}
467
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000468bool ARMDAGToDAGISel::SelectAddrMode4(SDNode *Op, SDValue N,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000469 SDValue &Addr, SDValue &Mode) {
470 Addr = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000471 Mode = CurDAG->getTargetConstant(0, MVT::i32);
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000472 return true;
473}
Evan Chenga8e29892007-01-19 07:51:42 +0000474
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000475bool ARMDAGToDAGISel::SelectAddrMode5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000476 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000477 if (N.getOpcode() != ISD::ADD) {
478 Base = N;
479 if (N.getOpcode() == ISD::FrameIndex) {
480 int FI = cast<FrameIndexSDNode>(N)->getIndex();
481 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000482 } else if (N.getOpcode() == ARMISD::Wrapper &&
483 !(Subtarget->useMovt() &&
484 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000485 Base = N.getOperand(0);
486 }
487 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000488 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000489 return true;
490 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000491
Evan Chenga8e29892007-01-19 07:51:42 +0000492 // If the RHS is +/- imm8, fold into addr mode.
493 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000494 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000495 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
496 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000497 if ((RHSC >= 0 && RHSC < 256) ||
498 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000499 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000500 if (Base.getOpcode() == ISD::FrameIndex) {
501 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
502 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
503 }
504
505 ARM_AM::AddrOpc AddSub = ARM_AM::add;
506 if (RHSC < 0) {
507 AddSub = ARM_AM::sub;
508 RHSC = - RHSC;
509 }
510 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000511 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000512 return true;
513 }
514 }
515 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000516
Evan Chenga8e29892007-01-19 07:51:42 +0000517 Base = N;
518 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000519 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000520 return true;
521}
522
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000523bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Op, SDValue N,
Bob Wilson226036e2010-03-20 22:13:40 +0000524 SDValue &Addr, SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000525 Addr = N;
Jim Grosbach8a5ec862009-11-07 21:25:39 +0000526 // Default to no alignment.
527 Align = CurDAG->getTargetConstant(0, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000528 return true;
529}
530
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000531bool ARMDAGToDAGISel::SelectAddrModePC(SDNode *Op, SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000532 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000533 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
534 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000535 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000536 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000537 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000538 return true;
539 }
540 return false;
541}
542
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000543bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000544 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000545 // FIXME dl should come from the parent load or store, not the address
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000546 DebugLoc dl = Op->getDebugLoc();
Evan Chengc38f2bc2007-01-23 22:59:13 +0000547 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000548 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
549 if (!NC || NC->getZExtValue() != 0)
550 return false;
551
552 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000553 return true;
554 }
555
Evan Chenga8e29892007-01-19 07:51:42 +0000556 Base = N.getOperand(0);
557 Offset = N.getOperand(1);
558 return true;
559}
560
Evan Cheng79d43262007-01-24 02:21:22 +0000561bool
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000562ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000563 unsigned Scale, SDValue &Base,
564 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000565 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000566 SDValue TmpBase, TmpOffImm;
Evan Cheng79d43262007-01-24 02:21:22 +0000567 if (SelectThumbAddrModeSP(Op, N, TmpBase, TmpOffImm))
568 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000569 if (N.getOpcode() == ARMISD::Wrapper &&
570 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
571 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000572 }
573
Evan Chenga8e29892007-01-19 07:51:42 +0000574 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000575 if (N.getOpcode() == ARMISD::Wrapper &&
576 !(Subtarget->useMovt() &&
577 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
578 Base = N.getOperand(0);
579 } else
580 Base = N;
581
Owen Anderson825b72b2009-08-11 20:47:22 +0000582 Offset = CurDAG->getRegister(0, MVT::i32);
583 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000584 return true;
585 }
586
Evan Chengad0e4652007-02-06 00:22:06 +0000587 // Thumb does not have [sp, r] address mode.
588 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
589 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
590 if ((LHSR && LHSR->getReg() == ARM::SP) ||
591 (RHSR && RHSR->getReg() == ARM::SP)) {
592 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000593 Offset = CurDAG->getRegister(0, MVT::i32);
594 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000595 return true;
596 }
597
Evan Chenga8e29892007-01-19 07:51:42 +0000598 // If the RHS is + imm5 * scale, fold into addr mode.
599 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000600 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000601 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
602 RHSC /= Scale;
603 if (RHSC >= 0 && RHSC < 32) {
604 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000605 Offset = CurDAG->getRegister(0, MVT::i32);
606 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000607 return true;
608 }
609 }
610 }
611
Evan Chengc38f2bc2007-01-23 22:59:13 +0000612 Base = N.getOperand(0);
613 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000614 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000615 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000616}
617
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000618bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000619 SDValue &Base, SDValue &OffImm,
620 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000621 return SelectThumbAddrModeRI5(Op, N, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000622}
623
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000624bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000625 SDValue &Base, SDValue &OffImm,
626 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000627 return SelectThumbAddrModeRI5(Op, N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000628}
629
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000630bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000631 SDValue &Base, SDValue &OffImm,
632 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000633 return SelectThumbAddrModeRI5(Op, N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000634}
635
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000636bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000637 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000638 if (N.getOpcode() == ISD::FrameIndex) {
639 int FI = cast<FrameIndexSDNode>(N)->getIndex();
640 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000641 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000642 return true;
643 }
Evan Cheng79d43262007-01-24 02:21:22 +0000644
Evan Chengad0e4652007-02-06 00:22:06 +0000645 if (N.getOpcode() != ISD::ADD)
646 return false;
647
648 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000649 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
650 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000651 // If the RHS is + imm8 * scale, fold into addr mode.
652 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000653 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000654 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
655 RHSC >>= 2;
656 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000657 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000658 if (Base.getOpcode() == ISD::FrameIndex) {
659 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
660 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
661 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000662 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000663 return true;
664 }
665 }
666 }
667 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000668
Evan Chenga8e29892007-01-19 07:51:42 +0000669 return false;
670}
671
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000672bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000673 SDValue &BaseReg,
674 SDValue &Opc) {
675 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
676
677 // Don't match base register only case. That is matched to a separate
678 // lower complexity pattern with explicit register operand.
679 if (ShOpcVal == ARM_AM::no_shift) return false;
680
681 BaseReg = N.getOperand(0);
682 unsigned ShImmVal = 0;
683 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
684 ShImmVal = RHS->getZExtValue() & 31;
685 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
686 return true;
687 }
688
689 return false;
690}
691
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000692bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000693 SDValue &Base, SDValue &OffImm) {
694 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000695
Evan Cheng3a214252009-08-11 08:52:18 +0000696 // Base only.
697 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000698 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000699 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000700 int FI = cast<FrameIndexSDNode>(N)->getIndex();
701 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000702 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000703 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000704 } else if (N.getOpcode() == ARMISD::Wrapper &&
705 !(Subtarget->useMovt() &&
706 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000707 Base = N.getOperand(0);
708 if (Base.getOpcode() == ISD::TargetConstantPool)
709 return false; // We want to select t2LDRpci instead.
710 } else
711 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000712 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000713 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000714 }
Evan Cheng055b0312009-06-29 07:51:04 +0000715
716 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Evan Cheng3a214252009-08-11 08:52:18 +0000717 if (SelectT2AddrModeImm8(Op, N, Base, OffImm))
718 // Let t2LDRi8 handle (R - imm8).
719 return false;
720
Evan Cheng055b0312009-06-29 07:51:04 +0000721 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000722 if (N.getOpcode() == ISD::SUB)
723 RHSC = -RHSC;
724
725 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +0000726 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +0000727 if (Base.getOpcode() == ISD::FrameIndex) {
728 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
729 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
730 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000731 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000732 return true;
733 }
734 }
735
Evan Cheng3a214252009-08-11 08:52:18 +0000736 // Base only.
737 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000738 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000739 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000740}
741
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000742bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000743 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +0000744 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +0000745 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +0000746 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
747 int RHSC = (int)RHS->getSExtValue();
748 if (N.getOpcode() == ISD::SUB)
749 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +0000750
Evan Cheng3a214252009-08-11 08:52:18 +0000751 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
752 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +0000753 if (Base.getOpcode() == ISD::FrameIndex) {
754 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
755 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
756 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000757 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +0000758 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000759 }
Evan Cheng055b0312009-06-29 07:51:04 +0000760 }
761 }
762
763 return false;
764}
765
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000766bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000767 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000768 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +0000769 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
770 ? cast<LoadSDNode>(Op)->getAddressingMode()
771 : cast<StoreSDNode>(Op)->getAddressingMode();
772 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
773 int RHSC = (int)RHS->getZExtValue();
774 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +0000775 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +0000776 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
777 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000778 return true;
779 }
780 }
781
782 return false;
783}
784
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000785bool ARMDAGToDAGISel::SelectT2AddrModeImm8s4(SDNode *Op, SDValue N,
David Goodwin6647cea2009-06-30 22:50:01 +0000786 SDValue &Base, SDValue &OffImm) {
787 if (N.getOpcode() == ISD::ADD) {
788 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
789 int RHSC = (int)RHS->getZExtValue();
Evan Cheng5c874172009-07-09 22:21:59 +0000790 if (((RHSC & 0x3) == 0) &&
791 ((RHSC >= 0 && RHSC < 0x400) || (RHSC < 0 && RHSC > -0x400))) { // 8 bits.
David Goodwin6647cea2009-06-30 22:50:01 +0000792 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000793 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000794 return true;
795 }
796 }
797 } else if (N.getOpcode() == ISD::SUB) {
798 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
799 int RHSC = (int)RHS->getZExtValue();
800 if (((RHSC & 0x3) == 0) && (RHSC >= 0 && RHSC < 0x400)) { // 8 bits.
801 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000802 OffImm = CurDAG->getTargetConstant(-RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000803 return true;
804 }
805 }
806 }
807
808 return false;
809}
810
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000811bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000812 SDValue &Base,
813 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +0000814 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
815 if (N.getOpcode() != ISD::ADD)
816 return false;
Evan Cheng055b0312009-06-29 07:51:04 +0000817
Evan Cheng3a214252009-08-11 08:52:18 +0000818 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
819 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
820 int RHSC = (int)RHS->getZExtValue();
821 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
822 return false;
823 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +0000824 return false;
825 }
826
Evan Cheng055b0312009-06-29 07:51:04 +0000827 // Look for (R + R) or (R + (R << [1,2,3])).
828 unsigned ShAmt = 0;
829 Base = N.getOperand(0);
830 OffReg = N.getOperand(1);
831
832 // Swap if it is ((R << c) + R).
833 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
834 if (ShOpcVal != ARM_AM::lsl) {
835 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
836 if (ShOpcVal == ARM_AM::lsl)
837 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +0000838 }
839
Evan Cheng055b0312009-06-29 07:51:04 +0000840 if (ShOpcVal == ARM_AM::lsl) {
841 // Check to see if the RHS of the shift is a constant, if not, we can't fold
842 // it.
843 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
844 ShAmt = Sh->getZExtValue();
845 if (ShAmt >= 4) {
846 ShAmt = 0;
847 ShOpcVal = ARM_AM::no_shift;
848 } else
849 OffReg = OffReg.getOperand(0);
850 } else {
851 ShOpcVal = ARM_AM::no_shift;
852 }
David Goodwin7ecc8502009-07-15 15:50:19 +0000853 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000854
Owen Anderson825b72b2009-08-11 20:47:22 +0000855 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000856
857 return true;
858}
859
860//===--------------------------------------------------------------------===//
861
Evan Chengee568cf2007-07-05 07:15:27 +0000862/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +0000863static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000864 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +0000865}
866
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000867SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
868 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +0000869 ISD::MemIndexedMode AM = LD->getAddressingMode();
870 if (AM == ISD::UNINDEXED)
871 return NULL;
872
Owen Andersone50ed302009-08-10 22:56:29 +0000873 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +0000874 SDValue Offset, AMOpc;
875 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
876 unsigned Opcode = 0;
877 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000878 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000879 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000880 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
881 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +0000882 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000883 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000884 Match = true;
885 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
886 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
887 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +0000888 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000889 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000890 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000891 Match = true;
892 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
893 }
894 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000895 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000896 Match = true;
897 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
898 }
899 }
900 }
901
902 if (Match) {
903 SDValue Chain = LD->getChain();
904 SDValue Base = LD->getBasePtr();
905 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000906 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000907 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000908 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +0000909 }
910
911 return NULL;
912}
913
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000914SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
915 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000916 ISD::MemIndexedMode AM = LD->getAddressingMode();
917 if (AM == ISD::UNINDEXED)
918 return NULL;
919
Owen Andersone50ed302009-08-10 22:56:29 +0000920 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +0000921 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000922 SDValue Offset;
923 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
924 unsigned Opcode = 0;
925 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000926 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000927 switch (LoadedVT.getSimpleVT().SimpleTy) {
928 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000929 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
930 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000931 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000932 if (isSExtLd)
933 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
934 else
935 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000936 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000937 case MVT::i8:
938 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000939 if (isSExtLd)
940 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
941 else
942 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000943 break;
944 default:
945 return NULL;
946 }
947 Match = true;
948 }
949
950 if (Match) {
951 SDValue Chain = LD->getChain();
952 SDValue Base = LD->getBasePtr();
953 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000954 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000955 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000956 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000957 }
958
959 return NULL;
960}
961
Evan Cheng603afbf2010-05-10 17:34:18 +0000962/// PairDRegs - Form a quad register from a pair of D registers.
963///
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000964SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
965 DebugLoc dl = V0.getNode()->getDebugLoc();
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000966 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
967 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +0000968 if (llvm::ModelWithRegSequence()) {
Evan Cheng94cc6d32010-05-04 20:39:49 +0000969 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
970 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
971 }
972 SDValue Undef =
973 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0);
Chris Lattner518bb532010-02-09 19:54:29 +0000974 SDNode *Pair = CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000975 VT, Undef, V0, SubReg0);
Chris Lattner518bb532010-02-09 19:54:29 +0000976 return CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000977 VT, SDValue(Pair, 0), V1, SubReg1);
978}
979
Evan Cheng7f687192010-05-14 00:21:45 +0000980/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +0000981///
982SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
983 DebugLoc dl = V0.getNode()->getDebugLoc();
984 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::QSUBREG_0, MVT::i32);
985 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::QSUBREG_1, MVT::i32);
986 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
987 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
988}
989
Evan Cheng7f687192010-05-14 00:21:45 +0000990/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +0000991///
992SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
993 SDValue V2, SDValue V3) {
994 DebugLoc dl = V0.getNode()->getDebugLoc();
995 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
996 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
997 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::DSUBREG_2, MVT::i32);
998 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::DSUBREG_3, MVT::i32);
999 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1000 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1001}
1002
Evan Cheng8f6de382010-05-16 03:27:48 +00001003/// QuadQRegs - Form 4 consecutive Q registers.
1004///
1005SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1006 SDValue V2, SDValue V3) {
1007 DebugLoc dl = V0.getNode()->getDebugLoc();
1008 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::QSUBREG_0, MVT::i32);
1009 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::QSUBREG_1, MVT::i32);
1010 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::QSUBREG_2, MVT::i32);
1011 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::QSUBREG_3, MVT::i32);
1012 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1013 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1014}
1015
Evan Cheng5c6aba22010-05-14 18:54:59 +00001016/// OctoDRegs - Form 8 consecutive D registers.
1017///
1018SDNode *ARMDAGToDAGISel::OctoDRegs(EVT VT, SDValue V0, SDValue V1,
1019 SDValue V2, SDValue V3,
1020 SDValue V4, SDValue V5,
1021 SDValue V6, SDValue V7) {
1022 DebugLoc dl = V0.getNode()->getDebugLoc();
1023 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
1024 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
1025 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::DSUBREG_2, MVT::i32);
1026 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::DSUBREG_3, MVT::i32);
1027 SDValue SubReg4 = CurDAG->getTargetConstant(ARM::DSUBREG_4, MVT::i32);
1028 SDValue SubReg5 = CurDAG->getTargetConstant(ARM::DSUBREG_5, MVT::i32);
1029 SDValue SubReg6 = CurDAG->getTargetConstant(ARM::DSUBREG_6, MVT::i32);
1030 SDValue SubReg7 = CurDAG->getTargetConstant(ARM::DSUBREG_7, MVT::i32);
1031 const SDValue Ops[] ={ V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3,
1032 V4, SubReg4, V5, SubReg5, V6, SubReg6, V7, SubReg7 };
1033 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 16);
1034}
1035
Bob Wilsona7c397c2009-10-14 16:19:03 +00001036/// GetNEONSubregVT - Given a type for a 128-bit NEON vector, return the type
1037/// for a 64-bit subregister of the vector.
1038static EVT GetNEONSubregVT(EVT VT) {
1039 switch (VT.getSimpleVT().SimpleTy) {
1040 default: llvm_unreachable("unhandled NEON type");
1041 case MVT::v16i8: return MVT::v8i8;
1042 case MVT::v8i16: return MVT::v4i16;
1043 case MVT::v4f32: return MVT::v2f32;
1044 case MVT::v4i32: return MVT::v2i32;
1045 case MVT::v2i64: return MVT::v1i64;
1046 }
1047}
1048
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001049SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001050 unsigned *DOpcodes, unsigned *QOpcodes0,
1051 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001052 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001053 DebugLoc dl = N->getDebugLoc();
1054
Bob Wilson226036e2010-03-20 22:13:40 +00001055 SDValue MemAddr, Align;
1056 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001057 return NULL;
1058
1059 SDValue Chain = N->getOperand(0);
1060 EVT VT = N->getValueType(0);
1061 bool is64BitVector = VT.is64BitVector();
1062
1063 unsigned OpcodeIndex;
1064 switch (VT.getSimpleVT().SimpleTy) {
1065 default: llvm_unreachable("unhandled vld type");
1066 // Double-register operations:
1067 case MVT::v8i8: OpcodeIndex = 0; break;
1068 case MVT::v4i16: OpcodeIndex = 1; break;
1069 case MVT::v2f32:
1070 case MVT::v2i32: OpcodeIndex = 2; break;
1071 case MVT::v1i64: OpcodeIndex = 3; break;
1072 // Quad-register operations:
1073 case MVT::v16i8: OpcodeIndex = 0; break;
1074 case MVT::v8i16: OpcodeIndex = 1; break;
1075 case MVT::v4f32:
1076 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001077 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001078 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001079 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001080 }
1081
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001082 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001083 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson3e36f132009-10-14 17:28:52 +00001084 if (is64BitVector) {
1085 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001086 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson3e36f132009-10-14 17:28:52 +00001087 std::vector<EVT> ResTys(NumVecs, VT);
1088 ResTys.push_back(MVT::Other);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001089 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
1090 if (!llvm::ModelWithRegSequence() || NumVecs < 2)
1091 return VLd;
1092
Evan Cheng0ce537a2010-05-11 01:19:40 +00001093 SDValue RegSeq;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001094 SDValue V0 = SDValue(VLd, 0);
1095 SDValue V1 = SDValue(VLd, 1);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001096
Evan Cheng0ce537a2010-05-11 01:19:40 +00001097 // Form a REG_SEQUENCE to force register allocation.
Evan Chenge9e2ba02010-05-10 21:26:24 +00001098 if (NumVecs == 2)
1099 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1100 else {
1101 SDValue V2 = SDValue(VLd, 2);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001102 // If it's a vld3, form a quad D-register but discard the last part.
Evan Chenge9e2ba02010-05-10 21:26:24 +00001103 SDValue V3 = (NumVecs == 3)
1104 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1105 : SDValue(VLd, 3);
1106 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1107 }
1108
Evan Cheng5c6aba22010-05-14 18:54:59 +00001109 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1110 SDValue D = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0+Vec,
1111 dl, VT, RegSeq);
1112 ReplaceUses(SDValue(N, Vec), D);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001113 }
1114 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, NumVecs));
1115 return NULL;
Bob Wilson3e36f132009-10-14 17:28:52 +00001116 }
1117
1118 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson621f1952010-03-23 05:25:43 +00001119 if (NumVecs <= 2) {
1120 // Quad registers are directly supported for VLD1 and VLD2,
1121 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001122 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001123 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson621f1952010-03-23 05:25:43 +00001124 std::vector<EVT> ResTys(2 * NumVecs, RegVT);
Bob Wilson3e36f132009-10-14 17:28:52 +00001125 ResTys.push_back(MVT::Other);
Bob Wilson226036e2010-03-20 22:13:40 +00001126 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson621f1952010-03-23 05:25:43 +00001127 Chain = SDValue(VLd, 2 * NumVecs);
Bob Wilson3e36f132009-10-14 17:28:52 +00001128
1129 // Combine the even and odd subregs to produce the result.
Evan Cheng603afbf2010-05-10 17:34:18 +00001130 if (llvm::ModelWithRegSequence()) {
1131 if (NumVecs == 1) {
1132 SDNode *Q = PairDRegs(VT, SDValue(VLd, 0), SDValue(VLd, 1));
1133 ReplaceUses(SDValue(N, 0), SDValue(Q, 0));
1134 } else {
1135 SDValue QQ = SDValue(QuadDRegs(MVT::v4i64,
1136 SDValue(VLd, 0), SDValue(VLd, 1),
1137 SDValue(VLd, 2), SDValue(VLd, 3)), 0);
1138 SDValue Q0 = CurDAG->getTargetExtractSubreg(ARM::QSUBREG_0, dl, VT, QQ);
1139 SDValue Q1 = CurDAG->getTargetExtractSubreg(ARM::QSUBREG_1, dl, VT, QQ);
1140 ReplaceUses(SDValue(N, 0), Q0);
1141 ReplaceUses(SDValue(N, 1), Q1);
1142 }
1143 } else {
1144 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1145 SDNode *Q = PairDRegs(VT, SDValue(VLd, 2*Vec), SDValue(VLd, 2*Vec+1));
1146 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1147 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001148 }
1149 } else {
1150 // Otherwise, quad registers are loaded with two separate instructions,
1151 // where one loads the even registers and the other loads the odd registers.
1152
Bob Wilson3e36f132009-10-14 17:28:52 +00001153 std::vector<EVT> ResTys(NumVecs, RegVT);
1154 ResTys.push_back(MemAddr.getValueType());
1155 ResTys.push_back(MVT::Other);
1156
Bob Wilson24f995d2009-10-14 18:32:29 +00001157 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001158 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001159 const SDValue OpsA[] = { MemAddr, Align, Reg0, Pred, Reg0, Chain };
1160 SDNode *VLdA = CurDAG->getMachineNode(Opc, dl, ResTys, OpsA, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001161 Chain = SDValue(VLdA, NumVecs+1);
1162
Bob Wilson24f995d2009-10-14 18:32:29 +00001163 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001164 Opc = QOpcodes1[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001165 const SDValue OpsB[] = { SDValue(VLdA, NumVecs),
1166 Align, Reg0, Pred, Reg0, Chain };
1167 SDNode *VLdB = CurDAG->getMachineNode(Opc, dl, ResTys, OpsB, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001168 Chain = SDValue(VLdB, NumVecs+1);
1169
Evan Cheng5c6aba22010-05-14 18:54:59 +00001170 if (llvm::ModelWithRegSequence()) {
1171 SDValue V0 = SDValue(VLdA, 0);
1172 SDValue V1 = SDValue(VLdB, 0);
1173 SDValue V2 = SDValue(VLdA, 1);
1174 SDValue V3 = SDValue(VLdB, 1);
1175 SDValue V4 = SDValue(VLdA, 2);
1176 SDValue V5 = SDValue(VLdB, 2);
1177 SDValue V6 = (NumVecs == 3)
1178 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,RegVT),
1179 0)
1180 : SDValue(VLdA, 3);
1181 SDValue V7 = (NumVecs == 3)
1182 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,RegVT),
1183 0)
1184 : SDValue(VLdB, 3);
1185 SDValue RegSeq = SDValue(OctoDRegs(MVT::v8i64, V0, V1, V2, V3,
1186 V4, V5, V6, V7), 0);
1187
1188 // Extract out the 3 / 4 Q registers.
1189 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1190 SDValue Q = CurDAG->getTargetExtractSubreg(ARM::QSUBREG_0+Vec,
1191 dl, VT, RegSeq);
1192 ReplaceUses(SDValue(N, Vec), Q);
1193 }
1194 } else {
1195 // Combine the even and odd subregs to produce the result.
1196 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1197 SDNode *Q = PairDRegs(VT, SDValue(VLdA, Vec), SDValue(VLdB, Vec));
1198 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1199 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001200 }
1201 }
1202 ReplaceUses(SDValue(N, NumVecs), Chain);
1203 return NULL;
1204}
1205
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001206SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001207 unsigned *DOpcodes, unsigned *QOpcodes0,
1208 unsigned *QOpcodes1) {
Bob Wilson11d98992010-03-23 06:20:33 +00001209 assert(NumVecs >=1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001210 DebugLoc dl = N->getDebugLoc();
1211
Bob Wilson226036e2010-03-20 22:13:40 +00001212 SDValue MemAddr, Align;
1213 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001214 return NULL;
1215
1216 SDValue Chain = N->getOperand(0);
1217 EVT VT = N->getOperand(3).getValueType();
1218 bool is64BitVector = VT.is64BitVector();
1219
1220 unsigned OpcodeIndex;
1221 switch (VT.getSimpleVT().SimpleTy) {
1222 default: llvm_unreachable("unhandled vst type");
1223 // Double-register operations:
1224 case MVT::v8i8: OpcodeIndex = 0; break;
1225 case MVT::v4i16: OpcodeIndex = 1; break;
1226 case MVT::v2f32:
1227 case MVT::v2i32: OpcodeIndex = 2; break;
1228 case MVT::v1i64: OpcodeIndex = 3; break;
1229 // Quad-register operations:
1230 case MVT::v16i8: OpcodeIndex = 0; break;
1231 case MVT::v8i16: OpcodeIndex = 1; break;
1232 case MVT::v4f32:
1233 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001234 case MVT::v2i64: OpcodeIndex = 3;
1235 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1236 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001237 }
1238
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001239 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001240 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001241
Bob Wilson226036e2010-03-20 22:13:40 +00001242 SmallVector<SDValue, 10> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001243 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001244 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001245
1246 if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001247 if (llvm::ModelWithRegSequence() && NumVecs >= 2) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001248 SDValue RegSeq;
1249 SDValue V0 = N->getOperand(0+3);
1250 SDValue V1 = N->getOperand(1+3);
1251
1252 // Form a REG_SEQUENCE to force register allocation.
1253 if (NumVecs == 2)
1254 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1255 else {
1256 SDValue V2 = N->getOperand(2+3);
1257 // If it's a vld3, form a quad D-register and leave the last part as
1258 // an undef.
1259 SDValue V3 = (NumVecs == 3)
1260 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1261 : N->getOperand(3+3);
1262 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1263 }
1264
1265 // Now extract the D registers back out.
1266 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, VT,
1267 RegSeq));
1268 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, VT,
1269 RegSeq));
1270 if (NumVecs > 2)
1271 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_2, dl, VT,
1272 RegSeq));
1273 if (NumVecs > 3)
1274 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_3, dl, VT,
1275 RegSeq));
1276 } else {
1277 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1278 Ops.push_back(N->getOperand(Vec+3));
1279 }
Evan Chengac0869d2009-11-21 06:21:52 +00001280 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001281 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001282 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001283 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001284 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+5);
Bob Wilson24f995d2009-10-14 18:32:29 +00001285 }
1286
1287 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson11d98992010-03-23 06:20:33 +00001288 if (NumVecs <= 2) {
1289 // Quad registers are directly supported for VST1 and VST2,
1290 // storing pairs of D regs.
Bob Wilson24f995d2009-10-14 18:32:29 +00001291 unsigned Opc = QOpcodes0[OpcodeIndex];
Evan Cheng603afbf2010-05-10 17:34:18 +00001292 if (llvm::ModelWithRegSequence() && NumVecs == 2) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001293 // First extract the pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001294 SDValue Q0 = N->getOperand(3);
1295 SDValue Q1 = N->getOperand(4);
1296
1297 // Form a QQ register.
1298 SDValue QQ = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
1299
1300 // Now extract the D registers back out.
Bob Wilson24f995d2009-10-14 18:32:29 +00001301 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001302 QQ));
Bob Wilson24f995d2009-10-14 18:32:29 +00001303 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001304 QQ));
1305 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_2, dl, RegVT,
1306 QQ));
1307 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_3, dl, RegVT,
1308 QQ));
1309 Ops.push_back(Pred);
1310 Ops.push_back(Reg0); // predicate register
1311 Ops.push_back(Chain);
1312 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 5 + 4);
1313 } else {
1314 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1315 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1316 N->getOperand(Vec+3)));
1317 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
1318 N->getOperand(Vec+3)));
1319 }
1320 Ops.push_back(Pred);
1321 Ops.push_back(Reg0); // predicate register
1322 Ops.push_back(Chain);
1323 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(),
1324 5 + 2 * NumVecs);
Bob Wilson24f995d2009-10-14 18:32:29 +00001325 }
Bob Wilson24f995d2009-10-14 18:32:29 +00001326 }
1327
1328 // Otherwise, quad registers are stored with two separate instructions,
1329 // where one stores the even registers and the other stores the odd registers.
Evan Cheng12c24692010-05-14 22:54:52 +00001330 if (llvm::ModelWithRegSequence()) {
Evan Cheng12c24692010-05-14 22:54:52 +00001331 // Form the QQQQ REG_SEQUENCE.
1332 SDValue V[8];
1333 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
1334 V[i] = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1335 N->getOperand(Vec+3));
1336 V[i+1] = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
1337 N->getOperand(Vec+3));
1338 }
1339 if (NumVecs == 3)
Evan Cheng7189fd02010-05-15 07:53:37 +00001340 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1341 dl, RegVT), 0);
1342
Evan Cheng12c24692010-05-14 22:54:52 +00001343 SDValue RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1344 V[4], V[5], V[6], V[7]), 0);
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001345
Evan Cheng12c24692010-05-14 22:54:52 +00001346 // Store the even D registers.
1347 Ops.push_back(Reg0); // post-access address offset
1348 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1349 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0+Vec*2, dl,
1350 RegVT, RegSeq));
1351 Ops.push_back(Pred);
1352 Ops.push_back(Reg0); // predicate register
1353 Ops.push_back(Chain);
1354 unsigned Opc = QOpcodes0[OpcodeIndex];
1355 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1356 MVT::Other, Ops.data(), NumVecs+6);
1357 Chain = SDValue(VStA, 1);
Bob Wilson24f995d2009-10-14 18:32:29 +00001358
Evan Cheng12c24692010-05-14 22:54:52 +00001359 // Store the odd D registers.
1360 Ops[0] = SDValue(VStA, 0); // MemAddr
1361 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1362 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1+Vec*2, dl,
1363 RegVT, RegSeq);
1364 Ops[NumVecs+5] = Chain;
1365 Opc = QOpcodes1[OpcodeIndex];
1366 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1367 MVT::Other, Ops.data(), NumVecs+6);
1368 Chain = SDValue(VStB, 1);
1369 ReplaceUses(SDValue(N, 0), Chain);
1370 return NULL;
1371 } else {
1372 Ops.push_back(Reg0); // post-access address offset
1373
1374 // Store the even subregs.
1375 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1376 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1377 N->getOperand(Vec+3)));
1378 Ops.push_back(Pred);
1379 Ops.push_back(Reg0); // predicate register
1380 Ops.push_back(Chain);
1381 unsigned Opc = QOpcodes0[OpcodeIndex];
1382 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1383 MVT::Other, Ops.data(), NumVecs+6);
1384 Chain = SDValue(VStA, 1);
1385
1386 // Store the odd subregs.
1387 Ops[0] = SDValue(VStA, 0); // MemAddr
1388 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1389 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
1390 N->getOperand(Vec+3));
1391 Ops[NumVecs+5] = Chain;
1392 Opc = QOpcodes1[OpcodeIndex];
1393 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1394 MVT::Other, Ops.data(), NumVecs+6);
1395 Chain = SDValue(VStB, 1);
1396 ReplaceUses(SDValue(N, 0), Chain);
1397 return NULL;
1398 }
Bob Wilson24f995d2009-10-14 18:32:29 +00001399}
1400
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001401SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001402 unsigned NumVecs, unsigned *DOpcodes,
1403 unsigned *QOpcodes0,
1404 unsigned *QOpcodes1) {
1405 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001406 DebugLoc dl = N->getDebugLoc();
1407
Bob Wilson226036e2010-03-20 22:13:40 +00001408 SDValue MemAddr, Align;
1409 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001410 return NULL;
1411
1412 SDValue Chain = N->getOperand(0);
1413 unsigned Lane =
1414 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001415 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001416 bool is64BitVector = VT.is64BitVector();
1417
Bob Wilson96493442009-10-14 16:46:45 +00001418 // Quad registers are handled by load/store of subregs. Find the subreg info.
Bob Wilsona7c397c2009-10-14 16:19:03 +00001419 unsigned NumElts = 0;
1420 int SubregIdx = 0;
Evan Cheng8f6de382010-05-16 03:27:48 +00001421 bool Even = false;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001422 EVT RegVT = VT;
1423 if (!is64BitVector) {
1424 RegVT = GetNEONSubregVT(VT);
1425 NumElts = RegVT.getVectorNumElements();
1426 SubregIdx = (Lane < NumElts) ? ARM::DSUBREG_0 : ARM::DSUBREG_1;
Evan Cheng8f6de382010-05-16 03:27:48 +00001427 Even = Lane < NumElts;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001428 }
1429
1430 unsigned OpcodeIndex;
1431 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001432 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001433 // Double-register operations:
1434 case MVT::v8i8: OpcodeIndex = 0; break;
1435 case MVT::v4i16: OpcodeIndex = 1; break;
1436 case MVT::v2f32:
1437 case MVT::v2i32: OpcodeIndex = 2; break;
1438 // Quad-register operations:
1439 case MVT::v8i16: OpcodeIndex = 0; break;
1440 case MVT::v4f32:
1441 case MVT::v4i32: OpcodeIndex = 1; break;
1442 }
1443
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001444 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001445 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001446
Bob Wilson226036e2010-03-20 22:13:40 +00001447 SmallVector<SDValue, 10> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001448 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001449 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001450
1451 unsigned Opc = 0;
1452 if (is64BitVector) {
1453 Opc = DOpcodes[OpcodeIndex];
Evan Cheng8f6de382010-05-16 03:27:48 +00001454 if (llvm::ModelWithRegSequence()) {
1455 SDValue RegSeq;
1456 SDValue V0 = N->getOperand(0+3);
1457 SDValue V1 = N->getOperand(1+3);
1458 if (NumVecs == 2) {
1459 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1460 } else {
1461 SDValue V2 = N->getOperand(2+3);
1462 SDValue V3 = (NumVecs == 3)
1463 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1464 : N->getOperand(3+3);
1465 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1466 }
1467
1468 // Now extract the D registers back out.
1469 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, VT,
1470 RegSeq));
1471 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, VT,
1472 RegSeq));
1473 if (NumVecs > 2)
1474 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_2, dl, VT,
1475 RegSeq));
1476 if (NumVecs > 3)
1477 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_3, dl, VT,
1478 RegSeq));
1479 } else {
1480 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1481 Ops.push_back(N->getOperand(Vec+3));
1482 }
Bob Wilsona7c397c2009-10-14 16:19:03 +00001483 } else {
1484 // Check if this is loading the even or odd subreg of a Q register.
1485 if (Lane < NumElts) {
1486 Opc = QOpcodes0[OpcodeIndex];
1487 } else {
1488 Lane -= NumElts;
1489 Opc = QOpcodes1[OpcodeIndex];
1490 }
Evan Cheng8f6de382010-05-16 03:27:48 +00001491
1492 if (llvm::ModelWithRegSequence()) {
1493 SDValue RegSeq;
1494 SDValue V0 = N->getOperand(0+3);
1495 SDValue V1 = N->getOperand(1+3);
1496 if (NumVecs == 2) {
1497 RegSeq = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
1498 } else {
1499 SDValue V2 = N->getOperand(2+3);
1500 SDValue V3 = (NumVecs == 3)
1501 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1502 : N->getOperand(3+3);
1503 RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
1504 }
1505
1506 // Extract the subregs of the input vector.
1507 unsigned SubIdx = Even ? ARM::DSUBREG_0 : ARM::DSUBREG_1;
1508 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1509 Ops.push_back(CurDAG->getTargetExtractSubreg(SubIdx+Vec*2, dl, RegVT,
1510 RegSeq));
1511 } else {
1512 // Extract the subregs of the input vector.
1513 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1514 Ops.push_back(CurDAG->getTargetExtractSubreg(SubregIdx, dl, RegVT,
1515 N->getOperand(Vec+3)));
1516 }
Bob Wilsona7c397c2009-10-14 16:19:03 +00001517 }
1518 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001519 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001520 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001521 Ops.push_back(Chain);
1522
Bob Wilson96493442009-10-14 16:46:45 +00001523 if (!IsLoad)
Bob Wilson226036e2010-03-20 22:13:40 +00001524 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson96493442009-10-14 16:46:45 +00001525
Bob Wilsona7c397c2009-10-14 16:19:03 +00001526 std::vector<EVT> ResTys(NumVecs, RegVT);
1527 ResTys.push_back(MVT::Other);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001528 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(),NumVecs+6);
1529
Evan Cheng7189fd02010-05-15 07:53:37 +00001530 if (llvm::ModelWithRegSequence()) {
Evan Cheng7092c2b2010-05-15 01:36:29 +00001531 // Form a REG_SEQUENCE to force register allocation.
Evan Cheng7189fd02010-05-15 07:53:37 +00001532 SDValue RegSeq;
1533 if (is64BitVector) {
1534 SDValue V0 = SDValue(VLdLn, 0);
1535 SDValue V1 = SDValue(VLdLn, 1);
1536 if (NumVecs == 2) {
1537 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1538 } else {
1539 SDValue V2 = SDValue(VLdLn, 2);
1540 // If it's a vld3, form a quad D-register but discard the last part.
1541 SDValue V3 = (NumVecs == 3)
Evan Cheng7092c2b2010-05-15 01:36:29 +00001542 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1543 : SDValue(VLdLn, 3);
Evan Cheng7189fd02010-05-15 07:53:37 +00001544 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1545 }
1546 } else {
1547 // For 128-bit vectors, take the 64-bit results of the load and insert them
1548 // as subregs into the result.
1549 SDValue V[8];
1550 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
Evan Cheng8f6de382010-05-16 03:27:48 +00001551 if (Even) {
Evan Cheng7189fd02010-05-15 07:53:37 +00001552 V[i] = SDValue(VLdLn, Vec);
1553 V[i+1] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1554 dl, RegVT), 0);
1555 } else {
1556 V[i] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1557 dl, RegVT), 0);
1558 V[i+1] = SDValue(VLdLn, Vec);
1559 }
1560 }
1561 if (NumVecs == 3)
1562 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1563 dl, RegVT), 0);
1564
1565 if (NumVecs == 2)
1566 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V[0], V[1], V[2], V[3]), 0);
1567 else
1568 RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1569 V[4], V[5], V[6], V[7]), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001570 }
1571
Evan Cheng7189fd02010-05-15 07:53:37 +00001572 unsigned SubIdx = is64BitVector ? ARM::DSUBREG_0 : ARM::QSUBREG_0;
1573 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1574 ReplaceUses(SDValue(N, Vec),
1575 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, RegSeq));
Evan Cheng7092c2b2010-05-15 01:36:29 +00001576 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, NumVecs));
1577 return NULL;
1578 }
1579
Bob Wilsona7c397c2009-10-14 16:19:03 +00001580 // For a 64-bit vector load to D registers, nothing more needs to be done.
1581 if (is64BitVector)
1582 return VLdLn;
1583
1584 // For 128-bit vectors, take the 64-bit results of the load and insert them
1585 // as subregs into the result.
1586 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1587 SDValue QuadVec = CurDAG->getTargetInsertSubreg(SubregIdx, dl, VT,
1588 N->getOperand(Vec+3),
1589 SDValue(VLdLn, Vec));
1590 ReplaceUses(SDValue(N, Vec), QuadVec);
1591 }
1592
1593 Chain = SDValue(VLdLn, NumVecs);
1594 ReplaceUses(SDValue(N, NumVecs), Chain);
1595 return NULL;
1596}
1597
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001598SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001599 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001600 if (!Subtarget->hasV6T2Ops())
1601 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001602
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001603 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1604 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1605
1606
1607 // For unsigned extracts, check for a shift right and mask
1608 unsigned And_imm = 0;
1609 if (N->getOpcode() == ISD::AND) {
1610 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1611
1612 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1613 if (And_imm & (And_imm + 1))
1614 return NULL;
1615
1616 unsigned Srl_imm = 0;
1617 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1618 Srl_imm)) {
1619 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1620
1621 unsigned Width = CountTrailingOnes_32(And_imm);
1622 unsigned LSB = Srl_imm;
1623 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1624 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1625 CurDAG->getTargetConstant(LSB, MVT::i32),
1626 CurDAG->getTargetConstant(Width, MVT::i32),
1627 getAL(CurDAG), Reg0 };
1628 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1629 }
1630 }
1631 return NULL;
1632 }
1633
1634 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001635 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001636 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001637 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1638 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001639 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001640 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1641 unsigned Width = 32 - Srl_imm;
1642 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001643 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001644 return NULL;
1645 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001646 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001647 CurDAG->getTargetConstant(LSB, MVT::i32),
1648 CurDAG->getTargetConstant(Width, MVT::i32),
1649 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001650 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001651 }
1652 }
1653 return NULL;
1654}
1655
Evan Cheng9ef48352009-11-20 00:54:03 +00001656SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001657SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001658 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1659 SDValue CPTmp0;
1660 SDValue CPTmp1;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001661 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001662 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1663 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1664 unsigned Opc = 0;
1665 switch (SOShOp) {
1666 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1667 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1668 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1669 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1670 default:
1671 llvm_unreachable("Unknown so_reg opcode!");
1672 break;
1673 }
1674 SDValue SOShImm =
1675 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1676 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1677 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001678 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001679 }
1680 return 0;
1681}
1682
1683SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001684SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001685 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1686 SDValue CPTmp0;
1687 SDValue CPTmp1;
1688 SDValue CPTmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001689 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001690 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1691 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001692 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001693 }
1694 return 0;
1695}
1696
1697SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001698SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001699 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1700 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1701 if (!T)
1702 return 0;
1703
1704 if (Predicate_t2_so_imm(TrueVal.getNode())) {
1705 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1706 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1707 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001708 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001709 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1710 }
1711 return 0;
1712}
1713
1714SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001715SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001716 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1717 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1718 if (!T)
1719 return 0;
1720
1721 if (Predicate_so_imm(TrueVal.getNode())) {
1722 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1723 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1724 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001725 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001726 ARM::MOVCCi, MVT::i32, Ops, 5);
1727 }
1728 return 0;
1729}
1730
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001731SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1732 EVT VT = N->getValueType(0);
1733 SDValue FalseVal = N->getOperand(0);
1734 SDValue TrueVal = N->getOperand(1);
1735 SDValue CC = N->getOperand(2);
1736 SDValue CCR = N->getOperand(3);
1737 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001738 assert(CC.getOpcode() == ISD::Constant);
1739 assert(CCR.getOpcode() == ISD::Register);
1740 ARMCC::CondCodes CCVal =
1741 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001742
1743 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1744 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1745 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1746 // Pattern complexity = 18 cost = 1 size = 0
1747 SDValue CPTmp0;
1748 SDValue CPTmp1;
1749 SDValue CPTmp2;
1750 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001751 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001752 CCVal, CCR, InFlag);
1753 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001754 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001755 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1756 if (Res)
1757 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001758 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001759 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001760 CCVal, CCR, InFlag);
1761 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001762 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001763 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1764 if (Res)
1765 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001766 }
1767
1768 // Pattern: (ARMcmov:i32 GPR:i32:$false,
1769 // (imm:i32)<<P:Predicate_so_imm>>:$true,
1770 // (imm:i32):$cc)
1771 // Emits: (MOVCCi:i32 GPR:i32:$false,
1772 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1773 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001774 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001775 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001776 CCVal, CCR, InFlag);
1777 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001778 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001779 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1780 if (Res)
1781 return Res;
1782 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001783 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001784 CCVal, CCR, InFlag);
1785 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001786 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001787 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1788 if (Res)
1789 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001790 }
1791 }
1792
1793 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1794 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1795 // Pattern complexity = 6 cost = 1 size = 0
1796 //
1797 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1798 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1799 // Pattern complexity = 6 cost = 11 size = 0
1800 //
1801 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001802 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1803 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001804 unsigned Opc = 0;
1805 switch (VT.getSimpleVT().SimpleTy) {
1806 default: assert(false && "Illegal conditional move type!");
1807 break;
1808 case MVT::i32:
1809 Opc = Subtarget->isThumb()
1810 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1811 : ARM::MOVCCr;
1812 break;
1813 case MVT::f32:
1814 Opc = ARM::VMOVScc;
1815 break;
1816 case MVT::f64:
1817 Opc = ARM::VMOVDcc;
1818 break;
1819 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001820 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001821}
1822
Evan Chengde8aa4e2010-05-05 18:28:36 +00001823SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
1824 // The only time a CONCAT_VECTORS operation can have legal types is when
1825 // two 64-bit vectors are concatenated to a 128-bit vector.
1826 EVT VT = N->getValueType(0);
1827 if (!VT.is128BitVector() || N->getNumOperands() != 2)
1828 llvm_unreachable("unexpected CONCAT_VECTORS");
1829 DebugLoc dl = N->getDebugLoc();
1830 SDValue V0 = N->getOperand(0);
1831 SDValue V1 = N->getOperand(1);
1832 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
1833 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
1834 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1835 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1836}
1837
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001838SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001839 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001840
Dan Gohmane8be6c62008-07-17 19:10:17 +00001841 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001842 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001843
1844 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001845 default: break;
1846 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001847 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001848 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001849 if (Subtarget->hasThumb2())
1850 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1851 // be done with MOV + MOVT, at worst.
1852 UseCP = 0;
1853 else {
1854 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001855 UseCP = (Val > 255 && // MOV
1856 ~Val > 255 && // MOV + MVN
1857 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001858 } else
1859 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1860 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1861 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1862 }
1863
Evan Chenga8e29892007-01-19 07:51:42 +00001864 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001865 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001866 CurDAG->getTargetConstantPool(ConstantInt::get(
1867 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001868 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001869
1870 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001871 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001872 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001873 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001874 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001875 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1876 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001877 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001878 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001879 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001880 CurDAG->getRegister(0, MVT::i32),
1881 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001882 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001883 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001884 CurDAG->getEntryNode()
1885 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001886 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1887 Ops, 6);
Evan Cheng012f2d92007-01-24 08:53:17 +00001888 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001889 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001890 return NULL;
1891 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001892
Evan Chenga8e29892007-01-19 07:51:42 +00001893 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001894 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001895 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001896 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001897 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001898 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001899 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001900 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001901 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1902 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001903 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001904 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1905 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001906 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1907 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1908 CurDAG->getRegister(0, MVT::i32) };
1909 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001910 }
Evan Chenga8e29892007-01-19 07:51:42 +00001911 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001912 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001913 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001914 return I;
1915 break;
1916 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001917 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001918 return I;
1919 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001920 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001921 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001922 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001923 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001924 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001925 if (!RHSV) break;
1926 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001927 unsigned ShImm = Log2_32(RHSV-1);
1928 if (ShImm >= 32)
1929 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001930 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001931 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001932 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1933 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001934 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001935 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001936 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001937 } else {
1938 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001939 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001940 }
Evan Chenga8e29892007-01-19 07:51:42 +00001941 }
1942 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001943 unsigned ShImm = Log2_32(RHSV+1);
1944 if (ShImm >= 32)
1945 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001946 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001947 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001948 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1949 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001950 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001951 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001952 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 5);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001953 } else {
1954 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001955 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001956 }
Evan Chenga8e29892007-01-19 07:51:42 +00001957 }
1958 }
1959 break;
Evan Cheng20956592009-10-21 08:15:52 +00001960 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001961 // Check for unsigned bitfield extract
1962 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1963 return I;
1964
Evan Cheng20956592009-10-21 08:15:52 +00001965 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1966 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1967 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1968 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1969 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001970 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001971 if (VT != MVT::i32)
1972 break;
1973 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1974 ? ARM::t2MOVTi16
1975 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1976 if (!Opc)
1977 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001978 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001979 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1980 if (!N1C)
1981 break;
1982 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1983 SDValue N2 = N0.getOperand(1);
1984 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1985 if (!N2C)
1986 break;
1987 unsigned N1CVal = N1C->getZExtValue();
1988 unsigned N2CVal = N2C->getZExtValue();
1989 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1990 (N1CVal & 0xffffU) == 0xffffU &&
1991 (N2CVal & 0xffffU) == 0x0U) {
1992 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1993 MVT::i32);
1994 SDValue Ops[] = { N0.getOperand(0), Imm16,
1995 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1996 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
1997 }
1998 }
1999 break;
2000 }
Jim Grosbache5165492009-11-09 00:11:35 +00002001 case ARMISD::VMOVRRD:
2002 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002003 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002004 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002005 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002006 if (Subtarget->isThumb1Only())
2007 break;
2008 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002009 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002010 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2011 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002012 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002013 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002014 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002015 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2016 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002017 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002018 }
Evan Chengee568cf2007-07-05 07:15:27 +00002019 }
Dan Gohman525178c2007-10-08 18:33:35 +00002020 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002021 if (Subtarget->isThumb1Only())
2022 break;
2023 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002024 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002025 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002026 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002027 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002028 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002029 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2030 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002031 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002032 }
Evan Chengee568cf2007-07-05 07:15:27 +00002033 }
Evan Chenga8e29892007-01-19 07:51:42 +00002034 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002035 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002036 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002037 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002038 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002039 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002040 if (ResNode)
2041 return ResNode;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002042
2043 // VLDMQ must be custom-selected for "v2f64 load" to set the AM5Opc value.
2044 if (Subtarget->hasVFP2() &&
2045 N->getValueType(0).getSimpleVT().SimpleTy == MVT::v2f64) {
2046 SDValue Chain = N->getOperand(0);
2047 SDValue AM5Opc =
2048 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002049 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002050 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2051 SDValue Ops[] = { N->getOperand(1), AM5Opc, Pred, PredReg, Chain };
2052 return CurDAG->getMachineNode(ARM::VLDMQ, dl, MVT::v2f64, MVT::Other,
2053 Ops, 5);
2054 }
2055 // Other cases are autogenerated.
2056 break;
2057 }
2058 case ISD::STORE: {
2059 // VSTMQ must be custom-selected for "v2f64 store" to set the AM5Opc value.
2060 if (Subtarget->hasVFP2() &&
2061 N->getOperand(1).getValueType().getSimpleVT().SimpleTy == MVT::v2f64) {
2062 SDValue Chain = N->getOperand(0);
2063 SDValue AM5Opc =
2064 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002065 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002066 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2067 SDValue Ops[] = { N->getOperand(1), N->getOperand(2),
2068 AM5Opc, Pred, PredReg, Chain };
2069 return CurDAG->getMachineNode(ARM::VSTMQ, dl, MVT::Other, Ops, 6);
2070 }
Evan Chenga8e29892007-01-19 07:51:42 +00002071 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002072 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002073 }
Evan Chengee568cf2007-07-05 07:15:27 +00002074 case ARMISD::BRCOND: {
2075 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2076 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2077 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002078
Evan Chengee568cf2007-07-05 07:15:27 +00002079 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2080 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2081 // Pattern complexity = 6 cost = 1 size = 0
2082
David Goodwin5e47a9a2009-06-30 18:04:13 +00002083 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2084 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2085 // Pattern complexity = 6 cost = 1 size = 0
2086
Jim Grosbach764ab522009-08-11 15:33:49 +00002087 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002088 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002089 SDValue Chain = N->getOperand(0);
2090 SDValue N1 = N->getOperand(1);
2091 SDValue N2 = N->getOperand(2);
2092 SDValue N3 = N->getOperand(3);
2093 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002094 assert(N1.getOpcode() == ISD::BasicBlock);
2095 assert(N2.getOpcode() == ISD::Constant);
2096 assert(N3.getOpcode() == ISD::Register);
2097
Dan Gohman475871a2008-07-27 21:46:04 +00002098 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002099 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002100 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002101 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002102 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
2103 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002104 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002105 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002106 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002107 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002108 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002109 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002110 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002111 return NULL;
2112 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002113 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002114 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002115 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002116 EVT VT = N->getValueType(0);
2117 SDValue N0 = N->getOperand(0);
2118 SDValue N1 = N->getOperand(1);
2119 SDValue N2 = N->getOperand(2);
2120 SDValue N3 = N->getOperand(3);
2121 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002122 assert(N2.getOpcode() == ISD::Constant);
2123 assert(N3.getOpcode() == ISD::Register);
2124
Dan Gohman475871a2008-07-27 21:46:04 +00002125 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002126 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002127 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002128 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002129 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002130 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002131 default: assert(false && "Illegal conditional move type!");
2132 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002133 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002134 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002135 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002136 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002137 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002138 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002139 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002140 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002141 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002142
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002143 case ARMISD::VZIP: {
2144 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002145 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002146 switch (VT.getSimpleVT().SimpleTy) {
2147 default: return NULL;
2148 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2149 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2150 case MVT::v2f32:
2151 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2152 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2153 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2154 case MVT::v4f32:
2155 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2156 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002157 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002158 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2159 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2160 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002161 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002162 case ARMISD::VUZP: {
2163 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002164 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002165 switch (VT.getSimpleVT().SimpleTy) {
2166 default: return NULL;
2167 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2168 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2169 case MVT::v2f32:
2170 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2171 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2172 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2173 case MVT::v4f32:
2174 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2175 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002176 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002177 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2178 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2179 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002180 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002181 case ARMISD::VTRN: {
2182 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002183 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002184 switch (VT.getSimpleVT().SimpleTy) {
2185 default: return NULL;
2186 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2187 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2188 case MVT::v2f32:
2189 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2190 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2191 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2192 case MVT::v4f32:
2193 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2194 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002195 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002196 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2197 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2198 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002199 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002200
2201 case ISD::INTRINSIC_VOID:
2202 case ISD::INTRINSIC_W_CHAIN: {
2203 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002204 switch (IntNo) {
2205 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002206 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002207
Bob Wilson621f1952010-03-23 05:25:43 +00002208 case Intrinsic::arm_neon_vld1: {
2209 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2210 ARM::VLD1d32, ARM::VLD1d64 };
2211 unsigned QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
2212 ARM::VLD1q32, ARM::VLD1q64 };
2213 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2214 }
2215
Bob Wilson31fb12f2009-08-26 17:39:53 +00002216 case Intrinsic::arm_neon_vld2: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002217 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
Bob Wilson621f1952010-03-23 05:25:43 +00002218 ARM::VLD2d32, ARM::VLD1q64 };
Bob Wilson3e36f132009-10-14 17:28:52 +00002219 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002220 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002221 }
2222
2223 case Intrinsic::arm_neon_vld3: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002224 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002225 ARM::VLD3d32, ARM::VLD1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002226 unsigned QOpcodes0[] = { ARM::VLD3q8_UPD,
2227 ARM::VLD3q16_UPD,
2228 ARM::VLD3q32_UPD };
2229 unsigned QOpcodes1[] = { ARM::VLD3q8odd_UPD,
2230 ARM::VLD3q16odd_UPD,
2231 ARM::VLD3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002232 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002233 }
2234
2235 case Intrinsic::arm_neon_vld4: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002236 unsigned DOpcodes[] = { ARM::VLD4d8, ARM::VLD4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002237 ARM::VLD4d32, ARM::VLD1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002238 unsigned QOpcodes0[] = { ARM::VLD4q8_UPD,
2239 ARM::VLD4q16_UPD,
2240 ARM::VLD4q32_UPD };
2241 unsigned QOpcodes1[] = { ARM::VLD4q8odd_UPD,
2242 ARM::VLD4q16odd_UPD,
2243 ARM::VLD4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002244 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002245 }
2246
Bob Wilson243fcc52009-09-01 04:26:28 +00002247 case Intrinsic::arm_neon_vld2lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002248 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002249 unsigned QOpcodes0[] = { ARM::VLD2LNq16, ARM::VLD2LNq32 };
2250 unsigned QOpcodes1[] = { ARM::VLD2LNq16odd, ARM::VLD2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002251 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002252 }
2253
2254 case Intrinsic::arm_neon_vld3lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002255 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002256 unsigned QOpcodes0[] = { ARM::VLD3LNq16, ARM::VLD3LNq32 };
2257 unsigned QOpcodes1[] = { ARM::VLD3LNq16odd, ARM::VLD3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002258 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002259 }
2260
2261 case Intrinsic::arm_neon_vld4lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002262 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002263 unsigned QOpcodes0[] = { ARM::VLD4LNq16, ARM::VLD4LNq32 };
2264 unsigned QOpcodes1[] = { ARM::VLD4LNq16odd, ARM::VLD4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002265 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002266 }
2267
Bob Wilson11d98992010-03-23 06:20:33 +00002268 case Intrinsic::arm_neon_vst1: {
2269 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2270 ARM::VST1d32, ARM::VST1d64 };
2271 unsigned QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
2272 ARM::VST1q32, ARM::VST1q64 };
2273 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2274 }
2275
Bob Wilson31fb12f2009-08-26 17:39:53 +00002276 case Intrinsic::arm_neon_vst2: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002277 unsigned DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
Bob Wilson11d98992010-03-23 06:20:33 +00002278 ARM::VST2d32, ARM::VST1q64 };
Bob Wilson24f995d2009-10-14 18:32:29 +00002279 unsigned QOpcodes[] = { ARM::VST2q8, ARM::VST2q16, ARM::VST2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002280 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002281 }
2282
2283 case Intrinsic::arm_neon_vst3: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002284 unsigned DOpcodes[] = { ARM::VST3d8, ARM::VST3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002285 ARM::VST3d32, ARM::VST1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002286 unsigned QOpcodes0[] = { ARM::VST3q8_UPD,
2287 ARM::VST3q16_UPD,
2288 ARM::VST3q32_UPD };
2289 unsigned QOpcodes1[] = { ARM::VST3q8odd_UPD,
2290 ARM::VST3q16odd_UPD,
2291 ARM::VST3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002292 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002293 }
2294
2295 case Intrinsic::arm_neon_vst4: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002296 unsigned DOpcodes[] = { ARM::VST4d8, ARM::VST4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002297 ARM::VST4d32, ARM::VST1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002298 unsigned QOpcodes0[] = { ARM::VST4q8_UPD,
2299 ARM::VST4q16_UPD,
2300 ARM::VST4q32_UPD };
2301 unsigned QOpcodes1[] = { ARM::VST4q8odd_UPD,
2302 ARM::VST4q16odd_UPD,
2303 ARM::VST4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002304 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002305 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002306
2307 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002308 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002309 unsigned QOpcodes0[] = { ARM::VST2LNq16, ARM::VST2LNq32 };
2310 unsigned QOpcodes1[] = { ARM::VST2LNq16odd, ARM::VST2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002311 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002312 }
2313
2314 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002315 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002316 unsigned QOpcodes0[] = { ARM::VST3LNq16, ARM::VST3LNq32 };
2317 unsigned QOpcodes1[] = { ARM::VST3LNq16odd, ARM::VST3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002318 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002319 }
2320
2321 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002322 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002323 unsigned QOpcodes0[] = { ARM::VST4LNq16, ARM::VST4LNq32 };
2324 unsigned QOpcodes1[] = { ARM::VST4LNq16odd, ARM::VST4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002325 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002326 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002327 }
Bob Wilson429009b2010-05-06 16:05:26 +00002328 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002329 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002330
Bob Wilson429009b2010-05-06 16:05:26 +00002331 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002332 return SelectConcatVector(N);
2333 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002334
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002335 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002336}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002337
Bob Wilson224c2442009-05-19 05:53:42 +00002338bool ARMDAGToDAGISel::
2339SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2340 std::vector<SDValue> &OutOps) {
2341 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002342 // Require the address to be in a register. That is safe for all ARM
2343 // variants and it is hard to do anything much smarter without knowing
2344 // how the operand is used.
2345 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002346 return false;
2347}
2348
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002349/// createARMISelDag - This pass converts a legalized DAG into a
2350/// ARM-specific DAG, ready for instruction scheduling.
2351///
Bob Wilson522ce972009-09-28 14:30:20 +00002352FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2353 CodeGenOpt::Level OptLevel) {
2354 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002355}
Evan Chengde8aa4e2010-05-05 18:28:36 +00002356
2357/// ModelWithRegSequence - Return true if isel should use REG_SEQUENCE to model
2358/// operations involving sub-registers.
2359bool llvm::ModelWithRegSequence() {
2360 return UseRegSeq;
2361}