blob: 456311ff25eb562befc2ab25171354cae606dafd [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 {
49class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000050 ARMBaseTargetMachine &TM;
Evan Cheng3f7eb8e2008-09-18 07:24:33 +000051
Evan Chenga8e29892007-01-19 07:51:42 +000052 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
53 /// make the right decision when generating code for different targets.
54 const ARMSubtarget *Subtarget;
55
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000056public:
Bob Wilson522ce972009-09-28 14:30:20 +000057 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
58 CodeGenOpt::Level OptLevel)
59 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Chenga8e29892007-01-19 07:51:42 +000060 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000061 }
62
Evan Chenga8e29892007-01-19 07:51:42 +000063 virtual const char *getPassName() const {
64 return "ARM Instruction Selection";
Anton Korobeynikov52237112009-06-17 18:13:58 +000065 }
66
Bob Wilsonaf4a8912009-10-08 18:51:31 +000067 /// getI32Imm - Return a target constant of type i32 with the specified
68 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000069 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000070 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000071 }
72
Dan Gohmaneeb3a002010-01-05 01:24:18 +000073 SDNode *Select(SDNode *N);
Evan Cheng014bf212010-02-15 19:41:07 +000074
Dan Gohmaneeb3a002010-01-05 01:24:18 +000075 bool SelectShifterOperandReg(SDNode *Op, SDValue N, SDValue &A,
Evan Cheng055b0312009-06-29 07:51:04 +000076 SDValue &B, SDValue &C);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000077 bool SelectAddrMode2(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000078 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000079 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +000080 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000081 bool SelectAddrMode3(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000082 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000083 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +000084 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000085 bool SelectAddrMode4(SDNode *Op, SDValue N, SDValue &Addr,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +000086 SDValue &Mode);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000087 bool SelectAddrMode5(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000088 SDValue &Offset);
Bob Wilson226036e2010-03-20 22:13:40 +000089 bool SelectAddrMode6(SDNode *Op, SDValue N, SDValue &Addr, SDValue &Align);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000090
Dan Gohmaneeb3a002010-01-05 01:24:18 +000091 bool SelectAddrModePC(SDNode *Op, SDValue N, SDValue &Offset,
Bob Wilson8b024a52009-07-01 23:16:05 +000092 SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +000093
Dan Gohmaneeb3a002010-01-05 01:24:18 +000094 bool SelectThumbAddrModeRR(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000095 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000096 bool SelectThumbAddrModeRI5(SDNode *Op, SDValue N, unsigned Scale,
Dan Gohman475871a2008-07-27 21:46:04 +000097 SDValue &Base, SDValue &OffImm,
98 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000099 bool SelectThumbAddrModeS1(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000100 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000101 bool SelectThumbAddrModeS2(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000102 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000103 bool SelectThumbAddrModeS4(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000104 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000105 bool SelectThumbAddrModeSP(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000106 SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000107
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000108 bool SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000109 SDValue &BaseReg, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000110 bool SelectT2AddrModeImm12(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000111 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000112 bool SelectT2AddrModeImm8(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000113 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000114 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000115 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000116 bool SelectT2AddrModeSoReg(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000117 SDValue &OffReg, SDValue &ShImm);
118
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000119 inline bool Pred_so_imm(SDNode *inN) const {
120 ConstantSDNode *N = cast<ConstantSDNode>(inN);
121 return ARM_AM::getSOImmVal(N->getZExtValue()) != -1;
122 }
123
124 inline bool Pred_t2_so_imm(SDNode *inN) const {
125 ConstantSDNode *N = cast<ConstantSDNode>(inN);
126 return ARM_AM::getT2SOImmVal(N->getZExtValue()) != -1;
127 }
128
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000129 // Include the pieces autogenerated from the target description.
130#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000131
132private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000133 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
134 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000135 SDNode *SelectARMIndexedLoad(SDNode *N);
136 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000137
Bob Wilson621f1952010-03-23 05:25:43 +0000138 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
139 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000140 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000141 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000142 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000143 unsigned *QOpcodes0, unsigned *QOpcodes1);
144
Bob Wilson24f995d2009-10-14 18:32:29 +0000145 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000146 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000147 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000148 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000149 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000150 unsigned *QOpcodes0, unsigned *QOpcodes1);
151
Bob Wilson96493442009-10-14 16:46:45 +0000152 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000153 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson96493442009-10-14 16:46:45 +0000154 /// load/store of D registers and even subregs and odd subregs of Q registers.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000155 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
Bob Wilson96493442009-10-14 16:46:45 +0000156 unsigned *DOpcodes, unsigned *QOpcodes0,
157 unsigned *QOpcodes1);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000158
Bob Wilson78dfbc32010-07-07 00:08:54 +0000159 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
160 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
161 /// generated to force the table registers to be consecutive.
162 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000163
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000164 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000165 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000166
Evan Cheng07ba9062009-11-19 21:45:22 +0000167 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000168 SDNode *SelectCMOVOp(SDNode *N);
169 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000170 ARMCC::CondCodes CCVal, SDValue CCR,
171 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000172 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000173 ARMCC::CondCodes CCVal, SDValue CCR,
174 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000175 SDNode *SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000176 ARMCC::CondCodes CCVal, SDValue CCR,
177 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000178 SDNode *SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000179 ARMCC::CondCodes CCVal, SDValue CCR,
180 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000181
Evan Chengde8aa4e2010-05-05 18:28:36 +0000182 SDNode *SelectConcatVector(SDNode *N);
183
Evan Chengaf4550f2009-07-02 01:23:32 +0000184 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
185 /// inline asm expressions.
186 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
187 char ConstraintCode,
188 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000189
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000190 // Form pairs of consecutive S, D, or Q registers.
191 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000192 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000193 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
194
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000195 // Form sequences of 4 consecutive S, D, or Q registers.
196 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000197 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000198 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
199
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000200 // Form sequences of 8 consecutive D registers.
Evan Cheng5c6aba22010-05-14 18:54:59 +0000201 SDNode *OctoDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3,
202 SDValue V4, SDValue V5, SDValue V6, SDValue V7);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000203};
Evan Chenga8e29892007-01-19 07:51:42 +0000204}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000205
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000206/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
207/// operand. If so Imm will receive the 32-bit value.
208static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
209 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
210 Imm = cast<ConstantSDNode>(N)->getZExtValue();
211 return true;
212 }
213 return false;
214}
215
216// isInt32Immediate - This method tests to see if a constant operand.
217// If so Imm will receive the 32 bit value.
218static bool isInt32Immediate(SDValue N, unsigned &Imm) {
219 return isInt32Immediate(N.getNode(), Imm);
220}
221
222// isOpcWithIntImmediate - This method tests to see if the node is a specific
223// opcode and that it has a immediate integer right operand.
224// If so Imm will receive the 32 bit value.
225static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
226 return N->getOpcode() == Opc &&
227 isInt32Immediate(N->getOperand(1).getNode(), Imm);
228}
229
230
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000231bool ARMDAGToDAGISel::SelectShifterOperandReg(SDNode *Op,
Evan Cheng055b0312009-06-29 07:51:04 +0000232 SDValue N,
233 SDValue &BaseReg,
234 SDValue &ShReg,
235 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000236 if (DisableShifterOp)
237 return false;
238
Evan Cheng055b0312009-06-29 07:51:04 +0000239 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
240
241 // Don't match base register only case. That is matched to a separate
242 // lower complexity pattern with explicit register operand.
243 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000244
Evan Cheng055b0312009-06-29 07:51:04 +0000245 BaseReg = N.getOperand(0);
246 unsigned ShImmVal = 0;
247 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000248 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000249 ShImmVal = RHS->getZExtValue() & 31;
250 } else {
251 ShReg = N.getOperand(1);
252 }
253 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000254 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000255 return true;
256}
257
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000258bool ARMDAGToDAGISel::SelectAddrMode2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000259 SDValue &Base, SDValue &Offset,
260 SDValue &Opc) {
Evan Chenga13fd102007-03-13 21:05:54 +0000261 if (N.getOpcode() == ISD::MUL) {
262 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
263 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000264 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000265 if (RHSC & 1) {
266 RHSC = RHSC & ~1;
267 ARM_AM::AddrOpc AddSub = ARM_AM::add;
268 if (RHSC < 0) {
269 AddSub = ARM_AM::sub;
270 RHSC = - RHSC;
271 }
272 if (isPowerOf2_32(RHSC)) {
273 unsigned ShAmt = Log2_32(RHSC);
274 Base = Offset = N.getOperand(0);
275 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
276 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000277 MVT::i32);
Evan Chenga13fd102007-03-13 21:05:54 +0000278 return true;
279 }
280 }
281 }
282 }
283
Evan Chenga8e29892007-01-19 07:51:42 +0000284 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
285 Base = N;
286 if (N.getOpcode() == ISD::FrameIndex) {
287 int FI = cast<FrameIndexSDNode>(N)->getIndex();
288 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000289 } else if (N.getOpcode() == ARMISD::Wrapper &&
290 !(Subtarget->useMovt() &&
291 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000292 Base = N.getOperand(0);
293 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000294 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000295 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
296 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000297 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000298 return true;
299 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000300
Evan Chenga8e29892007-01-19 07:51:42 +0000301 // Match simple R +/- imm12 operands.
302 if (N.getOpcode() == ISD::ADD)
303 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000304 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000305 if ((RHSC >= 0 && RHSC < 0x1000) ||
306 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000307 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000308 if (Base.getOpcode() == ISD::FrameIndex) {
309 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
310 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
311 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000312 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000313
314 ARM_AM::AddrOpc AddSub = ARM_AM::add;
315 if (RHSC < 0) {
316 AddSub = ARM_AM::sub;
317 RHSC = - RHSC;
318 }
319 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000320 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000321 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000322 return true;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000323 }
Evan Chenga8e29892007-01-19 07:51:42 +0000324 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000325
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000326 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000327 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
328 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
329 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000330
Evan Chenga8e29892007-01-19 07:51:42 +0000331 Base = N.getOperand(0);
332 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000333
Evan Chenga8e29892007-01-19 07:51:42 +0000334 if (ShOpcVal != ARM_AM::no_shift) {
335 // Check to see if the RHS of the shift is a constant, if not, we can't fold
336 // it.
337 if (ConstantSDNode *Sh =
338 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000339 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000340 Offset = N.getOperand(1).getOperand(0);
341 } else {
342 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000343 }
344 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000345
Evan Chenga8e29892007-01-19 07:51:42 +0000346 // Try matching (R shl C) + (R).
347 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
348 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
349 if (ShOpcVal != ARM_AM::no_shift) {
350 // Check to see if the RHS of the shift is a constant, if not, we can't
351 // fold it.
352 if (ConstantSDNode *Sh =
353 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000354 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000355 Offset = N.getOperand(0).getOperand(0);
356 Base = N.getOperand(1);
357 } else {
358 ShOpcVal = ARM_AM::no_shift;
359 }
360 }
361 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000362
Evan Chenga8e29892007-01-19 07:51:42 +0000363 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000364 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000365 return true;
366}
367
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000368bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000369 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000370 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000371 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
372 ? cast<LoadSDNode>(Op)->getAddressingMode()
373 : cast<StoreSDNode>(Op)->getAddressingMode();
374 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
375 ? ARM_AM::add : ARM_AM::sub;
376 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000377 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000378 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000379 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000380 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
381 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000382 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000383 return true;
384 }
385 }
386
387 Offset = N;
388 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
389 unsigned ShAmt = 0;
390 if (ShOpcVal != ARM_AM::no_shift) {
391 // Check to see if the RHS of the shift is a constant, if not, we can't fold
392 // it.
393 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000394 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000395 Offset = N.getOperand(0);
396 } else {
397 ShOpcVal = ARM_AM::no_shift;
398 }
399 }
400
401 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000402 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000403 return true;
404}
405
Evan Chenga8e29892007-01-19 07:51:42 +0000406
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000407bool ARMDAGToDAGISel::SelectAddrMode3(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000408 SDValue &Base, SDValue &Offset,
409 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000410 if (N.getOpcode() == ISD::SUB) {
411 // X - C is canonicalize to X + -C, no need to handle it here.
412 Base = N.getOperand(0);
413 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000414 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000415 return true;
416 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000417
Evan Chenga8e29892007-01-19 07:51:42 +0000418 if (N.getOpcode() != ISD::ADD) {
419 Base = N;
420 if (N.getOpcode() == ISD::FrameIndex) {
421 int FI = cast<FrameIndexSDNode>(N)->getIndex();
422 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
423 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000424 Offset = CurDAG->getRegister(0, MVT::i32);
425 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000426 return true;
427 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000428
Evan Chenga8e29892007-01-19 07:51:42 +0000429 // If the RHS is +/- imm8, fold into addr mode.
430 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000431 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000432 if ((RHSC >= 0 && RHSC < 256) ||
433 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000434 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000435 if (Base.getOpcode() == ISD::FrameIndex) {
436 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
437 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
438 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000439 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000440
441 ARM_AM::AddrOpc AddSub = ARM_AM::add;
442 if (RHSC < 0) {
443 AddSub = ARM_AM::sub;
444 RHSC = - RHSC;
445 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000446 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000447 return true;
448 }
449 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000450
Evan Chenga8e29892007-01-19 07:51:42 +0000451 Base = N.getOperand(0);
452 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000453 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000454 return true;
455}
456
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000457bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000458 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000459 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000460 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
461 ? cast<LoadSDNode>(Op)->getAddressingMode()
462 : cast<StoreSDNode>(Op)->getAddressingMode();
463 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
464 ? ARM_AM::add : ARM_AM::sub;
465 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000466 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000467 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000468 Offset = CurDAG->getRegister(0, MVT::i32);
469 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000470 return true;
471 }
472 }
473
474 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000475 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000476 return true;
477}
478
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000479bool ARMDAGToDAGISel::SelectAddrMode4(SDNode *Op, SDValue N,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000480 SDValue &Addr, SDValue &Mode) {
481 Addr = N;
Bob Wilsonfd7fd942010-08-28 00:20:11 +0000482 Mode = CurDAG->getTargetConstant(ARM_AM::getAM4ModeImm(ARM_AM::ia), MVT::i32);
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000483 return true;
484}
Evan Chenga8e29892007-01-19 07:51:42 +0000485
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000486bool ARMDAGToDAGISel::SelectAddrMode5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000487 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000488 if (N.getOpcode() != ISD::ADD) {
489 Base = N;
490 if (N.getOpcode() == ISD::FrameIndex) {
491 int FI = cast<FrameIndexSDNode>(N)->getIndex();
492 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000493 } else if (N.getOpcode() == ARMISD::Wrapper &&
494 !(Subtarget->useMovt() &&
495 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000496 Base = N.getOperand(0);
497 }
498 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000499 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000500 return true;
501 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000502
Evan Chenga8e29892007-01-19 07:51:42 +0000503 // If the RHS is +/- imm8, fold into addr mode.
504 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000505 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000506 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
507 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000508 if ((RHSC >= 0 && RHSC < 256) ||
509 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000510 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000511 if (Base.getOpcode() == ISD::FrameIndex) {
512 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
513 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
514 }
515
516 ARM_AM::AddrOpc AddSub = ARM_AM::add;
517 if (RHSC < 0) {
518 AddSub = ARM_AM::sub;
519 RHSC = - RHSC;
520 }
521 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000522 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000523 return true;
524 }
525 }
526 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000527
Evan Chenga8e29892007-01-19 07:51:42 +0000528 Base = N;
529 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000530 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000531 return true;
532}
533
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000534bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Op, SDValue N,
Bob Wilson226036e2010-03-20 22:13:40 +0000535 SDValue &Addr, SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000536 Addr = N;
Jim Grosbach8a5ec862009-11-07 21:25:39 +0000537 // Default to no alignment.
538 Align = CurDAG->getTargetConstant(0, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000539 return true;
540}
541
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000542bool ARMDAGToDAGISel::SelectAddrModePC(SDNode *Op, SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000543 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000544 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
545 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000546 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000547 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000548 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000549 return true;
550 }
551 return false;
552}
553
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000554bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000555 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000556 // FIXME dl should come from the parent load or store, not the address
Evan Chengc38f2bc2007-01-23 22:59:13 +0000557 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000558 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000559 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000560 return false;
561
562 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000563 return true;
564 }
565
Evan Chenga8e29892007-01-19 07:51:42 +0000566 Base = N.getOperand(0);
567 Offset = N.getOperand(1);
568 return true;
569}
570
Evan Cheng79d43262007-01-24 02:21:22 +0000571bool
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000572ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000573 unsigned Scale, SDValue &Base,
574 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000575 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000576 SDValue TmpBase, TmpOffImm;
Evan Cheng79d43262007-01-24 02:21:22 +0000577 if (SelectThumbAddrModeSP(Op, N, TmpBase, TmpOffImm))
578 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000579 if (N.getOpcode() == ARMISD::Wrapper &&
580 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
581 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000582 }
583
Evan Chenga8e29892007-01-19 07:51:42 +0000584 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000585 if (N.getOpcode() == ARMISD::Wrapper &&
586 !(Subtarget->useMovt() &&
587 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
588 Base = N.getOperand(0);
589 } else
590 Base = N;
591
Owen Anderson825b72b2009-08-11 20:47:22 +0000592 Offset = CurDAG->getRegister(0, MVT::i32);
593 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000594 return true;
595 }
596
Evan Chengad0e4652007-02-06 00:22:06 +0000597 // Thumb does not have [sp, r] address mode.
598 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
599 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
600 if ((LHSR && LHSR->getReg() == ARM::SP) ||
601 (RHSR && RHSR->getReg() == ARM::SP)) {
602 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000603 Offset = CurDAG->getRegister(0, MVT::i32);
604 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000605 return true;
606 }
607
Evan Chenga8e29892007-01-19 07:51:42 +0000608 // If the RHS is + imm5 * scale, fold into addr mode.
609 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000610 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000611 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
612 RHSC /= Scale;
613 if (RHSC >= 0 && RHSC < 32) {
614 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000615 Offset = CurDAG->getRegister(0, MVT::i32);
616 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000617 return true;
618 }
619 }
620 }
621
Evan Chengc38f2bc2007-01-23 22:59:13 +0000622 Base = N.getOperand(0);
623 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000624 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000625 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000626}
627
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000628bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000629 SDValue &Base, SDValue &OffImm,
630 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000631 return SelectThumbAddrModeRI5(Op, N, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000632}
633
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000634bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000635 SDValue &Base, SDValue &OffImm,
636 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000637 return SelectThumbAddrModeRI5(Op, N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000638}
639
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000640bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000641 SDValue &Base, SDValue &OffImm,
642 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000643 return SelectThumbAddrModeRI5(Op, N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000644}
645
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000646bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000647 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000648 if (N.getOpcode() == ISD::FrameIndex) {
649 int FI = cast<FrameIndexSDNode>(N)->getIndex();
650 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000651 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000652 return true;
653 }
Evan Cheng79d43262007-01-24 02:21:22 +0000654
Evan Chengad0e4652007-02-06 00:22:06 +0000655 if (N.getOpcode() != ISD::ADD)
656 return false;
657
658 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000659 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
660 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000661 // If the RHS is + imm8 * scale, fold into addr mode.
662 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000663 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000664 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
665 RHSC >>= 2;
666 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000667 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000668 if (Base.getOpcode() == ISD::FrameIndex) {
669 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
670 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
671 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000672 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000673 return true;
674 }
675 }
676 }
677 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000678
Evan Chenga8e29892007-01-19 07:51:42 +0000679 return false;
680}
681
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000682bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000683 SDValue &BaseReg,
684 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000685 if (DisableShifterOp)
686 return false;
687
Evan Cheng9cb9e672009-06-27 02:26:13 +0000688 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
689
690 // Don't match base register only case. That is matched to a separate
691 // lower complexity pattern with explicit register operand.
692 if (ShOpcVal == ARM_AM::no_shift) return false;
693
694 BaseReg = N.getOperand(0);
695 unsigned ShImmVal = 0;
696 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
697 ShImmVal = RHS->getZExtValue() & 31;
698 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
699 return true;
700 }
701
702 return false;
703}
704
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000705bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000706 SDValue &Base, SDValue &OffImm) {
707 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000708
Evan Cheng3a214252009-08-11 08:52:18 +0000709 // Base only.
710 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000711 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000712 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000713 int FI = cast<FrameIndexSDNode>(N)->getIndex();
714 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000715 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000716 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000717 } else if (N.getOpcode() == ARMISD::Wrapper &&
718 !(Subtarget->useMovt() &&
719 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000720 Base = N.getOperand(0);
721 if (Base.getOpcode() == ISD::TargetConstantPool)
722 return false; // We want to select t2LDRpci instead.
723 } else
724 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000725 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000726 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000727 }
Evan Cheng055b0312009-06-29 07:51:04 +0000728
729 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Evan Cheng3a214252009-08-11 08:52:18 +0000730 if (SelectT2AddrModeImm8(Op, N, Base, OffImm))
731 // Let t2LDRi8 handle (R - imm8).
732 return false;
733
Evan Cheng055b0312009-06-29 07:51:04 +0000734 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000735 if (N.getOpcode() == ISD::SUB)
736 RHSC = -RHSC;
737
738 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +0000739 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +0000740 if (Base.getOpcode() == ISD::FrameIndex) {
741 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
742 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
743 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000744 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000745 return true;
746 }
747 }
748
Evan Cheng3a214252009-08-11 08:52:18 +0000749 // Base only.
750 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000751 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000752 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000753}
754
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000755bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000756 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +0000757 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +0000758 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +0000759 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
760 int RHSC = (int)RHS->getSExtValue();
761 if (N.getOpcode() == ISD::SUB)
762 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +0000763
Evan Cheng3a214252009-08-11 08:52:18 +0000764 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
765 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +0000766 if (Base.getOpcode() == ISD::FrameIndex) {
767 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
768 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
769 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000770 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +0000771 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000772 }
Evan Cheng055b0312009-06-29 07:51:04 +0000773 }
774 }
775
776 return false;
777}
778
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000779bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000780 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000781 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +0000782 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
783 ? cast<LoadSDNode>(Op)->getAddressingMode()
784 : cast<StoreSDNode>(Op)->getAddressingMode();
785 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
786 int RHSC = (int)RHS->getZExtValue();
787 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +0000788 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +0000789 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
790 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000791 return true;
792 }
793 }
794
795 return false;
796}
797
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000798bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000799 SDValue &Base,
800 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +0000801 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
802 if (N.getOpcode() != ISD::ADD)
803 return false;
Evan Cheng055b0312009-06-29 07:51:04 +0000804
Evan Cheng3a214252009-08-11 08:52:18 +0000805 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
806 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
807 int RHSC = (int)RHS->getZExtValue();
808 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
809 return false;
810 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +0000811 return false;
812 }
813
Evan Cheng055b0312009-06-29 07:51:04 +0000814 // Look for (R + R) or (R + (R << [1,2,3])).
815 unsigned ShAmt = 0;
816 Base = N.getOperand(0);
817 OffReg = N.getOperand(1);
818
819 // Swap if it is ((R << c) + R).
820 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
821 if (ShOpcVal != ARM_AM::lsl) {
822 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
823 if (ShOpcVal == ARM_AM::lsl)
824 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +0000825 }
826
Evan Cheng055b0312009-06-29 07:51:04 +0000827 if (ShOpcVal == ARM_AM::lsl) {
828 // Check to see if the RHS of the shift is a constant, if not, we can't fold
829 // it.
830 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
831 ShAmt = Sh->getZExtValue();
832 if (ShAmt >= 4) {
833 ShAmt = 0;
834 ShOpcVal = ARM_AM::no_shift;
835 } else
836 OffReg = OffReg.getOperand(0);
837 } else {
838 ShOpcVal = ARM_AM::no_shift;
839 }
David Goodwin7ecc8502009-07-15 15:50:19 +0000840 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000841
Owen Anderson825b72b2009-08-11 20:47:22 +0000842 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000843
844 return true;
845}
846
847//===--------------------------------------------------------------------===//
848
Evan Chengee568cf2007-07-05 07:15:27 +0000849/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +0000850static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000851 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +0000852}
853
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000854SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
855 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +0000856 ISD::MemIndexedMode AM = LD->getAddressingMode();
857 if (AM == ISD::UNINDEXED)
858 return NULL;
859
Owen Andersone50ed302009-08-10 22:56:29 +0000860 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +0000861 SDValue Offset, AMOpc;
862 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
863 unsigned Opcode = 0;
864 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000865 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000866 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000867 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
868 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +0000869 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000870 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000871 Match = true;
872 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
873 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
874 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +0000875 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000876 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000877 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000878 Match = true;
879 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
880 }
881 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000882 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000883 Match = true;
884 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
885 }
886 }
887 }
888
889 if (Match) {
890 SDValue Chain = LD->getChain();
891 SDValue Base = LD->getBasePtr();
892 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000893 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000894 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000895 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +0000896 }
897
898 return NULL;
899}
900
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000901SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
902 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000903 ISD::MemIndexedMode AM = LD->getAddressingMode();
904 if (AM == ISD::UNINDEXED)
905 return NULL;
906
Owen Andersone50ed302009-08-10 22:56:29 +0000907 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +0000908 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000909 SDValue Offset;
910 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
911 unsigned Opcode = 0;
912 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000913 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000914 switch (LoadedVT.getSimpleVT().SimpleTy) {
915 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000916 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
917 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000918 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000919 if (isSExtLd)
920 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
921 else
922 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000923 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000924 case MVT::i8:
925 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000926 if (isSExtLd)
927 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
928 else
929 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000930 break;
931 default:
932 return NULL;
933 }
934 Match = true;
935 }
936
937 if (Match) {
938 SDValue Chain = LD->getChain();
939 SDValue Base = LD->getBasePtr();
940 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000941 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000942 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000943 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000944 }
945
946 return NULL;
947}
948
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000949/// PairSRegs - Form a D register from a pair of S registers.
950///
951SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
952 DebugLoc dl = V0.getNode()->getDebugLoc();
953 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
954 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +0000955 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
956 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000957}
958
Evan Cheng603afbf2010-05-10 17:34:18 +0000959/// PairDRegs - Form a quad register from a pair of D registers.
960///
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000961SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
962 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +0000963 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
964 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +0000965 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
966 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000967}
968
Evan Cheng7f687192010-05-14 00:21:45 +0000969/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +0000970///
971SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
972 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +0000973 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
974 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +0000975 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
976 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
977}
978
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000979/// QuadSRegs - Form 4 consecutive S registers.
980///
981SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
982 SDValue V2, SDValue V3) {
983 DebugLoc dl = V0.getNode()->getDebugLoc();
984 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
985 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
986 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
987 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
988 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
989 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
990}
991
Evan Cheng7f687192010-05-14 00:21:45 +0000992/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +0000993///
994SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
995 SDValue V2, SDValue V3) {
996 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +0000997 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
998 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
999 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1000 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001001 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1002 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1003}
1004
Evan Cheng8f6de382010-05-16 03:27:48 +00001005/// QuadQRegs - Form 4 consecutive Q registers.
1006///
1007SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1008 SDValue V2, SDValue V3) {
1009 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001010 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1011 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1012 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1013 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Evan Cheng8f6de382010-05-16 03:27:48 +00001014 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1015 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1016}
1017
Evan Cheng5c6aba22010-05-14 18:54:59 +00001018/// OctoDRegs - Form 8 consecutive D registers.
1019///
1020SDNode *ARMDAGToDAGISel::OctoDRegs(EVT VT, SDValue V0, SDValue V1,
1021 SDValue V2, SDValue V3,
1022 SDValue V4, SDValue V5,
1023 SDValue V6, SDValue V7) {
1024 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001025 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1026 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1027 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1028 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
1029 SDValue SubReg4 = CurDAG->getTargetConstant(ARM::dsub_4, MVT::i32);
1030 SDValue SubReg5 = CurDAG->getTargetConstant(ARM::dsub_5, MVT::i32);
1031 SDValue SubReg6 = CurDAG->getTargetConstant(ARM::dsub_6, MVT::i32);
1032 SDValue SubReg7 = CurDAG->getTargetConstant(ARM::dsub_7, MVT::i32);
Evan Cheng5c6aba22010-05-14 18:54:59 +00001033 const SDValue Ops[] ={ V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3,
1034 V4, SubReg4, V5, SubReg5, V6, SubReg6, V7, SubReg7 };
1035 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 16);
1036}
1037
Bob Wilsona7c397c2009-10-14 16:19:03 +00001038/// GetNEONSubregVT - Given a type for a 128-bit NEON vector, return the type
1039/// for a 64-bit subregister of the vector.
1040static EVT GetNEONSubregVT(EVT VT) {
1041 switch (VT.getSimpleVT().SimpleTy) {
1042 default: llvm_unreachable("unhandled NEON type");
1043 case MVT::v16i8: return MVT::v8i8;
1044 case MVT::v8i16: return MVT::v4i16;
1045 case MVT::v4f32: return MVT::v2f32;
1046 case MVT::v4i32: return MVT::v2i32;
1047 case MVT::v2i64: return MVT::v1i64;
1048 }
1049}
1050
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001051SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001052 unsigned *DOpcodes, unsigned *QOpcodes0,
1053 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001054 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001055 DebugLoc dl = N->getDebugLoc();
1056
Bob Wilson226036e2010-03-20 22:13:40 +00001057 SDValue MemAddr, Align;
1058 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001059 return NULL;
1060
1061 SDValue Chain = N->getOperand(0);
1062 EVT VT = N->getValueType(0);
1063 bool is64BitVector = VT.is64BitVector();
1064
1065 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;
1169 if (!SelectAddrMode6(N, 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
1176 unsigned OpcodeIndex;
1177 switch (VT.getSimpleVT().SimpleTy) {
1178 default: llvm_unreachable("unhandled vst type");
1179 // Double-register operations:
1180 case MVT::v8i8: OpcodeIndex = 0; break;
1181 case MVT::v4i16: OpcodeIndex = 1; break;
1182 case MVT::v2f32:
1183 case MVT::v2i32: OpcodeIndex = 2; break;
1184 case MVT::v1i64: OpcodeIndex = 3; break;
1185 // Quad-register operations:
1186 case MVT::v16i8: OpcodeIndex = 0; break;
1187 case MVT::v8i16: OpcodeIndex = 1; break;
1188 case MVT::v4f32:
1189 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001190 case MVT::v2i64: OpcodeIndex = 3;
1191 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1192 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001193 }
1194
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001195 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001196 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001197
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001198 SmallVector<SDValue, 7> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001199 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001200 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001201
1202 if (is64BitVector) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001203 if (NumVecs == 1) {
1204 Ops.push_back(N->getOperand(3));
1205 } else {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001206 SDValue RegSeq;
1207 SDValue V0 = N->getOperand(0+3);
1208 SDValue V1 = N->getOperand(1+3);
1209
1210 // Form a REG_SEQUENCE to force register allocation.
1211 if (NumVecs == 2)
1212 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1213 else {
1214 SDValue V2 = N->getOperand(2+3);
1215 // If it's a vld3, form a quad D-register and leave the last part as
1216 // an undef.
1217 SDValue V3 = (NumVecs == 3)
1218 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1219 : N->getOperand(3+3);
1220 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1221 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001222 Ops.push_back(RegSeq);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001223 }
Evan Chengac0869d2009-11-21 06:21:52 +00001224 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001225 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001226 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001227 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001228 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001229 }
1230
Bob Wilson11d98992010-03-23 06:20:33 +00001231 if (NumVecs <= 2) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001232 // Quad registers are directly supported for VST1 and VST2.
Bob Wilson24f995d2009-10-14 18:32:29 +00001233 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001234 if (NumVecs == 1) {
1235 Ops.push_back(N->getOperand(3));
1236 } else {
1237 // Form a QQ register.
Evan Cheng603afbf2010-05-10 17:34:18 +00001238 SDValue Q0 = N->getOperand(3);
1239 SDValue Q1 = N->getOperand(4);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001240 Ops.push_back(SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0));
Bob Wilson24f995d2009-10-14 18:32:29 +00001241 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001242 Ops.push_back(Pred);
1243 Ops.push_back(Reg0); // predicate register
1244 Ops.push_back(Chain);
1245 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001246 }
1247
1248 // Otherwise, quad registers are stored with two separate instructions,
1249 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001250
Bob Wilson07f6e802010-06-16 21:34:01 +00001251 // Form the QQQQ REG_SEQUENCE.
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001252 SDValue V0 = N->getOperand(0+3);
1253 SDValue V1 = N->getOperand(1+3);
1254 SDValue V2 = N->getOperand(2+3);
1255 SDValue V3 = (NumVecs == 3)
1256 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1257 : N->getOperand(3+3);
1258 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001259
1260 // Store the even D registers.
Bob Wilson07f6e802010-06-16 21:34:01 +00001261 Ops.push_back(Reg0); // post-access address offset
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001262 Ops.push_back(RegSeq);
Bob Wilson07f6e802010-06-16 21:34:01 +00001263 Ops.push_back(Pred);
1264 Ops.push_back(Reg0); // predicate register
1265 Ops.push_back(Chain);
1266 unsigned Opc = QOpcodes0[OpcodeIndex];
1267 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001268 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001269 Chain = SDValue(VStA, 1);
1270
1271 // Store the odd D registers.
1272 Ops[0] = SDValue(VStA, 0); // MemAddr
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001273 Ops[6] = Chain;
Bob Wilson07f6e802010-06-16 21:34:01 +00001274 Opc = QOpcodes1[OpcodeIndex];
1275 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001276 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001277 Chain = SDValue(VStB, 1);
1278 ReplaceUses(SDValue(N, 0), Chain);
1279 return NULL;
Bob Wilson24f995d2009-10-14 18:32:29 +00001280}
1281
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001282SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001283 unsigned NumVecs, unsigned *DOpcodes,
1284 unsigned *QOpcodes0,
1285 unsigned *QOpcodes1) {
1286 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001287 DebugLoc dl = N->getDebugLoc();
1288
Bob Wilson226036e2010-03-20 22:13:40 +00001289 SDValue MemAddr, Align;
1290 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001291 return NULL;
1292
1293 SDValue Chain = N->getOperand(0);
1294 unsigned Lane =
1295 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001296 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001297 bool is64BitVector = VT.is64BitVector();
1298
Bob Wilson96493442009-10-14 16:46:45 +00001299 // Quad registers are handled by load/store of subregs. Find the subreg info.
Bob Wilsona7c397c2009-10-14 16:19:03 +00001300 unsigned NumElts = 0;
Evan Cheng8f6de382010-05-16 03:27:48 +00001301 bool Even = false;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001302 EVT RegVT = VT;
1303 if (!is64BitVector) {
1304 RegVT = GetNEONSubregVT(VT);
1305 NumElts = RegVT.getVectorNumElements();
Evan Cheng8f6de382010-05-16 03:27:48 +00001306 Even = Lane < NumElts;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001307 }
1308
1309 unsigned OpcodeIndex;
1310 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001311 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001312 // Double-register operations:
1313 case MVT::v8i8: OpcodeIndex = 0; break;
1314 case MVT::v4i16: OpcodeIndex = 1; break;
1315 case MVT::v2f32:
1316 case MVT::v2i32: OpcodeIndex = 2; break;
1317 // Quad-register operations:
1318 case MVT::v8i16: OpcodeIndex = 0; break;
1319 case MVT::v4f32:
1320 case MVT::v4i32: OpcodeIndex = 1; break;
1321 }
1322
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001323 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001324 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001325
Bob Wilson226036e2010-03-20 22:13:40 +00001326 SmallVector<SDValue, 10> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001327 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001328 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001329
1330 unsigned Opc = 0;
1331 if (is64BitVector) {
1332 Opc = DOpcodes[OpcodeIndex];
Bob Wilson07f6e802010-06-16 21:34:01 +00001333 SDValue RegSeq;
1334 SDValue V0 = N->getOperand(0+3);
1335 SDValue V1 = N->getOperand(1+3);
1336 if (NumVecs == 2) {
1337 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001338 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001339 SDValue V2 = N->getOperand(2+3);
1340 SDValue V3 = (NumVecs == 3)
1341 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1342 : N->getOperand(3+3);
1343 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001344 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001345
1346 // Now extract the D registers back out.
1347 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT, RegSeq));
1348 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT, RegSeq));
1349 if (NumVecs > 2)
1350 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT,RegSeq));
1351 if (NumVecs > 3)
1352 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT,RegSeq));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001353 } else {
1354 // Check if this is loading the even or odd subreg of a Q register.
1355 if (Lane < NumElts) {
1356 Opc = QOpcodes0[OpcodeIndex];
1357 } else {
1358 Lane -= NumElts;
1359 Opc = QOpcodes1[OpcodeIndex];
1360 }
Evan Cheng8f6de382010-05-16 03:27:48 +00001361
Bob Wilson07f6e802010-06-16 21:34:01 +00001362 SDValue RegSeq;
1363 SDValue V0 = N->getOperand(0+3);
1364 SDValue V1 = N->getOperand(1+3);
1365 if (NumVecs == 2) {
1366 RegSeq = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001367 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001368 SDValue V2 = N->getOperand(2+3);
1369 SDValue V3 = (NumVecs == 3)
1370 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1371 : N->getOperand(3+3);
1372 RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001373 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001374
1375 // Extract the subregs of the input vector.
1376 unsigned SubIdx = Even ? ARM::dsub_0 : ARM::dsub_1;
1377 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1378 Ops.push_back(CurDAG->getTargetExtractSubreg(SubIdx+Vec*2, dl, RegVT,
1379 RegSeq));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001380 }
1381 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001382 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001383 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001384 Ops.push_back(Chain);
1385
Bob Wilson96493442009-10-14 16:46:45 +00001386 if (!IsLoad)
Bob Wilson226036e2010-03-20 22:13:40 +00001387 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson96493442009-10-14 16:46:45 +00001388
Bob Wilsona7c397c2009-10-14 16:19:03 +00001389 std::vector<EVT> ResTys(NumVecs, RegVT);
1390 ResTys.push_back(MVT::Other);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001391 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(),NumVecs+6);
1392
Bob Wilson07f6e802010-06-16 21:34:01 +00001393 // Form a REG_SEQUENCE to force register allocation.
1394 SDValue RegSeq;
1395 if (is64BitVector) {
1396 SDValue V0 = SDValue(VLdLn, 0);
1397 SDValue V1 = SDValue(VLdLn, 1);
1398 if (NumVecs == 2) {
1399 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng7189fd02010-05-15 07:53:37 +00001400 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001401 SDValue V2 = SDValue(VLdLn, 2);
1402 // If it's a vld3, form a quad D-register but discard the last part.
1403 SDValue V3 = (NumVecs == 3)
1404 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1405 : SDValue(VLdLn, 3);
1406 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001407 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001408 } else {
1409 // For 128-bit vectors, take the 64-bit results of the load and insert
1410 // them as subregs into the result.
1411 SDValue V[8];
1412 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
1413 if (Even) {
1414 V[i] = SDValue(VLdLn, Vec);
1415 V[i+1] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1416 dl, RegVT), 0);
1417 } else {
1418 V[i] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1419 dl, RegVT), 0);
1420 V[i+1] = SDValue(VLdLn, Vec);
1421 }
1422 }
1423 if (NumVecs == 3)
1424 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1425 dl, RegVT), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001426
Bob Wilson07f6e802010-06-16 21:34:01 +00001427 if (NumVecs == 2)
1428 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V[0], V[1], V[2], V[3]), 0);
1429 else
1430 RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1431 V[4], V[5], V[6], V[7]), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001432 }
1433
Bob Wilson07f6e802010-06-16 21:34:01 +00001434 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1435 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1436 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
1437 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1438 ReplaceUses(SDValue(N, Vec),
1439 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, RegSeq));
1440 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, NumVecs));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001441 return NULL;
1442}
1443
Bob Wilson78dfbc32010-07-07 00:08:54 +00001444SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1445 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001446 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1447 DebugLoc dl = N->getDebugLoc();
1448 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001449 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001450
1451 // Form a REG_SEQUENCE to force register allocation.
1452 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001453 SDValue V0 = N->getOperand(FirstTblReg + 0);
1454 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001455 if (NumVecs == 2)
1456 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1457 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001458 SDValue V2 = N->getOperand(FirstTblReg + 2);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001459 // If it's a vtbl3, form a quad D-register and leave the last part as
1460 // an undef.
1461 SDValue V3 = (NumVecs == 3)
1462 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001463 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001464 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1465 }
1466
1467 // Now extract the D registers back out.
Bob Wilson78dfbc32010-07-07 00:08:54 +00001468 SmallVector<SDValue, 6> Ops;
1469 if (IsExt)
1470 Ops.push_back(N->getOperand(1));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001471 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT, RegSeq));
1472 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT, RegSeq));
1473 if (NumVecs > 2)
1474 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT, RegSeq));
1475 if (NumVecs > 3)
1476 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT, RegSeq));
1477
Bob Wilson78dfbc32010-07-07 00:08:54 +00001478 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001479 Ops.push_back(getAL(CurDAG)); // predicate
1480 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001481 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001482}
1483
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001484SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001485 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001486 if (!Subtarget->hasV6T2Ops())
1487 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001488
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001489 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1490 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1491
1492
1493 // For unsigned extracts, check for a shift right and mask
1494 unsigned And_imm = 0;
1495 if (N->getOpcode() == ISD::AND) {
1496 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1497
1498 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1499 if (And_imm & (And_imm + 1))
1500 return NULL;
1501
1502 unsigned Srl_imm = 0;
1503 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1504 Srl_imm)) {
1505 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1506
1507 unsigned Width = CountTrailingOnes_32(And_imm);
1508 unsigned LSB = Srl_imm;
1509 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1510 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1511 CurDAG->getTargetConstant(LSB, MVT::i32),
1512 CurDAG->getTargetConstant(Width, MVT::i32),
1513 getAL(CurDAG), Reg0 };
1514 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1515 }
1516 }
1517 return NULL;
1518 }
1519
1520 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001521 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001522 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001523 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1524 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001525 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001526 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1527 unsigned Width = 32 - Srl_imm;
1528 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001529 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001530 return NULL;
1531 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001532 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001533 CurDAG->getTargetConstant(LSB, MVT::i32),
1534 CurDAG->getTargetConstant(Width, MVT::i32),
1535 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001536 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001537 }
1538 }
1539 return NULL;
1540}
1541
Evan Cheng9ef48352009-11-20 00:54:03 +00001542SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001543SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001544 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1545 SDValue CPTmp0;
1546 SDValue CPTmp1;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001547 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001548 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1549 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1550 unsigned Opc = 0;
1551 switch (SOShOp) {
1552 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1553 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1554 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1555 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1556 default:
1557 llvm_unreachable("Unknown so_reg opcode!");
1558 break;
1559 }
1560 SDValue SOShImm =
1561 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1562 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1563 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001564 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001565 }
1566 return 0;
1567}
1568
1569SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001570SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001571 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1572 SDValue CPTmp0;
1573 SDValue CPTmp1;
1574 SDValue CPTmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001575 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001576 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1577 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001578 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001579 }
1580 return 0;
1581}
1582
1583SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001584SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001585 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1586 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1587 if (!T)
1588 return 0;
1589
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00001590 if (Pred_t2_so_imm(TrueVal.getNode())) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001591 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1592 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1593 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001594 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001595 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1596 }
1597 return 0;
1598}
1599
1600SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001601SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001602 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1603 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1604 if (!T)
1605 return 0;
1606
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00001607 if (Pred_so_imm(TrueVal.getNode())) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001608 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1609 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1610 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001611 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001612 ARM::MOVCCi, MVT::i32, Ops, 5);
1613 }
1614 return 0;
1615}
1616
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001617SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1618 EVT VT = N->getValueType(0);
1619 SDValue FalseVal = N->getOperand(0);
1620 SDValue TrueVal = N->getOperand(1);
1621 SDValue CC = N->getOperand(2);
1622 SDValue CCR = N->getOperand(3);
1623 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001624 assert(CC.getOpcode() == ISD::Constant);
1625 assert(CCR.getOpcode() == ISD::Register);
1626 ARMCC::CondCodes CCVal =
1627 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001628
1629 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1630 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1631 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1632 // Pattern complexity = 18 cost = 1 size = 0
1633 SDValue CPTmp0;
1634 SDValue CPTmp1;
1635 SDValue CPTmp2;
1636 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001637 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001638 CCVal, CCR, InFlag);
1639 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001640 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001641 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1642 if (Res)
1643 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001644 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001645 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001646 CCVal, CCR, InFlag);
1647 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001648 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001649 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1650 if (Res)
1651 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001652 }
1653
1654 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00001655 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00001656 // (imm:i32):$cc)
1657 // Emits: (MOVCCi:i32 GPR:i32:$false,
1658 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1659 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001660 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001661 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001662 CCVal, CCR, InFlag);
1663 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001664 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001665 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1666 if (Res)
1667 return Res;
1668 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001669 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001670 CCVal, CCR, InFlag);
1671 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001672 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001673 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1674 if (Res)
1675 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001676 }
1677 }
1678
1679 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1680 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1681 // Pattern complexity = 6 cost = 1 size = 0
1682 //
1683 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1684 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1685 // Pattern complexity = 6 cost = 11 size = 0
1686 //
1687 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001688 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1689 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001690 unsigned Opc = 0;
1691 switch (VT.getSimpleVT().SimpleTy) {
1692 default: assert(false && "Illegal conditional move type!");
1693 break;
1694 case MVT::i32:
1695 Opc = Subtarget->isThumb()
1696 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1697 : ARM::MOVCCr;
1698 break;
1699 case MVT::f32:
1700 Opc = ARM::VMOVScc;
1701 break;
1702 case MVT::f64:
1703 Opc = ARM::VMOVDcc;
1704 break;
1705 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001706 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001707}
1708
Evan Chengde8aa4e2010-05-05 18:28:36 +00001709SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
1710 // The only time a CONCAT_VECTORS operation can have legal types is when
1711 // two 64-bit vectors are concatenated to a 128-bit vector.
1712 EVT VT = N->getValueType(0);
1713 if (!VT.is128BitVector() || N->getNumOperands() != 2)
1714 llvm_unreachable("unexpected CONCAT_VECTORS");
1715 DebugLoc dl = N->getDebugLoc();
1716 SDValue V0 = N->getOperand(0);
1717 SDValue V1 = N->getOperand(1);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001718 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1719 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +00001720 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1721 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1722}
1723
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001724SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001725 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001726
Dan Gohmane8be6c62008-07-17 19:10:17 +00001727 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001728 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001729
1730 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001731 default: break;
1732 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001733 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001734 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001735 if (Subtarget->hasThumb2())
1736 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1737 // be done with MOV + MOVT, at worst.
1738 UseCP = 0;
1739 else {
1740 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001741 UseCP = (Val > 255 && // MOV
1742 ~Val > 255 && // MOV + MVN
1743 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001744 } else
1745 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1746 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1747 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1748 }
1749
Evan Chenga8e29892007-01-19 07:51:42 +00001750 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001751 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001752 CurDAG->getTargetConstantPool(ConstantInt::get(
1753 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001754 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001755
1756 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001757 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001758 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001759 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001760 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001761 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1762 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001763 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001764 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001765 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001766 CurDAG->getRegister(0, MVT::i32),
1767 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001768 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001769 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001770 CurDAG->getEntryNode()
1771 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001772 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1773 Ops, 6);
Evan Cheng012f2d92007-01-24 08:53:17 +00001774 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001775 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001776 return NULL;
1777 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001778
Evan Chenga8e29892007-01-19 07:51:42 +00001779 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001780 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001781 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001782 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001783 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001784 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001785 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001786 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001787 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1788 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001789 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001790 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1791 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001792 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1793 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1794 CurDAG->getRegister(0, MVT::i32) };
1795 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001796 }
Evan Chenga8e29892007-01-19 07:51:42 +00001797 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001798 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001799 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001800 return I;
1801 break;
1802 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001803 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001804 return I;
1805 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001806 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001807 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001808 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001809 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001810 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001811 if (!RHSV) break;
1812 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001813 unsigned ShImm = Log2_32(RHSV-1);
1814 if (ShImm >= 32)
1815 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001816 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001817 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001818 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1819 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001820 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001821 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001822 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001823 } else {
1824 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001825 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001826 }
Evan Chenga8e29892007-01-19 07:51:42 +00001827 }
1828 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001829 unsigned ShImm = Log2_32(RHSV+1);
1830 if (ShImm >= 32)
1831 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001832 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001833 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001834 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1835 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001836 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00001837 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1838 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001839 } else {
1840 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001841 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001842 }
Evan Chenga8e29892007-01-19 07:51:42 +00001843 }
1844 }
1845 break;
Evan Cheng20956592009-10-21 08:15:52 +00001846 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001847 // Check for unsigned bitfield extract
1848 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1849 return I;
1850
Evan Cheng20956592009-10-21 08:15:52 +00001851 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1852 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1853 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1854 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1855 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001856 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001857 if (VT != MVT::i32)
1858 break;
1859 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1860 ? ARM::t2MOVTi16
1861 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1862 if (!Opc)
1863 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001864 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001865 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1866 if (!N1C)
1867 break;
1868 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1869 SDValue N2 = N0.getOperand(1);
1870 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1871 if (!N2C)
1872 break;
1873 unsigned N1CVal = N1C->getZExtValue();
1874 unsigned N2CVal = N2C->getZExtValue();
1875 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1876 (N1CVal & 0xffffU) == 0xffffU &&
1877 (N2CVal & 0xffffU) == 0x0U) {
1878 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1879 MVT::i32);
1880 SDValue Ops[] = { N0.getOperand(0), Imm16,
1881 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1882 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
1883 }
1884 }
1885 break;
1886 }
Jim Grosbache5165492009-11-09 00:11:35 +00001887 case ARMISD::VMOVRRD:
1888 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001889 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00001890 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00001891 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001892 if (Subtarget->isThumb1Only())
1893 break;
1894 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001895 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001896 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1897 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00001898 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001899 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001900 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001901 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1902 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001903 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001904 }
Evan Chengee568cf2007-07-05 07:15:27 +00001905 }
Dan Gohman525178c2007-10-08 18:33:35 +00001906 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001907 if (Subtarget->isThumb1Only())
1908 break;
1909 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001910 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001911 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00001912 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001913 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001914 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001915 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1916 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001917 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001918 }
Evan Chengee568cf2007-07-05 07:15:27 +00001919 }
Evan Chenga8e29892007-01-19 07:51:42 +00001920 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00001921 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001922 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001923 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001924 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001925 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001926 if (ResNode)
1927 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00001928 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001929 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001930 }
Evan Chengee568cf2007-07-05 07:15:27 +00001931 case ARMISD::BRCOND: {
1932 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1933 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1934 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001935
Evan Chengee568cf2007-07-05 07:15:27 +00001936 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1937 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
1938 // Pattern complexity = 6 cost = 1 size = 0
1939
David Goodwin5e47a9a2009-06-30 18:04:13 +00001940 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1941 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1942 // Pattern complexity = 6 cost = 1 size = 0
1943
Jim Grosbach764ab522009-08-11 15:33:49 +00001944 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00001945 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001946 SDValue Chain = N->getOperand(0);
1947 SDValue N1 = N->getOperand(1);
1948 SDValue N2 = N->getOperand(2);
1949 SDValue N3 = N->getOperand(3);
1950 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00001951 assert(N1.getOpcode() == ISD::BasicBlock);
1952 assert(N2.getOpcode() == ISD::Constant);
1953 assert(N3.getOpcode() == ISD::Register);
1954
Dan Gohman475871a2008-07-27 21:46:04 +00001955 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001956 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00001957 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00001958 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00001959 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
1960 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00001961 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001962 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00001963 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001964 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00001965 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001966 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00001967 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00001968 return NULL;
1969 }
Evan Cheng07ba9062009-11-19 21:45:22 +00001970 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001971 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00001972 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001973 EVT VT = N->getValueType(0);
1974 SDValue N0 = N->getOperand(0);
1975 SDValue N1 = N->getOperand(1);
1976 SDValue N2 = N->getOperand(2);
1977 SDValue N3 = N->getOperand(3);
1978 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00001979 assert(N2.getOpcode() == ISD::Constant);
1980 assert(N3.getOpcode() == ISD::Register);
1981
Dan Gohman475871a2008-07-27 21:46:04 +00001982 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001983 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00001984 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00001985 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00001986 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00001987 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00001988 default: assert(false && "Illegal conditional move type!");
1989 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001990 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00001991 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00001992 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001993 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00001994 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00001995 break;
Evan Chengee568cf2007-07-05 07:15:27 +00001996 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001997 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001998 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00001999
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002000 case ARMISD::VZIP: {
2001 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002002 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002003 switch (VT.getSimpleVT().SimpleTy) {
2004 default: return NULL;
2005 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2006 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2007 case MVT::v2f32:
2008 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2009 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2010 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2011 case MVT::v4f32:
2012 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2013 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002014 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002015 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2016 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2017 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002018 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002019 case ARMISD::VUZP: {
2020 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002021 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002022 switch (VT.getSimpleVT().SimpleTy) {
2023 default: return NULL;
2024 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2025 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2026 case MVT::v2f32:
2027 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2028 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2029 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2030 case MVT::v4f32:
2031 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2032 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002033 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002034 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2035 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2036 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002037 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002038 case ARMISD::VTRN: {
2039 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002040 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002041 switch (VT.getSimpleVT().SimpleTy) {
2042 default: return NULL;
2043 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2044 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2045 case MVT::v2f32:
2046 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2047 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2048 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2049 case MVT::v4f32:
2050 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2051 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002052 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002053 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2054 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2055 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002056 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002057 case ARMISD::BUILD_VECTOR: {
2058 EVT VecVT = N->getValueType(0);
2059 EVT EltVT = VecVT.getVectorElementType();
2060 unsigned NumElts = VecVT.getVectorNumElements();
2061 if (EltVT.getSimpleVT() == MVT::f64) {
2062 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2063 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2064 }
2065 assert(EltVT.getSimpleVT() == MVT::f32 &&
2066 "unexpected type for BUILD_VECTOR");
2067 if (NumElts == 2)
2068 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2069 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2070 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2071 N->getOperand(2), N->getOperand(3));
2072 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002073
2074 case ISD::INTRINSIC_VOID:
2075 case ISD::INTRINSIC_W_CHAIN: {
2076 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002077 switch (IntNo) {
2078 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002079 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002080
Bob Wilson621f1952010-03-23 05:25:43 +00002081 case Intrinsic::arm_neon_vld1: {
2082 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2083 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002084 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2085 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson621f1952010-03-23 05:25:43 +00002086 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2087 }
2088
Bob Wilson31fb12f2009-08-26 17:39:53 +00002089 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002090 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2091 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2092 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2093 ARM::VLD2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002094 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002095 }
2096
2097 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002098 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2099 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2100 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2101 ARM::VLD3q16Pseudo_UPD,
2102 ARM::VLD3q32Pseudo_UPD };
2103 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2104 ARM::VLD3q16oddPseudo_UPD,
2105 ARM::VLD3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002106 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002107 }
2108
2109 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002110 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2111 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2112 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2113 ARM::VLD4q16Pseudo_UPD,
2114 ARM::VLD4q32Pseudo_UPD };
2115 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2116 ARM::VLD4q16oddPseudo_UPD,
2117 ARM::VLD4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002118 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002119 }
2120
Bob Wilson243fcc52009-09-01 04:26:28 +00002121 case Intrinsic::arm_neon_vld2lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002122 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002123 unsigned QOpcodes0[] = { ARM::VLD2LNq16, ARM::VLD2LNq32 };
2124 unsigned QOpcodes1[] = { ARM::VLD2LNq16odd, ARM::VLD2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002125 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002126 }
2127
2128 case Intrinsic::arm_neon_vld3lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002129 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002130 unsigned QOpcodes0[] = { ARM::VLD3LNq16, ARM::VLD3LNq32 };
2131 unsigned QOpcodes1[] = { ARM::VLD3LNq16odd, ARM::VLD3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002132 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002133 }
2134
2135 case Intrinsic::arm_neon_vld4lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002136 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002137 unsigned QOpcodes0[] = { ARM::VLD4LNq16, ARM::VLD4LNq32 };
2138 unsigned QOpcodes1[] = { ARM::VLD4LNq16odd, ARM::VLD4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002139 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002140 }
2141
Bob Wilson11d98992010-03-23 06:20:33 +00002142 case Intrinsic::arm_neon_vst1: {
2143 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2144 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002145 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2146 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson11d98992010-03-23 06:20:33 +00002147 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2148 }
2149
Bob Wilson31fb12f2009-08-26 17:39:53 +00002150 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002151 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2152 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2153 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2154 ARM::VST2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002155 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002156 }
2157
2158 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002159 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2160 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2161 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2162 ARM::VST3q16Pseudo_UPD,
2163 ARM::VST3q32Pseudo_UPD };
2164 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2165 ARM::VST3q16oddPseudo_UPD,
2166 ARM::VST3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002167 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002168 }
2169
2170 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002171 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002172 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002173 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2174 ARM::VST4q16Pseudo_UPD,
2175 ARM::VST4q32Pseudo_UPD };
2176 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2177 ARM::VST4q16oddPseudo_UPD,
2178 ARM::VST4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002179 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002180 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002181
2182 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002183 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002184 unsigned QOpcodes0[] = { ARM::VST2LNq16, ARM::VST2LNq32 };
2185 unsigned QOpcodes1[] = { ARM::VST2LNq16odd, ARM::VST2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002186 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002187 }
2188
2189 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002190 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002191 unsigned QOpcodes0[] = { ARM::VST3LNq16, ARM::VST3LNq32 };
2192 unsigned QOpcodes1[] = { ARM::VST3LNq16odd, ARM::VST3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002193 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002194 }
2195
2196 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002197 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002198 unsigned QOpcodes0[] = { ARM::VST4LNq16, ARM::VST4LNq32 };
2199 unsigned QOpcodes1[] = { ARM::VST4LNq16odd, ARM::VST4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002200 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002201 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002202 }
Bob Wilson429009b2010-05-06 16:05:26 +00002203 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002204 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002205
Bob Wilsond491d6e2010-07-06 23:36:25 +00002206 case ISD::INTRINSIC_WO_CHAIN: {
2207 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2208 switch (IntNo) {
2209 default:
2210 break;
2211
2212 case Intrinsic::arm_neon_vtbl2:
Bob Wilson78dfbc32010-07-07 00:08:54 +00002213 return SelectVTBL(N, false, 2, ARM::VTBL2);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002214 case Intrinsic::arm_neon_vtbl3:
Bob Wilson78dfbc32010-07-07 00:08:54 +00002215 return SelectVTBL(N, false, 3, ARM::VTBL3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002216 case Intrinsic::arm_neon_vtbl4:
Bob Wilson78dfbc32010-07-07 00:08:54 +00002217 return SelectVTBL(N, false, 4, ARM::VTBL4);
2218
2219 case Intrinsic::arm_neon_vtbx2:
2220 return SelectVTBL(N, true, 2, ARM::VTBX2);
2221 case Intrinsic::arm_neon_vtbx3:
2222 return SelectVTBL(N, true, 3, ARM::VTBX3);
2223 case Intrinsic::arm_neon_vtbx4:
2224 return SelectVTBL(N, true, 4, ARM::VTBX4);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002225 }
2226 break;
2227 }
2228
Bob Wilson429009b2010-05-06 16:05:26 +00002229 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002230 return SelectConcatVector(N);
2231 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002232
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002233 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002234}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002235
Bob Wilson224c2442009-05-19 05:53:42 +00002236bool ARMDAGToDAGISel::
2237SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2238 std::vector<SDValue> &OutOps) {
2239 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002240 // Require the address to be in a register. That is safe for all ARM
2241 // variants and it is hard to do anything much smarter without knowing
2242 // how the operand is used.
2243 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002244 return false;
2245}
2246
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002247/// createARMISelDag - This pass converts a legalized DAG into a
2248/// ARM-specific DAG, ready for instruction scheduling.
2249///
Bob Wilson522ce972009-09-28 14:30:20 +00002250FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2251 CodeGenOpt::Level OptLevel) {
2252 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002253}