blob: 332ca3cb2a73f4c85d16a6e28090f5b92166a7a4 [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 Wilson226036e2010-03-20 22:13:40 +000083 bool SelectAddrMode6(SDNode *Op, SDValue N, SDValue &Addr, SDValue &Align);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000084
Dan Gohmaneeb3a002010-01-05 01:24:18 +000085 bool SelectAddrModePC(SDNode *Op, SDValue N, SDValue &Offset,
Bob Wilson8b024a52009-07-01 23:16:05 +000086 SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +000087
Dan Gohmaneeb3a002010-01-05 01:24:18 +000088 bool SelectThumbAddrModeRR(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000089 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000090 bool SelectThumbAddrModeRI5(SDNode *Op, SDValue N, unsigned Scale,
Dan Gohman475871a2008-07-27 21:46:04 +000091 SDValue &Base, SDValue &OffImm,
92 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000093 bool SelectThumbAddrModeS1(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000094 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000095 bool SelectThumbAddrModeS2(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000096 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000097 bool SelectThumbAddrModeS4(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000098 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000099 bool SelectThumbAddrModeSP(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000100 SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000101
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000102 bool SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000103 SDValue &BaseReg, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000104 bool SelectT2AddrModeImm12(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000105 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000106 bool SelectT2AddrModeImm8(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000107 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000108 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000109 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000110 bool SelectT2AddrModeImm8s4(SDNode *Op, SDValue N, SDValue &Base,
David Goodwin6647cea2009-06-30 22:50:01 +0000111 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000112 bool SelectT2AddrModeSoReg(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000113 SDValue &OffReg, SDValue &ShImm);
114
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000115 // Include the pieces autogenerated from the target description.
116#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000117
118private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000119 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
120 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000121 SDNode *SelectARMIndexedLoad(SDNode *N);
122 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000123
Evan Cheng86198642009-08-07 00:34:42 +0000124 /// SelectDYN_ALLOC - Select dynamic alloc for Thumb.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000125 SDNode *SelectDYN_ALLOC(SDNode *N);
Evan Chengaf4550f2009-07-02 01:23:32 +0000126
Bob Wilson621f1952010-03-23 05:25:43 +0000127 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
128 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000129 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000130 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000131 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000132 unsigned *QOpcodes0, unsigned *QOpcodes1);
133
Bob Wilson24f995d2009-10-14 18:32:29 +0000134 /// SelectVST - Select NEON store intrinsics. NumVecs should
135 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
136 /// stores of D registers and even subregs and odd subregs of Q registers.
137 /// For NumVecs == 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000138 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000139 unsigned *QOpcodes0, unsigned *QOpcodes1);
140
Bob Wilson96493442009-10-14 16:46:45 +0000141 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000142 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson96493442009-10-14 16:46:45 +0000143 /// load/store of D registers and even subregs and odd subregs of Q registers.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000144 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
Bob Wilson96493442009-10-14 16:46:45 +0000145 unsigned *DOpcodes, unsigned *QOpcodes0,
146 unsigned *QOpcodes1);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000147
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000148 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000149 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, unsigned Opc);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000150
Evan Cheng07ba9062009-11-19 21:45:22 +0000151 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000152 SDNode *SelectCMOVOp(SDNode *N);
153 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000154 ARMCC::CondCodes CCVal, SDValue CCR,
155 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000156 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000157 ARMCC::CondCodes CCVal, SDValue CCR,
158 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000159 SDNode *SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000160 ARMCC::CondCodes CCVal, SDValue CCR,
161 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000162 SDNode *SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000163 ARMCC::CondCodes CCVal, SDValue CCR,
164 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000165
Evan Chengaf4550f2009-07-02 01:23:32 +0000166 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
167 /// inline asm expressions.
168 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
169 char ConstraintCode,
170 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000171
172 /// PairDRegs - Insert a pair of double registers into an implicit def to
173 /// form a quad register.
174 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000175};
Evan Chenga8e29892007-01-19 07:51:42 +0000176}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000177
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000178/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
179/// operand. If so Imm will receive the 32-bit value.
180static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
181 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
182 Imm = cast<ConstantSDNode>(N)->getZExtValue();
183 return true;
184 }
185 return false;
186}
187
188// isInt32Immediate - This method tests to see if a constant operand.
189// If so Imm will receive the 32 bit value.
190static bool isInt32Immediate(SDValue N, unsigned &Imm) {
191 return isInt32Immediate(N.getNode(), Imm);
192}
193
194// isOpcWithIntImmediate - This method tests to see if the node is a specific
195// opcode and that it has a immediate integer right operand.
196// If so Imm will receive the 32 bit value.
197static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
198 return N->getOpcode() == Opc &&
199 isInt32Immediate(N->getOperand(1).getNode(), Imm);
200}
201
202
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000203bool ARMDAGToDAGISel::SelectShifterOperandReg(SDNode *Op,
Evan Cheng055b0312009-06-29 07:51:04 +0000204 SDValue N,
205 SDValue &BaseReg,
206 SDValue &ShReg,
207 SDValue &Opc) {
208 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
209
210 // Don't match base register only case. That is matched to a separate
211 // lower complexity pattern with explicit register operand.
212 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000213
Evan Cheng055b0312009-06-29 07:51:04 +0000214 BaseReg = N.getOperand(0);
215 unsigned ShImmVal = 0;
216 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000217 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000218 ShImmVal = RHS->getZExtValue() & 31;
219 } else {
220 ShReg = N.getOperand(1);
221 }
222 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000223 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000224 return true;
225}
226
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000227bool ARMDAGToDAGISel::SelectAddrMode2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000228 SDValue &Base, SDValue &Offset,
229 SDValue &Opc) {
Evan Chenga13fd102007-03-13 21:05:54 +0000230 if (N.getOpcode() == ISD::MUL) {
231 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
232 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000233 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000234 if (RHSC & 1) {
235 RHSC = RHSC & ~1;
236 ARM_AM::AddrOpc AddSub = ARM_AM::add;
237 if (RHSC < 0) {
238 AddSub = ARM_AM::sub;
239 RHSC = - RHSC;
240 }
241 if (isPowerOf2_32(RHSC)) {
242 unsigned ShAmt = Log2_32(RHSC);
243 Base = Offset = N.getOperand(0);
244 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
245 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000246 MVT::i32);
Evan Chenga13fd102007-03-13 21:05:54 +0000247 return true;
248 }
249 }
250 }
251 }
252
Evan Chenga8e29892007-01-19 07:51:42 +0000253 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
254 Base = N;
255 if (N.getOpcode() == ISD::FrameIndex) {
256 int FI = cast<FrameIndexSDNode>(N)->getIndex();
257 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000258 } else if (N.getOpcode() == ARMISD::Wrapper &&
259 !(Subtarget->useMovt() &&
260 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000261 Base = N.getOperand(0);
262 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000263 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000264 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
265 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000266 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000267 return true;
268 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000269
Evan Chenga8e29892007-01-19 07:51:42 +0000270 // Match simple R +/- imm12 operands.
271 if (N.getOpcode() == ISD::ADD)
272 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000273 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000274 if ((RHSC >= 0 && RHSC < 0x1000) ||
275 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000276 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000277 if (Base.getOpcode() == ISD::FrameIndex) {
278 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
279 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
280 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000281 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000282
283 ARM_AM::AddrOpc AddSub = ARM_AM::add;
284 if (RHSC < 0) {
285 AddSub = ARM_AM::sub;
286 RHSC = - RHSC;
287 }
288 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000289 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000290 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000291 return true;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000292 }
Evan Chenga8e29892007-01-19 07:51:42 +0000293 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000294
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000295 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000296 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
297 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
298 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000299
Evan Chenga8e29892007-01-19 07:51:42 +0000300 Base = N.getOperand(0);
301 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000302
Evan Chenga8e29892007-01-19 07:51:42 +0000303 if (ShOpcVal != ARM_AM::no_shift) {
304 // Check to see if the RHS of the shift is a constant, if not, we can't fold
305 // it.
306 if (ConstantSDNode *Sh =
307 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000308 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000309 Offset = N.getOperand(1).getOperand(0);
310 } else {
311 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000312 }
313 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000314
Evan Chenga8e29892007-01-19 07:51:42 +0000315 // Try matching (R shl C) + (R).
316 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
317 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
318 if (ShOpcVal != ARM_AM::no_shift) {
319 // Check to see if the RHS of the shift is a constant, if not, we can't
320 // fold it.
321 if (ConstantSDNode *Sh =
322 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000323 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000324 Offset = N.getOperand(0).getOperand(0);
325 Base = N.getOperand(1);
326 } else {
327 ShOpcVal = ARM_AM::no_shift;
328 }
329 }
330 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000331
Evan Chenga8e29892007-01-19 07:51:42 +0000332 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000333 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000334 return true;
335}
336
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000337bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000338 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000339 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000340 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
341 ? cast<LoadSDNode>(Op)->getAddressingMode()
342 : cast<StoreSDNode>(Op)->getAddressingMode();
343 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
344 ? ARM_AM::add : ARM_AM::sub;
345 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000346 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000347 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000348 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000349 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
350 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000351 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000352 return true;
353 }
354 }
355
356 Offset = N;
357 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
358 unsigned ShAmt = 0;
359 if (ShOpcVal != ARM_AM::no_shift) {
360 // Check to see if the RHS of the shift is a constant, if not, we can't fold
361 // it.
362 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000363 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000364 Offset = N.getOperand(0);
365 } else {
366 ShOpcVal = ARM_AM::no_shift;
367 }
368 }
369
370 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000371 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000372 return true;
373}
374
Evan Chenga8e29892007-01-19 07:51:42 +0000375
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000376bool ARMDAGToDAGISel::SelectAddrMode3(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000377 SDValue &Base, SDValue &Offset,
378 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000379 if (N.getOpcode() == ISD::SUB) {
380 // X - C is canonicalize to X + -C, no need to handle it here.
381 Base = N.getOperand(0);
382 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000383 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000384 return true;
385 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000386
Evan Chenga8e29892007-01-19 07:51:42 +0000387 if (N.getOpcode() != ISD::ADD) {
388 Base = N;
389 if (N.getOpcode() == ISD::FrameIndex) {
390 int FI = cast<FrameIndexSDNode>(N)->getIndex();
391 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
392 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000393 Offset = CurDAG->getRegister(0, MVT::i32);
394 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000395 return true;
396 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000397
Evan Chenga8e29892007-01-19 07:51:42 +0000398 // If the RHS is +/- imm8, fold into addr mode.
399 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000400 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000401 if ((RHSC >= 0 && RHSC < 256) ||
402 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000403 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000404 if (Base.getOpcode() == ISD::FrameIndex) {
405 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
406 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
407 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000408 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000409
410 ARM_AM::AddrOpc AddSub = ARM_AM::add;
411 if (RHSC < 0) {
412 AddSub = ARM_AM::sub;
413 RHSC = - RHSC;
414 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000415 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000416 return true;
417 }
418 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000419
Evan Chenga8e29892007-01-19 07:51:42 +0000420 Base = N.getOperand(0);
421 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000422 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000423 return true;
424}
425
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000426bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000427 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000428 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000429 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
430 ? cast<LoadSDNode>(Op)->getAddressingMode()
431 : cast<StoreSDNode>(Op)->getAddressingMode();
432 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
433 ? ARM_AM::add : ARM_AM::sub;
434 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000435 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000436 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000437 Offset = CurDAG->getRegister(0, MVT::i32);
438 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000439 return true;
440 }
441 }
442
443 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000444 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000445 return true;
446}
447
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000448bool ARMDAGToDAGISel::SelectAddrMode4(SDNode *Op, SDValue N,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000449 SDValue &Addr, SDValue &Mode) {
450 Addr = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000451 Mode = CurDAG->getTargetConstant(0, MVT::i32);
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000452 return true;
453}
Evan Chenga8e29892007-01-19 07:51:42 +0000454
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000455bool ARMDAGToDAGISel::SelectAddrMode5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000456 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000457 if (N.getOpcode() != ISD::ADD) {
458 Base = N;
459 if (N.getOpcode() == ISD::FrameIndex) {
460 int FI = cast<FrameIndexSDNode>(N)->getIndex();
461 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000462 } else if (N.getOpcode() == ARMISD::Wrapper &&
463 !(Subtarget->useMovt() &&
464 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000465 Base = N.getOperand(0);
466 }
467 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000468 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000469 return true;
470 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000471
Evan Chenga8e29892007-01-19 07:51:42 +0000472 // If the RHS is +/- imm8, fold into addr mode.
473 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000474 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000475 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
476 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000477 if ((RHSC >= 0 && RHSC < 256) ||
478 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000479 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000480 if (Base.getOpcode() == ISD::FrameIndex) {
481 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
482 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
483 }
484
485 ARM_AM::AddrOpc AddSub = ARM_AM::add;
486 if (RHSC < 0) {
487 AddSub = ARM_AM::sub;
488 RHSC = - RHSC;
489 }
490 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000491 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000492 return true;
493 }
494 }
495 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000496
Evan Chenga8e29892007-01-19 07:51:42 +0000497 Base = N;
498 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000499 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000500 return true;
501}
502
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000503bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Op, SDValue N,
Bob Wilson226036e2010-03-20 22:13:40 +0000504 SDValue &Addr, SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000505 Addr = N;
Jim Grosbach8a5ec862009-11-07 21:25:39 +0000506 // Default to no alignment.
507 Align = CurDAG->getTargetConstant(0, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000508 return true;
509}
510
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000511bool ARMDAGToDAGISel::SelectAddrModePC(SDNode *Op, SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000512 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000513 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
514 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000515 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000516 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000517 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000518 return true;
519 }
520 return false;
521}
522
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000523bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000524 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000525 // FIXME dl should come from the parent load or store, not the address
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000526 DebugLoc dl = Op->getDebugLoc();
Evan Chengc38f2bc2007-01-23 22:59:13 +0000527 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000528 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
529 if (!NC || NC->getZExtValue() != 0)
530 return false;
531
532 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000533 return true;
534 }
535
Evan Chenga8e29892007-01-19 07:51:42 +0000536 Base = N.getOperand(0);
537 Offset = N.getOperand(1);
538 return true;
539}
540
Evan Cheng79d43262007-01-24 02:21:22 +0000541bool
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000542ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000543 unsigned Scale, SDValue &Base,
544 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000545 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000546 SDValue TmpBase, TmpOffImm;
Evan Cheng79d43262007-01-24 02:21:22 +0000547 if (SelectThumbAddrModeSP(Op, N, TmpBase, TmpOffImm))
548 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000549 if (N.getOpcode() == ARMISD::Wrapper &&
550 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
551 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000552 }
553
Evan Chenga8e29892007-01-19 07:51:42 +0000554 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000555 if (N.getOpcode() == ARMISD::Wrapper &&
556 !(Subtarget->useMovt() &&
557 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
558 Base = N.getOperand(0);
559 } else
560 Base = N;
561
Owen Anderson825b72b2009-08-11 20:47:22 +0000562 Offset = CurDAG->getRegister(0, MVT::i32);
563 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000564 return true;
565 }
566
Evan Chengad0e4652007-02-06 00:22:06 +0000567 // Thumb does not have [sp, r] address mode.
568 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
569 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
570 if ((LHSR && LHSR->getReg() == ARM::SP) ||
571 (RHSR && RHSR->getReg() == ARM::SP)) {
572 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000573 Offset = CurDAG->getRegister(0, MVT::i32);
574 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000575 return true;
576 }
577
Evan Chenga8e29892007-01-19 07:51:42 +0000578 // If the RHS is + imm5 * scale, fold into addr mode.
579 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000580 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000581 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
582 RHSC /= Scale;
583 if (RHSC >= 0 && RHSC < 32) {
584 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000585 Offset = CurDAG->getRegister(0, MVT::i32);
586 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000587 return true;
588 }
589 }
590 }
591
Evan Chengc38f2bc2007-01-23 22:59:13 +0000592 Base = N.getOperand(0);
593 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000594 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000595 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000596}
597
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000598bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000599 SDValue &Base, SDValue &OffImm,
600 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000601 return SelectThumbAddrModeRI5(Op, N, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000602}
603
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000604bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000605 SDValue &Base, SDValue &OffImm,
606 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000607 return SelectThumbAddrModeRI5(Op, N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000608}
609
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000610bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000611 SDValue &Base, SDValue &OffImm,
612 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000613 return SelectThumbAddrModeRI5(Op, N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000614}
615
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000616bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000617 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000618 if (N.getOpcode() == ISD::FrameIndex) {
619 int FI = cast<FrameIndexSDNode>(N)->getIndex();
620 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000621 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000622 return true;
623 }
Evan Cheng79d43262007-01-24 02:21:22 +0000624
Evan Chengad0e4652007-02-06 00:22:06 +0000625 if (N.getOpcode() != ISD::ADD)
626 return false;
627
628 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000629 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
630 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000631 // If the RHS is + imm8 * scale, fold into addr mode.
632 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000633 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000634 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
635 RHSC >>= 2;
636 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000637 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000638 if (Base.getOpcode() == ISD::FrameIndex) {
639 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
640 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
641 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000642 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000643 return true;
644 }
645 }
646 }
647 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000648
Evan Chenga8e29892007-01-19 07:51:42 +0000649 return false;
650}
651
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000652bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000653 SDValue &BaseReg,
654 SDValue &Opc) {
655 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
656
657 // Don't match base register only case. That is matched to a separate
658 // lower complexity pattern with explicit register operand.
659 if (ShOpcVal == ARM_AM::no_shift) return false;
660
661 BaseReg = N.getOperand(0);
662 unsigned ShImmVal = 0;
663 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
664 ShImmVal = RHS->getZExtValue() & 31;
665 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
666 return true;
667 }
668
669 return false;
670}
671
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000672bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000673 SDValue &Base, SDValue &OffImm) {
674 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000675
Evan Cheng3a214252009-08-11 08:52:18 +0000676 // Base only.
677 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000678 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000679 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000680 int FI = cast<FrameIndexSDNode>(N)->getIndex();
681 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000682 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000683 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000684 } else if (N.getOpcode() == ARMISD::Wrapper &&
685 !(Subtarget->useMovt() &&
686 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000687 Base = N.getOperand(0);
688 if (Base.getOpcode() == ISD::TargetConstantPool)
689 return false; // We want to select t2LDRpci instead.
690 } else
691 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000692 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000693 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000694 }
Evan Cheng055b0312009-06-29 07:51:04 +0000695
696 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Evan Cheng3a214252009-08-11 08:52:18 +0000697 if (SelectT2AddrModeImm8(Op, N, Base, OffImm))
698 // Let t2LDRi8 handle (R - imm8).
699 return false;
700
Evan Cheng055b0312009-06-29 07:51:04 +0000701 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000702 if (N.getOpcode() == ISD::SUB)
703 RHSC = -RHSC;
704
705 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +0000706 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +0000707 if (Base.getOpcode() == ISD::FrameIndex) {
708 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
709 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
710 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000711 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000712 return true;
713 }
714 }
715
Evan Cheng3a214252009-08-11 08:52:18 +0000716 // Base only.
717 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000718 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000719 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000720}
721
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000722bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000723 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +0000724 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +0000725 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +0000726 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
727 int RHSC = (int)RHS->getSExtValue();
728 if (N.getOpcode() == ISD::SUB)
729 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +0000730
Evan Cheng3a214252009-08-11 08:52:18 +0000731 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
732 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +0000733 if (Base.getOpcode() == ISD::FrameIndex) {
734 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
735 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
736 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000737 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +0000738 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000739 }
Evan Cheng055b0312009-06-29 07:51:04 +0000740 }
741 }
742
743 return false;
744}
745
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000746bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000747 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000748 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +0000749 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
750 ? cast<LoadSDNode>(Op)->getAddressingMode()
751 : cast<StoreSDNode>(Op)->getAddressingMode();
752 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
753 int RHSC = (int)RHS->getZExtValue();
754 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +0000755 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +0000756 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
757 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000758 return true;
759 }
760 }
761
762 return false;
763}
764
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000765bool ARMDAGToDAGISel::SelectT2AddrModeImm8s4(SDNode *Op, SDValue N,
David Goodwin6647cea2009-06-30 22:50:01 +0000766 SDValue &Base, SDValue &OffImm) {
767 if (N.getOpcode() == ISD::ADD) {
768 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
769 int RHSC = (int)RHS->getZExtValue();
Evan Cheng5c874172009-07-09 22:21:59 +0000770 if (((RHSC & 0x3) == 0) &&
771 ((RHSC >= 0 && RHSC < 0x400) || (RHSC < 0 && RHSC > -0x400))) { // 8 bits.
David Goodwin6647cea2009-06-30 22:50:01 +0000772 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000773 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000774 return true;
775 }
776 }
777 } else if (N.getOpcode() == ISD::SUB) {
778 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
779 int RHSC = (int)RHS->getZExtValue();
780 if (((RHSC & 0x3) == 0) && (RHSC >= 0 && RHSC < 0x400)) { // 8 bits.
781 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000782 OffImm = CurDAG->getTargetConstant(-RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000783 return true;
784 }
785 }
786 }
787
788 return false;
789}
790
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000791bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000792 SDValue &Base,
793 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +0000794 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
795 if (N.getOpcode() != ISD::ADD)
796 return false;
Evan Cheng055b0312009-06-29 07:51:04 +0000797
Evan Cheng3a214252009-08-11 08:52:18 +0000798 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
799 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
800 int RHSC = (int)RHS->getZExtValue();
801 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
802 return false;
803 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +0000804 return false;
805 }
806
Evan Cheng055b0312009-06-29 07:51:04 +0000807 // Look for (R + R) or (R + (R << [1,2,3])).
808 unsigned ShAmt = 0;
809 Base = N.getOperand(0);
810 OffReg = N.getOperand(1);
811
812 // Swap if it is ((R << c) + R).
813 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
814 if (ShOpcVal != ARM_AM::lsl) {
815 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
816 if (ShOpcVal == ARM_AM::lsl)
817 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +0000818 }
819
Evan Cheng055b0312009-06-29 07:51:04 +0000820 if (ShOpcVal == ARM_AM::lsl) {
821 // Check to see if the RHS of the shift is a constant, if not, we can't fold
822 // it.
823 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
824 ShAmt = Sh->getZExtValue();
825 if (ShAmt >= 4) {
826 ShAmt = 0;
827 ShOpcVal = ARM_AM::no_shift;
828 } else
829 OffReg = OffReg.getOperand(0);
830 } else {
831 ShOpcVal = ARM_AM::no_shift;
832 }
David Goodwin7ecc8502009-07-15 15:50:19 +0000833 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000834
Owen Anderson825b72b2009-08-11 20:47:22 +0000835 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000836
837 return true;
838}
839
840//===--------------------------------------------------------------------===//
841
Evan Chengee568cf2007-07-05 07:15:27 +0000842/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +0000843static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000844 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +0000845}
846
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000847SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
848 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +0000849 ISD::MemIndexedMode AM = LD->getAddressingMode();
850 if (AM == ISD::UNINDEXED)
851 return NULL;
852
Owen Andersone50ed302009-08-10 22:56:29 +0000853 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +0000854 SDValue Offset, AMOpc;
855 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
856 unsigned Opcode = 0;
857 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000858 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000859 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000860 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
861 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +0000862 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000863 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000864 Match = true;
865 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
866 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
867 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +0000868 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000869 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000870 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000871 Match = true;
872 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
873 }
874 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000875 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000876 Match = true;
877 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
878 }
879 }
880 }
881
882 if (Match) {
883 SDValue Chain = LD->getChain();
884 SDValue Base = LD->getBasePtr();
885 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000886 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000887 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000888 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +0000889 }
890
891 return NULL;
892}
893
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000894SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
895 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000896 ISD::MemIndexedMode AM = LD->getAddressingMode();
897 if (AM == ISD::UNINDEXED)
898 return NULL;
899
Owen Andersone50ed302009-08-10 22:56:29 +0000900 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +0000901 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000902 SDValue Offset;
903 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
904 unsigned Opcode = 0;
905 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000906 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000907 switch (LoadedVT.getSimpleVT().SimpleTy) {
908 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000909 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
910 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000911 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000912 if (isSExtLd)
913 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
914 else
915 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000916 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000917 case MVT::i8:
918 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000919 if (isSExtLd)
920 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
921 else
922 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000923 break;
924 default:
925 return NULL;
926 }
927 Match = true;
928 }
929
930 if (Match) {
931 SDValue Chain = LD->getChain();
932 SDValue Base = LD->getBasePtr();
933 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000934 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000935 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000936 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000937 }
938
939 return NULL;
940}
941
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000942SDNode *ARMDAGToDAGISel::SelectDYN_ALLOC(SDNode *N) {
Evan Cheng86198642009-08-07 00:34:42 +0000943 DebugLoc dl = N->getDebugLoc();
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000944 EVT VT = N->getValueType(0);
945 SDValue Chain = N->getOperand(0);
946 SDValue Size = N->getOperand(1);
947 SDValue Align = N->getOperand(2);
Owen Anderson825b72b2009-08-11 20:47:22 +0000948 SDValue SP = CurDAG->getRegister(ARM::SP, MVT::i32);
Evan Cheng86198642009-08-07 00:34:42 +0000949 int32_t AlignVal = cast<ConstantSDNode>(Align)->getSExtValue();
950 if (AlignVal < 0)
951 // We need to align the stack. Use Thumb1 tAND which is the only thumb
952 // instruction that can read and write SP. This matches to a pseudo
953 // instruction that has a chain to ensure the result is written back to
954 // the stack pointer.
Dan Gohman602b0c82009-09-25 18:54:59 +0000955 SP = SDValue(CurDAG->getMachineNode(ARM::tANDsp, dl, VT, SP, Align), 0);
Evan Cheng86198642009-08-07 00:34:42 +0000956
957 bool isC = isa<ConstantSDNode>(Size);
958 uint32_t C = isC ? cast<ConstantSDNode>(Size)->getZExtValue() : ~0UL;
959 // Handle the most common case for both Thumb1 and Thumb2:
960 // tSUBspi - immediate is between 0 ... 508 inclusive.
961 if (C <= 508 && ((C & 3) == 0))
962 // FIXME: tSUBspi encode scale 4 implicitly.
Owen Anderson825b72b2009-08-11 20:47:22 +0000963 return CurDAG->SelectNodeTo(N, ARM::tSUBspi_, VT, MVT::Other, SP,
964 CurDAG->getTargetConstant(C/4, MVT::i32),
Evan Cheng86198642009-08-07 00:34:42 +0000965 Chain);
966
967 if (Subtarget->isThumb1Only()) {
Evan Chengb89030a2009-08-11 23:00:31 +0000968 // Use tADDspr since Thumb1 does not have a sub r, sp, r. ARMISelLowering
Evan Cheng86198642009-08-07 00:34:42 +0000969 // should have negated the size operand already. FIXME: We can't insert
970 // new target independent node at this stage so we are forced to negate
Jim Grosbach764ab522009-08-11 15:33:49 +0000971 // it earlier. Is there a better solution?
Owen Anderson825b72b2009-08-11 20:47:22 +0000972 return CurDAG->SelectNodeTo(N, ARM::tADDspr_, VT, MVT::Other, SP, Size,
Evan Cheng86198642009-08-07 00:34:42 +0000973 Chain);
974 } else if (Subtarget->isThumb2()) {
975 if (isC && Predicate_t2_so_imm(Size.getNode())) {
976 // t2SUBrSPi
Owen Anderson825b72b2009-08-11 20:47:22 +0000977 SDValue Ops[] = { SP, CurDAG->getTargetConstant(C, MVT::i32), Chain };
978 return CurDAG->SelectNodeTo(N, ARM::t2SUBrSPi_, VT, MVT::Other, Ops, 3);
Evan Cheng86198642009-08-07 00:34:42 +0000979 } else if (isC && Predicate_imm0_4095(Size.getNode())) {
980 // t2SUBrSPi12
Owen Anderson825b72b2009-08-11 20:47:22 +0000981 SDValue Ops[] = { SP, CurDAG->getTargetConstant(C, MVT::i32), Chain };
982 return CurDAG->SelectNodeTo(N, ARM::t2SUBrSPi12_, VT, MVT::Other, Ops, 3);
Evan Cheng86198642009-08-07 00:34:42 +0000983 } else {
984 // t2SUBrSPs
985 SDValue Ops[] = { SP, Size,
986 getI32Imm(ARM_AM::getSORegOpc(ARM_AM::lsl,0)), Chain };
Owen Anderson825b72b2009-08-11 20:47:22 +0000987 return CurDAG->SelectNodeTo(N, ARM::t2SUBrSPs_, VT, MVT::Other, Ops, 4);
Evan Cheng86198642009-08-07 00:34:42 +0000988 }
989 }
990
991 // FIXME: Add ADD / SUB sp instructions for ARM.
992 return 0;
993}
Evan Chenga8e29892007-01-19 07:51:42 +0000994
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000995/// PairDRegs - Insert a pair of double registers into an implicit def to
996/// form a quad register.
997SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
998 DebugLoc dl = V0.getNode()->getDebugLoc();
999 SDValue Undef =
Chris Lattner518bb532010-02-09 19:54:29 +00001000 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001001 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
1002 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
Chris Lattner518bb532010-02-09 19:54:29 +00001003 SDNode *Pair = CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001004 VT, Undef, V0, SubReg0);
Chris Lattner518bb532010-02-09 19:54:29 +00001005 return CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001006 VT, SDValue(Pair, 0), V1, SubReg1);
1007}
1008
Bob Wilsona7c397c2009-10-14 16:19:03 +00001009/// GetNEONSubregVT - Given a type for a 128-bit NEON vector, return the type
1010/// for a 64-bit subregister of the vector.
1011static EVT GetNEONSubregVT(EVT VT) {
1012 switch (VT.getSimpleVT().SimpleTy) {
1013 default: llvm_unreachable("unhandled NEON type");
1014 case MVT::v16i8: return MVT::v8i8;
1015 case MVT::v8i16: return MVT::v4i16;
1016 case MVT::v4f32: return MVT::v2f32;
1017 case MVT::v4i32: return MVT::v2i32;
1018 case MVT::v2i64: return MVT::v1i64;
1019 }
1020}
1021
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001022SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001023 unsigned *DOpcodes, unsigned *QOpcodes0,
1024 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001025 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001026 DebugLoc dl = N->getDebugLoc();
1027
Bob Wilson226036e2010-03-20 22:13:40 +00001028 SDValue MemAddr, Align;
1029 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001030 return NULL;
1031
1032 SDValue Chain = N->getOperand(0);
1033 EVT VT = N->getValueType(0);
1034 bool is64BitVector = VT.is64BitVector();
1035
1036 unsigned OpcodeIndex;
1037 switch (VT.getSimpleVT().SimpleTy) {
1038 default: llvm_unreachable("unhandled vld type");
1039 // Double-register operations:
1040 case MVT::v8i8: OpcodeIndex = 0; break;
1041 case MVT::v4i16: OpcodeIndex = 1; break;
1042 case MVT::v2f32:
1043 case MVT::v2i32: OpcodeIndex = 2; break;
1044 case MVT::v1i64: OpcodeIndex = 3; break;
1045 // Quad-register operations:
1046 case MVT::v16i8: OpcodeIndex = 0; break;
1047 case MVT::v8i16: OpcodeIndex = 1; break;
1048 case MVT::v4f32:
1049 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001050 case MVT::v2i64: OpcodeIndex = 3;
1051 assert(NumVecs == 1 && "v2i64 type only supported for VLD1/VST1");
1052 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001053 }
1054
Evan Chengac0869d2009-11-21 06:21:52 +00001055 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
Bob Wilson226036e2010-03-20 22:13:40 +00001056 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson3e36f132009-10-14 17:28:52 +00001057 if (is64BitVector) {
1058 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001059 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson3e36f132009-10-14 17:28:52 +00001060 std::vector<EVT> ResTys(NumVecs, VT);
1061 ResTys.push_back(MVT::Other);
Bob Wilson226036e2010-03-20 22:13:40 +00001062 return CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson3e36f132009-10-14 17:28:52 +00001063 }
1064
1065 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson621f1952010-03-23 05:25:43 +00001066 if (NumVecs <= 2) {
1067 // Quad registers are directly supported for VLD1 and VLD2,
1068 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001069 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001070 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson621f1952010-03-23 05:25:43 +00001071 std::vector<EVT> ResTys(2 * NumVecs, RegVT);
Bob Wilson3e36f132009-10-14 17:28:52 +00001072 ResTys.push_back(MVT::Other);
Bob Wilson226036e2010-03-20 22:13:40 +00001073 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson621f1952010-03-23 05:25:43 +00001074 Chain = SDValue(VLd, 2 * NumVecs);
Bob Wilson3e36f132009-10-14 17:28:52 +00001075
1076 // Combine the even and odd subregs to produce the result.
1077 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1078 SDNode *Q = PairDRegs(VT, SDValue(VLd, 2*Vec), SDValue(VLd, 2*Vec+1));
1079 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1080 }
1081 } else {
1082 // Otherwise, quad registers are loaded with two separate instructions,
1083 // where one loads the even registers and the other loads the odd registers.
1084
Bob Wilson3e36f132009-10-14 17:28:52 +00001085 std::vector<EVT> ResTys(NumVecs, RegVT);
1086 ResTys.push_back(MemAddr.getValueType());
1087 ResTys.push_back(MVT::Other);
1088
Bob Wilson24f995d2009-10-14 18:32:29 +00001089 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001090 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001091 const SDValue OpsA[] = { MemAddr, Align, Reg0, Pred, Reg0, Chain };
1092 SDNode *VLdA = CurDAG->getMachineNode(Opc, dl, ResTys, OpsA, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001093 Chain = SDValue(VLdA, NumVecs+1);
1094
Bob Wilson24f995d2009-10-14 18:32:29 +00001095 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001096 Opc = QOpcodes1[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001097 const SDValue OpsB[] = { SDValue(VLdA, NumVecs),
1098 Align, Reg0, Pred, Reg0, Chain };
1099 SDNode *VLdB = CurDAG->getMachineNode(Opc, dl, ResTys, OpsB, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001100 Chain = SDValue(VLdB, NumVecs+1);
1101
1102 // Combine the even and odd subregs to produce the result.
1103 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1104 SDNode *Q = PairDRegs(VT, SDValue(VLdA, Vec), SDValue(VLdB, Vec));
1105 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1106 }
1107 }
1108 ReplaceUses(SDValue(N, NumVecs), Chain);
1109 return NULL;
1110}
1111
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001112SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001113 unsigned *DOpcodes, unsigned *QOpcodes0,
1114 unsigned *QOpcodes1) {
1115 assert(NumVecs >=2 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001116 DebugLoc dl = N->getDebugLoc();
1117
Bob Wilson226036e2010-03-20 22:13:40 +00001118 SDValue MemAddr, Align;
1119 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001120 return NULL;
1121
1122 SDValue Chain = N->getOperand(0);
1123 EVT VT = N->getOperand(3).getValueType();
1124 bool is64BitVector = VT.is64BitVector();
1125
1126 unsigned OpcodeIndex;
1127 switch (VT.getSimpleVT().SimpleTy) {
1128 default: llvm_unreachable("unhandled vst type");
1129 // Double-register operations:
1130 case MVT::v8i8: OpcodeIndex = 0; break;
1131 case MVT::v4i16: OpcodeIndex = 1; break;
1132 case MVT::v2f32:
1133 case MVT::v2i32: OpcodeIndex = 2; break;
1134 case MVT::v1i64: OpcodeIndex = 3; break;
1135 // Quad-register operations:
1136 case MVT::v16i8: OpcodeIndex = 0; break;
1137 case MVT::v8i16: OpcodeIndex = 1; break;
1138 case MVT::v4f32:
1139 case MVT::v4i32: OpcodeIndex = 2; break;
1140 }
1141
Evan Chengac0869d2009-11-21 06:21:52 +00001142 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
Bob Wilson226036e2010-03-20 22:13:40 +00001143 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001144
Bob Wilson226036e2010-03-20 22:13:40 +00001145 SmallVector<SDValue, 10> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001146 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001147 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001148
1149 if (is64BitVector) {
1150 unsigned Opc = DOpcodes[OpcodeIndex];
1151 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1152 Ops.push_back(N->getOperand(Vec+3));
Evan Chengac0869d2009-11-21 06:21:52 +00001153 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001154 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001155 Ops.push_back(Chain);
Bob Wilson226036e2010-03-20 22:13:40 +00001156 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+5);
Bob Wilson24f995d2009-10-14 18:32:29 +00001157 }
1158
1159 EVT RegVT = GetNEONSubregVT(VT);
1160 if (NumVecs == 2) {
1161 // Quad registers are directly supported for VST2,
1162 // storing 2 pairs of D regs.
1163 unsigned Opc = QOpcodes0[OpcodeIndex];
1164 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1165 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1166 N->getOperand(Vec+3)));
1167 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
1168 N->getOperand(Vec+3)));
1169 }
Evan Chengac0869d2009-11-21 06:21:52 +00001170 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001171 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001172 Ops.push_back(Chain);
Bob Wilson226036e2010-03-20 22:13:40 +00001173 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 9);
Bob Wilson24f995d2009-10-14 18:32:29 +00001174 }
1175
1176 // Otherwise, quad registers are stored with two separate instructions,
1177 // where one stores the even registers and the other stores the odd registers.
1178
Bob Wilson226036e2010-03-20 22:13:40 +00001179 Ops.push_back(Reg0); // post-access address offset
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001180
Bob Wilson24f995d2009-10-14 18:32:29 +00001181 // Store the even subregs.
1182 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1183 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1184 N->getOperand(Vec+3)));
Evan Chengac0869d2009-11-21 06:21:52 +00001185 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001186 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001187 Ops.push_back(Chain);
1188 unsigned Opc = QOpcodes0[OpcodeIndex];
1189 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilson226036e2010-03-20 22:13:40 +00001190 MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001191 Chain = SDValue(VStA, 1);
1192
1193 // Store the odd subregs.
1194 Ops[0] = SDValue(VStA, 0); // MemAddr
1195 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
Bob Wilson226036e2010-03-20 22:13:40 +00001196 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
Bob Wilson24f995d2009-10-14 18:32:29 +00001197 N->getOperand(Vec+3));
Bob Wilson226036e2010-03-20 22:13:40 +00001198 Ops[NumVecs+5] = Chain;
Bob Wilson24f995d2009-10-14 18:32:29 +00001199 Opc = QOpcodes1[OpcodeIndex];
1200 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilson226036e2010-03-20 22:13:40 +00001201 MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001202 Chain = SDValue(VStB, 1);
1203 ReplaceUses(SDValue(N, 0), Chain);
1204 return NULL;
1205}
1206
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001207SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001208 unsigned NumVecs, unsigned *DOpcodes,
1209 unsigned *QOpcodes0,
1210 unsigned *QOpcodes1) {
1211 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001212 DebugLoc dl = N->getDebugLoc();
1213
Bob Wilson226036e2010-03-20 22:13:40 +00001214 SDValue MemAddr, Align;
1215 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001216 return NULL;
1217
1218 SDValue Chain = N->getOperand(0);
1219 unsigned Lane =
1220 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001221 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001222 bool is64BitVector = VT.is64BitVector();
1223
Bob Wilson96493442009-10-14 16:46:45 +00001224 // Quad registers are handled by load/store of subregs. Find the subreg info.
Bob Wilsona7c397c2009-10-14 16:19:03 +00001225 unsigned NumElts = 0;
1226 int SubregIdx = 0;
1227 EVT RegVT = VT;
1228 if (!is64BitVector) {
1229 RegVT = GetNEONSubregVT(VT);
1230 NumElts = RegVT.getVectorNumElements();
1231 SubregIdx = (Lane < NumElts) ? ARM::DSUBREG_0 : ARM::DSUBREG_1;
1232 }
1233
1234 unsigned OpcodeIndex;
1235 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001236 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001237 // Double-register operations:
1238 case MVT::v8i8: OpcodeIndex = 0; break;
1239 case MVT::v4i16: OpcodeIndex = 1; break;
1240 case MVT::v2f32:
1241 case MVT::v2i32: OpcodeIndex = 2; break;
1242 // Quad-register operations:
1243 case MVT::v8i16: OpcodeIndex = 0; break;
1244 case MVT::v4f32:
1245 case MVT::v4i32: OpcodeIndex = 1; break;
1246 }
1247
Evan Chengac0869d2009-11-21 06:21:52 +00001248 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
Bob Wilson226036e2010-03-20 22:13:40 +00001249 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001250
Bob Wilson226036e2010-03-20 22:13:40 +00001251 SmallVector<SDValue, 10> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001252 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001253 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001254
1255 unsigned Opc = 0;
1256 if (is64BitVector) {
1257 Opc = DOpcodes[OpcodeIndex];
1258 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1259 Ops.push_back(N->getOperand(Vec+3));
1260 } else {
1261 // Check if this is loading the even or odd subreg of a Q register.
1262 if (Lane < NumElts) {
1263 Opc = QOpcodes0[OpcodeIndex];
1264 } else {
1265 Lane -= NumElts;
1266 Opc = QOpcodes1[OpcodeIndex];
1267 }
1268 // Extract the subregs of the input vector.
1269 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1270 Ops.push_back(CurDAG->getTargetExtractSubreg(SubregIdx, dl, RegVT,
1271 N->getOperand(Vec+3)));
1272 }
1273 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001274 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001275 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001276 Ops.push_back(Chain);
1277
Bob Wilson96493442009-10-14 16:46:45 +00001278 if (!IsLoad)
Bob Wilson226036e2010-03-20 22:13:40 +00001279 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson96493442009-10-14 16:46:45 +00001280
Bob Wilsona7c397c2009-10-14 16:19:03 +00001281 std::vector<EVT> ResTys(NumVecs, RegVT);
1282 ResTys.push_back(MVT::Other);
1283 SDNode *VLdLn =
Bob Wilson226036e2010-03-20 22:13:40 +00001284 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), NumVecs+6);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001285 // For a 64-bit vector load to D registers, nothing more needs to be done.
1286 if (is64BitVector)
1287 return VLdLn;
1288
1289 // For 128-bit vectors, take the 64-bit results of the load and insert them
1290 // as subregs into the result.
1291 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1292 SDValue QuadVec = CurDAG->getTargetInsertSubreg(SubregIdx, dl, VT,
1293 N->getOperand(Vec+3),
1294 SDValue(VLdLn, Vec));
1295 ReplaceUses(SDValue(N, Vec), QuadVec);
1296 }
1297
1298 Chain = SDValue(VLdLn, NumVecs);
1299 ReplaceUses(SDValue(N, NumVecs), Chain);
1300 return NULL;
1301}
1302
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001303SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001304 unsigned Opc) {
1305 if (!Subtarget->hasV6T2Ops())
1306 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001307
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001308 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001309 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001310 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1311 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001312 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001313 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1314 unsigned Width = 32 - Srl_imm;
1315 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001316 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001317 return NULL;
1318 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001319 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001320 CurDAG->getTargetConstant(LSB, MVT::i32),
1321 CurDAG->getTargetConstant(Width, MVT::i32),
1322 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001323 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001324 }
1325 }
1326 return NULL;
1327}
1328
Evan Cheng9ef48352009-11-20 00:54:03 +00001329SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001330SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001331 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1332 SDValue CPTmp0;
1333 SDValue CPTmp1;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001334 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001335 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1336 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1337 unsigned Opc = 0;
1338 switch (SOShOp) {
1339 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1340 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1341 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1342 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1343 default:
1344 llvm_unreachable("Unknown so_reg opcode!");
1345 break;
1346 }
1347 SDValue SOShImm =
1348 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1349 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1350 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001351 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001352 }
1353 return 0;
1354}
1355
1356SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001357SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001358 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1359 SDValue CPTmp0;
1360 SDValue CPTmp1;
1361 SDValue CPTmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001362 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001363 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1364 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001365 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001366 }
1367 return 0;
1368}
1369
1370SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001371SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001372 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1373 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1374 if (!T)
1375 return 0;
1376
1377 if (Predicate_t2_so_imm(TrueVal.getNode())) {
1378 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1379 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1380 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001381 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001382 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1383 }
1384 return 0;
1385}
1386
1387SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001388SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001389 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1390 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1391 if (!T)
1392 return 0;
1393
1394 if (Predicate_so_imm(TrueVal.getNode())) {
1395 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1396 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1397 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001398 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001399 ARM::MOVCCi, MVT::i32, Ops, 5);
1400 }
1401 return 0;
1402}
1403
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001404SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1405 EVT VT = N->getValueType(0);
1406 SDValue FalseVal = N->getOperand(0);
1407 SDValue TrueVal = N->getOperand(1);
1408 SDValue CC = N->getOperand(2);
1409 SDValue CCR = N->getOperand(3);
1410 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001411 assert(CC.getOpcode() == ISD::Constant);
1412 assert(CCR.getOpcode() == ISD::Register);
1413 ARMCC::CondCodes CCVal =
1414 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001415
1416 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1417 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1418 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1419 // Pattern complexity = 18 cost = 1 size = 0
1420 SDValue CPTmp0;
1421 SDValue CPTmp1;
1422 SDValue CPTmp2;
1423 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001424 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001425 CCVal, CCR, InFlag);
1426 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001427 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001428 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1429 if (Res)
1430 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001431 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001432 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001433 CCVal, CCR, InFlag);
1434 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001435 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001436 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1437 if (Res)
1438 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001439 }
1440
1441 // Pattern: (ARMcmov:i32 GPR:i32:$false,
1442 // (imm:i32)<<P:Predicate_so_imm>>:$true,
1443 // (imm:i32):$cc)
1444 // Emits: (MOVCCi:i32 GPR:i32:$false,
1445 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1446 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001447 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001448 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001449 CCVal, CCR, InFlag);
1450 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001451 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001452 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1453 if (Res)
1454 return Res;
1455 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001456 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001457 CCVal, CCR, InFlag);
1458 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001459 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001460 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1461 if (Res)
1462 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001463 }
1464 }
1465
1466 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1467 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1468 // Pattern complexity = 6 cost = 1 size = 0
1469 //
1470 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1471 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1472 // Pattern complexity = 6 cost = 11 size = 0
1473 //
1474 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001475 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1476 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001477 unsigned Opc = 0;
1478 switch (VT.getSimpleVT().SimpleTy) {
1479 default: assert(false && "Illegal conditional move type!");
1480 break;
1481 case MVT::i32:
1482 Opc = Subtarget->isThumb()
1483 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1484 : ARM::MOVCCr;
1485 break;
1486 case MVT::f32:
1487 Opc = ARM::VMOVScc;
1488 break;
1489 case MVT::f64:
1490 Opc = ARM::VMOVDcc;
1491 break;
1492 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001493 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001494}
1495
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001496SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001497 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001498
Dan Gohmane8be6c62008-07-17 19:10:17 +00001499 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001500 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001501
1502 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001503 default: break;
1504 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001505 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001506 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001507 if (Subtarget->hasThumb2())
1508 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1509 // be done with MOV + MOVT, at worst.
1510 UseCP = 0;
1511 else {
1512 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001513 UseCP = (Val > 255 && // MOV
1514 ~Val > 255 && // MOV + MVN
1515 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001516 } else
1517 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1518 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1519 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1520 }
1521
Evan Chenga8e29892007-01-19 07:51:42 +00001522 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001523 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001524 CurDAG->getTargetConstantPool(ConstantInt::get(
1525 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001526 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001527
1528 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001529 if (Subtarget->isThumb1Only()) {
Evan Chengac0869d2009-11-21 06:21:52 +00001530 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
Owen Anderson825b72b2009-08-11 20:47:22 +00001531 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001532 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001533 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1534 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001535 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001536 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001537 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001538 CurDAG->getRegister(0, MVT::i32),
1539 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001540 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001541 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001542 CurDAG->getEntryNode()
1543 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001544 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1545 Ops, 6);
Evan Cheng012f2d92007-01-24 08:53:17 +00001546 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001547 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001548 return NULL;
1549 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001550
Evan Chenga8e29892007-01-19 07:51:42 +00001551 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001552 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001553 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001554 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001555 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001556 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001557 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001558 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001559 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1560 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001561 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001562 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1563 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001564 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1565 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1566 CurDAG->getRegister(0, MVT::i32) };
1567 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001568 }
Evan Chenga8e29892007-01-19 07:51:42 +00001569 }
Evan Cheng86198642009-08-07 00:34:42 +00001570 case ARMISD::DYN_ALLOC:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001571 return SelectDYN_ALLOC(N);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001572 case ISD::SRL:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001573 if (SDNode *I = SelectV6T2BitfieldExtractOp(N,
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001574 Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX))
1575 return I;
1576 break;
1577 case ISD::SRA:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001578 if (SDNode *I = SelectV6T2BitfieldExtractOp(N,
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001579 Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX))
1580 return I;
1581 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001582 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001583 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001584 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001585 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001586 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001587 if (!RHSV) break;
1588 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001589 unsigned ShImm = Log2_32(RHSV-1);
1590 if (ShImm >= 32)
1591 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001592 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001593 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001594 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1595 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001596 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001597 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001598 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001599 } else {
1600 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001601 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001602 }
Evan Chenga8e29892007-01-19 07:51:42 +00001603 }
1604 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001605 unsigned ShImm = Log2_32(RHSV+1);
1606 if (ShImm >= 32)
1607 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001608 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001609 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001610 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1611 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001612 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001613 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001614 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 5);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001615 } else {
1616 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001617 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001618 }
Evan Chenga8e29892007-01-19 07:51:42 +00001619 }
1620 }
1621 break;
Evan Cheng20956592009-10-21 08:15:52 +00001622 case ISD::AND: {
1623 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1624 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1625 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1626 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1627 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001628 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001629 if (VT != MVT::i32)
1630 break;
1631 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1632 ? ARM::t2MOVTi16
1633 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1634 if (!Opc)
1635 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001636 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001637 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1638 if (!N1C)
1639 break;
1640 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1641 SDValue N2 = N0.getOperand(1);
1642 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1643 if (!N2C)
1644 break;
1645 unsigned N1CVal = N1C->getZExtValue();
1646 unsigned N2CVal = N2C->getZExtValue();
1647 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1648 (N1CVal & 0xffffU) == 0xffffU &&
1649 (N2CVal & 0xffffU) == 0x0U) {
1650 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1651 MVT::i32);
1652 SDValue Ops[] = { N0.getOperand(0), Imm16,
1653 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1654 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
1655 }
1656 }
1657 break;
1658 }
Jim Grosbache5165492009-11-09 00:11:35 +00001659 case ARMISD::VMOVRRD:
1660 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001661 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00001662 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00001663 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001664 if (Subtarget->isThumb1Only())
1665 break;
1666 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001667 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001668 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1669 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001670 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001671 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001672 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001673 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1674 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001675 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001676 }
Evan Chengee568cf2007-07-05 07:15:27 +00001677 }
Dan Gohman525178c2007-10-08 18:33:35 +00001678 case ISD::SMUL_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) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001684 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001685 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001686 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001687 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1688 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001689 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001690 }
Evan Chengee568cf2007-07-05 07:15:27 +00001691 }
Evan Chenga8e29892007-01-19 07:51:42 +00001692 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00001693 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001694 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001695 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001696 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001697 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001698 if (ResNode)
1699 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00001700 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001701 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001702 }
Evan Chengee568cf2007-07-05 07:15:27 +00001703 case ARMISD::BRCOND: {
1704 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1705 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1706 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001707
Evan Chengee568cf2007-07-05 07:15:27 +00001708 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1709 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
1710 // Pattern complexity = 6 cost = 1 size = 0
1711
David Goodwin5e47a9a2009-06-30 18:04:13 +00001712 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1713 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1714 // Pattern complexity = 6 cost = 1 size = 0
1715
Jim Grosbach764ab522009-08-11 15:33:49 +00001716 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00001717 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001718 SDValue Chain = N->getOperand(0);
1719 SDValue N1 = N->getOperand(1);
1720 SDValue N2 = N->getOperand(2);
1721 SDValue N3 = N->getOperand(3);
1722 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00001723 assert(N1.getOpcode() == ISD::BasicBlock);
1724 assert(N2.getOpcode() == ISD::Constant);
1725 assert(N3.getOpcode() == ISD::Register);
1726
Dan Gohman475871a2008-07-27 21:46:04 +00001727 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001728 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00001729 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00001730 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00001731 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
1732 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00001733 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001734 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00001735 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001736 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00001737 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001738 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00001739 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00001740 return NULL;
1741 }
Evan Cheng07ba9062009-11-19 21:45:22 +00001742 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001743 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00001744 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001745 EVT VT = N->getValueType(0);
1746 SDValue N0 = N->getOperand(0);
1747 SDValue N1 = N->getOperand(1);
1748 SDValue N2 = N->getOperand(2);
1749 SDValue N3 = N->getOperand(3);
1750 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00001751 assert(N2.getOpcode() == ISD::Constant);
1752 assert(N3.getOpcode() == ISD::Register);
1753
Dan Gohman475871a2008-07-27 21:46:04 +00001754 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001755 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00001756 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00001757 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00001758 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00001759 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00001760 default: assert(false && "Illegal conditional move type!");
1761 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001762 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00001763 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00001764 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001765 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00001766 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00001767 break;
Evan Chengee568cf2007-07-05 07:15:27 +00001768 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001769 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001770 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00001771
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001772 case ARMISD::VZIP: {
1773 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001774 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001775 switch (VT.getSimpleVT().SimpleTy) {
1776 default: return NULL;
1777 case MVT::v8i8: Opc = ARM::VZIPd8; break;
1778 case MVT::v4i16: Opc = ARM::VZIPd16; break;
1779 case MVT::v2f32:
1780 case MVT::v2i32: Opc = ARM::VZIPd32; break;
1781 case MVT::v16i8: Opc = ARM::VZIPq8; break;
1782 case MVT::v8i16: Opc = ARM::VZIPq16; break;
1783 case MVT::v4f32:
1784 case MVT::v4i32: Opc = ARM::VZIPq32; break;
1785 }
Evan Chengac0869d2009-11-21 06:21:52 +00001786 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
1787 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1788 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1789 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001790 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001791 case ARMISD::VUZP: {
1792 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001793 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001794 switch (VT.getSimpleVT().SimpleTy) {
1795 default: return NULL;
1796 case MVT::v8i8: Opc = ARM::VUZPd8; break;
1797 case MVT::v4i16: Opc = ARM::VUZPd16; break;
1798 case MVT::v2f32:
1799 case MVT::v2i32: Opc = ARM::VUZPd32; break;
1800 case MVT::v16i8: Opc = ARM::VUZPq8; break;
1801 case MVT::v8i16: Opc = ARM::VUZPq16; break;
1802 case MVT::v4f32:
1803 case MVT::v4i32: Opc = ARM::VUZPq32; break;
1804 }
Evan Chengac0869d2009-11-21 06:21:52 +00001805 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
1806 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1807 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1808 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001809 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001810 case ARMISD::VTRN: {
1811 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001812 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001813 switch (VT.getSimpleVT().SimpleTy) {
1814 default: return NULL;
1815 case MVT::v8i8: Opc = ARM::VTRNd8; break;
1816 case MVT::v4i16: Opc = ARM::VTRNd16; break;
1817 case MVT::v2f32:
1818 case MVT::v2i32: Opc = ARM::VTRNd32; break;
1819 case MVT::v16i8: Opc = ARM::VTRNq8; break;
1820 case MVT::v8i16: Opc = ARM::VTRNq16; break;
1821 case MVT::v4f32:
1822 case MVT::v4i32: Opc = ARM::VTRNq32; break;
1823 }
Evan Chengac0869d2009-11-21 06:21:52 +00001824 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
1825 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1826 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1827 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001828 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00001829
1830 case ISD::INTRINSIC_VOID:
1831 case ISD::INTRINSIC_W_CHAIN: {
1832 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00001833 switch (IntNo) {
1834 default:
1835 break;
1836
Bob Wilson621f1952010-03-23 05:25:43 +00001837 case Intrinsic::arm_neon_vld1: {
1838 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
1839 ARM::VLD1d32, ARM::VLD1d64 };
1840 unsigned QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
1841 ARM::VLD1q32, ARM::VLD1q64 };
1842 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
1843 }
1844
Bob Wilson31fb12f2009-08-26 17:39:53 +00001845 case Intrinsic::arm_neon_vld2: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001846 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
Bob Wilson621f1952010-03-23 05:25:43 +00001847 ARM::VLD2d32, ARM::VLD1q64 };
Bob Wilson3e36f132009-10-14 17:28:52 +00001848 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001849 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001850 }
1851
1852 case Intrinsic::arm_neon_vld3: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001853 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00001854 ARM::VLD3d32, ARM::VLD1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001855 unsigned QOpcodes0[] = { ARM::VLD3q8_UPD,
1856 ARM::VLD3q16_UPD,
1857 ARM::VLD3q32_UPD };
1858 unsigned QOpcodes1[] = { ARM::VLD3q8odd_UPD,
1859 ARM::VLD3q16odd_UPD,
1860 ARM::VLD3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001861 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001862 }
1863
1864 case Intrinsic::arm_neon_vld4: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001865 unsigned DOpcodes[] = { ARM::VLD4d8, ARM::VLD4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00001866 ARM::VLD4d32, ARM::VLD1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001867 unsigned QOpcodes0[] = { ARM::VLD4q8_UPD,
1868 ARM::VLD4q16_UPD,
1869 ARM::VLD4q32_UPD };
1870 unsigned QOpcodes1[] = { ARM::VLD4q8odd_UPD,
1871 ARM::VLD4q16odd_UPD,
1872 ARM::VLD4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001873 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001874 }
1875
Bob Wilson243fcc52009-09-01 04:26:28 +00001876 case Intrinsic::arm_neon_vld2lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00001877 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001878 unsigned QOpcodes0[] = { ARM::VLD2LNq16, ARM::VLD2LNq32 };
1879 unsigned QOpcodes1[] = { ARM::VLD2LNq16odd, ARM::VLD2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001880 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00001881 }
1882
1883 case Intrinsic::arm_neon_vld3lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00001884 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001885 unsigned QOpcodes0[] = { ARM::VLD3LNq16, ARM::VLD3LNq32 };
1886 unsigned QOpcodes1[] = { ARM::VLD3LNq16odd, ARM::VLD3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001887 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00001888 }
1889
1890 case Intrinsic::arm_neon_vld4lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00001891 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001892 unsigned QOpcodes0[] = { ARM::VLD4LNq16, ARM::VLD4LNq32 };
1893 unsigned QOpcodes1[] = { ARM::VLD4LNq16odd, ARM::VLD4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001894 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00001895 }
1896
Bob Wilson31fb12f2009-08-26 17:39:53 +00001897 case Intrinsic::arm_neon_vst2: {
Bob Wilson24f995d2009-10-14 18:32:29 +00001898 unsigned DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
1899 ARM::VST2d32, ARM::VST2d64 };
1900 unsigned QOpcodes[] = { ARM::VST2q8, ARM::VST2q16, ARM::VST2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001901 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001902 }
1903
1904 case Intrinsic::arm_neon_vst3: {
Bob Wilson24f995d2009-10-14 18:32:29 +00001905 unsigned DOpcodes[] = { ARM::VST3d8, ARM::VST3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00001906 ARM::VST3d32, ARM::VST1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001907 unsigned QOpcodes0[] = { ARM::VST3q8_UPD,
1908 ARM::VST3q16_UPD,
1909 ARM::VST3q32_UPD };
1910 unsigned QOpcodes1[] = { ARM::VST3q8odd_UPD,
1911 ARM::VST3q16odd_UPD,
1912 ARM::VST3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001913 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001914 }
1915
1916 case Intrinsic::arm_neon_vst4: {
Bob Wilson24f995d2009-10-14 18:32:29 +00001917 unsigned DOpcodes[] = { ARM::VST4d8, ARM::VST4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00001918 ARM::VST4d32, ARM::VST1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001919 unsigned QOpcodes0[] = { ARM::VST4q8_UPD,
1920 ARM::VST4q16_UPD,
1921 ARM::VST4q32_UPD };
1922 unsigned QOpcodes1[] = { ARM::VST4q8odd_UPD,
1923 ARM::VST4q16odd_UPD,
1924 ARM::VST4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001925 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001926 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00001927
1928 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson96493442009-10-14 16:46:45 +00001929 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001930 unsigned QOpcodes0[] = { ARM::VST2LNq16, ARM::VST2LNq32 };
1931 unsigned QOpcodes1[] = { ARM::VST2LNq16odd, ARM::VST2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001932 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00001933 }
1934
1935 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson96493442009-10-14 16:46:45 +00001936 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001937 unsigned QOpcodes0[] = { ARM::VST3LNq16, ARM::VST3LNq32 };
1938 unsigned QOpcodes1[] = { ARM::VST3LNq16odd, ARM::VST3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001939 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00001940 }
1941
1942 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson96493442009-10-14 16:46:45 +00001943 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001944 unsigned QOpcodes0[] = { ARM::VST4LNq16, ARM::VST4LNq32 };
1945 unsigned QOpcodes1[] = { ARM::VST4LNq16odd, ARM::VST4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001946 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00001947 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00001948 }
1949 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00001950 }
1951
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001952 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00001953}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001954
Bob Wilson224c2442009-05-19 05:53:42 +00001955bool ARMDAGToDAGISel::
1956SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
1957 std::vector<SDValue> &OutOps) {
1958 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00001959 // Require the address to be in a register. That is safe for all ARM
1960 // variants and it is hard to do anything much smarter without knowing
1961 // how the operand is used.
1962 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00001963 return false;
1964}
1965
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001966/// createARMISelDag - This pass converts a legalized DAG into a
1967/// ARM-specific DAG, ready for instruction scheduling.
1968///
Bob Wilson522ce972009-09-28 14:30:20 +00001969FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
1970 CodeGenOpt::Level OptLevel) {
1971 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001972}