blob: df4ae706b3338200f5db7fde5938434b0ef8f737 [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"
Evan Chenga8e29892007-01-19 07:51:42 +000016#include "ARMISelLowering.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000017#include "ARMTargetMachine.h"
Rafael Espindola84b19be2006-07-16 01:02:57 +000018#include "llvm/CallingConv.h"
Evan Chenga8e29892007-01-19 07:51:42 +000019#include "llvm/Constants.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000020#include "llvm/DerivedTypes.h"
21#include "llvm/Function.h"
22#include "llvm/Intrinsics.h"
Owen Anderson9adc0ab2009-07-14 23:09:55 +000023#include "llvm/LLVMContext.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000024#include "llvm/CodeGen/MachineFrameInfo.h"
25#include "llvm/CodeGen/MachineFunction.h"
26#include "llvm/CodeGen/MachineInstrBuilder.h"
27#include "llvm/CodeGen/SelectionDAG.h"
28#include "llvm/CodeGen/SelectionDAGISel.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000029#include "llvm/Target/TargetLowering.h"
Chris Lattner72939122007-05-03 00:32:00 +000030#include "llvm/Target/TargetOptions.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
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000038//===--------------------------------------------------------------------===//
39/// ARMDAGToDAGISel - ARM specific code to select ARM machine
40/// instructions for SelectionDAG operations.
41///
42namespace {
43class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000044 ARMBaseTargetMachine &TM;
Evan Cheng3f7eb8e2008-09-18 07:24:33 +000045
Evan Chenga8e29892007-01-19 07:51:42 +000046 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
47 /// make the right decision when generating code for different targets.
48 const ARMSubtarget *Subtarget;
49
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000050public:
Bob Wilson522ce972009-09-28 14:30:20 +000051 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
52 CodeGenOpt::Level OptLevel)
53 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Chenga8e29892007-01-19 07:51:42 +000054 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000055 }
56
Evan Chenga8e29892007-01-19 07:51:42 +000057 virtual const char *getPassName() const {
58 return "ARM Instruction Selection";
Anton Korobeynikov52237112009-06-17 18:13:58 +000059 }
60
Evan Cheng014bf212010-02-15 19:41:07 +000061 virtual void InstructionSelect();
62
Bob Wilsonaf4a8912009-10-08 18:51:31 +000063 /// getI32Imm - Return a target constant of type i32 with the specified
64 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000065 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000066 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000067 }
68
Dan Gohmaneeb3a002010-01-05 01:24:18 +000069 SDNode *Select(SDNode *N);
Evan Cheng014bf212010-02-15 19:41:07 +000070
Dan Gohmaneeb3a002010-01-05 01:24:18 +000071 bool SelectShifterOperandReg(SDNode *Op, SDValue N, SDValue &A,
Evan Cheng055b0312009-06-29 07:51:04 +000072 SDValue &B, SDValue &C);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000073 bool SelectAddrMode2(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000074 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000075 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +000076 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000077 bool SelectAddrMode3(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000078 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000079 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +000080 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000081 bool SelectAddrMode4(SDNode *Op, SDValue N, SDValue &Addr,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +000082 SDValue &Mode);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000083 bool SelectAddrMode5(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000084 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000085 bool SelectAddrMode6(SDNode *Op, SDValue N, SDValue &Addr, SDValue &Update,
Jim Grosbach8a5ec862009-11-07 21:25:39 +000086 SDValue &Opc, SDValue &Align);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000087
Dan Gohmaneeb3a002010-01-05 01:24:18 +000088 bool SelectAddrModePC(SDNode *Op, SDValue N, SDValue &Offset,
Bob Wilson8b024a52009-07-01 23:16:05 +000089 SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +000090
Dan Gohmaneeb3a002010-01-05 01:24:18 +000091 bool SelectThumbAddrModeRR(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000092 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000093 bool SelectThumbAddrModeRI5(SDNode *Op, SDValue N, unsigned Scale,
Dan Gohman475871a2008-07-27 21:46:04 +000094 SDValue &Base, SDValue &OffImm,
95 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000096 bool SelectThumbAddrModeS1(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000097 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000098 bool SelectThumbAddrModeS2(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000099 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000100 bool SelectThumbAddrModeS4(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000101 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000102 bool SelectThumbAddrModeSP(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000103 SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000104
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000105 bool SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000106 SDValue &BaseReg, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000107 bool SelectT2AddrModeImm12(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000108 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000109 bool SelectT2AddrModeImm8(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000110 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000111 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000112 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000113 bool SelectT2AddrModeImm8s4(SDNode *Op, SDValue N, SDValue &Base,
David Goodwin6647cea2009-06-30 22:50:01 +0000114 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000115 bool SelectT2AddrModeSoReg(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000116 SDValue &OffReg, SDValue &ShImm);
117
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000118 // Include the pieces autogenerated from the target description.
119#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000120
121private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000122 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
123 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000124 SDNode *SelectARMIndexedLoad(SDNode *N);
125 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000126
Evan Cheng86198642009-08-07 00:34:42 +0000127 /// SelectDYN_ALLOC - Select dynamic alloc for Thumb.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000128 SDNode *SelectDYN_ALLOC(SDNode *N);
Evan Chengaf4550f2009-07-02 01:23:32 +0000129
Bob Wilson3e36f132009-10-14 17:28:52 +0000130 /// SelectVLD - Select NEON load intrinsics. NumVecs should
131 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
132 /// loads of D registers and even subregs and odd subregs of Q registers.
133 /// For NumVecs == 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000134 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000135 unsigned *QOpcodes0, unsigned *QOpcodes1);
136
Bob Wilson24f995d2009-10-14 18:32:29 +0000137 /// SelectVST - Select NEON store intrinsics. NumVecs should
138 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
139 /// stores of D registers and even subregs and odd subregs of Q registers.
140 /// For NumVecs == 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000141 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000142 unsigned *QOpcodes0, unsigned *QOpcodes1);
143
Bob Wilson96493442009-10-14 16:46:45 +0000144 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000145 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson96493442009-10-14 16:46:45 +0000146 /// load/store of D registers and even subregs and odd subregs of Q registers.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000147 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
Bob Wilson96493442009-10-14 16:46:45 +0000148 unsigned *DOpcodes, unsigned *QOpcodes0,
149 unsigned *QOpcodes1);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000150
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000151 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000152 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, unsigned Opc);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000153
Evan Cheng07ba9062009-11-19 21:45:22 +0000154 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000155 SDNode *SelectCMOVOp(SDNode *N);
156 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000157 ARMCC::CondCodes CCVal, SDValue CCR,
158 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000159 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000160 ARMCC::CondCodes CCVal, SDValue CCR,
161 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000162 SDNode *SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000163 ARMCC::CondCodes CCVal, SDValue CCR,
164 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000165 SDNode *SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000166 ARMCC::CondCodes CCVal, SDValue CCR,
167 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000168
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 Gohmanf350b272008-08-23 02:25:05 +0000206void ARMDAGToDAGISel::InstructionSelect() {
David Greene8ad4c002008-10-27 21:56:29 +0000207 SelectRoot(*CurDAG);
Dan Gohmanf350b272008-08-23 02:25:05 +0000208 CurDAG->RemoveDeadNodes();
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000209}
210
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000211bool ARMDAGToDAGISel::SelectShifterOperandReg(SDNode *Op,
Evan Cheng055b0312009-06-29 07:51:04 +0000212 SDValue N,
213 SDValue &BaseReg,
214 SDValue &ShReg,
215 SDValue &Opc) {
216 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
217
218 // Don't match base register only case. That is matched to a separate
219 // lower complexity pattern with explicit register operand.
220 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000221
Evan Cheng055b0312009-06-29 07:51:04 +0000222 BaseReg = N.getOperand(0);
223 unsigned ShImmVal = 0;
224 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000225 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000226 ShImmVal = RHS->getZExtValue() & 31;
227 } else {
228 ShReg = N.getOperand(1);
229 }
230 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000231 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000232 return true;
233}
234
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000235bool ARMDAGToDAGISel::SelectAddrMode2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000236 SDValue &Base, SDValue &Offset,
237 SDValue &Opc) {
Evan Chenga13fd102007-03-13 21:05:54 +0000238 if (N.getOpcode() == ISD::MUL) {
239 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
240 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000241 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000242 if (RHSC & 1) {
243 RHSC = RHSC & ~1;
244 ARM_AM::AddrOpc AddSub = ARM_AM::add;
245 if (RHSC < 0) {
246 AddSub = ARM_AM::sub;
247 RHSC = - RHSC;
248 }
249 if (isPowerOf2_32(RHSC)) {
250 unsigned ShAmt = Log2_32(RHSC);
251 Base = Offset = N.getOperand(0);
252 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
253 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000254 MVT::i32);
Evan Chenga13fd102007-03-13 21:05:54 +0000255 return true;
256 }
257 }
258 }
259 }
260
Evan Chenga8e29892007-01-19 07:51:42 +0000261 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
262 Base = N;
263 if (N.getOpcode() == ISD::FrameIndex) {
264 int FI = cast<FrameIndexSDNode>(N)->getIndex();
265 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000266 } else if (N.getOpcode() == ARMISD::Wrapper &&
267 !(Subtarget->useMovt() &&
268 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000269 Base = N.getOperand(0);
270 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000271 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000272 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
273 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000274 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000275 return true;
276 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000277
Evan Chenga8e29892007-01-19 07:51:42 +0000278 // Match simple R +/- imm12 operands.
279 if (N.getOpcode() == ISD::ADD)
280 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000281 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000282 if ((RHSC >= 0 && RHSC < 0x1000) ||
283 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000284 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000285 if (Base.getOpcode() == ISD::FrameIndex) {
286 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
287 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
288 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000289 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000290
291 ARM_AM::AddrOpc AddSub = ARM_AM::add;
292 if (RHSC < 0) {
293 AddSub = ARM_AM::sub;
294 RHSC = - RHSC;
295 }
296 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000297 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000298 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000299 return true;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000300 }
Evan Chenga8e29892007-01-19 07:51:42 +0000301 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000302
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000303 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000304 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
305 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
306 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000307
Evan Chenga8e29892007-01-19 07:51:42 +0000308 Base = N.getOperand(0);
309 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000310
Evan Chenga8e29892007-01-19 07:51:42 +0000311 if (ShOpcVal != ARM_AM::no_shift) {
312 // Check to see if the RHS of the shift is a constant, if not, we can't fold
313 // it.
314 if (ConstantSDNode *Sh =
315 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000316 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000317 Offset = N.getOperand(1).getOperand(0);
318 } else {
319 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000320 }
321 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000322
Evan Chenga8e29892007-01-19 07:51:42 +0000323 // Try matching (R shl C) + (R).
324 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
325 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
326 if (ShOpcVal != ARM_AM::no_shift) {
327 // Check to see if the RHS of the shift is a constant, if not, we can't
328 // fold it.
329 if (ConstantSDNode *Sh =
330 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000331 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000332 Offset = N.getOperand(0).getOperand(0);
333 Base = N.getOperand(1);
334 } else {
335 ShOpcVal = ARM_AM::no_shift;
336 }
337 }
338 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000339
Evan Chenga8e29892007-01-19 07:51:42 +0000340 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000341 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000342 return true;
343}
344
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000345bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000346 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000347 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000348 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
349 ? cast<LoadSDNode>(Op)->getAddressingMode()
350 : cast<StoreSDNode>(Op)->getAddressingMode();
351 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
352 ? ARM_AM::add : ARM_AM::sub;
353 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000354 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000355 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000356 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000357 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
358 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000359 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000360 return true;
361 }
362 }
363
364 Offset = N;
365 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
366 unsigned ShAmt = 0;
367 if (ShOpcVal != ARM_AM::no_shift) {
368 // Check to see if the RHS of the shift is a constant, if not, we can't fold
369 // it.
370 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000371 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000372 Offset = N.getOperand(0);
373 } else {
374 ShOpcVal = ARM_AM::no_shift;
375 }
376 }
377
378 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000379 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000380 return true;
381}
382
Evan Chenga8e29892007-01-19 07:51:42 +0000383
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000384bool ARMDAGToDAGISel::SelectAddrMode3(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000385 SDValue &Base, SDValue &Offset,
386 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000387 if (N.getOpcode() == ISD::SUB) {
388 // X - C is canonicalize to X + -C, no need to handle it here.
389 Base = N.getOperand(0);
390 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000391 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000392 return true;
393 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000394
Evan Chenga8e29892007-01-19 07:51:42 +0000395 if (N.getOpcode() != ISD::ADD) {
396 Base = N;
397 if (N.getOpcode() == ISD::FrameIndex) {
398 int FI = cast<FrameIndexSDNode>(N)->getIndex();
399 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
400 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000401 Offset = CurDAG->getRegister(0, MVT::i32);
402 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000403 return true;
404 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000405
Evan Chenga8e29892007-01-19 07:51:42 +0000406 // If the RHS is +/- imm8, fold into addr mode.
407 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000408 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000409 if ((RHSC >= 0 && RHSC < 256) ||
410 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000411 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000412 if (Base.getOpcode() == ISD::FrameIndex) {
413 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
414 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
415 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000416 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000417
418 ARM_AM::AddrOpc AddSub = ARM_AM::add;
419 if (RHSC < 0) {
420 AddSub = ARM_AM::sub;
421 RHSC = - RHSC;
422 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000423 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000424 return true;
425 }
426 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000427
Evan Chenga8e29892007-01-19 07:51:42 +0000428 Base = N.getOperand(0);
429 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000430 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000431 return true;
432}
433
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000434bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000435 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000436 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000437 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
438 ? cast<LoadSDNode>(Op)->getAddressingMode()
439 : cast<StoreSDNode>(Op)->getAddressingMode();
440 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
441 ? ARM_AM::add : ARM_AM::sub;
442 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000443 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000444 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000445 Offset = CurDAG->getRegister(0, MVT::i32);
446 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000447 return true;
448 }
449 }
450
451 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000452 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000453 return true;
454}
455
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000456bool ARMDAGToDAGISel::SelectAddrMode4(SDNode *Op, SDValue N,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000457 SDValue &Addr, SDValue &Mode) {
458 Addr = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000459 Mode = CurDAG->getTargetConstant(0, MVT::i32);
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000460 return true;
461}
Evan Chenga8e29892007-01-19 07:51:42 +0000462
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000463bool ARMDAGToDAGISel::SelectAddrMode5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000464 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000465 if (N.getOpcode() != ISD::ADD) {
466 Base = N;
467 if (N.getOpcode() == ISD::FrameIndex) {
468 int FI = cast<FrameIndexSDNode>(N)->getIndex();
469 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000470 } else if (N.getOpcode() == ARMISD::Wrapper &&
471 !(Subtarget->useMovt() &&
472 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000473 Base = N.getOperand(0);
474 }
475 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000476 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000477 return true;
478 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000479
Evan Chenga8e29892007-01-19 07:51:42 +0000480 // If the RHS is +/- imm8, fold into addr mode.
481 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000482 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000483 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
484 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000485 if ((RHSC >= 0 && RHSC < 256) ||
486 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000487 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000488 if (Base.getOpcode() == ISD::FrameIndex) {
489 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
490 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
491 }
492
493 ARM_AM::AddrOpc AddSub = ARM_AM::add;
494 if (RHSC < 0) {
495 AddSub = ARM_AM::sub;
496 RHSC = - RHSC;
497 }
498 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000499 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000500 return true;
501 }
502 }
503 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000504
Evan Chenga8e29892007-01-19 07:51:42 +0000505 Base = N;
506 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000507 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000508 return true;
509}
510
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000511bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Op, SDValue N,
Bob Wilson8b024a52009-07-01 23:16:05 +0000512 SDValue &Addr, SDValue &Update,
Jim Grosbach8a5ec862009-11-07 21:25:39 +0000513 SDValue &Opc, SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000514 Addr = N;
Bob Wilsonff8952e2009-10-07 17:24:55 +0000515 // Default to no writeback.
Owen Anderson825b72b2009-08-11 20:47:22 +0000516 Update = CurDAG->getRegister(0, MVT::i32);
517 Opc = CurDAG->getTargetConstant(ARM_AM::getAM6Opc(false), MVT::i32);
Jim Grosbach8a5ec862009-11-07 21:25:39 +0000518 // Default to no alignment.
519 Align = CurDAG->getTargetConstant(0, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000520 return true;
521}
522
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000523bool ARMDAGToDAGISel::SelectAddrModePC(SDNode *Op, SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000524 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000525 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
526 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000527 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000528 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000529 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000530 return true;
531 }
532 return false;
533}
534
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000535bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000536 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000537 // FIXME dl should come from the parent load or store, not the address
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000538 DebugLoc dl = Op->getDebugLoc();
Evan Chengc38f2bc2007-01-23 22:59:13 +0000539 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000540 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
541 if (!NC || NC->getZExtValue() != 0)
542 return false;
543
544 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000545 return true;
546 }
547
Evan Chenga8e29892007-01-19 07:51:42 +0000548 Base = N.getOperand(0);
549 Offset = N.getOperand(1);
550 return true;
551}
552
Evan Cheng79d43262007-01-24 02:21:22 +0000553bool
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000554ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000555 unsigned Scale, SDValue &Base,
556 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000557 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000558 SDValue TmpBase, TmpOffImm;
Evan Cheng79d43262007-01-24 02:21:22 +0000559 if (SelectThumbAddrModeSP(Op, N, TmpBase, TmpOffImm))
560 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000561 if (N.getOpcode() == ARMISD::Wrapper &&
562 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
563 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000564 }
565
Evan Chenga8e29892007-01-19 07:51:42 +0000566 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000567 if (N.getOpcode() == ARMISD::Wrapper &&
568 !(Subtarget->useMovt() &&
569 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
570 Base = N.getOperand(0);
571 } else
572 Base = N;
573
Owen Anderson825b72b2009-08-11 20:47:22 +0000574 Offset = CurDAG->getRegister(0, MVT::i32);
575 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000576 return true;
577 }
578
Evan Chengad0e4652007-02-06 00:22:06 +0000579 // Thumb does not have [sp, r] address mode.
580 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
581 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
582 if ((LHSR && LHSR->getReg() == ARM::SP) ||
583 (RHSR && RHSR->getReg() == ARM::SP)) {
584 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000585 Offset = CurDAG->getRegister(0, MVT::i32);
586 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000587 return true;
588 }
589
Evan Chenga8e29892007-01-19 07:51:42 +0000590 // If the RHS is + imm5 * scale, fold into addr mode.
591 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000592 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000593 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
594 RHSC /= Scale;
595 if (RHSC >= 0 && RHSC < 32) {
596 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000597 Offset = CurDAG->getRegister(0, MVT::i32);
598 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000599 return true;
600 }
601 }
602 }
603
Evan Chengc38f2bc2007-01-23 22:59:13 +0000604 Base = N.getOperand(0);
605 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000606 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000607 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000608}
609
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000610bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000611 SDValue &Base, SDValue &OffImm,
612 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000613 return SelectThumbAddrModeRI5(Op, N, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000614}
615
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000616bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000617 SDValue &Base, SDValue &OffImm,
618 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000619 return SelectThumbAddrModeRI5(Op, N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000620}
621
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000622bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000623 SDValue &Base, SDValue &OffImm,
624 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000625 return SelectThumbAddrModeRI5(Op, N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000626}
627
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000628bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000629 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000630 if (N.getOpcode() == ISD::FrameIndex) {
631 int FI = cast<FrameIndexSDNode>(N)->getIndex();
632 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000633 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000634 return true;
635 }
Evan Cheng79d43262007-01-24 02:21:22 +0000636
Evan Chengad0e4652007-02-06 00:22:06 +0000637 if (N.getOpcode() != ISD::ADD)
638 return false;
639
640 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000641 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
642 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000643 // If the RHS is + imm8 * scale, fold into addr mode.
644 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000645 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000646 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
647 RHSC >>= 2;
648 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000649 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000650 if (Base.getOpcode() == ISD::FrameIndex) {
651 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
652 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
653 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000654 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000655 return true;
656 }
657 }
658 }
659 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000660
Evan Chenga8e29892007-01-19 07:51:42 +0000661 return false;
662}
663
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000664bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000665 SDValue &BaseReg,
666 SDValue &Opc) {
667 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
668
669 // Don't match base register only case. That is matched to a separate
670 // lower complexity pattern with explicit register operand.
671 if (ShOpcVal == ARM_AM::no_shift) return false;
672
673 BaseReg = N.getOperand(0);
674 unsigned ShImmVal = 0;
675 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
676 ShImmVal = RHS->getZExtValue() & 31;
677 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
678 return true;
679 }
680
681 return false;
682}
683
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000684bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000685 SDValue &Base, SDValue &OffImm) {
686 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000687
Evan Cheng3a214252009-08-11 08:52:18 +0000688 // Base only.
689 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000690 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000691 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000692 int FI = cast<FrameIndexSDNode>(N)->getIndex();
693 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000694 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000695 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000696 } else if (N.getOpcode() == ARMISD::Wrapper &&
697 !(Subtarget->useMovt() &&
698 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000699 Base = N.getOperand(0);
700 if (Base.getOpcode() == ISD::TargetConstantPool)
701 return false; // We want to select t2LDRpci instead.
702 } else
703 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000704 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000705 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000706 }
Evan Cheng055b0312009-06-29 07:51:04 +0000707
708 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Evan Cheng3a214252009-08-11 08:52:18 +0000709 if (SelectT2AddrModeImm8(Op, N, Base, OffImm))
710 // Let t2LDRi8 handle (R - imm8).
711 return false;
712
Evan Cheng055b0312009-06-29 07:51:04 +0000713 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000714 if (N.getOpcode() == ISD::SUB)
715 RHSC = -RHSC;
716
717 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +0000718 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +0000719 if (Base.getOpcode() == ISD::FrameIndex) {
720 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
721 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
722 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000723 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000724 return true;
725 }
726 }
727
Evan Cheng3a214252009-08-11 08:52:18 +0000728 // Base only.
729 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000730 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000731 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000732}
733
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000734bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000735 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +0000736 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +0000737 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +0000738 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
739 int RHSC = (int)RHS->getSExtValue();
740 if (N.getOpcode() == ISD::SUB)
741 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +0000742
Evan Cheng3a214252009-08-11 08:52:18 +0000743 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
744 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +0000745 if (Base.getOpcode() == ISD::FrameIndex) {
746 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
747 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
748 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000749 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +0000750 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000751 }
Evan Cheng055b0312009-06-29 07:51:04 +0000752 }
753 }
754
755 return false;
756}
757
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000758bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000759 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000760 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +0000761 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
762 ? cast<LoadSDNode>(Op)->getAddressingMode()
763 : cast<StoreSDNode>(Op)->getAddressingMode();
764 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
765 int RHSC = (int)RHS->getZExtValue();
766 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +0000767 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +0000768 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
769 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000770 return true;
771 }
772 }
773
774 return false;
775}
776
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000777bool ARMDAGToDAGISel::SelectT2AddrModeImm8s4(SDNode *Op, SDValue N,
David Goodwin6647cea2009-06-30 22:50:01 +0000778 SDValue &Base, SDValue &OffImm) {
779 if (N.getOpcode() == ISD::ADD) {
780 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
781 int RHSC = (int)RHS->getZExtValue();
Evan Cheng5c874172009-07-09 22:21:59 +0000782 if (((RHSC & 0x3) == 0) &&
783 ((RHSC >= 0 && RHSC < 0x400) || (RHSC < 0 && RHSC > -0x400))) { // 8 bits.
David Goodwin6647cea2009-06-30 22:50:01 +0000784 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 } else if (N.getOpcode() == ISD::SUB) {
790 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
791 int RHSC = (int)RHS->getZExtValue();
792 if (((RHSC & 0x3) == 0) && (RHSC >= 0 && RHSC < 0x400)) { // 8 bits.
793 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000794 OffImm = CurDAG->getTargetConstant(-RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000795 return true;
796 }
797 }
798 }
799
800 return false;
801}
802
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000803bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000804 SDValue &Base,
805 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +0000806 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
807 if (N.getOpcode() != ISD::ADD)
808 return false;
Evan Cheng055b0312009-06-29 07:51:04 +0000809
Evan Cheng3a214252009-08-11 08:52:18 +0000810 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
811 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
812 int RHSC = (int)RHS->getZExtValue();
813 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
814 return false;
815 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +0000816 return false;
817 }
818
Evan Cheng055b0312009-06-29 07:51:04 +0000819 // Look for (R + R) or (R + (R << [1,2,3])).
820 unsigned ShAmt = 0;
821 Base = N.getOperand(0);
822 OffReg = N.getOperand(1);
823
824 // Swap if it is ((R << c) + R).
825 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
826 if (ShOpcVal != ARM_AM::lsl) {
827 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
828 if (ShOpcVal == ARM_AM::lsl)
829 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +0000830 }
831
Evan Cheng055b0312009-06-29 07:51:04 +0000832 if (ShOpcVal == ARM_AM::lsl) {
833 // Check to see if the RHS of the shift is a constant, if not, we can't fold
834 // it.
835 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
836 ShAmt = Sh->getZExtValue();
837 if (ShAmt >= 4) {
838 ShAmt = 0;
839 ShOpcVal = ARM_AM::no_shift;
840 } else
841 OffReg = OffReg.getOperand(0);
842 } else {
843 ShOpcVal = ARM_AM::no_shift;
844 }
David Goodwin7ecc8502009-07-15 15:50:19 +0000845 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000846
Owen Anderson825b72b2009-08-11 20:47:22 +0000847 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000848
849 return true;
850}
851
852//===--------------------------------------------------------------------===//
853
Evan Chengee568cf2007-07-05 07:15:27 +0000854/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +0000855static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000856 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +0000857}
858
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000859SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
860 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +0000861 ISD::MemIndexedMode AM = LD->getAddressingMode();
862 if (AM == ISD::UNINDEXED)
863 return NULL;
864
Owen Andersone50ed302009-08-10 22:56:29 +0000865 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +0000866 SDValue Offset, AMOpc;
867 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
868 unsigned Opcode = 0;
869 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000870 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000871 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000872 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
873 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +0000874 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000875 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000876 Match = true;
877 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
878 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
879 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +0000880 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000881 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000882 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000883 Match = true;
884 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
885 }
886 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000887 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000888 Match = true;
889 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
890 }
891 }
892 }
893
894 if (Match) {
895 SDValue Chain = LD->getChain();
896 SDValue Base = LD->getBasePtr();
897 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000898 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000899 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000900 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +0000901 }
902
903 return NULL;
904}
905
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000906SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
907 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000908 ISD::MemIndexedMode AM = LD->getAddressingMode();
909 if (AM == ISD::UNINDEXED)
910 return NULL;
911
Owen Andersone50ed302009-08-10 22:56:29 +0000912 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +0000913 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000914 SDValue Offset;
915 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
916 unsigned Opcode = 0;
917 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000918 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000919 switch (LoadedVT.getSimpleVT().SimpleTy) {
920 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000921 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
922 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000923 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000924 if (isSExtLd)
925 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
926 else
927 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000928 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000929 case MVT::i8:
930 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000931 if (isSExtLd)
932 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
933 else
934 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000935 break;
936 default:
937 return NULL;
938 }
939 Match = true;
940 }
941
942 if (Match) {
943 SDValue Chain = LD->getChain();
944 SDValue Base = LD->getBasePtr();
945 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000946 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000947 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000948 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000949 }
950
951 return NULL;
952}
953
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000954SDNode *ARMDAGToDAGISel::SelectDYN_ALLOC(SDNode *N) {
Evan Cheng86198642009-08-07 00:34:42 +0000955 DebugLoc dl = N->getDebugLoc();
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000956 EVT VT = N->getValueType(0);
957 SDValue Chain = N->getOperand(0);
958 SDValue Size = N->getOperand(1);
959 SDValue Align = N->getOperand(2);
Owen Anderson825b72b2009-08-11 20:47:22 +0000960 SDValue SP = CurDAG->getRegister(ARM::SP, MVT::i32);
Evan Cheng86198642009-08-07 00:34:42 +0000961 int32_t AlignVal = cast<ConstantSDNode>(Align)->getSExtValue();
962 if (AlignVal < 0)
963 // We need to align the stack. Use Thumb1 tAND which is the only thumb
964 // instruction that can read and write SP. This matches to a pseudo
965 // instruction that has a chain to ensure the result is written back to
966 // the stack pointer.
Dan Gohman602b0c82009-09-25 18:54:59 +0000967 SP = SDValue(CurDAG->getMachineNode(ARM::tANDsp, dl, VT, SP, Align), 0);
Evan Cheng86198642009-08-07 00:34:42 +0000968
969 bool isC = isa<ConstantSDNode>(Size);
970 uint32_t C = isC ? cast<ConstantSDNode>(Size)->getZExtValue() : ~0UL;
971 // Handle the most common case for both Thumb1 and Thumb2:
972 // tSUBspi - immediate is between 0 ... 508 inclusive.
973 if (C <= 508 && ((C & 3) == 0))
974 // FIXME: tSUBspi encode scale 4 implicitly.
Owen Anderson825b72b2009-08-11 20:47:22 +0000975 return CurDAG->SelectNodeTo(N, ARM::tSUBspi_, VT, MVT::Other, SP,
976 CurDAG->getTargetConstant(C/4, MVT::i32),
Evan Cheng86198642009-08-07 00:34:42 +0000977 Chain);
978
979 if (Subtarget->isThumb1Only()) {
Evan Chengb89030a2009-08-11 23:00:31 +0000980 // Use tADDspr since Thumb1 does not have a sub r, sp, r. ARMISelLowering
Evan Cheng86198642009-08-07 00:34:42 +0000981 // should have negated the size operand already. FIXME: We can't insert
982 // new target independent node at this stage so we are forced to negate
Jim Grosbach764ab522009-08-11 15:33:49 +0000983 // it earlier. Is there a better solution?
Owen Anderson825b72b2009-08-11 20:47:22 +0000984 return CurDAG->SelectNodeTo(N, ARM::tADDspr_, VT, MVT::Other, SP, Size,
Evan Cheng86198642009-08-07 00:34:42 +0000985 Chain);
986 } else if (Subtarget->isThumb2()) {
987 if (isC && Predicate_t2_so_imm(Size.getNode())) {
988 // t2SUBrSPi
Owen Anderson825b72b2009-08-11 20:47:22 +0000989 SDValue Ops[] = { SP, CurDAG->getTargetConstant(C, MVT::i32), Chain };
990 return CurDAG->SelectNodeTo(N, ARM::t2SUBrSPi_, VT, MVT::Other, Ops, 3);
Evan Cheng86198642009-08-07 00:34:42 +0000991 } else if (isC && Predicate_imm0_4095(Size.getNode())) {
992 // t2SUBrSPi12
Owen Anderson825b72b2009-08-11 20:47:22 +0000993 SDValue Ops[] = { SP, CurDAG->getTargetConstant(C, MVT::i32), Chain };
994 return CurDAG->SelectNodeTo(N, ARM::t2SUBrSPi12_, VT, MVT::Other, Ops, 3);
Evan Cheng86198642009-08-07 00:34:42 +0000995 } else {
996 // t2SUBrSPs
997 SDValue Ops[] = { SP, Size,
998 getI32Imm(ARM_AM::getSORegOpc(ARM_AM::lsl,0)), Chain };
Owen Anderson825b72b2009-08-11 20:47:22 +0000999 return CurDAG->SelectNodeTo(N, ARM::t2SUBrSPs_, VT, MVT::Other, Ops, 4);
Evan Cheng86198642009-08-07 00:34:42 +00001000 }
1001 }
1002
1003 // FIXME: Add ADD / SUB sp instructions for ARM.
1004 return 0;
1005}
Evan Chenga8e29892007-01-19 07:51:42 +00001006
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001007/// PairDRegs - Insert a pair of double registers into an implicit def to
1008/// form a quad register.
1009SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1010 DebugLoc dl = V0.getNode()->getDebugLoc();
1011 SDValue Undef =
Chris Lattner518bb532010-02-09 19:54:29 +00001012 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001013 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
1014 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
Chris Lattner518bb532010-02-09 19:54:29 +00001015 SDNode *Pair = CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001016 VT, Undef, V0, SubReg0);
Chris Lattner518bb532010-02-09 19:54:29 +00001017 return CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001018 VT, SDValue(Pair, 0), V1, SubReg1);
1019}
1020
Bob Wilsona7c397c2009-10-14 16:19:03 +00001021/// GetNEONSubregVT - Given a type for a 128-bit NEON vector, return the type
1022/// for a 64-bit subregister of the vector.
1023static EVT GetNEONSubregVT(EVT VT) {
1024 switch (VT.getSimpleVT().SimpleTy) {
1025 default: llvm_unreachable("unhandled NEON type");
1026 case MVT::v16i8: return MVT::v8i8;
1027 case MVT::v8i16: return MVT::v4i16;
1028 case MVT::v4f32: return MVT::v2f32;
1029 case MVT::v4i32: return MVT::v2i32;
1030 case MVT::v2i64: return MVT::v1i64;
1031 }
1032}
1033
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001034SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001035 unsigned *DOpcodes, unsigned *QOpcodes0,
1036 unsigned *QOpcodes1) {
1037 assert(NumVecs >=2 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001038 DebugLoc dl = N->getDebugLoc();
1039
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001040 SDValue MemAddr, MemUpdate, MemOpc, Align;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001041 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, MemUpdate, MemOpc, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001042 return NULL;
1043
1044 SDValue Chain = N->getOperand(0);
1045 EVT VT = N->getValueType(0);
1046 bool is64BitVector = VT.is64BitVector();
1047
1048 unsigned OpcodeIndex;
1049 switch (VT.getSimpleVT().SimpleTy) {
1050 default: llvm_unreachable("unhandled vld type");
1051 // Double-register operations:
1052 case MVT::v8i8: OpcodeIndex = 0; break;
1053 case MVT::v4i16: OpcodeIndex = 1; break;
1054 case MVT::v2f32:
1055 case MVT::v2i32: OpcodeIndex = 2; break;
1056 case MVT::v1i64: OpcodeIndex = 3; break;
1057 // Quad-register operations:
1058 case MVT::v16i8: OpcodeIndex = 0; break;
1059 case MVT::v8i16: OpcodeIndex = 1; break;
1060 case MVT::v4f32:
1061 case MVT::v4i32: OpcodeIndex = 2; break;
1062 }
1063
Evan Chengac0869d2009-11-21 06:21:52 +00001064 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
1065 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Bob Wilson3e36f132009-10-14 17:28:52 +00001066 if (is64BitVector) {
1067 unsigned Opc = DOpcodes[OpcodeIndex];
Evan Chengac0869d2009-11-21 06:21:52 +00001068 const SDValue Ops[] = { MemAddr, MemUpdate, MemOpc, Align,
1069 Pred, PredReg, Chain };
Bob Wilson3e36f132009-10-14 17:28:52 +00001070 std::vector<EVT> ResTys(NumVecs, VT);
1071 ResTys.push_back(MVT::Other);
Evan Chengac0869d2009-11-21 06:21:52 +00001072 return CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 7);
Bob Wilson3e36f132009-10-14 17:28:52 +00001073 }
1074
1075 EVT RegVT = GetNEONSubregVT(VT);
1076 if (NumVecs == 2) {
1077 // Quad registers are directly supported for VLD2,
1078 // loading 2 pairs of D regs.
1079 unsigned Opc = QOpcodes0[OpcodeIndex];
Evan Chengac0869d2009-11-21 06:21:52 +00001080 const SDValue Ops[] = { MemAddr, MemUpdate, MemOpc, Align,
1081 Pred, PredReg, Chain };
Bob Wilson3e36f132009-10-14 17:28:52 +00001082 std::vector<EVT> ResTys(4, VT);
1083 ResTys.push_back(MVT::Other);
Evan Chengac0869d2009-11-21 06:21:52 +00001084 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 7);
Bob Wilson3e36f132009-10-14 17:28:52 +00001085 Chain = SDValue(VLd, 4);
1086
1087 // Combine the even and odd subregs to produce the result.
1088 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1089 SDNode *Q = PairDRegs(VT, SDValue(VLd, 2*Vec), SDValue(VLd, 2*Vec+1));
1090 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1091 }
1092 } else {
1093 // Otherwise, quad registers are loaded with two separate instructions,
1094 // where one loads the even registers and the other loads the odd registers.
1095
1096 // Enable writeback to the address register.
1097 MemOpc = CurDAG->getTargetConstant(ARM_AM::getAM6Opc(true), MVT::i32);
1098
1099 std::vector<EVT> ResTys(NumVecs, RegVT);
1100 ResTys.push_back(MemAddr.getValueType());
1101 ResTys.push_back(MVT::Other);
1102
Bob Wilson24f995d2009-10-14 18:32:29 +00001103 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001104 unsigned Opc = QOpcodes0[OpcodeIndex];
Evan Chengac0869d2009-11-21 06:21:52 +00001105 const SDValue OpsA[] = { MemAddr, MemUpdate, MemOpc, Align,
1106 Pred, PredReg, Chain };
1107 SDNode *VLdA = CurDAG->getMachineNode(Opc, dl, ResTys, OpsA, 7);
Bob Wilson3e36f132009-10-14 17:28:52 +00001108 Chain = SDValue(VLdA, NumVecs+1);
1109
Bob Wilson24f995d2009-10-14 18:32:29 +00001110 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001111 Opc = QOpcodes1[OpcodeIndex];
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001112 const SDValue OpsB[] = { SDValue(VLdA, NumVecs), MemUpdate, MemOpc,
Evan Chengac0869d2009-11-21 06:21:52 +00001113 Align, Pred, PredReg, Chain };
1114 SDNode *VLdB = CurDAG->getMachineNode(Opc, dl, ResTys, OpsB, 7);
Bob Wilson3e36f132009-10-14 17:28:52 +00001115 Chain = SDValue(VLdB, NumVecs+1);
1116
1117 // Combine the even and odd subregs to produce the result.
1118 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1119 SDNode *Q = PairDRegs(VT, SDValue(VLdA, Vec), SDValue(VLdB, Vec));
1120 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1121 }
1122 }
1123 ReplaceUses(SDValue(N, NumVecs), Chain);
1124 return NULL;
1125}
1126
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001127SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001128 unsigned *DOpcodes, unsigned *QOpcodes0,
1129 unsigned *QOpcodes1) {
1130 assert(NumVecs >=2 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001131 DebugLoc dl = N->getDebugLoc();
1132
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001133 SDValue MemAddr, MemUpdate, MemOpc, Align;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001134 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, MemUpdate, MemOpc, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001135 return NULL;
1136
1137 SDValue Chain = N->getOperand(0);
1138 EVT VT = N->getOperand(3).getValueType();
1139 bool is64BitVector = VT.is64BitVector();
1140
1141 unsigned OpcodeIndex;
1142 switch (VT.getSimpleVT().SimpleTy) {
1143 default: llvm_unreachable("unhandled vst type");
1144 // Double-register operations:
1145 case MVT::v8i8: OpcodeIndex = 0; break;
1146 case MVT::v4i16: OpcodeIndex = 1; break;
1147 case MVT::v2f32:
1148 case MVT::v2i32: OpcodeIndex = 2; break;
1149 case MVT::v1i64: OpcodeIndex = 3; break;
1150 // Quad-register operations:
1151 case MVT::v16i8: OpcodeIndex = 0; break;
1152 case MVT::v8i16: OpcodeIndex = 1; break;
1153 case MVT::v4f32:
1154 case MVT::v4i32: OpcodeIndex = 2; break;
1155 }
1156
Evan Chengac0869d2009-11-21 06:21:52 +00001157 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
1158 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1159
Bob Wilson24f995d2009-10-14 18:32:29 +00001160 SmallVector<SDValue, 8> Ops;
1161 Ops.push_back(MemAddr);
1162 Ops.push_back(MemUpdate);
1163 Ops.push_back(MemOpc);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001164 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001165
1166 if (is64BitVector) {
1167 unsigned Opc = DOpcodes[OpcodeIndex];
1168 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1169 Ops.push_back(N->getOperand(Vec+3));
Evan Chengac0869d2009-11-21 06:21:52 +00001170 Ops.push_back(Pred);
1171 Ops.push_back(PredReg);
Bob Wilson24f995d2009-10-14 18:32:29 +00001172 Ops.push_back(Chain);
Evan Chengac0869d2009-11-21 06:21:52 +00001173 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+7);
Bob Wilson24f995d2009-10-14 18:32:29 +00001174 }
1175
1176 EVT RegVT = GetNEONSubregVT(VT);
1177 if (NumVecs == 2) {
1178 // Quad registers are directly supported for VST2,
1179 // storing 2 pairs of D regs.
1180 unsigned Opc = QOpcodes0[OpcodeIndex];
1181 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1182 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1183 N->getOperand(Vec+3)));
1184 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
1185 N->getOperand(Vec+3)));
1186 }
Evan Chengac0869d2009-11-21 06:21:52 +00001187 Ops.push_back(Pred);
1188 Ops.push_back(PredReg);
Bob Wilson24f995d2009-10-14 18:32:29 +00001189 Ops.push_back(Chain);
Evan Chengac0869d2009-11-21 06:21:52 +00001190 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 11);
Bob Wilson24f995d2009-10-14 18:32:29 +00001191 }
1192
1193 // Otherwise, quad registers are stored with two separate instructions,
1194 // where one stores the even registers and the other stores the odd registers.
1195
1196 // Enable writeback to the address register.
1197 MemOpc = CurDAG->getTargetConstant(ARM_AM::getAM6Opc(true), MVT::i32);
1198
1199 // Store the even subregs.
1200 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1201 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1202 N->getOperand(Vec+3)));
Evan Chengac0869d2009-11-21 06:21:52 +00001203 Ops.push_back(Pred);
1204 Ops.push_back(PredReg);
Bob Wilson24f995d2009-10-14 18:32:29 +00001205 Ops.push_back(Chain);
1206 unsigned Opc = QOpcodes0[OpcodeIndex];
1207 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Evan Chengac0869d2009-11-21 06:21:52 +00001208 MVT::Other, Ops.data(), NumVecs+7);
Bob Wilson24f995d2009-10-14 18:32:29 +00001209 Chain = SDValue(VStA, 1);
1210
1211 // Store the odd subregs.
1212 Ops[0] = SDValue(VStA, 0); // MemAddr
1213 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001214 Ops[Vec+4] = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
Bob Wilson24f995d2009-10-14 18:32:29 +00001215 N->getOperand(Vec+3));
Evan Chengac0869d2009-11-21 06:21:52 +00001216 Ops[NumVecs+4] = Pred;
1217 Ops[NumVecs+5] = PredReg;
1218 Ops[NumVecs+6] = Chain;
Bob Wilson24f995d2009-10-14 18:32:29 +00001219 Opc = QOpcodes1[OpcodeIndex];
1220 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Evan Chengac0869d2009-11-21 06:21:52 +00001221 MVT::Other, Ops.data(), NumVecs+7);
Bob Wilson24f995d2009-10-14 18:32:29 +00001222 Chain = SDValue(VStB, 1);
1223 ReplaceUses(SDValue(N, 0), Chain);
1224 return NULL;
1225}
1226
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001227SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001228 unsigned NumVecs, unsigned *DOpcodes,
1229 unsigned *QOpcodes0,
1230 unsigned *QOpcodes1) {
1231 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001232 DebugLoc dl = N->getDebugLoc();
1233
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001234 SDValue MemAddr, MemUpdate, MemOpc, Align;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001235 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, MemUpdate, MemOpc, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001236 return NULL;
1237
1238 SDValue Chain = N->getOperand(0);
1239 unsigned Lane =
1240 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001241 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001242 bool is64BitVector = VT.is64BitVector();
1243
Bob Wilson96493442009-10-14 16:46:45 +00001244 // Quad registers are handled by load/store of subregs. Find the subreg info.
Bob Wilsona7c397c2009-10-14 16:19:03 +00001245 unsigned NumElts = 0;
1246 int SubregIdx = 0;
1247 EVT RegVT = VT;
1248 if (!is64BitVector) {
1249 RegVT = GetNEONSubregVT(VT);
1250 NumElts = RegVT.getVectorNumElements();
1251 SubregIdx = (Lane < NumElts) ? ARM::DSUBREG_0 : ARM::DSUBREG_1;
1252 }
1253
1254 unsigned OpcodeIndex;
1255 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001256 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001257 // Double-register operations:
1258 case MVT::v8i8: OpcodeIndex = 0; break;
1259 case MVT::v4i16: OpcodeIndex = 1; break;
1260 case MVT::v2f32:
1261 case MVT::v2i32: OpcodeIndex = 2; break;
1262 // Quad-register operations:
1263 case MVT::v8i16: OpcodeIndex = 0; break;
1264 case MVT::v4f32:
1265 case MVT::v4i32: OpcodeIndex = 1; break;
1266 }
1267
Evan Chengac0869d2009-11-21 06:21:52 +00001268 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
1269 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1270
Bob Wilsona7c397c2009-10-14 16:19:03 +00001271 SmallVector<SDValue, 9> Ops;
1272 Ops.push_back(MemAddr);
1273 Ops.push_back(MemUpdate);
1274 Ops.push_back(MemOpc);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001275 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001276
1277 unsigned Opc = 0;
1278 if (is64BitVector) {
1279 Opc = DOpcodes[OpcodeIndex];
1280 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1281 Ops.push_back(N->getOperand(Vec+3));
1282 } else {
1283 // Check if this is loading the even or odd subreg of a Q register.
1284 if (Lane < NumElts) {
1285 Opc = QOpcodes0[OpcodeIndex];
1286 } else {
1287 Lane -= NumElts;
1288 Opc = QOpcodes1[OpcodeIndex];
1289 }
1290 // Extract the subregs of the input vector.
1291 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1292 Ops.push_back(CurDAG->getTargetExtractSubreg(SubregIdx, dl, RegVT,
1293 N->getOperand(Vec+3)));
1294 }
1295 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001296 Ops.push_back(Pred);
1297 Ops.push_back(PredReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001298 Ops.push_back(Chain);
1299
Bob Wilson96493442009-10-14 16:46:45 +00001300 if (!IsLoad)
Bob Wilson507d32a2010-01-17 05:58:23 +00001301 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+8);
Bob Wilson96493442009-10-14 16:46:45 +00001302
Bob Wilsona7c397c2009-10-14 16:19:03 +00001303 std::vector<EVT> ResTys(NumVecs, RegVT);
1304 ResTys.push_back(MVT::Other);
1305 SDNode *VLdLn =
Bob Wilson507d32a2010-01-17 05:58:23 +00001306 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), NumVecs+8);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001307 // For a 64-bit vector load to D registers, nothing more needs to be done.
1308 if (is64BitVector)
1309 return VLdLn;
1310
1311 // For 128-bit vectors, take the 64-bit results of the load and insert them
1312 // as subregs into the result.
1313 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1314 SDValue QuadVec = CurDAG->getTargetInsertSubreg(SubregIdx, dl, VT,
1315 N->getOperand(Vec+3),
1316 SDValue(VLdLn, Vec));
1317 ReplaceUses(SDValue(N, Vec), QuadVec);
1318 }
1319
1320 Chain = SDValue(VLdLn, NumVecs);
1321 ReplaceUses(SDValue(N, NumVecs), Chain);
1322 return NULL;
1323}
1324
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001325SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001326 unsigned Opc) {
1327 if (!Subtarget->hasV6T2Ops())
1328 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001329
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001330 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001331 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001332 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1333 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001334 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001335 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1336 unsigned Width = 32 - Srl_imm;
1337 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001338 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001339 return NULL;
1340 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001341 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001342 CurDAG->getTargetConstant(LSB, MVT::i32),
1343 CurDAG->getTargetConstant(Width, MVT::i32),
1344 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001345 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001346 }
1347 }
1348 return NULL;
1349}
1350
Evan Cheng9ef48352009-11-20 00:54:03 +00001351SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001352SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001353 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1354 SDValue CPTmp0;
1355 SDValue CPTmp1;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001356 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001357 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1358 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1359 unsigned Opc = 0;
1360 switch (SOShOp) {
1361 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1362 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1363 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1364 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1365 default:
1366 llvm_unreachable("Unknown so_reg opcode!");
1367 break;
1368 }
1369 SDValue SOShImm =
1370 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1371 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1372 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001373 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001374 }
1375 return 0;
1376}
1377
1378SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001379SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001380 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1381 SDValue CPTmp0;
1382 SDValue CPTmp1;
1383 SDValue CPTmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001384 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001385 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1386 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001387 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001388 }
1389 return 0;
1390}
1391
1392SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001393SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001394 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1395 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1396 if (!T)
1397 return 0;
1398
1399 if (Predicate_t2_so_imm(TrueVal.getNode())) {
1400 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1401 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1402 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001403 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001404 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1405 }
1406 return 0;
1407}
1408
1409SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001410SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001411 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1412 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1413 if (!T)
1414 return 0;
1415
1416 if (Predicate_so_imm(TrueVal.getNode())) {
1417 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1418 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1419 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001420 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001421 ARM::MOVCCi, MVT::i32, Ops, 5);
1422 }
1423 return 0;
1424}
1425
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001426SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1427 EVT VT = N->getValueType(0);
1428 SDValue FalseVal = N->getOperand(0);
1429 SDValue TrueVal = N->getOperand(1);
1430 SDValue CC = N->getOperand(2);
1431 SDValue CCR = N->getOperand(3);
1432 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001433 assert(CC.getOpcode() == ISD::Constant);
1434 assert(CCR.getOpcode() == ISD::Register);
1435 ARMCC::CondCodes CCVal =
1436 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001437
1438 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1439 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1440 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1441 // Pattern complexity = 18 cost = 1 size = 0
1442 SDValue CPTmp0;
1443 SDValue CPTmp1;
1444 SDValue CPTmp2;
1445 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001446 SDNode *Res = SelectT2CMOVShiftOp(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 = SelectT2CMOVShiftOp(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 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001454 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001455 CCVal, CCR, InFlag);
1456 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001457 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001458 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1459 if (Res)
1460 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001461 }
1462
1463 // Pattern: (ARMcmov:i32 GPR:i32:$false,
1464 // (imm:i32)<<P:Predicate_so_imm>>:$true,
1465 // (imm:i32):$cc)
1466 // Emits: (MOVCCi:i32 GPR:i32:$false,
1467 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1468 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001469 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001470 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001471 CCVal, CCR, InFlag);
1472 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001473 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001474 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1475 if (Res)
1476 return Res;
1477 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001478 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001479 CCVal, CCR, InFlag);
1480 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001481 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001482 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1483 if (Res)
1484 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001485 }
1486 }
1487
1488 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1489 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1490 // Pattern complexity = 6 cost = 1 size = 0
1491 //
1492 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1493 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1494 // Pattern complexity = 6 cost = 11 size = 0
1495 //
1496 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001497 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1498 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001499 unsigned Opc = 0;
1500 switch (VT.getSimpleVT().SimpleTy) {
1501 default: assert(false && "Illegal conditional move type!");
1502 break;
1503 case MVT::i32:
1504 Opc = Subtarget->isThumb()
1505 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1506 : ARM::MOVCCr;
1507 break;
1508 case MVT::f32:
1509 Opc = ARM::VMOVScc;
1510 break;
1511 case MVT::f64:
1512 Opc = ARM::VMOVDcc;
1513 break;
1514 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001515 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001516}
1517
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001518SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001519 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001520
Dan Gohmane8be6c62008-07-17 19:10:17 +00001521 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001522 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001523
1524 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001525 default: break;
1526 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001527 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001528 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001529 if (Subtarget->hasThumb2())
1530 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1531 // be done with MOV + MOVT, at worst.
1532 UseCP = 0;
1533 else {
1534 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001535 UseCP = (Val > 255 && // MOV
1536 ~Val > 255 && // MOV + MVN
1537 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001538 } else
1539 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1540 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1541 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1542 }
1543
Evan Chenga8e29892007-01-19 07:51:42 +00001544 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001545 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001546 CurDAG->getTargetConstantPool(ConstantInt::get(
1547 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001548 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001549
1550 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001551 if (Subtarget->isThumb1Only()) {
Evan Chengac0869d2009-11-21 06:21:52 +00001552 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
Owen Anderson825b72b2009-08-11 20:47:22 +00001553 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001554 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001555 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1556 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001557 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001558 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001559 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001560 CurDAG->getRegister(0, MVT::i32),
1561 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001562 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001563 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001564 CurDAG->getEntryNode()
1565 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001566 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1567 Ops, 6);
Evan Cheng012f2d92007-01-24 08:53:17 +00001568 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001569 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001570 return NULL;
1571 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001572
Evan Chenga8e29892007-01-19 07:51:42 +00001573 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001574 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001575 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001576 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001577 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001578 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001579 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001580 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001581 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1582 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001583 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001584 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1585 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001586 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1587 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1588 CurDAG->getRegister(0, MVT::i32) };
1589 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001590 }
Evan Chenga8e29892007-01-19 07:51:42 +00001591 }
Evan Cheng86198642009-08-07 00:34:42 +00001592 case ARMISD::DYN_ALLOC:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001593 return SelectDYN_ALLOC(N);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001594 case ISD::SRL:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001595 if (SDNode *I = SelectV6T2BitfieldExtractOp(N,
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001596 Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX))
1597 return I;
1598 break;
1599 case ISD::SRA:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001600 if (SDNode *I = SelectV6T2BitfieldExtractOp(N,
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001601 Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX))
1602 return I;
1603 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001604 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001605 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001606 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001607 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001608 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001609 if (!RHSV) break;
1610 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001611 unsigned ShImm = Log2_32(RHSV-1);
1612 if (ShImm >= 32)
1613 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001614 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001615 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001616 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1617 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001618 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001619 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001620 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001621 } else {
1622 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001623 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001624 }
Evan Chenga8e29892007-01-19 07:51:42 +00001625 }
1626 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001627 unsigned ShImm = Log2_32(RHSV+1);
1628 if (ShImm >= 32)
1629 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001630 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001631 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001632 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1633 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001634 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001635 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001636 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 5);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001637 } else {
1638 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001639 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001640 }
Evan Chenga8e29892007-01-19 07:51:42 +00001641 }
1642 }
1643 break;
Evan Cheng20956592009-10-21 08:15:52 +00001644 case ISD::AND: {
1645 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1646 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1647 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1648 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1649 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001650 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001651 if (VT != MVT::i32)
1652 break;
1653 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1654 ? ARM::t2MOVTi16
1655 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1656 if (!Opc)
1657 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001658 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001659 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1660 if (!N1C)
1661 break;
1662 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1663 SDValue N2 = N0.getOperand(1);
1664 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1665 if (!N2C)
1666 break;
1667 unsigned N1CVal = N1C->getZExtValue();
1668 unsigned N2CVal = N2C->getZExtValue();
1669 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1670 (N1CVal & 0xffffU) == 0xffffU &&
1671 (N2CVal & 0xffffU) == 0x0U) {
1672 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1673 MVT::i32);
1674 SDValue Ops[] = { N0.getOperand(0), Imm16,
1675 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1676 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
1677 }
1678 }
1679 break;
1680 }
Jim Grosbache5165492009-11-09 00:11:35 +00001681 case ARMISD::VMOVRRD:
1682 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001683 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00001684 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00001685 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001686 if (Subtarget->isThumb1Only())
1687 break;
1688 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001689 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001690 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1691 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001692 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001693 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001694 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001695 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1696 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001697 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001698 }
Evan Chengee568cf2007-07-05 07:15:27 +00001699 }
Dan Gohman525178c2007-10-08 18:33:35 +00001700 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001701 if (Subtarget->isThumb1Only())
1702 break;
1703 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001704 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001705 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001706 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001707 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001708 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001709 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1710 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001711 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001712 }
Evan Chengee568cf2007-07-05 07:15:27 +00001713 }
Evan Chenga8e29892007-01-19 07:51:42 +00001714 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00001715 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001716 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001717 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001718 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001719 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001720 if (ResNode)
1721 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00001722 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001723 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001724 }
Evan Chengee568cf2007-07-05 07:15:27 +00001725 case ARMISD::BRCOND: {
1726 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1727 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1728 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001729
Evan Chengee568cf2007-07-05 07:15:27 +00001730 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1731 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
1732 // Pattern complexity = 6 cost = 1 size = 0
1733
David Goodwin5e47a9a2009-06-30 18:04:13 +00001734 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1735 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1736 // Pattern complexity = 6 cost = 1 size = 0
1737
Jim Grosbach764ab522009-08-11 15:33:49 +00001738 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00001739 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001740 SDValue Chain = N->getOperand(0);
1741 SDValue N1 = N->getOperand(1);
1742 SDValue N2 = N->getOperand(2);
1743 SDValue N3 = N->getOperand(3);
1744 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00001745 assert(N1.getOpcode() == ISD::BasicBlock);
1746 assert(N2.getOpcode() == ISD::Constant);
1747 assert(N3.getOpcode() == ISD::Register);
1748
Dan Gohman475871a2008-07-27 21:46:04 +00001749 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001750 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00001751 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00001752 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00001753 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
1754 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00001755 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001756 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00001757 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001758 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00001759 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001760 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00001761 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00001762 return NULL;
1763 }
Evan Cheng07ba9062009-11-19 21:45:22 +00001764 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001765 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00001766 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001767 EVT VT = N->getValueType(0);
1768 SDValue N0 = N->getOperand(0);
1769 SDValue N1 = N->getOperand(1);
1770 SDValue N2 = N->getOperand(2);
1771 SDValue N3 = N->getOperand(3);
1772 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00001773 assert(N2.getOpcode() == ISD::Constant);
1774 assert(N3.getOpcode() == ISD::Register);
1775
Dan Gohman475871a2008-07-27 21:46:04 +00001776 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001777 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00001778 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00001779 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00001780 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00001781 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00001782 default: assert(false && "Illegal conditional move type!");
1783 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001784 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00001785 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00001786 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001787 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00001788 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00001789 break;
Evan Chengee568cf2007-07-05 07:15:27 +00001790 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001791 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001792 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00001793
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001794 case ARMISD::VZIP: {
1795 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001796 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001797 switch (VT.getSimpleVT().SimpleTy) {
1798 default: return NULL;
1799 case MVT::v8i8: Opc = ARM::VZIPd8; break;
1800 case MVT::v4i16: Opc = ARM::VZIPd16; break;
1801 case MVT::v2f32:
1802 case MVT::v2i32: Opc = ARM::VZIPd32; break;
1803 case MVT::v16i8: Opc = ARM::VZIPq8; break;
1804 case MVT::v8i16: Opc = ARM::VZIPq16; break;
1805 case MVT::v4f32:
1806 case MVT::v4i32: Opc = ARM::VZIPq32; break;
1807 }
Evan Chengac0869d2009-11-21 06:21:52 +00001808 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
1809 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1810 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1811 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001812 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001813 case ARMISD::VUZP: {
1814 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001815 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001816 switch (VT.getSimpleVT().SimpleTy) {
1817 default: return NULL;
1818 case MVT::v8i8: Opc = ARM::VUZPd8; break;
1819 case MVT::v4i16: Opc = ARM::VUZPd16; break;
1820 case MVT::v2f32:
1821 case MVT::v2i32: Opc = ARM::VUZPd32; break;
1822 case MVT::v16i8: Opc = ARM::VUZPq8; break;
1823 case MVT::v8i16: Opc = ARM::VUZPq16; break;
1824 case MVT::v4f32:
1825 case MVT::v4i32: Opc = ARM::VUZPq32; break;
1826 }
Evan Chengac0869d2009-11-21 06:21:52 +00001827 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
1828 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1829 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1830 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001831 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001832 case ARMISD::VTRN: {
1833 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001834 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001835 switch (VT.getSimpleVT().SimpleTy) {
1836 default: return NULL;
1837 case MVT::v8i8: Opc = ARM::VTRNd8; break;
1838 case MVT::v4i16: Opc = ARM::VTRNd16; break;
1839 case MVT::v2f32:
1840 case MVT::v2i32: Opc = ARM::VTRNd32; break;
1841 case MVT::v16i8: Opc = ARM::VTRNq8; break;
1842 case MVT::v8i16: Opc = ARM::VTRNq16; break;
1843 case MVT::v4f32:
1844 case MVT::v4i32: Opc = ARM::VTRNq32; break;
1845 }
Evan Chengac0869d2009-11-21 06:21:52 +00001846 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
1847 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1848 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1849 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001850 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00001851
1852 case ISD::INTRINSIC_VOID:
1853 case ISD::INTRINSIC_W_CHAIN: {
1854 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00001855 switch (IntNo) {
1856 default:
1857 break;
1858
1859 case Intrinsic::arm_neon_vld2: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001860 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
1861 ARM::VLD2d32, ARM::VLD2d64 };
1862 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001863 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001864 }
1865
1866 case Intrinsic::arm_neon_vld3: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001867 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
1868 ARM::VLD3d32, ARM::VLD3d64 };
1869 unsigned QOpcodes0[] = { ARM::VLD3q8a, ARM::VLD3q16a, ARM::VLD3q32a };
1870 unsigned QOpcodes1[] = { ARM::VLD3q8b, ARM::VLD3q16b, ARM::VLD3q32b };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001871 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001872 }
1873
1874 case Intrinsic::arm_neon_vld4: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001875 unsigned DOpcodes[] = { ARM::VLD4d8, ARM::VLD4d16,
1876 ARM::VLD4d32, ARM::VLD4d64 };
1877 unsigned QOpcodes0[] = { ARM::VLD4q8a, ARM::VLD4q16a, ARM::VLD4q32a };
1878 unsigned QOpcodes1[] = { ARM::VLD4q8b, ARM::VLD4q16b, ARM::VLD4q32b };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001879 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001880 }
1881
Bob Wilson243fcc52009-09-01 04:26:28 +00001882 case Intrinsic::arm_neon_vld2lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00001883 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
1884 unsigned QOpcodes0[] = { ARM::VLD2LNq16a, ARM::VLD2LNq32a };
1885 unsigned QOpcodes1[] = { ARM::VLD2LNq16b, ARM::VLD2LNq32b };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001886 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00001887 }
1888
1889 case Intrinsic::arm_neon_vld3lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00001890 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
1891 unsigned QOpcodes0[] = { ARM::VLD3LNq16a, ARM::VLD3LNq32a };
1892 unsigned QOpcodes1[] = { ARM::VLD3LNq16b, ARM::VLD3LNq32b };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001893 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00001894 }
1895
1896 case Intrinsic::arm_neon_vld4lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00001897 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
1898 unsigned QOpcodes0[] = { ARM::VLD4LNq16a, ARM::VLD4LNq32a };
1899 unsigned QOpcodes1[] = { ARM::VLD4LNq16b, ARM::VLD4LNq32b };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001900 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00001901 }
1902
Bob Wilson31fb12f2009-08-26 17:39:53 +00001903 case Intrinsic::arm_neon_vst2: {
Bob Wilson24f995d2009-10-14 18:32:29 +00001904 unsigned DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
1905 ARM::VST2d32, ARM::VST2d64 };
1906 unsigned QOpcodes[] = { ARM::VST2q8, ARM::VST2q16, ARM::VST2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001907 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001908 }
1909
1910 case Intrinsic::arm_neon_vst3: {
Bob Wilson24f995d2009-10-14 18:32:29 +00001911 unsigned DOpcodes[] = { ARM::VST3d8, ARM::VST3d16,
1912 ARM::VST3d32, ARM::VST3d64 };
1913 unsigned QOpcodes0[] = { ARM::VST3q8a, ARM::VST3q16a, ARM::VST3q32a };
1914 unsigned QOpcodes1[] = { ARM::VST3q8b, ARM::VST3q16b, ARM::VST3q32b };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001915 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001916 }
1917
1918 case Intrinsic::arm_neon_vst4: {
Bob Wilson24f995d2009-10-14 18:32:29 +00001919 unsigned DOpcodes[] = { ARM::VST4d8, ARM::VST4d16,
1920 ARM::VST4d32, ARM::VST4d64 };
1921 unsigned QOpcodes0[] = { ARM::VST4q8a, ARM::VST4q16a, ARM::VST4q32a };
1922 unsigned QOpcodes1[] = { ARM::VST4q8b, ARM::VST4q16b, ARM::VST4q32b };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001923 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001924 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00001925
1926 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson96493442009-10-14 16:46:45 +00001927 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
1928 unsigned QOpcodes0[] = { ARM::VST2LNq16a, ARM::VST2LNq32a };
1929 unsigned QOpcodes1[] = { ARM::VST2LNq16b, ARM::VST2LNq32b };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001930 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00001931 }
1932
1933 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson96493442009-10-14 16:46:45 +00001934 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
1935 unsigned QOpcodes0[] = { ARM::VST3LNq16a, ARM::VST3LNq32a };
1936 unsigned QOpcodes1[] = { ARM::VST3LNq16b, ARM::VST3LNq32b };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001937 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00001938 }
1939
1940 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson96493442009-10-14 16:46:45 +00001941 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
1942 unsigned QOpcodes0[] = { ARM::VST4LNq16a, ARM::VST4LNq32a };
1943 unsigned QOpcodes1[] = { ARM::VST4LNq16b, ARM::VST4LNq32b };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001944 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00001945 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00001946 }
1947 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00001948 }
1949
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001950 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00001951}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001952
Bob Wilson224c2442009-05-19 05:53:42 +00001953bool ARMDAGToDAGISel::
1954SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
1955 std::vector<SDValue> &OutOps) {
1956 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00001957 // Require the address to be in a register. That is safe for all ARM
1958 // variants and it is hard to do anything much smarter without knowing
1959 // how the operand is used.
1960 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00001961 return false;
1962}
1963
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001964/// createARMISelDag - This pass converts a legalized DAG into a
1965/// ARM-specific DAG, ready for instruction scheduling.
1966///
Bob Wilson522ce972009-09-28 14:30:20 +00001967FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
1968 CodeGenOpt::Level OptLevel) {
1969 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001970}