blob: abc02e263e6e43d2a122ff1a90478616a60954a7 [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);
Bob Wilson226036e2010-03-20 22:13:40 +00001047 return CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson3e36f132009-10-14 17:28:52 +00001048 }
1049
1050 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson621f1952010-03-23 05:25:43 +00001051 if (NumVecs <= 2) {
1052 // Quad registers are directly supported for VLD1 and VLD2,
1053 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001054 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001055 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson621f1952010-03-23 05:25:43 +00001056 std::vector<EVT> ResTys(2 * NumVecs, RegVT);
Bob Wilson3e36f132009-10-14 17:28:52 +00001057 ResTys.push_back(MVT::Other);
Bob Wilson226036e2010-03-20 22:13:40 +00001058 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson621f1952010-03-23 05:25:43 +00001059 Chain = SDValue(VLd, 2 * NumVecs);
Bob Wilson3e36f132009-10-14 17:28:52 +00001060
1061 // Combine the even and odd subregs to produce the result.
Evan Cheng603afbf2010-05-10 17:34:18 +00001062 if (llvm::ModelWithRegSequence()) {
1063 if (NumVecs == 1) {
1064 SDNode *Q = PairDRegs(VT, SDValue(VLd, 0), SDValue(VLd, 1));
1065 ReplaceUses(SDValue(N, 0), SDValue(Q, 0));
1066 } else {
1067 SDValue QQ = SDValue(QuadDRegs(MVT::v4i64,
1068 SDValue(VLd, 0), SDValue(VLd, 1),
1069 SDValue(VLd, 2), SDValue(VLd, 3)), 0);
1070 SDValue Q0 = CurDAG->getTargetExtractSubreg(ARM::QSUBREG_0, dl, VT, QQ);
1071 SDValue Q1 = CurDAG->getTargetExtractSubreg(ARM::QSUBREG_1, dl, VT, QQ);
1072 ReplaceUses(SDValue(N, 0), Q0);
1073 ReplaceUses(SDValue(N, 1), Q1);
1074 }
1075 } else {
1076 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1077 SDNode *Q = PairDRegs(VT, SDValue(VLd, 2*Vec), SDValue(VLd, 2*Vec+1));
1078 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1079 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001080 }
1081 } else {
1082 // Otherwise, quad registers are loaded with two separate instructions,
1083 // where one loads the even registers and the other loads the odd registers.
1084
Bob Wilson3e36f132009-10-14 17:28:52 +00001085 std::vector<EVT> ResTys(NumVecs, RegVT);
1086 ResTys.push_back(MemAddr.getValueType());
1087 ResTys.push_back(MVT::Other);
1088
Bob Wilson24f995d2009-10-14 18:32:29 +00001089 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001090 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001091 const SDValue OpsA[] = { MemAddr, Align, Reg0, Pred, Reg0, Chain };
1092 SDNode *VLdA = CurDAG->getMachineNode(Opc, dl, ResTys, OpsA, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001093 Chain = SDValue(VLdA, NumVecs+1);
1094
Bob Wilson24f995d2009-10-14 18:32:29 +00001095 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001096 Opc = QOpcodes1[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001097 const SDValue OpsB[] = { SDValue(VLdA, NumVecs),
1098 Align, Reg0, Pred, Reg0, Chain };
1099 SDNode *VLdB = CurDAG->getMachineNode(Opc, dl, ResTys, OpsB, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001100 Chain = SDValue(VLdB, NumVecs+1);
1101
1102 // Combine the even and odd subregs to produce the result.
1103 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1104 SDNode *Q = PairDRegs(VT, SDValue(VLdA, Vec), SDValue(VLdB, Vec));
1105 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1106 }
1107 }
1108 ReplaceUses(SDValue(N, NumVecs), Chain);
1109 return NULL;
1110}
1111
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001112SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001113 unsigned *DOpcodes, unsigned *QOpcodes0,
1114 unsigned *QOpcodes1) {
Bob Wilson11d98992010-03-23 06:20:33 +00001115 assert(NumVecs >=1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001116 DebugLoc dl = N->getDebugLoc();
1117
Bob Wilson226036e2010-03-20 22:13:40 +00001118 SDValue MemAddr, Align;
1119 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001120 return NULL;
1121
1122 SDValue Chain = N->getOperand(0);
1123 EVT VT = N->getOperand(3).getValueType();
1124 bool is64BitVector = VT.is64BitVector();
1125
1126 unsigned OpcodeIndex;
1127 switch (VT.getSimpleVT().SimpleTy) {
1128 default: llvm_unreachable("unhandled vst type");
1129 // Double-register operations:
1130 case MVT::v8i8: OpcodeIndex = 0; break;
1131 case MVT::v4i16: OpcodeIndex = 1; break;
1132 case MVT::v2f32:
1133 case MVT::v2i32: OpcodeIndex = 2; break;
1134 case MVT::v1i64: OpcodeIndex = 3; break;
1135 // Quad-register operations:
1136 case MVT::v16i8: OpcodeIndex = 0; break;
1137 case MVT::v8i16: OpcodeIndex = 1; break;
1138 case MVT::v4f32:
1139 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001140 case MVT::v2i64: OpcodeIndex = 3;
1141 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1142 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001143 }
1144
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001145 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001146 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001147
Bob Wilson226036e2010-03-20 22:13:40 +00001148 SmallVector<SDValue, 10> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001149 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001150 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001151
1152 if (is64BitVector) {
1153 unsigned Opc = DOpcodes[OpcodeIndex];
1154 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1155 Ops.push_back(N->getOperand(Vec+3));
Evan Chengac0869d2009-11-21 06:21:52 +00001156 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001157 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001158 Ops.push_back(Chain);
Bob Wilson226036e2010-03-20 22:13:40 +00001159 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+5);
Bob Wilson24f995d2009-10-14 18:32:29 +00001160 }
1161
1162 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson11d98992010-03-23 06:20:33 +00001163 if (NumVecs <= 2) {
1164 // Quad registers are directly supported for VST1 and VST2,
1165 // storing pairs of D regs.
Bob Wilson24f995d2009-10-14 18:32:29 +00001166 unsigned Opc = QOpcodes0[OpcodeIndex];
Evan Cheng603afbf2010-05-10 17:34:18 +00001167 if (llvm::ModelWithRegSequence() && NumVecs == 2) {
1168 // First extract the quad D registers.
1169 SDValue Q0 = N->getOperand(3);
1170 SDValue Q1 = N->getOperand(4);
1171
1172 // Form a QQ register.
1173 SDValue QQ = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
1174
1175 // Now extract the D registers back out.
Bob Wilson24f995d2009-10-14 18:32:29 +00001176 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001177 QQ));
Bob Wilson24f995d2009-10-14 18:32:29 +00001178 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001179 QQ));
1180 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_2, dl, RegVT,
1181 QQ));
1182 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_3, dl, RegVT,
1183 QQ));
1184 Ops.push_back(Pred);
1185 Ops.push_back(Reg0); // predicate register
1186 Ops.push_back(Chain);
1187 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 5 + 4);
1188 } else {
1189 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1190 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1191 N->getOperand(Vec+3)));
1192 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
1193 N->getOperand(Vec+3)));
1194 }
1195 Ops.push_back(Pred);
1196 Ops.push_back(Reg0); // predicate register
1197 Ops.push_back(Chain);
1198 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(),
1199 5 + 2 * NumVecs);
Bob Wilson24f995d2009-10-14 18:32:29 +00001200 }
Bob Wilson24f995d2009-10-14 18:32:29 +00001201 }
1202
1203 // Otherwise, quad registers are stored with two separate instructions,
1204 // where one stores the even registers and the other stores the odd registers.
1205
Bob Wilson226036e2010-03-20 22:13:40 +00001206 Ops.push_back(Reg0); // post-access address offset
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001207
Bob Wilson24f995d2009-10-14 18:32:29 +00001208 // Store the even subregs.
1209 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1210 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1211 N->getOperand(Vec+3)));
Evan Chengac0869d2009-11-21 06:21:52 +00001212 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001213 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001214 Ops.push_back(Chain);
1215 unsigned Opc = QOpcodes0[OpcodeIndex];
1216 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilson226036e2010-03-20 22:13:40 +00001217 MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001218 Chain = SDValue(VStA, 1);
1219
1220 // Store the odd subregs.
1221 Ops[0] = SDValue(VStA, 0); // MemAddr
1222 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
Bob Wilson226036e2010-03-20 22:13:40 +00001223 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
Bob Wilson24f995d2009-10-14 18:32:29 +00001224 N->getOperand(Vec+3));
Bob Wilson226036e2010-03-20 22:13:40 +00001225 Ops[NumVecs+5] = Chain;
Bob Wilson24f995d2009-10-14 18:32:29 +00001226 Opc = QOpcodes1[OpcodeIndex];
1227 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilson226036e2010-03-20 22:13:40 +00001228 MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001229 Chain = SDValue(VStB, 1);
1230 ReplaceUses(SDValue(N, 0), Chain);
1231 return NULL;
1232}
1233
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001234SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001235 unsigned NumVecs, unsigned *DOpcodes,
1236 unsigned *QOpcodes0,
1237 unsigned *QOpcodes1) {
1238 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001239 DebugLoc dl = N->getDebugLoc();
1240
Bob Wilson226036e2010-03-20 22:13:40 +00001241 SDValue MemAddr, Align;
1242 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001243 return NULL;
1244
1245 SDValue Chain = N->getOperand(0);
1246 unsigned Lane =
1247 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001248 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001249 bool is64BitVector = VT.is64BitVector();
1250
Bob Wilson96493442009-10-14 16:46:45 +00001251 // Quad registers are handled by load/store of subregs. Find the subreg info.
Bob Wilsona7c397c2009-10-14 16:19:03 +00001252 unsigned NumElts = 0;
1253 int SubregIdx = 0;
1254 EVT RegVT = VT;
1255 if (!is64BitVector) {
1256 RegVT = GetNEONSubregVT(VT);
1257 NumElts = RegVT.getVectorNumElements();
1258 SubregIdx = (Lane < NumElts) ? ARM::DSUBREG_0 : ARM::DSUBREG_1;
1259 }
1260
1261 unsigned OpcodeIndex;
1262 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001263 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001264 // Double-register operations:
1265 case MVT::v8i8: OpcodeIndex = 0; break;
1266 case MVT::v4i16: OpcodeIndex = 1; break;
1267 case MVT::v2f32:
1268 case MVT::v2i32: OpcodeIndex = 2; break;
1269 // Quad-register operations:
1270 case MVT::v8i16: OpcodeIndex = 0; break;
1271 case MVT::v4f32:
1272 case MVT::v4i32: OpcodeIndex = 1; break;
1273 }
1274
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001275 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001276 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001277
Bob Wilson226036e2010-03-20 22:13:40 +00001278 SmallVector<SDValue, 10> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001279 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001280 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001281
1282 unsigned Opc = 0;
1283 if (is64BitVector) {
1284 Opc = DOpcodes[OpcodeIndex];
1285 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1286 Ops.push_back(N->getOperand(Vec+3));
1287 } else {
1288 // Check if this is loading the even or odd subreg of a Q register.
1289 if (Lane < NumElts) {
1290 Opc = QOpcodes0[OpcodeIndex];
1291 } else {
1292 Lane -= NumElts;
1293 Opc = QOpcodes1[OpcodeIndex];
1294 }
1295 // Extract the subregs of the input vector.
1296 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1297 Ops.push_back(CurDAG->getTargetExtractSubreg(SubregIdx, dl, RegVT,
1298 N->getOperand(Vec+3)));
1299 }
1300 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001301 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001302 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001303 Ops.push_back(Chain);
1304
Bob Wilson96493442009-10-14 16:46:45 +00001305 if (!IsLoad)
Bob Wilson226036e2010-03-20 22:13:40 +00001306 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson96493442009-10-14 16:46:45 +00001307
Bob Wilsona7c397c2009-10-14 16:19:03 +00001308 std::vector<EVT> ResTys(NumVecs, RegVT);
1309 ResTys.push_back(MVT::Other);
1310 SDNode *VLdLn =
Bob Wilson226036e2010-03-20 22:13:40 +00001311 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), NumVecs+6);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001312 // For a 64-bit vector load to D registers, nothing more needs to be done.
1313 if (is64BitVector)
1314 return VLdLn;
1315
1316 // For 128-bit vectors, take the 64-bit results of the load and insert them
1317 // as subregs into the result.
1318 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1319 SDValue QuadVec = CurDAG->getTargetInsertSubreg(SubregIdx, dl, VT,
1320 N->getOperand(Vec+3),
1321 SDValue(VLdLn, Vec));
1322 ReplaceUses(SDValue(N, Vec), QuadVec);
1323 }
1324
1325 Chain = SDValue(VLdLn, NumVecs);
1326 ReplaceUses(SDValue(N, NumVecs), Chain);
1327 return NULL;
1328}
1329
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001330SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001331 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001332 if (!Subtarget->hasV6T2Ops())
1333 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001334
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001335 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1336 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1337
1338
1339 // For unsigned extracts, check for a shift right and mask
1340 unsigned And_imm = 0;
1341 if (N->getOpcode() == ISD::AND) {
1342 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1343
1344 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1345 if (And_imm & (And_imm + 1))
1346 return NULL;
1347
1348 unsigned Srl_imm = 0;
1349 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1350 Srl_imm)) {
1351 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1352
1353 unsigned Width = CountTrailingOnes_32(And_imm);
1354 unsigned LSB = Srl_imm;
1355 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1356 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1357 CurDAG->getTargetConstant(LSB, MVT::i32),
1358 CurDAG->getTargetConstant(Width, MVT::i32),
1359 getAL(CurDAG), Reg0 };
1360 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1361 }
1362 }
1363 return NULL;
1364 }
1365
1366 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001367 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001368 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001369 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1370 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001371 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001372 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1373 unsigned Width = 32 - Srl_imm;
1374 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001375 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001376 return NULL;
1377 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001378 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001379 CurDAG->getTargetConstant(LSB, MVT::i32),
1380 CurDAG->getTargetConstant(Width, MVT::i32),
1381 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001382 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001383 }
1384 }
1385 return NULL;
1386}
1387
Evan Cheng9ef48352009-11-20 00:54:03 +00001388SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001389SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001390 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1391 SDValue CPTmp0;
1392 SDValue CPTmp1;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001393 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001394 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1395 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1396 unsigned Opc = 0;
1397 switch (SOShOp) {
1398 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1399 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1400 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1401 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1402 default:
1403 llvm_unreachable("Unknown so_reg opcode!");
1404 break;
1405 }
1406 SDValue SOShImm =
1407 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1408 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1409 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001410 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001411 }
1412 return 0;
1413}
1414
1415SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001416SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001417 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1418 SDValue CPTmp0;
1419 SDValue CPTmp1;
1420 SDValue CPTmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001421 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001422 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1423 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001424 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001425 }
1426 return 0;
1427}
1428
1429SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001430SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001431 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1432 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1433 if (!T)
1434 return 0;
1435
1436 if (Predicate_t2_so_imm(TrueVal.getNode())) {
1437 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1438 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1439 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001440 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001441 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1442 }
1443 return 0;
1444}
1445
1446SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001447SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001448 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1449 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1450 if (!T)
1451 return 0;
1452
1453 if (Predicate_so_imm(TrueVal.getNode())) {
1454 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1455 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1456 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001457 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001458 ARM::MOVCCi, MVT::i32, Ops, 5);
1459 }
1460 return 0;
1461}
1462
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001463SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1464 EVT VT = N->getValueType(0);
1465 SDValue FalseVal = N->getOperand(0);
1466 SDValue TrueVal = N->getOperand(1);
1467 SDValue CC = N->getOperand(2);
1468 SDValue CCR = N->getOperand(3);
1469 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001470 assert(CC.getOpcode() == ISD::Constant);
1471 assert(CCR.getOpcode() == ISD::Register);
1472 ARMCC::CondCodes CCVal =
1473 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001474
1475 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1476 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1477 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1478 // Pattern complexity = 18 cost = 1 size = 0
1479 SDValue CPTmp0;
1480 SDValue CPTmp1;
1481 SDValue CPTmp2;
1482 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001483 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001484 CCVal, CCR, InFlag);
1485 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001486 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001487 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1488 if (Res)
1489 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001490 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001491 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001492 CCVal, CCR, InFlag);
1493 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001494 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001495 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1496 if (Res)
1497 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001498 }
1499
1500 // Pattern: (ARMcmov:i32 GPR:i32:$false,
1501 // (imm:i32)<<P:Predicate_so_imm>>:$true,
1502 // (imm:i32):$cc)
1503 // Emits: (MOVCCi:i32 GPR:i32:$false,
1504 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1505 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001506 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001507 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001508 CCVal, CCR, InFlag);
1509 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001510 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001511 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1512 if (Res)
1513 return Res;
1514 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001515 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001516 CCVal, CCR, InFlag);
1517 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001518 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001519 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1520 if (Res)
1521 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001522 }
1523 }
1524
1525 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1526 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1527 // Pattern complexity = 6 cost = 1 size = 0
1528 //
1529 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1530 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1531 // Pattern complexity = 6 cost = 11 size = 0
1532 //
1533 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001534 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1535 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001536 unsigned Opc = 0;
1537 switch (VT.getSimpleVT().SimpleTy) {
1538 default: assert(false && "Illegal conditional move type!");
1539 break;
1540 case MVT::i32:
1541 Opc = Subtarget->isThumb()
1542 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1543 : ARM::MOVCCr;
1544 break;
1545 case MVT::f32:
1546 Opc = ARM::VMOVScc;
1547 break;
1548 case MVT::f64:
1549 Opc = ARM::VMOVDcc;
1550 break;
1551 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001552 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001553}
1554
Evan Chengde8aa4e2010-05-05 18:28:36 +00001555SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
1556 // The only time a CONCAT_VECTORS operation can have legal types is when
1557 // two 64-bit vectors are concatenated to a 128-bit vector.
1558 EVT VT = N->getValueType(0);
1559 if (!VT.is128BitVector() || N->getNumOperands() != 2)
1560 llvm_unreachable("unexpected CONCAT_VECTORS");
1561 DebugLoc dl = N->getDebugLoc();
1562 SDValue V0 = N->getOperand(0);
1563 SDValue V1 = N->getOperand(1);
1564 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
1565 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
1566 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1567 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1568}
1569
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001570SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001571 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001572
Dan Gohmane8be6c62008-07-17 19:10:17 +00001573 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001574 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001575
1576 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001577 default: break;
1578 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001579 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001580 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001581 if (Subtarget->hasThumb2())
1582 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1583 // be done with MOV + MOVT, at worst.
1584 UseCP = 0;
1585 else {
1586 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001587 UseCP = (Val > 255 && // MOV
1588 ~Val > 255 && // MOV + MVN
1589 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001590 } else
1591 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1592 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1593 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1594 }
1595
Evan Chenga8e29892007-01-19 07:51:42 +00001596 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001597 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001598 CurDAG->getTargetConstantPool(ConstantInt::get(
1599 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001600 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001601
1602 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001603 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001604 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001605 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001606 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001607 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1608 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001609 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001610 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001611 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001612 CurDAG->getRegister(0, MVT::i32),
1613 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001614 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001615 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001616 CurDAG->getEntryNode()
1617 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001618 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1619 Ops, 6);
Evan Cheng012f2d92007-01-24 08:53:17 +00001620 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001621 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001622 return NULL;
1623 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001624
Evan Chenga8e29892007-01-19 07:51:42 +00001625 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001626 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001627 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001628 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001629 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001630 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001631 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001632 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001633 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1634 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001635 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001636 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1637 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001638 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1639 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1640 CurDAG->getRegister(0, MVT::i32) };
1641 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001642 }
Evan Chenga8e29892007-01-19 07:51:42 +00001643 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001644 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001645 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001646 return I;
1647 break;
1648 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001649 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001650 return I;
1651 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001652 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001653 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001654 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001655 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001656 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001657 if (!RHSV) break;
1658 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001659 unsigned ShImm = Log2_32(RHSV-1);
1660 if (ShImm >= 32)
1661 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001662 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001663 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001664 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1665 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001666 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001667 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001668 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001669 } else {
1670 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001671 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001672 }
Evan Chenga8e29892007-01-19 07:51:42 +00001673 }
1674 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001675 unsigned ShImm = Log2_32(RHSV+1);
1676 if (ShImm >= 32)
1677 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001678 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001679 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001680 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1681 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001682 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001683 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001684 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 5);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001685 } else {
1686 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001687 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001688 }
Evan Chenga8e29892007-01-19 07:51:42 +00001689 }
1690 }
1691 break;
Evan Cheng20956592009-10-21 08:15:52 +00001692 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001693 // Check for unsigned bitfield extract
1694 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1695 return I;
1696
Evan Cheng20956592009-10-21 08:15:52 +00001697 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1698 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1699 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1700 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1701 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001702 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001703 if (VT != MVT::i32)
1704 break;
1705 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1706 ? ARM::t2MOVTi16
1707 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1708 if (!Opc)
1709 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001710 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001711 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1712 if (!N1C)
1713 break;
1714 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1715 SDValue N2 = N0.getOperand(1);
1716 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1717 if (!N2C)
1718 break;
1719 unsigned N1CVal = N1C->getZExtValue();
1720 unsigned N2CVal = N2C->getZExtValue();
1721 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1722 (N1CVal & 0xffffU) == 0xffffU &&
1723 (N2CVal & 0xffffU) == 0x0U) {
1724 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1725 MVT::i32);
1726 SDValue Ops[] = { N0.getOperand(0), Imm16,
1727 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1728 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
1729 }
1730 }
1731 break;
1732 }
Jim Grosbache5165492009-11-09 00:11:35 +00001733 case ARMISD::VMOVRRD:
1734 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001735 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00001736 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00001737 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001738 if (Subtarget->isThumb1Only())
1739 break;
1740 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001741 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001742 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1743 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001744 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001745 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001746 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001747 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1748 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001749 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001750 }
Evan Chengee568cf2007-07-05 07:15:27 +00001751 }
Dan Gohman525178c2007-10-08 18:33:35 +00001752 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001753 if (Subtarget->isThumb1Only())
1754 break;
1755 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001756 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001757 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001758 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001759 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001760 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001761 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1762 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001763 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001764 }
Evan Chengee568cf2007-07-05 07:15:27 +00001765 }
Evan Chenga8e29892007-01-19 07:51:42 +00001766 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00001767 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001768 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001769 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001770 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001771 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001772 if (ResNode)
1773 return ResNode;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00001774
1775 // VLDMQ must be custom-selected for "v2f64 load" to set the AM5Opc value.
1776 if (Subtarget->hasVFP2() &&
1777 N->getValueType(0).getSimpleVT().SimpleTy == MVT::v2f64) {
1778 SDValue Chain = N->getOperand(0);
1779 SDValue AM5Opc =
1780 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001781 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00001782 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1783 SDValue Ops[] = { N->getOperand(1), AM5Opc, Pred, PredReg, Chain };
1784 return CurDAG->getMachineNode(ARM::VLDMQ, dl, MVT::v2f64, MVT::Other,
1785 Ops, 5);
1786 }
1787 // Other cases are autogenerated.
1788 break;
1789 }
1790 case ISD::STORE: {
1791 // VSTMQ must be custom-selected for "v2f64 store" to set the AM5Opc value.
1792 if (Subtarget->hasVFP2() &&
1793 N->getOperand(1).getValueType().getSimpleVT().SimpleTy == MVT::v2f64) {
1794 SDValue Chain = N->getOperand(0);
1795 SDValue AM5Opc =
1796 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001797 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00001798 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1799 SDValue Ops[] = { N->getOperand(1), N->getOperand(2),
1800 AM5Opc, Pred, PredReg, Chain };
1801 return CurDAG->getMachineNode(ARM::VSTMQ, dl, MVT::Other, Ops, 6);
1802 }
Evan Chenga8e29892007-01-19 07:51:42 +00001803 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001804 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001805 }
Evan Chengee568cf2007-07-05 07:15:27 +00001806 case ARMISD::BRCOND: {
1807 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1808 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1809 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001810
Evan Chengee568cf2007-07-05 07:15:27 +00001811 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1812 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
1813 // Pattern complexity = 6 cost = 1 size = 0
1814
David Goodwin5e47a9a2009-06-30 18:04:13 +00001815 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1816 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1817 // Pattern complexity = 6 cost = 1 size = 0
1818
Jim Grosbach764ab522009-08-11 15:33:49 +00001819 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00001820 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001821 SDValue Chain = N->getOperand(0);
1822 SDValue N1 = N->getOperand(1);
1823 SDValue N2 = N->getOperand(2);
1824 SDValue N3 = N->getOperand(3);
1825 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00001826 assert(N1.getOpcode() == ISD::BasicBlock);
1827 assert(N2.getOpcode() == ISD::Constant);
1828 assert(N3.getOpcode() == ISD::Register);
1829
Dan Gohman475871a2008-07-27 21:46:04 +00001830 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001831 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00001832 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00001833 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00001834 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
1835 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00001836 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001837 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00001838 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001839 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00001840 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001841 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00001842 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00001843 return NULL;
1844 }
Evan Cheng07ba9062009-11-19 21:45:22 +00001845 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001846 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00001847 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001848 EVT VT = N->getValueType(0);
1849 SDValue N0 = N->getOperand(0);
1850 SDValue N1 = N->getOperand(1);
1851 SDValue N2 = N->getOperand(2);
1852 SDValue N3 = N->getOperand(3);
1853 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00001854 assert(N2.getOpcode() == ISD::Constant);
1855 assert(N3.getOpcode() == ISD::Register);
1856
Dan Gohman475871a2008-07-27 21:46:04 +00001857 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001858 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00001859 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00001860 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00001861 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00001862 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00001863 default: assert(false && "Illegal conditional move type!");
1864 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001865 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00001866 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00001867 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001868 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00001869 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00001870 break;
Evan Chengee568cf2007-07-05 07:15:27 +00001871 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001872 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001873 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00001874
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001875 case ARMISD::VZIP: {
1876 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001877 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001878 switch (VT.getSimpleVT().SimpleTy) {
1879 default: return NULL;
1880 case MVT::v8i8: Opc = ARM::VZIPd8; break;
1881 case MVT::v4i16: Opc = ARM::VZIPd16; break;
1882 case MVT::v2f32:
1883 case MVT::v2i32: Opc = ARM::VZIPd32; break;
1884 case MVT::v16i8: Opc = ARM::VZIPq8; break;
1885 case MVT::v8i16: Opc = ARM::VZIPq16; break;
1886 case MVT::v4f32:
1887 case MVT::v4i32: Opc = ARM::VZIPq32; break;
1888 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001889 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00001890 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1891 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1892 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001893 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001894 case ARMISD::VUZP: {
1895 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001896 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001897 switch (VT.getSimpleVT().SimpleTy) {
1898 default: return NULL;
1899 case MVT::v8i8: Opc = ARM::VUZPd8; break;
1900 case MVT::v4i16: Opc = ARM::VUZPd16; break;
1901 case MVT::v2f32:
1902 case MVT::v2i32: Opc = ARM::VUZPd32; break;
1903 case MVT::v16i8: Opc = ARM::VUZPq8; break;
1904 case MVT::v8i16: Opc = ARM::VUZPq16; break;
1905 case MVT::v4f32:
1906 case MVT::v4i32: Opc = ARM::VUZPq32; break;
1907 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001908 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00001909 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1910 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1911 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001912 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001913 case ARMISD::VTRN: {
1914 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001915 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001916 switch (VT.getSimpleVT().SimpleTy) {
1917 default: return NULL;
1918 case MVT::v8i8: Opc = ARM::VTRNd8; break;
1919 case MVT::v4i16: Opc = ARM::VTRNd16; break;
1920 case MVT::v2f32:
1921 case MVT::v2i32: Opc = ARM::VTRNd32; break;
1922 case MVT::v16i8: Opc = ARM::VTRNq8; break;
1923 case MVT::v8i16: Opc = ARM::VTRNq16; break;
1924 case MVT::v4f32:
1925 case MVT::v4i32: Opc = ARM::VTRNq32; break;
1926 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001927 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00001928 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1929 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1930 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001931 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00001932
1933 case ISD::INTRINSIC_VOID:
1934 case ISD::INTRINSIC_W_CHAIN: {
1935 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00001936 switch (IntNo) {
1937 default:
Bob Wilson429009b2010-05-06 16:05:26 +00001938 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00001939
Bob Wilson621f1952010-03-23 05:25:43 +00001940 case Intrinsic::arm_neon_vld1: {
1941 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
1942 ARM::VLD1d32, ARM::VLD1d64 };
1943 unsigned QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
1944 ARM::VLD1q32, ARM::VLD1q64 };
1945 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
1946 }
1947
Bob Wilson31fb12f2009-08-26 17:39:53 +00001948 case Intrinsic::arm_neon_vld2: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001949 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
Bob Wilson621f1952010-03-23 05:25:43 +00001950 ARM::VLD2d32, ARM::VLD1q64 };
Bob Wilson3e36f132009-10-14 17:28:52 +00001951 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001952 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001953 }
1954
1955 case Intrinsic::arm_neon_vld3: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001956 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00001957 ARM::VLD3d32, ARM::VLD1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001958 unsigned QOpcodes0[] = { ARM::VLD3q8_UPD,
1959 ARM::VLD3q16_UPD,
1960 ARM::VLD3q32_UPD };
1961 unsigned QOpcodes1[] = { ARM::VLD3q8odd_UPD,
1962 ARM::VLD3q16odd_UPD,
1963 ARM::VLD3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001964 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001965 }
1966
1967 case Intrinsic::arm_neon_vld4: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001968 unsigned DOpcodes[] = { ARM::VLD4d8, ARM::VLD4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00001969 ARM::VLD4d32, ARM::VLD1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001970 unsigned QOpcodes0[] = { ARM::VLD4q8_UPD,
1971 ARM::VLD4q16_UPD,
1972 ARM::VLD4q32_UPD };
1973 unsigned QOpcodes1[] = { ARM::VLD4q8odd_UPD,
1974 ARM::VLD4q16odd_UPD,
1975 ARM::VLD4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001976 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001977 }
1978
Bob Wilson243fcc52009-09-01 04:26:28 +00001979 case Intrinsic::arm_neon_vld2lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00001980 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001981 unsigned QOpcodes0[] = { ARM::VLD2LNq16, ARM::VLD2LNq32 };
1982 unsigned QOpcodes1[] = { ARM::VLD2LNq16odd, ARM::VLD2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001983 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00001984 }
1985
1986 case Intrinsic::arm_neon_vld3lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00001987 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001988 unsigned QOpcodes0[] = { ARM::VLD3LNq16, ARM::VLD3LNq32 };
1989 unsigned QOpcodes1[] = { ARM::VLD3LNq16odd, ARM::VLD3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001990 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00001991 }
1992
1993 case Intrinsic::arm_neon_vld4lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00001994 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001995 unsigned QOpcodes0[] = { ARM::VLD4LNq16, ARM::VLD4LNq32 };
1996 unsigned QOpcodes1[] = { ARM::VLD4LNq16odd, ARM::VLD4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001997 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00001998 }
1999
Bob Wilson11d98992010-03-23 06:20:33 +00002000 case Intrinsic::arm_neon_vst1: {
2001 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2002 ARM::VST1d32, ARM::VST1d64 };
2003 unsigned QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
2004 ARM::VST1q32, ARM::VST1q64 };
2005 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2006 }
2007
Bob Wilson31fb12f2009-08-26 17:39:53 +00002008 case Intrinsic::arm_neon_vst2: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002009 unsigned DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
Bob Wilson11d98992010-03-23 06:20:33 +00002010 ARM::VST2d32, ARM::VST1q64 };
Bob Wilson24f995d2009-10-14 18:32:29 +00002011 unsigned QOpcodes[] = { ARM::VST2q8, ARM::VST2q16, ARM::VST2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002012 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002013 }
2014
2015 case Intrinsic::arm_neon_vst3: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002016 unsigned DOpcodes[] = { ARM::VST3d8, ARM::VST3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002017 ARM::VST3d32, ARM::VST1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002018 unsigned QOpcodes0[] = { ARM::VST3q8_UPD,
2019 ARM::VST3q16_UPD,
2020 ARM::VST3q32_UPD };
2021 unsigned QOpcodes1[] = { ARM::VST3q8odd_UPD,
2022 ARM::VST3q16odd_UPD,
2023 ARM::VST3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002024 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002025 }
2026
2027 case Intrinsic::arm_neon_vst4: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002028 unsigned DOpcodes[] = { ARM::VST4d8, ARM::VST4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002029 ARM::VST4d32, ARM::VST1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002030 unsigned QOpcodes0[] = { ARM::VST4q8_UPD,
2031 ARM::VST4q16_UPD,
2032 ARM::VST4q32_UPD };
2033 unsigned QOpcodes1[] = { ARM::VST4q8odd_UPD,
2034 ARM::VST4q16odd_UPD,
2035 ARM::VST4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002036 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002037 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002038
2039 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002040 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002041 unsigned QOpcodes0[] = { ARM::VST2LNq16, ARM::VST2LNq32 };
2042 unsigned QOpcodes1[] = { ARM::VST2LNq16odd, ARM::VST2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002043 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002044 }
2045
2046 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002047 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002048 unsigned QOpcodes0[] = { ARM::VST3LNq16, ARM::VST3LNq32 };
2049 unsigned QOpcodes1[] = { ARM::VST3LNq16odd, ARM::VST3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002050 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002051 }
2052
2053 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002054 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002055 unsigned QOpcodes0[] = { ARM::VST4LNq16, ARM::VST4LNq32 };
2056 unsigned QOpcodes1[] = { ARM::VST4LNq16odd, ARM::VST4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002057 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002058 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002059 }
Bob Wilson429009b2010-05-06 16:05:26 +00002060 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002061 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002062
Bob Wilson429009b2010-05-06 16:05:26 +00002063 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002064 return SelectConcatVector(N);
2065 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002066
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002067 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002068}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002069
Bob Wilson224c2442009-05-19 05:53:42 +00002070bool ARMDAGToDAGISel::
2071SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2072 std::vector<SDValue> &OutOps) {
2073 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002074 // Require the address to be in a register. That is safe for all ARM
2075 // variants and it is hard to do anything much smarter without knowing
2076 // how the operand is used.
2077 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002078 return false;
2079}
2080
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002081/// createARMISelDag - This pass converts a legalized DAG into a
2082/// ARM-specific DAG, ready for instruction scheduling.
2083///
Bob Wilson522ce972009-09-28 14:30:20 +00002084FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2085 CodeGenOpt::Level OptLevel) {
2086 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002087}
Evan Chengde8aa4e2010-05-05 18:28:36 +00002088
2089/// ModelWithRegSequence - Return true if isel should use REG_SEQUENCE to model
2090/// operations involving sub-registers.
2091bool llvm::ModelWithRegSequence() {
2092 return UseRegSeq;
2093}