blob: 57a12f09e046888210a8ca38ef7f6eba173e2299 [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
175 /// PairDRegs - Insert a pair of double registers into an implicit def to
176 /// form a quad register.
177 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000178};
Evan Chenga8e29892007-01-19 07:51:42 +0000179}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000180
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000181/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
182/// operand. If so Imm will receive the 32-bit value.
183static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
184 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
185 Imm = cast<ConstantSDNode>(N)->getZExtValue();
186 return true;
187 }
188 return false;
189}
190
191// isInt32Immediate - This method tests to see if a constant operand.
192// If so Imm will receive the 32 bit value.
193static bool isInt32Immediate(SDValue N, unsigned &Imm) {
194 return isInt32Immediate(N.getNode(), Imm);
195}
196
197// isOpcWithIntImmediate - This method tests to see if the node is a specific
198// opcode and that it has a immediate integer right operand.
199// If so Imm will receive the 32 bit value.
200static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
201 return N->getOpcode() == Opc &&
202 isInt32Immediate(N->getOperand(1).getNode(), Imm);
203}
204
205
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000206bool ARMDAGToDAGISel::SelectShifterOperandReg(SDNode *Op,
Evan Cheng055b0312009-06-29 07:51:04 +0000207 SDValue N,
208 SDValue &BaseReg,
209 SDValue &ShReg,
210 SDValue &Opc) {
211 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
212
213 // Don't match base register only case. That is matched to a separate
214 // lower complexity pattern with explicit register operand.
215 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000216
Evan Cheng055b0312009-06-29 07:51:04 +0000217 BaseReg = N.getOperand(0);
218 unsigned ShImmVal = 0;
219 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000220 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000221 ShImmVal = RHS->getZExtValue() & 31;
222 } else {
223 ShReg = N.getOperand(1);
224 }
225 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000226 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000227 return true;
228}
229
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000230bool ARMDAGToDAGISel::SelectAddrMode2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000231 SDValue &Base, SDValue &Offset,
232 SDValue &Opc) {
Evan Chenga13fd102007-03-13 21:05:54 +0000233 if (N.getOpcode() == ISD::MUL) {
234 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
235 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000236 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000237 if (RHSC & 1) {
238 RHSC = RHSC & ~1;
239 ARM_AM::AddrOpc AddSub = ARM_AM::add;
240 if (RHSC < 0) {
241 AddSub = ARM_AM::sub;
242 RHSC = - RHSC;
243 }
244 if (isPowerOf2_32(RHSC)) {
245 unsigned ShAmt = Log2_32(RHSC);
246 Base = Offset = N.getOperand(0);
247 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
248 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000249 MVT::i32);
Evan Chenga13fd102007-03-13 21:05:54 +0000250 return true;
251 }
252 }
253 }
254 }
255
Evan Chenga8e29892007-01-19 07:51:42 +0000256 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
257 Base = N;
258 if (N.getOpcode() == ISD::FrameIndex) {
259 int FI = cast<FrameIndexSDNode>(N)->getIndex();
260 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000261 } else if (N.getOpcode() == ARMISD::Wrapper &&
262 !(Subtarget->useMovt() &&
263 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000264 Base = N.getOperand(0);
265 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000266 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000267 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
268 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000269 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000270 return true;
271 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000272
Evan Chenga8e29892007-01-19 07:51:42 +0000273 // Match simple R +/- imm12 operands.
274 if (N.getOpcode() == ISD::ADD)
275 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000276 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000277 if ((RHSC >= 0 && RHSC < 0x1000) ||
278 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000279 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000280 if (Base.getOpcode() == ISD::FrameIndex) {
281 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
282 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
283 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000284 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000285
286 ARM_AM::AddrOpc AddSub = ARM_AM::add;
287 if (RHSC < 0) {
288 AddSub = ARM_AM::sub;
289 RHSC = - RHSC;
290 }
291 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000292 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000293 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000294 return true;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000295 }
Evan Chenga8e29892007-01-19 07:51:42 +0000296 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000297
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000298 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000299 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
300 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
301 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000302
Evan Chenga8e29892007-01-19 07:51:42 +0000303 Base = N.getOperand(0);
304 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000305
Evan Chenga8e29892007-01-19 07:51:42 +0000306 if (ShOpcVal != ARM_AM::no_shift) {
307 // Check to see if the RHS of the shift is a constant, if not, we can't fold
308 // it.
309 if (ConstantSDNode *Sh =
310 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000311 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000312 Offset = N.getOperand(1).getOperand(0);
313 } else {
314 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000315 }
316 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000317
Evan Chenga8e29892007-01-19 07:51:42 +0000318 // Try matching (R shl C) + (R).
319 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
320 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
321 if (ShOpcVal != ARM_AM::no_shift) {
322 // Check to see if the RHS of the shift is a constant, if not, we can't
323 // fold it.
324 if (ConstantSDNode *Sh =
325 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000326 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000327 Offset = N.getOperand(0).getOperand(0);
328 Base = N.getOperand(1);
329 } else {
330 ShOpcVal = ARM_AM::no_shift;
331 }
332 }
333 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000334
Evan Chenga8e29892007-01-19 07:51:42 +0000335 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000336 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000337 return true;
338}
339
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000340bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000341 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000342 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000343 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
344 ? cast<LoadSDNode>(Op)->getAddressingMode()
345 : cast<StoreSDNode>(Op)->getAddressingMode();
346 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
347 ? ARM_AM::add : ARM_AM::sub;
348 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000349 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000350 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000351 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000352 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
353 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000354 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000355 return true;
356 }
357 }
358
359 Offset = N;
360 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
361 unsigned ShAmt = 0;
362 if (ShOpcVal != ARM_AM::no_shift) {
363 // Check to see if the RHS of the shift is a constant, if not, we can't fold
364 // it.
365 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000366 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000367 Offset = N.getOperand(0);
368 } else {
369 ShOpcVal = ARM_AM::no_shift;
370 }
371 }
372
373 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000374 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000375 return true;
376}
377
Evan Chenga8e29892007-01-19 07:51:42 +0000378
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000379bool ARMDAGToDAGISel::SelectAddrMode3(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000380 SDValue &Base, SDValue &Offset,
381 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000382 if (N.getOpcode() == ISD::SUB) {
383 // X - C is canonicalize to X + -C, no need to handle it here.
384 Base = N.getOperand(0);
385 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000386 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000387 return true;
388 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000389
Evan Chenga8e29892007-01-19 07:51:42 +0000390 if (N.getOpcode() != ISD::ADD) {
391 Base = N;
392 if (N.getOpcode() == ISD::FrameIndex) {
393 int FI = cast<FrameIndexSDNode>(N)->getIndex();
394 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
395 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000396 Offset = CurDAG->getRegister(0, MVT::i32);
397 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000398 return true;
399 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000400
Evan Chenga8e29892007-01-19 07:51:42 +0000401 // If the RHS is +/- imm8, fold into addr mode.
402 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000403 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000404 if ((RHSC >= 0 && RHSC < 256) ||
405 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000406 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000407 if (Base.getOpcode() == ISD::FrameIndex) {
408 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
409 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
410 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000411 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000412
413 ARM_AM::AddrOpc AddSub = ARM_AM::add;
414 if (RHSC < 0) {
415 AddSub = ARM_AM::sub;
416 RHSC = - RHSC;
417 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000418 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000419 return true;
420 }
421 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000422
Evan Chenga8e29892007-01-19 07:51:42 +0000423 Base = N.getOperand(0);
424 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000425 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000426 return true;
427}
428
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000429bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000430 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000431 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000432 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
433 ? cast<LoadSDNode>(Op)->getAddressingMode()
434 : cast<StoreSDNode>(Op)->getAddressingMode();
435 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
436 ? ARM_AM::add : ARM_AM::sub;
437 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000438 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000439 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000440 Offset = CurDAG->getRegister(0, MVT::i32);
441 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000442 return true;
443 }
444 }
445
446 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000447 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000448 return true;
449}
450
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000451bool ARMDAGToDAGISel::SelectAddrMode4(SDNode *Op, SDValue N,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000452 SDValue &Addr, SDValue &Mode) {
453 Addr = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000454 Mode = CurDAG->getTargetConstant(0, MVT::i32);
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000455 return true;
456}
Evan Chenga8e29892007-01-19 07:51:42 +0000457
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000458bool ARMDAGToDAGISel::SelectAddrMode5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000459 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000460 if (N.getOpcode() != ISD::ADD) {
461 Base = N;
462 if (N.getOpcode() == ISD::FrameIndex) {
463 int FI = cast<FrameIndexSDNode>(N)->getIndex();
464 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000465 } else if (N.getOpcode() == ARMISD::Wrapper &&
466 !(Subtarget->useMovt() &&
467 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000468 Base = N.getOperand(0);
469 }
470 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000471 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000472 return true;
473 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000474
Evan Chenga8e29892007-01-19 07:51:42 +0000475 // If the RHS is +/- imm8, fold into addr mode.
476 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000477 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000478 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
479 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000480 if ((RHSC >= 0 && RHSC < 256) ||
481 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000482 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000483 if (Base.getOpcode() == ISD::FrameIndex) {
484 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
485 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
486 }
487
488 ARM_AM::AddrOpc AddSub = ARM_AM::add;
489 if (RHSC < 0) {
490 AddSub = ARM_AM::sub;
491 RHSC = - RHSC;
492 }
493 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000494 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000495 return true;
496 }
497 }
498 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000499
Evan Chenga8e29892007-01-19 07:51:42 +0000500 Base = N;
501 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000502 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000503 return true;
504}
505
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000506bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Op, SDValue N,
Bob Wilson226036e2010-03-20 22:13:40 +0000507 SDValue &Addr, SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000508 Addr = N;
Jim Grosbach8a5ec862009-11-07 21:25:39 +0000509 // Default to no alignment.
510 Align = CurDAG->getTargetConstant(0, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000511 return true;
512}
513
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000514bool ARMDAGToDAGISel::SelectAddrModePC(SDNode *Op, SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000515 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000516 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
517 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000518 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000519 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000520 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000521 return true;
522 }
523 return false;
524}
525
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000526bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000527 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000528 // FIXME dl should come from the parent load or store, not the address
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000529 DebugLoc dl = Op->getDebugLoc();
Evan Chengc38f2bc2007-01-23 22:59:13 +0000530 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000531 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
532 if (!NC || NC->getZExtValue() != 0)
533 return false;
534
535 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000536 return true;
537 }
538
Evan Chenga8e29892007-01-19 07:51:42 +0000539 Base = N.getOperand(0);
540 Offset = N.getOperand(1);
541 return true;
542}
543
Evan Cheng79d43262007-01-24 02:21:22 +0000544bool
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000545ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000546 unsigned Scale, SDValue &Base,
547 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000548 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000549 SDValue TmpBase, TmpOffImm;
Evan Cheng79d43262007-01-24 02:21:22 +0000550 if (SelectThumbAddrModeSP(Op, N, TmpBase, TmpOffImm))
551 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000552 if (N.getOpcode() == ARMISD::Wrapper &&
553 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
554 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000555 }
556
Evan Chenga8e29892007-01-19 07:51:42 +0000557 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000558 if (N.getOpcode() == ARMISD::Wrapper &&
559 !(Subtarget->useMovt() &&
560 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
561 Base = N.getOperand(0);
562 } else
563 Base = N;
564
Owen Anderson825b72b2009-08-11 20:47:22 +0000565 Offset = CurDAG->getRegister(0, MVT::i32);
566 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000567 return true;
568 }
569
Evan Chengad0e4652007-02-06 00:22:06 +0000570 // Thumb does not have [sp, r] address mode.
571 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
572 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
573 if ((LHSR && LHSR->getReg() == ARM::SP) ||
574 (RHSR && RHSR->getReg() == ARM::SP)) {
575 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000576 Offset = CurDAG->getRegister(0, MVT::i32);
577 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000578 return true;
579 }
580
Evan Chenga8e29892007-01-19 07:51:42 +0000581 // If the RHS is + imm5 * scale, fold into addr mode.
582 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000583 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000584 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
585 RHSC /= Scale;
586 if (RHSC >= 0 && RHSC < 32) {
587 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000588 Offset = CurDAG->getRegister(0, MVT::i32);
589 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000590 return true;
591 }
592 }
593 }
594
Evan Chengc38f2bc2007-01-23 22:59:13 +0000595 Base = N.getOperand(0);
596 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000597 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000598 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000599}
600
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000601bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000602 SDValue &Base, SDValue &OffImm,
603 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000604 return SelectThumbAddrModeRI5(Op, N, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000605}
606
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000607bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000608 SDValue &Base, SDValue &OffImm,
609 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000610 return SelectThumbAddrModeRI5(Op, N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000611}
612
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000613bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000614 SDValue &Base, SDValue &OffImm,
615 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000616 return SelectThumbAddrModeRI5(Op, N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000617}
618
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000619bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000620 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000621 if (N.getOpcode() == ISD::FrameIndex) {
622 int FI = cast<FrameIndexSDNode>(N)->getIndex();
623 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000624 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000625 return true;
626 }
Evan Cheng79d43262007-01-24 02:21:22 +0000627
Evan Chengad0e4652007-02-06 00:22:06 +0000628 if (N.getOpcode() != ISD::ADD)
629 return false;
630
631 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000632 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
633 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000634 // If the RHS is + imm8 * scale, fold into addr mode.
635 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000636 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000637 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
638 RHSC >>= 2;
639 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000640 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000641 if (Base.getOpcode() == ISD::FrameIndex) {
642 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
643 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
644 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000645 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000646 return true;
647 }
648 }
649 }
650 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000651
Evan Chenga8e29892007-01-19 07:51:42 +0000652 return false;
653}
654
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000655bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000656 SDValue &BaseReg,
657 SDValue &Opc) {
658 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
659
660 // Don't match base register only case. That is matched to a separate
661 // lower complexity pattern with explicit register operand.
662 if (ShOpcVal == ARM_AM::no_shift) return false;
663
664 BaseReg = N.getOperand(0);
665 unsigned ShImmVal = 0;
666 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
667 ShImmVal = RHS->getZExtValue() & 31;
668 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
669 return true;
670 }
671
672 return false;
673}
674
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000675bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000676 SDValue &Base, SDValue &OffImm) {
677 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000678
Evan Cheng3a214252009-08-11 08:52:18 +0000679 // Base only.
680 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000681 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000682 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000683 int FI = cast<FrameIndexSDNode>(N)->getIndex();
684 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000685 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000686 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000687 } else if (N.getOpcode() == ARMISD::Wrapper &&
688 !(Subtarget->useMovt() &&
689 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000690 Base = N.getOperand(0);
691 if (Base.getOpcode() == ISD::TargetConstantPool)
692 return false; // We want to select t2LDRpci instead.
693 } else
694 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000695 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000696 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000697 }
Evan Cheng055b0312009-06-29 07:51:04 +0000698
699 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Evan Cheng3a214252009-08-11 08:52:18 +0000700 if (SelectT2AddrModeImm8(Op, N, Base, OffImm))
701 // Let t2LDRi8 handle (R - imm8).
702 return false;
703
Evan Cheng055b0312009-06-29 07:51:04 +0000704 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000705 if (N.getOpcode() == ISD::SUB)
706 RHSC = -RHSC;
707
708 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +0000709 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +0000710 if (Base.getOpcode() == ISD::FrameIndex) {
711 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
712 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
713 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000714 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000715 return true;
716 }
717 }
718
Evan Cheng3a214252009-08-11 08:52:18 +0000719 // Base only.
720 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000721 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000722 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000723}
724
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000725bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000726 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +0000727 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +0000728 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +0000729 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
730 int RHSC = (int)RHS->getSExtValue();
731 if (N.getOpcode() == ISD::SUB)
732 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +0000733
Evan Cheng3a214252009-08-11 08:52:18 +0000734 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
735 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +0000736 if (Base.getOpcode() == ISD::FrameIndex) {
737 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
738 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
739 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000740 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +0000741 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000742 }
Evan Cheng055b0312009-06-29 07:51:04 +0000743 }
744 }
745
746 return false;
747}
748
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000749bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000750 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000751 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +0000752 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
753 ? cast<LoadSDNode>(Op)->getAddressingMode()
754 : cast<StoreSDNode>(Op)->getAddressingMode();
755 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
756 int RHSC = (int)RHS->getZExtValue();
757 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +0000758 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +0000759 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
760 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000761 return true;
762 }
763 }
764
765 return false;
766}
767
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000768bool ARMDAGToDAGISel::SelectT2AddrModeImm8s4(SDNode *Op, SDValue N,
David Goodwin6647cea2009-06-30 22:50:01 +0000769 SDValue &Base, SDValue &OffImm) {
770 if (N.getOpcode() == ISD::ADD) {
771 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
772 int RHSC = (int)RHS->getZExtValue();
Evan Cheng5c874172009-07-09 22:21:59 +0000773 if (((RHSC & 0x3) == 0) &&
774 ((RHSC >= 0 && RHSC < 0x400) || (RHSC < 0 && RHSC > -0x400))) { // 8 bits.
David Goodwin6647cea2009-06-30 22:50:01 +0000775 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000776 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000777 return true;
778 }
779 }
780 } else if (N.getOpcode() == ISD::SUB) {
781 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
782 int RHSC = (int)RHS->getZExtValue();
783 if (((RHSC & 0x3) == 0) && (RHSC >= 0 && RHSC < 0x400)) { // 8 bits.
784 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000785 OffImm = CurDAG->getTargetConstant(-RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000786 return true;
787 }
788 }
789 }
790
791 return false;
792}
793
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000794bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000795 SDValue &Base,
796 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +0000797 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
798 if (N.getOpcode() != ISD::ADD)
799 return false;
Evan Cheng055b0312009-06-29 07:51:04 +0000800
Evan Cheng3a214252009-08-11 08:52:18 +0000801 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
802 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
803 int RHSC = (int)RHS->getZExtValue();
804 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
805 return false;
806 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +0000807 return false;
808 }
809
Evan Cheng055b0312009-06-29 07:51:04 +0000810 // Look for (R + R) or (R + (R << [1,2,3])).
811 unsigned ShAmt = 0;
812 Base = N.getOperand(0);
813 OffReg = N.getOperand(1);
814
815 // Swap if it is ((R << c) + R).
816 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
817 if (ShOpcVal != ARM_AM::lsl) {
818 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
819 if (ShOpcVal == ARM_AM::lsl)
820 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +0000821 }
822
Evan Cheng055b0312009-06-29 07:51:04 +0000823 if (ShOpcVal == ARM_AM::lsl) {
824 // Check to see if the RHS of the shift is a constant, if not, we can't fold
825 // it.
826 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
827 ShAmt = Sh->getZExtValue();
828 if (ShAmt >= 4) {
829 ShAmt = 0;
830 ShOpcVal = ARM_AM::no_shift;
831 } else
832 OffReg = OffReg.getOperand(0);
833 } else {
834 ShOpcVal = ARM_AM::no_shift;
835 }
David Goodwin7ecc8502009-07-15 15:50:19 +0000836 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000837
Owen Anderson825b72b2009-08-11 20:47:22 +0000838 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000839
840 return true;
841}
842
843//===--------------------------------------------------------------------===//
844
Evan Chengee568cf2007-07-05 07:15:27 +0000845/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +0000846static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000847 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +0000848}
849
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000850SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
851 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +0000852 ISD::MemIndexedMode AM = LD->getAddressingMode();
853 if (AM == ISD::UNINDEXED)
854 return NULL;
855
Owen Andersone50ed302009-08-10 22:56:29 +0000856 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +0000857 SDValue Offset, AMOpc;
858 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
859 unsigned Opcode = 0;
860 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000861 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000862 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000863 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
864 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +0000865 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000866 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000867 Match = true;
868 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
869 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
870 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +0000871 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000872 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000873 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000874 Match = true;
875 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
876 }
877 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000878 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000879 Match = true;
880 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
881 }
882 }
883 }
884
885 if (Match) {
886 SDValue Chain = LD->getChain();
887 SDValue Base = LD->getBasePtr();
888 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000889 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000890 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000891 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +0000892 }
893
894 return NULL;
895}
896
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000897SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
898 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000899 ISD::MemIndexedMode AM = LD->getAddressingMode();
900 if (AM == ISD::UNINDEXED)
901 return NULL;
902
Owen Andersone50ed302009-08-10 22:56:29 +0000903 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +0000904 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000905 SDValue Offset;
906 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
907 unsigned Opcode = 0;
908 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000909 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000910 switch (LoadedVT.getSimpleVT().SimpleTy) {
911 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000912 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
913 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000914 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000915 if (isSExtLd)
916 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
917 else
918 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000919 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000920 case MVT::i8:
921 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000922 if (isSExtLd)
923 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
924 else
925 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000926 break;
927 default:
928 return NULL;
929 }
930 Match = true;
931 }
932
933 if (Match) {
934 SDValue Chain = LD->getChain();
935 SDValue Base = LD->getBasePtr();
936 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000937 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000938 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000939 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000940 }
941
942 return NULL;
943}
944
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000945/// PairDRegs - Insert a pair of double registers into an implicit def to
946/// form a quad register.
947SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
948 DebugLoc dl = V0.getNode()->getDebugLoc();
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000949 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
950 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +0000951 if (llvm::ModelWithRegSequence()) {
Evan Cheng94cc6d32010-05-04 20:39:49 +0000952 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
953 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
954 }
955 SDValue Undef =
956 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0);
Chris Lattner518bb532010-02-09 19:54:29 +0000957 SDNode *Pair = CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000958 VT, Undef, V0, SubReg0);
Chris Lattner518bb532010-02-09 19:54:29 +0000959 return CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000960 VT, SDValue(Pair, 0), V1, SubReg1);
961}
962
Bob Wilsona7c397c2009-10-14 16:19:03 +0000963/// GetNEONSubregVT - Given a type for a 128-bit NEON vector, return the type
964/// for a 64-bit subregister of the vector.
965static EVT GetNEONSubregVT(EVT VT) {
966 switch (VT.getSimpleVT().SimpleTy) {
967 default: llvm_unreachable("unhandled NEON type");
968 case MVT::v16i8: return MVT::v8i8;
969 case MVT::v8i16: return MVT::v4i16;
970 case MVT::v4f32: return MVT::v2f32;
971 case MVT::v4i32: return MVT::v2i32;
972 case MVT::v2i64: return MVT::v1i64;
973 }
974}
975
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000976SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +0000977 unsigned *DOpcodes, unsigned *QOpcodes0,
978 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +0000979 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +0000980 DebugLoc dl = N->getDebugLoc();
981
Bob Wilson226036e2010-03-20 22:13:40 +0000982 SDValue MemAddr, Align;
983 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +0000984 return NULL;
985
986 SDValue Chain = N->getOperand(0);
987 EVT VT = N->getValueType(0);
988 bool is64BitVector = VT.is64BitVector();
989
990 unsigned OpcodeIndex;
991 switch (VT.getSimpleVT().SimpleTy) {
992 default: llvm_unreachable("unhandled vld type");
993 // Double-register operations:
994 case MVT::v8i8: OpcodeIndex = 0; break;
995 case MVT::v4i16: OpcodeIndex = 1; break;
996 case MVT::v2f32:
997 case MVT::v2i32: OpcodeIndex = 2; break;
998 case MVT::v1i64: OpcodeIndex = 3; break;
999 // Quad-register operations:
1000 case MVT::v16i8: OpcodeIndex = 0; break;
1001 case MVT::v8i16: OpcodeIndex = 1; break;
1002 case MVT::v4f32:
1003 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001004 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001005 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001006 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001007 }
1008
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001009 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001010 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson3e36f132009-10-14 17:28:52 +00001011 if (is64BitVector) {
1012 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001013 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson3e36f132009-10-14 17:28:52 +00001014 std::vector<EVT> ResTys(NumVecs, VT);
1015 ResTys.push_back(MVT::Other);
Bob Wilson226036e2010-03-20 22:13:40 +00001016 return CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson3e36f132009-10-14 17:28:52 +00001017 }
1018
1019 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson621f1952010-03-23 05:25:43 +00001020 if (NumVecs <= 2) {
1021 // Quad registers are directly supported for VLD1 and VLD2,
1022 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001023 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001024 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson621f1952010-03-23 05:25:43 +00001025 std::vector<EVT> ResTys(2 * NumVecs, RegVT);
Bob Wilson3e36f132009-10-14 17:28:52 +00001026 ResTys.push_back(MVT::Other);
Bob Wilson226036e2010-03-20 22:13:40 +00001027 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson621f1952010-03-23 05:25:43 +00001028 Chain = SDValue(VLd, 2 * NumVecs);
Bob Wilson3e36f132009-10-14 17:28:52 +00001029
1030 // Combine the even and odd subregs to produce the result.
1031 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1032 SDNode *Q = PairDRegs(VT, SDValue(VLd, 2*Vec), SDValue(VLd, 2*Vec+1));
1033 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1034 }
1035 } else {
1036 // Otherwise, quad registers are loaded with two separate instructions,
1037 // where one loads the even registers and the other loads the odd registers.
1038
Bob Wilson3e36f132009-10-14 17:28:52 +00001039 std::vector<EVT> ResTys(NumVecs, RegVT);
1040 ResTys.push_back(MemAddr.getValueType());
1041 ResTys.push_back(MVT::Other);
1042
Bob Wilson24f995d2009-10-14 18:32:29 +00001043 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001044 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001045 const SDValue OpsA[] = { MemAddr, Align, Reg0, Pred, Reg0, Chain };
1046 SDNode *VLdA = CurDAG->getMachineNode(Opc, dl, ResTys, OpsA, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001047 Chain = SDValue(VLdA, NumVecs+1);
1048
Bob Wilson24f995d2009-10-14 18:32:29 +00001049 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001050 Opc = QOpcodes1[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001051 const SDValue OpsB[] = { SDValue(VLdA, NumVecs),
1052 Align, Reg0, Pred, Reg0, Chain };
1053 SDNode *VLdB = CurDAG->getMachineNode(Opc, dl, ResTys, OpsB, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001054 Chain = SDValue(VLdB, NumVecs+1);
1055
1056 // Combine the even and odd subregs to produce the result.
1057 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1058 SDNode *Q = PairDRegs(VT, SDValue(VLdA, Vec), SDValue(VLdB, Vec));
1059 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1060 }
1061 }
1062 ReplaceUses(SDValue(N, NumVecs), Chain);
1063 return NULL;
1064}
1065
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001066SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001067 unsigned *DOpcodes, unsigned *QOpcodes0,
1068 unsigned *QOpcodes1) {
Bob Wilson11d98992010-03-23 06:20:33 +00001069 assert(NumVecs >=1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001070 DebugLoc dl = N->getDebugLoc();
1071
Bob Wilson226036e2010-03-20 22:13:40 +00001072 SDValue MemAddr, Align;
1073 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001074 return NULL;
1075
1076 SDValue Chain = N->getOperand(0);
1077 EVT VT = N->getOperand(3).getValueType();
1078 bool is64BitVector = VT.is64BitVector();
1079
1080 unsigned OpcodeIndex;
1081 switch (VT.getSimpleVT().SimpleTy) {
1082 default: llvm_unreachable("unhandled vst type");
1083 // Double-register operations:
1084 case MVT::v8i8: OpcodeIndex = 0; break;
1085 case MVT::v4i16: OpcodeIndex = 1; break;
1086 case MVT::v2f32:
1087 case MVT::v2i32: OpcodeIndex = 2; break;
1088 case MVT::v1i64: OpcodeIndex = 3; break;
1089 // Quad-register operations:
1090 case MVT::v16i8: OpcodeIndex = 0; break;
1091 case MVT::v8i16: OpcodeIndex = 1; break;
1092 case MVT::v4f32:
1093 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001094 case MVT::v2i64: OpcodeIndex = 3;
1095 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1096 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001097 }
1098
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001099 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001100 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001101
Bob Wilson226036e2010-03-20 22:13:40 +00001102 SmallVector<SDValue, 10> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001103 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001104 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001105
1106 if (is64BitVector) {
1107 unsigned Opc = DOpcodes[OpcodeIndex];
1108 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1109 Ops.push_back(N->getOperand(Vec+3));
Evan Chengac0869d2009-11-21 06:21:52 +00001110 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001111 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001112 Ops.push_back(Chain);
Bob Wilson226036e2010-03-20 22:13:40 +00001113 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+5);
Bob Wilson24f995d2009-10-14 18:32:29 +00001114 }
1115
1116 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson11d98992010-03-23 06:20:33 +00001117 if (NumVecs <= 2) {
1118 // Quad registers are directly supported for VST1 and VST2,
1119 // storing pairs of D regs.
Bob Wilson24f995d2009-10-14 18:32:29 +00001120 unsigned Opc = QOpcodes0[OpcodeIndex];
1121 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1122 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1123 N->getOperand(Vec+3)));
1124 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
1125 N->getOperand(Vec+3)));
1126 }
Evan Chengac0869d2009-11-21 06:21:52 +00001127 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001128 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001129 Ops.push_back(Chain);
Bob Wilson11d98992010-03-23 06:20:33 +00001130 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(),
1131 5 + 2 * NumVecs);
Bob Wilson24f995d2009-10-14 18:32:29 +00001132 }
1133
1134 // Otherwise, quad registers are stored with two separate instructions,
1135 // where one stores the even registers and the other stores the odd registers.
1136
Bob Wilson226036e2010-03-20 22:13:40 +00001137 Ops.push_back(Reg0); // post-access address offset
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001138
Bob Wilson24f995d2009-10-14 18:32:29 +00001139 // Store the even subregs.
1140 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1141 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1142 N->getOperand(Vec+3)));
Evan Chengac0869d2009-11-21 06:21:52 +00001143 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001144 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001145 Ops.push_back(Chain);
1146 unsigned Opc = QOpcodes0[OpcodeIndex];
1147 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilson226036e2010-03-20 22:13:40 +00001148 MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001149 Chain = SDValue(VStA, 1);
1150
1151 // Store the odd subregs.
1152 Ops[0] = SDValue(VStA, 0); // MemAddr
1153 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
Bob Wilson226036e2010-03-20 22:13:40 +00001154 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
Bob Wilson24f995d2009-10-14 18:32:29 +00001155 N->getOperand(Vec+3));
Bob Wilson226036e2010-03-20 22:13:40 +00001156 Ops[NumVecs+5] = Chain;
Bob Wilson24f995d2009-10-14 18:32:29 +00001157 Opc = QOpcodes1[OpcodeIndex];
1158 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilson226036e2010-03-20 22:13:40 +00001159 MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001160 Chain = SDValue(VStB, 1);
1161 ReplaceUses(SDValue(N, 0), Chain);
1162 return NULL;
1163}
1164
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001165SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001166 unsigned NumVecs, unsigned *DOpcodes,
1167 unsigned *QOpcodes0,
1168 unsigned *QOpcodes1) {
1169 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001170 DebugLoc dl = N->getDebugLoc();
1171
Bob Wilson226036e2010-03-20 22:13:40 +00001172 SDValue MemAddr, Align;
1173 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001174 return NULL;
1175
1176 SDValue Chain = N->getOperand(0);
1177 unsigned Lane =
1178 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001179 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001180 bool is64BitVector = VT.is64BitVector();
1181
Bob Wilson96493442009-10-14 16:46:45 +00001182 // Quad registers are handled by load/store of subregs. Find the subreg info.
Bob Wilsona7c397c2009-10-14 16:19:03 +00001183 unsigned NumElts = 0;
1184 int SubregIdx = 0;
1185 EVT RegVT = VT;
1186 if (!is64BitVector) {
1187 RegVT = GetNEONSubregVT(VT);
1188 NumElts = RegVT.getVectorNumElements();
1189 SubregIdx = (Lane < NumElts) ? ARM::DSUBREG_0 : ARM::DSUBREG_1;
1190 }
1191
1192 unsigned OpcodeIndex;
1193 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001194 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001195 // Double-register operations:
1196 case MVT::v8i8: OpcodeIndex = 0; break;
1197 case MVT::v4i16: OpcodeIndex = 1; break;
1198 case MVT::v2f32:
1199 case MVT::v2i32: OpcodeIndex = 2; break;
1200 // Quad-register operations:
1201 case MVT::v8i16: OpcodeIndex = 0; break;
1202 case MVT::v4f32:
1203 case MVT::v4i32: OpcodeIndex = 1; break;
1204 }
1205
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001206 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001207 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001208
Bob Wilson226036e2010-03-20 22:13:40 +00001209 SmallVector<SDValue, 10> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001210 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001211 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001212
1213 unsigned Opc = 0;
1214 if (is64BitVector) {
1215 Opc = DOpcodes[OpcodeIndex];
1216 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1217 Ops.push_back(N->getOperand(Vec+3));
1218 } else {
1219 // Check if this is loading the even or odd subreg of a Q register.
1220 if (Lane < NumElts) {
1221 Opc = QOpcodes0[OpcodeIndex];
1222 } else {
1223 Lane -= NumElts;
1224 Opc = QOpcodes1[OpcodeIndex];
1225 }
1226 // Extract the subregs of the input vector.
1227 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1228 Ops.push_back(CurDAG->getTargetExtractSubreg(SubregIdx, dl, RegVT,
1229 N->getOperand(Vec+3)));
1230 }
1231 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001232 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001233 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001234 Ops.push_back(Chain);
1235
Bob Wilson96493442009-10-14 16:46:45 +00001236 if (!IsLoad)
Bob Wilson226036e2010-03-20 22:13:40 +00001237 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson96493442009-10-14 16:46:45 +00001238
Bob Wilsona7c397c2009-10-14 16:19:03 +00001239 std::vector<EVT> ResTys(NumVecs, RegVT);
1240 ResTys.push_back(MVT::Other);
1241 SDNode *VLdLn =
Bob Wilson226036e2010-03-20 22:13:40 +00001242 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), NumVecs+6);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001243 // For a 64-bit vector load to D registers, nothing more needs to be done.
1244 if (is64BitVector)
1245 return VLdLn;
1246
1247 // For 128-bit vectors, take the 64-bit results of the load and insert them
1248 // as subregs into the result.
1249 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1250 SDValue QuadVec = CurDAG->getTargetInsertSubreg(SubregIdx, dl, VT,
1251 N->getOperand(Vec+3),
1252 SDValue(VLdLn, Vec));
1253 ReplaceUses(SDValue(N, Vec), QuadVec);
1254 }
1255
1256 Chain = SDValue(VLdLn, NumVecs);
1257 ReplaceUses(SDValue(N, NumVecs), Chain);
1258 return NULL;
1259}
1260
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001261SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001262 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001263 if (!Subtarget->hasV6T2Ops())
1264 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001265
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001266 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1267 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1268
1269
1270 // For unsigned extracts, check for a shift right and mask
1271 unsigned And_imm = 0;
1272 if (N->getOpcode() == ISD::AND) {
1273 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1274
1275 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1276 if (And_imm & (And_imm + 1))
1277 return NULL;
1278
1279 unsigned Srl_imm = 0;
1280 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1281 Srl_imm)) {
1282 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1283
1284 unsigned Width = CountTrailingOnes_32(And_imm);
1285 unsigned LSB = Srl_imm;
1286 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1287 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1288 CurDAG->getTargetConstant(LSB, MVT::i32),
1289 CurDAG->getTargetConstant(Width, MVT::i32),
1290 getAL(CurDAG), Reg0 };
1291 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1292 }
1293 }
1294 return NULL;
1295 }
1296
1297 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001298 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001299 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001300 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1301 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001302 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001303 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1304 unsigned Width = 32 - Srl_imm;
1305 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001306 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001307 return NULL;
1308 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001309 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001310 CurDAG->getTargetConstant(LSB, MVT::i32),
1311 CurDAG->getTargetConstant(Width, MVT::i32),
1312 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001313 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001314 }
1315 }
1316 return NULL;
1317}
1318
Evan Cheng9ef48352009-11-20 00:54:03 +00001319SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001320SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001321 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1322 SDValue CPTmp0;
1323 SDValue CPTmp1;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001324 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001325 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1326 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1327 unsigned Opc = 0;
1328 switch (SOShOp) {
1329 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1330 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1331 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1332 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1333 default:
1334 llvm_unreachable("Unknown so_reg opcode!");
1335 break;
1336 }
1337 SDValue SOShImm =
1338 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1339 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1340 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001341 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001342 }
1343 return 0;
1344}
1345
1346SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001347SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001348 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1349 SDValue CPTmp0;
1350 SDValue CPTmp1;
1351 SDValue CPTmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001352 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001353 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1354 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001355 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001356 }
1357 return 0;
1358}
1359
1360SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001361SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001362 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1363 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1364 if (!T)
1365 return 0;
1366
1367 if (Predicate_t2_so_imm(TrueVal.getNode())) {
1368 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1369 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1370 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001371 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001372 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1373 }
1374 return 0;
1375}
1376
1377SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001378SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001379 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1380 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1381 if (!T)
1382 return 0;
1383
1384 if (Predicate_so_imm(TrueVal.getNode())) {
1385 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1386 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1387 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001388 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001389 ARM::MOVCCi, MVT::i32, Ops, 5);
1390 }
1391 return 0;
1392}
1393
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001394SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1395 EVT VT = N->getValueType(0);
1396 SDValue FalseVal = N->getOperand(0);
1397 SDValue TrueVal = N->getOperand(1);
1398 SDValue CC = N->getOperand(2);
1399 SDValue CCR = N->getOperand(3);
1400 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001401 assert(CC.getOpcode() == ISD::Constant);
1402 assert(CCR.getOpcode() == ISD::Register);
1403 ARMCC::CondCodes CCVal =
1404 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001405
1406 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1407 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1408 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1409 // Pattern complexity = 18 cost = 1 size = 0
1410 SDValue CPTmp0;
1411 SDValue CPTmp1;
1412 SDValue CPTmp2;
1413 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001414 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001415 CCVal, CCR, InFlag);
1416 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001417 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001418 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1419 if (Res)
1420 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001421 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001422 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001423 CCVal, CCR, InFlag);
1424 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001425 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001426 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1427 if (Res)
1428 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001429 }
1430
1431 // Pattern: (ARMcmov:i32 GPR:i32:$false,
1432 // (imm:i32)<<P:Predicate_so_imm>>:$true,
1433 // (imm:i32):$cc)
1434 // Emits: (MOVCCi:i32 GPR:i32:$false,
1435 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1436 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001437 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001438 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001439 CCVal, CCR, InFlag);
1440 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001441 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001442 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1443 if (Res)
1444 return Res;
1445 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001446 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001447 CCVal, CCR, InFlag);
1448 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001449 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001450 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1451 if (Res)
1452 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001453 }
1454 }
1455
1456 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1457 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1458 // Pattern complexity = 6 cost = 1 size = 0
1459 //
1460 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1461 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1462 // Pattern complexity = 6 cost = 11 size = 0
1463 //
1464 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001465 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1466 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001467 unsigned Opc = 0;
1468 switch (VT.getSimpleVT().SimpleTy) {
1469 default: assert(false && "Illegal conditional move type!");
1470 break;
1471 case MVT::i32:
1472 Opc = Subtarget->isThumb()
1473 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1474 : ARM::MOVCCr;
1475 break;
1476 case MVT::f32:
1477 Opc = ARM::VMOVScc;
1478 break;
1479 case MVT::f64:
1480 Opc = ARM::VMOVDcc;
1481 break;
1482 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001483 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001484}
1485
Evan Chengde8aa4e2010-05-05 18:28:36 +00001486SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
1487 // The only time a CONCAT_VECTORS operation can have legal types is when
1488 // two 64-bit vectors are concatenated to a 128-bit vector.
1489 EVT VT = N->getValueType(0);
1490 if (!VT.is128BitVector() || N->getNumOperands() != 2)
1491 llvm_unreachable("unexpected CONCAT_VECTORS");
1492 DebugLoc dl = N->getDebugLoc();
1493 SDValue V0 = N->getOperand(0);
1494 SDValue V1 = N->getOperand(1);
1495 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
1496 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
1497 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1498 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1499}
1500
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001501SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001502 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001503
Dan Gohmane8be6c62008-07-17 19:10:17 +00001504 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001505 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001506
1507 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001508 default: break;
1509 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001510 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001511 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001512 if (Subtarget->hasThumb2())
1513 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1514 // be done with MOV + MOVT, at worst.
1515 UseCP = 0;
1516 else {
1517 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001518 UseCP = (Val > 255 && // MOV
1519 ~Val > 255 && // MOV + MVN
1520 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001521 } else
1522 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1523 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1524 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1525 }
1526
Evan Chenga8e29892007-01-19 07:51:42 +00001527 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001528 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001529 CurDAG->getTargetConstantPool(ConstantInt::get(
1530 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001531 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001532
1533 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001534 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001535 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001536 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001537 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001538 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1539 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001540 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001541 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001542 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001543 CurDAG->getRegister(0, MVT::i32),
1544 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001545 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001546 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001547 CurDAG->getEntryNode()
1548 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001549 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1550 Ops, 6);
Evan Cheng012f2d92007-01-24 08:53:17 +00001551 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001552 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001553 return NULL;
1554 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001555
Evan Chenga8e29892007-01-19 07:51:42 +00001556 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001557 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001558 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001559 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001560 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001561 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001562 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001563 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001564 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1565 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001566 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001567 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1568 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001569 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1570 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1571 CurDAG->getRegister(0, MVT::i32) };
1572 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001573 }
Evan Chenga8e29892007-01-19 07:51:42 +00001574 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001575 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001576 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001577 return I;
1578 break;
1579 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001580 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001581 return I;
1582 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001583 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001584 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001585 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001586 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001587 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001588 if (!RHSV) break;
1589 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001590 unsigned ShImm = Log2_32(RHSV-1);
1591 if (ShImm >= 32)
1592 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001593 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001594 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001595 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1596 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001597 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001598 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001599 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001600 } else {
1601 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001602 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001603 }
Evan Chenga8e29892007-01-19 07:51:42 +00001604 }
1605 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001606 unsigned ShImm = Log2_32(RHSV+1);
1607 if (ShImm >= 32)
1608 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001609 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001610 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001611 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1612 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001613 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001614 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001615 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 5);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001616 } else {
1617 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001618 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001619 }
Evan Chenga8e29892007-01-19 07:51:42 +00001620 }
1621 }
1622 break;
Evan Cheng20956592009-10-21 08:15:52 +00001623 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001624 // Check for unsigned bitfield extract
1625 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1626 return I;
1627
Evan Cheng20956592009-10-21 08:15:52 +00001628 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1629 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1630 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1631 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1632 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001633 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001634 if (VT != MVT::i32)
1635 break;
1636 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1637 ? ARM::t2MOVTi16
1638 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1639 if (!Opc)
1640 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001641 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001642 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1643 if (!N1C)
1644 break;
1645 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1646 SDValue N2 = N0.getOperand(1);
1647 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1648 if (!N2C)
1649 break;
1650 unsigned N1CVal = N1C->getZExtValue();
1651 unsigned N2CVal = N2C->getZExtValue();
1652 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1653 (N1CVal & 0xffffU) == 0xffffU &&
1654 (N2CVal & 0xffffU) == 0x0U) {
1655 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1656 MVT::i32);
1657 SDValue Ops[] = { N0.getOperand(0), Imm16,
1658 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1659 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
1660 }
1661 }
1662 break;
1663 }
Jim Grosbache5165492009-11-09 00:11:35 +00001664 case ARMISD::VMOVRRD:
1665 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001666 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00001667 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00001668 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001669 if (Subtarget->isThumb1Only())
1670 break;
1671 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001672 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001673 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1674 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001675 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001676 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001677 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001678 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1679 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001680 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001681 }
Evan Chengee568cf2007-07-05 07:15:27 +00001682 }
Dan Gohman525178c2007-10-08 18:33:35 +00001683 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001684 if (Subtarget->isThumb1Only())
1685 break;
1686 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001687 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001688 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001689 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001690 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001691 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001692 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1693 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001694 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001695 }
Evan Chengee568cf2007-07-05 07:15:27 +00001696 }
Evan Chenga8e29892007-01-19 07:51:42 +00001697 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00001698 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001699 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001700 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001701 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001702 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001703 if (ResNode)
1704 return ResNode;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00001705
1706 // VLDMQ must be custom-selected for "v2f64 load" to set the AM5Opc value.
1707 if (Subtarget->hasVFP2() &&
1708 N->getValueType(0).getSimpleVT().SimpleTy == MVT::v2f64) {
1709 SDValue Chain = N->getOperand(0);
1710 SDValue AM5Opc =
1711 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001712 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00001713 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1714 SDValue Ops[] = { N->getOperand(1), AM5Opc, Pred, PredReg, Chain };
1715 return CurDAG->getMachineNode(ARM::VLDMQ, dl, MVT::v2f64, MVT::Other,
1716 Ops, 5);
1717 }
1718 // Other cases are autogenerated.
1719 break;
1720 }
1721 case ISD::STORE: {
1722 // VSTMQ must be custom-selected for "v2f64 store" to set the AM5Opc value.
1723 if (Subtarget->hasVFP2() &&
1724 N->getOperand(1).getValueType().getSimpleVT().SimpleTy == MVT::v2f64) {
1725 SDValue Chain = N->getOperand(0);
1726 SDValue AM5Opc =
1727 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001728 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00001729 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1730 SDValue Ops[] = { N->getOperand(1), N->getOperand(2),
1731 AM5Opc, Pred, PredReg, Chain };
1732 return CurDAG->getMachineNode(ARM::VSTMQ, dl, MVT::Other, Ops, 6);
1733 }
Evan Chenga8e29892007-01-19 07:51:42 +00001734 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001735 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001736 }
Evan Chengee568cf2007-07-05 07:15:27 +00001737 case ARMISD::BRCOND: {
1738 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1739 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1740 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001741
Evan Chengee568cf2007-07-05 07:15:27 +00001742 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1743 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
1744 // Pattern complexity = 6 cost = 1 size = 0
1745
David Goodwin5e47a9a2009-06-30 18:04:13 +00001746 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1747 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1748 // Pattern complexity = 6 cost = 1 size = 0
1749
Jim Grosbach764ab522009-08-11 15:33:49 +00001750 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00001751 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001752 SDValue Chain = N->getOperand(0);
1753 SDValue N1 = N->getOperand(1);
1754 SDValue N2 = N->getOperand(2);
1755 SDValue N3 = N->getOperand(3);
1756 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00001757 assert(N1.getOpcode() == ISD::BasicBlock);
1758 assert(N2.getOpcode() == ISD::Constant);
1759 assert(N3.getOpcode() == ISD::Register);
1760
Dan Gohman475871a2008-07-27 21:46:04 +00001761 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001762 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00001763 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00001764 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00001765 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
1766 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00001767 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001768 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00001769 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001770 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00001771 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001772 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00001773 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00001774 return NULL;
1775 }
Evan Cheng07ba9062009-11-19 21:45:22 +00001776 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001777 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00001778 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001779 EVT VT = N->getValueType(0);
1780 SDValue N0 = N->getOperand(0);
1781 SDValue N1 = N->getOperand(1);
1782 SDValue N2 = N->getOperand(2);
1783 SDValue N3 = N->getOperand(3);
1784 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00001785 assert(N2.getOpcode() == ISD::Constant);
1786 assert(N3.getOpcode() == ISD::Register);
1787
Dan Gohman475871a2008-07-27 21:46:04 +00001788 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001789 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00001790 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00001791 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00001792 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00001793 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00001794 default: assert(false && "Illegal conditional move type!");
1795 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001796 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00001797 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00001798 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001799 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00001800 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00001801 break;
Evan Chengee568cf2007-07-05 07:15:27 +00001802 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001803 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001804 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00001805
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001806 case ARMISD::VZIP: {
1807 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001808 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001809 switch (VT.getSimpleVT().SimpleTy) {
1810 default: return NULL;
1811 case MVT::v8i8: Opc = ARM::VZIPd8; break;
1812 case MVT::v4i16: Opc = ARM::VZIPd16; break;
1813 case MVT::v2f32:
1814 case MVT::v2i32: Opc = ARM::VZIPd32; break;
1815 case MVT::v16i8: Opc = ARM::VZIPq8; break;
1816 case MVT::v8i16: Opc = ARM::VZIPq16; break;
1817 case MVT::v4f32:
1818 case MVT::v4i32: Opc = ARM::VZIPq32; break;
1819 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001820 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00001821 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1822 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1823 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001824 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001825 case ARMISD::VUZP: {
1826 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001827 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001828 switch (VT.getSimpleVT().SimpleTy) {
1829 default: return NULL;
1830 case MVT::v8i8: Opc = ARM::VUZPd8; break;
1831 case MVT::v4i16: Opc = ARM::VUZPd16; break;
1832 case MVT::v2f32:
1833 case MVT::v2i32: Opc = ARM::VUZPd32; break;
1834 case MVT::v16i8: Opc = ARM::VUZPq8; break;
1835 case MVT::v8i16: Opc = ARM::VUZPq16; break;
1836 case MVT::v4f32:
1837 case MVT::v4i32: Opc = ARM::VUZPq32; break;
1838 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001839 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00001840 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1841 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1842 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001843 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001844 case ARMISD::VTRN: {
1845 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001846 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001847 switch (VT.getSimpleVT().SimpleTy) {
1848 default: return NULL;
1849 case MVT::v8i8: Opc = ARM::VTRNd8; break;
1850 case MVT::v4i16: Opc = ARM::VTRNd16; break;
1851 case MVT::v2f32:
1852 case MVT::v2i32: Opc = ARM::VTRNd32; break;
1853 case MVT::v16i8: Opc = ARM::VTRNq8; break;
1854 case MVT::v8i16: Opc = ARM::VTRNq16; break;
1855 case MVT::v4f32:
1856 case MVT::v4i32: Opc = ARM::VTRNq32; break;
1857 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001858 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00001859 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1860 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1861 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001862 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00001863
1864 case ISD::INTRINSIC_VOID:
1865 case ISD::INTRINSIC_W_CHAIN: {
1866 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00001867 switch (IntNo) {
1868 default:
1869 break;
1870
Bob Wilson621f1952010-03-23 05:25:43 +00001871 case Intrinsic::arm_neon_vld1: {
1872 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
1873 ARM::VLD1d32, ARM::VLD1d64 };
1874 unsigned QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
1875 ARM::VLD1q32, ARM::VLD1q64 };
1876 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
1877 }
1878
Bob Wilson31fb12f2009-08-26 17:39:53 +00001879 case Intrinsic::arm_neon_vld2: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001880 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
Bob Wilson621f1952010-03-23 05:25:43 +00001881 ARM::VLD2d32, ARM::VLD1q64 };
Bob Wilson3e36f132009-10-14 17:28:52 +00001882 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001883 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001884 }
1885
1886 case Intrinsic::arm_neon_vld3: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001887 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00001888 ARM::VLD3d32, ARM::VLD1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001889 unsigned QOpcodes0[] = { ARM::VLD3q8_UPD,
1890 ARM::VLD3q16_UPD,
1891 ARM::VLD3q32_UPD };
1892 unsigned QOpcodes1[] = { ARM::VLD3q8odd_UPD,
1893 ARM::VLD3q16odd_UPD,
1894 ARM::VLD3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001895 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001896 }
1897
1898 case Intrinsic::arm_neon_vld4: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001899 unsigned DOpcodes[] = { ARM::VLD4d8, ARM::VLD4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00001900 ARM::VLD4d32, ARM::VLD1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001901 unsigned QOpcodes0[] = { ARM::VLD4q8_UPD,
1902 ARM::VLD4q16_UPD,
1903 ARM::VLD4q32_UPD };
1904 unsigned QOpcodes1[] = { ARM::VLD4q8odd_UPD,
1905 ARM::VLD4q16odd_UPD,
1906 ARM::VLD4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001907 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001908 }
1909
Bob Wilson243fcc52009-09-01 04:26:28 +00001910 case Intrinsic::arm_neon_vld2lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00001911 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001912 unsigned QOpcodes0[] = { ARM::VLD2LNq16, ARM::VLD2LNq32 };
1913 unsigned QOpcodes1[] = { ARM::VLD2LNq16odd, ARM::VLD2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001914 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00001915 }
1916
1917 case Intrinsic::arm_neon_vld3lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00001918 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001919 unsigned QOpcodes0[] = { ARM::VLD3LNq16, ARM::VLD3LNq32 };
1920 unsigned QOpcodes1[] = { ARM::VLD3LNq16odd, ARM::VLD3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001921 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00001922 }
1923
1924 case Intrinsic::arm_neon_vld4lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00001925 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001926 unsigned QOpcodes0[] = { ARM::VLD4LNq16, ARM::VLD4LNq32 };
1927 unsigned QOpcodes1[] = { ARM::VLD4LNq16odd, ARM::VLD4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001928 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00001929 }
1930
Bob Wilson11d98992010-03-23 06:20:33 +00001931 case Intrinsic::arm_neon_vst1: {
1932 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
1933 ARM::VST1d32, ARM::VST1d64 };
1934 unsigned QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
1935 ARM::VST1q32, ARM::VST1q64 };
1936 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
1937 }
1938
Bob Wilson31fb12f2009-08-26 17:39:53 +00001939 case Intrinsic::arm_neon_vst2: {
Bob Wilson24f995d2009-10-14 18:32:29 +00001940 unsigned DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
Bob Wilson11d98992010-03-23 06:20:33 +00001941 ARM::VST2d32, ARM::VST1q64 };
Bob Wilson24f995d2009-10-14 18:32:29 +00001942 unsigned QOpcodes[] = { ARM::VST2q8, ARM::VST2q16, ARM::VST2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001943 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001944 }
1945
1946 case Intrinsic::arm_neon_vst3: {
Bob Wilson24f995d2009-10-14 18:32:29 +00001947 unsigned DOpcodes[] = { ARM::VST3d8, ARM::VST3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00001948 ARM::VST3d32, ARM::VST1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001949 unsigned QOpcodes0[] = { ARM::VST3q8_UPD,
1950 ARM::VST3q16_UPD,
1951 ARM::VST3q32_UPD };
1952 unsigned QOpcodes1[] = { ARM::VST3q8odd_UPD,
1953 ARM::VST3q16odd_UPD,
1954 ARM::VST3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001955 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001956 }
1957
1958 case Intrinsic::arm_neon_vst4: {
Bob Wilson24f995d2009-10-14 18:32:29 +00001959 unsigned DOpcodes[] = { ARM::VST4d8, ARM::VST4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00001960 ARM::VST4d32, ARM::VST1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001961 unsigned QOpcodes0[] = { ARM::VST4q8_UPD,
1962 ARM::VST4q16_UPD,
1963 ARM::VST4q32_UPD };
1964 unsigned QOpcodes1[] = { ARM::VST4q8odd_UPD,
1965 ARM::VST4q16odd_UPD,
1966 ARM::VST4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001967 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001968 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00001969
1970 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson96493442009-10-14 16:46:45 +00001971 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001972 unsigned QOpcodes0[] = { ARM::VST2LNq16, ARM::VST2LNq32 };
1973 unsigned QOpcodes1[] = { ARM::VST2LNq16odd, ARM::VST2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001974 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00001975 }
1976
1977 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson96493442009-10-14 16:46:45 +00001978 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001979 unsigned QOpcodes0[] = { ARM::VST3LNq16, ARM::VST3LNq32 };
1980 unsigned QOpcodes1[] = { ARM::VST3LNq16odd, ARM::VST3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001981 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00001982 }
1983
1984 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson96493442009-10-14 16:46:45 +00001985 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001986 unsigned QOpcodes0[] = { ARM::VST4LNq16, ARM::VST4LNq32 };
1987 unsigned QOpcodes1[] = { ARM::VST4LNq16odd, ARM::VST4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001988 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00001989 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00001990 }
1991 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00001992
1993 case ISD::CONCAT_VECTORS: {
1994 return SelectConcatVector(N);
1995 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00001996 }
1997
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001998 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00001999}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002000
Bob Wilson224c2442009-05-19 05:53:42 +00002001bool ARMDAGToDAGISel::
2002SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2003 std::vector<SDValue> &OutOps) {
2004 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002005 // Require the address to be in a register. That is safe for all ARM
2006 // variants and it is hard to do anything much smarter without knowing
2007 // how the operand is used.
2008 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002009 return false;
2010}
2011
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002012/// createARMISelDag - This pass converts a legalized DAG into a
2013/// ARM-specific DAG, ready for instruction scheduling.
2014///
Bob Wilson522ce972009-09-28 14:30:20 +00002015FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2016 CodeGenOpt::Level OptLevel) {
2017 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002018}
Evan Chengde8aa4e2010-05-05 18:28:36 +00002019
2020/// ModelWithRegSequence - Return true if isel should use REG_SEQUENCE to model
2021/// operations involving sub-registers.
2022bool llvm::ModelWithRegSequence() {
2023 return UseRegSeq;
2024}