blob: 5285a43735c3528090a515b9a3a9bafe9452af98 [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
Dale Johannesen51e28e62010-06-03 21:09:53 +000014#define DEBUG_TYPE "arm-isel"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000015#include "ARM.h"
Evan Chenge5ad88e2008-12-10 21:54:21 +000016#include "ARMAddressingModes.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"
Evan Cheng94cc6d32010-05-04 20:39:49 +000031#include "llvm/Support/CommandLine.h"
Chris Lattner3d62d782008-02-03 05:43:57 +000032#include "llvm/Support/Compiler.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000033#include "llvm/Support/Debug.h"
Torok Edwindac237e2009-07-08 20:53:28 +000034#include "llvm/Support/ErrorHandling.h"
35#include "llvm/Support/raw_ostream.h"
36
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000037using namespace llvm;
38
Evan Chenga2c519b2010-07-30 23:33:54 +000039static cl::opt<bool>
40DisableShifterOp("disable-shifter-op", cl::Hidden,
41 cl::desc("Disable isel of shifter-op"),
42 cl::init(false));
43
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000044//===--------------------------------------------------------------------===//
45/// ARMDAGToDAGISel - ARM specific code to select ARM machine
46/// instructions for SelectionDAG operations.
47///
48namespace {
Jim Grosbach82891622010-09-29 19:03:54 +000049
50enum AddrMode2Type {
51 AM2_BASE, // Simple AM2 (+-imm12)
52 AM2_SHOP // Shifter-op AM2
53};
54
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000055class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000056 ARMBaseTargetMachine &TM;
Evan Cheng3f7eb8e2008-09-18 07:24:33 +000057
Evan Chenga8e29892007-01-19 07:51:42 +000058 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
59 /// make the right decision when generating code for different targets.
60 const ARMSubtarget *Subtarget;
61
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000062public:
Bob Wilson522ce972009-09-28 14:30:20 +000063 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
64 CodeGenOpt::Level OptLevel)
65 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Chenga8e29892007-01-19 07:51:42 +000066 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000067 }
68
Evan Chenga8e29892007-01-19 07:51:42 +000069 virtual const char *getPassName() const {
70 return "ARM Instruction Selection";
Anton Korobeynikov52237112009-06-17 18:13:58 +000071 }
72
Bob Wilsonaf4a8912009-10-08 18:51:31 +000073 /// getI32Imm - Return a target constant of type i32 with the specified
74 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000075 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000076 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000077 }
78
Dan Gohmaneeb3a002010-01-05 01:24:18 +000079 SDNode *Select(SDNode *N);
Evan Cheng014bf212010-02-15 19:41:07 +000080
Chris Lattner52a261b2010-09-21 20:31:19 +000081 bool SelectShifterOperandReg(SDValue N, SDValue &A,
Evan Cheng055b0312009-06-29 07:51:04 +000082 SDValue &B, SDValue &C);
Jim Grosbach3e556122010-10-26 22:37:02 +000083 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
84 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
85
Jim Grosbach82891622010-09-29 19:03:54 +000086 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
87 SDValue &Offset, SDValue &Opc);
88 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
89 SDValue &Opc) {
90 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
91 }
92
93 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
94 SDValue &Opc) {
95 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
96 }
97
98 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
99 SDValue &Opc) {
100 SelectAddrMode2Worker(N, Base, Offset, Opc);
Jim Grosbach3e556122010-10-26 22:37:02 +0000101// return SelectAddrMode2ShOp(N, Base, Offset, Opc);
Jim Grosbach82891622010-09-29 19:03:54 +0000102 // This always matches one way or another.
103 return true;
104 }
105
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000106 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000107 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000108 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000109 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000110 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000111 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000112 bool SelectAddrMode4(SDValue N, SDValue &Addr, SDValue &Mode);
113 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000114 SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000115 bool SelectAddrMode6(SDValue N, SDValue &Addr, SDValue &Align);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000116
Chris Lattner52a261b2010-09-21 20:31:19 +0000117 bool SelectAddrModePC(SDValue N, SDValue &Offset,
Bob Wilson8b024a52009-07-01 23:16:05 +0000118 SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +0000119
Chris Lattner52a261b2010-09-21 20:31:19 +0000120 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
121 bool SelectThumbAddrModeRI5(SDValue N, unsigned Scale,
Dan Gohman475871a2008-07-27 21:46:04 +0000122 SDValue &Base, SDValue &OffImm,
123 SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000124 bool SelectThumbAddrModeS1(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000125 SDValue &OffImm, SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000126 bool SelectThumbAddrModeS2(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000127 SDValue &OffImm, SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000128 bool SelectThumbAddrModeS4(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000129 SDValue &OffImm, SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000130 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000131
Chris Lattner52a261b2010-09-21 20:31:19 +0000132 bool SelectT2ShifterOperandReg(SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000133 SDValue &BaseReg, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000134 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
135 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000136 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000137 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000138 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000139 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000140 SDValue &OffReg, SDValue &ShImm);
141
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000142 inline bool Pred_so_imm(SDNode *inN) const {
143 ConstantSDNode *N = cast<ConstantSDNode>(inN);
144 return ARM_AM::getSOImmVal(N->getZExtValue()) != -1;
145 }
146
147 inline bool Pred_t2_so_imm(SDNode *inN) const {
148 ConstantSDNode *N = cast<ConstantSDNode>(inN);
149 return ARM_AM::getT2SOImmVal(N->getZExtValue()) != -1;
150 }
151
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000152 // Include the pieces autogenerated from the target description.
153#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000154
155private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000156 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
157 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000158 SDNode *SelectARMIndexedLoad(SDNode *N);
159 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000160
Bob Wilson621f1952010-03-23 05:25:43 +0000161 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
162 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000163 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000164 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000165 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000166 unsigned *QOpcodes0, unsigned *QOpcodes1);
167
Bob Wilson24f995d2009-10-14 18:32:29 +0000168 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000169 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000170 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000171 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000172 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000173 unsigned *QOpcodes0, unsigned *QOpcodes1);
174
Bob Wilson96493442009-10-14 16:46:45 +0000175 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000176 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson8466fa12010-09-13 23:01:35 +0000177 /// load/store of D registers and Q registers.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000178 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
Bob Wilson8466fa12010-09-13 23:01:35 +0000179 unsigned *DOpcodes, unsigned *QOpcodes);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000180
Bob Wilson78dfbc32010-07-07 00:08:54 +0000181 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
182 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
183 /// generated to force the table registers to be consecutive.
184 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000185
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000186 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000187 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000188
Evan Cheng07ba9062009-11-19 21:45:22 +0000189 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000190 SDNode *SelectCMOVOp(SDNode *N);
191 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000192 ARMCC::CondCodes CCVal, SDValue CCR,
193 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000194 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000195 ARMCC::CondCodes CCVal, SDValue CCR,
196 SDValue InFlag);
Jim Grosbacha4257162010-10-07 00:53:56 +0000197 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000198 ARMCC::CondCodes CCVal, SDValue CCR,
199 SDValue InFlag);
Jim Grosbach3bbdcea2010-10-07 00:42:42 +0000200 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000201 ARMCC::CondCodes CCVal, SDValue CCR,
202 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000203
Evan Chengde8aa4e2010-05-05 18:28:36 +0000204 SDNode *SelectConcatVector(SDNode *N);
205
Evan Chengaf4550f2009-07-02 01:23:32 +0000206 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
207 /// inline asm expressions.
208 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
209 char ConstraintCode,
210 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000211
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000212 // Form pairs of consecutive S, D, or Q registers.
213 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000214 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000215 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
216
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000217 // Form sequences of 4 consecutive S, D, or Q registers.
218 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000219 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000220 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000221};
Evan Chenga8e29892007-01-19 07:51:42 +0000222}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000223
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000224/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
225/// operand. If so Imm will receive the 32-bit value.
226static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
227 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
228 Imm = cast<ConstantSDNode>(N)->getZExtValue();
229 return true;
230 }
231 return false;
232}
233
234// isInt32Immediate - This method tests to see if a constant operand.
235// If so Imm will receive the 32 bit value.
236static bool isInt32Immediate(SDValue N, unsigned &Imm) {
237 return isInt32Immediate(N.getNode(), Imm);
238}
239
240// isOpcWithIntImmediate - This method tests to see if the node is a specific
241// opcode and that it has a immediate integer right operand.
242// If so Imm will receive the 32 bit value.
243static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
244 return N->getOpcode() == Opc &&
245 isInt32Immediate(N->getOperand(1).getNode(), Imm);
246}
247
248
Chris Lattner52a261b2010-09-21 20:31:19 +0000249bool ARMDAGToDAGISel::SelectShifterOperandReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000250 SDValue &BaseReg,
251 SDValue &ShReg,
252 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000253 if (DisableShifterOp)
254 return false;
255
Evan Cheng055b0312009-06-29 07:51:04 +0000256 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
257
258 // Don't match base register only case. That is matched to a separate
259 // lower complexity pattern with explicit register operand.
260 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000261
Evan Cheng055b0312009-06-29 07:51:04 +0000262 BaseReg = N.getOperand(0);
263 unsigned ShImmVal = 0;
264 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000265 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000266 ShImmVal = RHS->getZExtValue() & 31;
267 } else {
268 ShReg = N.getOperand(1);
269 }
270 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000271 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000272 return true;
273}
274
Jim Grosbach3e556122010-10-26 22:37:02 +0000275bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
276 SDValue &Base,
277 SDValue &OffImm) {
278 // Match simple R + imm12 operands.
279
280 // Base only.
281 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
282 if (N.getOpcode() == ISD::FrameIndex) {
283 // Match frame index...
284 int FI = cast<FrameIndexSDNode>(N)->getIndex();
285 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
286 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
287 return true;
288 } else if (N.getOpcode() == ARMISD::Wrapper &&
289 !(Subtarget->useMovt() &&
290 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
291 Base = N.getOperand(0);
292 } else
293 Base = N;
294 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
295 return true;
296 }
297
298 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
299 int RHSC = (int)RHS->getZExtValue();
300 if (N.getOpcode() == ISD::SUB)
301 RHSC = -RHSC;
302
303 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
304 Base = N.getOperand(0);
305 if (Base.getOpcode() == ISD::FrameIndex) {
306 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
307 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
308 }
309 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
310 return true;
311 }
312 }
313
314 // Base only.
315 Base = N;
316 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
317 return true;
318}
319
320
321
322bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
323 SDValue &Opc) {
324 if (N.getOpcode() == ISD::MUL) {
325 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
326 // X * [3,5,9] -> X + X * [2,4,8] etc.
327 int RHSC = (int)RHS->getZExtValue();
328 if (RHSC & 1) {
329 RHSC = RHSC & ~1;
330 ARM_AM::AddrOpc AddSub = ARM_AM::add;
331 if (RHSC < 0) {
332 AddSub = ARM_AM::sub;
333 RHSC = - RHSC;
334 }
335 if (isPowerOf2_32(RHSC)) {
336 unsigned ShAmt = Log2_32(RHSC);
337 Base = Offset = N.getOperand(0);
338 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
339 ARM_AM::lsl),
340 MVT::i32);
341 return true;
342 }
343 }
344 }
345 }
346
347 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB)
348 return false;
349
350 // Leave simple R +/- imm12 operands for LDRi12
351 if (N.getOpcode() == ISD::ADD) {
352 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
353 int RHSC = (int)RHS->getZExtValue();
354 if ((RHSC >= 0 && RHSC < 0x1000) ||
355 (RHSC < 0 && RHSC > -0x1000)) // 12 bits.
356 return false;
357 }
358 }
359
360 // Otherwise this is R +/- [possibly shifted] R.
361 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
362 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
363 unsigned ShAmt = 0;
364
365 Base = N.getOperand(0);
366 Offset = N.getOperand(1);
367
368 if (ShOpcVal != ARM_AM::no_shift) {
369 // Check to see if the RHS of the shift is a constant, if not, we can't fold
370 // it.
371 if (ConstantSDNode *Sh =
372 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
373 ShAmt = Sh->getZExtValue();
374 Offset = N.getOperand(1).getOperand(0);
375 } else {
376 ShOpcVal = ARM_AM::no_shift;
377 }
378 }
379
380 // Try matching (R shl C) + (R).
381 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
382 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
383 if (ShOpcVal != ARM_AM::no_shift) {
384 // Check to see if the RHS of the shift is a constant, if not, we can't
385 // fold it.
386 if (ConstantSDNode *Sh =
387 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
388 ShAmt = Sh->getZExtValue();
389 Offset = N.getOperand(0).getOperand(0);
390 Base = N.getOperand(1);
391 } else {
392 ShOpcVal = ARM_AM::no_shift;
393 }
394 }
395 }
396
397 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
398 MVT::i32);
399 return true;
400}
401
402
403
404
405//-----
406
Jim Grosbach82891622010-09-29 19:03:54 +0000407AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
408 SDValue &Base,
409 SDValue &Offset,
410 SDValue &Opc) {
Evan Chenga13fd102007-03-13 21:05:54 +0000411 if (N.getOpcode() == ISD::MUL) {
412 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
413 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000414 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000415 if (RHSC & 1) {
416 RHSC = RHSC & ~1;
417 ARM_AM::AddrOpc AddSub = ARM_AM::add;
418 if (RHSC < 0) {
419 AddSub = ARM_AM::sub;
420 RHSC = - RHSC;
421 }
422 if (isPowerOf2_32(RHSC)) {
423 unsigned ShAmt = Log2_32(RHSC);
424 Base = Offset = N.getOperand(0);
425 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
426 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000427 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000428 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000429 }
430 }
431 }
432 }
433
Evan Chenga8e29892007-01-19 07:51:42 +0000434 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
435 Base = N;
436 if (N.getOpcode() == ISD::FrameIndex) {
437 int FI = cast<FrameIndexSDNode>(N)->getIndex();
438 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000439 } else if (N.getOpcode() == ARMISD::Wrapper &&
440 !(Subtarget->useMovt() &&
441 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000442 Base = N.getOperand(0);
443 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000444 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000445 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
446 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000447 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000448 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000449 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000450
Evan Chenga8e29892007-01-19 07:51:42 +0000451 // Match simple R +/- imm12 operands.
Jim Grosbachbe912322010-09-29 17:32:29 +0000452 if (N.getOpcode() == ISD::ADD) {
Evan Chenga8e29892007-01-19 07:51:42 +0000453 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000454 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000455 if ((RHSC >= 0 && RHSC < 0x1000) ||
456 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000457 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000458 if (Base.getOpcode() == ISD::FrameIndex) {
459 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
460 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
461 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000462 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000463
464 ARM_AM::AddrOpc AddSub = ARM_AM::add;
465 if (RHSC < 0) {
466 AddSub = ARM_AM::sub;
467 RHSC = - RHSC;
468 }
469 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000470 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000471 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000472 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000473 }
Evan Chenga8e29892007-01-19 07:51:42 +0000474 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000475 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000476
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000477 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000478 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
479 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
480 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000481
Evan Chenga8e29892007-01-19 07:51:42 +0000482 Base = N.getOperand(0);
483 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000484
Evan Chenga8e29892007-01-19 07:51:42 +0000485 if (ShOpcVal != ARM_AM::no_shift) {
486 // Check to see if the RHS of the shift is a constant, if not, we can't fold
487 // it.
488 if (ConstantSDNode *Sh =
489 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000490 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000491 Offset = N.getOperand(1).getOperand(0);
492 } else {
493 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000494 }
495 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000496
Evan Chenga8e29892007-01-19 07:51:42 +0000497 // Try matching (R shl C) + (R).
498 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
499 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
500 if (ShOpcVal != ARM_AM::no_shift) {
501 // Check to see if the RHS of the shift is a constant, if not, we can't
502 // fold it.
503 if (ConstantSDNode *Sh =
504 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000505 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000506 Offset = N.getOperand(0).getOperand(0);
507 Base = N.getOperand(1);
508 } else {
509 ShOpcVal = ARM_AM::no_shift;
510 }
511 }
512 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000513
Evan Chenga8e29892007-01-19 07:51:42 +0000514 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000515 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000516 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000517}
518
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000519bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000520 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000521 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000522 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
523 ? cast<LoadSDNode>(Op)->getAddressingMode()
524 : cast<StoreSDNode>(Op)->getAddressingMode();
525 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
526 ? ARM_AM::add : ARM_AM::sub;
527 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000528 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000529 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000530 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000531 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
532 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000533 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000534 return true;
535 }
536 }
537
538 Offset = N;
539 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
540 unsigned ShAmt = 0;
541 if (ShOpcVal != ARM_AM::no_shift) {
542 // Check to see if the RHS of the shift is a constant, if not, we can't fold
543 // it.
544 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000545 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000546 Offset = N.getOperand(0);
547 } else {
548 ShOpcVal = ARM_AM::no_shift;
549 }
550 }
551
552 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000553 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000554 return true;
555}
556
Evan Chenga8e29892007-01-19 07:51:42 +0000557
Chris Lattner52a261b2010-09-21 20:31:19 +0000558bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000559 SDValue &Base, SDValue &Offset,
560 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000561 if (N.getOpcode() == ISD::SUB) {
562 // X - C is canonicalize to X + -C, no need to handle it here.
563 Base = N.getOperand(0);
564 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000565 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000566 return true;
567 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000568
Evan Chenga8e29892007-01-19 07:51:42 +0000569 if (N.getOpcode() != ISD::ADD) {
570 Base = N;
571 if (N.getOpcode() == ISD::FrameIndex) {
572 int FI = cast<FrameIndexSDNode>(N)->getIndex();
573 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
574 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000575 Offset = CurDAG->getRegister(0, MVT::i32);
576 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000577 return true;
578 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000579
Evan Chenga8e29892007-01-19 07:51:42 +0000580 // If the RHS is +/- imm8, fold into addr mode.
581 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000582 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000583 if ((RHSC >= 0 && RHSC < 256) ||
584 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000585 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000586 if (Base.getOpcode() == ISD::FrameIndex) {
587 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
588 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
589 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000590 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000591
592 ARM_AM::AddrOpc AddSub = ARM_AM::add;
593 if (RHSC < 0) {
594 AddSub = ARM_AM::sub;
595 RHSC = - RHSC;
596 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000597 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000598 return true;
599 }
600 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000601
Evan Chenga8e29892007-01-19 07:51:42 +0000602 Base = N.getOperand(0);
603 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000604 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000605 return true;
606}
607
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000608bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000609 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000610 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000611 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
612 ? cast<LoadSDNode>(Op)->getAddressingMode()
613 : cast<StoreSDNode>(Op)->getAddressingMode();
614 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
615 ? ARM_AM::add : ARM_AM::sub;
616 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000617 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000618 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000619 Offset = CurDAG->getRegister(0, MVT::i32);
620 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000621 return true;
622 }
623 }
624
625 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000626 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000627 return true;
628}
629
Chris Lattner52a261b2010-09-21 20:31:19 +0000630bool ARMDAGToDAGISel::SelectAddrMode4(SDValue N, SDValue &Addr, SDValue &Mode) {
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000631 Addr = N;
Bob Wilsonfd7fd942010-08-28 00:20:11 +0000632 Mode = CurDAG->getTargetConstant(ARM_AM::getAM4ModeImm(ARM_AM::ia), MVT::i32);
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000633 return true;
634}
Evan Chenga8e29892007-01-19 07:51:42 +0000635
Jim Grosbach3ab56582010-10-21 19:38:40 +0000636bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000637 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000638 if (N.getOpcode() != ISD::ADD) {
639 Base = N;
640 if (N.getOpcode() == ISD::FrameIndex) {
641 int FI = cast<FrameIndexSDNode>(N)->getIndex();
642 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000643 } else if (N.getOpcode() == ARMISD::Wrapper &&
644 !(Subtarget->useMovt() &&
645 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000646 Base = N.getOperand(0);
647 }
648 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000649 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000650 return true;
651 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000652
Evan Chenga8e29892007-01-19 07:51:42 +0000653 // If the RHS is +/- imm8, fold into addr mode.
654 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000655 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000656 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
657 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000658 if ((RHSC >= 0 && RHSC < 256) ||
659 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000660 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000661 if (Base.getOpcode() == ISD::FrameIndex) {
662 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
663 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
664 }
665
666 ARM_AM::AddrOpc AddSub = ARM_AM::add;
667 if (RHSC < 0) {
668 AddSub = ARM_AM::sub;
669 RHSC = - RHSC;
670 }
671 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000672 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000673 return true;
674 }
675 }
676 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000677
Evan Chenga8e29892007-01-19 07:51:42 +0000678 Base = N;
679 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000680 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000681 return true;
682}
683
Chris Lattner52a261b2010-09-21 20:31:19 +0000684bool ARMDAGToDAGISel::SelectAddrMode6(SDValue N, SDValue &Addr, SDValue &Align){
Bob Wilson8b024a52009-07-01 23:16:05 +0000685 Addr = N;
Jim Grosbach8a5ec862009-11-07 21:25:39 +0000686 // Default to no alignment.
687 Align = CurDAG->getTargetConstant(0, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000688 return true;
689}
690
Chris Lattner52a261b2010-09-21 20:31:19 +0000691bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000692 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000693 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
694 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000695 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000696 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000697 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000698 return true;
699 }
700 return false;
701}
702
Chris Lattner52a261b2010-09-21 20:31:19 +0000703bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000704 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000705 // FIXME dl should come from the parent load or store, not the address
Evan Chengc38f2bc2007-01-23 22:59:13 +0000706 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000707 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000708 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000709 return false;
710
711 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000712 return true;
713 }
714
Evan Chenga8e29892007-01-19 07:51:42 +0000715 Base = N.getOperand(0);
716 Offset = N.getOperand(1);
717 return true;
718}
719
Evan Cheng79d43262007-01-24 02:21:22 +0000720bool
Chris Lattner52a261b2010-09-21 20:31:19 +0000721ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000722 unsigned Scale, SDValue &Base,
723 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000724 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000725 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000726 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000727 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000728 if (N.getOpcode() == ARMISD::Wrapper &&
729 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
730 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000731 }
732
Evan Chenga8e29892007-01-19 07:51:42 +0000733 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000734 if (N.getOpcode() == ARMISD::Wrapper &&
735 !(Subtarget->useMovt() &&
736 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
737 Base = N.getOperand(0);
738 } else
739 Base = N;
740
Owen Anderson825b72b2009-08-11 20:47:22 +0000741 Offset = CurDAG->getRegister(0, MVT::i32);
742 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000743 return true;
744 }
745
Evan Chengad0e4652007-02-06 00:22:06 +0000746 // Thumb does not have [sp, r] address mode.
747 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
748 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
749 if ((LHSR && LHSR->getReg() == ARM::SP) ||
750 (RHSR && RHSR->getReg() == ARM::SP)) {
751 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000752 Offset = CurDAG->getRegister(0, MVT::i32);
753 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000754 return true;
755 }
756
Evan Chenga8e29892007-01-19 07:51:42 +0000757 // If the RHS is + imm5 * scale, fold into addr mode.
758 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000759 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000760 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
761 RHSC /= Scale;
762 if (RHSC >= 0 && RHSC < 32) {
763 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000764 Offset = CurDAG->getRegister(0, MVT::i32);
765 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000766 return true;
767 }
768 }
769 }
770
Evan Chengc38f2bc2007-01-23 22:59:13 +0000771 Base = N.getOperand(0);
772 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000773 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000774 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000775}
776
Chris Lattner52a261b2010-09-21 20:31:19 +0000777bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000778 SDValue &Base, SDValue &OffImm,
779 SDValue &Offset) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000780 return SelectThumbAddrModeRI5(N, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000781}
782
Chris Lattner52a261b2010-09-21 20:31:19 +0000783bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000784 SDValue &Base, SDValue &OffImm,
785 SDValue &Offset) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000786 return SelectThumbAddrModeRI5(N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000787}
788
Chris Lattner52a261b2010-09-21 20:31:19 +0000789bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000790 SDValue &Base, SDValue &OffImm,
791 SDValue &Offset) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000792 return SelectThumbAddrModeRI5(N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000793}
794
Chris Lattner52a261b2010-09-21 20:31:19 +0000795bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
796 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000797 if (N.getOpcode() == ISD::FrameIndex) {
798 int FI = cast<FrameIndexSDNode>(N)->getIndex();
799 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000800 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000801 return true;
802 }
Evan Cheng79d43262007-01-24 02:21:22 +0000803
Evan Chengad0e4652007-02-06 00:22:06 +0000804 if (N.getOpcode() != ISD::ADD)
805 return false;
806
807 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000808 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
809 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000810 // If the RHS is + imm8 * scale, fold into addr mode.
811 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000812 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000813 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
814 RHSC >>= 2;
815 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000816 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000817 if (Base.getOpcode() == ISD::FrameIndex) {
818 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
819 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
820 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000821 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000822 return true;
823 }
824 }
825 }
826 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000827
Evan Chenga8e29892007-01-19 07:51:42 +0000828 return false;
829}
830
Chris Lattner52a261b2010-09-21 20:31:19 +0000831bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000832 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000833 if (DisableShifterOp)
834 return false;
835
Evan Cheng9cb9e672009-06-27 02:26:13 +0000836 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
837
838 // Don't match base register only case. That is matched to a separate
839 // lower complexity pattern with explicit register operand.
840 if (ShOpcVal == ARM_AM::no_shift) return false;
841
842 BaseReg = N.getOperand(0);
843 unsigned ShImmVal = 0;
844 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
845 ShImmVal = RHS->getZExtValue() & 31;
846 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
847 return true;
848 }
849
850 return false;
851}
852
Chris Lattner52a261b2010-09-21 20:31:19 +0000853bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000854 SDValue &Base, SDValue &OffImm) {
855 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000856
Evan Cheng3a214252009-08-11 08:52:18 +0000857 // Base only.
858 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000859 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000860 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000861 int FI = cast<FrameIndexSDNode>(N)->getIndex();
862 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000863 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000864 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000865 } else if (N.getOpcode() == ARMISD::Wrapper &&
866 !(Subtarget->useMovt() &&
867 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000868 Base = N.getOperand(0);
869 if (Base.getOpcode() == ISD::TargetConstantPool)
870 return false; // We want to select t2LDRpci instead.
871 } else
872 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000873 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000874 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000875 }
Evan Cheng055b0312009-06-29 07:51:04 +0000876
877 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000878 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +0000879 // Let t2LDRi8 handle (R - imm8).
880 return false;
881
Evan Cheng055b0312009-06-29 07:51:04 +0000882 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000883 if (N.getOpcode() == ISD::SUB)
884 RHSC = -RHSC;
885
886 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +0000887 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +0000888 if (Base.getOpcode() == ISD::FrameIndex) {
889 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
890 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
891 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000892 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000893 return true;
894 }
895 }
896
Evan Cheng3a214252009-08-11 08:52:18 +0000897 // Base only.
898 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000899 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000900 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000901}
902
Chris Lattner52a261b2010-09-21 20:31:19 +0000903bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000904 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +0000905 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +0000906 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +0000907 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
908 int RHSC = (int)RHS->getSExtValue();
909 if (N.getOpcode() == ISD::SUB)
910 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +0000911
Evan Cheng3a214252009-08-11 08:52:18 +0000912 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
913 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +0000914 if (Base.getOpcode() == ISD::FrameIndex) {
915 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
916 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
917 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000918 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +0000919 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000920 }
Evan Cheng055b0312009-06-29 07:51:04 +0000921 }
922 }
923
924 return false;
925}
926
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000927bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000928 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000929 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +0000930 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
931 ? cast<LoadSDNode>(Op)->getAddressingMode()
932 : cast<StoreSDNode>(Op)->getAddressingMode();
933 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
934 int RHSC = (int)RHS->getZExtValue();
935 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +0000936 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +0000937 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
938 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000939 return true;
940 }
941 }
942
943 return false;
944}
945
Chris Lattner52a261b2010-09-21 20:31:19 +0000946bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000947 SDValue &Base,
948 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +0000949 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
950 if (N.getOpcode() != ISD::ADD)
951 return false;
Evan Cheng055b0312009-06-29 07:51:04 +0000952
Evan Cheng3a214252009-08-11 08:52:18 +0000953 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
954 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
955 int RHSC = (int)RHS->getZExtValue();
956 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
957 return false;
958 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +0000959 return false;
960 }
961
Evan Cheng055b0312009-06-29 07:51:04 +0000962 // Look for (R + R) or (R + (R << [1,2,3])).
963 unsigned ShAmt = 0;
964 Base = N.getOperand(0);
965 OffReg = N.getOperand(1);
966
967 // Swap if it is ((R << c) + R).
968 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
969 if (ShOpcVal != ARM_AM::lsl) {
970 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
971 if (ShOpcVal == ARM_AM::lsl)
972 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +0000973 }
974
Evan Cheng055b0312009-06-29 07:51:04 +0000975 if (ShOpcVal == ARM_AM::lsl) {
976 // Check to see if the RHS of the shift is a constant, if not, we can't fold
977 // it.
978 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
979 ShAmt = Sh->getZExtValue();
980 if (ShAmt >= 4) {
981 ShAmt = 0;
982 ShOpcVal = ARM_AM::no_shift;
983 } else
984 OffReg = OffReg.getOperand(0);
985 } else {
986 ShOpcVal = ARM_AM::no_shift;
987 }
David Goodwin7ecc8502009-07-15 15:50:19 +0000988 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000989
Owen Anderson825b72b2009-08-11 20:47:22 +0000990 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000991
992 return true;
993}
994
995//===--------------------------------------------------------------------===//
996
Evan Chengee568cf2007-07-05 07:15:27 +0000997/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +0000998static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000999 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001000}
1001
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001002SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1003 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001004 ISD::MemIndexedMode AM = LD->getAddressingMode();
1005 if (AM == ISD::UNINDEXED)
1006 return NULL;
1007
Owen Andersone50ed302009-08-10 22:56:29 +00001008 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001009 SDValue Offset, AMOpc;
1010 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1011 unsigned Opcode = 0;
1012 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +00001013 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001014 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001015 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
1016 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +00001017 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001018 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001019 Match = true;
1020 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1021 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1022 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001023 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001024 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001025 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001026 Match = true;
1027 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1028 }
1029 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001030 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001031 Match = true;
1032 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
1033 }
1034 }
1035 }
1036
1037 if (Match) {
1038 SDValue Chain = LD->getChain();
1039 SDValue Base = LD->getBasePtr();
1040 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001041 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001042 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001043 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +00001044 }
1045
1046 return NULL;
1047}
1048
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001049SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1050 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001051 ISD::MemIndexedMode AM = LD->getAddressingMode();
1052 if (AM == ISD::UNINDEXED)
1053 return NULL;
1054
Owen Andersone50ed302009-08-10 22:56:29 +00001055 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001056 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001057 SDValue Offset;
1058 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1059 unsigned Opcode = 0;
1060 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001061 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001062 switch (LoadedVT.getSimpleVT().SimpleTy) {
1063 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001064 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1065 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001066 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001067 if (isSExtLd)
1068 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1069 else
1070 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001071 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001072 case MVT::i8:
1073 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001074 if (isSExtLd)
1075 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1076 else
1077 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001078 break;
1079 default:
1080 return NULL;
1081 }
1082 Match = true;
1083 }
1084
1085 if (Match) {
1086 SDValue Chain = LD->getChain();
1087 SDValue Base = LD->getBasePtr();
1088 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001089 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001090 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001091 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001092 }
1093
1094 return NULL;
1095}
1096
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001097/// PairSRegs - Form a D register from a pair of S registers.
1098///
1099SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1100 DebugLoc dl = V0.getNode()->getDebugLoc();
1101 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1102 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001103 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1104 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001105}
1106
Evan Cheng603afbf2010-05-10 17:34:18 +00001107/// PairDRegs - Form a quad register from a pair of D registers.
1108///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001109SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1110 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001111 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1112 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001113 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1114 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001115}
1116
Evan Cheng7f687192010-05-14 00:21:45 +00001117/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001118///
1119SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1120 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001121 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1122 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001123 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1124 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1125}
1126
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001127/// QuadSRegs - Form 4 consecutive S registers.
1128///
1129SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1130 SDValue V2, SDValue V3) {
1131 DebugLoc dl = V0.getNode()->getDebugLoc();
1132 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1133 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1134 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1135 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
1136 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1137 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1138}
1139
Evan Cheng7f687192010-05-14 00:21:45 +00001140/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001141///
1142SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1143 SDValue V2, SDValue V3) {
1144 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001145 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1146 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1147 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1148 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001149 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1150 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1151}
1152
Evan Cheng8f6de382010-05-16 03:27:48 +00001153/// QuadQRegs - Form 4 consecutive Q registers.
1154///
1155SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1156 SDValue V2, SDValue V3) {
1157 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001158 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1159 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1160 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1161 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Evan Cheng8f6de382010-05-16 03:27:48 +00001162 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1163 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1164}
1165
Bob Wilson2a6e6162010-09-23 23:42:37 +00001166/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1167/// of a NEON VLD or VST instruction. The supported values depend on the
1168/// number of registers being loaded.
1169static unsigned GetVLDSTAlign(SDNode *N, unsigned NumVecs, bool is64BitVector) {
1170 unsigned NumRegs = NumVecs;
1171 if (!is64BitVector && NumVecs < 3)
1172 NumRegs *= 2;
1173
1174 unsigned Alignment = cast<MemIntrinsicSDNode>(N)->getAlignment();
1175 if (Alignment >= 32 && NumRegs == 4)
1176 return 32;
1177 if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1178 return 16;
1179 if (Alignment >= 8)
1180 return 8;
1181 return 0;
1182}
1183
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001184SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001185 unsigned *DOpcodes, unsigned *QOpcodes0,
1186 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001187 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001188 DebugLoc dl = N->getDebugLoc();
1189
Bob Wilson226036e2010-03-20 22:13:40 +00001190 SDValue MemAddr, Align;
Chris Lattner52a261b2010-09-21 20:31:19 +00001191 if (!SelectAddrMode6(N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001192 return NULL;
1193
1194 SDValue Chain = N->getOperand(0);
1195 EVT VT = N->getValueType(0);
1196 bool is64BitVector = VT.is64BitVector();
1197
Bob Wilson2a6e6162010-09-23 23:42:37 +00001198 unsigned Alignment = GetVLDSTAlign(N, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001199 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1200
Bob Wilson3e36f132009-10-14 17:28:52 +00001201 unsigned OpcodeIndex;
1202 switch (VT.getSimpleVT().SimpleTy) {
1203 default: llvm_unreachable("unhandled vld type");
1204 // Double-register operations:
1205 case MVT::v8i8: OpcodeIndex = 0; break;
1206 case MVT::v4i16: OpcodeIndex = 1; break;
1207 case MVT::v2f32:
1208 case MVT::v2i32: OpcodeIndex = 2; break;
1209 case MVT::v1i64: OpcodeIndex = 3; break;
1210 // Quad-register operations:
1211 case MVT::v16i8: OpcodeIndex = 0; break;
1212 case MVT::v8i16: OpcodeIndex = 1; break;
1213 case MVT::v4f32:
1214 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001215 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001216 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001217 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001218 }
1219
Bob Wilsonf5721912010-09-03 18:16:02 +00001220 EVT ResTy;
1221 if (NumVecs == 1)
1222 ResTy = VT;
1223 else {
1224 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1225 if (!is64BitVector)
1226 ResTyElts *= 2;
1227 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1228 }
1229
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001230 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001231 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilsonf5721912010-09-03 18:16:02 +00001232 SDValue SuperReg;
Bob Wilson3e36f132009-10-14 17:28:52 +00001233 if (is64BitVector) {
1234 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001235 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilsonf5721912010-09-03 18:16:02 +00001236 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
Bob Wilsonffde0802010-09-02 16:00:54 +00001237 if (NumVecs == 1)
Evan Chenge9e2ba02010-05-10 21:26:24 +00001238 return VLd;
1239
Bob Wilsonf5721912010-09-03 18:16:02 +00001240 SuperReg = SDValue(VLd, 0);
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001241 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
Evan Cheng5c6aba22010-05-14 18:54:59 +00001242 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001243 SDValue D = CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec,
Bob Wilsonffde0802010-09-02 16:00:54 +00001244 dl, VT, SuperReg);
Evan Cheng5c6aba22010-05-14 18:54:59 +00001245 ReplaceUses(SDValue(N, Vec), D);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001246 }
Bob Wilsonf5721912010-09-03 18:16:02 +00001247 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
Evan Chenge9e2ba02010-05-10 21:26:24 +00001248 return NULL;
Bob Wilson3e36f132009-10-14 17:28:52 +00001249 }
1250
Bob Wilson621f1952010-03-23 05:25:43 +00001251 if (NumVecs <= 2) {
1252 // Quad registers are directly supported for VLD1 and VLD2,
1253 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001254 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001255 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilsonffde0802010-09-02 16:00:54 +00001256 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
Bob Wilsonffde0802010-09-02 16:00:54 +00001257 if (NumVecs == 1)
1258 return VLd;
1259
Bob Wilsonf5721912010-09-03 18:16:02 +00001260 SuperReg = SDValue(VLd, 0);
Bob Wilsonffde0802010-09-02 16:00:54 +00001261 Chain = SDValue(VLd, 1);
1262
Bob Wilson3e36f132009-10-14 17:28:52 +00001263 } else {
1264 // Otherwise, quad registers are loaded with two separate instructions,
1265 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001266 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001267
Bob Wilson24f995d2009-10-14 18:32:29 +00001268 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001269 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsonf5721912010-09-03 18:16:02 +00001270 SDValue ImplDef =
1271 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1272 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
1273 SDNode *VLdA =
1274 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsA, 7);
1275 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001276
Bob Wilson24f995d2009-10-14 18:32:29 +00001277 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001278 Opc = QOpcodes1[OpcodeIndex];
Bob Wilsonf5721912010-09-03 18:16:02 +00001279 const SDValue OpsB[] = { SDValue(VLdA, 1), Align, Reg0, SDValue(VLdA, 0),
1280 Pred, Reg0, Chain };
1281 SDNode *VLdB =
1282 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsB, 7);
1283 SuperReg = SDValue(VLdB, 0);
1284 Chain = SDValue(VLdB, 2);
1285 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001286
Bob Wilsonf5721912010-09-03 18:16:02 +00001287 // Extract out the Q registers.
1288 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1289 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1290 SDValue Q = CurDAG->getTargetExtractSubreg(ARM::qsub_0+Vec,
1291 dl, VT, SuperReg);
1292 ReplaceUses(SDValue(N, Vec), Q);
Bob Wilson3e36f132009-10-14 17:28:52 +00001293 }
1294 ReplaceUses(SDValue(N, NumVecs), Chain);
1295 return NULL;
1296}
1297
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001298SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001299 unsigned *DOpcodes, unsigned *QOpcodes0,
1300 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001301 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001302 DebugLoc dl = N->getDebugLoc();
1303
Bob Wilson226036e2010-03-20 22:13:40 +00001304 SDValue MemAddr, Align;
Chris Lattner52a261b2010-09-21 20:31:19 +00001305 if (!SelectAddrMode6(N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001306 return NULL;
1307
1308 SDValue Chain = N->getOperand(0);
1309 EVT VT = N->getOperand(3).getValueType();
1310 bool is64BitVector = VT.is64BitVector();
1311
Bob Wilson2a6e6162010-09-23 23:42:37 +00001312 unsigned Alignment = GetVLDSTAlign(N, NumVecs, is64BitVector);
1313 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1314
Bob Wilson24f995d2009-10-14 18:32:29 +00001315 unsigned OpcodeIndex;
1316 switch (VT.getSimpleVT().SimpleTy) {
1317 default: llvm_unreachable("unhandled vst type");
1318 // Double-register operations:
1319 case MVT::v8i8: OpcodeIndex = 0; break;
1320 case MVT::v4i16: OpcodeIndex = 1; break;
1321 case MVT::v2f32:
1322 case MVT::v2i32: OpcodeIndex = 2; break;
1323 case MVT::v1i64: OpcodeIndex = 3; break;
1324 // Quad-register operations:
1325 case MVT::v16i8: OpcodeIndex = 0; break;
1326 case MVT::v8i16: OpcodeIndex = 1; break;
1327 case MVT::v4f32:
1328 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001329 case MVT::v2i64: OpcodeIndex = 3;
1330 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1331 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001332 }
1333
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001334 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001335 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001336
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001337 SmallVector<SDValue, 7> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001338 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001339 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001340
1341 if (is64BitVector) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001342 if (NumVecs == 1) {
1343 Ops.push_back(N->getOperand(3));
1344 } else {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001345 SDValue RegSeq;
1346 SDValue V0 = N->getOperand(0+3);
1347 SDValue V1 = N->getOperand(1+3);
1348
1349 // Form a REG_SEQUENCE to force register allocation.
1350 if (NumVecs == 2)
1351 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1352 else {
1353 SDValue V2 = N->getOperand(2+3);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001354 // If it's a vld3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001355 // an undef.
1356 SDValue V3 = (NumVecs == 3)
1357 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1358 : N->getOperand(3+3);
1359 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1360 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001361 Ops.push_back(RegSeq);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001362 }
Evan Chengac0869d2009-11-21 06:21:52 +00001363 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001364 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001365 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001366 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001367 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001368 }
1369
Bob Wilson11d98992010-03-23 06:20:33 +00001370 if (NumVecs <= 2) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001371 // Quad registers are directly supported for VST1 and VST2.
Bob Wilson24f995d2009-10-14 18:32:29 +00001372 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001373 if (NumVecs == 1) {
1374 Ops.push_back(N->getOperand(3));
1375 } else {
1376 // Form a QQ register.
Evan Cheng603afbf2010-05-10 17:34:18 +00001377 SDValue Q0 = N->getOperand(3);
1378 SDValue Q1 = N->getOperand(4);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001379 Ops.push_back(SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0));
Bob Wilson24f995d2009-10-14 18:32:29 +00001380 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001381 Ops.push_back(Pred);
1382 Ops.push_back(Reg0); // predicate register
1383 Ops.push_back(Chain);
1384 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001385 }
1386
1387 // Otherwise, quad registers are stored with two separate instructions,
1388 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001389
Bob Wilson07f6e802010-06-16 21:34:01 +00001390 // Form the QQQQ REG_SEQUENCE.
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001391 SDValue V0 = N->getOperand(0+3);
1392 SDValue V1 = N->getOperand(1+3);
1393 SDValue V2 = N->getOperand(2+3);
1394 SDValue V3 = (NumVecs == 3)
1395 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1396 : N->getOperand(3+3);
1397 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001398
1399 // Store the even D registers.
Bob Wilson07f6e802010-06-16 21:34:01 +00001400 Ops.push_back(Reg0); // post-access address offset
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001401 Ops.push_back(RegSeq);
Bob Wilson07f6e802010-06-16 21:34:01 +00001402 Ops.push_back(Pred);
1403 Ops.push_back(Reg0); // predicate register
1404 Ops.push_back(Chain);
1405 unsigned Opc = QOpcodes0[OpcodeIndex];
1406 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001407 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001408 Chain = SDValue(VStA, 1);
1409
1410 // Store the odd D registers.
1411 Ops[0] = SDValue(VStA, 0); // MemAddr
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001412 Ops[6] = Chain;
Bob Wilson07f6e802010-06-16 21:34:01 +00001413 Opc = QOpcodes1[OpcodeIndex];
1414 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001415 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001416 Chain = SDValue(VStB, 1);
1417 ReplaceUses(SDValue(N, 0), Chain);
1418 return NULL;
Bob Wilson24f995d2009-10-14 18:32:29 +00001419}
1420
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001421SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001422 unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001423 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001424 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001425 DebugLoc dl = N->getDebugLoc();
1426
Bob Wilson226036e2010-03-20 22:13:40 +00001427 SDValue MemAddr, Align;
Chris Lattner52a261b2010-09-21 20:31:19 +00001428 if (!SelectAddrMode6(N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001429 return NULL;
1430
1431 SDValue Chain = N->getOperand(0);
1432 unsigned Lane =
1433 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001434 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001435 bool is64BitVector = VT.is64BitVector();
1436
Bob Wilson3454ed92010-10-19 00:16:32 +00001437 if (NumVecs != 3) {
1438 unsigned Alignment = cast<MemIntrinsicSDNode>(N)->getAlignment();
1439 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1440 if (Alignment > NumBytes)
1441 Alignment = NumBytes;
1442 // Alignment must be a power of two; make sure of that.
1443 Alignment = (Alignment & -Alignment);
1444 if (Alignment > 1)
1445 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1446 }
1447
Bob Wilsona7c397c2009-10-14 16:19:03 +00001448 unsigned OpcodeIndex;
1449 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001450 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001451 // Double-register operations:
1452 case MVT::v8i8: OpcodeIndex = 0; break;
1453 case MVT::v4i16: OpcodeIndex = 1; break;
1454 case MVT::v2f32:
1455 case MVT::v2i32: OpcodeIndex = 2; break;
1456 // Quad-register operations:
1457 case MVT::v8i16: OpcodeIndex = 0; break;
1458 case MVT::v4f32:
1459 case MVT::v4i32: OpcodeIndex = 1; break;
1460 }
1461
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001462 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001463 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001464
Bob Wilson8466fa12010-09-13 23:01:35 +00001465 SmallVector<SDValue, 7> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001466 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001467 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001468
Jim Grosbach3ab56582010-10-21 19:38:40 +00001469 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
Eric Christopher23da0b22010-09-14 08:31:25 +00001470 QOpcodes[OpcodeIndex]);
Bob Wilson07f6e802010-06-16 21:34:01 +00001471
Bob Wilson8466fa12010-09-13 23:01:35 +00001472 SDValue SuperReg;
1473 SDValue V0 = N->getOperand(0+3);
1474 SDValue V1 = N->getOperand(1+3);
1475 if (NumVecs == 2) {
1476 if (is64BitVector)
1477 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1478 else
1479 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001480 } else {
Bob Wilson8466fa12010-09-13 23:01:35 +00001481 SDValue V2 = N->getOperand(2+3);
1482 SDValue V3 = (NumVecs == 3)
1483 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1484 : N->getOperand(3+3);
1485 if (is64BitVector)
1486 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1487 else
1488 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001489 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001490 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001491 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001492 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001493 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001494 Ops.push_back(Chain);
1495
Bob Wilson96493442009-10-14 16:46:45 +00001496 if (!IsLoad)
Bob Wilson8466fa12010-09-13 23:01:35 +00001497 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 7);
Bob Wilson96493442009-10-14 16:46:45 +00001498
Bob Wilson8466fa12010-09-13 23:01:35 +00001499 EVT ResTy;
1500 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1501 if (!is64BitVector)
1502 ResTyElts *= 2;
1503 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001504
Bob Wilson8466fa12010-09-13 23:01:35 +00001505 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other,
1506 Ops.data(), 7);
1507 SuperReg = SDValue(VLdLn, 0);
1508 Chain = SDValue(VLdLn, 1);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001509
Bob Wilson8466fa12010-09-13 23:01:35 +00001510 // Extract the subregisters.
Bob Wilson07f6e802010-06-16 21:34:01 +00001511 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1512 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1513 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
1514 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1515 ReplaceUses(SDValue(N, Vec),
Bob Wilson8466fa12010-09-13 23:01:35 +00001516 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
1517 ReplaceUses(SDValue(N, NumVecs), Chain);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001518 return NULL;
1519}
1520
Bob Wilson78dfbc32010-07-07 00:08:54 +00001521SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1522 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001523 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1524 DebugLoc dl = N->getDebugLoc();
1525 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001526 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001527
1528 // Form a REG_SEQUENCE to force register allocation.
1529 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001530 SDValue V0 = N->getOperand(FirstTblReg + 0);
1531 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001532 if (NumVecs == 2)
1533 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1534 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001535 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001536 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00001537 // an undef.
1538 SDValue V3 = (NumVecs == 3)
1539 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001540 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001541 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1542 }
1543
Bob Wilson78dfbc32010-07-07 00:08:54 +00001544 SmallVector<SDValue, 6> Ops;
1545 if (IsExt)
1546 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00001547 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001548 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001549 Ops.push_back(getAL(CurDAG)); // predicate
1550 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001551 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001552}
1553
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001554SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001555 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001556 if (!Subtarget->hasV6T2Ops())
1557 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001558
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001559 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1560 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1561
1562
1563 // For unsigned extracts, check for a shift right and mask
1564 unsigned And_imm = 0;
1565 if (N->getOpcode() == ISD::AND) {
1566 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1567
1568 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1569 if (And_imm & (And_imm + 1))
1570 return NULL;
1571
1572 unsigned Srl_imm = 0;
1573 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1574 Srl_imm)) {
1575 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1576
1577 unsigned Width = CountTrailingOnes_32(And_imm);
1578 unsigned LSB = Srl_imm;
1579 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1580 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1581 CurDAG->getTargetConstant(LSB, MVT::i32),
1582 CurDAG->getTargetConstant(Width, MVT::i32),
1583 getAL(CurDAG), Reg0 };
1584 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1585 }
1586 }
1587 return NULL;
1588 }
1589
1590 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001591 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001592 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001593 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1594 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001595 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001596 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1597 unsigned Width = 32 - Srl_imm;
1598 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001599 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001600 return NULL;
1601 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001602 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001603 CurDAG->getTargetConstant(LSB, MVT::i32),
1604 CurDAG->getTargetConstant(Width, MVT::i32),
1605 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001606 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001607 }
1608 }
1609 return NULL;
1610}
1611
Evan Cheng9ef48352009-11-20 00:54:03 +00001612SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001613SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001614 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1615 SDValue CPTmp0;
1616 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00001617 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001618 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1619 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1620 unsigned Opc = 0;
1621 switch (SOShOp) {
1622 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1623 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1624 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1625 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1626 default:
1627 llvm_unreachable("Unknown so_reg opcode!");
1628 break;
1629 }
1630 SDValue SOShImm =
1631 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1632 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1633 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001634 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001635 }
1636 return 0;
1637}
1638
1639SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001640SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001641 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1642 SDValue CPTmp0;
1643 SDValue CPTmp1;
1644 SDValue CPTmp2;
Chris Lattner52a261b2010-09-21 20:31:19 +00001645 if (SelectShifterOperandReg(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001646 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1647 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001648 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001649 }
1650 return 0;
1651}
1652
1653SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00001654SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001655 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1656 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1657 if (!T)
1658 return 0;
1659
Jim Grosbacha4257162010-10-07 00:53:56 +00001660 unsigned TrueImm = T->getZExtValue();
1661 bool isSoImm = Pred_t2_so_imm(TrueVal.getNode());
1662 if (isSoImm || TrueImm <= 0xffff) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001663 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1664 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1665 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Jim Grosbacha4257162010-10-07 00:53:56 +00001666 return CurDAG->SelectNodeTo(N, (isSoImm ? ARM::t2MOVCCi : ARM::t2MOVCCi16),
1667 MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00001668 }
1669 return 0;
1670}
1671
1672SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001673SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001674 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1675 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1676 if (!T)
1677 return 0;
1678
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001679 unsigned TrueImm = T->getZExtValue();
1680 bool isSoImm = Pred_so_imm(TrueVal.getNode());
1681 if (isSoImm || (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff)) {
1682 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00001683 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1684 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001685 return CurDAG->SelectNodeTo(N, (isSoImm ? ARM::MOVCCi : ARM::MOVCCi16),
1686 MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00001687 }
1688 return 0;
1689}
1690
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001691SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1692 EVT VT = N->getValueType(0);
1693 SDValue FalseVal = N->getOperand(0);
1694 SDValue TrueVal = N->getOperand(1);
1695 SDValue CC = N->getOperand(2);
1696 SDValue CCR = N->getOperand(3);
1697 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001698 assert(CC.getOpcode() == ISD::Constant);
1699 assert(CCR.getOpcode() == ISD::Register);
1700 ARMCC::CondCodes CCVal =
1701 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001702
1703 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1704 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1705 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1706 // Pattern complexity = 18 cost = 1 size = 0
1707 SDValue CPTmp0;
1708 SDValue CPTmp1;
1709 SDValue CPTmp2;
1710 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001711 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001712 CCVal, CCR, InFlag);
1713 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001714 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001715 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1716 if (Res)
1717 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001718 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001719 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001720 CCVal, CCR, InFlag);
1721 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001722 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001723 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1724 if (Res)
1725 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001726 }
1727
1728 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00001729 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00001730 // (imm:i32):$cc)
1731 // Emits: (MOVCCi:i32 GPR:i32:$false,
1732 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1733 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001734 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00001735 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001736 CCVal, CCR, InFlag);
1737 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00001738 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001739 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1740 if (Res)
1741 return Res;
1742 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001743 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001744 CCVal, CCR, InFlag);
1745 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001746 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001747 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1748 if (Res)
1749 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001750 }
1751 }
1752
1753 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1754 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1755 // Pattern complexity = 6 cost = 1 size = 0
1756 //
1757 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1758 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1759 // Pattern complexity = 6 cost = 11 size = 0
1760 //
1761 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001762 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1763 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001764 unsigned Opc = 0;
1765 switch (VT.getSimpleVT().SimpleTy) {
1766 default: assert(false && "Illegal conditional move type!");
1767 break;
1768 case MVT::i32:
1769 Opc = Subtarget->isThumb()
1770 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1771 : ARM::MOVCCr;
1772 break;
1773 case MVT::f32:
1774 Opc = ARM::VMOVScc;
1775 break;
1776 case MVT::f64:
1777 Opc = ARM::VMOVDcc;
1778 break;
1779 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001780 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001781}
1782
Evan Chengde8aa4e2010-05-05 18:28:36 +00001783SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
1784 // The only time a CONCAT_VECTORS operation can have legal types is when
1785 // two 64-bit vectors are concatenated to a 128-bit vector.
1786 EVT VT = N->getValueType(0);
1787 if (!VT.is128BitVector() || N->getNumOperands() != 2)
1788 llvm_unreachable("unexpected CONCAT_VECTORS");
1789 DebugLoc dl = N->getDebugLoc();
1790 SDValue V0 = N->getOperand(0);
1791 SDValue V1 = N->getOperand(1);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001792 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1793 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +00001794 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1795 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1796}
1797
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001798SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001799 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001800
Dan Gohmane8be6c62008-07-17 19:10:17 +00001801 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001802 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001803
1804 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001805 default: break;
1806 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001807 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001808 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001809 if (Subtarget->hasThumb2())
1810 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1811 // be done with MOV + MOVT, at worst.
1812 UseCP = 0;
1813 else {
1814 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001815 UseCP = (Val > 255 && // MOV
1816 ~Val > 255 && // MOV + MVN
1817 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001818 } else
1819 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1820 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1821 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1822 }
1823
Evan Chenga8e29892007-01-19 07:51:42 +00001824 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001825 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001826 CurDAG->getTargetConstantPool(ConstantInt::get(
1827 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001828 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001829
1830 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001831 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001832 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001833 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001834 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001835 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1836 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001837 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001838 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001839 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001840 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001841 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001842 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001843 CurDAG->getEntryNode()
1844 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001845 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00001846 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00001847 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001848 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001849 return NULL;
1850 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001851
Evan Chenga8e29892007-01-19 07:51:42 +00001852 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001853 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001854 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001855 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001856 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001857 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001858 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001859 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001860 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1861 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001862 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001863 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1864 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001865 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1866 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1867 CurDAG->getRegister(0, MVT::i32) };
1868 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001869 }
Evan Chenga8e29892007-01-19 07:51:42 +00001870 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001871 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001872 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001873 return I;
1874 break;
1875 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001876 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001877 return I;
1878 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001879 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001880 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001881 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001882 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001883 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001884 if (!RHSV) break;
1885 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001886 unsigned ShImm = Log2_32(RHSV-1);
1887 if (ShImm >= 32)
1888 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001889 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001890 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001891 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1892 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001893 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001894 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001895 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001896 } else {
1897 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001898 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001899 }
Evan Chenga8e29892007-01-19 07:51:42 +00001900 }
1901 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001902 unsigned ShImm = Log2_32(RHSV+1);
1903 if (ShImm >= 32)
1904 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001905 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001906 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001907 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1908 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001909 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00001910 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1911 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001912 } else {
1913 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001914 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001915 }
Evan Chenga8e29892007-01-19 07:51:42 +00001916 }
1917 }
1918 break;
Evan Cheng20956592009-10-21 08:15:52 +00001919 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001920 // Check for unsigned bitfield extract
1921 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1922 return I;
1923
Evan Cheng20956592009-10-21 08:15:52 +00001924 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1925 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1926 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1927 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1928 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001929 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001930 if (VT != MVT::i32)
1931 break;
1932 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1933 ? ARM::t2MOVTi16
1934 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1935 if (!Opc)
1936 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001937 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001938 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1939 if (!N1C)
1940 break;
1941 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1942 SDValue N2 = N0.getOperand(1);
1943 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1944 if (!N2C)
1945 break;
1946 unsigned N1CVal = N1C->getZExtValue();
1947 unsigned N2CVal = N2C->getZExtValue();
1948 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1949 (N1CVal & 0xffffU) == 0xffffU &&
1950 (N2CVal & 0xffffU) == 0x0U) {
1951 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1952 MVT::i32);
1953 SDValue Ops[] = { N0.getOperand(0), Imm16,
1954 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1955 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
1956 }
1957 }
1958 break;
1959 }
Jim Grosbache5165492009-11-09 00:11:35 +00001960 case ARMISD::VMOVRRD:
1961 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001962 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00001963 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00001964 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001965 if (Subtarget->isThumb1Only())
1966 break;
1967 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001968 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001969 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1970 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00001971 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001972 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001973 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001974 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1975 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001976 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001977 }
Evan Chengee568cf2007-07-05 07:15:27 +00001978 }
Dan Gohman525178c2007-10-08 18:33:35 +00001979 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001980 if (Subtarget->isThumb1Only())
1981 break;
1982 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001983 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001984 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00001985 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001986 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001987 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001988 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1989 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001990 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001991 }
Evan Chengee568cf2007-07-05 07:15:27 +00001992 }
Evan Chenga8e29892007-01-19 07:51:42 +00001993 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00001994 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001995 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001996 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001997 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001998 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001999 if (ResNode)
2000 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002001 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002002 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002003 }
Evan Chengee568cf2007-07-05 07:15:27 +00002004 case ARMISD::BRCOND: {
2005 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2006 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2007 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002008
Evan Chengee568cf2007-07-05 07:15:27 +00002009 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2010 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2011 // Pattern complexity = 6 cost = 1 size = 0
2012
David Goodwin5e47a9a2009-06-30 18:04:13 +00002013 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2014 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2015 // Pattern complexity = 6 cost = 1 size = 0
2016
Jim Grosbach764ab522009-08-11 15:33:49 +00002017 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002018 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002019 SDValue Chain = N->getOperand(0);
2020 SDValue N1 = N->getOperand(1);
2021 SDValue N2 = N->getOperand(2);
2022 SDValue N3 = N->getOperand(3);
2023 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002024 assert(N1.getOpcode() == ISD::BasicBlock);
2025 assert(N2.getOpcode() == ISD::Constant);
2026 assert(N3.getOpcode() == ISD::Register);
2027
Dan Gohman475871a2008-07-27 21:46:04 +00002028 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002029 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002030 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002031 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002032 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
2033 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002034 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002035 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002036 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002037 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002038 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002039 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002040 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002041 return NULL;
2042 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002043 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002044 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002045 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002046 EVT VT = N->getValueType(0);
2047 SDValue N0 = N->getOperand(0);
2048 SDValue N1 = N->getOperand(1);
2049 SDValue N2 = N->getOperand(2);
2050 SDValue N3 = N->getOperand(3);
2051 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002052 assert(N2.getOpcode() == ISD::Constant);
2053 assert(N3.getOpcode() == ISD::Register);
2054
Dan Gohman475871a2008-07-27 21:46:04 +00002055 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002056 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002057 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002058 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002059 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002060 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002061 default: assert(false && "Illegal conditional move type!");
2062 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002063 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002064 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002065 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002066 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002067 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002068 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002069 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002070 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002071 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002072
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002073 case ARMISD::VZIP: {
2074 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002075 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002076 switch (VT.getSimpleVT().SimpleTy) {
2077 default: return NULL;
2078 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2079 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2080 case MVT::v2f32:
2081 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2082 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2083 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2084 case MVT::v4f32:
2085 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2086 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002087 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002088 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2089 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2090 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002091 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002092 case ARMISD::VUZP: {
2093 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002094 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002095 switch (VT.getSimpleVT().SimpleTy) {
2096 default: return NULL;
2097 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2098 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2099 case MVT::v2f32:
2100 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2101 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2102 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2103 case MVT::v4f32:
2104 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2105 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002106 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002107 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2108 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2109 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002110 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002111 case ARMISD::VTRN: {
2112 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002113 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002114 switch (VT.getSimpleVT().SimpleTy) {
2115 default: return NULL;
2116 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2117 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2118 case MVT::v2f32:
2119 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2120 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2121 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2122 case MVT::v4f32:
2123 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2124 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002125 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002126 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2127 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2128 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002129 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002130 case ARMISD::BUILD_VECTOR: {
2131 EVT VecVT = N->getValueType(0);
2132 EVT EltVT = VecVT.getVectorElementType();
2133 unsigned NumElts = VecVT.getVectorNumElements();
2134 if (EltVT.getSimpleVT() == MVT::f64) {
2135 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2136 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2137 }
2138 assert(EltVT.getSimpleVT() == MVT::f32 &&
2139 "unexpected type for BUILD_VECTOR");
2140 if (NumElts == 2)
2141 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2142 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2143 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2144 N->getOperand(2), N->getOperand(3));
2145 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002146
2147 case ISD::INTRINSIC_VOID:
2148 case ISD::INTRINSIC_W_CHAIN: {
2149 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002150 switch (IntNo) {
2151 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002152 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002153
Bob Wilson621f1952010-03-23 05:25:43 +00002154 case Intrinsic::arm_neon_vld1: {
2155 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2156 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002157 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2158 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson621f1952010-03-23 05:25:43 +00002159 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2160 }
2161
Bob Wilson31fb12f2009-08-26 17:39:53 +00002162 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002163 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2164 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2165 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2166 ARM::VLD2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002167 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002168 }
2169
2170 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002171 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2172 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2173 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2174 ARM::VLD3q16Pseudo_UPD,
2175 ARM::VLD3q32Pseudo_UPD };
2176 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2177 ARM::VLD3q16oddPseudo_UPD,
2178 ARM::VLD3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002179 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002180 }
2181
2182 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002183 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2184 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2185 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2186 ARM::VLD4q16Pseudo_UPD,
2187 ARM::VLD4q32Pseudo_UPD };
2188 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2189 ARM::VLD4q16oddPseudo_UPD,
2190 ARM::VLD4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002191 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002192 }
2193
Bob Wilson243fcc52009-09-01 04:26:28 +00002194 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002195 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2196 ARM::VLD2LNd32Pseudo };
2197 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
2198 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002199 }
2200
2201 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002202 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2203 ARM::VLD3LNd32Pseudo };
2204 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
2205 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002206 }
2207
2208 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002209 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2210 ARM::VLD4LNd32Pseudo };
2211 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
2212 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002213 }
2214
Bob Wilson11d98992010-03-23 06:20:33 +00002215 case Intrinsic::arm_neon_vst1: {
2216 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2217 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002218 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2219 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson11d98992010-03-23 06:20:33 +00002220 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2221 }
2222
Bob Wilson31fb12f2009-08-26 17:39:53 +00002223 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002224 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2225 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2226 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2227 ARM::VST2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002228 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002229 }
2230
2231 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002232 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2233 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2234 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2235 ARM::VST3q16Pseudo_UPD,
2236 ARM::VST3q32Pseudo_UPD };
2237 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2238 ARM::VST3q16oddPseudo_UPD,
2239 ARM::VST3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002240 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002241 }
2242
2243 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002244 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002245 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002246 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2247 ARM::VST4q16Pseudo_UPD,
2248 ARM::VST4q32Pseudo_UPD };
2249 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2250 ARM::VST4q16oddPseudo_UPD,
2251 ARM::VST4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002252 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002253 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002254
2255 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002256 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2257 ARM::VST2LNd32Pseudo };
2258 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
2259 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002260 }
2261
2262 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002263 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2264 ARM::VST3LNd32Pseudo };
2265 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
2266 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002267 }
2268
2269 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002270 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2271 ARM::VST4LNd32Pseudo };
2272 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
2273 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002274 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002275 }
Bob Wilson429009b2010-05-06 16:05:26 +00002276 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002277 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002278
Bob Wilsond491d6e2010-07-06 23:36:25 +00002279 case ISD::INTRINSIC_WO_CHAIN: {
2280 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2281 switch (IntNo) {
2282 default:
2283 break;
2284
2285 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002286 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002287 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002288 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002289 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002290 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002291
2292 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002293 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002294 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002295 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002296 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002297 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002298 }
2299 break;
2300 }
2301
Bob Wilson429009b2010-05-06 16:05:26 +00002302 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002303 return SelectConcatVector(N);
2304 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002305
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002306 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002307}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002308
Bob Wilson224c2442009-05-19 05:53:42 +00002309bool ARMDAGToDAGISel::
2310SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2311 std::vector<SDValue> &OutOps) {
2312 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002313 // Require the address to be in a register. That is safe for all ARM
2314 // variants and it is hard to do anything much smarter without knowing
2315 // how the operand is used.
2316 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002317 return false;
2318}
2319
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002320/// createARMISelDag - This pass converts a legalized DAG into a
2321/// ARM-specific DAG, ready for instruction scheduling.
2322///
Bob Wilson522ce972009-09-28 14:30:20 +00002323FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2324 CodeGenOpt::Level OptLevel) {
2325 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002326}