blob: aa65a48bcc422ba03c0f7f1aa0c8f3ebf47eee06 [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 Grosbach82891622010-09-29 19:03:54 +000083 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
84 SDValue &Offset, SDValue &Opc);
85 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
86 SDValue &Opc) {
87 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
88 }
89
90 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
91 SDValue &Opc) {
92 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
93 }
94
95 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
96 SDValue &Opc) {
97 SelectAddrMode2Worker(N, Base, Offset, Opc);
98 // This always matches one way or another.
99 return true;
100 }
101
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000102 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000103 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000104 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000105 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000106 bool SelectAddrMode3Offset(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 SelectAddrMode4(SDValue N, SDValue &Addr, SDValue &Mode);
109 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000110 SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000111 bool SelectAddrMode6(SDValue N, SDValue &Addr, SDValue &Align);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000112
Chris Lattner52a261b2010-09-21 20:31:19 +0000113 bool SelectAddrModePC(SDValue N, SDValue &Offset,
Bob Wilson8b024a52009-07-01 23:16:05 +0000114 SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +0000115
Chris Lattner52a261b2010-09-21 20:31:19 +0000116 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
117 bool SelectThumbAddrModeRI5(SDValue N, unsigned Scale,
Dan Gohman475871a2008-07-27 21:46:04 +0000118 SDValue &Base, SDValue &OffImm,
119 SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000120 bool SelectThumbAddrModeS1(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000121 SDValue &OffImm, SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000122 bool SelectThumbAddrModeS2(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000123 SDValue &OffImm, SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000124 bool SelectThumbAddrModeS4(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 SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000127
Chris Lattner52a261b2010-09-21 20:31:19 +0000128 bool SelectT2ShifterOperandReg(SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000129 SDValue &BaseReg, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000130 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
131 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000132 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000133 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000134 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000135 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000136 SDValue &OffReg, SDValue &ShImm);
137
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000138 inline bool Pred_so_imm(SDNode *inN) const {
139 ConstantSDNode *N = cast<ConstantSDNode>(inN);
140 return ARM_AM::getSOImmVal(N->getZExtValue()) != -1;
141 }
142
143 inline bool Pred_t2_so_imm(SDNode *inN) const {
144 ConstantSDNode *N = cast<ConstantSDNode>(inN);
145 return ARM_AM::getT2SOImmVal(N->getZExtValue()) != -1;
146 }
147
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000148 // Include the pieces autogenerated from the target description.
149#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000150
151private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000152 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
153 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000154 SDNode *SelectARMIndexedLoad(SDNode *N);
155 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000156
Bob Wilson621f1952010-03-23 05:25:43 +0000157 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
158 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000159 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000160 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000161 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000162 unsigned *QOpcodes0, unsigned *QOpcodes1);
163
Bob Wilson24f995d2009-10-14 18:32:29 +0000164 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000165 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000166 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000167 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000168 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000169 unsigned *QOpcodes0, unsigned *QOpcodes1);
170
Bob Wilson96493442009-10-14 16:46:45 +0000171 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000172 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson8466fa12010-09-13 23:01:35 +0000173 /// load/store of D registers and Q registers.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000174 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
Bob Wilson8466fa12010-09-13 23:01:35 +0000175 unsigned *DOpcodes, unsigned *QOpcodes);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000176
Bob Wilson78dfbc32010-07-07 00:08:54 +0000177 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
178 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
179 /// generated to force the table registers to be consecutive.
180 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000181
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000182 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000183 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000184
Evan Cheng07ba9062009-11-19 21:45:22 +0000185 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000186 SDNode *SelectCMOVOp(SDNode *N);
187 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000188 ARMCC::CondCodes CCVal, SDValue CCR,
189 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000190 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000191 ARMCC::CondCodes CCVal, SDValue CCR,
192 SDValue InFlag);
Jim Grosbacha4257162010-10-07 00:53:56 +0000193 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000194 ARMCC::CondCodes CCVal, SDValue CCR,
195 SDValue InFlag);
Jim Grosbach3bbdcea2010-10-07 00:42:42 +0000196 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000197 ARMCC::CondCodes CCVal, SDValue CCR,
198 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000199
Evan Chengde8aa4e2010-05-05 18:28:36 +0000200 SDNode *SelectConcatVector(SDNode *N);
201
Evan Chengaf4550f2009-07-02 01:23:32 +0000202 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
203 /// inline asm expressions.
204 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
205 char ConstraintCode,
206 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000207
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000208 // Form pairs of consecutive S, D, or Q registers.
209 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000210 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000211 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
212
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000213 // Form sequences of 4 consecutive S, D, or Q registers.
214 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000215 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000216 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000217};
Evan Chenga8e29892007-01-19 07:51:42 +0000218}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000219
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000220/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
221/// operand. If so Imm will receive the 32-bit value.
222static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
223 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
224 Imm = cast<ConstantSDNode>(N)->getZExtValue();
225 return true;
226 }
227 return false;
228}
229
230// isInt32Immediate - This method tests to see if a constant operand.
231// If so Imm will receive the 32 bit value.
232static bool isInt32Immediate(SDValue N, unsigned &Imm) {
233 return isInt32Immediate(N.getNode(), Imm);
234}
235
236// isOpcWithIntImmediate - This method tests to see if the node is a specific
237// opcode and that it has a immediate integer right operand.
238// If so Imm will receive the 32 bit value.
239static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
240 return N->getOpcode() == Opc &&
241 isInt32Immediate(N->getOperand(1).getNode(), Imm);
242}
243
244
Chris Lattner52a261b2010-09-21 20:31:19 +0000245bool ARMDAGToDAGISel::SelectShifterOperandReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000246 SDValue &BaseReg,
247 SDValue &ShReg,
248 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000249 if (DisableShifterOp)
250 return false;
251
Evan Cheng055b0312009-06-29 07:51:04 +0000252 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
253
254 // Don't match base register only case. That is matched to a separate
255 // lower complexity pattern with explicit register operand.
256 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000257
Evan Cheng055b0312009-06-29 07:51:04 +0000258 BaseReg = N.getOperand(0);
259 unsigned ShImmVal = 0;
260 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000261 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000262 ShImmVal = RHS->getZExtValue() & 31;
263 } else {
264 ShReg = N.getOperand(1);
265 }
266 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000267 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000268 return true;
269}
270
Jim Grosbach82891622010-09-29 19:03:54 +0000271AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
272 SDValue &Base,
273 SDValue &Offset,
274 SDValue &Opc) {
Evan Chenga13fd102007-03-13 21:05:54 +0000275 if (N.getOpcode() == ISD::MUL) {
276 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
277 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000278 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000279 if (RHSC & 1) {
280 RHSC = RHSC & ~1;
281 ARM_AM::AddrOpc AddSub = ARM_AM::add;
282 if (RHSC < 0) {
283 AddSub = ARM_AM::sub;
284 RHSC = - RHSC;
285 }
286 if (isPowerOf2_32(RHSC)) {
287 unsigned ShAmt = Log2_32(RHSC);
288 Base = Offset = N.getOperand(0);
289 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
290 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000291 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000292 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000293 }
294 }
295 }
296 }
297
Evan Chenga8e29892007-01-19 07:51:42 +0000298 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
299 Base = N;
300 if (N.getOpcode() == ISD::FrameIndex) {
301 int FI = cast<FrameIndexSDNode>(N)->getIndex();
302 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000303 } else if (N.getOpcode() == ARMISD::Wrapper &&
304 !(Subtarget->useMovt() &&
305 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000306 Base = N.getOperand(0);
307 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000308 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000309 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
310 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000311 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000312 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000313 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000314
Evan Chenga8e29892007-01-19 07:51:42 +0000315 // Match simple R +/- imm12 operands.
Jim Grosbachbe912322010-09-29 17:32:29 +0000316 if (N.getOpcode() == ISD::ADD) {
Evan Chenga8e29892007-01-19 07:51:42 +0000317 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000318 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000319 if ((RHSC >= 0 && RHSC < 0x1000) ||
320 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000321 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000322 if (Base.getOpcode() == ISD::FrameIndex) {
323 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
324 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
325 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000326 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000327
328 ARM_AM::AddrOpc AddSub = ARM_AM::add;
329 if (RHSC < 0) {
330 AddSub = ARM_AM::sub;
331 RHSC = - RHSC;
332 }
333 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000334 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000335 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000336 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000337 }
Evan Chenga8e29892007-01-19 07:51:42 +0000338 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000339 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000340
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000341 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000342 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
343 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
344 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000345
Evan Chenga8e29892007-01-19 07:51:42 +0000346 Base = N.getOperand(0);
347 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000348
Evan Chenga8e29892007-01-19 07:51:42 +0000349 if (ShOpcVal != ARM_AM::no_shift) {
350 // Check to see if the RHS of the shift is a constant, if not, we can't fold
351 // it.
352 if (ConstantSDNode *Sh =
353 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000354 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000355 Offset = N.getOperand(1).getOperand(0);
356 } else {
357 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000358 }
359 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000360
Evan Chenga8e29892007-01-19 07:51:42 +0000361 // Try matching (R shl C) + (R).
362 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
363 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
364 if (ShOpcVal != ARM_AM::no_shift) {
365 // Check to see if the RHS of the shift is a constant, if not, we can't
366 // fold it.
367 if (ConstantSDNode *Sh =
368 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000369 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000370 Offset = N.getOperand(0).getOperand(0);
371 Base = N.getOperand(1);
372 } else {
373 ShOpcVal = ARM_AM::no_shift;
374 }
375 }
376 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000377
Evan Chenga8e29892007-01-19 07:51:42 +0000378 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000379 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000380 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000381}
382
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000383bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000384 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000385 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000386 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
387 ? cast<LoadSDNode>(Op)->getAddressingMode()
388 : cast<StoreSDNode>(Op)->getAddressingMode();
389 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
390 ? ARM_AM::add : ARM_AM::sub;
391 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000392 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000393 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000394 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000395 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
396 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000397 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000398 return true;
399 }
400 }
401
402 Offset = N;
403 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
404 unsigned ShAmt = 0;
405 if (ShOpcVal != ARM_AM::no_shift) {
406 // Check to see if the RHS of the shift is a constant, if not, we can't fold
407 // it.
408 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000409 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000410 Offset = N.getOperand(0);
411 } else {
412 ShOpcVal = ARM_AM::no_shift;
413 }
414 }
415
416 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000417 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000418 return true;
419}
420
Evan Chenga8e29892007-01-19 07:51:42 +0000421
Chris Lattner52a261b2010-09-21 20:31:19 +0000422bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000423 SDValue &Base, SDValue &Offset,
424 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000425 if (N.getOpcode() == ISD::SUB) {
426 // X - C is canonicalize to X + -C, no need to handle it here.
427 Base = N.getOperand(0);
428 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000429 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000430 return true;
431 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000432
Evan Chenga8e29892007-01-19 07:51:42 +0000433 if (N.getOpcode() != ISD::ADD) {
434 Base = N;
435 if (N.getOpcode() == ISD::FrameIndex) {
436 int FI = cast<FrameIndexSDNode>(N)->getIndex();
437 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
438 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000439 Offset = CurDAG->getRegister(0, MVT::i32);
440 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000441 return true;
442 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000443
Evan Chenga8e29892007-01-19 07:51:42 +0000444 // If the RHS is +/- imm8, fold into addr mode.
445 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000446 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000447 if ((RHSC >= 0 && RHSC < 256) ||
448 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000449 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000450 if (Base.getOpcode() == ISD::FrameIndex) {
451 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
452 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
453 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000454 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000455
456 ARM_AM::AddrOpc AddSub = ARM_AM::add;
457 if (RHSC < 0) {
458 AddSub = ARM_AM::sub;
459 RHSC = - RHSC;
460 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000461 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000462 return true;
463 }
464 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000465
Evan Chenga8e29892007-01-19 07:51:42 +0000466 Base = N.getOperand(0);
467 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000468 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000469 return true;
470}
471
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000472bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000473 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000474 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000475 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
476 ? cast<LoadSDNode>(Op)->getAddressingMode()
477 : cast<StoreSDNode>(Op)->getAddressingMode();
478 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
479 ? ARM_AM::add : ARM_AM::sub;
480 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000481 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000482 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000483 Offset = CurDAG->getRegister(0, MVT::i32);
484 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000485 return true;
486 }
487 }
488
489 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000490 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000491 return true;
492}
493
Chris Lattner52a261b2010-09-21 20:31:19 +0000494bool ARMDAGToDAGISel::SelectAddrMode4(SDValue N, SDValue &Addr, SDValue &Mode) {
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000495 Addr = N;
Bob Wilsonfd7fd942010-08-28 00:20:11 +0000496 Mode = CurDAG->getTargetConstant(ARM_AM::getAM4ModeImm(ARM_AM::ia), MVT::i32);
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000497 return true;
498}
Evan Chenga8e29892007-01-19 07:51:42 +0000499
Chris Lattner52a261b2010-09-21 20:31:19 +0000500bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000501 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000502 if (N.getOpcode() != ISD::ADD) {
503 Base = N;
504 if (N.getOpcode() == ISD::FrameIndex) {
505 int FI = cast<FrameIndexSDNode>(N)->getIndex();
506 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000507 } else if (N.getOpcode() == ARMISD::Wrapper &&
508 !(Subtarget->useMovt() &&
509 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000510 Base = N.getOperand(0);
511 }
512 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000513 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000514 return true;
515 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000516
Evan Chenga8e29892007-01-19 07:51:42 +0000517 // If the RHS is +/- imm8, fold into addr mode.
518 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000519 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000520 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
521 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000522 if ((RHSC >= 0 && RHSC < 256) ||
523 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000524 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000525 if (Base.getOpcode() == ISD::FrameIndex) {
526 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
527 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
528 }
529
530 ARM_AM::AddrOpc AddSub = ARM_AM::add;
531 if (RHSC < 0) {
532 AddSub = ARM_AM::sub;
533 RHSC = - RHSC;
534 }
535 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000536 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000537 return true;
538 }
539 }
540 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000541
Evan Chenga8e29892007-01-19 07:51:42 +0000542 Base = N;
543 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000544 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000545 return true;
546}
547
Chris Lattner52a261b2010-09-21 20:31:19 +0000548bool ARMDAGToDAGISel::SelectAddrMode6(SDValue N, SDValue &Addr, SDValue &Align){
Bob Wilson8b024a52009-07-01 23:16:05 +0000549 Addr = N;
Jim Grosbach8a5ec862009-11-07 21:25:39 +0000550 // Default to no alignment.
551 Align = CurDAG->getTargetConstant(0, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000552 return true;
553}
554
Chris Lattner52a261b2010-09-21 20:31:19 +0000555bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000556 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000557 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
558 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000559 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000560 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000561 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000562 return true;
563 }
564 return false;
565}
566
Chris Lattner52a261b2010-09-21 20:31:19 +0000567bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000568 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000569 // FIXME dl should come from the parent load or store, not the address
Evan Chengc38f2bc2007-01-23 22:59:13 +0000570 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000571 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000572 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000573 return false;
574
575 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000576 return true;
577 }
578
Evan Chenga8e29892007-01-19 07:51:42 +0000579 Base = N.getOperand(0);
580 Offset = N.getOperand(1);
581 return true;
582}
583
Evan Cheng79d43262007-01-24 02:21:22 +0000584bool
Chris Lattner52a261b2010-09-21 20:31:19 +0000585ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000586 unsigned Scale, SDValue &Base,
587 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000588 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000589 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000590 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000591 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000592 if (N.getOpcode() == ARMISD::Wrapper &&
593 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
594 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000595 }
596
Evan Chenga8e29892007-01-19 07:51:42 +0000597 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000598 if (N.getOpcode() == ARMISD::Wrapper &&
599 !(Subtarget->useMovt() &&
600 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
601 Base = N.getOperand(0);
602 } else
603 Base = N;
604
Owen Anderson825b72b2009-08-11 20:47:22 +0000605 Offset = CurDAG->getRegister(0, MVT::i32);
606 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000607 return true;
608 }
609
Evan Chengad0e4652007-02-06 00:22:06 +0000610 // Thumb does not have [sp, r] address mode.
611 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
612 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
613 if ((LHSR && LHSR->getReg() == ARM::SP) ||
614 (RHSR && RHSR->getReg() == ARM::SP)) {
615 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000616 Offset = CurDAG->getRegister(0, MVT::i32);
617 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000618 return true;
619 }
620
Evan Chenga8e29892007-01-19 07:51:42 +0000621 // If the RHS is + imm5 * scale, fold into addr mode.
622 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000623 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000624 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
625 RHSC /= Scale;
626 if (RHSC >= 0 && RHSC < 32) {
627 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000628 Offset = CurDAG->getRegister(0, MVT::i32);
629 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000630 return true;
631 }
632 }
633 }
634
Evan Chengc38f2bc2007-01-23 22:59:13 +0000635 Base = N.getOperand(0);
636 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000637 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000638 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000639}
640
Chris Lattner52a261b2010-09-21 20:31:19 +0000641bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000642 SDValue &Base, SDValue &OffImm,
643 SDValue &Offset) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000644 return SelectThumbAddrModeRI5(N, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000645}
646
Chris Lattner52a261b2010-09-21 20:31:19 +0000647bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000648 SDValue &Base, SDValue &OffImm,
649 SDValue &Offset) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000650 return SelectThumbAddrModeRI5(N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000651}
652
Chris Lattner52a261b2010-09-21 20:31:19 +0000653bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000654 SDValue &Base, SDValue &OffImm,
655 SDValue &Offset) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000656 return SelectThumbAddrModeRI5(N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000657}
658
Chris Lattner52a261b2010-09-21 20:31:19 +0000659bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
660 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000661 if (N.getOpcode() == ISD::FrameIndex) {
662 int FI = cast<FrameIndexSDNode>(N)->getIndex();
663 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000664 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000665 return true;
666 }
Evan Cheng79d43262007-01-24 02:21:22 +0000667
Evan Chengad0e4652007-02-06 00:22:06 +0000668 if (N.getOpcode() != ISD::ADD)
669 return false;
670
671 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000672 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
673 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000674 // If the RHS is + imm8 * scale, fold into addr mode.
675 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000676 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000677 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
678 RHSC >>= 2;
679 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000680 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000681 if (Base.getOpcode() == ISD::FrameIndex) {
682 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
683 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
684 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000685 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000686 return true;
687 }
688 }
689 }
690 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000691
Evan Chenga8e29892007-01-19 07:51:42 +0000692 return false;
693}
694
Chris Lattner52a261b2010-09-21 20:31:19 +0000695bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000696 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000697 if (DisableShifterOp)
698 return false;
699
Evan Cheng9cb9e672009-06-27 02:26:13 +0000700 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
701
702 // Don't match base register only case. That is matched to a separate
703 // lower complexity pattern with explicit register operand.
704 if (ShOpcVal == ARM_AM::no_shift) return false;
705
706 BaseReg = N.getOperand(0);
707 unsigned ShImmVal = 0;
708 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
709 ShImmVal = RHS->getZExtValue() & 31;
710 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
711 return true;
712 }
713
714 return false;
715}
716
Chris Lattner52a261b2010-09-21 20:31:19 +0000717bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000718 SDValue &Base, SDValue &OffImm) {
719 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000720
Evan Cheng3a214252009-08-11 08:52:18 +0000721 // Base only.
722 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000723 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000724 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000725 int FI = cast<FrameIndexSDNode>(N)->getIndex();
726 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000727 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000728 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000729 } else if (N.getOpcode() == ARMISD::Wrapper &&
730 !(Subtarget->useMovt() &&
731 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000732 Base = N.getOperand(0);
733 if (Base.getOpcode() == ISD::TargetConstantPool)
734 return false; // We want to select t2LDRpci instead.
735 } else
736 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000737 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000738 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000739 }
Evan Cheng055b0312009-06-29 07:51:04 +0000740
741 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000742 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +0000743 // Let t2LDRi8 handle (R - imm8).
744 return false;
745
Evan Cheng055b0312009-06-29 07:51:04 +0000746 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000747 if (N.getOpcode() == ISD::SUB)
748 RHSC = -RHSC;
749
750 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +0000751 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +0000752 if (Base.getOpcode() == ISD::FrameIndex) {
753 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
754 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
755 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000756 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000757 return true;
758 }
759 }
760
Evan Cheng3a214252009-08-11 08:52:18 +0000761 // Base only.
762 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000763 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000764 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000765}
766
Chris Lattner52a261b2010-09-21 20:31:19 +0000767bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000768 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +0000769 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +0000770 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +0000771 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
772 int RHSC = (int)RHS->getSExtValue();
773 if (N.getOpcode() == ISD::SUB)
774 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +0000775
Evan Cheng3a214252009-08-11 08:52:18 +0000776 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
777 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +0000778 if (Base.getOpcode() == ISD::FrameIndex) {
779 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
780 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
781 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000782 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +0000783 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000784 }
Evan Cheng055b0312009-06-29 07:51:04 +0000785 }
786 }
787
788 return false;
789}
790
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000791bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000792 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000793 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +0000794 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
795 ? cast<LoadSDNode>(Op)->getAddressingMode()
796 : cast<StoreSDNode>(Op)->getAddressingMode();
797 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
798 int RHSC = (int)RHS->getZExtValue();
799 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +0000800 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +0000801 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
802 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000803 return true;
804 }
805 }
806
807 return false;
808}
809
Chris Lattner52a261b2010-09-21 20:31:19 +0000810bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000811 SDValue &Base,
812 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +0000813 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
814 if (N.getOpcode() != ISD::ADD)
815 return false;
Evan Cheng055b0312009-06-29 07:51:04 +0000816
Evan Cheng3a214252009-08-11 08:52:18 +0000817 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
818 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
819 int RHSC = (int)RHS->getZExtValue();
820 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
821 return false;
822 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +0000823 return false;
824 }
825
Evan Cheng055b0312009-06-29 07:51:04 +0000826 // Look for (R + R) or (R + (R << [1,2,3])).
827 unsigned ShAmt = 0;
828 Base = N.getOperand(0);
829 OffReg = N.getOperand(1);
830
831 // Swap if it is ((R << c) + R).
832 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
833 if (ShOpcVal != ARM_AM::lsl) {
834 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
835 if (ShOpcVal == ARM_AM::lsl)
836 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +0000837 }
838
Evan Cheng055b0312009-06-29 07:51:04 +0000839 if (ShOpcVal == ARM_AM::lsl) {
840 // Check to see if the RHS of the shift is a constant, if not, we can't fold
841 // it.
842 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
843 ShAmt = Sh->getZExtValue();
844 if (ShAmt >= 4) {
845 ShAmt = 0;
846 ShOpcVal = ARM_AM::no_shift;
847 } else
848 OffReg = OffReg.getOperand(0);
849 } else {
850 ShOpcVal = ARM_AM::no_shift;
851 }
David Goodwin7ecc8502009-07-15 15:50:19 +0000852 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000853
Owen Anderson825b72b2009-08-11 20:47:22 +0000854 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000855
856 return true;
857}
858
859//===--------------------------------------------------------------------===//
860
Evan Chengee568cf2007-07-05 07:15:27 +0000861/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +0000862static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000863 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +0000864}
865
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000866SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
867 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +0000868 ISD::MemIndexedMode AM = LD->getAddressingMode();
869 if (AM == ISD::UNINDEXED)
870 return NULL;
871
Owen Andersone50ed302009-08-10 22:56:29 +0000872 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +0000873 SDValue Offset, AMOpc;
874 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
875 unsigned Opcode = 0;
876 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000877 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000878 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000879 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
880 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +0000881 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000882 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000883 Match = true;
884 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
885 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
886 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +0000887 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000888 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000889 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000890 Match = true;
891 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
892 }
893 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000894 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000895 Match = true;
896 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
897 }
898 }
899 }
900
901 if (Match) {
902 SDValue Chain = LD->getChain();
903 SDValue Base = LD->getBasePtr();
904 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000905 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000906 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000907 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +0000908 }
909
910 return NULL;
911}
912
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000913SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
914 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000915 ISD::MemIndexedMode AM = LD->getAddressingMode();
916 if (AM == ISD::UNINDEXED)
917 return NULL;
918
Owen Andersone50ed302009-08-10 22:56:29 +0000919 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +0000920 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000921 SDValue Offset;
922 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
923 unsigned Opcode = 0;
924 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000925 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000926 switch (LoadedVT.getSimpleVT().SimpleTy) {
927 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000928 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
929 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000930 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000931 if (isSExtLd)
932 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
933 else
934 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000935 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000936 case MVT::i8:
937 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000938 if (isSExtLd)
939 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
940 else
941 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000942 break;
943 default:
944 return NULL;
945 }
946 Match = true;
947 }
948
949 if (Match) {
950 SDValue Chain = LD->getChain();
951 SDValue Base = LD->getBasePtr();
952 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000953 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000954 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000955 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000956 }
957
958 return NULL;
959}
960
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000961/// PairSRegs - Form a D register from a pair of S registers.
962///
963SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
964 DebugLoc dl = V0.getNode()->getDebugLoc();
965 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
966 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +0000967 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
968 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000969}
970
Evan Cheng603afbf2010-05-10 17:34:18 +0000971/// PairDRegs - Form a quad register from a pair of D registers.
972///
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000973SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
974 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +0000975 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
976 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +0000977 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
978 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000979}
980
Evan Cheng7f687192010-05-14 00:21:45 +0000981/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +0000982///
983SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
984 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +0000985 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
986 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +0000987 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
988 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
989}
990
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000991/// QuadSRegs - Form 4 consecutive S registers.
992///
993SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
994 SDValue V2, SDValue V3) {
995 DebugLoc dl = V0.getNode()->getDebugLoc();
996 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
997 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
998 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
999 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
1000 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1001 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1002}
1003
Evan Cheng7f687192010-05-14 00:21:45 +00001004/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001005///
1006SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1007 SDValue V2, SDValue V3) {
1008 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001009 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1010 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1011 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1012 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001013 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1014 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1015}
1016
Evan Cheng8f6de382010-05-16 03:27:48 +00001017/// QuadQRegs - Form 4 consecutive Q registers.
1018///
1019SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1020 SDValue V2, SDValue V3) {
1021 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001022 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1023 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1024 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1025 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Evan Cheng8f6de382010-05-16 03:27:48 +00001026 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1027 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1028}
1029
Bob Wilson2a6e6162010-09-23 23:42:37 +00001030/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1031/// of a NEON VLD or VST instruction. The supported values depend on the
1032/// number of registers being loaded.
1033static unsigned GetVLDSTAlign(SDNode *N, unsigned NumVecs, bool is64BitVector) {
1034 unsigned NumRegs = NumVecs;
1035 if (!is64BitVector && NumVecs < 3)
1036 NumRegs *= 2;
1037
1038 unsigned Alignment = cast<MemIntrinsicSDNode>(N)->getAlignment();
1039 if (Alignment >= 32 && NumRegs == 4)
1040 return 32;
1041 if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1042 return 16;
1043 if (Alignment >= 8)
1044 return 8;
1045 return 0;
1046}
1047
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001048SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001049 unsigned *DOpcodes, unsigned *QOpcodes0,
1050 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001051 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001052 DebugLoc dl = N->getDebugLoc();
1053
Bob Wilson226036e2010-03-20 22:13:40 +00001054 SDValue MemAddr, Align;
Chris Lattner52a261b2010-09-21 20:31:19 +00001055 if (!SelectAddrMode6(N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001056 return NULL;
1057
1058 SDValue Chain = N->getOperand(0);
1059 EVT VT = N->getValueType(0);
1060 bool is64BitVector = VT.is64BitVector();
1061
Bob Wilson2a6e6162010-09-23 23:42:37 +00001062 unsigned Alignment = GetVLDSTAlign(N, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001063 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1064
Bob Wilson3e36f132009-10-14 17:28:52 +00001065 unsigned OpcodeIndex;
1066 switch (VT.getSimpleVT().SimpleTy) {
1067 default: llvm_unreachable("unhandled vld type");
1068 // Double-register operations:
1069 case MVT::v8i8: OpcodeIndex = 0; break;
1070 case MVT::v4i16: OpcodeIndex = 1; break;
1071 case MVT::v2f32:
1072 case MVT::v2i32: OpcodeIndex = 2; break;
1073 case MVT::v1i64: OpcodeIndex = 3; break;
1074 // Quad-register operations:
1075 case MVT::v16i8: OpcodeIndex = 0; break;
1076 case MVT::v8i16: OpcodeIndex = 1; break;
1077 case MVT::v4f32:
1078 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001079 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001080 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001081 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001082 }
1083
Bob Wilsonf5721912010-09-03 18:16:02 +00001084 EVT ResTy;
1085 if (NumVecs == 1)
1086 ResTy = VT;
1087 else {
1088 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1089 if (!is64BitVector)
1090 ResTyElts *= 2;
1091 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1092 }
1093
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001094 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001095 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilsonf5721912010-09-03 18:16:02 +00001096 SDValue SuperReg;
Bob Wilson3e36f132009-10-14 17:28:52 +00001097 if (is64BitVector) {
1098 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001099 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilsonf5721912010-09-03 18:16:02 +00001100 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
Bob Wilsonffde0802010-09-02 16:00:54 +00001101 if (NumVecs == 1)
Evan Chenge9e2ba02010-05-10 21:26:24 +00001102 return VLd;
1103
Bob Wilsonf5721912010-09-03 18:16:02 +00001104 SuperReg = SDValue(VLd, 0);
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001105 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
Evan Cheng5c6aba22010-05-14 18:54:59 +00001106 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001107 SDValue D = CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec,
Bob Wilsonffde0802010-09-02 16:00:54 +00001108 dl, VT, SuperReg);
Evan Cheng5c6aba22010-05-14 18:54:59 +00001109 ReplaceUses(SDValue(N, Vec), D);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001110 }
Bob Wilsonf5721912010-09-03 18:16:02 +00001111 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
Evan Chenge9e2ba02010-05-10 21:26:24 +00001112 return NULL;
Bob Wilson3e36f132009-10-14 17:28:52 +00001113 }
1114
Bob Wilson621f1952010-03-23 05:25:43 +00001115 if (NumVecs <= 2) {
1116 // Quad registers are directly supported for VLD1 and VLD2,
1117 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001118 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001119 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilsonffde0802010-09-02 16:00:54 +00001120 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
Bob Wilsonffde0802010-09-02 16:00:54 +00001121 if (NumVecs == 1)
1122 return VLd;
1123
Bob Wilsonf5721912010-09-03 18:16:02 +00001124 SuperReg = SDValue(VLd, 0);
Bob Wilsonffde0802010-09-02 16:00:54 +00001125 Chain = SDValue(VLd, 1);
1126
Bob Wilson3e36f132009-10-14 17:28:52 +00001127 } else {
1128 // Otherwise, quad registers are loaded with two separate instructions,
1129 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001130 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001131
Bob Wilson24f995d2009-10-14 18:32:29 +00001132 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001133 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsonf5721912010-09-03 18:16:02 +00001134 SDValue ImplDef =
1135 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1136 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
1137 SDNode *VLdA =
1138 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsA, 7);
1139 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001140
Bob Wilson24f995d2009-10-14 18:32:29 +00001141 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001142 Opc = QOpcodes1[OpcodeIndex];
Bob Wilsonf5721912010-09-03 18:16:02 +00001143 const SDValue OpsB[] = { SDValue(VLdA, 1), Align, Reg0, SDValue(VLdA, 0),
1144 Pred, Reg0, Chain };
1145 SDNode *VLdB =
1146 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsB, 7);
1147 SuperReg = SDValue(VLdB, 0);
1148 Chain = SDValue(VLdB, 2);
1149 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001150
Bob Wilsonf5721912010-09-03 18:16:02 +00001151 // Extract out the Q registers.
1152 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1153 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1154 SDValue Q = CurDAG->getTargetExtractSubreg(ARM::qsub_0+Vec,
1155 dl, VT, SuperReg);
1156 ReplaceUses(SDValue(N, Vec), Q);
Bob Wilson3e36f132009-10-14 17:28:52 +00001157 }
1158 ReplaceUses(SDValue(N, NumVecs), Chain);
1159 return NULL;
1160}
1161
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001162SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001163 unsigned *DOpcodes, unsigned *QOpcodes0,
1164 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001165 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001166 DebugLoc dl = N->getDebugLoc();
1167
Bob Wilson226036e2010-03-20 22:13:40 +00001168 SDValue MemAddr, Align;
Chris Lattner52a261b2010-09-21 20:31:19 +00001169 if (!SelectAddrMode6(N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001170 return NULL;
1171
1172 SDValue Chain = N->getOperand(0);
1173 EVT VT = N->getOperand(3).getValueType();
1174 bool is64BitVector = VT.is64BitVector();
1175
Bob Wilson2a6e6162010-09-23 23:42:37 +00001176 unsigned Alignment = GetVLDSTAlign(N, NumVecs, is64BitVector);
1177 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1178
Bob Wilson24f995d2009-10-14 18:32:29 +00001179 unsigned OpcodeIndex;
1180 switch (VT.getSimpleVT().SimpleTy) {
1181 default: llvm_unreachable("unhandled vst type");
1182 // Double-register operations:
1183 case MVT::v8i8: OpcodeIndex = 0; break;
1184 case MVT::v4i16: OpcodeIndex = 1; break;
1185 case MVT::v2f32:
1186 case MVT::v2i32: OpcodeIndex = 2; break;
1187 case MVT::v1i64: OpcodeIndex = 3; break;
1188 // Quad-register operations:
1189 case MVT::v16i8: OpcodeIndex = 0; break;
1190 case MVT::v8i16: OpcodeIndex = 1; break;
1191 case MVT::v4f32:
1192 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001193 case MVT::v2i64: OpcodeIndex = 3;
1194 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1195 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001196 }
1197
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001198 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001199 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001200
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001201 SmallVector<SDValue, 7> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001202 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001203 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001204
1205 if (is64BitVector) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001206 if (NumVecs == 1) {
1207 Ops.push_back(N->getOperand(3));
1208 } else {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001209 SDValue RegSeq;
1210 SDValue V0 = N->getOperand(0+3);
1211 SDValue V1 = N->getOperand(1+3);
1212
1213 // Form a REG_SEQUENCE to force register allocation.
1214 if (NumVecs == 2)
1215 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1216 else {
1217 SDValue V2 = N->getOperand(2+3);
1218 // If it's a vld3, form a quad D-register and leave the last part as
1219 // an undef.
1220 SDValue V3 = (NumVecs == 3)
1221 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1222 : N->getOperand(3+3);
1223 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1224 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001225 Ops.push_back(RegSeq);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001226 }
Evan Chengac0869d2009-11-21 06:21:52 +00001227 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001228 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001229 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001230 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001231 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001232 }
1233
Bob Wilson11d98992010-03-23 06:20:33 +00001234 if (NumVecs <= 2) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001235 // Quad registers are directly supported for VST1 and VST2.
Bob Wilson24f995d2009-10-14 18:32:29 +00001236 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001237 if (NumVecs == 1) {
1238 Ops.push_back(N->getOperand(3));
1239 } else {
1240 // Form a QQ register.
Evan Cheng603afbf2010-05-10 17:34:18 +00001241 SDValue Q0 = N->getOperand(3);
1242 SDValue Q1 = N->getOperand(4);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001243 Ops.push_back(SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0));
Bob Wilson24f995d2009-10-14 18:32:29 +00001244 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001245 Ops.push_back(Pred);
1246 Ops.push_back(Reg0); // predicate register
1247 Ops.push_back(Chain);
1248 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001249 }
1250
1251 // Otherwise, quad registers are stored with two separate instructions,
1252 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001253
Bob Wilson07f6e802010-06-16 21:34:01 +00001254 // Form the QQQQ REG_SEQUENCE.
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001255 SDValue V0 = N->getOperand(0+3);
1256 SDValue V1 = N->getOperand(1+3);
1257 SDValue V2 = N->getOperand(2+3);
1258 SDValue V3 = (NumVecs == 3)
1259 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1260 : N->getOperand(3+3);
1261 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001262
1263 // Store the even D registers.
Bob Wilson07f6e802010-06-16 21:34:01 +00001264 Ops.push_back(Reg0); // post-access address offset
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001265 Ops.push_back(RegSeq);
Bob Wilson07f6e802010-06-16 21:34:01 +00001266 Ops.push_back(Pred);
1267 Ops.push_back(Reg0); // predicate register
1268 Ops.push_back(Chain);
1269 unsigned Opc = QOpcodes0[OpcodeIndex];
1270 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001271 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001272 Chain = SDValue(VStA, 1);
1273
1274 // Store the odd D registers.
1275 Ops[0] = SDValue(VStA, 0); // MemAddr
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001276 Ops[6] = Chain;
Bob Wilson07f6e802010-06-16 21:34:01 +00001277 Opc = QOpcodes1[OpcodeIndex];
1278 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001279 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001280 Chain = SDValue(VStB, 1);
1281 ReplaceUses(SDValue(N, 0), Chain);
1282 return NULL;
Bob Wilson24f995d2009-10-14 18:32:29 +00001283}
1284
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001285SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001286 unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001287 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001288 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001289 DebugLoc dl = N->getDebugLoc();
1290
Bob Wilson226036e2010-03-20 22:13:40 +00001291 SDValue MemAddr, Align;
Chris Lattner52a261b2010-09-21 20:31:19 +00001292 if (!SelectAddrMode6(N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001293 return NULL;
1294
1295 SDValue Chain = N->getOperand(0);
1296 unsigned Lane =
1297 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001298 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001299 bool is64BitVector = VT.is64BitVector();
1300
Bob Wilson3454ed92010-10-19 00:16:32 +00001301 if (NumVecs != 3) {
1302 unsigned Alignment = cast<MemIntrinsicSDNode>(N)->getAlignment();
1303 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1304 if (Alignment > NumBytes)
1305 Alignment = NumBytes;
1306 // Alignment must be a power of two; make sure of that.
1307 Alignment = (Alignment & -Alignment);
1308 if (Alignment > 1)
1309 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1310 }
1311
Bob Wilsona7c397c2009-10-14 16:19:03 +00001312 unsigned OpcodeIndex;
1313 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001314 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001315 // Double-register operations:
1316 case MVT::v8i8: OpcodeIndex = 0; break;
1317 case MVT::v4i16: OpcodeIndex = 1; break;
1318 case MVT::v2f32:
1319 case MVT::v2i32: OpcodeIndex = 2; break;
1320 // Quad-register operations:
1321 case MVT::v8i16: OpcodeIndex = 0; break;
1322 case MVT::v4f32:
1323 case MVT::v4i32: OpcodeIndex = 1; break;
1324 }
1325
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001326 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001327 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001328
Bob Wilson8466fa12010-09-13 23:01:35 +00001329 SmallVector<SDValue, 7> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001330 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001331 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001332
Eric Christopher23da0b22010-09-14 08:31:25 +00001333 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1334 QOpcodes[OpcodeIndex]);
Bob Wilson07f6e802010-06-16 21:34:01 +00001335
Bob Wilson8466fa12010-09-13 23:01:35 +00001336 SDValue SuperReg;
1337 SDValue V0 = N->getOperand(0+3);
1338 SDValue V1 = N->getOperand(1+3);
1339 if (NumVecs == 2) {
1340 if (is64BitVector)
1341 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1342 else
1343 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001344 } else {
Bob Wilson8466fa12010-09-13 23:01:35 +00001345 SDValue V2 = N->getOperand(2+3);
1346 SDValue V3 = (NumVecs == 3)
1347 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1348 : N->getOperand(3+3);
1349 if (is64BitVector)
1350 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1351 else
1352 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001353 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001354 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001355 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001356 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001357 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001358 Ops.push_back(Chain);
1359
Bob Wilson96493442009-10-14 16:46:45 +00001360 if (!IsLoad)
Bob Wilson8466fa12010-09-13 23:01:35 +00001361 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 7);
Bob Wilson96493442009-10-14 16:46:45 +00001362
Bob Wilson8466fa12010-09-13 23:01:35 +00001363 EVT ResTy;
1364 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1365 if (!is64BitVector)
1366 ResTyElts *= 2;
1367 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001368
Bob Wilson8466fa12010-09-13 23:01:35 +00001369 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other,
1370 Ops.data(), 7);
1371 SuperReg = SDValue(VLdLn, 0);
1372 Chain = SDValue(VLdLn, 1);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001373
Bob Wilson8466fa12010-09-13 23:01:35 +00001374 // Extract the subregisters.
Bob Wilson07f6e802010-06-16 21:34:01 +00001375 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1376 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1377 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
1378 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1379 ReplaceUses(SDValue(N, Vec),
Bob Wilson8466fa12010-09-13 23:01:35 +00001380 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
1381 ReplaceUses(SDValue(N, NumVecs), Chain);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001382 return NULL;
1383}
1384
Bob Wilson78dfbc32010-07-07 00:08:54 +00001385SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1386 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001387 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1388 DebugLoc dl = N->getDebugLoc();
1389 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001390 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001391
1392 // Form a REG_SEQUENCE to force register allocation.
1393 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001394 SDValue V0 = N->getOperand(FirstTblReg + 0);
1395 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001396 if (NumVecs == 2)
1397 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1398 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001399 SDValue V2 = N->getOperand(FirstTblReg + 2);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001400 // If it's a vtbl3, form a quad D-register and leave the last part as
1401 // an undef.
1402 SDValue V3 = (NumVecs == 3)
1403 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001404 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001405 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1406 }
1407
Bob Wilson78dfbc32010-07-07 00:08:54 +00001408 SmallVector<SDValue, 6> Ops;
1409 if (IsExt)
1410 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00001411 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001412 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001413 Ops.push_back(getAL(CurDAG)); // predicate
1414 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001415 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001416}
1417
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001418SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001419 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001420 if (!Subtarget->hasV6T2Ops())
1421 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001422
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001423 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1424 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1425
1426
1427 // For unsigned extracts, check for a shift right and mask
1428 unsigned And_imm = 0;
1429 if (N->getOpcode() == ISD::AND) {
1430 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1431
1432 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1433 if (And_imm & (And_imm + 1))
1434 return NULL;
1435
1436 unsigned Srl_imm = 0;
1437 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1438 Srl_imm)) {
1439 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1440
1441 unsigned Width = CountTrailingOnes_32(And_imm);
1442 unsigned LSB = Srl_imm;
1443 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1444 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1445 CurDAG->getTargetConstant(LSB, MVT::i32),
1446 CurDAG->getTargetConstant(Width, MVT::i32),
1447 getAL(CurDAG), Reg0 };
1448 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1449 }
1450 }
1451 return NULL;
1452 }
1453
1454 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001455 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001456 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001457 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1458 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001459 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001460 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1461 unsigned Width = 32 - Srl_imm;
1462 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001463 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001464 return NULL;
1465 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001466 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001467 CurDAG->getTargetConstant(LSB, MVT::i32),
1468 CurDAG->getTargetConstant(Width, MVT::i32),
1469 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001470 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001471 }
1472 }
1473 return NULL;
1474}
1475
Evan Cheng9ef48352009-11-20 00:54:03 +00001476SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001477SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001478 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1479 SDValue CPTmp0;
1480 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00001481 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001482 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1483 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1484 unsigned Opc = 0;
1485 switch (SOShOp) {
1486 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1487 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1488 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1489 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1490 default:
1491 llvm_unreachable("Unknown so_reg opcode!");
1492 break;
1493 }
1494 SDValue SOShImm =
1495 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1496 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1497 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001498 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001499 }
1500 return 0;
1501}
1502
1503SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001504SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001505 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1506 SDValue CPTmp0;
1507 SDValue CPTmp1;
1508 SDValue CPTmp2;
Chris Lattner52a261b2010-09-21 20:31:19 +00001509 if (SelectShifterOperandReg(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001510 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1511 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001512 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001513 }
1514 return 0;
1515}
1516
1517SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00001518SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001519 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1520 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1521 if (!T)
1522 return 0;
1523
Jim Grosbacha4257162010-10-07 00:53:56 +00001524 unsigned TrueImm = T->getZExtValue();
1525 bool isSoImm = Pred_t2_so_imm(TrueVal.getNode());
1526 if (isSoImm || TrueImm <= 0xffff) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001527 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1528 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1529 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Jim Grosbacha4257162010-10-07 00:53:56 +00001530 return CurDAG->SelectNodeTo(N, (isSoImm ? ARM::t2MOVCCi : ARM::t2MOVCCi16),
1531 MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00001532 }
1533 return 0;
1534}
1535
1536SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001537SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001538 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1539 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1540 if (!T)
1541 return 0;
1542
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001543 unsigned TrueImm = T->getZExtValue();
1544 bool isSoImm = Pred_so_imm(TrueVal.getNode());
1545 if (isSoImm || (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff)) {
1546 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00001547 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1548 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001549 return CurDAG->SelectNodeTo(N, (isSoImm ? ARM::MOVCCi : ARM::MOVCCi16),
1550 MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00001551 }
1552 return 0;
1553}
1554
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001555SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1556 EVT VT = N->getValueType(0);
1557 SDValue FalseVal = N->getOperand(0);
1558 SDValue TrueVal = N->getOperand(1);
1559 SDValue CC = N->getOperand(2);
1560 SDValue CCR = N->getOperand(3);
1561 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001562 assert(CC.getOpcode() == ISD::Constant);
1563 assert(CCR.getOpcode() == ISD::Register);
1564 ARMCC::CondCodes CCVal =
1565 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001566
1567 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1568 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1569 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1570 // Pattern complexity = 18 cost = 1 size = 0
1571 SDValue CPTmp0;
1572 SDValue CPTmp1;
1573 SDValue CPTmp2;
1574 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001575 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001576 CCVal, CCR, InFlag);
1577 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001578 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001579 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1580 if (Res)
1581 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001582 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001583 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001584 CCVal, CCR, InFlag);
1585 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001586 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001587 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1588 if (Res)
1589 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001590 }
1591
1592 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00001593 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00001594 // (imm:i32):$cc)
1595 // Emits: (MOVCCi:i32 GPR:i32:$false,
1596 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1597 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001598 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00001599 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001600 CCVal, CCR, InFlag);
1601 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00001602 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001603 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1604 if (Res)
1605 return Res;
1606 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001607 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001608 CCVal, CCR, InFlag);
1609 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001610 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001611 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1612 if (Res)
1613 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001614 }
1615 }
1616
1617 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1618 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1619 // Pattern complexity = 6 cost = 1 size = 0
1620 //
1621 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1622 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1623 // Pattern complexity = 6 cost = 11 size = 0
1624 //
1625 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001626 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1627 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001628 unsigned Opc = 0;
1629 switch (VT.getSimpleVT().SimpleTy) {
1630 default: assert(false && "Illegal conditional move type!");
1631 break;
1632 case MVT::i32:
1633 Opc = Subtarget->isThumb()
1634 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1635 : ARM::MOVCCr;
1636 break;
1637 case MVT::f32:
1638 Opc = ARM::VMOVScc;
1639 break;
1640 case MVT::f64:
1641 Opc = ARM::VMOVDcc;
1642 break;
1643 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001644 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001645}
1646
Evan Chengde8aa4e2010-05-05 18:28:36 +00001647SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
1648 // The only time a CONCAT_VECTORS operation can have legal types is when
1649 // two 64-bit vectors are concatenated to a 128-bit vector.
1650 EVT VT = N->getValueType(0);
1651 if (!VT.is128BitVector() || N->getNumOperands() != 2)
1652 llvm_unreachable("unexpected CONCAT_VECTORS");
1653 DebugLoc dl = N->getDebugLoc();
1654 SDValue V0 = N->getOperand(0);
1655 SDValue V1 = N->getOperand(1);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001656 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1657 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +00001658 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1659 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1660}
1661
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001662SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001663 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001664
Dan Gohmane8be6c62008-07-17 19:10:17 +00001665 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001666 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001667
1668 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001669 default: break;
1670 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001671 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001672 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001673 if (Subtarget->hasThumb2())
1674 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1675 // be done with MOV + MOVT, at worst.
1676 UseCP = 0;
1677 else {
1678 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001679 UseCP = (Val > 255 && // MOV
1680 ~Val > 255 && // MOV + MVN
1681 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001682 } else
1683 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1684 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1685 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1686 }
1687
Evan Chenga8e29892007-01-19 07:51:42 +00001688 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001689 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001690 CurDAG->getTargetConstantPool(ConstantInt::get(
1691 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001692 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001693
1694 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001695 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001696 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001697 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001698 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001699 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1700 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001701 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001702 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001703 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001704 CurDAG->getRegister(0, MVT::i32),
1705 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001706 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001707 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001708 CurDAG->getEntryNode()
1709 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001710 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1711 Ops, 6);
Evan Cheng012f2d92007-01-24 08:53:17 +00001712 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001713 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001714 return NULL;
1715 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001716
Evan Chenga8e29892007-01-19 07:51:42 +00001717 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001718 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001719 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001720 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001721 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001722 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001723 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001724 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001725 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1726 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001727 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001728 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1729 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001730 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1731 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1732 CurDAG->getRegister(0, MVT::i32) };
1733 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001734 }
Evan Chenga8e29892007-01-19 07:51:42 +00001735 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001736 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001737 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001738 return I;
1739 break;
1740 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001741 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001742 return I;
1743 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001744 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001745 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001746 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001747 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001748 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001749 if (!RHSV) break;
1750 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001751 unsigned ShImm = Log2_32(RHSV-1);
1752 if (ShImm >= 32)
1753 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001754 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001755 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001756 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1757 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001758 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001759 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001760 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001761 } else {
1762 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001763 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001764 }
Evan Chenga8e29892007-01-19 07:51:42 +00001765 }
1766 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001767 unsigned ShImm = Log2_32(RHSV+1);
1768 if (ShImm >= 32)
1769 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001770 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001771 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001772 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1773 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001774 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00001775 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1776 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001777 } else {
1778 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001779 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001780 }
Evan Chenga8e29892007-01-19 07:51:42 +00001781 }
1782 }
1783 break;
Evan Cheng20956592009-10-21 08:15:52 +00001784 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001785 // Check for unsigned bitfield extract
1786 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1787 return I;
1788
Evan Cheng20956592009-10-21 08:15:52 +00001789 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1790 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1791 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1792 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1793 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001794 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001795 if (VT != MVT::i32)
1796 break;
1797 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1798 ? ARM::t2MOVTi16
1799 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1800 if (!Opc)
1801 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001802 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001803 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1804 if (!N1C)
1805 break;
1806 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1807 SDValue N2 = N0.getOperand(1);
1808 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1809 if (!N2C)
1810 break;
1811 unsigned N1CVal = N1C->getZExtValue();
1812 unsigned N2CVal = N2C->getZExtValue();
1813 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1814 (N1CVal & 0xffffU) == 0xffffU &&
1815 (N2CVal & 0xffffU) == 0x0U) {
1816 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1817 MVT::i32);
1818 SDValue Ops[] = { N0.getOperand(0), Imm16,
1819 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1820 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
1821 }
1822 }
1823 break;
1824 }
Jim Grosbache5165492009-11-09 00:11:35 +00001825 case ARMISD::VMOVRRD:
1826 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001827 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00001828 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00001829 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001830 if (Subtarget->isThumb1Only())
1831 break;
1832 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001833 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001834 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1835 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00001836 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001837 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001838 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001839 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1840 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001841 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001842 }
Evan Chengee568cf2007-07-05 07:15:27 +00001843 }
Dan Gohman525178c2007-10-08 18:33:35 +00001844 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001845 if (Subtarget->isThumb1Only())
1846 break;
1847 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001848 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001849 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00001850 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001851 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001852 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001853 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1854 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001855 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001856 }
Evan Chengee568cf2007-07-05 07:15:27 +00001857 }
Evan Chenga8e29892007-01-19 07:51:42 +00001858 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00001859 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001860 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001861 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001862 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001863 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001864 if (ResNode)
1865 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00001866 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001867 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001868 }
Evan Chengee568cf2007-07-05 07:15:27 +00001869 case ARMISD::BRCOND: {
1870 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1871 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1872 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001873
Evan Chengee568cf2007-07-05 07:15:27 +00001874 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1875 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
1876 // Pattern complexity = 6 cost = 1 size = 0
1877
David Goodwin5e47a9a2009-06-30 18:04:13 +00001878 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1879 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1880 // Pattern complexity = 6 cost = 1 size = 0
1881
Jim Grosbach764ab522009-08-11 15:33:49 +00001882 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00001883 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001884 SDValue Chain = N->getOperand(0);
1885 SDValue N1 = N->getOperand(1);
1886 SDValue N2 = N->getOperand(2);
1887 SDValue N3 = N->getOperand(3);
1888 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00001889 assert(N1.getOpcode() == ISD::BasicBlock);
1890 assert(N2.getOpcode() == ISD::Constant);
1891 assert(N3.getOpcode() == ISD::Register);
1892
Dan Gohman475871a2008-07-27 21:46:04 +00001893 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001894 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00001895 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00001896 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00001897 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
1898 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00001899 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001900 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00001901 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001902 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00001903 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001904 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00001905 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00001906 return NULL;
1907 }
Evan Cheng07ba9062009-11-19 21:45:22 +00001908 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001909 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00001910 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001911 EVT VT = N->getValueType(0);
1912 SDValue N0 = N->getOperand(0);
1913 SDValue N1 = N->getOperand(1);
1914 SDValue N2 = N->getOperand(2);
1915 SDValue N3 = N->getOperand(3);
1916 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00001917 assert(N2.getOpcode() == ISD::Constant);
1918 assert(N3.getOpcode() == ISD::Register);
1919
Dan Gohman475871a2008-07-27 21:46:04 +00001920 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001921 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00001922 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00001923 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00001924 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00001925 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00001926 default: assert(false && "Illegal conditional move type!");
1927 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001928 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00001929 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00001930 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001931 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00001932 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00001933 break;
Evan Chengee568cf2007-07-05 07:15:27 +00001934 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001935 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001936 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00001937
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001938 case ARMISD::VZIP: {
1939 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001940 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001941 switch (VT.getSimpleVT().SimpleTy) {
1942 default: return NULL;
1943 case MVT::v8i8: Opc = ARM::VZIPd8; break;
1944 case MVT::v4i16: Opc = ARM::VZIPd16; break;
1945 case MVT::v2f32:
1946 case MVT::v2i32: Opc = ARM::VZIPd32; break;
1947 case MVT::v16i8: Opc = ARM::VZIPq8; break;
1948 case MVT::v8i16: Opc = ARM::VZIPq16; break;
1949 case MVT::v4f32:
1950 case MVT::v4i32: Opc = ARM::VZIPq32; break;
1951 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001952 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00001953 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1954 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1955 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001956 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001957 case ARMISD::VUZP: {
1958 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001959 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001960 switch (VT.getSimpleVT().SimpleTy) {
1961 default: return NULL;
1962 case MVT::v8i8: Opc = ARM::VUZPd8; break;
1963 case MVT::v4i16: Opc = ARM::VUZPd16; break;
1964 case MVT::v2f32:
1965 case MVT::v2i32: Opc = ARM::VUZPd32; break;
1966 case MVT::v16i8: Opc = ARM::VUZPq8; break;
1967 case MVT::v8i16: Opc = ARM::VUZPq16; break;
1968 case MVT::v4f32:
1969 case MVT::v4i32: Opc = ARM::VUZPq32; break;
1970 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001971 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00001972 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1973 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1974 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001975 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001976 case ARMISD::VTRN: {
1977 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001978 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001979 switch (VT.getSimpleVT().SimpleTy) {
1980 default: return NULL;
1981 case MVT::v8i8: Opc = ARM::VTRNd8; break;
1982 case MVT::v4i16: Opc = ARM::VTRNd16; break;
1983 case MVT::v2f32:
1984 case MVT::v2i32: Opc = ARM::VTRNd32; break;
1985 case MVT::v16i8: Opc = ARM::VTRNq8; break;
1986 case MVT::v8i16: Opc = ARM::VTRNq16; break;
1987 case MVT::v4f32:
1988 case MVT::v4i32: Opc = ARM::VTRNq32; break;
1989 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001990 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00001991 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1992 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1993 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001994 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001995 case ARMISD::BUILD_VECTOR: {
1996 EVT VecVT = N->getValueType(0);
1997 EVT EltVT = VecVT.getVectorElementType();
1998 unsigned NumElts = VecVT.getVectorNumElements();
1999 if (EltVT.getSimpleVT() == MVT::f64) {
2000 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2001 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2002 }
2003 assert(EltVT.getSimpleVT() == MVT::f32 &&
2004 "unexpected type for BUILD_VECTOR");
2005 if (NumElts == 2)
2006 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2007 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2008 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2009 N->getOperand(2), N->getOperand(3));
2010 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002011
2012 case ISD::INTRINSIC_VOID:
2013 case ISD::INTRINSIC_W_CHAIN: {
2014 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002015 switch (IntNo) {
2016 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002017 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002018
Bob Wilson621f1952010-03-23 05:25:43 +00002019 case Intrinsic::arm_neon_vld1: {
2020 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2021 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002022 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2023 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson621f1952010-03-23 05:25:43 +00002024 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2025 }
2026
Bob Wilson31fb12f2009-08-26 17:39:53 +00002027 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002028 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2029 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2030 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2031 ARM::VLD2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002032 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002033 }
2034
2035 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002036 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2037 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2038 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2039 ARM::VLD3q16Pseudo_UPD,
2040 ARM::VLD3q32Pseudo_UPD };
2041 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2042 ARM::VLD3q16oddPseudo_UPD,
2043 ARM::VLD3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002044 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002045 }
2046
2047 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002048 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2049 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2050 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2051 ARM::VLD4q16Pseudo_UPD,
2052 ARM::VLD4q32Pseudo_UPD };
2053 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2054 ARM::VLD4q16oddPseudo_UPD,
2055 ARM::VLD4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002056 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002057 }
2058
Bob Wilson243fcc52009-09-01 04:26:28 +00002059 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002060 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2061 ARM::VLD2LNd32Pseudo };
2062 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
2063 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002064 }
2065
2066 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002067 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2068 ARM::VLD3LNd32Pseudo };
2069 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
2070 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002071 }
2072
2073 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002074 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2075 ARM::VLD4LNd32Pseudo };
2076 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
2077 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002078 }
2079
Bob Wilson11d98992010-03-23 06:20:33 +00002080 case Intrinsic::arm_neon_vst1: {
2081 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2082 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002083 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2084 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson11d98992010-03-23 06:20:33 +00002085 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2086 }
2087
Bob Wilson31fb12f2009-08-26 17:39:53 +00002088 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002089 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2090 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2091 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2092 ARM::VST2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002093 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002094 }
2095
2096 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002097 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2098 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2099 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2100 ARM::VST3q16Pseudo_UPD,
2101 ARM::VST3q32Pseudo_UPD };
2102 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2103 ARM::VST3q16oddPseudo_UPD,
2104 ARM::VST3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002105 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002106 }
2107
2108 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002109 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002110 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002111 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2112 ARM::VST4q16Pseudo_UPD,
2113 ARM::VST4q32Pseudo_UPD };
2114 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2115 ARM::VST4q16oddPseudo_UPD,
2116 ARM::VST4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002117 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002118 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002119
2120 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002121 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2122 ARM::VST2LNd32Pseudo };
2123 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
2124 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002125 }
2126
2127 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002128 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2129 ARM::VST3LNd32Pseudo };
2130 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
2131 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002132 }
2133
2134 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002135 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2136 ARM::VST4LNd32Pseudo };
2137 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
2138 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002139 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002140 }
Bob Wilson429009b2010-05-06 16:05:26 +00002141 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002142 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002143
Bob Wilsond491d6e2010-07-06 23:36:25 +00002144 case ISD::INTRINSIC_WO_CHAIN: {
2145 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2146 switch (IntNo) {
2147 default:
2148 break;
2149
2150 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002151 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002152 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002153 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002154 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002155 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002156
2157 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002158 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002159 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002160 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002161 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002162 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002163 }
2164 break;
2165 }
2166
Bob Wilson429009b2010-05-06 16:05:26 +00002167 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002168 return SelectConcatVector(N);
2169 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002170
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002171 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002172}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002173
Bob Wilson224c2442009-05-19 05:53:42 +00002174bool ARMDAGToDAGISel::
2175SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2176 std::vector<SDValue> &OutOps) {
2177 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002178 // Require the address to be in a register. That is safe for all ARM
2179 // variants and it is hard to do anything much smarter without knowing
2180 // how the operand is used.
2181 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002182 return false;
2183}
2184
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002185/// createARMISelDag - This pass converts a legalized DAG into a
2186/// ARM-specific DAG, ready for instruction scheduling.
2187///
Bob Wilson522ce972009-09-28 14:30:20 +00002188FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2189 CodeGenOpt::Level OptLevel) {
2190 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002191}