blob: 36a1827ce6e8b13097dc89782cf71ae366dc70f7 [file] [log] [blame]
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001//===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the ARM target.
11//
12//===----------------------------------------------------------------------===//
13
14#include "ARM.h"
Evan Chenge5ad88e2008-12-10 21:54:21 +000015#include "ARMAddressingModes.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000016#include "ARMTargetMachine.h"
Rafael Espindola84b19be2006-07-16 01:02:57 +000017#include "llvm/CallingConv.h"
Evan Chenga8e29892007-01-19 07:51:42 +000018#include "llvm/Constants.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000019#include "llvm/DerivedTypes.h"
20#include "llvm/Function.h"
21#include "llvm/Intrinsics.h"
Owen Anderson9adc0ab2009-07-14 23:09:55 +000022#include "llvm/LLVMContext.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000023#include "llvm/CodeGen/MachineFrameInfo.h"
24#include "llvm/CodeGen/MachineFunction.h"
25#include "llvm/CodeGen/MachineInstrBuilder.h"
26#include "llvm/CodeGen/SelectionDAG.h"
27#include "llvm/CodeGen/SelectionDAGISel.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000028#include "llvm/Target/TargetLowering.h"
Chris Lattner72939122007-05-03 00:32:00 +000029#include "llvm/Target/TargetOptions.h"
Chris Lattner3d62d782008-02-03 05:43:57 +000030#include "llvm/Support/Compiler.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000031#include "llvm/Support/Debug.h"
Torok Edwindac237e2009-07-08 20:53:28 +000032#include "llvm/Support/ErrorHandling.h"
33#include "llvm/Support/raw_ostream.h"
34
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000035using namespace llvm;
36
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000037//===--------------------------------------------------------------------===//
38/// ARMDAGToDAGISel - ARM specific code to select ARM machine
39/// instructions for SelectionDAG operations.
40///
41namespace {
42class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000043 ARMBaseTargetMachine &TM;
Evan Cheng3f7eb8e2008-09-18 07:24:33 +000044
Evan Chenga8e29892007-01-19 07:51:42 +000045 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
46 /// make the right decision when generating code for different targets.
47 const ARMSubtarget *Subtarget;
48
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000049public:
Bob Wilson522ce972009-09-28 14:30:20 +000050 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
51 CodeGenOpt::Level OptLevel)
52 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Chenga8e29892007-01-19 07:51:42 +000053 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000054 }
55
Evan Chenga8e29892007-01-19 07:51:42 +000056 virtual const char *getPassName() const {
57 return "ARM Instruction Selection";
Anton Korobeynikov52237112009-06-17 18:13:58 +000058 }
59
Bob Wilsonaf4a8912009-10-08 18:51:31 +000060 /// getI32Imm - Return a target constant of type i32 with the specified
61 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000062 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000063 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000064 }
65
Dan Gohmaneeb3a002010-01-05 01:24:18 +000066 SDNode *Select(SDNode *N);
Evan Cheng014bf212010-02-15 19:41:07 +000067
Dan Gohmaneeb3a002010-01-05 01:24:18 +000068 bool SelectShifterOperandReg(SDNode *Op, SDValue N, SDValue &A,
Evan Cheng055b0312009-06-29 07:51:04 +000069 SDValue &B, SDValue &C);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000070 bool SelectAddrMode2(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000071 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000072 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +000073 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000074 bool SelectAddrMode3(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000075 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000076 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +000077 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000078 bool SelectAddrMode4(SDNode *Op, SDValue N, SDValue &Addr,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +000079 SDValue &Mode);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000080 bool SelectAddrMode5(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000081 SDValue &Offset);
Bob Wilson226036e2010-03-20 22:13:40 +000082 bool SelectAddrMode6(SDNode *Op, SDValue N, SDValue &Addr, SDValue &Align);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000083
Dan Gohmaneeb3a002010-01-05 01:24:18 +000084 bool SelectAddrModePC(SDNode *Op, SDValue N, SDValue &Offset,
Bob Wilson8b024a52009-07-01 23:16:05 +000085 SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +000086
Dan Gohmaneeb3a002010-01-05 01:24:18 +000087 bool SelectThumbAddrModeRR(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000088 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000089 bool SelectThumbAddrModeRI5(SDNode *Op, SDValue N, unsigned Scale,
Dan Gohman475871a2008-07-27 21:46:04 +000090 SDValue &Base, SDValue &OffImm,
91 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000092 bool SelectThumbAddrModeS1(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000093 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000094 bool SelectThumbAddrModeS2(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000095 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000096 bool SelectThumbAddrModeS4(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000097 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000098 bool SelectThumbAddrModeSP(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000099 SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000100
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000101 bool SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000102 SDValue &BaseReg, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000103 bool SelectT2AddrModeImm12(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000104 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000105 bool SelectT2AddrModeImm8(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000106 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000107 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000108 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000109 bool SelectT2AddrModeImm8s4(SDNode *Op, SDValue N, SDValue &Base,
David Goodwin6647cea2009-06-30 22:50:01 +0000110 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000111 bool SelectT2AddrModeSoReg(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000112 SDValue &OffReg, SDValue &ShImm);
113
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000114 // Include the pieces autogenerated from the target description.
115#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000116
117private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000118 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
119 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000120 SDNode *SelectARMIndexedLoad(SDNode *N);
121 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000122
Bob Wilson621f1952010-03-23 05:25:43 +0000123 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
124 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000125 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000126 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000127 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000128 unsigned *QOpcodes0, unsigned *QOpcodes1);
129
Bob Wilson24f995d2009-10-14 18:32:29 +0000130 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000131 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000132 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000133 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000134 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000135 unsigned *QOpcodes0, unsigned *QOpcodes1);
136
Bob Wilson96493442009-10-14 16:46:45 +0000137 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000138 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson96493442009-10-14 16:46:45 +0000139 /// load/store of D registers and even subregs and odd subregs of Q registers.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000140 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
Bob Wilson96493442009-10-14 16:46:45 +0000141 unsigned *DOpcodes, unsigned *QOpcodes0,
142 unsigned *QOpcodes1);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000143
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000144 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000145 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000146
Evan Cheng07ba9062009-11-19 21:45:22 +0000147 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000148 SDNode *SelectCMOVOp(SDNode *N);
149 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000150 ARMCC::CondCodes CCVal, SDValue CCR,
151 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000152 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000153 ARMCC::CondCodes CCVal, SDValue CCR,
154 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000155 SDNode *SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000156 ARMCC::CondCodes CCVal, SDValue CCR,
157 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000158 SDNode *SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000159 ARMCC::CondCodes CCVal, SDValue CCR,
160 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000161
Evan Chengaf4550f2009-07-02 01:23:32 +0000162 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
163 /// inline asm expressions.
164 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
165 char ConstraintCode,
166 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000167
168 /// PairDRegs - Insert a pair of double registers into an implicit def to
169 /// form a quad register.
170 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000171};
Evan Chenga8e29892007-01-19 07:51:42 +0000172}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000173
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000174/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
175/// operand. If so Imm will receive the 32-bit value.
176static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
177 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
178 Imm = cast<ConstantSDNode>(N)->getZExtValue();
179 return true;
180 }
181 return false;
182}
183
184// isInt32Immediate - This method tests to see if a constant operand.
185// If so Imm will receive the 32 bit value.
186static bool isInt32Immediate(SDValue N, unsigned &Imm) {
187 return isInt32Immediate(N.getNode(), Imm);
188}
189
190// isOpcWithIntImmediate - This method tests to see if the node is a specific
191// opcode and that it has a immediate integer right operand.
192// If so Imm will receive the 32 bit value.
193static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
194 return N->getOpcode() == Opc &&
195 isInt32Immediate(N->getOperand(1).getNode(), Imm);
196}
197
198
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000199bool ARMDAGToDAGISel::SelectShifterOperandReg(SDNode *Op,
Evan Cheng055b0312009-06-29 07:51:04 +0000200 SDValue N,
201 SDValue &BaseReg,
202 SDValue &ShReg,
203 SDValue &Opc) {
204 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
205
206 // Don't match base register only case. That is matched to a separate
207 // lower complexity pattern with explicit register operand.
208 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000209
Evan Cheng055b0312009-06-29 07:51:04 +0000210 BaseReg = N.getOperand(0);
211 unsigned ShImmVal = 0;
212 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000213 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000214 ShImmVal = RHS->getZExtValue() & 31;
215 } else {
216 ShReg = N.getOperand(1);
217 }
218 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000219 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000220 return true;
221}
222
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000223bool ARMDAGToDAGISel::SelectAddrMode2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000224 SDValue &Base, SDValue &Offset,
225 SDValue &Opc) {
Evan Chenga13fd102007-03-13 21:05:54 +0000226 if (N.getOpcode() == ISD::MUL) {
227 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
228 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000229 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000230 if (RHSC & 1) {
231 RHSC = RHSC & ~1;
232 ARM_AM::AddrOpc AddSub = ARM_AM::add;
233 if (RHSC < 0) {
234 AddSub = ARM_AM::sub;
235 RHSC = - RHSC;
236 }
237 if (isPowerOf2_32(RHSC)) {
238 unsigned ShAmt = Log2_32(RHSC);
239 Base = Offset = N.getOperand(0);
240 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
241 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000242 MVT::i32);
Evan Chenga13fd102007-03-13 21:05:54 +0000243 return true;
244 }
245 }
246 }
247 }
248
Evan Chenga8e29892007-01-19 07:51:42 +0000249 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
250 Base = N;
251 if (N.getOpcode() == ISD::FrameIndex) {
252 int FI = cast<FrameIndexSDNode>(N)->getIndex();
253 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000254 } else if (N.getOpcode() == ARMISD::Wrapper &&
255 !(Subtarget->useMovt() &&
256 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000257 Base = N.getOperand(0);
258 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000259 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000260 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
261 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000262 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000263 return true;
264 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000265
Evan Chenga8e29892007-01-19 07:51:42 +0000266 // Match simple R +/- imm12 operands.
267 if (N.getOpcode() == ISD::ADD)
268 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000269 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000270 if ((RHSC >= 0 && RHSC < 0x1000) ||
271 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000272 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000273 if (Base.getOpcode() == ISD::FrameIndex) {
274 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
275 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
276 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000277 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000278
279 ARM_AM::AddrOpc AddSub = ARM_AM::add;
280 if (RHSC < 0) {
281 AddSub = ARM_AM::sub;
282 RHSC = - RHSC;
283 }
284 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000285 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000286 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000287 return true;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000288 }
Evan Chenga8e29892007-01-19 07:51:42 +0000289 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000290
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000291 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000292 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
293 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
294 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000295
Evan Chenga8e29892007-01-19 07:51:42 +0000296 Base = N.getOperand(0);
297 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000298
Evan Chenga8e29892007-01-19 07:51:42 +0000299 if (ShOpcVal != ARM_AM::no_shift) {
300 // Check to see if the RHS of the shift is a constant, if not, we can't fold
301 // it.
302 if (ConstantSDNode *Sh =
303 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000304 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000305 Offset = N.getOperand(1).getOperand(0);
306 } else {
307 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000308 }
309 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000310
Evan Chenga8e29892007-01-19 07:51:42 +0000311 // Try matching (R shl C) + (R).
312 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
313 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
314 if (ShOpcVal != ARM_AM::no_shift) {
315 // Check to see if the RHS of the shift is a constant, if not, we can't
316 // fold it.
317 if (ConstantSDNode *Sh =
318 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000319 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000320 Offset = N.getOperand(0).getOperand(0);
321 Base = N.getOperand(1);
322 } else {
323 ShOpcVal = ARM_AM::no_shift;
324 }
325 }
326 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000327
Evan Chenga8e29892007-01-19 07:51:42 +0000328 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000329 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000330 return true;
331}
332
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000333bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000334 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000335 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000336 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
337 ? cast<LoadSDNode>(Op)->getAddressingMode()
338 : cast<StoreSDNode>(Op)->getAddressingMode();
339 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
340 ? ARM_AM::add : ARM_AM::sub;
341 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000342 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000343 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000344 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000345 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
346 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000347 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000348 return true;
349 }
350 }
351
352 Offset = N;
353 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
354 unsigned ShAmt = 0;
355 if (ShOpcVal != ARM_AM::no_shift) {
356 // Check to see if the RHS of the shift is a constant, if not, we can't fold
357 // it.
358 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000359 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000360 Offset = N.getOperand(0);
361 } else {
362 ShOpcVal = ARM_AM::no_shift;
363 }
364 }
365
366 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000367 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000368 return true;
369}
370
Evan Chenga8e29892007-01-19 07:51:42 +0000371
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000372bool ARMDAGToDAGISel::SelectAddrMode3(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000373 SDValue &Base, SDValue &Offset,
374 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000375 if (N.getOpcode() == ISD::SUB) {
376 // X - C is canonicalize to X + -C, no need to handle it here.
377 Base = N.getOperand(0);
378 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000379 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000380 return true;
381 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000382
Evan Chenga8e29892007-01-19 07:51:42 +0000383 if (N.getOpcode() != ISD::ADD) {
384 Base = N;
385 if (N.getOpcode() == ISD::FrameIndex) {
386 int FI = cast<FrameIndexSDNode>(N)->getIndex();
387 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
388 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000389 Offset = CurDAG->getRegister(0, MVT::i32);
390 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000391 return true;
392 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000393
Evan Chenga8e29892007-01-19 07:51:42 +0000394 // If the RHS is +/- imm8, fold into addr mode.
395 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000396 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000397 if ((RHSC >= 0 && RHSC < 256) ||
398 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000399 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000400 if (Base.getOpcode() == ISD::FrameIndex) {
401 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
402 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
403 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000404 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000405
406 ARM_AM::AddrOpc AddSub = ARM_AM::add;
407 if (RHSC < 0) {
408 AddSub = ARM_AM::sub;
409 RHSC = - RHSC;
410 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000411 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000412 return true;
413 }
414 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000415
Evan Chenga8e29892007-01-19 07:51:42 +0000416 Base = N.getOperand(0);
417 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000418 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000419 return true;
420}
421
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000422bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000423 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000424 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000425 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
426 ? cast<LoadSDNode>(Op)->getAddressingMode()
427 : cast<StoreSDNode>(Op)->getAddressingMode();
428 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
429 ? ARM_AM::add : ARM_AM::sub;
430 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000431 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000432 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000433 Offset = CurDAG->getRegister(0, MVT::i32);
434 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000435 return true;
436 }
437 }
438
439 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000440 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000441 return true;
442}
443
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000444bool ARMDAGToDAGISel::SelectAddrMode4(SDNode *Op, SDValue N,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000445 SDValue &Addr, SDValue &Mode) {
446 Addr = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000447 Mode = CurDAG->getTargetConstant(0, MVT::i32);
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000448 return true;
449}
Evan Chenga8e29892007-01-19 07:51:42 +0000450
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000451bool ARMDAGToDAGISel::SelectAddrMode5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000452 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000453 if (N.getOpcode() != ISD::ADD) {
454 Base = N;
455 if (N.getOpcode() == ISD::FrameIndex) {
456 int FI = cast<FrameIndexSDNode>(N)->getIndex();
457 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000458 } else if (N.getOpcode() == ARMISD::Wrapper &&
459 !(Subtarget->useMovt() &&
460 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000461 Base = N.getOperand(0);
462 }
463 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000464 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000465 return true;
466 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000467
Evan Chenga8e29892007-01-19 07:51:42 +0000468 // If the RHS is +/- imm8, fold into addr mode.
469 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000470 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000471 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
472 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000473 if ((RHSC >= 0 && RHSC < 256) ||
474 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000475 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000476 if (Base.getOpcode() == ISD::FrameIndex) {
477 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
478 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
479 }
480
481 ARM_AM::AddrOpc AddSub = ARM_AM::add;
482 if (RHSC < 0) {
483 AddSub = ARM_AM::sub;
484 RHSC = - RHSC;
485 }
486 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000487 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000488 return true;
489 }
490 }
491 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000492
Evan Chenga8e29892007-01-19 07:51:42 +0000493 Base = N;
494 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000495 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000496 return true;
497}
498
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000499bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Op, SDValue N,
Bob Wilson226036e2010-03-20 22:13:40 +0000500 SDValue &Addr, SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000501 Addr = N;
Jim Grosbach8a5ec862009-11-07 21:25:39 +0000502 // Default to no alignment.
503 Align = CurDAG->getTargetConstant(0, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000504 return true;
505}
506
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000507bool ARMDAGToDAGISel::SelectAddrModePC(SDNode *Op, SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000508 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000509 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
510 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000511 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000512 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000513 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000514 return true;
515 }
516 return false;
517}
518
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000519bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000520 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000521 // FIXME dl should come from the parent load or store, not the address
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000522 DebugLoc dl = Op->getDebugLoc();
Evan Chengc38f2bc2007-01-23 22:59:13 +0000523 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000524 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
525 if (!NC || NC->getZExtValue() != 0)
526 return false;
527
528 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000529 return true;
530 }
531
Evan Chenga8e29892007-01-19 07:51:42 +0000532 Base = N.getOperand(0);
533 Offset = N.getOperand(1);
534 return true;
535}
536
Evan Cheng79d43262007-01-24 02:21:22 +0000537bool
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000538ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000539 unsigned Scale, SDValue &Base,
540 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000541 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000542 SDValue TmpBase, TmpOffImm;
Evan Cheng79d43262007-01-24 02:21:22 +0000543 if (SelectThumbAddrModeSP(Op, N, TmpBase, TmpOffImm))
544 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000545 if (N.getOpcode() == ARMISD::Wrapper &&
546 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
547 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000548 }
549
Evan Chenga8e29892007-01-19 07:51:42 +0000550 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000551 if (N.getOpcode() == ARMISD::Wrapper &&
552 !(Subtarget->useMovt() &&
553 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
554 Base = N.getOperand(0);
555 } else
556 Base = N;
557
Owen Anderson825b72b2009-08-11 20:47:22 +0000558 Offset = CurDAG->getRegister(0, MVT::i32);
559 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000560 return true;
561 }
562
Evan Chengad0e4652007-02-06 00:22:06 +0000563 // Thumb does not have [sp, r] address mode.
564 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
565 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
566 if ((LHSR && LHSR->getReg() == ARM::SP) ||
567 (RHSR && RHSR->getReg() == ARM::SP)) {
568 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000569 Offset = CurDAG->getRegister(0, MVT::i32);
570 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000571 return true;
572 }
573
Evan Chenga8e29892007-01-19 07:51:42 +0000574 // If the RHS is + imm5 * scale, fold into addr mode.
575 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000576 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000577 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
578 RHSC /= Scale;
579 if (RHSC >= 0 && RHSC < 32) {
580 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000581 Offset = CurDAG->getRegister(0, MVT::i32);
582 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000583 return true;
584 }
585 }
586 }
587
Evan Chengc38f2bc2007-01-23 22:59:13 +0000588 Base = N.getOperand(0);
589 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000590 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000591 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000592}
593
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000594bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000595 SDValue &Base, SDValue &OffImm,
596 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000597 return SelectThumbAddrModeRI5(Op, N, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000598}
599
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000600bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000601 SDValue &Base, SDValue &OffImm,
602 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000603 return SelectThumbAddrModeRI5(Op, N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000604}
605
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000606bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000607 SDValue &Base, SDValue &OffImm,
608 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000609 return SelectThumbAddrModeRI5(Op, N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000610}
611
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000612bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000613 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000614 if (N.getOpcode() == ISD::FrameIndex) {
615 int FI = cast<FrameIndexSDNode>(N)->getIndex();
616 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000617 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000618 return true;
619 }
Evan Cheng79d43262007-01-24 02:21:22 +0000620
Evan Chengad0e4652007-02-06 00:22:06 +0000621 if (N.getOpcode() != ISD::ADD)
622 return false;
623
624 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000625 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
626 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000627 // If the RHS is + imm8 * scale, fold into addr mode.
628 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000629 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000630 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
631 RHSC >>= 2;
632 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000633 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000634 if (Base.getOpcode() == ISD::FrameIndex) {
635 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
636 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
637 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000638 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000639 return true;
640 }
641 }
642 }
643 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000644
Evan Chenga8e29892007-01-19 07:51:42 +0000645 return false;
646}
647
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000648bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000649 SDValue &BaseReg,
650 SDValue &Opc) {
651 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
652
653 // Don't match base register only case. That is matched to a separate
654 // lower complexity pattern with explicit register operand.
655 if (ShOpcVal == ARM_AM::no_shift) return false;
656
657 BaseReg = N.getOperand(0);
658 unsigned ShImmVal = 0;
659 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
660 ShImmVal = RHS->getZExtValue() & 31;
661 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
662 return true;
663 }
664
665 return false;
666}
667
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000668bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000669 SDValue &Base, SDValue &OffImm) {
670 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000671
Evan Cheng3a214252009-08-11 08:52:18 +0000672 // Base only.
673 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000674 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000675 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000676 int FI = cast<FrameIndexSDNode>(N)->getIndex();
677 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000678 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000679 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000680 } else if (N.getOpcode() == ARMISD::Wrapper &&
681 !(Subtarget->useMovt() &&
682 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000683 Base = N.getOperand(0);
684 if (Base.getOpcode() == ISD::TargetConstantPool)
685 return false; // We want to select t2LDRpci instead.
686 } else
687 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000688 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000689 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000690 }
Evan Cheng055b0312009-06-29 07:51:04 +0000691
692 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Evan Cheng3a214252009-08-11 08:52:18 +0000693 if (SelectT2AddrModeImm8(Op, N, Base, OffImm))
694 // Let t2LDRi8 handle (R - imm8).
695 return false;
696
Evan Cheng055b0312009-06-29 07:51:04 +0000697 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000698 if (N.getOpcode() == ISD::SUB)
699 RHSC = -RHSC;
700
701 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +0000702 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +0000703 if (Base.getOpcode() == ISD::FrameIndex) {
704 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
705 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
706 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000707 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000708 return true;
709 }
710 }
711
Evan Cheng3a214252009-08-11 08:52:18 +0000712 // Base only.
713 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000714 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000715 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000716}
717
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000718bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000719 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +0000720 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +0000721 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +0000722 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
723 int RHSC = (int)RHS->getSExtValue();
724 if (N.getOpcode() == ISD::SUB)
725 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +0000726
Evan Cheng3a214252009-08-11 08:52:18 +0000727 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
728 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +0000729 if (Base.getOpcode() == ISD::FrameIndex) {
730 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
731 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
732 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000733 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +0000734 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000735 }
Evan Cheng055b0312009-06-29 07:51:04 +0000736 }
737 }
738
739 return false;
740}
741
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000742bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000743 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000744 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +0000745 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
746 ? cast<LoadSDNode>(Op)->getAddressingMode()
747 : cast<StoreSDNode>(Op)->getAddressingMode();
748 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
749 int RHSC = (int)RHS->getZExtValue();
750 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +0000751 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +0000752 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
753 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000754 return true;
755 }
756 }
757
758 return false;
759}
760
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000761bool ARMDAGToDAGISel::SelectT2AddrModeImm8s4(SDNode *Op, SDValue N,
David Goodwin6647cea2009-06-30 22:50:01 +0000762 SDValue &Base, SDValue &OffImm) {
763 if (N.getOpcode() == ISD::ADD) {
764 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
765 int RHSC = (int)RHS->getZExtValue();
Evan Cheng5c874172009-07-09 22:21:59 +0000766 if (((RHSC & 0x3) == 0) &&
767 ((RHSC >= 0 && RHSC < 0x400) || (RHSC < 0 && RHSC > -0x400))) { // 8 bits.
David Goodwin6647cea2009-06-30 22:50:01 +0000768 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000769 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000770 return true;
771 }
772 }
773 } else if (N.getOpcode() == ISD::SUB) {
774 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
775 int RHSC = (int)RHS->getZExtValue();
776 if (((RHSC & 0x3) == 0) && (RHSC >= 0 && RHSC < 0x400)) { // 8 bits.
777 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000778 OffImm = CurDAG->getTargetConstant(-RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000779 return true;
780 }
781 }
782 }
783
784 return false;
785}
786
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000787bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000788 SDValue &Base,
789 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +0000790 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
791 if (N.getOpcode() != ISD::ADD)
792 return false;
Evan Cheng055b0312009-06-29 07:51:04 +0000793
Evan Cheng3a214252009-08-11 08:52:18 +0000794 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
795 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
796 int RHSC = (int)RHS->getZExtValue();
797 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
798 return false;
799 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +0000800 return false;
801 }
802
Evan Cheng055b0312009-06-29 07:51:04 +0000803 // Look for (R + R) or (R + (R << [1,2,3])).
804 unsigned ShAmt = 0;
805 Base = N.getOperand(0);
806 OffReg = N.getOperand(1);
807
808 // Swap if it is ((R << c) + R).
809 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
810 if (ShOpcVal != ARM_AM::lsl) {
811 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
812 if (ShOpcVal == ARM_AM::lsl)
813 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +0000814 }
815
Evan Cheng055b0312009-06-29 07:51:04 +0000816 if (ShOpcVal == ARM_AM::lsl) {
817 // Check to see if the RHS of the shift is a constant, if not, we can't fold
818 // it.
819 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
820 ShAmt = Sh->getZExtValue();
821 if (ShAmt >= 4) {
822 ShAmt = 0;
823 ShOpcVal = ARM_AM::no_shift;
824 } else
825 OffReg = OffReg.getOperand(0);
826 } else {
827 ShOpcVal = ARM_AM::no_shift;
828 }
David Goodwin7ecc8502009-07-15 15:50:19 +0000829 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000830
Owen Anderson825b72b2009-08-11 20:47:22 +0000831 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000832
833 return true;
834}
835
836//===--------------------------------------------------------------------===//
837
Evan Chengee568cf2007-07-05 07:15:27 +0000838/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +0000839static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000840 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +0000841}
842
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000843SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
844 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +0000845 ISD::MemIndexedMode AM = LD->getAddressingMode();
846 if (AM == ISD::UNINDEXED)
847 return NULL;
848
Owen Andersone50ed302009-08-10 22:56:29 +0000849 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +0000850 SDValue Offset, AMOpc;
851 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
852 unsigned Opcode = 0;
853 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000854 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000855 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000856 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
857 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +0000858 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000859 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000860 Match = true;
861 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
862 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
863 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +0000864 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000865 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000866 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000867 Match = true;
868 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
869 }
870 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000871 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000872 Match = true;
873 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
874 }
875 }
876 }
877
878 if (Match) {
879 SDValue Chain = LD->getChain();
880 SDValue Base = LD->getBasePtr();
881 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000882 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000883 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000884 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +0000885 }
886
887 return NULL;
888}
889
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000890SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
891 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000892 ISD::MemIndexedMode AM = LD->getAddressingMode();
893 if (AM == ISD::UNINDEXED)
894 return NULL;
895
Owen Andersone50ed302009-08-10 22:56:29 +0000896 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +0000897 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000898 SDValue Offset;
899 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
900 unsigned Opcode = 0;
901 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000902 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000903 switch (LoadedVT.getSimpleVT().SimpleTy) {
904 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000905 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
906 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000907 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000908 if (isSExtLd)
909 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
910 else
911 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000912 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000913 case MVT::i8:
914 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000915 if (isSExtLd)
916 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
917 else
918 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000919 break;
920 default:
921 return NULL;
922 }
923 Match = true;
924 }
925
926 if (Match) {
927 SDValue Chain = LD->getChain();
928 SDValue Base = LD->getBasePtr();
929 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000930 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000931 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000932 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000933 }
934
935 return NULL;
936}
937
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000938/// PairDRegs - Insert a pair of double registers into an implicit def to
939/// form a quad register.
940SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
941 DebugLoc dl = V0.getNode()->getDebugLoc();
942 SDValue Undef =
Chris Lattner518bb532010-02-09 19:54:29 +0000943 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000944 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
945 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
Chris Lattner518bb532010-02-09 19:54:29 +0000946 SDNode *Pair = CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000947 VT, Undef, V0, SubReg0);
Chris Lattner518bb532010-02-09 19:54:29 +0000948 return CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000949 VT, SDValue(Pair, 0), V1, SubReg1);
950}
951
Bob Wilsona7c397c2009-10-14 16:19:03 +0000952/// GetNEONSubregVT - Given a type for a 128-bit NEON vector, return the type
953/// for a 64-bit subregister of the vector.
954static EVT GetNEONSubregVT(EVT VT) {
955 switch (VT.getSimpleVT().SimpleTy) {
956 default: llvm_unreachable("unhandled NEON type");
957 case MVT::v16i8: return MVT::v8i8;
958 case MVT::v8i16: return MVT::v4i16;
959 case MVT::v4f32: return MVT::v2f32;
960 case MVT::v4i32: return MVT::v2i32;
961 case MVT::v2i64: return MVT::v1i64;
962 }
963}
964
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000965SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +0000966 unsigned *DOpcodes, unsigned *QOpcodes0,
967 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +0000968 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +0000969 DebugLoc dl = N->getDebugLoc();
970
Bob Wilson226036e2010-03-20 22:13:40 +0000971 SDValue MemAddr, Align;
972 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +0000973 return NULL;
974
975 SDValue Chain = N->getOperand(0);
976 EVT VT = N->getValueType(0);
977 bool is64BitVector = VT.is64BitVector();
978
979 unsigned OpcodeIndex;
980 switch (VT.getSimpleVT().SimpleTy) {
981 default: llvm_unreachable("unhandled vld type");
982 // Double-register operations:
983 case MVT::v8i8: OpcodeIndex = 0; break;
984 case MVT::v4i16: OpcodeIndex = 1; break;
985 case MVT::v2f32:
986 case MVT::v2i32: OpcodeIndex = 2; break;
987 case MVT::v1i64: OpcodeIndex = 3; break;
988 // Quad-register operations:
989 case MVT::v16i8: OpcodeIndex = 0; break;
990 case MVT::v8i16: OpcodeIndex = 1; break;
991 case MVT::v4f32:
992 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +0000993 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +0000994 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +0000995 break;
Bob Wilson3e36f132009-10-14 17:28:52 +0000996 }
997
Evan Cheng47b7b9f2010-04-16 05:46:06 +0000998 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +0000999 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson3e36f132009-10-14 17:28:52 +00001000 if (is64BitVector) {
1001 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001002 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson3e36f132009-10-14 17:28:52 +00001003 std::vector<EVT> ResTys(NumVecs, VT);
1004 ResTys.push_back(MVT::Other);
Bob Wilson226036e2010-03-20 22:13:40 +00001005 return CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson3e36f132009-10-14 17:28:52 +00001006 }
1007
1008 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson621f1952010-03-23 05:25:43 +00001009 if (NumVecs <= 2) {
1010 // Quad registers are directly supported for VLD1 and VLD2,
1011 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001012 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001013 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson621f1952010-03-23 05:25:43 +00001014 std::vector<EVT> ResTys(2 * NumVecs, RegVT);
Bob Wilson3e36f132009-10-14 17:28:52 +00001015 ResTys.push_back(MVT::Other);
Bob Wilson226036e2010-03-20 22:13:40 +00001016 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson621f1952010-03-23 05:25:43 +00001017 Chain = SDValue(VLd, 2 * NumVecs);
Bob Wilson3e36f132009-10-14 17:28:52 +00001018
1019 // Combine the even and odd subregs to produce the result.
1020 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1021 SDNode *Q = PairDRegs(VT, SDValue(VLd, 2*Vec), SDValue(VLd, 2*Vec+1));
1022 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1023 }
1024 } else {
1025 // Otherwise, quad registers are loaded with two separate instructions,
1026 // where one loads the even registers and the other loads the odd registers.
1027
Bob Wilson3e36f132009-10-14 17:28:52 +00001028 std::vector<EVT> ResTys(NumVecs, RegVT);
1029 ResTys.push_back(MemAddr.getValueType());
1030 ResTys.push_back(MVT::Other);
1031
Bob Wilson24f995d2009-10-14 18:32:29 +00001032 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001033 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001034 const SDValue OpsA[] = { MemAddr, Align, Reg0, Pred, Reg0, Chain };
1035 SDNode *VLdA = CurDAG->getMachineNode(Opc, dl, ResTys, OpsA, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001036 Chain = SDValue(VLdA, NumVecs+1);
1037
Bob Wilson24f995d2009-10-14 18:32:29 +00001038 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001039 Opc = QOpcodes1[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001040 const SDValue OpsB[] = { SDValue(VLdA, NumVecs),
1041 Align, Reg0, Pred, Reg0, Chain };
1042 SDNode *VLdB = CurDAG->getMachineNode(Opc, dl, ResTys, OpsB, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001043 Chain = SDValue(VLdB, NumVecs+1);
1044
1045 // Combine the even and odd subregs to produce the result.
1046 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1047 SDNode *Q = PairDRegs(VT, SDValue(VLdA, Vec), SDValue(VLdB, Vec));
1048 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1049 }
1050 }
1051 ReplaceUses(SDValue(N, NumVecs), Chain);
1052 return NULL;
1053}
1054
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001055SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001056 unsigned *DOpcodes, unsigned *QOpcodes0,
1057 unsigned *QOpcodes1) {
Bob Wilson11d98992010-03-23 06:20:33 +00001058 assert(NumVecs >=1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001059 DebugLoc dl = N->getDebugLoc();
1060
Bob Wilson226036e2010-03-20 22:13:40 +00001061 SDValue MemAddr, Align;
1062 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001063 return NULL;
1064
1065 SDValue Chain = N->getOperand(0);
1066 EVT VT = N->getOperand(3).getValueType();
1067 bool is64BitVector = VT.is64BitVector();
1068
1069 unsigned OpcodeIndex;
1070 switch (VT.getSimpleVT().SimpleTy) {
1071 default: llvm_unreachable("unhandled vst type");
1072 // Double-register operations:
1073 case MVT::v8i8: OpcodeIndex = 0; break;
1074 case MVT::v4i16: OpcodeIndex = 1; break;
1075 case MVT::v2f32:
1076 case MVT::v2i32: OpcodeIndex = 2; break;
1077 case MVT::v1i64: OpcodeIndex = 3; break;
1078 // Quad-register operations:
1079 case MVT::v16i8: OpcodeIndex = 0; break;
1080 case MVT::v8i16: OpcodeIndex = 1; break;
1081 case MVT::v4f32:
1082 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001083 case MVT::v2i64: OpcodeIndex = 3;
1084 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1085 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001086 }
1087
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001088 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001089 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001090
Bob Wilson226036e2010-03-20 22:13:40 +00001091 SmallVector<SDValue, 10> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001092 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001093 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001094
1095 if (is64BitVector) {
1096 unsigned Opc = DOpcodes[OpcodeIndex];
1097 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1098 Ops.push_back(N->getOperand(Vec+3));
Evan Chengac0869d2009-11-21 06:21:52 +00001099 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001100 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001101 Ops.push_back(Chain);
Bob Wilson226036e2010-03-20 22:13:40 +00001102 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+5);
Bob Wilson24f995d2009-10-14 18:32:29 +00001103 }
1104
1105 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson11d98992010-03-23 06:20:33 +00001106 if (NumVecs <= 2) {
1107 // Quad registers are directly supported for VST1 and VST2,
1108 // storing pairs of D regs.
Bob Wilson24f995d2009-10-14 18:32:29 +00001109 unsigned Opc = QOpcodes0[OpcodeIndex];
1110 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1111 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1112 N->getOperand(Vec+3)));
1113 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
1114 N->getOperand(Vec+3)));
1115 }
Evan Chengac0869d2009-11-21 06:21:52 +00001116 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001117 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001118 Ops.push_back(Chain);
Bob Wilson11d98992010-03-23 06:20:33 +00001119 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(),
1120 5 + 2 * NumVecs);
Bob Wilson24f995d2009-10-14 18:32:29 +00001121 }
1122
1123 // Otherwise, quad registers are stored with two separate instructions,
1124 // where one stores the even registers and the other stores the odd registers.
1125
Bob Wilson226036e2010-03-20 22:13:40 +00001126 Ops.push_back(Reg0); // post-access address offset
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001127
Bob Wilson24f995d2009-10-14 18:32:29 +00001128 // Store the even subregs.
1129 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1130 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1131 N->getOperand(Vec+3)));
Evan Chengac0869d2009-11-21 06:21:52 +00001132 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001133 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001134 Ops.push_back(Chain);
1135 unsigned Opc = QOpcodes0[OpcodeIndex];
1136 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilson226036e2010-03-20 22:13:40 +00001137 MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001138 Chain = SDValue(VStA, 1);
1139
1140 // Store the odd subregs.
1141 Ops[0] = SDValue(VStA, 0); // MemAddr
1142 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
Bob Wilson226036e2010-03-20 22:13:40 +00001143 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
Bob Wilson24f995d2009-10-14 18:32:29 +00001144 N->getOperand(Vec+3));
Bob Wilson226036e2010-03-20 22:13:40 +00001145 Ops[NumVecs+5] = Chain;
Bob Wilson24f995d2009-10-14 18:32:29 +00001146 Opc = QOpcodes1[OpcodeIndex];
1147 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilson226036e2010-03-20 22:13:40 +00001148 MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001149 Chain = SDValue(VStB, 1);
1150 ReplaceUses(SDValue(N, 0), Chain);
1151 return NULL;
1152}
1153
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001154SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001155 unsigned NumVecs, unsigned *DOpcodes,
1156 unsigned *QOpcodes0,
1157 unsigned *QOpcodes1) {
1158 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001159 DebugLoc dl = N->getDebugLoc();
1160
Bob Wilson226036e2010-03-20 22:13:40 +00001161 SDValue MemAddr, Align;
1162 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001163 return NULL;
1164
1165 SDValue Chain = N->getOperand(0);
1166 unsigned Lane =
1167 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001168 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001169 bool is64BitVector = VT.is64BitVector();
1170
Bob Wilson96493442009-10-14 16:46:45 +00001171 // Quad registers are handled by load/store of subregs. Find the subreg info.
Bob Wilsona7c397c2009-10-14 16:19:03 +00001172 unsigned NumElts = 0;
1173 int SubregIdx = 0;
1174 EVT RegVT = VT;
1175 if (!is64BitVector) {
1176 RegVT = GetNEONSubregVT(VT);
1177 NumElts = RegVT.getVectorNumElements();
1178 SubregIdx = (Lane < NumElts) ? ARM::DSUBREG_0 : ARM::DSUBREG_1;
1179 }
1180
1181 unsigned OpcodeIndex;
1182 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001183 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001184 // Double-register operations:
1185 case MVT::v8i8: OpcodeIndex = 0; break;
1186 case MVT::v4i16: OpcodeIndex = 1; break;
1187 case MVT::v2f32:
1188 case MVT::v2i32: OpcodeIndex = 2; break;
1189 // Quad-register operations:
1190 case MVT::v8i16: OpcodeIndex = 0; break;
1191 case MVT::v4f32:
1192 case MVT::v4i32: OpcodeIndex = 1; break;
1193 }
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 Wilson226036e2010-03-20 22:13:40 +00001198 SmallVector<SDValue, 10> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001199 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001200 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001201
1202 unsigned Opc = 0;
1203 if (is64BitVector) {
1204 Opc = DOpcodes[OpcodeIndex];
1205 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1206 Ops.push_back(N->getOperand(Vec+3));
1207 } else {
1208 // Check if this is loading the even or odd subreg of a Q register.
1209 if (Lane < NumElts) {
1210 Opc = QOpcodes0[OpcodeIndex];
1211 } else {
1212 Lane -= NumElts;
1213 Opc = QOpcodes1[OpcodeIndex];
1214 }
1215 // Extract the subregs of the input vector.
1216 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1217 Ops.push_back(CurDAG->getTargetExtractSubreg(SubregIdx, dl, RegVT,
1218 N->getOperand(Vec+3)));
1219 }
1220 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001221 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001222 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001223 Ops.push_back(Chain);
1224
Bob Wilson96493442009-10-14 16:46:45 +00001225 if (!IsLoad)
Bob Wilson226036e2010-03-20 22:13:40 +00001226 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson96493442009-10-14 16:46:45 +00001227
Bob Wilsona7c397c2009-10-14 16:19:03 +00001228 std::vector<EVT> ResTys(NumVecs, RegVT);
1229 ResTys.push_back(MVT::Other);
1230 SDNode *VLdLn =
Bob Wilson226036e2010-03-20 22:13:40 +00001231 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), NumVecs+6);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001232 // For a 64-bit vector load to D registers, nothing more needs to be done.
1233 if (is64BitVector)
1234 return VLdLn;
1235
1236 // For 128-bit vectors, take the 64-bit results of the load and insert them
1237 // as subregs into the result.
1238 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1239 SDValue QuadVec = CurDAG->getTargetInsertSubreg(SubregIdx, dl, VT,
1240 N->getOperand(Vec+3),
1241 SDValue(VLdLn, Vec));
1242 ReplaceUses(SDValue(N, Vec), QuadVec);
1243 }
1244
1245 Chain = SDValue(VLdLn, NumVecs);
1246 ReplaceUses(SDValue(N, NumVecs), Chain);
1247 return NULL;
1248}
1249
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001250SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001251 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001252 if (!Subtarget->hasV6T2Ops())
1253 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001254
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001255 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1256 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1257
1258
1259 // For unsigned extracts, check for a shift right and mask
1260 unsigned And_imm = 0;
1261 if (N->getOpcode() == ISD::AND) {
1262 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1263
1264 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1265 if (And_imm & (And_imm + 1))
1266 return NULL;
1267
1268 unsigned Srl_imm = 0;
1269 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1270 Srl_imm)) {
1271 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1272
1273 unsigned Width = CountTrailingOnes_32(And_imm);
1274 unsigned LSB = Srl_imm;
1275 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1276 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1277 CurDAG->getTargetConstant(LSB, MVT::i32),
1278 CurDAG->getTargetConstant(Width, MVT::i32),
1279 getAL(CurDAG), Reg0 };
1280 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1281 }
1282 }
1283 return NULL;
1284 }
1285
1286 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001287 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001288 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001289 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1290 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001291 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001292 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1293 unsigned Width = 32 - Srl_imm;
1294 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001295 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001296 return NULL;
1297 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001298 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001299 CurDAG->getTargetConstant(LSB, MVT::i32),
1300 CurDAG->getTargetConstant(Width, MVT::i32),
1301 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001302 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001303 }
1304 }
1305 return NULL;
1306}
1307
Evan Cheng9ef48352009-11-20 00:54:03 +00001308SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001309SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001310 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1311 SDValue CPTmp0;
1312 SDValue CPTmp1;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001313 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001314 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1315 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1316 unsigned Opc = 0;
1317 switch (SOShOp) {
1318 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1319 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1320 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1321 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1322 default:
1323 llvm_unreachable("Unknown so_reg opcode!");
1324 break;
1325 }
1326 SDValue SOShImm =
1327 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1328 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1329 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001330 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001331 }
1332 return 0;
1333}
1334
1335SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001336SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001337 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1338 SDValue CPTmp0;
1339 SDValue CPTmp1;
1340 SDValue CPTmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001341 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001342 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1343 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001344 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001345 }
1346 return 0;
1347}
1348
1349SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001350SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001351 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1352 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1353 if (!T)
1354 return 0;
1355
1356 if (Predicate_t2_so_imm(TrueVal.getNode())) {
1357 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1358 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1359 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001360 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001361 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1362 }
1363 return 0;
1364}
1365
1366SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001367SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001368 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1369 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1370 if (!T)
1371 return 0;
1372
1373 if (Predicate_so_imm(TrueVal.getNode())) {
1374 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1375 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1376 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001377 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001378 ARM::MOVCCi, MVT::i32, Ops, 5);
1379 }
1380 return 0;
1381}
1382
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001383SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1384 EVT VT = N->getValueType(0);
1385 SDValue FalseVal = N->getOperand(0);
1386 SDValue TrueVal = N->getOperand(1);
1387 SDValue CC = N->getOperand(2);
1388 SDValue CCR = N->getOperand(3);
1389 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001390 assert(CC.getOpcode() == ISD::Constant);
1391 assert(CCR.getOpcode() == ISD::Register);
1392 ARMCC::CondCodes CCVal =
1393 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001394
1395 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1396 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1397 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1398 // Pattern complexity = 18 cost = 1 size = 0
1399 SDValue CPTmp0;
1400 SDValue CPTmp1;
1401 SDValue CPTmp2;
1402 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001403 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001404 CCVal, CCR, InFlag);
1405 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001406 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001407 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1408 if (Res)
1409 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001410 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001411 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001412 CCVal, CCR, InFlag);
1413 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001414 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001415 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1416 if (Res)
1417 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001418 }
1419
1420 // Pattern: (ARMcmov:i32 GPR:i32:$false,
1421 // (imm:i32)<<P:Predicate_so_imm>>:$true,
1422 // (imm:i32):$cc)
1423 // Emits: (MOVCCi:i32 GPR:i32:$false,
1424 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1425 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001426 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001427 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001428 CCVal, CCR, InFlag);
1429 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001430 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001431 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1432 if (Res)
1433 return Res;
1434 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001435 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001436 CCVal, CCR, InFlag);
1437 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001438 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001439 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1440 if (Res)
1441 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001442 }
1443 }
1444
1445 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1446 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1447 // Pattern complexity = 6 cost = 1 size = 0
1448 //
1449 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1450 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1451 // Pattern complexity = 6 cost = 11 size = 0
1452 //
1453 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001454 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1455 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001456 unsigned Opc = 0;
1457 switch (VT.getSimpleVT().SimpleTy) {
1458 default: assert(false && "Illegal conditional move type!");
1459 break;
1460 case MVT::i32:
1461 Opc = Subtarget->isThumb()
1462 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1463 : ARM::MOVCCr;
1464 break;
1465 case MVT::f32:
1466 Opc = ARM::VMOVScc;
1467 break;
1468 case MVT::f64:
1469 Opc = ARM::VMOVDcc;
1470 break;
1471 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001472 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001473}
1474
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001475SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001476 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001477
Dan Gohmane8be6c62008-07-17 19:10:17 +00001478 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001479 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001480
1481 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001482 default: break;
1483 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001484 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001485 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001486 if (Subtarget->hasThumb2())
1487 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1488 // be done with MOV + MOVT, at worst.
1489 UseCP = 0;
1490 else {
1491 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001492 UseCP = (Val > 255 && // MOV
1493 ~Val > 255 && // MOV + MVN
1494 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001495 } else
1496 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1497 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1498 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1499 }
1500
Evan Chenga8e29892007-01-19 07:51:42 +00001501 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001502 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001503 CurDAG->getTargetConstantPool(ConstantInt::get(
1504 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001505 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001506
1507 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001508 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001509 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001510 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001511 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001512 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1513 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001514 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001515 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001516 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001517 CurDAG->getRegister(0, MVT::i32),
1518 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001519 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001520 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001521 CurDAG->getEntryNode()
1522 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001523 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1524 Ops, 6);
Evan Cheng012f2d92007-01-24 08:53:17 +00001525 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001526 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001527 return NULL;
1528 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001529
Evan Chenga8e29892007-01-19 07:51:42 +00001530 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001531 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001532 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001533 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001534 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001535 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001536 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001537 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001538 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1539 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001540 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001541 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1542 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001543 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1544 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1545 CurDAG->getRegister(0, MVT::i32) };
1546 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001547 }
Evan Chenga8e29892007-01-19 07:51:42 +00001548 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001549 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001550 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001551 return I;
1552 break;
1553 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001554 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001555 return I;
1556 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001557 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001558 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001559 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001560 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001561 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001562 if (!RHSV) break;
1563 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001564 unsigned ShImm = Log2_32(RHSV-1);
1565 if (ShImm >= 32)
1566 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001567 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001568 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001569 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1570 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001571 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001572 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001573 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001574 } else {
1575 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001576 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001577 }
Evan Chenga8e29892007-01-19 07:51:42 +00001578 }
1579 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001580 unsigned ShImm = Log2_32(RHSV+1);
1581 if (ShImm >= 32)
1582 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001583 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001584 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001585 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1586 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001587 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001588 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001589 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 5);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001590 } else {
1591 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001592 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001593 }
Evan Chenga8e29892007-01-19 07:51:42 +00001594 }
1595 }
1596 break;
Evan Cheng20956592009-10-21 08:15:52 +00001597 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001598 // Check for unsigned bitfield extract
1599 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1600 return I;
1601
Evan Cheng20956592009-10-21 08:15:52 +00001602 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1603 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1604 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1605 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1606 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001607 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001608 if (VT != MVT::i32)
1609 break;
1610 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1611 ? ARM::t2MOVTi16
1612 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1613 if (!Opc)
1614 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001615 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001616 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1617 if (!N1C)
1618 break;
1619 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1620 SDValue N2 = N0.getOperand(1);
1621 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1622 if (!N2C)
1623 break;
1624 unsigned N1CVal = N1C->getZExtValue();
1625 unsigned N2CVal = N2C->getZExtValue();
1626 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1627 (N1CVal & 0xffffU) == 0xffffU &&
1628 (N2CVal & 0xffffU) == 0x0U) {
1629 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1630 MVT::i32);
1631 SDValue Ops[] = { N0.getOperand(0), Imm16,
1632 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1633 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
1634 }
1635 }
1636 break;
1637 }
Jim Grosbache5165492009-11-09 00:11:35 +00001638 case ARMISD::VMOVRRD:
1639 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001640 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00001641 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00001642 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001643 if (Subtarget->isThumb1Only())
1644 break;
1645 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001646 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001647 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1648 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001649 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001650 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001651 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001652 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1653 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001654 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001655 }
Evan Chengee568cf2007-07-05 07:15:27 +00001656 }
Dan Gohman525178c2007-10-08 18:33:35 +00001657 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001658 if (Subtarget->isThumb1Only())
1659 break;
1660 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001661 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001662 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001663 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001664 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001665 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001666 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1667 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001668 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001669 }
Evan Chengee568cf2007-07-05 07:15:27 +00001670 }
Evan Chenga8e29892007-01-19 07:51:42 +00001671 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00001672 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001673 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001674 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001675 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001676 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001677 if (ResNode)
1678 return ResNode;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00001679
1680 // VLDMQ must be custom-selected for "v2f64 load" to set the AM5Opc value.
1681 if (Subtarget->hasVFP2() &&
1682 N->getValueType(0).getSimpleVT().SimpleTy == MVT::v2f64) {
1683 SDValue Chain = N->getOperand(0);
1684 SDValue AM5Opc =
1685 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001686 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00001687 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1688 SDValue Ops[] = { N->getOperand(1), AM5Opc, Pred, PredReg, Chain };
1689 return CurDAG->getMachineNode(ARM::VLDMQ, dl, MVT::v2f64, MVT::Other,
1690 Ops, 5);
1691 }
1692 // Other cases are autogenerated.
1693 break;
1694 }
1695 case ISD::STORE: {
1696 // VSTMQ must be custom-selected for "v2f64 store" to set the AM5Opc value.
1697 if (Subtarget->hasVFP2() &&
1698 N->getOperand(1).getValueType().getSimpleVT().SimpleTy == MVT::v2f64) {
1699 SDValue Chain = N->getOperand(0);
1700 SDValue AM5Opc =
1701 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001702 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00001703 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1704 SDValue Ops[] = { N->getOperand(1), N->getOperand(2),
1705 AM5Opc, Pred, PredReg, Chain };
1706 return CurDAG->getMachineNode(ARM::VSTMQ, dl, MVT::Other, Ops, 6);
1707 }
Evan Chenga8e29892007-01-19 07:51:42 +00001708 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001709 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001710 }
Evan Chengee568cf2007-07-05 07:15:27 +00001711 case ARMISD::BRCOND: {
1712 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1713 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1714 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001715
Evan Chengee568cf2007-07-05 07:15:27 +00001716 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1717 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
1718 // Pattern complexity = 6 cost = 1 size = 0
1719
David Goodwin5e47a9a2009-06-30 18:04:13 +00001720 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1721 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1722 // Pattern complexity = 6 cost = 1 size = 0
1723
Jim Grosbach764ab522009-08-11 15:33:49 +00001724 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00001725 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001726 SDValue Chain = N->getOperand(0);
1727 SDValue N1 = N->getOperand(1);
1728 SDValue N2 = N->getOperand(2);
1729 SDValue N3 = N->getOperand(3);
1730 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00001731 assert(N1.getOpcode() == ISD::BasicBlock);
1732 assert(N2.getOpcode() == ISD::Constant);
1733 assert(N3.getOpcode() == ISD::Register);
1734
Dan Gohman475871a2008-07-27 21:46:04 +00001735 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001736 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00001737 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00001738 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00001739 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
1740 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00001741 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001742 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00001743 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001744 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00001745 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001746 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00001747 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00001748 return NULL;
1749 }
Evan Cheng07ba9062009-11-19 21:45:22 +00001750 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001751 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00001752 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001753 EVT VT = N->getValueType(0);
1754 SDValue N0 = N->getOperand(0);
1755 SDValue N1 = N->getOperand(1);
1756 SDValue N2 = N->getOperand(2);
1757 SDValue N3 = N->getOperand(3);
1758 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00001759 assert(N2.getOpcode() == ISD::Constant);
1760 assert(N3.getOpcode() == ISD::Register);
1761
Dan Gohman475871a2008-07-27 21:46:04 +00001762 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001763 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00001764 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00001765 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00001766 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00001767 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00001768 default: assert(false && "Illegal conditional move type!");
1769 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001770 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00001771 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00001772 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001773 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00001774 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00001775 break;
Evan Chengee568cf2007-07-05 07:15:27 +00001776 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001777 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001778 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00001779
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001780 case ARMISD::VZIP: {
1781 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001782 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001783 switch (VT.getSimpleVT().SimpleTy) {
1784 default: return NULL;
1785 case MVT::v8i8: Opc = ARM::VZIPd8; break;
1786 case MVT::v4i16: Opc = ARM::VZIPd16; break;
1787 case MVT::v2f32:
1788 case MVT::v2i32: Opc = ARM::VZIPd32; break;
1789 case MVT::v16i8: Opc = ARM::VZIPq8; break;
1790 case MVT::v8i16: Opc = ARM::VZIPq16; break;
1791 case MVT::v4f32:
1792 case MVT::v4i32: Opc = ARM::VZIPq32; break;
1793 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001794 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00001795 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1796 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1797 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001798 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001799 case ARMISD::VUZP: {
1800 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001801 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001802 switch (VT.getSimpleVT().SimpleTy) {
1803 default: return NULL;
1804 case MVT::v8i8: Opc = ARM::VUZPd8; break;
1805 case MVT::v4i16: Opc = ARM::VUZPd16; break;
1806 case MVT::v2f32:
1807 case MVT::v2i32: Opc = ARM::VUZPd32; break;
1808 case MVT::v16i8: Opc = ARM::VUZPq8; break;
1809 case MVT::v8i16: Opc = ARM::VUZPq16; break;
1810 case MVT::v4f32:
1811 case MVT::v4i32: Opc = ARM::VUZPq32; break;
1812 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001813 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00001814 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1815 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1816 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001817 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001818 case ARMISD::VTRN: {
1819 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001820 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001821 switch (VT.getSimpleVT().SimpleTy) {
1822 default: return NULL;
1823 case MVT::v8i8: Opc = ARM::VTRNd8; break;
1824 case MVT::v4i16: Opc = ARM::VTRNd16; break;
1825 case MVT::v2f32:
1826 case MVT::v2i32: Opc = ARM::VTRNd32; break;
1827 case MVT::v16i8: Opc = ARM::VTRNq8; break;
1828 case MVT::v8i16: Opc = ARM::VTRNq16; break;
1829 case MVT::v4f32:
1830 case MVT::v4i32: Opc = ARM::VTRNq32; break;
1831 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001832 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00001833 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1834 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1835 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001836 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00001837
1838 case ISD::INTRINSIC_VOID:
1839 case ISD::INTRINSIC_W_CHAIN: {
1840 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00001841 switch (IntNo) {
1842 default:
1843 break;
1844
Bob Wilson621f1952010-03-23 05:25:43 +00001845 case Intrinsic::arm_neon_vld1: {
1846 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
1847 ARM::VLD1d32, ARM::VLD1d64 };
1848 unsigned QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
1849 ARM::VLD1q32, ARM::VLD1q64 };
1850 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
1851 }
1852
Bob Wilson31fb12f2009-08-26 17:39:53 +00001853 case Intrinsic::arm_neon_vld2: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001854 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
Bob Wilson621f1952010-03-23 05:25:43 +00001855 ARM::VLD2d32, ARM::VLD1q64 };
Bob Wilson3e36f132009-10-14 17:28:52 +00001856 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001857 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001858 }
1859
1860 case Intrinsic::arm_neon_vld3: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001861 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00001862 ARM::VLD3d32, ARM::VLD1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001863 unsigned QOpcodes0[] = { ARM::VLD3q8_UPD,
1864 ARM::VLD3q16_UPD,
1865 ARM::VLD3q32_UPD };
1866 unsigned QOpcodes1[] = { ARM::VLD3q8odd_UPD,
1867 ARM::VLD3q16odd_UPD,
1868 ARM::VLD3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001869 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001870 }
1871
1872 case Intrinsic::arm_neon_vld4: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001873 unsigned DOpcodes[] = { ARM::VLD4d8, ARM::VLD4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00001874 ARM::VLD4d32, ARM::VLD1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001875 unsigned QOpcodes0[] = { ARM::VLD4q8_UPD,
1876 ARM::VLD4q16_UPD,
1877 ARM::VLD4q32_UPD };
1878 unsigned QOpcodes1[] = { ARM::VLD4q8odd_UPD,
1879 ARM::VLD4q16odd_UPD,
1880 ARM::VLD4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001881 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001882 }
1883
Bob Wilson243fcc52009-09-01 04:26:28 +00001884 case Intrinsic::arm_neon_vld2lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00001885 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001886 unsigned QOpcodes0[] = { ARM::VLD2LNq16, ARM::VLD2LNq32 };
1887 unsigned QOpcodes1[] = { ARM::VLD2LNq16odd, ARM::VLD2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001888 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00001889 }
1890
1891 case Intrinsic::arm_neon_vld3lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00001892 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001893 unsigned QOpcodes0[] = { ARM::VLD3LNq16, ARM::VLD3LNq32 };
1894 unsigned QOpcodes1[] = { ARM::VLD3LNq16odd, ARM::VLD3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001895 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00001896 }
1897
1898 case Intrinsic::arm_neon_vld4lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00001899 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001900 unsigned QOpcodes0[] = { ARM::VLD4LNq16, ARM::VLD4LNq32 };
1901 unsigned QOpcodes1[] = { ARM::VLD4LNq16odd, ARM::VLD4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001902 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00001903 }
1904
Bob Wilson11d98992010-03-23 06:20:33 +00001905 case Intrinsic::arm_neon_vst1: {
1906 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
1907 ARM::VST1d32, ARM::VST1d64 };
1908 unsigned QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
1909 ARM::VST1q32, ARM::VST1q64 };
1910 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
1911 }
1912
Bob Wilson31fb12f2009-08-26 17:39:53 +00001913 case Intrinsic::arm_neon_vst2: {
Bob Wilson24f995d2009-10-14 18:32:29 +00001914 unsigned DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
Bob Wilson11d98992010-03-23 06:20:33 +00001915 ARM::VST2d32, ARM::VST1q64 };
Bob Wilson24f995d2009-10-14 18:32:29 +00001916 unsigned QOpcodes[] = { ARM::VST2q8, ARM::VST2q16, ARM::VST2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001917 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001918 }
1919
1920 case Intrinsic::arm_neon_vst3: {
Bob Wilson24f995d2009-10-14 18:32:29 +00001921 unsigned DOpcodes[] = { ARM::VST3d8, ARM::VST3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00001922 ARM::VST3d32, ARM::VST1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001923 unsigned QOpcodes0[] = { ARM::VST3q8_UPD,
1924 ARM::VST3q16_UPD,
1925 ARM::VST3q32_UPD };
1926 unsigned QOpcodes1[] = { ARM::VST3q8odd_UPD,
1927 ARM::VST3q16odd_UPD,
1928 ARM::VST3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001929 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001930 }
1931
1932 case Intrinsic::arm_neon_vst4: {
Bob Wilson24f995d2009-10-14 18:32:29 +00001933 unsigned DOpcodes[] = { ARM::VST4d8, ARM::VST4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00001934 ARM::VST4d32, ARM::VST1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001935 unsigned QOpcodes0[] = { ARM::VST4q8_UPD,
1936 ARM::VST4q16_UPD,
1937 ARM::VST4q32_UPD };
1938 unsigned QOpcodes1[] = { ARM::VST4q8odd_UPD,
1939 ARM::VST4q16odd_UPD,
1940 ARM::VST4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001941 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001942 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00001943
1944 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson96493442009-10-14 16:46:45 +00001945 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001946 unsigned QOpcodes0[] = { ARM::VST2LNq16, ARM::VST2LNq32 };
1947 unsigned QOpcodes1[] = { ARM::VST2LNq16odd, ARM::VST2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001948 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00001949 }
1950
1951 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson96493442009-10-14 16:46:45 +00001952 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001953 unsigned QOpcodes0[] = { ARM::VST3LNq16, ARM::VST3LNq32 };
1954 unsigned QOpcodes1[] = { ARM::VST3LNq16odd, ARM::VST3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001955 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00001956 }
1957
1958 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson96493442009-10-14 16:46:45 +00001959 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001960 unsigned QOpcodes0[] = { ARM::VST4LNq16, ARM::VST4LNq32 };
1961 unsigned QOpcodes1[] = { ARM::VST4LNq16odd, ARM::VST4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001962 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00001963 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00001964 }
1965 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00001966 }
1967
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001968 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00001969}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001970
Bob Wilson224c2442009-05-19 05:53:42 +00001971bool ARMDAGToDAGISel::
1972SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
1973 std::vector<SDValue> &OutOps) {
1974 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00001975 // Require the address to be in a register. That is safe for all ARM
1976 // variants and it is hard to do anything much smarter without knowing
1977 // how the operand is used.
1978 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00001979 return false;
1980}
1981
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001982/// createARMISelDag - This pass converts a legalized DAG into a
1983/// ARM-specific DAG, ready for instruction scheduling.
1984///
Bob Wilson522ce972009-09-28 14:30:20 +00001985FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
1986 CodeGenOpt::Level OptLevel) {
1987 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001988}