blob: 14a45b3ab45c342bc653641c9a7845babdc75102 [file] [log] [blame]
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001//===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the ARM target.
11//
12//===----------------------------------------------------------------------===//
13
14#include "ARM.h"
Evan Chenge5ad88e2008-12-10 21:54:21 +000015#include "ARMAddressingModes.h"
Evan Chenga8e29892007-01-19 07:51:42 +000016#include "ARMISelLowering.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000017#include "ARMTargetMachine.h"
Rafael Espindola84b19be2006-07-16 01:02:57 +000018#include "llvm/CallingConv.h"
Evan Chenga8e29892007-01-19 07:51:42 +000019#include "llvm/Constants.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000020#include "llvm/DerivedTypes.h"
21#include "llvm/Function.h"
22#include "llvm/Intrinsics.h"
Owen Anderson9adc0ab2009-07-14 23:09:55 +000023#include "llvm/LLVMContext.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000024#include "llvm/CodeGen/MachineFrameInfo.h"
25#include "llvm/CodeGen/MachineFunction.h"
26#include "llvm/CodeGen/MachineInstrBuilder.h"
27#include "llvm/CodeGen/SelectionDAG.h"
28#include "llvm/CodeGen/SelectionDAGISel.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000029#include "llvm/Target/TargetLowering.h"
Chris Lattner72939122007-05-03 00:32:00 +000030#include "llvm/Target/TargetOptions.h"
Chris Lattner3d62d782008-02-03 05:43:57 +000031#include "llvm/Support/Compiler.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000032#include "llvm/Support/Debug.h"
Torok Edwindac237e2009-07-08 20:53:28 +000033#include "llvm/Support/ErrorHandling.h"
34#include "llvm/Support/raw_ostream.h"
35
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000036using namespace llvm;
37
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000038//===--------------------------------------------------------------------===//
39/// ARMDAGToDAGISel - ARM specific code to select ARM machine
40/// instructions for SelectionDAG operations.
41///
42namespace {
43class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000044 ARMBaseTargetMachine &TM;
Evan Cheng3f7eb8e2008-09-18 07:24:33 +000045
Evan Chenga8e29892007-01-19 07:51:42 +000046 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
47 /// make the right decision when generating code for different targets.
48 const ARMSubtarget *Subtarget;
49
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000050public:
Bob Wilson522ce972009-09-28 14:30:20 +000051 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
52 CodeGenOpt::Level OptLevel)
53 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Chenga8e29892007-01-19 07:51:42 +000054 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000055 }
56
Evan Chenga8e29892007-01-19 07:51:42 +000057 virtual const char *getPassName() const {
58 return "ARM Instruction Selection";
Anton Korobeynikov52237112009-06-17 18:13:58 +000059 }
60
Bob Wilsonaf4a8912009-10-08 18:51:31 +000061 /// getI32Imm - Return a target constant of type i32 with the specified
62 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000063 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000064 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000065 }
66
Dan Gohmaneeb3a002010-01-05 01:24:18 +000067 SDNode *Select(SDNode *N);
Dan Gohmanf350b272008-08-23 02:25:05 +000068 virtual void InstructionSelect();
Dan Gohmaneeb3a002010-01-05 01:24:18 +000069 bool SelectShifterOperandReg(SDNode *Op, SDValue N, SDValue &A,
Evan Cheng055b0312009-06-29 07:51:04 +000070 SDValue &B, SDValue &C);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000071 bool SelectAddrMode2(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000072 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000073 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +000074 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000075 bool SelectAddrMode3(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000076 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000077 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +000078 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000079 bool SelectAddrMode4(SDNode *Op, SDValue N, SDValue &Addr,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +000080 SDValue &Mode);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000081 bool SelectAddrMode5(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000082 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000083 bool SelectAddrMode6(SDNode *Op, SDValue N, SDValue &Addr, SDValue &Update,
Jim Grosbach8a5ec862009-11-07 21:25:39 +000084 SDValue &Opc, SDValue &Align);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000085
Dan Gohmaneeb3a002010-01-05 01:24:18 +000086 bool SelectAddrModePC(SDNode *Op, SDValue N, SDValue &Offset,
Bob Wilson8b024a52009-07-01 23:16:05 +000087 SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +000088
Dan Gohmaneeb3a002010-01-05 01:24:18 +000089 bool SelectThumbAddrModeRR(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000090 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000091 bool SelectThumbAddrModeRI5(SDNode *Op, SDValue N, unsigned Scale,
Dan Gohman475871a2008-07-27 21:46:04 +000092 SDValue &Base, SDValue &OffImm,
93 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000094 bool SelectThumbAddrModeS1(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 SelectThumbAddrModeS2(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 SelectThumbAddrModeS4(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000099 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000100 bool SelectThumbAddrModeSP(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000101 SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000102
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000103 bool SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000104 SDValue &BaseReg, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000105 bool SelectT2AddrModeImm12(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 SelectT2AddrModeImm8(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000108 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000109 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000110 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000111 bool SelectT2AddrModeImm8s4(SDNode *Op, SDValue N, SDValue &Base,
David Goodwin6647cea2009-06-30 22:50:01 +0000112 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000113 bool SelectT2AddrModeSoReg(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000114 SDValue &OffReg, SDValue &ShImm);
115
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000116 // Include the pieces autogenerated from the target description.
117#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000118
119private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000120 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
121 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000122 SDNode *SelectARMIndexedLoad(SDNode *N);
123 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000124
Evan Cheng86198642009-08-07 00:34:42 +0000125 /// SelectDYN_ALLOC - Select dynamic alloc for Thumb.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000126 SDNode *SelectDYN_ALLOC(SDNode *N);
Evan Chengaf4550f2009-07-02 01:23:32 +0000127
Bob Wilson3e36f132009-10-14 17:28:52 +0000128 /// SelectVLD - Select NEON load intrinsics. NumVecs should
129 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
130 /// loads of D registers and even subregs and odd subregs of Q registers.
131 /// For NumVecs == 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000132 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000133 unsigned *QOpcodes0, unsigned *QOpcodes1);
134
Bob Wilson24f995d2009-10-14 18:32:29 +0000135 /// SelectVST - Select NEON store intrinsics. NumVecs should
136 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
137 /// stores of D registers and even subregs and odd subregs of Q registers.
138 /// For NumVecs == 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000139 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000140 unsigned *QOpcodes0, unsigned *QOpcodes1);
141
Bob Wilson96493442009-10-14 16:46:45 +0000142 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000143 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson96493442009-10-14 16:46:45 +0000144 /// load/store of D registers and even subregs and odd subregs of Q registers.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000145 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
Bob Wilson96493442009-10-14 16:46:45 +0000146 unsigned *DOpcodes, unsigned *QOpcodes0,
147 unsigned *QOpcodes1);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000148
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000149 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000150 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, unsigned Opc);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000151
Evan Cheng07ba9062009-11-19 21:45:22 +0000152 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000153 SDNode *SelectCMOVOp(SDNode *N);
154 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000155 ARMCC::CondCodes CCVal, SDValue CCR,
156 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000157 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000158 ARMCC::CondCodes CCVal, SDValue CCR,
159 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000160 SDNode *SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000161 ARMCC::CondCodes CCVal, SDValue CCR,
162 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000163 SDNode *SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000164 ARMCC::CondCodes CCVal, SDValue CCR,
165 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000166
Evan Chengaf4550f2009-07-02 01:23:32 +0000167 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
168 /// inline asm expressions.
169 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
170 char ConstraintCode,
171 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000172
173 /// PairDRegs - Insert a pair of double registers into an implicit def to
174 /// form a quad register.
175 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000176};
Evan Chenga8e29892007-01-19 07:51:42 +0000177}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000178
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000179/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
180/// operand. If so Imm will receive the 32-bit value.
181static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
182 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
183 Imm = cast<ConstantSDNode>(N)->getZExtValue();
184 return true;
185 }
186 return false;
187}
188
189// isInt32Immediate - This method tests to see if a constant operand.
190// If so Imm will receive the 32 bit value.
191static bool isInt32Immediate(SDValue N, unsigned &Imm) {
192 return isInt32Immediate(N.getNode(), Imm);
193}
194
195// isOpcWithIntImmediate - This method tests to see if the node is a specific
196// opcode and that it has a immediate integer right operand.
197// If so Imm will receive the 32 bit value.
198static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
199 return N->getOpcode() == Opc &&
200 isInt32Immediate(N->getOperand(1).getNode(), Imm);
201}
202
203
Dan Gohmanf350b272008-08-23 02:25:05 +0000204void ARMDAGToDAGISel::InstructionSelect() {
David Greene8ad4c002008-10-27 21:56:29 +0000205 SelectRoot(*CurDAG);
Dan Gohmanf350b272008-08-23 02:25:05 +0000206 CurDAG->RemoveDeadNodes();
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000207}
208
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000209bool ARMDAGToDAGISel::SelectShifterOperandReg(SDNode *Op,
Evan Cheng055b0312009-06-29 07:51:04 +0000210 SDValue N,
211 SDValue &BaseReg,
212 SDValue &ShReg,
213 SDValue &Opc) {
214 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
215
216 // Don't match base register only case. That is matched to a separate
217 // lower complexity pattern with explicit register operand.
218 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000219
Evan Cheng055b0312009-06-29 07:51:04 +0000220 BaseReg = N.getOperand(0);
221 unsigned ShImmVal = 0;
222 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000223 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000224 ShImmVal = RHS->getZExtValue() & 31;
225 } else {
226 ShReg = N.getOperand(1);
227 }
228 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000229 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000230 return true;
231}
232
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000233bool ARMDAGToDAGISel::SelectAddrMode2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000234 SDValue &Base, SDValue &Offset,
235 SDValue &Opc) {
Evan Chenga13fd102007-03-13 21:05:54 +0000236 if (N.getOpcode() == ISD::MUL) {
237 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
238 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000239 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000240 if (RHSC & 1) {
241 RHSC = RHSC & ~1;
242 ARM_AM::AddrOpc AddSub = ARM_AM::add;
243 if (RHSC < 0) {
244 AddSub = ARM_AM::sub;
245 RHSC = - RHSC;
246 }
247 if (isPowerOf2_32(RHSC)) {
248 unsigned ShAmt = Log2_32(RHSC);
249 Base = Offset = N.getOperand(0);
250 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
251 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000252 MVT::i32);
Evan Chenga13fd102007-03-13 21:05:54 +0000253 return true;
254 }
255 }
256 }
257 }
258
Evan Chenga8e29892007-01-19 07:51:42 +0000259 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
260 Base = N;
261 if (N.getOpcode() == ISD::FrameIndex) {
262 int FI = cast<FrameIndexSDNode>(N)->getIndex();
263 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000264 } else if (N.getOpcode() == ARMISD::Wrapper &&
265 !(Subtarget->useMovt() &&
266 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000267 Base = N.getOperand(0);
268 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000269 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000270 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
271 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000272 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000273 return true;
274 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000275
Evan Chenga8e29892007-01-19 07:51:42 +0000276 // Match simple R +/- imm12 operands.
277 if (N.getOpcode() == ISD::ADD)
278 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000279 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000280 if ((RHSC >= 0 && RHSC < 0x1000) ||
281 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000282 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000283 if (Base.getOpcode() == ISD::FrameIndex) {
284 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
285 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
286 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000287 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000288
289 ARM_AM::AddrOpc AddSub = ARM_AM::add;
290 if (RHSC < 0) {
291 AddSub = ARM_AM::sub;
292 RHSC = - RHSC;
293 }
294 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000295 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000296 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000297 return true;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000298 }
Evan Chenga8e29892007-01-19 07:51:42 +0000299 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000300
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000301 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000302 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
303 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
304 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000305
Evan Chenga8e29892007-01-19 07:51:42 +0000306 Base = N.getOperand(0);
307 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000308
Evan Chenga8e29892007-01-19 07:51:42 +0000309 if (ShOpcVal != ARM_AM::no_shift) {
310 // Check to see if the RHS of the shift is a constant, if not, we can't fold
311 // it.
312 if (ConstantSDNode *Sh =
313 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000314 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000315 Offset = N.getOperand(1).getOperand(0);
316 } else {
317 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000318 }
319 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000320
Evan Chenga8e29892007-01-19 07:51:42 +0000321 // Try matching (R shl C) + (R).
322 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
323 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
324 if (ShOpcVal != ARM_AM::no_shift) {
325 // Check to see if the RHS of the shift is a constant, if not, we can't
326 // fold it.
327 if (ConstantSDNode *Sh =
328 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000329 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000330 Offset = N.getOperand(0).getOperand(0);
331 Base = N.getOperand(1);
332 } else {
333 ShOpcVal = ARM_AM::no_shift;
334 }
335 }
336 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000337
Evan Chenga8e29892007-01-19 07:51:42 +0000338 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000339 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000340 return true;
341}
342
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000343bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000344 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000345 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000346 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
347 ? cast<LoadSDNode>(Op)->getAddressingMode()
348 : cast<StoreSDNode>(Op)->getAddressingMode();
349 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
350 ? ARM_AM::add : ARM_AM::sub;
351 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000352 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000353 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000354 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000355 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
356 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000357 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000358 return true;
359 }
360 }
361
362 Offset = N;
363 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
364 unsigned ShAmt = 0;
365 if (ShOpcVal != ARM_AM::no_shift) {
366 // Check to see if the RHS of the shift is a constant, if not, we can't fold
367 // it.
368 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000369 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000370 Offset = N.getOperand(0);
371 } else {
372 ShOpcVal = ARM_AM::no_shift;
373 }
374 }
375
376 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000377 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000378 return true;
379}
380
Evan Chenga8e29892007-01-19 07:51:42 +0000381
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000382bool ARMDAGToDAGISel::SelectAddrMode3(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000383 SDValue &Base, SDValue &Offset,
384 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000385 if (N.getOpcode() == ISD::SUB) {
386 // X - C is canonicalize to X + -C, no need to handle it here.
387 Base = N.getOperand(0);
388 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000389 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000390 return true;
391 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000392
Evan Chenga8e29892007-01-19 07:51:42 +0000393 if (N.getOpcode() != ISD::ADD) {
394 Base = N;
395 if (N.getOpcode() == ISD::FrameIndex) {
396 int FI = cast<FrameIndexSDNode>(N)->getIndex();
397 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
398 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000399 Offset = CurDAG->getRegister(0, MVT::i32);
400 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000401 return true;
402 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000403
Evan Chenga8e29892007-01-19 07:51:42 +0000404 // If the RHS is +/- imm8, fold into addr mode.
405 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000406 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000407 if ((RHSC >= 0 && RHSC < 256) ||
408 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000409 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000410 if (Base.getOpcode() == ISD::FrameIndex) {
411 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
412 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
413 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000414 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000415
416 ARM_AM::AddrOpc AddSub = ARM_AM::add;
417 if (RHSC < 0) {
418 AddSub = ARM_AM::sub;
419 RHSC = - RHSC;
420 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000421 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000422 return true;
423 }
424 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000425
Evan Chenga8e29892007-01-19 07:51:42 +0000426 Base = N.getOperand(0);
427 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000428 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000429 return true;
430}
431
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000432bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000433 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000434 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000435 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
436 ? cast<LoadSDNode>(Op)->getAddressingMode()
437 : cast<StoreSDNode>(Op)->getAddressingMode();
438 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
439 ? ARM_AM::add : ARM_AM::sub;
440 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000441 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000442 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000443 Offset = CurDAG->getRegister(0, MVT::i32);
444 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000445 return true;
446 }
447 }
448
449 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000450 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000451 return true;
452}
453
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000454bool ARMDAGToDAGISel::SelectAddrMode4(SDNode *Op, SDValue N,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000455 SDValue &Addr, SDValue &Mode) {
456 Addr = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000457 Mode = CurDAG->getTargetConstant(0, MVT::i32);
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000458 return true;
459}
Evan Chenga8e29892007-01-19 07:51:42 +0000460
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000461bool ARMDAGToDAGISel::SelectAddrMode5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000462 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000463 if (N.getOpcode() != ISD::ADD) {
464 Base = N;
465 if (N.getOpcode() == ISD::FrameIndex) {
466 int FI = cast<FrameIndexSDNode>(N)->getIndex();
467 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000468 } else if (N.getOpcode() == ARMISD::Wrapper &&
469 !(Subtarget->useMovt() &&
470 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000471 Base = N.getOperand(0);
472 }
473 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000474 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000475 return true;
476 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000477
Evan Chenga8e29892007-01-19 07:51:42 +0000478 // If the RHS is +/- imm8, fold into addr mode.
479 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000480 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000481 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
482 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000483 if ((RHSC >= 0 && RHSC < 256) ||
484 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000485 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000486 if (Base.getOpcode() == ISD::FrameIndex) {
487 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
488 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
489 }
490
491 ARM_AM::AddrOpc AddSub = ARM_AM::add;
492 if (RHSC < 0) {
493 AddSub = ARM_AM::sub;
494 RHSC = - RHSC;
495 }
496 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000497 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000498 return true;
499 }
500 }
501 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000502
Evan Chenga8e29892007-01-19 07:51:42 +0000503 Base = N;
504 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000505 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000506 return true;
507}
508
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000509bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Op, SDValue N,
Bob Wilson8b024a52009-07-01 23:16:05 +0000510 SDValue &Addr, SDValue &Update,
Jim Grosbach8a5ec862009-11-07 21:25:39 +0000511 SDValue &Opc, SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000512 Addr = N;
Bob Wilsonff8952e2009-10-07 17:24:55 +0000513 // Default to no writeback.
Owen Anderson825b72b2009-08-11 20:47:22 +0000514 Update = CurDAG->getRegister(0, MVT::i32);
515 Opc = CurDAG->getTargetConstant(ARM_AM::getAM6Opc(false), MVT::i32);
Jim Grosbach8a5ec862009-11-07 21:25:39 +0000516 // Default to no alignment.
517 Align = CurDAG->getTargetConstant(0, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000518 return true;
519}
520
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000521bool ARMDAGToDAGISel::SelectAddrModePC(SDNode *Op, SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000522 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000523 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
524 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000525 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000526 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000527 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000528 return true;
529 }
530 return false;
531}
532
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000533bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000534 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000535 // FIXME dl should come from the parent load or store, not the address
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000536 DebugLoc dl = Op->getDebugLoc();
Evan Chengc38f2bc2007-01-23 22:59:13 +0000537 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000538 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
539 if (!NC || NC->getZExtValue() != 0)
540 return false;
541
542 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000543 return true;
544 }
545
Evan Chenga8e29892007-01-19 07:51:42 +0000546 Base = N.getOperand(0);
547 Offset = N.getOperand(1);
548 return true;
549}
550
Evan Cheng79d43262007-01-24 02:21:22 +0000551bool
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000552ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000553 unsigned Scale, SDValue &Base,
554 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000555 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000556 SDValue TmpBase, TmpOffImm;
Evan Cheng79d43262007-01-24 02:21:22 +0000557 if (SelectThumbAddrModeSP(Op, N, TmpBase, TmpOffImm))
558 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000559 if (N.getOpcode() == ARMISD::Wrapper &&
560 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
561 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000562 }
563
Evan Chenga8e29892007-01-19 07:51:42 +0000564 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000565 if (N.getOpcode() == ARMISD::Wrapper &&
566 !(Subtarget->useMovt() &&
567 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
568 Base = N.getOperand(0);
569 } else
570 Base = N;
571
Owen Anderson825b72b2009-08-11 20:47:22 +0000572 Offset = CurDAG->getRegister(0, MVT::i32);
573 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000574 return true;
575 }
576
Evan Chengad0e4652007-02-06 00:22:06 +0000577 // Thumb does not have [sp, r] address mode.
578 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
579 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
580 if ((LHSR && LHSR->getReg() == ARM::SP) ||
581 (RHSR && RHSR->getReg() == ARM::SP)) {
582 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000583 Offset = CurDAG->getRegister(0, MVT::i32);
584 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000585 return true;
586 }
587
Evan Chenga8e29892007-01-19 07:51:42 +0000588 // If the RHS is + imm5 * scale, fold into addr mode.
589 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000590 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000591 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
592 RHSC /= Scale;
593 if (RHSC >= 0 && RHSC < 32) {
594 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000595 Offset = CurDAG->getRegister(0, MVT::i32);
596 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000597 return true;
598 }
599 }
600 }
601
Evan Chengc38f2bc2007-01-23 22:59:13 +0000602 Base = N.getOperand(0);
603 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000604 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000605 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000606}
607
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000608bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000609 SDValue &Base, SDValue &OffImm,
610 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000611 return SelectThumbAddrModeRI5(Op, N, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000612}
613
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000614bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000615 SDValue &Base, SDValue &OffImm,
616 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000617 return SelectThumbAddrModeRI5(Op, N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000618}
619
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000620bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000621 SDValue &Base, SDValue &OffImm,
622 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000623 return SelectThumbAddrModeRI5(Op, N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000624}
625
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000626bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000627 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000628 if (N.getOpcode() == ISD::FrameIndex) {
629 int FI = cast<FrameIndexSDNode>(N)->getIndex();
630 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000631 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000632 return true;
633 }
Evan Cheng79d43262007-01-24 02:21:22 +0000634
Evan Chengad0e4652007-02-06 00:22:06 +0000635 if (N.getOpcode() != ISD::ADD)
636 return false;
637
638 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000639 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
640 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000641 // If the RHS is + imm8 * scale, fold into addr mode.
642 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000643 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000644 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
645 RHSC >>= 2;
646 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000647 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000648 if (Base.getOpcode() == ISD::FrameIndex) {
649 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
650 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
651 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000652 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000653 return true;
654 }
655 }
656 }
657 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000658
Evan Chenga8e29892007-01-19 07:51:42 +0000659 return false;
660}
661
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000662bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000663 SDValue &BaseReg,
664 SDValue &Opc) {
665 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
666
667 // Don't match base register only case. That is matched to a separate
668 // lower complexity pattern with explicit register operand.
669 if (ShOpcVal == ARM_AM::no_shift) return false;
670
671 BaseReg = N.getOperand(0);
672 unsigned ShImmVal = 0;
673 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
674 ShImmVal = RHS->getZExtValue() & 31;
675 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
676 return true;
677 }
678
679 return false;
680}
681
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000682bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000683 SDValue &Base, SDValue &OffImm) {
684 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000685
Evan Cheng3a214252009-08-11 08:52:18 +0000686 // Base only.
687 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000688 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000689 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000690 int FI = cast<FrameIndexSDNode>(N)->getIndex();
691 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000692 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000693 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000694 } else if (N.getOpcode() == ARMISD::Wrapper &&
695 !(Subtarget->useMovt() &&
696 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000697 Base = N.getOperand(0);
698 if (Base.getOpcode() == ISD::TargetConstantPool)
699 return false; // We want to select t2LDRpci instead.
700 } else
701 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000702 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000703 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000704 }
Evan Cheng055b0312009-06-29 07:51:04 +0000705
706 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Evan Cheng3a214252009-08-11 08:52:18 +0000707 if (SelectT2AddrModeImm8(Op, N, Base, OffImm))
708 // Let t2LDRi8 handle (R - imm8).
709 return false;
710
Evan Cheng055b0312009-06-29 07:51:04 +0000711 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000712 if (N.getOpcode() == ISD::SUB)
713 RHSC = -RHSC;
714
715 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +0000716 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +0000717 if (Base.getOpcode() == ISD::FrameIndex) {
718 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
719 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
720 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000721 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000722 return true;
723 }
724 }
725
Evan Cheng3a214252009-08-11 08:52:18 +0000726 // Base only.
727 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000728 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000729 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000730}
731
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000732bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000733 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +0000734 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +0000735 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +0000736 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
737 int RHSC = (int)RHS->getSExtValue();
738 if (N.getOpcode() == ISD::SUB)
739 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +0000740
Evan Cheng3a214252009-08-11 08:52:18 +0000741 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
742 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +0000743 if (Base.getOpcode() == ISD::FrameIndex) {
744 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
745 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
746 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000747 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +0000748 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000749 }
Evan Cheng055b0312009-06-29 07:51:04 +0000750 }
751 }
752
753 return false;
754}
755
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000756bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000757 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000758 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +0000759 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
760 ? cast<LoadSDNode>(Op)->getAddressingMode()
761 : cast<StoreSDNode>(Op)->getAddressingMode();
762 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
763 int RHSC = (int)RHS->getZExtValue();
764 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +0000765 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +0000766 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
767 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000768 return true;
769 }
770 }
771
772 return false;
773}
774
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000775bool ARMDAGToDAGISel::SelectT2AddrModeImm8s4(SDNode *Op, SDValue N,
David Goodwin6647cea2009-06-30 22:50:01 +0000776 SDValue &Base, SDValue &OffImm) {
777 if (N.getOpcode() == ISD::ADD) {
778 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
779 int RHSC = (int)RHS->getZExtValue();
Evan Cheng5c874172009-07-09 22:21:59 +0000780 if (((RHSC & 0x3) == 0) &&
781 ((RHSC >= 0 && RHSC < 0x400) || (RHSC < 0 && RHSC > -0x400))) { // 8 bits.
David Goodwin6647cea2009-06-30 22:50:01 +0000782 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000783 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000784 return true;
785 }
786 }
787 } else if (N.getOpcode() == ISD::SUB) {
788 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
789 int RHSC = (int)RHS->getZExtValue();
790 if (((RHSC & 0x3) == 0) && (RHSC >= 0 && RHSC < 0x400)) { // 8 bits.
791 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000792 OffImm = CurDAG->getTargetConstant(-RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000793 return true;
794 }
795 }
796 }
797
798 return false;
799}
800
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000801bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000802 SDValue &Base,
803 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +0000804 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
805 if (N.getOpcode() != ISD::ADD)
806 return false;
Evan Cheng055b0312009-06-29 07:51:04 +0000807
Evan Cheng3a214252009-08-11 08:52:18 +0000808 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
809 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
810 int RHSC = (int)RHS->getZExtValue();
811 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
812 return false;
813 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +0000814 return false;
815 }
816
Evan Cheng055b0312009-06-29 07:51:04 +0000817 // Look for (R + R) or (R + (R << [1,2,3])).
818 unsigned ShAmt = 0;
819 Base = N.getOperand(0);
820 OffReg = N.getOperand(1);
821
822 // Swap if it is ((R << c) + R).
823 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
824 if (ShOpcVal != ARM_AM::lsl) {
825 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
826 if (ShOpcVal == ARM_AM::lsl)
827 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +0000828 }
829
Evan Cheng055b0312009-06-29 07:51:04 +0000830 if (ShOpcVal == ARM_AM::lsl) {
831 // Check to see if the RHS of the shift is a constant, if not, we can't fold
832 // it.
833 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
834 ShAmt = Sh->getZExtValue();
835 if (ShAmt >= 4) {
836 ShAmt = 0;
837 ShOpcVal = ARM_AM::no_shift;
838 } else
839 OffReg = OffReg.getOperand(0);
840 } else {
841 ShOpcVal = ARM_AM::no_shift;
842 }
David Goodwin7ecc8502009-07-15 15:50:19 +0000843 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000844
Owen Anderson825b72b2009-08-11 20:47:22 +0000845 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000846
847 return true;
848}
849
850//===--------------------------------------------------------------------===//
851
Evan Chengee568cf2007-07-05 07:15:27 +0000852/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +0000853static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000854 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +0000855}
856
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000857SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
858 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +0000859 ISD::MemIndexedMode AM = LD->getAddressingMode();
860 if (AM == ISD::UNINDEXED)
861 return NULL;
862
Owen Andersone50ed302009-08-10 22:56:29 +0000863 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +0000864 SDValue Offset, AMOpc;
865 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
866 unsigned Opcode = 0;
867 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000868 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000869 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000870 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
871 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +0000872 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000873 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000874 Match = true;
875 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
876 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
877 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +0000878 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000879 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000880 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000881 Match = true;
882 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
883 }
884 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000885 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000886 Match = true;
887 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
888 }
889 }
890 }
891
892 if (Match) {
893 SDValue Chain = LD->getChain();
894 SDValue Base = LD->getBasePtr();
895 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000896 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000897 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000898 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +0000899 }
900
901 return NULL;
902}
903
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000904SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
905 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000906 ISD::MemIndexedMode AM = LD->getAddressingMode();
907 if (AM == ISD::UNINDEXED)
908 return NULL;
909
Owen Andersone50ed302009-08-10 22:56:29 +0000910 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +0000911 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000912 SDValue Offset;
913 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
914 unsigned Opcode = 0;
915 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000916 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000917 switch (LoadedVT.getSimpleVT().SimpleTy) {
918 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000919 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
920 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000921 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000922 if (isSExtLd)
923 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
924 else
925 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000926 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000927 case MVT::i8:
928 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000929 if (isSExtLd)
930 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
931 else
932 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000933 break;
934 default:
935 return NULL;
936 }
937 Match = true;
938 }
939
940 if (Match) {
941 SDValue Chain = LD->getChain();
942 SDValue Base = LD->getBasePtr();
943 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000944 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000945 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000946 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000947 }
948
949 return NULL;
950}
951
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000952SDNode *ARMDAGToDAGISel::SelectDYN_ALLOC(SDNode *N) {
Evan Cheng86198642009-08-07 00:34:42 +0000953 DebugLoc dl = N->getDebugLoc();
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000954 EVT VT = N->getValueType(0);
955 SDValue Chain = N->getOperand(0);
956 SDValue Size = N->getOperand(1);
957 SDValue Align = N->getOperand(2);
Owen Anderson825b72b2009-08-11 20:47:22 +0000958 SDValue SP = CurDAG->getRegister(ARM::SP, MVT::i32);
Evan Cheng86198642009-08-07 00:34:42 +0000959 int32_t AlignVal = cast<ConstantSDNode>(Align)->getSExtValue();
960 if (AlignVal < 0)
961 // We need to align the stack. Use Thumb1 tAND which is the only thumb
962 // instruction that can read and write SP. This matches to a pseudo
963 // instruction that has a chain to ensure the result is written back to
964 // the stack pointer.
Dan Gohman602b0c82009-09-25 18:54:59 +0000965 SP = SDValue(CurDAG->getMachineNode(ARM::tANDsp, dl, VT, SP, Align), 0);
Evan Cheng86198642009-08-07 00:34:42 +0000966
967 bool isC = isa<ConstantSDNode>(Size);
968 uint32_t C = isC ? cast<ConstantSDNode>(Size)->getZExtValue() : ~0UL;
969 // Handle the most common case for both Thumb1 and Thumb2:
970 // tSUBspi - immediate is between 0 ... 508 inclusive.
971 if (C <= 508 && ((C & 3) == 0))
972 // FIXME: tSUBspi encode scale 4 implicitly.
Owen Anderson825b72b2009-08-11 20:47:22 +0000973 return CurDAG->SelectNodeTo(N, ARM::tSUBspi_, VT, MVT::Other, SP,
974 CurDAG->getTargetConstant(C/4, MVT::i32),
Evan Cheng86198642009-08-07 00:34:42 +0000975 Chain);
976
977 if (Subtarget->isThumb1Only()) {
Evan Chengb89030a2009-08-11 23:00:31 +0000978 // Use tADDspr since Thumb1 does not have a sub r, sp, r. ARMISelLowering
Evan Cheng86198642009-08-07 00:34:42 +0000979 // should have negated the size operand already. FIXME: We can't insert
980 // new target independent node at this stage so we are forced to negate
Jim Grosbach764ab522009-08-11 15:33:49 +0000981 // it earlier. Is there a better solution?
Owen Anderson825b72b2009-08-11 20:47:22 +0000982 return CurDAG->SelectNodeTo(N, ARM::tADDspr_, VT, MVT::Other, SP, Size,
Evan Cheng86198642009-08-07 00:34:42 +0000983 Chain);
984 } else if (Subtarget->isThumb2()) {
985 if (isC && Predicate_t2_so_imm(Size.getNode())) {
986 // t2SUBrSPi
Owen Anderson825b72b2009-08-11 20:47:22 +0000987 SDValue Ops[] = { SP, CurDAG->getTargetConstant(C, MVT::i32), Chain };
988 return CurDAG->SelectNodeTo(N, ARM::t2SUBrSPi_, VT, MVT::Other, Ops, 3);
Evan Cheng86198642009-08-07 00:34:42 +0000989 } else if (isC && Predicate_imm0_4095(Size.getNode())) {
990 // t2SUBrSPi12
Owen Anderson825b72b2009-08-11 20:47:22 +0000991 SDValue Ops[] = { SP, CurDAG->getTargetConstant(C, MVT::i32), Chain };
992 return CurDAG->SelectNodeTo(N, ARM::t2SUBrSPi12_, VT, MVT::Other, Ops, 3);
Evan Cheng86198642009-08-07 00:34:42 +0000993 } else {
994 // t2SUBrSPs
995 SDValue Ops[] = { SP, Size,
996 getI32Imm(ARM_AM::getSORegOpc(ARM_AM::lsl,0)), Chain };
Owen Anderson825b72b2009-08-11 20:47:22 +0000997 return CurDAG->SelectNodeTo(N, ARM::t2SUBrSPs_, VT, MVT::Other, Ops, 4);
Evan Cheng86198642009-08-07 00:34:42 +0000998 }
999 }
1000
1001 // FIXME: Add ADD / SUB sp instructions for ARM.
1002 return 0;
1003}
Evan Chenga8e29892007-01-19 07:51:42 +00001004
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001005/// PairDRegs - Insert a pair of double registers into an implicit def to
1006/// form a quad register.
1007SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1008 DebugLoc dl = V0.getNode()->getDebugLoc();
1009 SDValue Undef =
1010 SDValue(CurDAG->getMachineNode(TargetInstrInfo::IMPLICIT_DEF, dl, VT), 0);
1011 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
1012 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
1013 SDNode *Pair = CurDAG->getMachineNode(TargetInstrInfo::INSERT_SUBREG, dl,
1014 VT, Undef, V0, SubReg0);
1015 return CurDAG->getMachineNode(TargetInstrInfo::INSERT_SUBREG, dl,
1016 VT, SDValue(Pair, 0), V1, SubReg1);
1017}
1018
Bob Wilsona7c397c2009-10-14 16:19:03 +00001019/// GetNEONSubregVT - Given a type for a 128-bit NEON vector, return the type
1020/// for a 64-bit subregister of the vector.
1021static EVT GetNEONSubregVT(EVT VT) {
1022 switch (VT.getSimpleVT().SimpleTy) {
1023 default: llvm_unreachable("unhandled NEON type");
1024 case MVT::v16i8: return MVT::v8i8;
1025 case MVT::v8i16: return MVT::v4i16;
1026 case MVT::v4f32: return MVT::v2f32;
1027 case MVT::v4i32: return MVT::v2i32;
1028 case MVT::v2i64: return MVT::v1i64;
1029 }
1030}
1031
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001032SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001033 unsigned *DOpcodes, unsigned *QOpcodes0,
1034 unsigned *QOpcodes1) {
1035 assert(NumVecs >=2 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001036 DebugLoc dl = N->getDebugLoc();
1037
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001038 SDValue MemAddr, MemUpdate, MemOpc, Align;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001039 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, MemUpdate, MemOpc, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001040 return NULL;
1041
1042 SDValue Chain = N->getOperand(0);
1043 EVT VT = N->getValueType(0);
1044 bool is64BitVector = VT.is64BitVector();
1045
1046 unsigned OpcodeIndex;
1047 switch (VT.getSimpleVT().SimpleTy) {
1048 default: llvm_unreachable("unhandled vld type");
1049 // Double-register operations:
1050 case MVT::v8i8: OpcodeIndex = 0; break;
1051 case MVT::v4i16: OpcodeIndex = 1; break;
1052 case MVT::v2f32:
1053 case MVT::v2i32: OpcodeIndex = 2; break;
1054 case MVT::v1i64: OpcodeIndex = 3; break;
1055 // Quad-register operations:
1056 case MVT::v16i8: OpcodeIndex = 0; break;
1057 case MVT::v8i16: OpcodeIndex = 1; break;
1058 case MVT::v4f32:
1059 case MVT::v4i32: OpcodeIndex = 2; break;
1060 }
1061
Evan Chengac0869d2009-11-21 06:21:52 +00001062 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
1063 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Bob Wilson3e36f132009-10-14 17:28:52 +00001064 if (is64BitVector) {
1065 unsigned Opc = DOpcodes[OpcodeIndex];
Evan Chengac0869d2009-11-21 06:21:52 +00001066 const SDValue Ops[] = { MemAddr, MemUpdate, MemOpc, Align,
1067 Pred, PredReg, Chain };
Bob Wilson3e36f132009-10-14 17:28:52 +00001068 std::vector<EVT> ResTys(NumVecs, VT);
1069 ResTys.push_back(MVT::Other);
Evan Chengac0869d2009-11-21 06:21:52 +00001070 return CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 7);
Bob Wilson3e36f132009-10-14 17:28:52 +00001071 }
1072
1073 EVT RegVT = GetNEONSubregVT(VT);
1074 if (NumVecs == 2) {
1075 // Quad registers are directly supported for VLD2,
1076 // loading 2 pairs of D regs.
1077 unsigned Opc = QOpcodes0[OpcodeIndex];
Evan Chengac0869d2009-11-21 06:21:52 +00001078 const SDValue Ops[] = { MemAddr, MemUpdate, MemOpc, Align,
1079 Pred, PredReg, Chain };
Bob Wilson3e36f132009-10-14 17:28:52 +00001080 std::vector<EVT> ResTys(4, VT);
1081 ResTys.push_back(MVT::Other);
Evan Chengac0869d2009-11-21 06:21:52 +00001082 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 7);
Bob Wilson3e36f132009-10-14 17:28:52 +00001083 Chain = SDValue(VLd, 4);
1084
1085 // Combine the even and odd subregs to produce the result.
1086 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1087 SDNode *Q = PairDRegs(VT, SDValue(VLd, 2*Vec), SDValue(VLd, 2*Vec+1));
1088 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1089 }
1090 } else {
1091 // Otherwise, quad registers are loaded with two separate instructions,
1092 // where one loads the even registers and the other loads the odd registers.
1093
1094 // Enable writeback to the address register.
1095 MemOpc = CurDAG->getTargetConstant(ARM_AM::getAM6Opc(true), MVT::i32);
1096
1097 std::vector<EVT> ResTys(NumVecs, RegVT);
1098 ResTys.push_back(MemAddr.getValueType());
1099 ResTys.push_back(MVT::Other);
1100
Bob Wilson24f995d2009-10-14 18:32:29 +00001101 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001102 unsigned Opc = QOpcodes0[OpcodeIndex];
Evan Chengac0869d2009-11-21 06:21:52 +00001103 const SDValue OpsA[] = { MemAddr, MemUpdate, MemOpc, Align,
1104 Pred, PredReg, Chain };
1105 SDNode *VLdA = CurDAG->getMachineNode(Opc, dl, ResTys, OpsA, 7);
Bob Wilson3e36f132009-10-14 17:28:52 +00001106 Chain = SDValue(VLdA, NumVecs+1);
1107
Bob Wilson24f995d2009-10-14 18:32:29 +00001108 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001109 Opc = QOpcodes1[OpcodeIndex];
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001110 const SDValue OpsB[] = { SDValue(VLdA, NumVecs), MemUpdate, MemOpc,
Evan Chengac0869d2009-11-21 06:21:52 +00001111 Align, Pred, PredReg, Chain };
1112 SDNode *VLdB = CurDAG->getMachineNode(Opc, dl, ResTys, OpsB, 7);
Bob Wilson3e36f132009-10-14 17:28:52 +00001113 Chain = SDValue(VLdB, NumVecs+1);
1114
1115 // Combine the even and odd subregs to produce the result.
1116 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1117 SDNode *Q = PairDRegs(VT, SDValue(VLdA, Vec), SDValue(VLdB, Vec));
1118 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1119 }
1120 }
1121 ReplaceUses(SDValue(N, NumVecs), Chain);
1122 return NULL;
1123}
1124
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001125SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001126 unsigned *DOpcodes, unsigned *QOpcodes0,
1127 unsigned *QOpcodes1) {
1128 assert(NumVecs >=2 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001129 DebugLoc dl = N->getDebugLoc();
1130
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001131 SDValue MemAddr, MemUpdate, MemOpc, Align;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001132 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, MemUpdate, MemOpc, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001133 return NULL;
1134
1135 SDValue Chain = N->getOperand(0);
1136 EVT VT = N->getOperand(3).getValueType();
1137 bool is64BitVector = VT.is64BitVector();
1138
1139 unsigned OpcodeIndex;
1140 switch (VT.getSimpleVT().SimpleTy) {
1141 default: llvm_unreachable("unhandled vst type");
1142 // Double-register operations:
1143 case MVT::v8i8: OpcodeIndex = 0; break;
1144 case MVT::v4i16: OpcodeIndex = 1; break;
1145 case MVT::v2f32:
1146 case MVT::v2i32: OpcodeIndex = 2; break;
1147 case MVT::v1i64: OpcodeIndex = 3; break;
1148 // Quad-register operations:
1149 case MVT::v16i8: OpcodeIndex = 0; break;
1150 case MVT::v8i16: OpcodeIndex = 1; break;
1151 case MVT::v4f32:
1152 case MVT::v4i32: OpcodeIndex = 2; break;
1153 }
1154
Evan Chengac0869d2009-11-21 06:21:52 +00001155 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
1156 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1157
Bob Wilson24f995d2009-10-14 18:32:29 +00001158 SmallVector<SDValue, 8> Ops;
1159 Ops.push_back(MemAddr);
1160 Ops.push_back(MemUpdate);
1161 Ops.push_back(MemOpc);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001162 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001163
1164 if (is64BitVector) {
1165 unsigned Opc = DOpcodes[OpcodeIndex];
1166 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1167 Ops.push_back(N->getOperand(Vec+3));
Evan Chengac0869d2009-11-21 06:21:52 +00001168 Ops.push_back(Pred);
1169 Ops.push_back(PredReg);
Bob Wilson24f995d2009-10-14 18:32:29 +00001170 Ops.push_back(Chain);
Evan Chengac0869d2009-11-21 06:21:52 +00001171 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+7);
Bob Wilson24f995d2009-10-14 18:32:29 +00001172 }
1173
1174 EVT RegVT = GetNEONSubregVT(VT);
1175 if (NumVecs == 2) {
1176 // Quad registers are directly supported for VST2,
1177 // storing 2 pairs of D regs.
1178 unsigned Opc = QOpcodes0[OpcodeIndex];
1179 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1180 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1181 N->getOperand(Vec+3)));
1182 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
1183 N->getOperand(Vec+3)));
1184 }
Evan Chengac0869d2009-11-21 06:21:52 +00001185 Ops.push_back(Pred);
1186 Ops.push_back(PredReg);
Bob Wilson24f995d2009-10-14 18:32:29 +00001187 Ops.push_back(Chain);
Evan Chengac0869d2009-11-21 06:21:52 +00001188 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 11);
Bob Wilson24f995d2009-10-14 18:32:29 +00001189 }
1190
1191 // Otherwise, quad registers are stored with two separate instructions,
1192 // where one stores the even registers and the other stores the odd registers.
1193
1194 // Enable writeback to the address register.
1195 MemOpc = CurDAG->getTargetConstant(ARM_AM::getAM6Opc(true), MVT::i32);
1196
1197 // Store the even subregs.
1198 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1199 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1200 N->getOperand(Vec+3)));
Evan Chengac0869d2009-11-21 06:21:52 +00001201 Ops.push_back(Pred);
1202 Ops.push_back(PredReg);
Bob Wilson24f995d2009-10-14 18:32:29 +00001203 Ops.push_back(Chain);
1204 unsigned Opc = QOpcodes0[OpcodeIndex];
1205 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Evan Chengac0869d2009-11-21 06:21:52 +00001206 MVT::Other, Ops.data(), NumVecs+7);
Bob Wilson24f995d2009-10-14 18:32:29 +00001207 Chain = SDValue(VStA, 1);
1208
1209 // Store the odd subregs.
1210 Ops[0] = SDValue(VStA, 0); // MemAddr
1211 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001212 Ops[Vec+4] = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
Bob Wilson24f995d2009-10-14 18:32:29 +00001213 N->getOperand(Vec+3));
Evan Chengac0869d2009-11-21 06:21:52 +00001214 Ops[NumVecs+4] = Pred;
1215 Ops[NumVecs+5] = PredReg;
1216 Ops[NumVecs+6] = Chain;
Bob Wilson24f995d2009-10-14 18:32:29 +00001217 Opc = QOpcodes1[OpcodeIndex];
1218 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Evan Chengac0869d2009-11-21 06:21:52 +00001219 MVT::Other, Ops.data(), NumVecs+7);
Bob Wilson24f995d2009-10-14 18:32:29 +00001220 Chain = SDValue(VStB, 1);
1221 ReplaceUses(SDValue(N, 0), Chain);
1222 return NULL;
1223}
1224
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001225SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001226 unsigned NumVecs, unsigned *DOpcodes,
1227 unsigned *QOpcodes0,
1228 unsigned *QOpcodes1) {
1229 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001230 DebugLoc dl = N->getDebugLoc();
1231
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001232 SDValue MemAddr, MemUpdate, MemOpc, Align;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001233 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, MemUpdate, MemOpc, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001234 return NULL;
1235
1236 SDValue Chain = N->getOperand(0);
1237 unsigned Lane =
1238 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001239 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001240 bool is64BitVector = VT.is64BitVector();
1241
Bob Wilson96493442009-10-14 16:46:45 +00001242 // Quad registers are handled by load/store of subregs. Find the subreg info.
Bob Wilsona7c397c2009-10-14 16:19:03 +00001243 unsigned NumElts = 0;
1244 int SubregIdx = 0;
1245 EVT RegVT = VT;
1246 if (!is64BitVector) {
1247 RegVT = GetNEONSubregVT(VT);
1248 NumElts = RegVT.getVectorNumElements();
1249 SubregIdx = (Lane < NumElts) ? ARM::DSUBREG_0 : ARM::DSUBREG_1;
1250 }
1251
1252 unsigned OpcodeIndex;
1253 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001254 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001255 // Double-register operations:
1256 case MVT::v8i8: OpcodeIndex = 0; break;
1257 case MVT::v4i16: OpcodeIndex = 1; break;
1258 case MVT::v2f32:
1259 case MVT::v2i32: OpcodeIndex = 2; break;
1260 // Quad-register operations:
1261 case MVT::v8i16: OpcodeIndex = 0; break;
1262 case MVT::v4f32:
1263 case MVT::v4i32: OpcodeIndex = 1; break;
1264 }
1265
Evan Chengac0869d2009-11-21 06:21:52 +00001266 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
1267 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1268
Bob Wilsona7c397c2009-10-14 16:19:03 +00001269 SmallVector<SDValue, 9> Ops;
1270 Ops.push_back(MemAddr);
1271 Ops.push_back(MemUpdate);
1272 Ops.push_back(MemOpc);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001273 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001274
1275 unsigned Opc = 0;
1276 if (is64BitVector) {
1277 Opc = DOpcodes[OpcodeIndex];
1278 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1279 Ops.push_back(N->getOperand(Vec+3));
1280 } else {
1281 // Check if this is loading the even or odd subreg of a Q register.
1282 if (Lane < NumElts) {
1283 Opc = QOpcodes0[OpcodeIndex];
1284 } else {
1285 Lane -= NumElts;
1286 Opc = QOpcodes1[OpcodeIndex];
1287 }
1288 // Extract the subregs of the input vector.
1289 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1290 Ops.push_back(CurDAG->getTargetExtractSubreg(SubregIdx, dl, RegVT,
1291 N->getOperand(Vec+3)));
1292 }
1293 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001294 Ops.push_back(Pred);
1295 Ops.push_back(PredReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001296 Ops.push_back(Chain);
1297
Bob Wilson96493442009-10-14 16:46:45 +00001298 if (!IsLoad)
Evan Chengac0869d2009-11-21 06:21:52 +00001299 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+7);
Bob Wilson96493442009-10-14 16:46:45 +00001300
Bob Wilsona7c397c2009-10-14 16:19:03 +00001301 std::vector<EVT> ResTys(NumVecs, RegVT);
1302 ResTys.push_back(MVT::Other);
1303 SDNode *VLdLn =
Evan Chengac0869d2009-11-21 06:21:52 +00001304 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), NumVecs+7);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001305 // For a 64-bit vector load to D registers, nothing more needs to be done.
1306 if (is64BitVector)
1307 return VLdLn;
1308
1309 // For 128-bit vectors, take the 64-bit results of the load and insert them
1310 // as subregs into the result.
1311 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1312 SDValue QuadVec = CurDAG->getTargetInsertSubreg(SubregIdx, dl, VT,
1313 N->getOperand(Vec+3),
1314 SDValue(VLdLn, Vec));
1315 ReplaceUses(SDValue(N, Vec), QuadVec);
1316 }
1317
1318 Chain = SDValue(VLdLn, NumVecs);
1319 ReplaceUses(SDValue(N, NumVecs), Chain);
1320 return NULL;
1321}
1322
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001323SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001324 unsigned Opc) {
1325 if (!Subtarget->hasV6T2Ops())
1326 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001327
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001328 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001329 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001330 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1331 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001332 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001333 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1334 unsigned Width = 32 - Srl_imm;
1335 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001336 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001337 return NULL;
1338 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001339 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001340 CurDAG->getTargetConstant(LSB, MVT::i32),
1341 CurDAG->getTargetConstant(Width, MVT::i32),
1342 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001343 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001344 }
1345 }
1346 return NULL;
1347}
1348
Evan Cheng9ef48352009-11-20 00:54:03 +00001349SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001350SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001351 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1352 SDValue CPTmp0;
1353 SDValue CPTmp1;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001354 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001355 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1356 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1357 unsigned Opc = 0;
1358 switch (SOShOp) {
1359 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1360 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1361 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1362 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1363 default:
1364 llvm_unreachable("Unknown so_reg opcode!");
1365 break;
1366 }
1367 SDValue SOShImm =
1368 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1369 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1370 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001371 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001372 }
1373 return 0;
1374}
1375
1376SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001377SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001378 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1379 SDValue CPTmp0;
1380 SDValue CPTmp1;
1381 SDValue CPTmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001382 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001383 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1384 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001385 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001386 }
1387 return 0;
1388}
1389
1390SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001391SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001392 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1393 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1394 if (!T)
1395 return 0;
1396
1397 if (Predicate_t2_so_imm(TrueVal.getNode())) {
1398 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1399 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1400 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001401 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001402 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1403 }
1404 return 0;
1405}
1406
1407SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001408SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001409 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1410 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1411 if (!T)
1412 return 0;
1413
1414 if (Predicate_so_imm(TrueVal.getNode())) {
1415 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1416 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1417 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001418 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001419 ARM::MOVCCi, MVT::i32, Ops, 5);
1420 }
1421 return 0;
1422}
1423
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001424SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1425 EVT VT = N->getValueType(0);
1426 SDValue FalseVal = N->getOperand(0);
1427 SDValue TrueVal = N->getOperand(1);
1428 SDValue CC = N->getOperand(2);
1429 SDValue CCR = N->getOperand(3);
1430 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001431 assert(CC.getOpcode() == ISD::Constant);
1432 assert(CCR.getOpcode() == ISD::Register);
1433 ARMCC::CondCodes CCVal =
1434 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001435
1436 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1437 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1438 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1439 // Pattern complexity = 18 cost = 1 size = 0
1440 SDValue CPTmp0;
1441 SDValue CPTmp1;
1442 SDValue CPTmp2;
1443 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001444 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001445 CCVal, CCR, InFlag);
1446 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001447 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001448 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1449 if (Res)
1450 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001451 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001452 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001453 CCVal, CCR, InFlag);
1454 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001455 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001456 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1457 if (Res)
1458 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001459 }
1460
1461 // Pattern: (ARMcmov:i32 GPR:i32:$false,
1462 // (imm:i32)<<P:Predicate_so_imm>>:$true,
1463 // (imm:i32):$cc)
1464 // Emits: (MOVCCi:i32 GPR:i32:$false,
1465 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1466 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001467 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001468 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001469 CCVal, CCR, InFlag);
1470 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001471 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001472 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1473 if (Res)
1474 return Res;
1475 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001476 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001477 CCVal, CCR, InFlag);
1478 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001479 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001480 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1481 if (Res)
1482 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001483 }
1484 }
1485
1486 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1487 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1488 // Pattern complexity = 6 cost = 1 size = 0
1489 //
1490 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1491 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1492 // Pattern complexity = 6 cost = 11 size = 0
1493 //
1494 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001495 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1496 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001497 unsigned Opc = 0;
1498 switch (VT.getSimpleVT().SimpleTy) {
1499 default: assert(false && "Illegal conditional move type!");
1500 break;
1501 case MVT::i32:
1502 Opc = Subtarget->isThumb()
1503 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1504 : ARM::MOVCCr;
1505 break;
1506 case MVT::f32:
1507 Opc = ARM::VMOVScc;
1508 break;
1509 case MVT::f64:
1510 Opc = ARM::VMOVDcc;
1511 break;
1512 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001513 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001514}
1515
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001516SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001517 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001518
Dan Gohmane8be6c62008-07-17 19:10:17 +00001519 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001520 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001521
1522 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001523 default: break;
1524 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001525 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001526 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001527 if (Subtarget->hasThumb2())
1528 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1529 // be done with MOV + MOVT, at worst.
1530 UseCP = 0;
1531 else {
1532 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001533 UseCP = (Val > 255 && // MOV
1534 ~Val > 255 && // MOV + MVN
1535 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001536 } else
1537 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1538 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1539 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1540 }
1541
Evan Chenga8e29892007-01-19 07:51:42 +00001542 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001543 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001544 CurDAG->getTargetConstantPool(ConstantInt::get(
1545 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001546 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001547
1548 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001549 if (Subtarget->isThumb1Only()) {
Evan Chengac0869d2009-11-21 06:21:52 +00001550 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
Owen Anderson825b72b2009-08-11 20:47:22 +00001551 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001552 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001553 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1554 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001555 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001556 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001557 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001558 CurDAG->getRegister(0, MVT::i32),
1559 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001560 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001561 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001562 CurDAG->getEntryNode()
1563 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001564 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1565 Ops, 6);
Evan Cheng012f2d92007-01-24 08:53:17 +00001566 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001567 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001568 return NULL;
1569 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001570
Evan Chenga8e29892007-01-19 07:51:42 +00001571 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001572 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001573 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001574 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001575 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001576 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001577 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001578 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001579 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1580 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001581 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001582 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1583 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001584 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1585 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1586 CurDAG->getRegister(0, MVT::i32) };
1587 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001588 }
Evan Chenga8e29892007-01-19 07:51:42 +00001589 }
Evan Cheng86198642009-08-07 00:34:42 +00001590 case ARMISD::DYN_ALLOC:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001591 return SelectDYN_ALLOC(N);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001592 case ISD::SRL:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001593 if (SDNode *I = SelectV6T2BitfieldExtractOp(N,
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001594 Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX))
1595 return I;
1596 break;
1597 case ISD::SRA:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001598 if (SDNode *I = SelectV6T2BitfieldExtractOp(N,
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001599 Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX))
1600 return I;
1601 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001602 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001603 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001604 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001605 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001606 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001607 if (!RHSV) break;
1608 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001609 unsigned ShImm = Log2_32(RHSV-1);
1610 if (ShImm >= 32)
1611 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001612 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001613 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001614 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1615 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001616 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001617 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001618 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001619 } else {
1620 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001621 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001622 }
Evan Chenga8e29892007-01-19 07:51:42 +00001623 }
1624 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001625 unsigned ShImm = Log2_32(RHSV+1);
1626 if (ShImm >= 32)
1627 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001628 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001629 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001630 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1631 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001632 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001633 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001634 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 5);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001635 } else {
1636 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001637 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001638 }
Evan Chenga8e29892007-01-19 07:51:42 +00001639 }
1640 }
1641 break;
Evan Cheng20956592009-10-21 08:15:52 +00001642 case ISD::AND: {
1643 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1644 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1645 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1646 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1647 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001648 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001649 if (VT != MVT::i32)
1650 break;
1651 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1652 ? ARM::t2MOVTi16
1653 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1654 if (!Opc)
1655 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001656 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001657 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1658 if (!N1C)
1659 break;
1660 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1661 SDValue N2 = N0.getOperand(1);
1662 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1663 if (!N2C)
1664 break;
1665 unsigned N1CVal = N1C->getZExtValue();
1666 unsigned N2CVal = N2C->getZExtValue();
1667 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1668 (N1CVal & 0xffffU) == 0xffffU &&
1669 (N2CVal & 0xffffU) == 0x0U) {
1670 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1671 MVT::i32);
1672 SDValue Ops[] = { N0.getOperand(0), Imm16,
1673 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1674 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
1675 }
1676 }
1677 break;
1678 }
Jim Grosbache5165492009-11-09 00:11:35 +00001679 case ARMISD::VMOVRRD:
1680 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001681 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00001682 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00001683 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001684 if (Subtarget->isThumb1Only())
1685 break;
1686 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001687 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001688 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1689 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001690 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001691 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001692 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001693 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1694 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001695 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001696 }
Evan Chengee568cf2007-07-05 07:15:27 +00001697 }
Dan Gohman525178c2007-10-08 18:33:35 +00001698 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001699 if (Subtarget->isThumb1Only())
1700 break;
1701 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001702 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001703 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001704 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001705 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001706 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001707 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1708 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001709 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001710 }
Evan Chengee568cf2007-07-05 07:15:27 +00001711 }
Evan Chenga8e29892007-01-19 07:51:42 +00001712 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00001713 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001714 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001715 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001716 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001717 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001718 if (ResNode)
1719 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00001720 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001721 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001722 }
Evan Chengee568cf2007-07-05 07:15:27 +00001723 case ARMISD::BRCOND: {
1724 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1725 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1726 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001727
Evan Chengee568cf2007-07-05 07:15:27 +00001728 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1729 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
1730 // Pattern complexity = 6 cost = 1 size = 0
1731
David Goodwin5e47a9a2009-06-30 18:04:13 +00001732 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1733 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1734 // Pattern complexity = 6 cost = 1 size = 0
1735
Jim Grosbach764ab522009-08-11 15:33:49 +00001736 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00001737 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001738 SDValue Chain = N->getOperand(0);
1739 SDValue N1 = N->getOperand(1);
1740 SDValue N2 = N->getOperand(2);
1741 SDValue N3 = N->getOperand(3);
1742 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00001743 assert(N1.getOpcode() == ISD::BasicBlock);
1744 assert(N2.getOpcode() == ISD::Constant);
1745 assert(N3.getOpcode() == ISD::Register);
1746
Dan Gohman475871a2008-07-27 21:46:04 +00001747 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001748 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00001749 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00001750 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00001751 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
1752 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00001753 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001754 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00001755 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001756 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00001757 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001758 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00001759 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00001760 return NULL;
1761 }
Evan Cheng07ba9062009-11-19 21:45:22 +00001762 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001763 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00001764 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001765 EVT VT = N->getValueType(0);
1766 SDValue N0 = N->getOperand(0);
1767 SDValue N1 = N->getOperand(1);
1768 SDValue N2 = N->getOperand(2);
1769 SDValue N3 = N->getOperand(3);
1770 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00001771 assert(N2.getOpcode() == ISD::Constant);
1772 assert(N3.getOpcode() == ISD::Register);
1773
Dan Gohman475871a2008-07-27 21:46:04 +00001774 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001775 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00001776 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00001777 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00001778 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00001779 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00001780 default: assert(false && "Illegal conditional move type!");
1781 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001782 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00001783 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00001784 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001785 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00001786 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00001787 break;
Evan Chengee568cf2007-07-05 07:15:27 +00001788 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001789 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001790 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00001791
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001792 case ARMISD::VZIP: {
1793 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001794 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001795 switch (VT.getSimpleVT().SimpleTy) {
1796 default: return NULL;
1797 case MVT::v8i8: Opc = ARM::VZIPd8; break;
1798 case MVT::v4i16: Opc = ARM::VZIPd16; break;
1799 case MVT::v2f32:
1800 case MVT::v2i32: Opc = ARM::VZIPd32; break;
1801 case MVT::v16i8: Opc = ARM::VZIPq8; break;
1802 case MVT::v8i16: Opc = ARM::VZIPq16; break;
1803 case MVT::v4f32:
1804 case MVT::v4i32: Opc = ARM::VZIPq32; break;
1805 }
Evan Chengac0869d2009-11-21 06:21:52 +00001806 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
1807 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1808 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1809 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001810 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001811 case ARMISD::VUZP: {
1812 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001813 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001814 switch (VT.getSimpleVT().SimpleTy) {
1815 default: return NULL;
1816 case MVT::v8i8: Opc = ARM::VUZPd8; break;
1817 case MVT::v4i16: Opc = ARM::VUZPd16; break;
1818 case MVT::v2f32:
1819 case MVT::v2i32: Opc = ARM::VUZPd32; break;
1820 case MVT::v16i8: Opc = ARM::VUZPq8; break;
1821 case MVT::v8i16: Opc = ARM::VUZPq16; break;
1822 case MVT::v4f32:
1823 case MVT::v4i32: Opc = ARM::VUZPq32; break;
1824 }
Evan Chengac0869d2009-11-21 06:21:52 +00001825 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
1826 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1827 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1828 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001829 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001830 case ARMISD::VTRN: {
1831 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001832 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001833 switch (VT.getSimpleVT().SimpleTy) {
1834 default: return NULL;
1835 case MVT::v8i8: Opc = ARM::VTRNd8; break;
1836 case MVT::v4i16: Opc = ARM::VTRNd16; break;
1837 case MVT::v2f32:
1838 case MVT::v2i32: Opc = ARM::VTRNd32; break;
1839 case MVT::v16i8: Opc = ARM::VTRNq8; break;
1840 case MVT::v8i16: Opc = ARM::VTRNq16; break;
1841 case MVT::v4f32:
1842 case MVT::v4i32: Opc = ARM::VTRNq32; break;
1843 }
Evan Chengac0869d2009-11-21 06:21:52 +00001844 SDValue Pred = CurDAG->getTargetConstant(14, MVT::i32);
1845 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1846 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1847 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001848 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00001849
1850 case ISD::INTRINSIC_VOID:
1851 case ISD::INTRINSIC_W_CHAIN: {
1852 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00001853 switch (IntNo) {
1854 default:
1855 break;
1856
1857 case Intrinsic::arm_neon_vld2: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001858 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
1859 ARM::VLD2d32, ARM::VLD2d64 };
1860 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001861 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001862 }
1863
1864 case Intrinsic::arm_neon_vld3: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001865 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
1866 ARM::VLD3d32, ARM::VLD3d64 };
1867 unsigned QOpcodes0[] = { ARM::VLD3q8a, ARM::VLD3q16a, ARM::VLD3q32a };
1868 unsigned QOpcodes1[] = { ARM::VLD3q8b, ARM::VLD3q16b, ARM::VLD3q32b };
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,
1874 ARM::VLD4d32, ARM::VLD4d64 };
1875 unsigned QOpcodes0[] = { ARM::VLD4q8a, ARM::VLD4q16a, ARM::VLD4q32a };
1876 unsigned QOpcodes1[] = { ARM::VLD4q8b, ARM::VLD4q16b, ARM::VLD4q32b };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001877 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001878 }
1879
Bob Wilson243fcc52009-09-01 04:26:28 +00001880 case Intrinsic::arm_neon_vld2lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00001881 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
1882 unsigned QOpcodes0[] = { ARM::VLD2LNq16a, ARM::VLD2LNq32a };
1883 unsigned QOpcodes1[] = { ARM::VLD2LNq16b, ARM::VLD2LNq32b };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001884 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00001885 }
1886
1887 case Intrinsic::arm_neon_vld3lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00001888 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
1889 unsigned QOpcodes0[] = { ARM::VLD3LNq16a, ARM::VLD3LNq32a };
1890 unsigned QOpcodes1[] = { ARM::VLD3LNq16b, ARM::VLD3LNq32b };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001891 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00001892 }
1893
1894 case Intrinsic::arm_neon_vld4lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00001895 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
1896 unsigned QOpcodes0[] = { ARM::VLD4LNq16a, ARM::VLD4LNq32a };
1897 unsigned QOpcodes1[] = { ARM::VLD4LNq16b, ARM::VLD4LNq32b };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001898 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00001899 }
1900
Bob Wilson31fb12f2009-08-26 17:39:53 +00001901 case Intrinsic::arm_neon_vst2: {
Bob Wilson24f995d2009-10-14 18:32:29 +00001902 unsigned DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
1903 ARM::VST2d32, ARM::VST2d64 };
1904 unsigned QOpcodes[] = { ARM::VST2q8, ARM::VST2q16, ARM::VST2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001905 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001906 }
1907
1908 case Intrinsic::arm_neon_vst3: {
Bob Wilson24f995d2009-10-14 18:32:29 +00001909 unsigned DOpcodes[] = { ARM::VST3d8, ARM::VST3d16,
1910 ARM::VST3d32, ARM::VST3d64 };
1911 unsigned QOpcodes0[] = { ARM::VST3q8a, ARM::VST3q16a, ARM::VST3q32a };
1912 unsigned QOpcodes1[] = { ARM::VST3q8b, ARM::VST3q16b, ARM::VST3q32b };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001913 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001914 }
1915
1916 case Intrinsic::arm_neon_vst4: {
Bob Wilson24f995d2009-10-14 18:32:29 +00001917 unsigned DOpcodes[] = { ARM::VST4d8, ARM::VST4d16,
1918 ARM::VST4d32, ARM::VST4d64 };
1919 unsigned QOpcodes0[] = { ARM::VST4q8a, ARM::VST4q16a, ARM::VST4q32a };
1920 unsigned QOpcodes1[] = { ARM::VST4q8b, ARM::VST4q16b, ARM::VST4q32b };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001921 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001922 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00001923
1924 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson96493442009-10-14 16:46:45 +00001925 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
1926 unsigned QOpcodes0[] = { ARM::VST2LNq16a, ARM::VST2LNq32a };
1927 unsigned QOpcodes1[] = { ARM::VST2LNq16b, ARM::VST2LNq32b };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001928 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00001929 }
1930
1931 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson96493442009-10-14 16:46:45 +00001932 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
1933 unsigned QOpcodes0[] = { ARM::VST3LNq16a, ARM::VST3LNq32a };
1934 unsigned QOpcodes1[] = { ARM::VST3LNq16b, ARM::VST3LNq32b };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001935 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00001936 }
1937
1938 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson96493442009-10-14 16:46:45 +00001939 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
1940 unsigned QOpcodes0[] = { ARM::VST4LNq16a, ARM::VST4LNq32a };
1941 unsigned QOpcodes1[] = { ARM::VST4LNq16b, ARM::VST4LNq32b };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001942 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00001943 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00001944 }
1945 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00001946 }
1947
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001948 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00001949}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001950
Bob Wilson224c2442009-05-19 05:53:42 +00001951bool ARMDAGToDAGISel::
1952SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
1953 std::vector<SDValue> &OutOps) {
1954 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00001955 // Require the address to be in a register. That is safe for all ARM
1956 // variants and it is hard to do anything much smarter without knowing
1957 // how the operand is used.
1958 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00001959 return false;
1960}
1961
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001962/// createARMISelDag - This pass converts a legalized DAG into a
1963/// ARM-specific DAG, ready for instruction scheduling.
1964///
Bob Wilson522ce972009-09-28 14:30:20 +00001965FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
1966 CodeGenOpt::Level OptLevel) {
1967 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001968}