blob: 0ddf5a0ecab9b6702f145e4dd372302c584c3401 [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
Bob Wilsonaf4a8912009-10-08 18:51:31 +000061 /// getI32Imm - Return a target constant of type i32 with the specified
62 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000063 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000064 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000065 }
66
Dan Gohmaneeb3a002010-01-05 01:24:18 +000067 SDNode *Select(SDNode *N);
Evan Cheng014bf212010-02-15 19:41:07 +000068
Dan Gohmaneeb3a002010-01-05 01:24:18 +000069 bool SelectShifterOperandReg(SDNode *Op, SDValue N, SDValue &A,
Evan Cheng055b0312009-06-29 07:51:04 +000070 SDValue &B, SDValue &C);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000071 bool SelectAddrMode2(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000072 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000073 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +000074 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000075 bool SelectAddrMode3(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000076 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000077 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +000078 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000079 bool SelectAddrMode4(SDNode *Op, SDValue N, SDValue &Addr,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +000080 SDValue &Mode);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000081 bool SelectAddrMode5(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000082 SDValue &Offset);
Bob Wilsona43e6bf2010-03-16 23:01:13 +000083 bool SelectAddrMode6(SDNode *Op, SDValue N, SDValue &Addr, SDValue &Update,
84 SDValue &Opc, SDValue &Align);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000085
Dan Gohmaneeb3a002010-01-05 01:24:18 +000086 bool SelectAddrModePC(SDNode *Op, SDValue N, SDValue &Offset,
Bob Wilson8b024a52009-07-01 23:16:05 +000087 SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +000088
Dan Gohmaneeb3a002010-01-05 01:24:18 +000089 bool SelectThumbAddrModeRR(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000090 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000091 bool SelectThumbAddrModeRI5(SDNode *Op, SDValue N, unsigned Scale,
Dan Gohman475871a2008-07-27 21:46:04 +000092 SDValue &Base, SDValue &OffImm,
93 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000094 bool SelectThumbAddrModeS1(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000095 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000096 bool SelectThumbAddrModeS2(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 SelectThumbAddrModeS4(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 SelectThumbAddrModeSP(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000101 SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000102
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000103 bool SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000104 SDValue &BaseReg, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000105 bool SelectT2AddrModeImm12(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000106 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000107 bool SelectT2AddrModeImm8(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 SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000110 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000111 bool SelectT2AddrModeImm8s4(SDNode *Op, SDValue N, SDValue &Base,
David Goodwin6647cea2009-06-30 22:50:01 +0000112 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000113 bool SelectT2AddrModeSoReg(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000114 SDValue &OffReg, SDValue &ShImm);
115
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000116 // Include the pieces autogenerated from the target description.
117#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000118
119private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000120 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
121 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000122 SDNode *SelectARMIndexedLoad(SDNode *N);
123 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000124
Evan Cheng86198642009-08-07 00:34:42 +0000125 /// SelectDYN_ALLOC - Select dynamic alloc for Thumb.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000126 SDNode *SelectDYN_ALLOC(SDNode *N);
Evan Chengaf4550f2009-07-02 01:23:32 +0000127
Bob Wilson3e36f132009-10-14 17:28:52 +0000128 /// SelectVLD - Select NEON load intrinsics. NumVecs should
129 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
130 /// loads of D registers and even subregs and odd subregs of Q registers.
131 /// For NumVecs == 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000132 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000133 unsigned *QOpcodes0, unsigned *QOpcodes1);
134
Bob Wilson24f995d2009-10-14 18:32:29 +0000135 /// SelectVST - Select NEON store intrinsics. NumVecs should
136 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
137 /// stores of D registers and even subregs and odd subregs of Q registers.
138 /// For NumVecs == 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000139 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000140 unsigned *QOpcodes0, unsigned *QOpcodes1);
141
Bob Wilson96493442009-10-14 16:46:45 +0000142 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000143 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson96493442009-10-14 16:46:45 +0000144 /// load/store of D registers and even subregs and odd subregs of Q registers.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000145 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
Bob Wilson96493442009-10-14 16:46:45 +0000146 unsigned *DOpcodes, unsigned *QOpcodes0,
147 unsigned *QOpcodes1);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000148
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000149 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000150 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, unsigned Opc);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000151
Evan Cheng07ba9062009-11-19 21:45:22 +0000152 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000153 SDNode *SelectCMOVOp(SDNode *N);
154 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000155 ARMCC::CondCodes CCVal, SDValue CCR,
156 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000157 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000158 ARMCC::CondCodes CCVal, SDValue CCR,
159 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000160 SDNode *SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000161 ARMCC::CondCodes CCVal, SDValue CCR,
162 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000163 SDNode *SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000164 ARMCC::CondCodes CCVal, SDValue CCR,
165 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000166
Evan Chengaf4550f2009-07-02 01:23:32 +0000167 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
168 /// inline asm expressions.
169 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
170 char ConstraintCode,
171 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000172
173 /// PairDRegs - Insert a pair of double registers into an implicit def to
174 /// form a quad register.
175 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000176};
Evan Chenga8e29892007-01-19 07:51:42 +0000177}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000178
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000179/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
180/// operand. If so Imm will receive the 32-bit value.
181static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
182 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
183 Imm = cast<ConstantSDNode>(N)->getZExtValue();
184 return true;
185 }
186 return false;
187}
188
189// isInt32Immediate - This method tests to see if a constant operand.
190// If so Imm will receive the 32 bit value.
191static bool isInt32Immediate(SDValue N, unsigned &Imm) {
192 return isInt32Immediate(N.getNode(), Imm);
193}
194
195// isOpcWithIntImmediate - This method tests to see if the node is a specific
196// opcode and that it has a immediate integer right operand.
197// If so Imm will receive the 32 bit value.
198static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
199 return N->getOpcode() == Opc &&
200 isInt32Immediate(N->getOperand(1).getNode(), Imm);
201}
202
203
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000204bool ARMDAGToDAGISel::SelectShifterOperandReg(SDNode *Op,
Evan Cheng055b0312009-06-29 07:51:04 +0000205 SDValue N,
206 SDValue &BaseReg,
207 SDValue &ShReg,
208 SDValue &Opc) {
209 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
210
211 // Don't match base register only case. That is matched to a separate
212 // lower complexity pattern with explicit register operand.
213 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000214
Evan Cheng055b0312009-06-29 07:51:04 +0000215 BaseReg = N.getOperand(0);
216 unsigned ShImmVal = 0;
217 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000218 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000219 ShImmVal = RHS->getZExtValue() & 31;
220 } else {
221 ShReg = N.getOperand(1);
222 }
223 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000224 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000225 return true;
226}
227
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000228bool ARMDAGToDAGISel::SelectAddrMode2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000229 SDValue &Base, SDValue &Offset,
230 SDValue &Opc) {
Evan Chenga13fd102007-03-13 21:05:54 +0000231 if (N.getOpcode() == ISD::MUL) {
232 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
233 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000234 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000235 if (RHSC & 1) {
236 RHSC = RHSC & ~1;
237 ARM_AM::AddrOpc AddSub = ARM_AM::add;
238 if (RHSC < 0) {
239 AddSub = ARM_AM::sub;
240 RHSC = - RHSC;
241 }
242 if (isPowerOf2_32(RHSC)) {
243 unsigned ShAmt = Log2_32(RHSC);
244 Base = Offset = N.getOperand(0);
245 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
246 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000247 MVT::i32);
Evan Chenga13fd102007-03-13 21:05:54 +0000248 return true;
249 }
250 }
251 }
252 }
253
Evan Chenga8e29892007-01-19 07:51:42 +0000254 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
255 Base = N;
256 if (N.getOpcode() == ISD::FrameIndex) {
257 int FI = cast<FrameIndexSDNode>(N)->getIndex();
258 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000259 } else if (N.getOpcode() == ARMISD::Wrapper &&
260 !(Subtarget->useMovt() &&
261 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000262 Base = N.getOperand(0);
263 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000264 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000265 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
266 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000267 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000268 return true;
269 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000270
Evan Chenga8e29892007-01-19 07:51:42 +0000271 // Match simple R +/- imm12 operands.
272 if (N.getOpcode() == ISD::ADD)
273 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000274 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000275 if ((RHSC >= 0 && RHSC < 0x1000) ||
276 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000277 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000278 if (Base.getOpcode() == ISD::FrameIndex) {
279 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
280 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
281 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000282 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000283
284 ARM_AM::AddrOpc AddSub = ARM_AM::add;
285 if (RHSC < 0) {
286 AddSub = ARM_AM::sub;
287 RHSC = - RHSC;
288 }
289 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000290 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000291 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000292 return true;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000293 }
Evan Chenga8e29892007-01-19 07:51:42 +0000294 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000295
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000296 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000297 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
298 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
299 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000300
Evan Chenga8e29892007-01-19 07:51:42 +0000301 Base = N.getOperand(0);
302 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000303
Evan Chenga8e29892007-01-19 07:51:42 +0000304 if (ShOpcVal != ARM_AM::no_shift) {
305 // Check to see if the RHS of the shift is a constant, if not, we can't fold
306 // it.
307 if (ConstantSDNode *Sh =
308 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000309 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000310 Offset = N.getOperand(1).getOperand(0);
311 } else {
312 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000313 }
314 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000315
Evan Chenga8e29892007-01-19 07:51:42 +0000316 // Try matching (R shl C) + (R).
317 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
318 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
319 if (ShOpcVal != ARM_AM::no_shift) {
320 // Check to see if the RHS of the shift is a constant, if not, we can't
321 // fold it.
322 if (ConstantSDNode *Sh =
323 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000324 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000325 Offset = N.getOperand(0).getOperand(0);
326 Base = N.getOperand(1);
327 } else {
328 ShOpcVal = ARM_AM::no_shift;
329 }
330 }
331 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000332
Evan Chenga8e29892007-01-19 07:51:42 +0000333 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000334 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000335 return true;
336}
337
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000338bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000339 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000340 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000341 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
342 ? cast<LoadSDNode>(Op)->getAddressingMode()
343 : cast<StoreSDNode>(Op)->getAddressingMode();
344 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
345 ? ARM_AM::add : ARM_AM::sub;
346 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000347 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000348 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000349 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000350 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
351 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000352 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000353 return true;
354 }
355 }
356
357 Offset = N;
358 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
359 unsigned ShAmt = 0;
360 if (ShOpcVal != ARM_AM::no_shift) {
361 // Check to see if the RHS of the shift is a constant, if not, we can't fold
362 // it.
363 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000364 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000365 Offset = N.getOperand(0);
366 } else {
367 ShOpcVal = ARM_AM::no_shift;
368 }
369 }
370
371 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000372 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000373 return true;
374}
375
Evan Chenga8e29892007-01-19 07:51:42 +0000376
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000377bool ARMDAGToDAGISel::SelectAddrMode3(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000378 SDValue &Base, SDValue &Offset,
379 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000380 if (N.getOpcode() == ISD::SUB) {
381 // X - C is canonicalize to X + -C, no need to handle it here.
382 Base = N.getOperand(0);
383 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000384 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000385 return true;
386 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000387
Evan Chenga8e29892007-01-19 07:51:42 +0000388 if (N.getOpcode() != ISD::ADD) {
389 Base = N;
390 if (N.getOpcode() == ISD::FrameIndex) {
391 int FI = cast<FrameIndexSDNode>(N)->getIndex();
392 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
393 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000394 Offset = CurDAG->getRegister(0, MVT::i32);
395 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000396 return true;
397 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000398
Evan Chenga8e29892007-01-19 07:51:42 +0000399 // If the RHS is +/- imm8, fold into addr mode.
400 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000401 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000402 if ((RHSC >= 0 && RHSC < 256) ||
403 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000404 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000405 if (Base.getOpcode() == ISD::FrameIndex) {
406 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
407 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
408 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000409 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000410
411 ARM_AM::AddrOpc AddSub = ARM_AM::add;
412 if (RHSC < 0) {
413 AddSub = ARM_AM::sub;
414 RHSC = - RHSC;
415 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000416 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000417 return true;
418 }
419 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000420
Evan Chenga8e29892007-01-19 07:51:42 +0000421 Base = N.getOperand(0);
422 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000423 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000424 return true;
425}
426
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000427bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000428 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000429 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000430 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
431 ? cast<LoadSDNode>(Op)->getAddressingMode()
432 : cast<StoreSDNode>(Op)->getAddressingMode();
433 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
434 ? ARM_AM::add : ARM_AM::sub;
435 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000436 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000437 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000438 Offset = CurDAG->getRegister(0, MVT::i32);
439 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000440 return true;
441 }
442 }
443
444 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000445 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000446 return true;
447}
448
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000449bool ARMDAGToDAGISel::SelectAddrMode4(SDNode *Op, SDValue N,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000450 SDValue &Addr, SDValue &Mode) {
451 Addr = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000452 Mode = CurDAG->getTargetConstant(0, MVT::i32);
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000453 return true;
454}
Evan Chenga8e29892007-01-19 07:51:42 +0000455
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000456bool ARMDAGToDAGISel::SelectAddrMode5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000457 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000458 if (N.getOpcode() != ISD::ADD) {
459 Base = N;
460 if (N.getOpcode() == ISD::FrameIndex) {
461 int FI = cast<FrameIndexSDNode>(N)->getIndex();
462 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000463 } else if (N.getOpcode() == ARMISD::Wrapper &&
464 !(Subtarget->useMovt() &&
465 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000466 Base = N.getOperand(0);
467 }
468 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000469 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000470 return true;
471 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000472
Evan Chenga8e29892007-01-19 07:51:42 +0000473 // If the RHS is +/- imm8, fold into addr mode.
474 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000475 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000476 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
477 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000478 if ((RHSC >= 0 && RHSC < 256) ||
479 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000480 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000481 if (Base.getOpcode() == ISD::FrameIndex) {
482 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
483 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
484 }
485
486 ARM_AM::AddrOpc AddSub = ARM_AM::add;
487 if (RHSC < 0) {
488 AddSub = ARM_AM::sub;
489 RHSC = - RHSC;
490 }
491 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000492 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000493 return true;
494 }
495 }
496 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000497
Evan Chenga8e29892007-01-19 07:51:42 +0000498 Base = N;
499 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000500 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000501 return true;
502}
503
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000504bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Op, SDValue N,
Bob Wilsona43e6bf2010-03-16 23:01:13 +0000505 SDValue &Addr, SDValue &Update,
506 SDValue &Opc, SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000507 Addr = N;
Bob Wilsona43e6bf2010-03-16 23:01:13 +0000508 // Default to no writeback.
509 Update = CurDAG->getRegister(0, MVT::i32);
510 Opc = CurDAG->getTargetConstant(ARM_AM::getAM6Opc(false), MVT::i32);
Jim Grosbach8a5ec862009-11-07 21:25:39 +0000511 // Default to no alignment.
512 Align = CurDAG->getTargetConstant(0, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000513 return true;
514}
515
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000516bool ARMDAGToDAGISel::SelectAddrModePC(SDNode *Op, SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000517 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000518 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
519 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000520 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000521 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000522 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000523 return true;
524 }
525 return false;
526}
527
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000528bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000529 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000530 // FIXME dl should come from the parent load or store, not the address
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000531 DebugLoc dl = Op->getDebugLoc();
Evan Chengc38f2bc2007-01-23 22:59:13 +0000532 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000533 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
534 if (!NC || NC->getZExtValue() != 0)
535 return false;
536
537 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000538 return true;
539 }
540
Evan Chenga8e29892007-01-19 07:51:42 +0000541 Base = N.getOperand(0);
542 Offset = N.getOperand(1);
543 return true;
544}
545
Evan Cheng79d43262007-01-24 02:21:22 +0000546bool
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000547ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000548 unsigned Scale, SDValue &Base,
549 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000550 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000551 SDValue TmpBase, TmpOffImm;
Evan Cheng79d43262007-01-24 02:21:22 +0000552 if (SelectThumbAddrModeSP(Op, N, TmpBase, TmpOffImm))
553 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000554 if (N.getOpcode() == ARMISD::Wrapper &&
555 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
556 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000557 }
558
Evan Chenga8e29892007-01-19 07:51:42 +0000559 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000560 if (N.getOpcode() == ARMISD::Wrapper &&
561 !(Subtarget->useMovt() &&
562 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
563 Base = N.getOperand(0);
564 } else
565 Base = N;
566
Owen Anderson825b72b2009-08-11 20:47:22 +0000567 Offset = CurDAG->getRegister(0, MVT::i32);
568 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000569 return true;
570 }
571
Evan Chengad0e4652007-02-06 00:22:06 +0000572 // Thumb does not have [sp, r] address mode.
573 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
574 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
575 if ((LHSR && LHSR->getReg() == ARM::SP) ||
576 (RHSR && RHSR->getReg() == ARM::SP)) {
577 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000578 Offset = CurDAG->getRegister(0, MVT::i32);
579 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000580 return true;
581 }
582
Evan Chenga8e29892007-01-19 07:51:42 +0000583 // If the RHS is + imm5 * scale, fold into addr mode.
584 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000585 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000586 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
587 RHSC /= Scale;
588 if (RHSC >= 0 && RHSC < 32) {
589 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000590 Offset = CurDAG->getRegister(0, MVT::i32);
591 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000592 return true;
593 }
594 }
595 }
596
Evan Chengc38f2bc2007-01-23 22:59:13 +0000597 Base = N.getOperand(0);
598 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000599 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000600 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000601}
602
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000603bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000604 SDValue &Base, SDValue &OffImm,
605 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000606 return SelectThumbAddrModeRI5(Op, N, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000607}
608
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000609bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000610 SDValue &Base, SDValue &OffImm,
611 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000612 return SelectThumbAddrModeRI5(Op, N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000613}
614
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000615bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000616 SDValue &Base, SDValue &OffImm,
617 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000618 return SelectThumbAddrModeRI5(Op, N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000619}
620
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000621bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000622 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000623 if (N.getOpcode() == ISD::FrameIndex) {
624 int FI = cast<FrameIndexSDNode>(N)->getIndex();
625 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000626 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000627 return true;
628 }
Evan Cheng79d43262007-01-24 02:21:22 +0000629
Evan Chengad0e4652007-02-06 00:22:06 +0000630 if (N.getOpcode() != ISD::ADD)
631 return false;
632
633 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000634 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
635 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000636 // If the RHS is + imm8 * scale, fold into addr mode.
637 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000638 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000639 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
640 RHSC >>= 2;
641 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000642 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000643 if (Base.getOpcode() == ISD::FrameIndex) {
644 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
645 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
646 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000647 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000648 return true;
649 }
650 }
651 }
652 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000653
Evan Chenga8e29892007-01-19 07:51:42 +0000654 return false;
655}
656
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000657bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000658 SDValue &BaseReg,
659 SDValue &Opc) {
660 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
661
662 // Don't match base register only case. That is matched to a separate
663 // lower complexity pattern with explicit register operand.
664 if (ShOpcVal == ARM_AM::no_shift) return false;
665
666 BaseReg = N.getOperand(0);
667 unsigned ShImmVal = 0;
668 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
669 ShImmVal = RHS->getZExtValue() & 31;
670 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
671 return true;
672 }
673
674 return false;
675}
676
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000677bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000678 SDValue &Base, SDValue &OffImm) {
679 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000680
Evan Cheng3a214252009-08-11 08:52:18 +0000681 // Base only.
682 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000683 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000684 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000685 int FI = cast<FrameIndexSDNode>(N)->getIndex();
686 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000687 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000688 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000689 } else if (N.getOpcode() == ARMISD::Wrapper &&
690 !(Subtarget->useMovt() &&
691 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000692 Base = N.getOperand(0);
693 if (Base.getOpcode() == ISD::TargetConstantPool)
694 return false; // We want to select t2LDRpci instead.
695 } else
696 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000697 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000698 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000699 }
Evan Cheng055b0312009-06-29 07:51:04 +0000700
701 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Evan Cheng3a214252009-08-11 08:52:18 +0000702 if (SelectT2AddrModeImm8(Op, N, Base, OffImm))
703 // Let t2LDRi8 handle (R - imm8).
704 return false;
705
Evan Cheng055b0312009-06-29 07:51:04 +0000706 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000707 if (N.getOpcode() == ISD::SUB)
708 RHSC = -RHSC;
709
710 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +0000711 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +0000712 if (Base.getOpcode() == ISD::FrameIndex) {
713 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
714 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
715 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000716 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000717 return true;
718 }
719 }
720
Evan Cheng3a214252009-08-11 08:52:18 +0000721 // Base only.
722 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000723 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000724 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000725}
726
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000727bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000728 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +0000729 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +0000730 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +0000731 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
732 int RHSC = (int)RHS->getSExtValue();
733 if (N.getOpcode() == ISD::SUB)
734 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +0000735
Evan Cheng3a214252009-08-11 08:52:18 +0000736 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
737 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +0000738 if (Base.getOpcode() == ISD::FrameIndex) {
739 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
740 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
741 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000742 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +0000743 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000744 }
Evan Cheng055b0312009-06-29 07:51:04 +0000745 }
746 }
747
748 return false;
749}
750
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000751bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000752 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000753 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +0000754 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
755 ? cast<LoadSDNode>(Op)->getAddressingMode()
756 : cast<StoreSDNode>(Op)->getAddressingMode();
757 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
758 int RHSC = (int)RHS->getZExtValue();
759 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +0000760 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +0000761 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
762 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000763 return true;
764 }
765 }
766
767 return false;
768}
769
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000770bool ARMDAGToDAGISel::SelectT2AddrModeImm8s4(SDNode *Op, SDValue N,
David Goodwin6647cea2009-06-30 22:50:01 +0000771 SDValue &Base, SDValue &OffImm) {
772 if (N.getOpcode() == ISD::ADD) {
773 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
774 int RHSC = (int)RHS->getZExtValue();
Evan Cheng5c874172009-07-09 22:21:59 +0000775 if (((RHSC & 0x3) == 0) &&
776 ((RHSC >= 0 && RHSC < 0x400) || (RHSC < 0 && RHSC > -0x400))) { // 8 bits.
David Goodwin6647cea2009-06-30 22:50:01 +0000777 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000778 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000779 return true;
780 }
781 }
782 } else if (N.getOpcode() == ISD::SUB) {
783 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
784 int RHSC = (int)RHS->getZExtValue();
785 if (((RHSC & 0x3) == 0) && (RHSC >= 0 && RHSC < 0x400)) { // 8 bits.
786 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000787 OffImm = CurDAG->getTargetConstant(-RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000788 return true;
789 }
790 }
791 }
792
793 return false;
794}
795
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000796bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000797 SDValue &Base,
798 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +0000799 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
800 if (N.getOpcode() != ISD::ADD)
801 return false;
Evan Cheng055b0312009-06-29 07:51:04 +0000802
Evan Cheng3a214252009-08-11 08:52:18 +0000803 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
804 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
805 int RHSC = (int)RHS->getZExtValue();
806 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
807 return false;
808 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +0000809 return false;
810 }
811
Evan Cheng055b0312009-06-29 07:51:04 +0000812 // Look for (R + R) or (R + (R << [1,2,3])).
813 unsigned ShAmt = 0;
814 Base = N.getOperand(0);
815 OffReg = N.getOperand(1);
816
817 // Swap if it is ((R << c) + R).
818 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
819 if (ShOpcVal != ARM_AM::lsl) {
820 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
821 if (ShOpcVal == ARM_AM::lsl)
822 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +0000823 }
824
Evan Cheng055b0312009-06-29 07:51:04 +0000825 if (ShOpcVal == ARM_AM::lsl) {
826 // Check to see if the RHS of the shift is a constant, if not, we can't fold
827 // it.
828 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
829 ShAmt = Sh->getZExtValue();
830 if (ShAmt >= 4) {
831 ShAmt = 0;
832 ShOpcVal = ARM_AM::no_shift;
833 } else
834 OffReg = OffReg.getOperand(0);
835 } else {
836 ShOpcVal = ARM_AM::no_shift;
837 }
David Goodwin7ecc8502009-07-15 15:50:19 +0000838 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000839
Owen Anderson825b72b2009-08-11 20:47:22 +0000840 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000841
842 return true;
843}
844
845//===--------------------------------------------------------------------===//
846
Evan Chengee568cf2007-07-05 07:15:27 +0000847/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +0000848static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000849 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +0000850}
851
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000852SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
853 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +0000854 ISD::MemIndexedMode AM = LD->getAddressingMode();
855 if (AM == ISD::UNINDEXED)
856 return NULL;
857
Owen Andersone50ed302009-08-10 22:56:29 +0000858 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +0000859 SDValue Offset, AMOpc;
860 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
861 unsigned Opcode = 0;
862 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000863 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000864 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000865 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
866 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +0000867 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000868 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000869 Match = true;
870 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
871 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
872 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +0000873 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000874 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000875 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000876 Match = true;
877 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
878 }
879 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000880 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000881 Match = true;
882 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
883 }
884 }
885 }
886
887 if (Match) {
888 SDValue Chain = LD->getChain();
889 SDValue Base = LD->getBasePtr();
890 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000891 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000892 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000893 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +0000894 }
895
896 return NULL;
897}
898
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000899SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
900 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000901 ISD::MemIndexedMode AM = LD->getAddressingMode();
902 if (AM == ISD::UNINDEXED)
903 return NULL;
904
Owen Andersone50ed302009-08-10 22:56:29 +0000905 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +0000906 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000907 SDValue Offset;
908 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
909 unsigned Opcode = 0;
910 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000911 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000912 switch (LoadedVT.getSimpleVT().SimpleTy) {
913 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000914 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
915 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000916 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000917 if (isSExtLd)
918 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
919 else
920 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000921 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000922 case MVT::i8:
923 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000924 if (isSExtLd)
925 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
926 else
927 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000928 break;
929 default:
930 return NULL;
931 }
932 Match = true;
933 }
934
935 if (Match) {
936 SDValue Chain = LD->getChain();
937 SDValue Base = LD->getBasePtr();
938 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000939 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000940 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000941 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000942 }
943
944 return NULL;
945}
946
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000947SDNode *ARMDAGToDAGISel::SelectDYN_ALLOC(SDNode *N) {
Evan Cheng86198642009-08-07 00:34:42 +0000948 DebugLoc dl = N->getDebugLoc();
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000949 EVT VT = N->getValueType(0);
950 SDValue Chain = N->getOperand(0);
951 SDValue Size = N->getOperand(1);
952 SDValue Align = N->getOperand(2);
Owen Anderson825b72b2009-08-11 20:47:22 +0000953 SDValue SP = CurDAG->getRegister(ARM::SP, MVT::i32);
Evan Cheng86198642009-08-07 00:34:42 +0000954 int32_t AlignVal = cast<ConstantSDNode>(Align)->getSExtValue();
955 if (AlignVal < 0)
956 // We need to align the stack. Use Thumb1 tAND which is the only thumb
957 // instruction that can read and write SP. This matches to a pseudo
958 // instruction that has a chain to ensure the result is written back to
959 // the stack pointer.
Dan Gohman602b0c82009-09-25 18:54:59 +0000960 SP = SDValue(CurDAG->getMachineNode(ARM::tANDsp, dl, VT, SP, Align), 0);
Evan Cheng86198642009-08-07 00:34:42 +0000961
962 bool isC = isa<ConstantSDNode>(Size);
963 uint32_t C = isC ? cast<ConstantSDNode>(Size)->getZExtValue() : ~0UL;
964 // Handle the most common case for both Thumb1 and Thumb2:
965 // tSUBspi - immediate is between 0 ... 508 inclusive.
966 if (C <= 508 && ((C & 3) == 0))
967 // FIXME: tSUBspi encode scale 4 implicitly.
Owen Anderson825b72b2009-08-11 20:47:22 +0000968 return CurDAG->SelectNodeTo(N, ARM::tSUBspi_, VT, MVT::Other, SP,
969 CurDAG->getTargetConstant(C/4, MVT::i32),
Evan Cheng86198642009-08-07 00:34:42 +0000970 Chain);
971
972 if (Subtarget->isThumb1Only()) {
Evan Chengb89030a2009-08-11 23:00:31 +0000973 // Use tADDspr since Thumb1 does not have a sub r, sp, r. ARMISelLowering
Evan Cheng86198642009-08-07 00:34:42 +0000974 // should have negated the size operand already. FIXME: We can't insert
975 // new target independent node at this stage so we are forced to negate
Jim Grosbach764ab522009-08-11 15:33:49 +0000976 // it earlier. Is there a better solution?
Owen Anderson825b72b2009-08-11 20:47:22 +0000977 return CurDAG->SelectNodeTo(N, ARM::tADDspr_, VT, MVT::Other, SP, Size,
Evan Cheng86198642009-08-07 00:34:42 +0000978 Chain);
979 } else if (Subtarget->isThumb2()) {
980 if (isC && Predicate_t2_so_imm(Size.getNode())) {
981 // t2SUBrSPi
Owen Anderson825b72b2009-08-11 20:47:22 +0000982 SDValue Ops[] = { SP, CurDAG->getTargetConstant(C, MVT::i32), Chain };
983 return CurDAG->SelectNodeTo(N, ARM::t2SUBrSPi_, VT, MVT::Other, Ops, 3);
Evan Cheng86198642009-08-07 00:34:42 +0000984 } else if (isC && Predicate_imm0_4095(Size.getNode())) {
985 // t2SUBrSPi12
Owen Anderson825b72b2009-08-11 20:47:22 +0000986 SDValue Ops[] = { SP, CurDAG->getTargetConstant(C, MVT::i32), Chain };
987 return CurDAG->SelectNodeTo(N, ARM::t2SUBrSPi12_, VT, MVT::Other, Ops, 3);
Evan Cheng86198642009-08-07 00:34:42 +0000988 } else {
989 // t2SUBrSPs
990 SDValue Ops[] = { SP, Size,
991 getI32Imm(ARM_AM::getSORegOpc(ARM_AM::lsl,0)), Chain };
Owen Anderson825b72b2009-08-11 20:47:22 +0000992 return CurDAG->SelectNodeTo(N, ARM::t2SUBrSPs_, VT, MVT::Other, Ops, 4);
Evan Cheng86198642009-08-07 00:34:42 +0000993 }
994 }
995
996 // FIXME: Add ADD / SUB sp instructions for ARM.
997 return 0;
998}
Evan Chenga8e29892007-01-19 07:51:42 +0000999
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001000/// PairDRegs - Insert a pair of double registers into an implicit def to
1001/// form a quad register.
1002SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1003 DebugLoc dl = V0.getNode()->getDebugLoc();
1004 SDValue Undef =
Chris Lattner518bb532010-02-09 19:54:29 +00001005 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001006 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
1007 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
Chris Lattner518bb532010-02-09 19:54:29 +00001008 SDNode *Pair = CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001009 VT, Undef, V0, SubReg0);
Chris Lattner518bb532010-02-09 19:54:29 +00001010 return CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001011 VT, SDValue(Pair, 0), V1, SubReg1);
1012}
1013
Bob Wilsona7c397c2009-10-14 16:19:03 +00001014/// GetNEONSubregVT - Given a type for a 128-bit NEON vector, return the type
1015/// for a 64-bit subregister of the vector.
1016static EVT GetNEONSubregVT(EVT VT) {
1017 switch (VT.getSimpleVT().SimpleTy) {
1018 default: llvm_unreachable("unhandled NEON type");
1019 case MVT::v16i8: return MVT::v8i8;
1020 case MVT::v8i16: return MVT::v4i16;
1021 case MVT::v4f32: return MVT::v2f32;
1022 case MVT::v4i32: return MVT::v2i32;
1023 case MVT::v2i64: return MVT::v1i64;
1024 }
1025}
1026
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001027SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001028 unsigned *DOpcodes, unsigned *QOpcodes0,
1029 unsigned *QOpcodes1) {
1030 assert(NumVecs >=2 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001031 DebugLoc dl = N->getDebugLoc();
1032
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001033 SDValue MemAddr, MemUpdate, MemOpc, Align;
1034 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, MemUpdate, MemOpc, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001035 return NULL;
1036
1037 SDValue Chain = N->getOperand(0);
1038 EVT VT = N->getValueType(0);
1039 bool is64BitVector = VT.is64BitVector();
1040
1041 unsigned OpcodeIndex;
1042 switch (VT.getSimpleVT().SimpleTy) {
1043 default: llvm_unreachable("unhandled vld type");
1044 // Double-register operations:
1045 case MVT::v8i8: OpcodeIndex = 0; break;
1046 case MVT::v4i16: OpcodeIndex = 1; break;
1047 case MVT::v2f32:
1048 case MVT::v2i32: OpcodeIndex = 2; break;
1049 case MVT::v1i64: OpcodeIndex = 3; break;
1050 // Quad-register operations:
1051 case MVT::v16i8: OpcodeIndex = 0; break;
1052 case MVT::v8i16: OpcodeIndex = 1; break;
1053 case MVT::v4f32:
1054 case MVT::v4i32: OpcodeIndex = 2; break;
1055 }
1056
Evan Chengac0869d2009-11-21 06:21:52 +00001057 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
1058 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Bob Wilson3e36f132009-10-14 17:28:52 +00001059 if (is64BitVector) {
1060 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001061 const SDValue Ops[] = { MemAddr, MemUpdate, MemOpc, Align,
1062 Pred, PredReg, Chain };
Bob Wilson3e36f132009-10-14 17:28:52 +00001063 std::vector<EVT> ResTys(NumVecs, VT);
1064 ResTys.push_back(MVT::Other);
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001065 return CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 7);
Bob Wilson3e36f132009-10-14 17:28:52 +00001066 }
1067
1068 EVT RegVT = GetNEONSubregVT(VT);
1069 if (NumVecs == 2) {
1070 // Quad registers are directly supported for VLD2,
1071 // loading 2 pairs of D regs.
1072 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001073 const SDValue Ops[] = { MemAddr, MemUpdate, MemOpc, Align,
1074 Pred, PredReg, Chain };
Bob Wilson3e36f132009-10-14 17:28:52 +00001075 std::vector<EVT> ResTys(4, VT);
1076 ResTys.push_back(MVT::Other);
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001077 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 7);
Bob Wilson3e36f132009-10-14 17:28:52 +00001078 Chain = SDValue(VLd, 4);
1079
1080 // Combine the even and odd subregs to produce the result.
1081 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1082 SDNode *Q = PairDRegs(VT, SDValue(VLd, 2*Vec), SDValue(VLd, 2*Vec+1));
1083 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1084 }
1085 } else {
1086 // Otherwise, quad registers are loaded with two separate instructions,
1087 // where one loads the even registers and the other loads the odd registers.
1088
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001089 // Enable writeback to the address register.
1090 MemOpc = CurDAG->getTargetConstant(ARM_AM::getAM6Opc(true), MVT::i32);
1091
Bob Wilson3e36f132009-10-14 17:28:52 +00001092 std::vector<EVT> ResTys(NumVecs, RegVT);
1093 ResTys.push_back(MemAddr.getValueType());
1094 ResTys.push_back(MVT::Other);
1095
Bob Wilson24f995d2009-10-14 18:32:29 +00001096 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001097 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001098 const SDValue OpsA[] = { MemAddr, MemUpdate, MemOpc, Align,
1099 Pred, PredReg, Chain };
1100 SDNode *VLdA = CurDAG->getMachineNode(Opc, dl, ResTys, OpsA, 7);
Bob Wilson3e36f132009-10-14 17:28:52 +00001101 Chain = SDValue(VLdA, NumVecs+1);
1102
Bob Wilson24f995d2009-10-14 18:32:29 +00001103 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001104 Opc = QOpcodes1[OpcodeIndex];
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001105 const SDValue OpsB[] = { SDValue(VLdA, NumVecs), MemUpdate, MemOpc,
Evan Chengac0869d2009-11-21 06:21:52 +00001106 Align, Pred, PredReg, Chain };
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001107 SDNode *VLdB = CurDAG->getMachineNode(Opc, dl, ResTys, OpsB, 7);
Bob Wilson3e36f132009-10-14 17:28:52 +00001108 Chain = SDValue(VLdB, NumVecs+1);
1109
1110 // Combine the even and odd subregs to produce the result.
1111 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1112 SDNode *Q = PairDRegs(VT, SDValue(VLdA, Vec), SDValue(VLdB, Vec));
1113 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1114 }
1115 }
1116 ReplaceUses(SDValue(N, NumVecs), Chain);
1117 return NULL;
1118}
1119
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001120SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001121 unsigned *DOpcodes, unsigned *QOpcodes0,
1122 unsigned *QOpcodes1) {
1123 assert(NumVecs >=2 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001124 DebugLoc dl = N->getDebugLoc();
1125
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001126 SDValue MemAddr, MemUpdate, MemOpc, Align;
1127 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, MemUpdate, MemOpc, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001128 return NULL;
1129
1130 SDValue Chain = N->getOperand(0);
1131 EVT VT = N->getOperand(3).getValueType();
1132 bool is64BitVector = VT.is64BitVector();
1133
1134 unsigned OpcodeIndex;
1135 switch (VT.getSimpleVT().SimpleTy) {
1136 default: llvm_unreachable("unhandled vst type");
1137 // Double-register operations:
1138 case MVT::v8i8: OpcodeIndex = 0; break;
1139 case MVT::v4i16: OpcodeIndex = 1; break;
1140 case MVT::v2f32:
1141 case MVT::v2i32: OpcodeIndex = 2; break;
1142 case MVT::v1i64: OpcodeIndex = 3; break;
1143 // Quad-register operations:
1144 case MVT::v16i8: OpcodeIndex = 0; break;
1145 case MVT::v8i16: OpcodeIndex = 1; break;
1146 case MVT::v4f32:
1147 case MVT::v4i32: OpcodeIndex = 2; break;
1148 }
1149
Evan Chengac0869d2009-11-21 06:21:52 +00001150 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
1151 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1152
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001153 SmallVector<SDValue, 8> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001154 Ops.push_back(MemAddr);
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001155 Ops.push_back(MemUpdate);
1156 Ops.push_back(MemOpc);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001157 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001158
1159 if (is64BitVector) {
1160 unsigned Opc = DOpcodes[OpcodeIndex];
1161 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1162 Ops.push_back(N->getOperand(Vec+3));
Evan Chengac0869d2009-11-21 06:21:52 +00001163 Ops.push_back(Pred);
1164 Ops.push_back(PredReg);
Bob Wilson24f995d2009-10-14 18:32:29 +00001165 Ops.push_back(Chain);
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001166 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+7);
Bob Wilson24f995d2009-10-14 18:32:29 +00001167 }
1168
1169 EVT RegVT = GetNEONSubregVT(VT);
1170 if (NumVecs == 2) {
1171 // Quad registers are directly supported for VST2,
1172 // storing 2 pairs of D regs.
1173 unsigned Opc = QOpcodes0[OpcodeIndex];
1174 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1175 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1176 N->getOperand(Vec+3)));
1177 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
1178 N->getOperand(Vec+3)));
1179 }
Evan Chengac0869d2009-11-21 06:21:52 +00001180 Ops.push_back(Pred);
1181 Ops.push_back(PredReg);
Bob Wilson24f995d2009-10-14 18:32:29 +00001182 Ops.push_back(Chain);
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001183 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 11);
Bob Wilson24f995d2009-10-14 18:32:29 +00001184 }
1185
1186 // Otherwise, quad registers are stored with two separate instructions,
1187 // where one stores the even registers and the other stores the odd registers.
1188
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001189 // Enable writeback to the address register.
1190 MemOpc = CurDAG->getTargetConstant(ARM_AM::getAM6Opc(true), MVT::i32);
1191
Bob Wilson24f995d2009-10-14 18:32:29 +00001192 // Store the even subregs.
1193 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1194 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1195 N->getOperand(Vec+3)));
Evan Chengac0869d2009-11-21 06:21:52 +00001196 Ops.push_back(Pred);
1197 Ops.push_back(PredReg);
Bob Wilson24f995d2009-10-14 18:32:29 +00001198 Ops.push_back(Chain);
1199 unsigned Opc = QOpcodes0[OpcodeIndex];
1200 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001201 MVT::Other, Ops.data(), NumVecs+7);
Bob Wilson24f995d2009-10-14 18:32:29 +00001202 Chain = SDValue(VStA, 1);
1203
1204 // Store the odd subregs.
1205 Ops[0] = SDValue(VStA, 0); // MemAddr
1206 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001207 Ops[Vec+4] = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
Bob Wilson24f995d2009-10-14 18:32:29 +00001208 N->getOperand(Vec+3));
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001209 Ops[NumVecs+4] = Pred;
1210 Ops[NumVecs+5] = PredReg;
1211 Ops[NumVecs+6] = Chain;
Bob Wilson24f995d2009-10-14 18:32:29 +00001212 Opc = QOpcodes1[OpcodeIndex];
1213 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001214 MVT::Other, Ops.data(), NumVecs+7);
Bob Wilson24f995d2009-10-14 18:32:29 +00001215 Chain = SDValue(VStB, 1);
1216 ReplaceUses(SDValue(N, 0), Chain);
1217 return NULL;
1218}
1219
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001220SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001221 unsigned NumVecs, unsigned *DOpcodes,
1222 unsigned *QOpcodes0,
1223 unsigned *QOpcodes1) {
1224 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001225 DebugLoc dl = N->getDebugLoc();
1226
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001227 SDValue MemAddr, MemUpdate, MemOpc, Align;
1228 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, MemUpdate, MemOpc, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001229 return NULL;
1230
1231 SDValue Chain = N->getOperand(0);
1232 unsigned Lane =
1233 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001234 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001235 bool is64BitVector = VT.is64BitVector();
1236
Bob Wilson96493442009-10-14 16:46:45 +00001237 // Quad registers are handled by load/store of subregs. Find the subreg info.
Bob Wilsona7c397c2009-10-14 16:19:03 +00001238 unsigned NumElts = 0;
1239 int SubregIdx = 0;
1240 EVT RegVT = VT;
1241 if (!is64BitVector) {
1242 RegVT = GetNEONSubregVT(VT);
1243 NumElts = RegVT.getVectorNumElements();
1244 SubregIdx = (Lane < NumElts) ? ARM::DSUBREG_0 : ARM::DSUBREG_1;
1245 }
1246
1247 unsigned OpcodeIndex;
1248 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001249 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001250 // Double-register operations:
1251 case MVT::v8i8: OpcodeIndex = 0; break;
1252 case MVT::v4i16: OpcodeIndex = 1; break;
1253 case MVT::v2f32:
1254 case MVT::v2i32: OpcodeIndex = 2; break;
1255 // Quad-register operations:
1256 case MVT::v8i16: OpcodeIndex = 0; break;
1257 case MVT::v4f32:
1258 case MVT::v4i32: OpcodeIndex = 1; break;
1259 }
1260
Evan Chengac0869d2009-11-21 06:21:52 +00001261 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
1262 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1263
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001264 SmallVector<SDValue, 9> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001265 Ops.push_back(MemAddr);
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001266 Ops.push_back(MemUpdate);
1267 Ops.push_back(MemOpc);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001268 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001269
1270 unsigned Opc = 0;
1271 if (is64BitVector) {
1272 Opc = DOpcodes[OpcodeIndex];
1273 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1274 Ops.push_back(N->getOperand(Vec+3));
1275 } else {
1276 // Check if this is loading the even or odd subreg of a Q register.
1277 if (Lane < NumElts) {
1278 Opc = QOpcodes0[OpcodeIndex];
1279 } else {
1280 Lane -= NumElts;
1281 Opc = QOpcodes1[OpcodeIndex];
1282 }
1283 // Extract the subregs of the input vector.
1284 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1285 Ops.push_back(CurDAG->getTargetExtractSubreg(SubregIdx, dl, RegVT,
1286 N->getOperand(Vec+3)));
1287 }
1288 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001289 Ops.push_back(Pred);
1290 Ops.push_back(PredReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001291 Ops.push_back(Chain);
1292
Bob Wilson96493442009-10-14 16:46:45 +00001293 if (!IsLoad)
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001294 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+8);
Bob Wilson96493442009-10-14 16:46:45 +00001295
Bob Wilsona7c397c2009-10-14 16:19:03 +00001296 std::vector<EVT> ResTys(NumVecs, RegVT);
1297 ResTys.push_back(MVT::Other);
1298 SDNode *VLdLn =
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001299 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), NumVecs+8);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001300 // For a 64-bit vector load to D registers, nothing more needs to be done.
1301 if (is64BitVector)
1302 return VLdLn;
1303
1304 // For 128-bit vectors, take the 64-bit results of the load and insert them
1305 // as subregs into the result.
1306 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1307 SDValue QuadVec = CurDAG->getTargetInsertSubreg(SubregIdx, dl, VT,
1308 N->getOperand(Vec+3),
1309 SDValue(VLdLn, Vec));
1310 ReplaceUses(SDValue(N, Vec), QuadVec);
1311 }
1312
1313 Chain = SDValue(VLdLn, NumVecs);
1314 ReplaceUses(SDValue(N, NumVecs), Chain);
1315 return NULL;
1316}
1317
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001318SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001319 unsigned Opc) {
1320 if (!Subtarget->hasV6T2Ops())
1321 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001322
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001323 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001324 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001325 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1326 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001327 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001328 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1329 unsigned Width = 32 - Srl_imm;
1330 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001331 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001332 return NULL;
1333 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001334 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001335 CurDAG->getTargetConstant(LSB, MVT::i32),
1336 CurDAG->getTargetConstant(Width, MVT::i32),
1337 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001338 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001339 }
1340 }
1341 return NULL;
1342}
1343
Evan Cheng9ef48352009-11-20 00:54:03 +00001344SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001345SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001346 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1347 SDValue CPTmp0;
1348 SDValue CPTmp1;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001349 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001350 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1351 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1352 unsigned Opc = 0;
1353 switch (SOShOp) {
1354 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1355 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1356 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1357 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1358 default:
1359 llvm_unreachable("Unknown so_reg opcode!");
1360 break;
1361 }
1362 SDValue SOShImm =
1363 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1364 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1365 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001366 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001367 }
1368 return 0;
1369}
1370
1371SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001372SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001373 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1374 SDValue CPTmp0;
1375 SDValue CPTmp1;
1376 SDValue CPTmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001377 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001378 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1379 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001380 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001381 }
1382 return 0;
1383}
1384
1385SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001386SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001387 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1388 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1389 if (!T)
1390 return 0;
1391
1392 if (Predicate_t2_so_imm(TrueVal.getNode())) {
1393 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1394 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1395 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001396 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001397 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1398 }
1399 return 0;
1400}
1401
1402SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001403SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001404 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1405 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1406 if (!T)
1407 return 0;
1408
1409 if (Predicate_so_imm(TrueVal.getNode())) {
1410 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1411 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1412 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001413 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001414 ARM::MOVCCi, MVT::i32, Ops, 5);
1415 }
1416 return 0;
1417}
1418
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001419SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1420 EVT VT = N->getValueType(0);
1421 SDValue FalseVal = N->getOperand(0);
1422 SDValue TrueVal = N->getOperand(1);
1423 SDValue CC = N->getOperand(2);
1424 SDValue CCR = N->getOperand(3);
1425 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001426 assert(CC.getOpcode() == ISD::Constant);
1427 assert(CCR.getOpcode() == ISD::Register);
1428 ARMCC::CondCodes CCVal =
1429 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001430
1431 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1432 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1433 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1434 // Pattern complexity = 18 cost = 1 size = 0
1435 SDValue CPTmp0;
1436 SDValue CPTmp1;
1437 SDValue CPTmp2;
1438 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001439 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001440 CCVal, CCR, InFlag);
1441 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001442 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001443 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1444 if (Res)
1445 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001446 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001447 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001448 CCVal, CCR, InFlag);
1449 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001450 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001451 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1452 if (Res)
1453 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001454 }
1455
1456 // Pattern: (ARMcmov:i32 GPR:i32:$false,
1457 // (imm:i32)<<P:Predicate_so_imm>>:$true,
1458 // (imm:i32):$cc)
1459 // Emits: (MOVCCi:i32 GPR:i32:$false,
1460 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1461 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001462 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001463 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001464 CCVal, CCR, InFlag);
1465 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001466 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001467 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1468 if (Res)
1469 return Res;
1470 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001471 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001472 CCVal, CCR, InFlag);
1473 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001474 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001475 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1476 if (Res)
1477 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001478 }
1479 }
1480
1481 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1482 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1483 // Pattern complexity = 6 cost = 1 size = 0
1484 //
1485 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1486 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1487 // Pattern complexity = 6 cost = 11 size = 0
1488 //
1489 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001490 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1491 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001492 unsigned Opc = 0;
1493 switch (VT.getSimpleVT().SimpleTy) {
1494 default: assert(false && "Illegal conditional move type!");
1495 break;
1496 case MVT::i32:
1497 Opc = Subtarget->isThumb()
1498 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1499 : ARM::MOVCCr;
1500 break;
1501 case MVT::f32:
1502 Opc = ARM::VMOVScc;
1503 break;
1504 case MVT::f64:
1505 Opc = ARM::VMOVDcc;
1506 break;
1507 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001508 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001509}
1510
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001511SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001512 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001513
Dan Gohmane8be6c62008-07-17 19:10:17 +00001514 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001515 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001516
1517 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001518 default: break;
1519 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001520 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001521 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001522 if (Subtarget->hasThumb2())
1523 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1524 // be done with MOV + MOVT, at worst.
1525 UseCP = 0;
1526 else {
1527 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001528 UseCP = (Val > 255 && // MOV
1529 ~Val > 255 && // MOV + MVN
1530 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001531 } else
1532 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1533 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1534 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1535 }
1536
Evan Chenga8e29892007-01-19 07:51:42 +00001537 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001538 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001539 CurDAG->getTargetConstantPool(ConstantInt::get(
1540 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001541 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001542
1543 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001544 if (Subtarget->isThumb1Only()) {
Evan Chengac0869d2009-11-21 06:21:52 +00001545 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
Owen Anderson825b72b2009-08-11 20:47:22 +00001546 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001547 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001548 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1549 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001550 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001551 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001552 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001553 CurDAG->getRegister(0, MVT::i32),
1554 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001555 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001556 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001557 CurDAG->getEntryNode()
1558 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001559 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1560 Ops, 6);
Evan Cheng012f2d92007-01-24 08:53:17 +00001561 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001562 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001563 return NULL;
1564 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001565
Evan Chenga8e29892007-01-19 07:51:42 +00001566 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001567 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001568 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001569 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001570 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001571 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001572 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001573 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001574 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1575 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001576 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001577 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1578 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001579 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1580 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1581 CurDAG->getRegister(0, MVT::i32) };
1582 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001583 }
Evan Chenga8e29892007-01-19 07:51:42 +00001584 }
Evan Cheng86198642009-08-07 00:34:42 +00001585 case ARMISD::DYN_ALLOC:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001586 return SelectDYN_ALLOC(N);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001587 case ISD::SRL:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001588 if (SDNode *I = SelectV6T2BitfieldExtractOp(N,
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001589 Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX))
1590 return I;
1591 break;
1592 case ISD::SRA:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001593 if (SDNode *I = SelectV6T2BitfieldExtractOp(N,
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001594 Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX))
1595 return I;
1596 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001597 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001598 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001599 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001600 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001601 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001602 if (!RHSV) break;
1603 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001604 unsigned ShImm = Log2_32(RHSV-1);
1605 if (ShImm >= 32)
1606 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001607 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001608 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001609 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1610 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001611 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001612 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001613 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001614 } else {
1615 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001616 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001617 }
Evan Chenga8e29892007-01-19 07:51:42 +00001618 }
1619 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001620 unsigned ShImm = Log2_32(RHSV+1);
1621 if (ShImm >= 32)
1622 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001623 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001624 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001625 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1626 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001627 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001628 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001629 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 5);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001630 } else {
1631 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001632 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001633 }
Evan Chenga8e29892007-01-19 07:51:42 +00001634 }
1635 }
1636 break;
Evan Cheng20956592009-10-21 08:15:52 +00001637 case ISD::AND: {
1638 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1639 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1640 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1641 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1642 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001643 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001644 if (VT != MVT::i32)
1645 break;
1646 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1647 ? ARM::t2MOVTi16
1648 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1649 if (!Opc)
1650 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001651 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001652 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1653 if (!N1C)
1654 break;
1655 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1656 SDValue N2 = N0.getOperand(1);
1657 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1658 if (!N2C)
1659 break;
1660 unsigned N1CVal = N1C->getZExtValue();
1661 unsigned N2CVal = N2C->getZExtValue();
1662 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1663 (N1CVal & 0xffffU) == 0xffffU &&
1664 (N2CVal & 0xffffU) == 0x0U) {
1665 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1666 MVT::i32);
1667 SDValue Ops[] = { N0.getOperand(0), Imm16,
1668 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1669 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
1670 }
1671 }
1672 break;
1673 }
Jim Grosbache5165492009-11-09 00:11:35 +00001674 case ARMISD::VMOVRRD:
1675 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001676 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00001677 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00001678 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001679 if (Subtarget->isThumb1Only())
1680 break;
1681 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001682 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001683 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1684 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001685 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001686 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001687 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001688 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1689 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001690 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001691 }
Evan Chengee568cf2007-07-05 07:15:27 +00001692 }
Dan Gohman525178c2007-10-08 18:33:35 +00001693 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001694 if (Subtarget->isThumb1Only())
1695 break;
1696 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001697 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001698 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001699 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001700 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001701 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001702 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1703 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001704 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001705 }
Evan Chengee568cf2007-07-05 07:15:27 +00001706 }
Evan Chenga8e29892007-01-19 07:51:42 +00001707 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00001708 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001709 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001710 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001711 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001712 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001713 if (ResNode)
1714 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00001715 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001716 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001717 }
Evan Chengee568cf2007-07-05 07:15:27 +00001718 case ARMISD::BRCOND: {
1719 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1720 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1721 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001722
Evan Chengee568cf2007-07-05 07:15:27 +00001723 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1724 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
1725 // Pattern complexity = 6 cost = 1 size = 0
1726
David Goodwin5e47a9a2009-06-30 18:04:13 +00001727 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1728 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1729 // Pattern complexity = 6 cost = 1 size = 0
1730
Jim Grosbach764ab522009-08-11 15:33:49 +00001731 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00001732 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001733 SDValue Chain = N->getOperand(0);
1734 SDValue N1 = N->getOperand(1);
1735 SDValue N2 = N->getOperand(2);
1736 SDValue N3 = N->getOperand(3);
1737 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00001738 assert(N1.getOpcode() == ISD::BasicBlock);
1739 assert(N2.getOpcode() == ISD::Constant);
1740 assert(N3.getOpcode() == ISD::Register);
1741
Dan Gohman475871a2008-07-27 21:46:04 +00001742 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001743 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00001744 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00001745 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00001746 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
1747 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00001748 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001749 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00001750 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001751 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00001752 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001753 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00001754 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00001755 return NULL;
1756 }
Evan Cheng07ba9062009-11-19 21:45:22 +00001757 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001758 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00001759 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001760 EVT VT = N->getValueType(0);
1761 SDValue N0 = N->getOperand(0);
1762 SDValue N1 = N->getOperand(1);
1763 SDValue N2 = N->getOperand(2);
1764 SDValue N3 = N->getOperand(3);
1765 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00001766 assert(N2.getOpcode() == ISD::Constant);
1767 assert(N3.getOpcode() == ISD::Register);
1768
Dan Gohman475871a2008-07-27 21:46:04 +00001769 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001770 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00001771 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00001772 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00001773 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00001774 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00001775 default: assert(false && "Illegal conditional move type!");
1776 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001777 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00001778 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00001779 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001780 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00001781 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00001782 break;
Evan Chengee568cf2007-07-05 07:15:27 +00001783 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001784 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001785 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00001786
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001787 case ARMISD::VZIP: {
1788 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001789 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001790 switch (VT.getSimpleVT().SimpleTy) {
1791 default: return NULL;
1792 case MVT::v8i8: Opc = ARM::VZIPd8; break;
1793 case MVT::v4i16: Opc = ARM::VZIPd16; break;
1794 case MVT::v2f32:
1795 case MVT::v2i32: Opc = ARM::VZIPd32; break;
1796 case MVT::v16i8: Opc = ARM::VZIPq8; break;
1797 case MVT::v8i16: Opc = ARM::VZIPq16; break;
1798 case MVT::v4f32:
1799 case MVT::v4i32: Opc = ARM::VZIPq32; break;
1800 }
Evan Chengac0869d2009-11-21 06:21:52 +00001801 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
1802 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1803 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1804 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001805 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001806 case ARMISD::VUZP: {
1807 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001808 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001809 switch (VT.getSimpleVT().SimpleTy) {
1810 default: return NULL;
1811 case MVT::v8i8: Opc = ARM::VUZPd8; break;
1812 case MVT::v4i16: Opc = ARM::VUZPd16; break;
1813 case MVT::v2f32:
1814 case MVT::v2i32: Opc = ARM::VUZPd32; break;
1815 case MVT::v16i8: Opc = ARM::VUZPq8; break;
1816 case MVT::v8i16: Opc = ARM::VUZPq16; break;
1817 case MVT::v4f32:
1818 case MVT::v4i32: Opc = ARM::VUZPq32; break;
1819 }
Evan Chengac0869d2009-11-21 06:21:52 +00001820 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
1821 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1822 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1823 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001824 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001825 case ARMISD::VTRN: {
1826 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001827 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001828 switch (VT.getSimpleVT().SimpleTy) {
1829 default: return NULL;
1830 case MVT::v8i8: Opc = ARM::VTRNd8; break;
1831 case MVT::v4i16: Opc = ARM::VTRNd16; break;
1832 case MVT::v2f32:
1833 case MVT::v2i32: Opc = ARM::VTRNd32; break;
1834 case MVT::v16i8: Opc = ARM::VTRNq8; break;
1835 case MVT::v8i16: Opc = ARM::VTRNq16; break;
1836 case MVT::v4f32:
1837 case MVT::v4i32: Opc = ARM::VTRNq32; break;
1838 }
Evan Chengac0869d2009-11-21 06:21:52 +00001839 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
1840 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1841 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1842 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001843 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00001844
1845 case ISD::INTRINSIC_VOID:
1846 case ISD::INTRINSIC_W_CHAIN: {
1847 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00001848 switch (IntNo) {
1849 default:
1850 break;
1851
1852 case Intrinsic::arm_neon_vld2: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001853 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
1854 ARM::VLD2d32, ARM::VLD2d64 };
1855 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001856 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001857 }
1858
1859 case Intrinsic::arm_neon_vld3: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001860 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
1861 ARM::VLD3d32, ARM::VLD3d64 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001862 unsigned QOpcodes0[] = { ARM::VLD3q8_UPD,
1863 ARM::VLD3q16_UPD,
1864 ARM::VLD3q32_UPD };
1865 unsigned QOpcodes1[] = { ARM::VLD3q8odd_UPD,
1866 ARM::VLD3q16odd_UPD,
1867 ARM::VLD3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001868 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001869 }
1870
1871 case Intrinsic::arm_neon_vld4: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001872 unsigned DOpcodes[] = { ARM::VLD4d8, ARM::VLD4d16,
1873 ARM::VLD4d32, ARM::VLD4d64 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001874 unsigned QOpcodes0[] = { ARM::VLD4q8_UPD,
1875 ARM::VLD4q16_UPD,
1876 ARM::VLD4q32_UPD };
1877 unsigned QOpcodes1[] = { ARM::VLD4q8odd_UPD,
1878 ARM::VLD4q16odd_UPD,
1879 ARM::VLD4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001880 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001881 }
1882
Bob Wilson243fcc52009-09-01 04:26:28 +00001883 case Intrinsic::arm_neon_vld2lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00001884 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001885 unsigned QOpcodes0[] = { ARM::VLD2LNq16, ARM::VLD2LNq32 };
1886 unsigned QOpcodes1[] = { ARM::VLD2LNq16odd, ARM::VLD2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001887 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00001888 }
1889
1890 case Intrinsic::arm_neon_vld3lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00001891 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001892 unsigned QOpcodes0[] = { ARM::VLD3LNq16, ARM::VLD3LNq32 };
1893 unsigned QOpcodes1[] = { ARM::VLD3LNq16odd, ARM::VLD3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001894 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00001895 }
1896
1897 case Intrinsic::arm_neon_vld4lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00001898 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001899 unsigned QOpcodes0[] = { ARM::VLD4LNq16, ARM::VLD4LNq32 };
1900 unsigned QOpcodes1[] = { ARM::VLD4LNq16odd, ARM::VLD4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001901 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00001902 }
1903
Bob Wilson31fb12f2009-08-26 17:39:53 +00001904 case Intrinsic::arm_neon_vst2: {
Bob Wilson24f995d2009-10-14 18:32:29 +00001905 unsigned DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
1906 ARM::VST2d32, ARM::VST2d64 };
1907 unsigned QOpcodes[] = { ARM::VST2q8, ARM::VST2q16, ARM::VST2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001908 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001909 }
1910
1911 case Intrinsic::arm_neon_vst3: {
Bob Wilson24f995d2009-10-14 18:32:29 +00001912 unsigned DOpcodes[] = { ARM::VST3d8, ARM::VST3d16,
1913 ARM::VST3d32, ARM::VST3d64 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001914 unsigned QOpcodes0[] = { ARM::VST3q8_UPD,
1915 ARM::VST3q16_UPD,
1916 ARM::VST3q32_UPD };
1917 unsigned QOpcodes1[] = { ARM::VST3q8odd_UPD,
1918 ARM::VST3q16odd_UPD,
1919 ARM::VST3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001920 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001921 }
1922
1923 case Intrinsic::arm_neon_vst4: {
Bob Wilson24f995d2009-10-14 18:32:29 +00001924 unsigned DOpcodes[] = { ARM::VST4d8, ARM::VST4d16,
1925 ARM::VST4d32, ARM::VST4d64 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001926 unsigned QOpcodes0[] = { ARM::VST4q8_UPD,
1927 ARM::VST4q16_UPD,
1928 ARM::VST4q32_UPD };
1929 unsigned QOpcodes1[] = { ARM::VST4q8odd_UPD,
1930 ARM::VST4q16odd_UPD,
1931 ARM::VST4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001932 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001933 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00001934
1935 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson96493442009-10-14 16:46:45 +00001936 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001937 unsigned QOpcodes0[] = { ARM::VST2LNq16, ARM::VST2LNq32 };
1938 unsigned QOpcodes1[] = { ARM::VST2LNq16odd, ARM::VST2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001939 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00001940 }
1941
1942 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson96493442009-10-14 16:46:45 +00001943 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001944 unsigned QOpcodes0[] = { ARM::VST3LNq16, ARM::VST3LNq32 };
1945 unsigned QOpcodes1[] = { ARM::VST3LNq16odd, ARM::VST3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001946 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00001947 }
1948
1949 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson96493442009-10-14 16:46:45 +00001950 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001951 unsigned QOpcodes0[] = { ARM::VST4LNq16, ARM::VST4LNq32 };
1952 unsigned QOpcodes1[] = { ARM::VST4LNq16odd, ARM::VST4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001953 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00001954 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00001955 }
1956 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00001957 }
1958
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001959 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00001960}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001961
Bob Wilson224c2442009-05-19 05:53:42 +00001962bool ARMDAGToDAGISel::
1963SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
1964 std::vector<SDValue> &OutOps) {
1965 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00001966 // Require the address to be in a register. That is safe for all ARM
1967 // variants and it is hard to do anything much smarter without knowing
1968 // how the operand is used.
1969 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00001970 return false;
1971}
1972
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001973/// createARMISelDag - This pass converts a legalized DAG into a
1974/// ARM-specific DAG, ready for instruction scheduling.
1975///
Bob Wilson522ce972009-09-28 14:30:20 +00001976FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
1977 CodeGenOpt::Level OptLevel) {
1978 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001979}