blob: 7f73556a244ead8751e656f577f7c5de2f6731ab [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);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000186};
Evan Chenga8e29892007-01-19 07:51:42 +0000187}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000188
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000189/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
190/// operand. If so Imm will receive the 32-bit value.
191static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
192 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
193 Imm = cast<ConstantSDNode>(N)->getZExtValue();
194 return true;
195 }
196 return false;
197}
198
199// isInt32Immediate - This method tests to see if a constant operand.
200// If so Imm will receive the 32 bit value.
201static bool isInt32Immediate(SDValue N, unsigned &Imm) {
202 return isInt32Immediate(N.getNode(), Imm);
203}
204
205// isOpcWithIntImmediate - This method tests to see if the node is a specific
206// opcode and that it has a immediate integer right operand.
207// If so Imm will receive the 32 bit value.
208static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
209 return N->getOpcode() == Opc &&
210 isInt32Immediate(N->getOperand(1).getNode(), Imm);
211}
212
213
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000214bool ARMDAGToDAGISel::SelectShifterOperandReg(SDNode *Op,
Evan Cheng055b0312009-06-29 07:51:04 +0000215 SDValue N,
216 SDValue &BaseReg,
217 SDValue &ShReg,
218 SDValue &Opc) {
219 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
220
221 // Don't match base register only case. That is matched to a separate
222 // lower complexity pattern with explicit register operand.
223 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000224
Evan Cheng055b0312009-06-29 07:51:04 +0000225 BaseReg = N.getOperand(0);
226 unsigned ShImmVal = 0;
227 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000228 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000229 ShImmVal = RHS->getZExtValue() & 31;
230 } else {
231 ShReg = N.getOperand(1);
232 }
233 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000234 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000235 return true;
236}
237
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000238bool ARMDAGToDAGISel::SelectAddrMode2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000239 SDValue &Base, SDValue &Offset,
240 SDValue &Opc) {
Evan Chenga13fd102007-03-13 21:05:54 +0000241 if (N.getOpcode() == ISD::MUL) {
242 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
243 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000244 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000245 if (RHSC & 1) {
246 RHSC = RHSC & ~1;
247 ARM_AM::AddrOpc AddSub = ARM_AM::add;
248 if (RHSC < 0) {
249 AddSub = ARM_AM::sub;
250 RHSC = - RHSC;
251 }
252 if (isPowerOf2_32(RHSC)) {
253 unsigned ShAmt = Log2_32(RHSC);
254 Base = Offset = N.getOperand(0);
255 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
256 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000257 MVT::i32);
Evan Chenga13fd102007-03-13 21:05:54 +0000258 return true;
259 }
260 }
261 }
262 }
263
Evan Chenga8e29892007-01-19 07:51:42 +0000264 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
265 Base = N;
266 if (N.getOpcode() == ISD::FrameIndex) {
267 int FI = cast<FrameIndexSDNode>(N)->getIndex();
268 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000269 } else if (N.getOpcode() == ARMISD::Wrapper &&
270 !(Subtarget->useMovt() &&
271 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000272 Base = N.getOperand(0);
273 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000274 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000275 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
276 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000277 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000278 return true;
279 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000280
Evan Chenga8e29892007-01-19 07:51:42 +0000281 // Match simple R +/- imm12 operands.
282 if (N.getOpcode() == ISD::ADD)
283 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000284 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000285 if ((RHSC >= 0 && RHSC < 0x1000) ||
286 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000287 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000288 if (Base.getOpcode() == ISD::FrameIndex) {
289 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
290 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
291 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000292 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000293
294 ARM_AM::AddrOpc AddSub = ARM_AM::add;
295 if (RHSC < 0) {
296 AddSub = ARM_AM::sub;
297 RHSC = - RHSC;
298 }
299 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000300 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000301 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000302 return true;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000303 }
Evan Chenga8e29892007-01-19 07:51:42 +0000304 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000305
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000306 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000307 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
308 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
309 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000310
Evan Chenga8e29892007-01-19 07:51:42 +0000311 Base = N.getOperand(0);
312 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000313
Evan Chenga8e29892007-01-19 07:51:42 +0000314 if (ShOpcVal != ARM_AM::no_shift) {
315 // Check to see if the RHS of the shift is a constant, if not, we can't fold
316 // it.
317 if (ConstantSDNode *Sh =
318 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000319 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000320 Offset = N.getOperand(1).getOperand(0);
321 } else {
322 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000323 }
324 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000325
Evan Chenga8e29892007-01-19 07:51:42 +0000326 // Try matching (R shl C) + (R).
327 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
328 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
329 if (ShOpcVal != ARM_AM::no_shift) {
330 // Check to see if the RHS of the shift is a constant, if not, we can't
331 // fold it.
332 if (ConstantSDNode *Sh =
333 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000334 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000335 Offset = N.getOperand(0).getOperand(0);
336 Base = N.getOperand(1);
337 } else {
338 ShOpcVal = ARM_AM::no_shift;
339 }
340 }
341 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000342
Evan Chenga8e29892007-01-19 07:51:42 +0000343 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000344 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000345 return true;
346}
347
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000348bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000349 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000350 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000351 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
352 ? cast<LoadSDNode>(Op)->getAddressingMode()
353 : cast<StoreSDNode>(Op)->getAddressingMode();
354 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
355 ? ARM_AM::add : ARM_AM::sub;
356 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000357 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000358 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000359 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000360 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
361 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000362 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000363 return true;
364 }
365 }
366
367 Offset = N;
368 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
369 unsigned ShAmt = 0;
370 if (ShOpcVal != ARM_AM::no_shift) {
371 // Check to see if the RHS of the shift is a constant, if not, we can't fold
372 // it.
373 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000374 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000375 Offset = N.getOperand(0);
376 } else {
377 ShOpcVal = ARM_AM::no_shift;
378 }
379 }
380
381 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000382 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000383 return true;
384}
385
Evan Chenga8e29892007-01-19 07:51:42 +0000386
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000387bool ARMDAGToDAGISel::SelectAddrMode3(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000388 SDValue &Base, SDValue &Offset,
389 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000390 if (N.getOpcode() == ISD::SUB) {
391 // X - C is canonicalize to X + -C, no need to handle it here.
392 Base = N.getOperand(0);
393 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000394 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000395 return true;
396 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000397
Evan Chenga8e29892007-01-19 07:51:42 +0000398 if (N.getOpcode() != ISD::ADD) {
399 Base = N;
400 if (N.getOpcode() == ISD::FrameIndex) {
401 int FI = cast<FrameIndexSDNode>(N)->getIndex();
402 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
403 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000404 Offset = CurDAG->getRegister(0, MVT::i32);
405 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000406 return true;
407 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000408
Evan Chenga8e29892007-01-19 07:51:42 +0000409 // If the RHS is +/- imm8, fold into addr mode.
410 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000411 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000412 if ((RHSC >= 0 && RHSC < 256) ||
413 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000414 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000415 if (Base.getOpcode() == ISD::FrameIndex) {
416 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
417 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
418 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000419 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000420
421 ARM_AM::AddrOpc AddSub = ARM_AM::add;
422 if (RHSC < 0) {
423 AddSub = ARM_AM::sub;
424 RHSC = - RHSC;
425 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000426 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000427 return true;
428 }
429 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000430
Evan Chenga8e29892007-01-19 07:51:42 +0000431 Base = N.getOperand(0);
432 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000433 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000434 return true;
435}
436
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000437bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000438 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000439 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000440 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
441 ? cast<LoadSDNode>(Op)->getAddressingMode()
442 : cast<StoreSDNode>(Op)->getAddressingMode();
443 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
444 ? ARM_AM::add : ARM_AM::sub;
445 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000446 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000447 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000448 Offset = CurDAG->getRegister(0, MVT::i32);
449 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000450 return true;
451 }
452 }
453
454 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000455 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000456 return true;
457}
458
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000459bool ARMDAGToDAGISel::SelectAddrMode4(SDNode *Op, SDValue N,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000460 SDValue &Addr, SDValue &Mode) {
461 Addr = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000462 Mode = CurDAG->getTargetConstant(0, MVT::i32);
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000463 return true;
464}
Evan Chenga8e29892007-01-19 07:51:42 +0000465
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000466bool ARMDAGToDAGISel::SelectAddrMode5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000467 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000468 if (N.getOpcode() != ISD::ADD) {
469 Base = N;
470 if (N.getOpcode() == ISD::FrameIndex) {
471 int FI = cast<FrameIndexSDNode>(N)->getIndex();
472 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000473 } else if (N.getOpcode() == ARMISD::Wrapper &&
474 !(Subtarget->useMovt() &&
475 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000476 Base = N.getOperand(0);
477 }
478 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000479 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000480 return true;
481 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000482
Evan Chenga8e29892007-01-19 07:51:42 +0000483 // If the RHS is +/- imm8, fold into addr mode.
484 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000485 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000486 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
487 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000488 if ((RHSC >= 0 && RHSC < 256) ||
489 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000490 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000491 if (Base.getOpcode() == ISD::FrameIndex) {
492 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
493 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
494 }
495
496 ARM_AM::AddrOpc AddSub = ARM_AM::add;
497 if (RHSC < 0) {
498 AddSub = ARM_AM::sub;
499 RHSC = - RHSC;
500 }
501 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000502 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000503 return true;
504 }
505 }
506 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000507
Evan Chenga8e29892007-01-19 07:51:42 +0000508 Base = N;
509 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000510 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000511 return true;
512}
513
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000514bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Op, SDValue N,
Bob Wilson226036e2010-03-20 22:13:40 +0000515 SDValue &Addr, SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000516 Addr = N;
Jim Grosbach8a5ec862009-11-07 21:25:39 +0000517 // Default to no alignment.
518 Align = CurDAG->getTargetConstant(0, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000519 return true;
520}
521
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000522bool ARMDAGToDAGISel::SelectAddrModePC(SDNode *Op, SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000523 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000524 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
525 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000526 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000527 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000528 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000529 return true;
530 }
531 return false;
532}
533
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000534bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000535 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000536 // FIXME dl should come from the parent load or store, not the address
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000537 DebugLoc dl = Op->getDebugLoc();
Evan Chengc38f2bc2007-01-23 22:59:13 +0000538 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000539 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
540 if (!NC || NC->getZExtValue() != 0)
541 return false;
542
543 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000544 return true;
545 }
546
Evan Chenga8e29892007-01-19 07:51:42 +0000547 Base = N.getOperand(0);
548 Offset = N.getOperand(1);
549 return true;
550}
551
Evan Cheng79d43262007-01-24 02:21:22 +0000552bool
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000553ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000554 unsigned Scale, SDValue &Base,
555 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000556 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000557 SDValue TmpBase, TmpOffImm;
Evan Cheng79d43262007-01-24 02:21:22 +0000558 if (SelectThumbAddrModeSP(Op, N, TmpBase, TmpOffImm))
559 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000560 if (N.getOpcode() == ARMISD::Wrapper &&
561 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
562 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000563 }
564
Evan Chenga8e29892007-01-19 07:51:42 +0000565 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000566 if (N.getOpcode() == ARMISD::Wrapper &&
567 !(Subtarget->useMovt() &&
568 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
569 Base = N.getOperand(0);
570 } else
571 Base = N;
572
Owen Anderson825b72b2009-08-11 20:47:22 +0000573 Offset = CurDAG->getRegister(0, MVT::i32);
574 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000575 return true;
576 }
577
Evan Chengad0e4652007-02-06 00:22:06 +0000578 // Thumb does not have [sp, r] address mode.
579 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
580 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
581 if ((LHSR && LHSR->getReg() == ARM::SP) ||
582 (RHSR && RHSR->getReg() == ARM::SP)) {
583 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000584 Offset = CurDAG->getRegister(0, MVT::i32);
585 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000586 return true;
587 }
588
Evan Chenga8e29892007-01-19 07:51:42 +0000589 // If the RHS is + imm5 * scale, fold into addr mode.
590 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000591 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000592 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
593 RHSC /= Scale;
594 if (RHSC >= 0 && RHSC < 32) {
595 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000596 Offset = CurDAG->getRegister(0, MVT::i32);
597 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000598 return true;
599 }
600 }
601 }
602
Evan Chengc38f2bc2007-01-23 22:59:13 +0000603 Base = N.getOperand(0);
604 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000605 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000606 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000607}
608
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000609bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000610 SDValue &Base, SDValue &OffImm,
611 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000612 return SelectThumbAddrModeRI5(Op, N, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000613}
614
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000615bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000616 SDValue &Base, SDValue &OffImm,
617 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000618 return SelectThumbAddrModeRI5(Op, N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000619}
620
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000621bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000622 SDValue &Base, SDValue &OffImm,
623 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000624 return SelectThumbAddrModeRI5(Op, N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000625}
626
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000627bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000628 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000629 if (N.getOpcode() == ISD::FrameIndex) {
630 int FI = cast<FrameIndexSDNode>(N)->getIndex();
631 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000632 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000633 return true;
634 }
Evan Cheng79d43262007-01-24 02:21:22 +0000635
Evan Chengad0e4652007-02-06 00:22:06 +0000636 if (N.getOpcode() != ISD::ADD)
637 return false;
638
639 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000640 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
641 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000642 // If the RHS is + imm8 * scale, fold into addr mode.
643 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000644 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000645 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
646 RHSC >>= 2;
647 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000648 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000649 if (Base.getOpcode() == ISD::FrameIndex) {
650 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
651 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
652 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000653 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000654 return true;
655 }
656 }
657 }
658 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000659
Evan Chenga8e29892007-01-19 07:51:42 +0000660 return false;
661}
662
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000663bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000664 SDValue &BaseReg,
665 SDValue &Opc) {
666 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
667
668 // Don't match base register only case. That is matched to a separate
669 // lower complexity pattern with explicit register operand.
670 if (ShOpcVal == ARM_AM::no_shift) return false;
671
672 BaseReg = N.getOperand(0);
673 unsigned ShImmVal = 0;
674 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
675 ShImmVal = RHS->getZExtValue() & 31;
676 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
677 return true;
678 }
679
680 return false;
681}
682
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000683bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000684 SDValue &Base, SDValue &OffImm) {
685 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000686
Evan Cheng3a214252009-08-11 08:52:18 +0000687 // Base only.
688 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000689 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000690 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000691 int FI = cast<FrameIndexSDNode>(N)->getIndex();
692 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000693 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000694 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000695 } else if (N.getOpcode() == ARMISD::Wrapper &&
696 !(Subtarget->useMovt() &&
697 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000698 Base = N.getOperand(0);
699 if (Base.getOpcode() == ISD::TargetConstantPool)
700 return false; // We want to select t2LDRpci instead.
701 } else
702 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000703 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000704 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000705 }
Evan Cheng055b0312009-06-29 07:51:04 +0000706
707 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Evan Cheng3a214252009-08-11 08:52:18 +0000708 if (SelectT2AddrModeImm8(Op, N, Base, OffImm))
709 // Let t2LDRi8 handle (R - imm8).
710 return false;
711
Evan Cheng055b0312009-06-29 07:51:04 +0000712 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000713 if (N.getOpcode() == ISD::SUB)
714 RHSC = -RHSC;
715
716 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +0000717 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +0000718 if (Base.getOpcode() == ISD::FrameIndex) {
719 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
720 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
721 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000722 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000723 return true;
724 }
725 }
726
Evan Cheng3a214252009-08-11 08:52:18 +0000727 // Base only.
728 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000729 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000730 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000731}
732
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000733bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000734 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +0000735 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +0000736 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +0000737 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
738 int RHSC = (int)RHS->getSExtValue();
739 if (N.getOpcode() == ISD::SUB)
740 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +0000741
Evan Cheng3a214252009-08-11 08:52:18 +0000742 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
743 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +0000744 if (Base.getOpcode() == ISD::FrameIndex) {
745 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
746 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
747 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000748 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +0000749 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000750 }
Evan Cheng055b0312009-06-29 07:51:04 +0000751 }
752 }
753
754 return false;
755}
756
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000757bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000758 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000759 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +0000760 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
761 ? cast<LoadSDNode>(Op)->getAddressingMode()
762 : cast<StoreSDNode>(Op)->getAddressingMode();
763 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
764 int RHSC = (int)RHS->getZExtValue();
765 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +0000766 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +0000767 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
768 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000769 return true;
770 }
771 }
772
773 return false;
774}
775
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000776bool ARMDAGToDAGISel::SelectT2AddrModeImm8s4(SDNode *Op, SDValue N,
David Goodwin6647cea2009-06-30 22:50:01 +0000777 SDValue &Base, SDValue &OffImm) {
778 if (N.getOpcode() == ISD::ADD) {
779 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
780 int RHSC = (int)RHS->getZExtValue();
Evan Cheng5c874172009-07-09 22:21:59 +0000781 if (((RHSC & 0x3) == 0) &&
782 ((RHSC >= 0 && RHSC < 0x400) || (RHSC < 0 && RHSC > -0x400))) { // 8 bits.
David Goodwin6647cea2009-06-30 22:50:01 +0000783 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000784 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000785 return true;
786 }
787 }
788 } else if (N.getOpcode() == ISD::SUB) {
789 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
790 int RHSC = (int)RHS->getZExtValue();
791 if (((RHSC & 0x3) == 0) && (RHSC >= 0 && RHSC < 0x400)) { // 8 bits.
792 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 }
798
799 return false;
800}
801
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000802bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000803 SDValue &Base,
804 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +0000805 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
806 if (N.getOpcode() != ISD::ADD)
807 return false;
Evan Cheng055b0312009-06-29 07:51:04 +0000808
Evan Cheng3a214252009-08-11 08:52:18 +0000809 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
810 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
811 int RHSC = (int)RHS->getZExtValue();
812 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
813 return false;
814 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +0000815 return false;
816 }
817
Evan Cheng055b0312009-06-29 07:51:04 +0000818 // Look for (R + R) or (R + (R << [1,2,3])).
819 unsigned ShAmt = 0;
820 Base = N.getOperand(0);
821 OffReg = N.getOperand(1);
822
823 // Swap if it is ((R << c) + R).
824 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
825 if (ShOpcVal != ARM_AM::lsl) {
826 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
827 if (ShOpcVal == ARM_AM::lsl)
828 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +0000829 }
830
Evan Cheng055b0312009-06-29 07:51:04 +0000831 if (ShOpcVal == ARM_AM::lsl) {
832 // Check to see if the RHS of the shift is a constant, if not, we can't fold
833 // it.
834 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
835 ShAmt = Sh->getZExtValue();
836 if (ShAmt >= 4) {
837 ShAmt = 0;
838 ShOpcVal = ARM_AM::no_shift;
839 } else
840 OffReg = OffReg.getOperand(0);
841 } else {
842 ShOpcVal = ARM_AM::no_shift;
843 }
David Goodwin7ecc8502009-07-15 15:50:19 +0000844 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000845
Owen Anderson825b72b2009-08-11 20:47:22 +0000846 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000847
848 return true;
849}
850
851//===--------------------------------------------------------------------===//
852
Evan Chengee568cf2007-07-05 07:15:27 +0000853/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +0000854static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000855 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +0000856}
857
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000858SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
859 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +0000860 ISD::MemIndexedMode AM = LD->getAddressingMode();
861 if (AM == ISD::UNINDEXED)
862 return NULL;
863
Owen Andersone50ed302009-08-10 22:56:29 +0000864 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +0000865 SDValue Offset, AMOpc;
866 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
867 unsigned Opcode = 0;
868 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000869 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000870 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000871 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
872 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +0000873 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000874 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000875 Match = true;
876 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
877 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
878 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +0000879 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000880 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000881 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000882 Match = true;
883 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
884 }
885 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000886 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000887 Match = true;
888 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
889 }
890 }
891 }
892
893 if (Match) {
894 SDValue Chain = LD->getChain();
895 SDValue Base = LD->getBasePtr();
896 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000897 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000898 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000899 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +0000900 }
901
902 return NULL;
903}
904
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000905SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
906 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000907 ISD::MemIndexedMode AM = LD->getAddressingMode();
908 if (AM == ISD::UNINDEXED)
909 return NULL;
910
Owen Andersone50ed302009-08-10 22:56:29 +0000911 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +0000912 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000913 SDValue Offset;
914 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
915 unsigned Opcode = 0;
916 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000917 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000918 switch (LoadedVT.getSimpleVT().SimpleTy) {
919 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000920 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
921 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000922 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000923 if (isSExtLd)
924 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
925 else
926 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000927 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000928 case MVT::i8:
929 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000930 if (isSExtLd)
931 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
932 else
933 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000934 break;
935 default:
936 return NULL;
937 }
938 Match = true;
939 }
940
941 if (Match) {
942 SDValue Chain = LD->getChain();
943 SDValue Base = LD->getBasePtr();
944 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000945 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000946 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000947 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000948 }
949
950 return NULL;
951}
952
Evan Cheng603afbf2010-05-10 17:34:18 +0000953/// PairDRegs - Form a quad register from a pair of D registers.
954///
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000955SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
956 DebugLoc dl = V0.getNode()->getDebugLoc();
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000957 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
958 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +0000959 if (llvm::ModelWithRegSequence()) {
Evan Cheng94cc6d32010-05-04 20:39:49 +0000960 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
961 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
962 }
963 SDValue Undef =
964 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0);
Chris Lattner518bb532010-02-09 19:54:29 +0000965 SDNode *Pair = CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000966 VT, Undef, V0, SubReg0);
Chris Lattner518bb532010-02-09 19:54:29 +0000967 return CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000968 VT, SDValue(Pair, 0), V1, SubReg1);
969}
970
Evan Cheng603afbf2010-05-10 17:34:18 +0000971/// PairDRegs - Form a quad register pair from a pair of Q registers.
972///
973SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
974 DebugLoc dl = V0.getNode()->getDebugLoc();
975 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::QSUBREG_0, MVT::i32);
976 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::QSUBREG_1, MVT::i32);
977 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
978 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
979}
980
981/// QuadDRegs - Form a octo register from a quad of D registers.
982///
983SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
984 SDValue V2, SDValue V3) {
985 DebugLoc dl = V0.getNode()->getDebugLoc();
986 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
987 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
988 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::DSUBREG_2, MVT::i32);
989 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::DSUBREG_3, MVT::i32);
990 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
991 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
992}
993
Bob Wilsona7c397c2009-10-14 16:19:03 +0000994/// GetNEONSubregVT - Given a type for a 128-bit NEON vector, return the type
995/// for a 64-bit subregister of the vector.
996static EVT GetNEONSubregVT(EVT VT) {
997 switch (VT.getSimpleVT().SimpleTy) {
998 default: llvm_unreachable("unhandled NEON type");
999 case MVT::v16i8: return MVT::v8i8;
1000 case MVT::v8i16: return MVT::v4i16;
1001 case MVT::v4f32: return MVT::v2f32;
1002 case MVT::v4i32: return MVT::v2i32;
1003 case MVT::v2i64: return MVT::v1i64;
1004 }
1005}
1006
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001007SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001008 unsigned *DOpcodes, unsigned *QOpcodes0,
1009 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001010 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001011 DebugLoc dl = N->getDebugLoc();
1012
Bob Wilson226036e2010-03-20 22:13:40 +00001013 SDValue MemAddr, Align;
1014 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001015 return NULL;
1016
1017 SDValue Chain = N->getOperand(0);
1018 EVT VT = N->getValueType(0);
1019 bool is64BitVector = VT.is64BitVector();
1020
1021 unsigned OpcodeIndex;
1022 switch (VT.getSimpleVT().SimpleTy) {
1023 default: llvm_unreachable("unhandled vld type");
1024 // Double-register operations:
1025 case MVT::v8i8: OpcodeIndex = 0; break;
1026 case MVT::v4i16: OpcodeIndex = 1; break;
1027 case MVT::v2f32:
1028 case MVT::v2i32: OpcodeIndex = 2; break;
1029 case MVT::v1i64: OpcodeIndex = 3; break;
1030 // Quad-register operations:
1031 case MVT::v16i8: OpcodeIndex = 0; break;
1032 case MVT::v8i16: OpcodeIndex = 1; break;
1033 case MVT::v4f32:
1034 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001035 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001036 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001037 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001038 }
1039
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001040 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001041 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson3e36f132009-10-14 17:28:52 +00001042 if (is64BitVector) {
1043 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001044 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson3e36f132009-10-14 17:28:52 +00001045 std::vector<EVT> ResTys(NumVecs, VT);
1046 ResTys.push_back(MVT::Other);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001047 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
1048 if (!llvm::ModelWithRegSequence() || NumVecs < 2)
1049 return VLd;
1050
1051 assert(NumVecs <= 4);
1052 SDValue V0 = SDValue(VLd, 0);
1053 SDValue V1 = SDValue(VLd, 1);
1054 SDValue RegSeq;
1055
1056 if (NumVecs == 2)
1057 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1058 else {
1059 SDValue V2 = SDValue(VLd, 2);
1060 SDValue V3 = (NumVecs == 3)
1061 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1062 : SDValue(VLd, 3);
1063 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1064 }
1065
1066 SDValue D0 = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, VT, RegSeq);
1067 ReplaceUses(SDValue(N, 0), D0);
1068 SDValue D1 = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, VT, RegSeq);
1069 ReplaceUses(SDValue(N, 1), D1);
1070
1071 if (NumVecs > 2) {
1072 SDValue D2 = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_2, dl, VT, RegSeq);
1073 ReplaceUses(SDValue(N, 2), D2);
1074 }
1075 if (NumVecs > 3) {
1076 SDValue D3 = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_3, dl, VT, RegSeq);
1077 ReplaceUses(SDValue(N, 3), D3);
1078 }
1079 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, NumVecs));
1080 return NULL;
Bob Wilson3e36f132009-10-14 17:28:52 +00001081 }
1082
1083 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson621f1952010-03-23 05:25:43 +00001084 if (NumVecs <= 2) {
1085 // Quad registers are directly supported for VLD1 and VLD2,
1086 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001087 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001088 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson621f1952010-03-23 05:25:43 +00001089 std::vector<EVT> ResTys(2 * NumVecs, RegVT);
Bob Wilson3e36f132009-10-14 17:28:52 +00001090 ResTys.push_back(MVT::Other);
Bob Wilson226036e2010-03-20 22:13:40 +00001091 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson621f1952010-03-23 05:25:43 +00001092 Chain = SDValue(VLd, 2 * NumVecs);
Bob Wilson3e36f132009-10-14 17:28:52 +00001093
1094 // Combine the even and odd subregs to produce the result.
Evan Cheng603afbf2010-05-10 17:34:18 +00001095 if (llvm::ModelWithRegSequence()) {
1096 if (NumVecs == 1) {
1097 SDNode *Q = PairDRegs(VT, SDValue(VLd, 0), SDValue(VLd, 1));
1098 ReplaceUses(SDValue(N, 0), SDValue(Q, 0));
1099 } else {
1100 SDValue QQ = SDValue(QuadDRegs(MVT::v4i64,
1101 SDValue(VLd, 0), SDValue(VLd, 1),
1102 SDValue(VLd, 2), SDValue(VLd, 3)), 0);
1103 SDValue Q0 = CurDAG->getTargetExtractSubreg(ARM::QSUBREG_0, dl, VT, QQ);
1104 SDValue Q1 = CurDAG->getTargetExtractSubreg(ARM::QSUBREG_1, dl, VT, QQ);
1105 ReplaceUses(SDValue(N, 0), Q0);
1106 ReplaceUses(SDValue(N, 1), Q1);
1107 }
1108 } else {
1109 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1110 SDNode *Q = PairDRegs(VT, SDValue(VLd, 2*Vec), SDValue(VLd, 2*Vec+1));
1111 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1112 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001113 }
1114 } else {
1115 // Otherwise, quad registers are loaded with two separate instructions,
1116 // where one loads the even registers and the other loads the odd registers.
1117
Bob Wilson3e36f132009-10-14 17:28:52 +00001118 std::vector<EVT> ResTys(NumVecs, RegVT);
1119 ResTys.push_back(MemAddr.getValueType());
1120 ResTys.push_back(MVT::Other);
1121
Bob Wilson24f995d2009-10-14 18:32:29 +00001122 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001123 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001124 const SDValue OpsA[] = { MemAddr, Align, Reg0, Pred, Reg0, Chain };
1125 SDNode *VLdA = CurDAG->getMachineNode(Opc, dl, ResTys, OpsA, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001126 Chain = SDValue(VLdA, NumVecs+1);
1127
Bob Wilson24f995d2009-10-14 18:32:29 +00001128 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001129 Opc = QOpcodes1[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001130 const SDValue OpsB[] = { SDValue(VLdA, NumVecs),
1131 Align, Reg0, Pred, Reg0, Chain };
1132 SDNode *VLdB = CurDAG->getMachineNode(Opc, dl, ResTys, OpsB, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001133 Chain = SDValue(VLdB, NumVecs+1);
1134
1135 // Combine the even and odd subregs to produce the result.
1136 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1137 SDNode *Q = PairDRegs(VT, SDValue(VLdA, Vec), SDValue(VLdB, Vec));
1138 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1139 }
1140 }
1141 ReplaceUses(SDValue(N, NumVecs), Chain);
1142 return NULL;
1143}
1144
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001145SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001146 unsigned *DOpcodes, unsigned *QOpcodes0,
1147 unsigned *QOpcodes1) {
Bob Wilson11d98992010-03-23 06:20:33 +00001148 assert(NumVecs >=1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001149 DebugLoc dl = N->getDebugLoc();
1150
Bob Wilson226036e2010-03-20 22:13:40 +00001151 SDValue MemAddr, Align;
1152 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001153 return NULL;
1154
1155 SDValue Chain = N->getOperand(0);
1156 EVT VT = N->getOperand(3).getValueType();
1157 bool is64BitVector = VT.is64BitVector();
1158
1159 unsigned OpcodeIndex;
1160 switch (VT.getSimpleVT().SimpleTy) {
1161 default: llvm_unreachable("unhandled vst type");
1162 // Double-register operations:
1163 case MVT::v8i8: OpcodeIndex = 0; break;
1164 case MVT::v4i16: OpcodeIndex = 1; break;
1165 case MVT::v2f32:
1166 case MVT::v2i32: OpcodeIndex = 2; break;
1167 case MVT::v1i64: OpcodeIndex = 3; break;
1168 // Quad-register operations:
1169 case MVT::v16i8: OpcodeIndex = 0; break;
1170 case MVT::v8i16: OpcodeIndex = 1; break;
1171 case MVT::v4f32:
1172 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001173 case MVT::v2i64: OpcodeIndex = 3;
1174 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1175 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001176 }
1177
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001178 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001179 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001180
Bob Wilson226036e2010-03-20 22:13:40 +00001181 SmallVector<SDValue, 10> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001182 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001183 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001184
1185 if (is64BitVector) {
1186 unsigned Opc = DOpcodes[OpcodeIndex];
1187 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1188 Ops.push_back(N->getOperand(Vec+3));
Evan Chengac0869d2009-11-21 06:21:52 +00001189 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001190 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001191 Ops.push_back(Chain);
Bob Wilson226036e2010-03-20 22:13:40 +00001192 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+5);
Bob Wilson24f995d2009-10-14 18:32:29 +00001193 }
1194
1195 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson11d98992010-03-23 06:20:33 +00001196 if (NumVecs <= 2) {
1197 // Quad registers are directly supported for VST1 and VST2,
1198 // storing pairs of D regs.
Bob Wilson24f995d2009-10-14 18:32:29 +00001199 unsigned Opc = QOpcodes0[OpcodeIndex];
Evan Cheng603afbf2010-05-10 17:34:18 +00001200 if (llvm::ModelWithRegSequence() && NumVecs == 2) {
1201 // First extract the quad D registers.
1202 SDValue Q0 = N->getOperand(3);
1203 SDValue Q1 = N->getOperand(4);
1204
1205 // Form a QQ register.
1206 SDValue QQ = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
1207
1208 // Now extract the D registers back out.
Bob Wilson24f995d2009-10-14 18:32:29 +00001209 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001210 QQ));
Bob Wilson24f995d2009-10-14 18:32:29 +00001211 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001212 QQ));
1213 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_2, dl, RegVT,
1214 QQ));
1215 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_3, dl, RegVT,
1216 QQ));
1217 Ops.push_back(Pred);
1218 Ops.push_back(Reg0); // predicate register
1219 Ops.push_back(Chain);
1220 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 5 + 4);
1221 } else {
1222 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1223 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1224 N->getOperand(Vec+3)));
1225 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
1226 N->getOperand(Vec+3)));
1227 }
1228 Ops.push_back(Pred);
1229 Ops.push_back(Reg0); // predicate register
1230 Ops.push_back(Chain);
1231 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(),
1232 5 + 2 * NumVecs);
Bob Wilson24f995d2009-10-14 18:32:29 +00001233 }
Bob Wilson24f995d2009-10-14 18:32:29 +00001234 }
1235
1236 // Otherwise, quad registers are stored with two separate instructions,
1237 // where one stores the even registers and the other stores the odd registers.
1238
Bob Wilson226036e2010-03-20 22:13:40 +00001239 Ops.push_back(Reg0); // post-access address offset
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001240
Bob Wilson24f995d2009-10-14 18:32:29 +00001241 // Store the even subregs.
1242 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1243 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1244 N->getOperand(Vec+3)));
Evan Chengac0869d2009-11-21 06:21:52 +00001245 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001246 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001247 Ops.push_back(Chain);
1248 unsigned Opc = QOpcodes0[OpcodeIndex];
1249 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilson226036e2010-03-20 22:13:40 +00001250 MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001251 Chain = SDValue(VStA, 1);
1252
1253 // Store the odd subregs.
1254 Ops[0] = SDValue(VStA, 0); // MemAddr
1255 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
Bob Wilson226036e2010-03-20 22:13:40 +00001256 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
Bob Wilson24f995d2009-10-14 18:32:29 +00001257 N->getOperand(Vec+3));
Bob Wilson226036e2010-03-20 22:13:40 +00001258 Ops[NumVecs+5] = Chain;
Bob Wilson24f995d2009-10-14 18:32:29 +00001259 Opc = QOpcodes1[OpcodeIndex];
1260 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilson226036e2010-03-20 22:13:40 +00001261 MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001262 Chain = SDValue(VStB, 1);
1263 ReplaceUses(SDValue(N, 0), Chain);
1264 return NULL;
1265}
1266
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001267SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001268 unsigned NumVecs, unsigned *DOpcodes,
1269 unsigned *QOpcodes0,
1270 unsigned *QOpcodes1) {
1271 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001272 DebugLoc dl = N->getDebugLoc();
1273
Bob Wilson226036e2010-03-20 22:13:40 +00001274 SDValue MemAddr, Align;
1275 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001276 return NULL;
1277
1278 SDValue Chain = N->getOperand(0);
1279 unsigned Lane =
1280 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001281 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001282 bool is64BitVector = VT.is64BitVector();
1283
Bob Wilson96493442009-10-14 16:46:45 +00001284 // Quad registers are handled by load/store of subregs. Find the subreg info.
Bob Wilsona7c397c2009-10-14 16:19:03 +00001285 unsigned NumElts = 0;
1286 int SubregIdx = 0;
1287 EVT RegVT = VT;
1288 if (!is64BitVector) {
1289 RegVT = GetNEONSubregVT(VT);
1290 NumElts = RegVT.getVectorNumElements();
1291 SubregIdx = (Lane < NumElts) ? ARM::DSUBREG_0 : ARM::DSUBREG_1;
1292 }
1293
1294 unsigned OpcodeIndex;
1295 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001296 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001297 // Double-register operations:
1298 case MVT::v8i8: OpcodeIndex = 0; break;
1299 case MVT::v4i16: OpcodeIndex = 1; break;
1300 case MVT::v2f32:
1301 case MVT::v2i32: OpcodeIndex = 2; break;
1302 // Quad-register operations:
1303 case MVT::v8i16: OpcodeIndex = 0; break;
1304 case MVT::v4f32:
1305 case MVT::v4i32: OpcodeIndex = 1; break;
1306 }
1307
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001308 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001309 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001310
Bob Wilson226036e2010-03-20 22:13:40 +00001311 SmallVector<SDValue, 10> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001312 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001313 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001314
1315 unsigned Opc = 0;
1316 if (is64BitVector) {
1317 Opc = DOpcodes[OpcodeIndex];
1318 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1319 Ops.push_back(N->getOperand(Vec+3));
1320 } else {
1321 // Check if this is loading the even or odd subreg of a Q register.
1322 if (Lane < NumElts) {
1323 Opc = QOpcodes0[OpcodeIndex];
1324 } else {
1325 Lane -= NumElts;
1326 Opc = QOpcodes1[OpcodeIndex];
1327 }
1328 // Extract the subregs of the input vector.
1329 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1330 Ops.push_back(CurDAG->getTargetExtractSubreg(SubregIdx, dl, RegVT,
1331 N->getOperand(Vec+3)));
1332 }
1333 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001334 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001335 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001336 Ops.push_back(Chain);
1337
Bob Wilson96493442009-10-14 16:46:45 +00001338 if (!IsLoad)
Bob Wilson226036e2010-03-20 22:13:40 +00001339 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson96493442009-10-14 16:46:45 +00001340
Bob Wilsona7c397c2009-10-14 16:19:03 +00001341 std::vector<EVT> ResTys(NumVecs, RegVT);
1342 ResTys.push_back(MVT::Other);
1343 SDNode *VLdLn =
Bob Wilson226036e2010-03-20 22:13:40 +00001344 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), NumVecs+6);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001345 // For a 64-bit vector load to D registers, nothing more needs to be done.
1346 if (is64BitVector)
1347 return VLdLn;
1348
1349 // For 128-bit vectors, take the 64-bit results of the load and insert them
1350 // as subregs into the result.
1351 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1352 SDValue QuadVec = CurDAG->getTargetInsertSubreg(SubregIdx, dl, VT,
1353 N->getOperand(Vec+3),
1354 SDValue(VLdLn, Vec));
1355 ReplaceUses(SDValue(N, Vec), QuadVec);
1356 }
1357
1358 Chain = SDValue(VLdLn, NumVecs);
1359 ReplaceUses(SDValue(N, NumVecs), Chain);
1360 return NULL;
1361}
1362
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001363SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001364 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001365 if (!Subtarget->hasV6T2Ops())
1366 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001367
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001368 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1369 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1370
1371
1372 // For unsigned extracts, check for a shift right and mask
1373 unsigned And_imm = 0;
1374 if (N->getOpcode() == ISD::AND) {
1375 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1376
1377 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1378 if (And_imm & (And_imm + 1))
1379 return NULL;
1380
1381 unsigned Srl_imm = 0;
1382 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1383 Srl_imm)) {
1384 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1385
1386 unsigned Width = CountTrailingOnes_32(And_imm);
1387 unsigned LSB = Srl_imm;
1388 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1389 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1390 CurDAG->getTargetConstant(LSB, MVT::i32),
1391 CurDAG->getTargetConstant(Width, MVT::i32),
1392 getAL(CurDAG), Reg0 };
1393 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1394 }
1395 }
1396 return NULL;
1397 }
1398
1399 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001400 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001401 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001402 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1403 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001404 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001405 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1406 unsigned Width = 32 - Srl_imm;
1407 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001408 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001409 return NULL;
1410 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001411 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001412 CurDAG->getTargetConstant(LSB, MVT::i32),
1413 CurDAG->getTargetConstant(Width, MVT::i32),
1414 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001415 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001416 }
1417 }
1418 return NULL;
1419}
1420
Evan Cheng9ef48352009-11-20 00:54:03 +00001421SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001422SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001423 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1424 SDValue CPTmp0;
1425 SDValue CPTmp1;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001426 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001427 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1428 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1429 unsigned Opc = 0;
1430 switch (SOShOp) {
1431 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1432 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1433 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1434 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1435 default:
1436 llvm_unreachable("Unknown so_reg opcode!");
1437 break;
1438 }
1439 SDValue SOShImm =
1440 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1441 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1442 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001443 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001444 }
1445 return 0;
1446}
1447
1448SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001449SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001450 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1451 SDValue CPTmp0;
1452 SDValue CPTmp1;
1453 SDValue CPTmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001454 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001455 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1456 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001457 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001458 }
1459 return 0;
1460}
1461
1462SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001463SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001464 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1465 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1466 if (!T)
1467 return 0;
1468
1469 if (Predicate_t2_so_imm(TrueVal.getNode())) {
1470 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1471 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1472 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001473 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001474 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1475 }
1476 return 0;
1477}
1478
1479SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001480SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001481 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1482 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1483 if (!T)
1484 return 0;
1485
1486 if (Predicate_so_imm(TrueVal.getNode())) {
1487 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1488 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1489 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001490 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001491 ARM::MOVCCi, MVT::i32, Ops, 5);
1492 }
1493 return 0;
1494}
1495
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001496SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1497 EVT VT = N->getValueType(0);
1498 SDValue FalseVal = N->getOperand(0);
1499 SDValue TrueVal = N->getOperand(1);
1500 SDValue CC = N->getOperand(2);
1501 SDValue CCR = N->getOperand(3);
1502 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001503 assert(CC.getOpcode() == ISD::Constant);
1504 assert(CCR.getOpcode() == ISD::Register);
1505 ARMCC::CondCodes CCVal =
1506 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001507
1508 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1509 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1510 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1511 // Pattern complexity = 18 cost = 1 size = 0
1512 SDValue CPTmp0;
1513 SDValue CPTmp1;
1514 SDValue CPTmp2;
1515 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001516 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001517 CCVal, CCR, InFlag);
1518 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001519 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001520 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1521 if (Res)
1522 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001523 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001524 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001525 CCVal, CCR, InFlag);
1526 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001527 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001528 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1529 if (Res)
1530 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001531 }
1532
1533 // Pattern: (ARMcmov:i32 GPR:i32:$false,
1534 // (imm:i32)<<P:Predicate_so_imm>>:$true,
1535 // (imm:i32):$cc)
1536 // Emits: (MOVCCi:i32 GPR:i32:$false,
1537 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1538 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001539 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001540 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001541 CCVal, CCR, InFlag);
1542 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001543 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001544 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1545 if (Res)
1546 return Res;
1547 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001548 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001549 CCVal, CCR, InFlag);
1550 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001551 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001552 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1553 if (Res)
1554 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001555 }
1556 }
1557
1558 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1559 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1560 // Pattern complexity = 6 cost = 1 size = 0
1561 //
1562 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1563 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1564 // Pattern complexity = 6 cost = 11 size = 0
1565 //
1566 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001567 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1568 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001569 unsigned Opc = 0;
1570 switch (VT.getSimpleVT().SimpleTy) {
1571 default: assert(false && "Illegal conditional move type!");
1572 break;
1573 case MVT::i32:
1574 Opc = Subtarget->isThumb()
1575 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1576 : ARM::MOVCCr;
1577 break;
1578 case MVT::f32:
1579 Opc = ARM::VMOVScc;
1580 break;
1581 case MVT::f64:
1582 Opc = ARM::VMOVDcc;
1583 break;
1584 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001585 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001586}
1587
Evan Chengde8aa4e2010-05-05 18:28:36 +00001588SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
1589 // The only time a CONCAT_VECTORS operation can have legal types is when
1590 // two 64-bit vectors are concatenated to a 128-bit vector.
1591 EVT VT = N->getValueType(0);
1592 if (!VT.is128BitVector() || N->getNumOperands() != 2)
1593 llvm_unreachable("unexpected CONCAT_VECTORS");
1594 DebugLoc dl = N->getDebugLoc();
1595 SDValue V0 = N->getOperand(0);
1596 SDValue V1 = N->getOperand(1);
1597 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
1598 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
1599 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1600 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1601}
1602
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001603SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001604 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001605
Dan Gohmane8be6c62008-07-17 19:10:17 +00001606 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001607 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001608
1609 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001610 default: break;
1611 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001612 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001613 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001614 if (Subtarget->hasThumb2())
1615 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1616 // be done with MOV + MOVT, at worst.
1617 UseCP = 0;
1618 else {
1619 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001620 UseCP = (Val > 255 && // MOV
1621 ~Val > 255 && // MOV + MVN
1622 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001623 } else
1624 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1625 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1626 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1627 }
1628
Evan Chenga8e29892007-01-19 07:51:42 +00001629 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001630 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001631 CurDAG->getTargetConstantPool(ConstantInt::get(
1632 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001633 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001634
1635 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001636 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001637 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001638 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001639 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001640 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1641 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001642 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001643 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001644 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001645 CurDAG->getRegister(0, MVT::i32),
1646 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001647 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001648 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001649 CurDAG->getEntryNode()
1650 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001651 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1652 Ops, 6);
Evan Cheng012f2d92007-01-24 08:53:17 +00001653 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001654 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001655 return NULL;
1656 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001657
Evan Chenga8e29892007-01-19 07:51:42 +00001658 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001659 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001660 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001661 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001662 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001663 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001664 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001665 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001666 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1667 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001668 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001669 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1670 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001671 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1672 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1673 CurDAG->getRegister(0, MVT::i32) };
1674 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001675 }
Evan Chenga8e29892007-01-19 07:51:42 +00001676 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001677 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001678 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001679 return I;
1680 break;
1681 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001682 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001683 return I;
1684 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001685 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001686 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001687 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001688 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001689 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001690 if (!RHSV) break;
1691 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001692 unsigned ShImm = Log2_32(RHSV-1);
1693 if (ShImm >= 32)
1694 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001695 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001696 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001697 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1698 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001699 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001700 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001701 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001702 } else {
1703 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001704 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001705 }
Evan Chenga8e29892007-01-19 07:51:42 +00001706 }
1707 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001708 unsigned ShImm = Log2_32(RHSV+1);
1709 if (ShImm >= 32)
1710 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001711 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001712 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001713 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1714 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001715 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001716 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001717 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 5);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001718 } else {
1719 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001720 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001721 }
Evan Chenga8e29892007-01-19 07:51:42 +00001722 }
1723 }
1724 break;
Evan Cheng20956592009-10-21 08:15:52 +00001725 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001726 // Check for unsigned bitfield extract
1727 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1728 return I;
1729
Evan Cheng20956592009-10-21 08:15:52 +00001730 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1731 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1732 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1733 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1734 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001735 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001736 if (VT != MVT::i32)
1737 break;
1738 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1739 ? ARM::t2MOVTi16
1740 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1741 if (!Opc)
1742 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001743 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001744 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1745 if (!N1C)
1746 break;
1747 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1748 SDValue N2 = N0.getOperand(1);
1749 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1750 if (!N2C)
1751 break;
1752 unsigned N1CVal = N1C->getZExtValue();
1753 unsigned N2CVal = N2C->getZExtValue();
1754 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1755 (N1CVal & 0xffffU) == 0xffffU &&
1756 (N2CVal & 0xffffU) == 0x0U) {
1757 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1758 MVT::i32);
1759 SDValue Ops[] = { N0.getOperand(0), Imm16,
1760 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1761 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
1762 }
1763 }
1764 break;
1765 }
Jim Grosbache5165492009-11-09 00:11:35 +00001766 case ARMISD::VMOVRRD:
1767 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001768 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00001769 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00001770 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001771 if (Subtarget->isThumb1Only())
1772 break;
1773 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001774 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001775 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1776 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001777 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001778 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001779 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001780 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1781 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001782 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001783 }
Evan Chengee568cf2007-07-05 07:15:27 +00001784 }
Dan Gohman525178c2007-10-08 18:33:35 +00001785 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001786 if (Subtarget->isThumb1Only())
1787 break;
1788 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001789 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001790 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001791 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001792 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001793 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001794 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1795 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001796 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001797 }
Evan Chengee568cf2007-07-05 07:15:27 +00001798 }
Evan Chenga8e29892007-01-19 07:51:42 +00001799 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00001800 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001801 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001802 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001803 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001804 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001805 if (ResNode)
1806 return ResNode;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00001807
1808 // VLDMQ must be custom-selected for "v2f64 load" to set the AM5Opc value.
1809 if (Subtarget->hasVFP2() &&
1810 N->getValueType(0).getSimpleVT().SimpleTy == MVT::v2f64) {
1811 SDValue Chain = N->getOperand(0);
1812 SDValue AM5Opc =
1813 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001814 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00001815 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1816 SDValue Ops[] = { N->getOperand(1), AM5Opc, Pred, PredReg, Chain };
1817 return CurDAG->getMachineNode(ARM::VLDMQ, dl, MVT::v2f64, MVT::Other,
1818 Ops, 5);
1819 }
1820 // Other cases are autogenerated.
1821 break;
1822 }
1823 case ISD::STORE: {
1824 // VSTMQ must be custom-selected for "v2f64 store" to set the AM5Opc value.
1825 if (Subtarget->hasVFP2() &&
1826 N->getOperand(1).getValueType().getSimpleVT().SimpleTy == MVT::v2f64) {
1827 SDValue Chain = N->getOperand(0);
1828 SDValue AM5Opc =
1829 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001830 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00001831 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1832 SDValue Ops[] = { N->getOperand(1), N->getOperand(2),
1833 AM5Opc, Pred, PredReg, Chain };
1834 return CurDAG->getMachineNode(ARM::VSTMQ, dl, MVT::Other, Ops, 6);
1835 }
Evan Chenga8e29892007-01-19 07:51:42 +00001836 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001837 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001838 }
Evan Chengee568cf2007-07-05 07:15:27 +00001839 case ARMISD::BRCOND: {
1840 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1841 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1842 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001843
Evan Chengee568cf2007-07-05 07:15:27 +00001844 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1845 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
1846 // Pattern complexity = 6 cost = 1 size = 0
1847
David Goodwin5e47a9a2009-06-30 18:04:13 +00001848 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1849 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1850 // Pattern complexity = 6 cost = 1 size = 0
1851
Jim Grosbach764ab522009-08-11 15:33:49 +00001852 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00001853 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001854 SDValue Chain = N->getOperand(0);
1855 SDValue N1 = N->getOperand(1);
1856 SDValue N2 = N->getOperand(2);
1857 SDValue N3 = N->getOperand(3);
1858 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00001859 assert(N1.getOpcode() == ISD::BasicBlock);
1860 assert(N2.getOpcode() == ISD::Constant);
1861 assert(N3.getOpcode() == ISD::Register);
1862
Dan Gohman475871a2008-07-27 21:46:04 +00001863 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001864 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00001865 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00001866 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00001867 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
1868 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00001869 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001870 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00001871 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001872 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00001873 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001874 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00001875 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00001876 return NULL;
1877 }
Evan Cheng07ba9062009-11-19 21:45:22 +00001878 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001879 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00001880 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001881 EVT VT = N->getValueType(0);
1882 SDValue N0 = N->getOperand(0);
1883 SDValue N1 = N->getOperand(1);
1884 SDValue N2 = N->getOperand(2);
1885 SDValue N3 = N->getOperand(3);
1886 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00001887 assert(N2.getOpcode() == ISD::Constant);
1888 assert(N3.getOpcode() == ISD::Register);
1889
Dan Gohman475871a2008-07-27 21:46:04 +00001890 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001891 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00001892 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00001893 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00001894 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00001895 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00001896 default: assert(false && "Illegal conditional move type!");
1897 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001898 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00001899 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00001900 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001901 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00001902 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00001903 break;
Evan Chengee568cf2007-07-05 07:15:27 +00001904 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001905 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001906 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00001907
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001908 case ARMISD::VZIP: {
1909 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001910 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001911 switch (VT.getSimpleVT().SimpleTy) {
1912 default: return NULL;
1913 case MVT::v8i8: Opc = ARM::VZIPd8; break;
1914 case MVT::v4i16: Opc = ARM::VZIPd16; break;
1915 case MVT::v2f32:
1916 case MVT::v2i32: Opc = ARM::VZIPd32; break;
1917 case MVT::v16i8: Opc = ARM::VZIPq8; break;
1918 case MVT::v8i16: Opc = ARM::VZIPq16; break;
1919 case MVT::v4f32:
1920 case MVT::v4i32: Opc = ARM::VZIPq32; break;
1921 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001922 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00001923 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1924 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1925 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001926 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001927 case ARMISD::VUZP: {
1928 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001929 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001930 switch (VT.getSimpleVT().SimpleTy) {
1931 default: return NULL;
1932 case MVT::v8i8: Opc = ARM::VUZPd8; break;
1933 case MVT::v4i16: Opc = ARM::VUZPd16; break;
1934 case MVT::v2f32:
1935 case MVT::v2i32: Opc = ARM::VUZPd32; break;
1936 case MVT::v16i8: Opc = ARM::VUZPq8; break;
1937 case MVT::v8i16: Opc = ARM::VUZPq16; break;
1938 case MVT::v4f32:
1939 case MVT::v4i32: Opc = ARM::VUZPq32; break;
1940 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001941 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00001942 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1943 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1944 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001945 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001946 case ARMISD::VTRN: {
1947 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001948 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001949 switch (VT.getSimpleVT().SimpleTy) {
1950 default: return NULL;
1951 case MVT::v8i8: Opc = ARM::VTRNd8; break;
1952 case MVT::v4i16: Opc = ARM::VTRNd16; break;
1953 case MVT::v2f32:
1954 case MVT::v2i32: Opc = ARM::VTRNd32; break;
1955 case MVT::v16i8: Opc = ARM::VTRNq8; break;
1956 case MVT::v8i16: Opc = ARM::VTRNq16; break;
1957 case MVT::v4f32:
1958 case MVT::v4i32: Opc = ARM::VTRNq32; break;
1959 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001960 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00001961 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1962 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1963 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001964 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00001965
1966 case ISD::INTRINSIC_VOID:
1967 case ISD::INTRINSIC_W_CHAIN: {
1968 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00001969 switch (IntNo) {
1970 default:
Bob Wilson429009b2010-05-06 16:05:26 +00001971 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00001972
Bob Wilson621f1952010-03-23 05:25:43 +00001973 case Intrinsic::arm_neon_vld1: {
1974 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
1975 ARM::VLD1d32, ARM::VLD1d64 };
1976 unsigned QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
1977 ARM::VLD1q32, ARM::VLD1q64 };
1978 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
1979 }
1980
Bob Wilson31fb12f2009-08-26 17:39:53 +00001981 case Intrinsic::arm_neon_vld2: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001982 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
Bob Wilson621f1952010-03-23 05:25:43 +00001983 ARM::VLD2d32, ARM::VLD1q64 };
Bob Wilson3e36f132009-10-14 17:28:52 +00001984 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001985 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001986 }
1987
1988 case Intrinsic::arm_neon_vld3: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001989 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00001990 ARM::VLD3d32, ARM::VLD1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001991 unsigned QOpcodes0[] = { ARM::VLD3q8_UPD,
1992 ARM::VLD3q16_UPD,
1993 ARM::VLD3q32_UPD };
1994 unsigned QOpcodes1[] = { ARM::VLD3q8odd_UPD,
1995 ARM::VLD3q16odd_UPD,
1996 ARM::VLD3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001997 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001998 }
1999
2000 case Intrinsic::arm_neon_vld4: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002001 unsigned DOpcodes[] = { ARM::VLD4d8, ARM::VLD4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002002 ARM::VLD4d32, ARM::VLD1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002003 unsigned QOpcodes0[] = { ARM::VLD4q8_UPD,
2004 ARM::VLD4q16_UPD,
2005 ARM::VLD4q32_UPD };
2006 unsigned QOpcodes1[] = { ARM::VLD4q8odd_UPD,
2007 ARM::VLD4q16odd_UPD,
2008 ARM::VLD4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002009 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002010 }
2011
Bob Wilson243fcc52009-09-01 04:26:28 +00002012 case Intrinsic::arm_neon_vld2lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002013 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002014 unsigned QOpcodes0[] = { ARM::VLD2LNq16, ARM::VLD2LNq32 };
2015 unsigned QOpcodes1[] = { ARM::VLD2LNq16odd, ARM::VLD2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002016 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002017 }
2018
2019 case Intrinsic::arm_neon_vld3lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002020 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002021 unsigned QOpcodes0[] = { ARM::VLD3LNq16, ARM::VLD3LNq32 };
2022 unsigned QOpcodes1[] = { ARM::VLD3LNq16odd, ARM::VLD3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002023 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002024 }
2025
2026 case Intrinsic::arm_neon_vld4lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002027 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002028 unsigned QOpcodes0[] = { ARM::VLD4LNq16, ARM::VLD4LNq32 };
2029 unsigned QOpcodes1[] = { ARM::VLD4LNq16odd, ARM::VLD4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002030 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002031 }
2032
Bob Wilson11d98992010-03-23 06:20:33 +00002033 case Intrinsic::arm_neon_vst1: {
2034 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2035 ARM::VST1d32, ARM::VST1d64 };
2036 unsigned QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
2037 ARM::VST1q32, ARM::VST1q64 };
2038 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2039 }
2040
Bob Wilson31fb12f2009-08-26 17:39:53 +00002041 case Intrinsic::arm_neon_vst2: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002042 unsigned DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
Bob Wilson11d98992010-03-23 06:20:33 +00002043 ARM::VST2d32, ARM::VST1q64 };
Bob Wilson24f995d2009-10-14 18:32:29 +00002044 unsigned QOpcodes[] = { ARM::VST2q8, ARM::VST2q16, ARM::VST2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002045 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002046 }
2047
2048 case Intrinsic::arm_neon_vst3: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002049 unsigned DOpcodes[] = { ARM::VST3d8, ARM::VST3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002050 ARM::VST3d32, ARM::VST1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002051 unsigned QOpcodes0[] = { ARM::VST3q8_UPD,
2052 ARM::VST3q16_UPD,
2053 ARM::VST3q32_UPD };
2054 unsigned QOpcodes1[] = { ARM::VST3q8odd_UPD,
2055 ARM::VST3q16odd_UPD,
2056 ARM::VST3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002057 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002058 }
2059
2060 case Intrinsic::arm_neon_vst4: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002061 unsigned DOpcodes[] = { ARM::VST4d8, ARM::VST4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002062 ARM::VST4d32, ARM::VST1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002063 unsigned QOpcodes0[] = { ARM::VST4q8_UPD,
2064 ARM::VST4q16_UPD,
2065 ARM::VST4q32_UPD };
2066 unsigned QOpcodes1[] = { ARM::VST4q8odd_UPD,
2067 ARM::VST4q16odd_UPD,
2068 ARM::VST4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002069 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002070 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002071
2072 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002073 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002074 unsigned QOpcodes0[] = { ARM::VST2LNq16, ARM::VST2LNq32 };
2075 unsigned QOpcodes1[] = { ARM::VST2LNq16odd, ARM::VST2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002076 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002077 }
2078
2079 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002080 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002081 unsigned QOpcodes0[] = { ARM::VST3LNq16, ARM::VST3LNq32 };
2082 unsigned QOpcodes1[] = { ARM::VST3LNq16odd, ARM::VST3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002083 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002084 }
2085
2086 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002087 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002088 unsigned QOpcodes0[] = { ARM::VST4LNq16, ARM::VST4LNq32 };
2089 unsigned QOpcodes1[] = { ARM::VST4LNq16odd, ARM::VST4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002090 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002091 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002092 }
Bob Wilson429009b2010-05-06 16:05:26 +00002093 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002094 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002095
Bob Wilson429009b2010-05-06 16:05:26 +00002096 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002097 return SelectConcatVector(N);
2098 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002099
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002100 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002101}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002102
Bob Wilson224c2442009-05-19 05:53:42 +00002103bool ARMDAGToDAGISel::
2104SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2105 std::vector<SDValue> &OutOps) {
2106 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002107 // Require the address to be in a register. That is safe for all ARM
2108 // variants and it is hard to do anything much smarter without knowing
2109 // how the operand is used.
2110 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002111 return false;
2112}
2113
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002114/// createARMISelDag - This pass converts a legalized DAG into a
2115/// ARM-specific DAG, ready for instruction scheduling.
2116///
Bob Wilson522ce972009-09-28 14:30:20 +00002117FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2118 CodeGenOpt::Level OptLevel) {
2119 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002120}
Evan Chengde8aa4e2010-05-05 18:28:36 +00002121
2122/// ModelWithRegSequence - Return true if isel should use REG_SEQUENCE to model
2123/// operations involving sub-registers.
2124bool llvm::ModelWithRegSequence() {
2125 return UseRegSeq;
2126}