blob: 92df37fea6b200dcdc56a62865adcb3698cb44bc [file] [log] [blame]
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001//===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the ARM target.
11//
12//===----------------------------------------------------------------------===//
13
Dale Johannesen51e28e62010-06-03 21:09:53 +000014#define DEBUG_TYPE "arm-isel"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000015#include "ARM.h"
Evan Cheng48575f62010-12-05 22:04:16 +000016#include "ARMBaseInstrInfo.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000017#include "ARMTargetMachine.h"
Evan Chengee04a6d2011-07-20 23:34:39 +000018#include "MCTargetDesc/ARMAddressingModes.h"
Rafael Espindola84b19be2006-07-16 01:02:57 +000019#include "llvm/CallingConv.h"
Evan Chenga8e29892007-01-19 07:51:42 +000020#include "llvm/Constants.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000021#include "llvm/DerivedTypes.h"
22#include "llvm/Function.h"
23#include "llvm/Intrinsics.h"
Owen Anderson9adc0ab2009-07-14 23:09:55 +000024#include "llvm/LLVMContext.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000025#include "llvm/CodeGen/MachineFrameInfo.h"
26#include "llvm/CodeGen/MachineFunction.h"
27#include "llvm/CodeGen/MachineInstrBuilder.h"
28#include "llvm/CodeGen/SelectionDAG.h"
29#include "llvm/CodeGen/SelectionDAGISel.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000030#include "llvm/Target/TargetLowering.h"
Chris Lattner72939122007-05-03 00:32:00 +000031#include "llvm/Target/TargetOptions.h"
Evan Cheng94cc6d32010-05-04 20:39:49 +000032#include "llvm/Support/CommandLine.h"
Chris Lattner3d62d782008-02-03 05:43:57 +000033#include "llvm/Support/Compiler.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000034#include "llvm/Support/Debug.h"
Torok Edwindac237e2009-07-08 20:53:28 +000035#include "llvm/Support/ErrorHandling.h"
36#include "llvm/Support/raw_ostream.h"
37
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000038using namespace llvm;
39
Evan Chenga2c519b2010-07-30 23:33:54 +000040static cl::opt<bool>
41DisableShifterOp("disable-shifter-op", cl::Hidden,
42 cl::desc("Disable isel of shifter-op"),
43 cl::init(false));
44
Evan Cheng48575f62010-12-05 22:04:16 +000045static cl::opt<bool>
46CheckVMLxHazard("check-vmlx-hazard", cl::Hidden,
47 cl::desc("Check fp vmla / vmls hazard at isel time"),
Bob Wilson84c5eed2011-04-19 18:11:57 +000048 cl::init(true));
Evan Cheng48575f62010-12-05 22:04:16 +000049
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000050//===--------------------------------------------------------------------===//
51/// ARMDAGToDAGISel - ARM specific code to select ARM machine
52/// instructions for SelectionDAG operations.
53///
54namespace {
Jim Grosbach82891622010-09-29 19:03:54 +000055
56enum AddrMode2Type {
57 AM2_BASE, // Simple AM2 (+-imm12)
58 AM2_SHOP // Shifter-op AM2
59};
60
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000061class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000062 ARMBaseTargetMachine &TM;
Evan Cheng48575f62010-12-05 22:04:16 +000063 const ARMBaseInstrInfo *TII;
Evan Cheng3f7eb8e2008-09-18 07:24:33 +000064
Evan Chenga8e29892007-01-19 07:51:42 +000065 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
66 /// make the right decision when generating code for different targets.
67 const ARMSubtarget *Subtarget;
68
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000069public:
Bob Wilson522ce972009-09-28 14:30:20 +000070 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
71 CodeGenOpt::Level OptLevel)
72 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Cheng48575f62010-12-05 22:04:16 +000073 TII(static_cast<const ARMBaseInstrInfo*>(TM.getInstrInfo())),
74 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000075 }
76
Evan Chenga8e29892007-01-19 07:51:42 +000077 virtual const char *getPassName() const {
78 return "ARM Instruction Selection";
Anton Korobeynikov52237112009-06-17 18:13:58 +000079 }
80
Bob Wilsonaf4a8912009-10-08 18:51:31 +000081 /// getI32Imm - Return a target constant of type i32 with the specified
82 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000083 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000084 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000085 }
86
Dan Gohmaneeb3a002010-01-05 01:24:18 +000087 SDNode *Select(SDNode *N);
Evan Cheng014bf212010-02-15 19:41:07 +000088
Evan Cheng48575f62010-12-05 22:04:16 +000089
90 bool hasNoVMLxHazardUse(SDNode *N) const;
Evan Chengf40deed2010-10-27 23:41:30 +000091 bool isShifterOpProfitable(const SDValue &Shift,
92 ARM_AM::ShiftOpc ShOpcVal, unsigned ShAmt);
Chris Lattner52a261b2010-09-21 20:31:19 +000093 bool SelectShifterOperandReg(SDValue N, SDValue &A,
Owen Anderson099e5552011-03-18 19:46:58 +000094 SDValue &B, SDValue &C,
95 bool CheckProfitability = true);
Evan Chengf40deed2010-10-27 23:41:30 +000096 bool SelectShiftShifterOperandReg(SDValue N, SDValue &A,
Owen Anderson099e5552011-03-18 19:46:58 +000097 SDValue &B, SDValue &C) {
98 // Don't apply the profitability check
99 return SelectShifterOperandReg(N, A, B, C, false);
100 }
101
Jim Grosbach3e556122010-10-26 22:37:02 +0000102 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
103 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
104
Jim Grosbach82891622010-09-29 19:03:54 +0000105 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
106 SDValue &Offset, SDValue &Opc);
107 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
108 SDValue &Opc) {
109 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
110 }
111
112 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
113 SDValue &Opc) {
114 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
115 }
116
117 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
118 SDValue &Opc) {
119 SelectAddrMode2Worker(N, Base, Offset, Opc);
Jim Grosbach3e556122010-10-26 22:37:02 +0000120// return SelectAddrMode2ShOp(N, Base, Offset, Opc);
Jim Grosbach82891622010-09-29 19:03:54 +0000121 // This always matches one way or another.
122 return true;
123 }
124
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000125 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000126 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000127 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000128 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000129 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000130 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000131 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000132 SDValue &Offset);
Bob Wilson665814b2010-11-01 23:40:51 +0000133 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
Bob Wilsonda525062011-02-25 06:42:42 +0000134 bool SelectAddrMode6Offset(SDNode *Op, SDValue N, SDValue &Offset);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000135
Evan Cheng5de5d4b2011-01-17 08:03:18 +0000136 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +0000137
Bill Wendlingf4caf692010-12-14 03:36:38 +0000138 // Thumb Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000139 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000140 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
141 unsigned Scale);
142 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
143 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
144 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
145 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
146 SDValue &OffImm);
147 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
148 SDValue &OffImm);
149 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
150 SDValue &OffImm);
151 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
152 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000153 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000154
Bill Wendlingf4caf692010-12-14 03:36:38 +0000155 // Thumb 2 Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000156 bool SelectT2ShifterOperandReg(SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000157 SDValue &BaseReg, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000158 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
159 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000160 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000161 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000162 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000163 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000164 SDValue &OffReg, SDValue &ShImm);
165
Evan Cheng875a6ac2010-11-12 22:42:47 +0000166 inline bool is_so_imm(unsigned Imm) const {
167 return ARM_AM::getSOImmVal(Imm) != -1;
168 }
169
170 inline bool is_so_imm_not(unsigned Imm) const {
171 return ARM_AM::getSOImmVal(~Imm) != -1;
172 }
173
174 inline bool is_t2_so_imm(unsigned Imm) const {
175 return ARM_AM::getT2SOImmVal(Imm) != -1;
176 }
177
178 inline bool is_t2_so_imm_not(unsigned Imm) const {
179 return ARM_AM::getT2SOImmVal(~Imm) != -1;
180 }
181
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000182 // Include the pieces autogenerated from the target description.
183#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000184
185private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000186 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
187 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000188 SDNode *SelectARMIndexedLoad(SDNode *N);
189 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000190
Bob Wilson621f1952010-03-23 05:25:43 +0000191 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
192 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000193 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000194 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000195 SDNode *SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
196 unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000197 unsigned *QOpcodes0, unsigned *QOpcodes1);
198
Bob Wilson24f995d2009-10-14 18:32:29 +0000199 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000200 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000201 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000202 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000203 SDNode *SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
204 unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000205 unsigned *QOpcodes0, unsigned *QOpcodes1);
206
Bob Wilson96493442009-10-14 16:46:45 +0000207 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000208 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson8466fa12010-09-13 23:01:35 +0000209 /// load/store of D registers and Q registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000210 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad,
211 bool isUpdating, unsigned NumVecs,
Bob Wilson8466fa12010-09-13 23:01:35 +0000212 unsigned *DOpcodes, unsigned *QOpcodes);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000213
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000214 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
215 /// should be 2, 3 or 4. The opcode array specifies the instructions used
216 /// for loading D registers. (Q registers are not supported.)
Bob Wilson1c3ef902011-02-07 17:43:21 +0000217 SDNode *SelectVLDDup(SDNode *N, bool isUpdating, unsigned NumVecs,
218 unsigned *Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000219
Bob Wilson78dfbc32010-07-07 00:08:54 +0000220 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
221 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
222 /// generated to force the table registers to be consecutive.
223 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000224
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000225 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000226 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000227
Evan Cheng07ba9062009-11-19 21:45:22 +0000228 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000229 SDNode *SelectCMOVOp(SDNode *N);
230 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000231 ARMCC::CondCodes CCVal, SDValue CCR,
232 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000233 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000234 ARMCC::CondCodes CCVal, SDValue CCR,
235 SDValue InFlag);
Jim Grosbacha4257162010-10-07 00:53:56 +0000236 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000237 ARMCC::CondCodes CCVal, SDValue CCR,
238 SDValue InFlag);
Jim Grosbach3bbdcea2010-10-07 00:42:42 +0000239 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000240 ARMCC::CondCodes CCVal, SDValue CCR,
241 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000242
Evan Chengde8aa4e2010-05-05 18:28:36 +0000243 SDNode *SelectConcatVector(SDNode *N);
244
Evan Chengaf4550f2009-07-02 01:23:32 +0000245 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
246 /// inline asm expressions.
247 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
248 char ConstraintCode,
249 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000250
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000251 // Form pairs of consecutive S, D, or Q registers.
252 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000253 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000254 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
255
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000256 // Form sequences of 4 consecutive S, D, or Q registers.
257 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000258 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000259 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilson665814b2010-11-01 23:40:51 +0000260
261 // Get the alignment operand for a NEON VLD or VST instruction.
262 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000263};
Evan Chenga8e29892007-01-19 07:51:42 +0000264}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000265
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000266/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
267/// operand. If so Imm will receive the 32-bit value.
268static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
269 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
270 Imm = cast<ConstantSDNode>(N)->getZExtValue();
271 return true;
272 }
273 return false;
274}
275
276// isInt32Immediate - This method tests to see if a constant operand.
277// If so Imm will receive the 32 bit value.
278static bool isInt32Immediate(SDValue N, unsigned &Imm) {
279 return isInt32Immediate(N.getNode(), Imm);
280}
281
282// isOpcWithIntImmediate - This method tests to see if the node is a specific
283// opcode and that it has a immediate integer right operand.
284// If so Imm will receive the 32 bit value.
285static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
286 return N->getOpcode() == Opc &&
287 isInt32Immediate(N->getOperand(1).getNode(), Imm);
288}
289
Daniel Dunbarec91d522011-01-19 15:12:16 +0000290/// \brief Check whether a particular node is a constant value representable as
291/// (N * Scale) where (N in [\arg RangeMin, \arg RangeMax).
292///
293/// \param ScaledConstant [out] - On success, the pre-scaled constant value.
294static bool isScaledConstantInRange(SDValue Node, unsigned Scale,
295 int RangeMin, int RangeMax,
296 int &ScaledConstant) {
297 assert(Scale && "Invalid scale!");
298
299 // Check that this is a constant.
300 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Node);
301 if (!C)
302 return false;
303
304 ScaledConstant = (int) C->getZExtValue();
305 if ((ScaledConstant % Scale) != 0)
306 return false;
307
308 ScaledConstant /= Scale;
309 return ScaledConstant >= RangeMin && ScaledConstant < RangeMax;
310}
311
Evan Cheng48575f62010-12-05 22:04:16 +0000312/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
313/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
314/// least on current ARM implementations) which should be avoidded.
315bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
316 if (OptLevel == CodeGenOpt::None)
317 return true;
318
319 if (!CheckVMLxHazard)
320 return true;
321
322 if (!Subtarget->isCortexA8() && !Subtarget->isCortexA9())
323 return true;
324
325 if (!N->hasOneUse())
326 return false;
327
328 SDNode *Use = *N->use_begin();
329 if (Use->getOpcode() == ISD::CopyToReg)
330 return true;
331 if (Use->isMachineOpcode()) {
Evan Chenge837dea2011-06-28 19:10:37 +0000332 const MCInstrDesc &MCID = TII->get(Use->getMachineOpcode());
333 if (MCID.mayStore())
Evan Cheng48575f62010-12-05 22:04:16 +0000334 return true;
Evan Chenge837dea2011-06-28 19:10:37 +0000335 unsigned Opcode = MCID.getOpcode();
Evan Cheng48575f62010-12-05 22:04:16 +0000336 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
337 return true;
338 // vmlx feeding into another vmlx. We actually want to unfold
339 // the use later in the MLxExpansion pass. e.g.
340 // vmla
341 // vmla (stall 8 cycles)
342 //
343 // vmul (5 cycles)
344 // vadd (5 cycles)
345 // vmla
346 // This adds up to about 18 - 19 cycles.
347 //
348 // vmla
349 // vmul (stall 4 cycles)
350 // vadd adds up to about 14 cycles.
351 return TII->isFpMLxInstruction(Opcode);
352 }
353
354 return false;
355}
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000356
Evan Chengf40deed2010-10-27 23:41:30 +0000357bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
358 ARM_AM::ShiftOpc ShOpcVal,
359 unsigned ShAmt) {
360 if (!Subtarget->isCortexA9())
361 return true;
362 if (Shift.hasOneUse())
363 return true;
364 // R << 2 is free.
365 return ShOpcVal == ARM_AM::lsl && ShAmt == 2;
366}
367
Chris Lattner52a261b2010-09-21 20:31:19 +0000368bool ARMDAGToDAGISel::SelectShifterOperandReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000369 SDValue &BaseReg,
370 SDValue &ShReg,
Owen Anderson099e5552011-03-18 19:46:58 +0000371 SDValue &Opc,
372 bool CheckProfitability) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000373 if (DisableShifterOp)
374 return false;
375
Evan Chengee04a6d2011-07-20 23:34:39 +0000376 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +0000377
378 // Don't match base register only case. That is matched to a separate
379 // lower complexity pattern with explicit register operand.
380 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000381
Evan Cheng055b0312009-06-29 07:51:04 +0000382 BaseReg = N.getOperand(0);
383 unsigned ShImmVal = 0;
384 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000385 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000386 ShImmVal = RHS->getZExtValue() & 31;
387 } else {
388 ShReg = N.getOperand(1);
Owen Anderson099e5552011-03-18 19:46:58 +0000389 if (CheckProfitability && !isShifterOpProfitable(N, ShOpcVal, ShImmVal))
Evan Chengf40deed2010-10-27 23:41:30 +0000390 return false;
391 }
392 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
393 MVT::i32);
394 return true;
395}
396
Jim Grosbach3e556122010-10-26 22:37:02 +0000397bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
398 SDValue &Base,
399 SDValue &OffImm) {
400 // Match simple R + imm12 operands.
401
402 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000403 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
404 !CurDAG->isBaseWithConstantOffset(N)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000405 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000406 // Match frame index.
Jim Grosbach3e556122010-10-26 22:37:02 +0000407 int FI = cast<FrameIndexSDNode>(N)->getIndex();
408 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
409 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
410 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000411 }
Owen Anderson099e5552011-03-18 19:46:58 +0000412
Chris Lattner0a9481f2011-02-13 22:25:43 +0000413 if (N.getOpcode() == ARMISD::Wrapper &&
414 !(Subtarget->useMovt() &&
415 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000416 Base = N.getOperand(0);
417 } else
418 Base = N;
419 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
420 return true;
421 }
422
423 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
424 int RHSC = (int)RHS->getZExtValue();
425 if (N.getOpcode() == ISD::SUB)
426 RHSC = -RHSC;
427
428 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
429 Base = N.getOperand(0);
430 if (Base.getOpcode() == ISD::FrameIndex) {
431 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
432 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
433 }
434 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
435 return true;
436 }
437 }
438
439 // Base only.
440 Base = N;
441 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
442 return true;
443}
444
445
446
447bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
448 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000449 if (N.getOpcode() == ISD::MUL &&
450 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000451 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
452 // X * [3,5,9] -> X + X * [2,4,8] etc.
453 int RHSC = (int)RHS->getZExtValue();
454 if (RHSC & 1) {
455 RHSC = RHSC & ~1;
456 ARM_AM::AddrOpc AddSub = ARM_AM::add;
457 if (RHSC < 0) {
458 AddSub = ARM_AM::sub;
459 RHSC = - RHSC;
460 }
461 if (isPowerOf2_32(RHSC)) {
462 unsigned ShAmt = Log2_32(RHSC);
463 Base = Offset = N.getOperand(0);
464 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
465 ARM_AM::lsl),
466 MVT::i32);
467 return true;
468 }
469 }
470 }
471 }
472
Chris Lattner0a9481f2011-02-13 22:25:43 +0000473 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
474 // ISD::OR that is equivalent to an ISD::ADD.
475 !CurDAG->isBaseWithConstantOffset(N))
Jim Grosbach3e556122010-10-26 22:37:02 +0000476 return false;
477
478 // Leave simple R +/- imm12 operands for LDRi12
Chris Lattner0a9481f2011-02-13 22:25:43 +0000479 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::OR) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000480 int RHSC;
481 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
482 -0x1000+1, 0x1000, RHSC)) // 12 bits.
483 return false;
Jim Grosbach3e556122010-10-26 22:37:02 +0000484 }
485
Evan Chengf40deed2010-10-27 23:41:30 +0000486 if (Subtarget->isCortexA9() && !N.hasOneUse())
487 // Compute R +/- (R << N) and reuse it.
488 return false;
489
Jim Grosbach3e556122010-10-26 22:37:02 +0000490 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000491 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::SUB ? ARM_AM::sub:ARM_AM::add;
Evan Chengee04a6d2011-07-20 23:34:39 +0000492 ARM_AM::ShiftOpc ShOpcVal =
493 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Jim Grosbach3e556122010-10-26 22:37:02 +0000494 unsigned ShAmt = 0;
495
496 Base = N.getOperand(0);
497 Offset = N.getOperand(1);
498
499 if (ShOpcVal != ARM_AM::no_shift) {
500 // Check to see if the RHS of the shift is a constant, if not, we can't fold
501 // it.
502 if (ConstantSDNode *Sh =
503 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
504 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000505 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
506 Offset = N.getOperand(1).getOperand(0);
507 else {
508 ShAmt = 0;
509 ShOpcVal = ARM_AM::no_shift;
510 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000511 } else {
512 ShOpcVal = ARM_AM::no_shift;
513 }
514 }
515
516 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000517 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000518 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000519 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Jim Grosbach3e556122010-10-26 22:37:02 +0000520 if (ShOpcVal != ARM_AM::no_shift) {
521 // Check to see if the RHS of the shift is a constant, if not, we can't
522 // fold it.
523 if (ConstantSDNode *Sh =
524 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
525 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000526 if (!Subtarget->isCortexA9() ||
527 (N.hasOneUse() &&
528 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
529 Offset = N.getOperand(0).getOperand(0);
530 Base = N.getOperand(1);
531 } else {
532 ShAmt = 0;
533 ShOpcVal = ARM_AM::no_shift;
534 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000535 } else {
536 ShOpcVal = ARM_AM::no_shift;
537 }
538 }
539 }
540
541 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
542 MVT::i32);
543 return true;
544}
545
546
547
548
549//-----
550
Jim Grosbach82891622010-09-29 19:03:54 +0000551AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
552 SDValue &Base,
553 SDValue &Offset,
554 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000555 if (N.getOpcode() == ISD::MUL &&
556 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000557 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
558 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000559 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000560 if (RHSC & 1) {
561 RHSC = RHSC & ~1;
562 ARM_AM::AddrOpc AddSub = ARM_AM::add;
563 if (RHSC < 0) {
564 AddSub = ARM_AM::sub;
565 RHSC = - RHSC;
566 }
567 if (isPowerOf2_32(RHSC)) {
568 unsigned ShAmt = Log2_32(RHSC);
569 Base = Offset = N.getOperand(0);
570 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
571 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000572 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000573 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000574 }
575 }
576 }
577 }
578
Chris Lattner0a9481f2011-02-13 22:25:43 +0000579 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
580 // ISD::OR that is equivalent to an ADD.
581 !CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000582 Base = N;
583 if (N.getOpcode() == ISD::FrameIndex) {
584 int FI = cast<FrameIndexSDNode>(N)->getIndex();
585 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000586 } else if (N.getOpcode() == ARMISD::Wrapper &&
587 !(Subtarget->useMovt() &&
588 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000589 Base = N.getOperand(0);
590 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000591 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000592 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
593 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000594 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000595 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000596 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000597
Evan Chenga8e29892007-01-19 07:51:42 +0000598 // Match simple R +/- imm12 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000599 if (N.getOpcode() != ISD::SUB) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000600 int RHSC;
601 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
602 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
603 Base = N.getOperand(0);
604 if (Base.getOpcode() == ISD::FrameIndex) {
605 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
606 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000607 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000608 Offset = CurDAG->getRegister(0, MVT::i32);
609
610 ARM_AM::AddrOpc AddSub = ARM_AM::add;
611 if (RHSC < 0) {
612 AddSub = ARM_AM::sub;
613 RHSC = - RHSC;
614 }
615 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
616 ARM_AM::no_shift),
617 MVT::i32);
618 return AM2_BASE;
Evan Chenga8e29892007-01-19 07:51:42 +0000619 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000620 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000621
Evan Chengf40deed2010-10-27 23:41:30 +0000622 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
623 // Compute R +/- (R << N) and reuse it.
624 Base = N;
625 Offset = CurDAG->getRegister(0, MVT::i32);
626 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
627 ARM_AM::no_shift),
628 MVT::i32);
629 return AM2_BASE;
630 }
631
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000632 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000633 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chengee04a6d2011-07-20 23:34:39 +0000634 ARM_AM::ShiftOpc ShOpcVal =
635 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000636 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000637
Evan Chenga8e29892007-01-19 07:51:42 +0000638 Base = N.getOperand(0);
639 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000640
Evan Chenga8e29892007-01-19 07:51:42 +0000641 if (ShOpcVal != ARM_AM::no_shift) {
642 // Check to see if the RHS of the shift is a constant, if not, we can't fold
643 // it.
644 if (ConstantSDNode *Sh =
645 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000646 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000647 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
648 Offset = N.getOperand(1).getOperand(0);
649 else {
650 ShAmt = 0;
651 ShOpcVal = ARM_AM::no_shift;
652 }
Evan Chenga8e29892007-01-19 07:51:42 +0000653 } else {
654 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000655 }
656 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000657
Evan Chenga8e29892007-01-19 07:51:42 +0000658 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000659 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000660 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000661 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000662 if (ShOpcVal != ARM_AM::no_shift) {
663 // Check to see if the RHS of the shift is a constant, if not, we can't
664 // fold it.
665 if (ConstantSDNode *Sh =
666 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000667 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000668 if (!Subtarget->isCortexA9() ||
669 (N.hasOneUse() &&
670 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
671 Offset = N.getOperand(0).getOperand(0);
672 Base = N.getOperand(1);
673 } else {
674 ShAmt = 0;
675 ShOpcVal = ARM_AM::no_shift;
676 }
Evan Chenga8e29892007-01-19 07:51:42 +0000677 } else {
678 ShOpcVal = ARM_AM::no_shift;
679 }
680 }
681 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000682
Evan Chenga8e29892007-01-19 07:51:42 +0000683 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000684 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000685 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000686}
687
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000688bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000689 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000690 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000691 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
692 ? cast<LoadSDNode>(Op)->getAddressingMode()
693 : cast<StoreSDNode>(Op)->getAddressingMode();
694 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
695 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000696 int Val;
697 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
698 Offset = CurDAG->getRegister(0, MVT::i32);
699 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
700 ARM_AM::no_shift),
701 MVT::i32);
702 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000703 }
704
705 Offset = N;
Evan Chengee04a6d2011-07-20 23:34:39 +0000706 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000707 unsigned ShAmt = 0;
708 if (ShOpcVal != ARM_AM::no_shift) {
709 // Check to see if the RHS of the shift is a constant, if not, we can't fold
710 // it.
711 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000712 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000713 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
714 Offset = N.getOperand(0);
715 else {
716 ShAmt = 0;
717 ShOpcVal = ARM_AM::no_shift;
718 }
Evan Chenga8e29892007-01-19 07:51:42 +0000719 } else {
720 ShOpcVal = ARM_AM::no_shift;
721 }
722 }
723
724 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000725 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000726 return true;
727}
728
Evan Chenga8e29892007-01-19 07:51:42 +0000729
Chris Lattner52a261b2010-09-21 20:31:19 +0000730bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000731 SDValue &Base, SDValue &Offset,
732 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000733 if (N.getOpcode() == ISD::SUB) {
734 // X - C is canonicalize to X + -C, no need to handle it here.
735 Base = N.getOperand(0);
736 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000737 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000738 return true;
739 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000740
Chris Lattner0a9481f2011-02-13 22:25:43 +0000741 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000742 Base = N;
743 if (N.getOpcode() == ISD::FrameIndex) {
744 int FI = cast<FrameIndexSDNode>(N)->getIndex();
745 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
746 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000747 Offset = CurDAG->getRegister(0, MVT::i32);
748 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000749 return true;
750 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000751
Evan Chenga8e29892007-01-19 07:51:42 +0000752 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000753 int RHSC;
754 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
755 -256 + 1, 256, RHSC)) { // 8 bits.
756 Base = N.getOperand(0);
757 if (Base.getOpcode() == ISD::FrameIndex) {
758 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
759 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000760 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000761 Offset = CurDAG->getRegister(0, MVT::i32);
762
763 ARM_AM::AddrOpc AddSub = ARM_AM::add;
764 if (RHSC < 0) {
765 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000766 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000767 }
768 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
769 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000770 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000771
Evan Chenga8e29892007-01-19 07:51:42 +0000772 Base = N.getOperand(0);
773 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000774 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000775 return true;
776}
777
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000778bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000779 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000780 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000781 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
782 ? cast<LoadSDNode>(Op)->getAddressingMode()
783 : cast<StoreSDNode>(Op)->getAddressingMode();
784 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
785 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000786 int Val;
787 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
788 Offset = CurDAG->getRegister(0, MVT::i32);
789 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
790 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000791 }
792
793 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000794 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000795 return true;
796}
797
Jim Grosbach3ab56582010-10-21 19:38:40 +0000798bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000799 SDValue &Base, SDValue &Offset) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000800 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000801 Base = N;
802 if (N.getOpcode() == ISD::FrameIndex) {
803 int FI = cast<FrameIndexSDNode>(N)->getIndex();
804 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000805 } else if (N.getOpcode() == ARMISD::Wrapper &&
806 !(Subtarget->useMovt() &&
807 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000808 Base = N.getOperand(0);
809 }
810 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000811 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000812 return true;
813 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000814
Evan Chenga8e29892007-01-19 07:51:42 +0000815 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000816 int RHSC;
817 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
818 -256 + 1, 256, RHSC)) {
819 Base = N.getOperand(0);
820 if (Base.getOpcode() == ISD::FrameIndex) {
821 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
822 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000823 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000824
825 ARM_AM::AddrOpc AddSub = ARM_AM::add;
826 if (RHSC < 0) {
827 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000828 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000829 }
830 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
831 MVT::i32);
832 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000833 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000834
Evan Chenga8e29892007-01-19 07:51:42 +0000835 Base = N;
836 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000837 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000838 return true;
839}
840
Bob Wilson665814b2010-11-01 23:40:51 +0000841bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
842 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000843 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000844
845 unsigned Alignment = 0;
846 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
847 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
848 // The maximum alignment is equal to the memory size being referenced.
849 unsigned LSNAlign = LSN->getAlignment();
850 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
851 if (LSNAlign > MemSize && MemSize > 1)
852 Alignment = MemSize;
853 } else {
854 // All other uses of addrmode6 are for intrinsics. For now just record
855 // the raw alignment value; it will be refined later based on the legal
856 // alignment operands for the intrinsic.
857 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
858 }
859
860 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000861 return true;
862}
863
Bob Wilsonda525062011-02-25 06:42:42 +0000864bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
865 SDValue &Offset) {
866 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
867 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
868 if (AM != ISD::POST_INC)
869 return false;
870 Offset = N;
871 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
872 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
873 Offset = CurDAG->getRegister(0, MVT::i32);
874 }
875 return true;
876}
877
Chris Lattner52a261b2010-09-21 20:31:19 +0000878bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000879 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000880 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
881 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000882 SDValue N1 = N.getOperand(1);
Evan Cheng9fe20092011-01-20 08:34:58 +0000883 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
884 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000885 return true;
886 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000887
Evan Chenga8e29892007-01-19 07:51:42 +0000888 return false;
889}
890
Bill Wendlingf4caf692010-12-14 03:36:38 +0000891
892//===----------------------------------------------------------------------===//
893// Thumb Addressing Modes
894//===----------------------------------------------------------------------===//
895
Chris Lattner52a261b2010-09-21 20:31:19 +0000896bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000897 SDValue &Base, SDValue &Offset){
Chris Lattner0a9481f2011-02-13 22:25:43 +0000898 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000899 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000900 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000901 return false;
902
903 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000904 return true;
905 }
906
Evan Chenga8e29892007-01-19 07:51:42 +0000907 Base = N.getOperand(0);
908 Offset = N.getOperand(1);
909 return true;
910}
911
Evan Cheng79d43262007-01-24 02:21:22 +0000912bool
Bill Wendlingf4caf692010-12-14 03:36:38 +0000913ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
914 SDValue &Offset, unsigned Scale) {
Evan Cheng79d43262007-01-24 02:21:22 +0000915 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000916 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000917 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000918 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendlingf4caf692010-12-14 03:36:38 +0000919
Evan Cheng012f2d92007-01-24 08:53:17 +0000920 if (N.getOpcode() == ARMISD::Wrapper &&
921 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
922 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000923 }
924
Chris Lattner0a9481f2011-02-13 22:25:43 +0000925 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000926 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000927
Evan Chengad0e4652007-02-06 00:22:06 +0000928 // Thumb does not have [sp, r] address mode.
929 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
930 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
931 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000932 (RHSR && RHSR->getReg() == ARM::SP))
933 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000934
Daniel Dunbarec91d522011-01-19 15:12:16 +0000935 // FIXME: Why do we explicitly check for a match here and then return false?
936 // Presumably to allow something else to match, but shouldn't this be
937 // documented?
938 int RHSC;
939 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
940 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000941
942 Base = N.getOperand(0);
943 Offset = N.getOperand(1);
944 return true;
945}
946
947bool
948ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
949 SDValue &Base,
950 SDValue &Offset) {
951 return SelectThumbAddrModeRI(N, Base, Offset, 1);
952}
953
954bool
955ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
956 SDValue &Base,
957 SDValue &Offset) {
958 return SelectThumbAddrModeRI(N, Base, Offset, 2);
959}
960
961bool
962ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
963 SDValue &Base,
964 SDValue &Offset) {
965 return SelectThumbAddrModeRI(N, Base, Offset, 4);
966}
967
968bool
969ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
970 SDValue &Base, SDValue &OffImm) {
971 if (Scale == 4) {
972 SDValue TmpBase, TmpOffImm;
973 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
974 return false; // We want to select tLDRspi / tSTRspi instead.
975
976 if (N.getOpcode() == ARMISD::Wrapper &&
977 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
978 return false; // We want to select tLDRpci instead.
979 }
980
Chris Lattner0a9481f2011-02-13 22:25:43 +0000981 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000982 if (N.getOpcode() == ARMISD::Wrapper &&
983 !(Subtarget->useMovt() &&
984 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
985 Base = N.getOperand(0);
986 } else {
987 Base = N;
988 }
989
Owen Anderson825b72b2009-08-11 20:47:22 +0000990 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000991 return true;
992 }
993
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000994 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
995 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
996 if ((LHSR && LHSR->getReg() == ARM::SP) ||
997 (RHSR && RHSR->getReg() == ARM::SP)) {
998 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
999 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1000 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1001 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1002
1003 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1004 if (LHSC != 0 || RHSC != 0) return false;
1005
1006 Base = N;
1007 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1008 return true;
1009 }
1010
Evan Chenga8e29892007-01-19 07:51:42 +00001011 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001012 int RHSC;
1013 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1014 Base = N.getOperand(0);
1015 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1016 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001017 }
1018
Evan Chengc38f2bc2007-01-23 22:59:13 +00001019 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001020 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +00001021 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001022}
1023
Bill Wendlingf4caf692010-12-14 03:36:38 +00001024bool
1025ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1026 SDValue &OffImm) {
1027 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001028}
1029
Bill Wendlingf4caf692010-12-14 03:36:38 +00001030bool
1031ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1032 SDValue &OffImm) {
1033 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001034}
1035
Bill Wendlingf4caf692010-12-14 03:36:38 +00001036bool
1037ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1038 SDValue &OffImm) {
1039 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001040}
1041
Chris Lattner52a261b2010-09-21 20:31:19 +00001042bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1043 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +00001044 if (N.getOpcode() == ISD::FrameIndex) {
1045 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1046 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001047 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001048 return true;
1049 }
Evan Cheng79d43262007-01-24 02:21:22 +00001050
Chris Lattner0a9481f2011-02-13 22:25:43 +00001051 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Chengad0e4652007-02-06 00:22:06 +00001052 return false;
1053
1054 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001055 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1056 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +00001057 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001058 int RHSC;
1059 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1060 Base = N.getOperand(0);
1061 if (Base.getOpcode() == ISD::FrameIndex) {
1062 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1063 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng79d43262007-01-24 02:21:22 +00001064 }
Daniel Dunbarec91d522011-01-19 15:12:16 +00001065 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1066 return true;
Evan Cheng79d43262007-01-24 02:21:22 +00001067 }
1068 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001069
Evan Chenga8e29892007-01-19 07:51:42 +00001070 return false;
1071}
1072
Bill Wendlingf4caf692010-12-14 03:36:38 +00001073
1074//===----------------------------------------------------------------------===//
1075// Thumb 2 Addressing Modes
1076//===----------------------------------------------------------------------===//
1077
1078
Chris Lattner52a261b2010-09-21 20:31:19 +00001079bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001080 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001081 if (DisableShifterOp)
1082 return false;
1083
Evan Chengee04a6d2011-07-20 23:34:39 +00001084 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng9cb9e672009-06-27 02:26:13 +00001085
1086 // Don't match base register only case. That is matched to a separate
1087 // lower complexity pattern with explicit register operand.
1088 if (ShOpcVal == ARM_AM::no_shift) return false;
1089
1090 BaseReg = N.getOperand(0);
1091 unsigned ShImmVal = 0;
1092 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1093 ShImmVal = RHS->getZExtValue() & 31;
1094 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1095 return true;
1096 }
1097
1098 return false;
1099}
1100
Chris Lattner52a261b2010-09-21 20:31:19 +00001101bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001102 SDValue &Base, SDValue &OffImm) {
1103 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001104
Evan Cheng3a214252009-08-11 08:52:18 +00001105 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001106 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1107 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001108 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +00001109 // Match frame index.
David Goodwin31e7eba2009-07-20 15:55:39 +00001110 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1111 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001112 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001113 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +00001114 }
Owen Anderson099e5552011-03-18 19:46:58 +00001115
Chris Lattner0a9481f2011-02-13 22:25:43 +00001116 if (N.getOpcode() == ARMISD::Wrapper &&
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001117 !(Subtarget->useMovt() &&
1118 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +00001119 Base = N.getOperand(0);
1120 if (Base.getOpcode() == ISD::TargetConstantPool)
1121 return false; // We want to select t2LDRpci instead.
1122 } else
1123 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001124 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001125 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +00001126 }
Evan Cheng055b0312009-06-29 07:51:04 +00001127
1128 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +00001129 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +00001130 // Let t2LDRi8 handle (R - imm8).
1131 return false;
1132
Evan Cheng055b0312009-06-29 07:51:04 +00001133 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +00001134 if (N.getOpcode() == ISD::SUB)
1135 RHSC = -RHSC;
1136
1137 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001138 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001139 if (Base.getOpcode() == ISD::FrameIndex) {
1140 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1141 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1142 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001143 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001144 return true;
1145 }
1146 }
1147
Evan Cheng3a214252009-08-11 08:52:18 +00001148 // Base only.
1149 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001150 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001151 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001152}
1153
Chris Lattner52a261b2010-09-21 20:31:19 +00001154bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001155 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001156 // Match simple R - imm8 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001157 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1158 !CurDAG->isBaseWithConstantOffset(N))
1159 return false;
Owen Anderson099e5552011-03-18 19:46:58 +00001160
Chris Lattner0a9481f2011-02-13 22:25:43 +00001161 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1162 int RHSC = (int)RHS->getSExtValue();
1163 if (N.getOpcode() == ISD::SUB)
1164 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001165
Chris Lattner0a9481f2011-02-13 22:25:43 +00001166 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1167 Base = N.getOperand(0);
1168 if (Base.getOpcode() == ISD::FrameIndex) {
1169 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1170 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng055b0312009-06-29 07:51:04 +00001171 }
Chris Lattner0a9481f2011-02-13 22:25:43 +00001172 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1173 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001174 }
1175 }
1176
1177 return false;
1178}
1179
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001180bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001181 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001182 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001183 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1184 ? cast<LoadSDNode>(Op)->getAddressingMode()
1185 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbarec91d522011-01-19 15:12:16 +00001186 int RHSC;
1187 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1188 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1189 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1190 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1191 return true;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001192 }
1193
1194 return false;
1195}
1196
Chris Lattner52a261b2010-09-21 20:31:19 +00001197bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001198 SDValue &Base,
1199 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001200 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001201 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng3a214252009-08-11 08:52:18 +00001202 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001203
Evan Cheng3a214252009-08-11 08:52:18 +00001204 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1205 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1206 int RHSC = (int)RHS->getZExtValue();
1207 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1208 return false;
1209 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001210 return false;
1211 }
1212
Evan Chengf40deed2010-10-27 23:41:30 +00001213 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
1214 // Compute R + (R << [1,2,3]) and reuse it.
1215 Base = N;
1216 return false;
1217 }
1218
Evan Cheng055b0312009-06-29 07:51:04 +00001219 // Look for (R + R) or (R + (R << [1,2,3])).
1220 unsigned ShAmt = 0;
1221 Base = N.getOperand(0);
1222 OffReg = N.getOperand(1);
1223
1224 // Swap if it is ((R << c) + R).
Evan Chengee04a6d2011-07-20 23:34:39 +00001225 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001226 if (ShOpcVal != ARM_AM::lsl) {
Evan Chengee04a6d2011-07-20 23:34:39 +00001227 ShOpcVal = ARM_AM::getShiftOpcForNode(Base.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001228 if (ShOpcVal == ARM_AM::lsl)
1229 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001230 }
1231
Evan Cheng055b0312009-06-29 07:51:04 +00001232 if (ShOpcVal == ARM_AM::lsl) {
1233 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1234 // it.
1235 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1236 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001237 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1238 OffReg = OffReg.getOperand(0);
1239 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001240 ShAmt = 0;
1241 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001242 }
Evan Cheng055b0312009-06-29 07:51:04 +00001243 } else {
1244 ShOpcVal = ARM_AM::no_shift;
1245 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001246 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001247
Owen Anderson825b72b2009-08-11 20:47:22 +00001248 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001249
1250 return true;
1251}
1252
1253//===--------------------------------------------------------------------===//
1254
Evan Chengee568cf2007-07-05 07:15:27 +00001255/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001256static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001257 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001258}
1259
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001260SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1261 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001262 ISD::MemIndexedMode AM = LD->getAddressingMode();
1263 if (AM == ISD::UNINDEXED)
1264 return NULL;
1265
Owen Andersone50ed302009-08-10 22:56:29 +00001266 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001267 SDValue Offset, AMOpc;
1268 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1269 unsigned Opcode = 0;
1270 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +00001271 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001272 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001273 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
1274 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +00001275 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001276 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001277 Match = true;
1278 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1279 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1280 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001281 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001282 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001283 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001284 Match = true;
1285 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1286 }
1287 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001288 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001289 Match = true;
1290 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
1291 }
1292 }
1293 }
1294
1295 if (Match) {
1296 SDValue Chain = LD->getChain();
1297 SDValue Base = LD->getBasePtr();
1298 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001299 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001300 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001301 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +00001302 }
1303
1304 return NULL;
1305}
1306
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001307SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1308 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001309 ISD::MemIndexedMode AM = LD->getAddressingMode();
1310 if (AM == ISD::UNINDEXED)
1311 return NULL;
1312
Owen Andersone50ed302009-08-10 22:56:29 +00001313 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001314 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001315 SDValue Offset;
1316 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1317 unsigned Opcode = 0;
1318 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001319 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001320 switch (LoadedVT.getSimpleVT().SimpleTy) {
1321 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001322 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1323 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001324 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001325 if (isSExtLd)
1326 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1327 else
1328 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001329 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001330 case MVT::i8:
1331 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001332 if (isSExtLd)
1333 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1334 else
1335 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001336 break;
1337 default:
1338 return NULL;
1339 }
1340 Match = true;
1341 }
1342
1343 if (Match) {
1344 SDValue Chain = LD->getChain();
1345 SDValue Base = LD->getBasePtr();
1346 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001347 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001348 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001349 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001350 }
1351
1352 return NULL;
1353}
1354
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001355/// PairSRegs - Form a D register from a pair of S registers.
1356///
1357SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1358 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001359 SDValue RegClass =
1360 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001361 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1362 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001363 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1364 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001365}
1366
Evan Cheng603afbf2010-05-10 17:34:18 +00001367/// PairDRegs - Form a quad register from a pair of D registers.
1368///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001369SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1370 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001371 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001372 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1373 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001374 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1375 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001376}
1377
Evan Cheng7f687192010-05-14 00:21:45 +00001378/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001379///
1380SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1381 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001382 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001383 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1384 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001385 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1386 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Evan Cheng603afbf2010-05-10 17:34:18 +00001387}
1388
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001389/// QuadSRegs - Form 4 consecutive S registers.
1390///
1391SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1392 SDValue V2, SDValue V3) {
1393 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001394 SDValue RegClass =
1395 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001396 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1397 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1398 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1399 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001400 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1401 V2, SubReg2, V3, SubReg3 };
1402 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001403}
1404
Evan Cheng7f687192010-05-14 00:21:45 +00001405/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001406///
1407SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1408 SDValue V2, SDValue V3) {
1409 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001410 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001411 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1412 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1413 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1414 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001415 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1416 V2, SubReg2, V3, SubReg3 };
1417 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng603afbf2010-05-10 17:34:18 +00001418}
1419
Evan Cheng8f6de382010-05-16 03:27:48 +00001420/// QuadQRegs - Form 4 consecutive Q registers.
1421///
1422SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1423 SDValue V2, SDValue V3) {
1424 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001425 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001426 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1427 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1428 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1429 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001430 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1431 V2, SubReg2, V3, SubReg3 };
1432 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng8f6de382010-05-16 03:27:48 +00001433}
1434
Bob Wilson2a6e6162010-09-23 23:42:37 +00001435/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1436/// of a NEON VLD or VST instruction. The supported values depend on the
1437/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001438SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1439 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001440 unsigned NumRegs = NumVecs;
1441 if (!is64BitVector && NumVecs < 3)
1442 NumRegs *= 2;
1443
Bob Wilson665814b2010-11-01 23:40:51 +00001444 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001445 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001446 Alignment = 32;
1447 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1448 Alignment = 16;
1449 else if (Alignment >= 8)
1450 Alignment = 8;
1451 else
1452 Alignment = 0;
1453
1454 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001455}
1456
Bob Wilson1c3ef902011-02-07 17:43:21 +00001457SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001458 unsigned *DOpcodes, unsigned *QOpcodes0,
1459 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001460 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001461 DebugLoc dl = N->getDebugLoc();
1462
Bob Wilson226036e2010-03-20 22:13:40 +00001463 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001464 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1465 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001466 return NULL;
1467
1468 SDValue Chain = N->getOperand(0);
1469 EVT VT = N->getValueType(0);
1470 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001471 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001472
Bob Wilson3e36f132009-10-14 17:28:52 +00001473 unsigned OpcodeIndex;
1474 switch (VT.getSimpleVT().SimpleTy) {
1475 default: llvm_unreachable("unhandled vld type");
1476 // Double-register operations:
1477 case MVT::v8i8: OpcodeIndex = 0; break;
1478 case MVT::v4i16: OpcodeIndex = 1; break;
1479 case MVT::v2f32:
1480 case MVT::v2i32: OpcodeIndex = 2; break;
1481 case MVT::v1i64: OpcodeIndex = 3; break;
1482 // Quad-register operations:
1483 case MVT::v16i8: OpcodeIndex = 0; break;
1484 case MVT::v8i16: OpcodeIndex = 1; break;
1485 case MVT::v4f32:
1486 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001487 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001488 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001489 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001490 }
1491
Bob Wilsonf5721912010-09-03 18:16:02 +00001492 EVT ResTy;
1493 if (NumVecs == 1)
1494 ResTy = VT;
1495 else {
1496 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1497 if (!is64BitVector)
1498 ResTyElts *= 2;
1499 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1500 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001501 std::vector<EVT> ResTys;
1502 ResTys.push_back(ResTy);
1503 if (isUpdating)
1504 ResTys.push_back(MVT::i32);
1505 ResTys.push_back(MVT::Other);
Bob Wilsonf5721912010-09-03 18:16:02 +00001506
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001507 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001508 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001509 SDNode *VLd;
1510 SmallVector<SDValue, 7> Ops;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001511
Bob Wilson1c3ef902011-02-07 17:43:21 +00001512 // Double registers and VLD1/VLD2 quad registers are directly supported.
1513 if (is64BitVector || NumVecs <= 2) {
1514 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1515 QOpcodes0[OpcodeIndex]);
1516 Ops.push_back(MemAddr);
1517 Ops.push_back(Align);
1518 if (isUpdating) {
1519 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1520 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001521 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001522 Ops.push_back(Pred);
1523 Ops.push_back(Reg0);
1524 Ops.push_back(Chain);
1525 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonffde0802010-09-02 16:00:54 +00001526
Bob Wilson3e36f132009-10-14 17:28:52 +00001527 } else {
1528 // Otherwise, quad registers are loaded with two separate instructions,
1529 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001530 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001531
Bob Wilson1c3ef902011-02-07 17:43:21 +00001532 // Load the even subregs. This is always an updating load, so that it
1533 // provides the address to the second load for the odd subregs.
Bob Wilsonf5721912010-09-03 18:16:02 +00001534 SDValue ImplDef =
1535 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1536 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilson7de68142011-02-07 17:43:15 +00001537 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1538 ResTy, AddrTy, MVT::Other, OpsA, 7);
Bob Wilsonf5721912010-09-03 18:16:02 +00001539 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001540
Bob Wilson24f995d2009-10-14 18:32:29 +00001541 // Load the odd subregs.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001542 Ops.push_back(SDValue(VLdA, 1));
1543 Ops.push_back(Align);
1544 if (isUpdating) {
1545 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1546 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1547 "only constant post-increment update allowed for VLD3/4");
1548 (void)Inc;
1549 Ops.push_back(Reg0);
1550 }
1551 Ops.push_back(SDValue(VLdA, 0));
1552 Ops.push_back(Pred);
1553 Ops.push_back(Reg0);
1554 Ops.push_back(Chain);
1555 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1556 Ops.data(), Ops.size());
Bob Wilsonf5721912010-09-03 18:16:02 +00001557 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001558
Evan Chengb58a3402011-04-19 00:04:03 +00001559 // Transfer memoperands.
1560 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1561 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1562 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1563
Bob Wilson1c3ef902011-02-07 17:43:21 +00001564 if (NumVecs == 1)
1565 return VLd;
1566
1567 // Extract out the subregisters.
1568 SDValue SuperReg = SDValue(VLd, 0);
1569 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1570 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1571 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1572 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1573 ReplaceUses(SDValue(N, Vec),
1574 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1575 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1576 if (isUpdating)
1577 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson3e36f132009-10-14 17:28:52 +00001578 return NULL;
1579}
1580
Bob Wilson1c3ef902011-02-07 17:43:21 +00001581SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001582 unsigned *DOpcodes, unsigned *QOpcodes0,
1583 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001584 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001585 DebugLoc dl = N->getDebugLoc();
1586
Bob Wilson226036e2010-03-20 22:13:40 +00001587 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001588 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1589 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1590 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001591 return NULL;
1592
Evan Chengb58a3402011-04-19 00:04:03 +00001593 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1594 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1595
Bob Wilson24f995d2009-10-14 18:32:29 +00001596 SDValue Chain = N->getOperand(0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001597 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson24f995d2009-10-14 18:32:29 +00001598 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001599 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001600
Bob Wilson24f995d2009-10-14 18:32:29 +00001601 unsigned OpcodeIndex;
1602 switch (VT.getSimpleVT().SimpleTy) {
1603 default: llvm_unreachable("unhandled vst type");
1604 // Double-register operations:
1605 case MVT::v8i8: OpcodeIndex = 0; break;
1606 case MVT::v4i16: OpcodeIndex = 1; break;
1607 case MVT::v2f32:
1608 case MVT::v2i32: OpcodeIndex = 2; break;
1609 case MVT::v1i64: OpcodeIndex = 3; break;
1610 // Quad-register operations:
1611 case MVT::v16i8: OpcodeIndex = 0; break;
1612 case MVT::v8i16: OpcodeIndex = 1; break;
1613 case MVT::v4f32:
1614 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001615 case MVT::v2i64: OpcodeIndex = 3;
1616 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1617 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001618 }
1619
Bob Wilson1c3ef902011-02-07 17:43:21 +00001620 std::vector<EVT> ResTys;
1621 if (isUpdating)
1622 ResTys.push_back(MVT::i32);
1623 ResTys.push_back(MVT::Other);
1624
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001625 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001626 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001627 SmallVector<SDValue, 7> Ops;
Evan Chengac0869d2009-11-21 06:21:52 +00001628
Bob Wilson1c3ef902011-02-07 17:43:21 +00001629 // Double registers and VST1/VST2 quad registers are directly supported.
1630 if (is64BitVector || NumVecs <= 2) {
Bob Wilson7de68142011-02-07 17:43:15 +00001631 SDValue SrcReg;
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001632 if (NumVecs == 1) {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001633 SrcReg = N->getOperand(Vec0Idx);
1634 } else if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001635 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001636 SDValue V0 = N->getOperand(Vec0Idx + 0);
1637 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001638 if (NumVecs == 2)
Bob Wilson7de68142011-02-07 17:43:15 +00001639 SrcReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001640 else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001641 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson7de68142011-02-07 17:43:15 +00001642 // If it's a vst3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001643 // an undef.
1644 SDValue V3 = (NumVecs == 3)
1645 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001646 : N->getOperand(Vec0Idx + 3);
Bob Wilson7de68142011-02-07 17:43:15 +00001647 SrcReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001648 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001649 } else {
1650 // Form a QQ register.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001651 SDValue Q0 = N->getOperand(Vec0Idx);
1652 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Bob Wilson7de68142011-02-07 17:43:15 +00001653 SrcReg = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
Bob Wilson24f995d2009-10-14 18:32:29 +00001654 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001655
1656 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1657 QOpcodes0[OpcodeIndex]);
1658 Ops.push_back(MemAddr);
1659 Ops.push_back(Align);
1660 if (isUpdating) {
1661 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1662 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1663 }
1664 Ops.push_back(SrcReg);
1665 Ops.push_back(Pred);
1666 Ops.push_back(Reg0);
1667 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001668 SDNode *VSt =
1669 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
1670
1671 // Transfer memoperands.
1672 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
1673
1674 return VSt;
Bob Wilson24f995d2009-10-14 18:32:29 +00001675 }
1676
1677 // Otherwise, quad registers are stored with two separate instructions,
1678 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001679
Bob Wilson07f6e802010-06-16 21:34:01 +00001680 // Form the QQQQ REG_SEQUENCE.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001681 SDValue V0 = N->getOperand(Vec0Idx + 0);
1682 SDValue V1 = N->getOperand(Vec0Idx + 1);
1683 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001684 SDValue V3 = (NumVecs == 3)
1685 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001686 : N->getOperand(Vec0Idx + 3);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001687 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001688
Bob Wilson1c3ef902011-02-07 17:43:21 +00001689 // Store the even D registers. This is always an updating store, so that it
1690 // provides the address to the second store for the odd subregs.
Bob Wilson7de68142011-02-07 17:43:15 +00001691 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1692 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1693 MemAddr.getValueType(),
1694 MVT::Other, OpsA, 7);
Evan Chengb58a3402011-04-19 00:04:03 +00001695 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson07f6e802010-06-16 21:34:01 +00001696 Chain = SDValue(VStA, 1);
1697
1698 // Store the odd D registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001699 Ops.push_back(SDValue(VStA, 0));
1700 Ops.push_back(Align);
1701 if (isUpdating) {
1702 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1703 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1704 "only constant post-increment update allowed for VST3/4");
1705 (void)Inc;
1706 Ops.push_back(Reg0);
1707 }
1708 Ops.push_back(RegSeq);
1709 Ops.push_back(Pred);
1710 Ops.push_back(Reg0);
1711 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001712 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1713 Ops.data(), Ops.size());
1714 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
1715 return VStB;
Bob Wilson24f995d2009-10-14 18:32:29 +00001716}
1717
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001718SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson1c3ef902011-02-07 17:43:21 +00001719 bool isUpdating, unsigned NumVecs,
1720 unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001721 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001722 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001723 DebugLoc dl = N->getDebugLoc();
1724
Bob Wilson226036e2010-03-20 22:13:40 +00001725 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001726 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1727 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1728 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001729 return NULL;
1730
Evan Chengb58a3402011-04-19 00:04:03 +00001731 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1732 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1733
Bob Wilsona7c397c2009-10-14 16:19:03 +00001734 SDValue Chain = N->getOperand(0);
1735 unsigned Lane =
Bob Wilson1c3ef902011-02-07 17:43:21 +00001736 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
1737 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001738 bool is64BitVector = VT.is64BitVector();
1739
Bob Wilson665814b2010-11-01 23:40:51 +00001740 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001741 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001742 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001743 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1744 if (Alignment > NumBytes)
1745 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001746 if (Alignment < 8 && Alignment < NumBytes)
1747 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001748 // Alignment must be a power of two; make sure of that.
1749 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001750 if (Alignment == 1)
1751 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001752 }
Bob Wilson665814b2010-11-01 23:40:51 +00001753 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001754
Bob Wilsona7c397c2009-10-14 16:19:03 +00001755 unsigned OpcodeIndex;
1756 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001757 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001758 // Double-register operations:
1759 case MVT::v8i8: OpcodeIndex = 0; break;
1760 case MVT::v4i16: OpcodeIndex = 1; break;
1761 case MVT::v2f32:
1762 case MVT::v2i32: OpcodeIndex = 2; break;
1763 // Quad-register operations:
1764 case MVT::v8i16: OpcodeIndex = 0; break;
1765 case MVT::v4f32:
1766 case MVT::v4i32: OpcodeIndex = 1; break;
1767 }
1768
Bob Wilson1c3ef902011-02-07 17:43:21 +00001769 std::vector<EVT> ResTys;
1770 if (IsLoad) {
1771 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1772 if (!is64BitVector)
1773 ResTyElts *= 2;
1774 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
1775 MVT::i64, ResTyElts));
1776 }
1777 if (isUpdating)
1778 ResTys.push_back(MVT::i32);
1779 ResTys.push_back(MVT::Other);
1780
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001781 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001782 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001783
Bob Wilson1c3ef902011-02-07 17:43:21 +00001784 SmallVector<SDValue, 8> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001785 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001786 Ops.push_back(Align);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001787 if (isUpdating) {
1788 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1789 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1790 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001791
Bob Wilson8466fa12010-09-13 23:01:35 +00001792 SDValue SuperReg;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001793 SDValue V0 = N->getOperand(Vec0Idx + 0);
1794 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilson8466fa12010-09-13 23:01:35 +00001795 if (NumVecs == 2) {
1796 if (is64BitVector)
1797 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1798 else
1799 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001800 } else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001801 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson8466fa12010-09-13 23:01:35 +00001802 SDValue V3 = (NumVecs == 3)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001803 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1804 : N->getOperand(Vec0Idx + 3);
Bob Wilson8466fa12010-09-13 23:01:35 +00001805 if (is64BitVector)
1806 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1807 else
1808 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001809 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001810 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001811 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001812 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001813 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001814 Ops.push_back(Chain);
1815
Bob Wilson1c3ef902011-02-07 17:43:21 +00001816 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1817 QOpcodes[OpcodeIndex]);
1818 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys,
1819 Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001820 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson96493442009-10-14 16:46:45 +00001821 if (!IsLoad)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001822 return VLdLn;
Evan Cheng7092c2b2010-05-15 01:36:29 +00001823
Bob Wilson8466fa12010-09-13 23:01:35 +00001824 // Extract the subregisters.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001825 SuperReg = SDValue(VLdLn, 0);
1826 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1827 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1828 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson07f6e802010-06-16 21:34:01 +00001829 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1830 ReplaceUses(SDValue(N, Vec),
Bob Wilson1c3ef902011-02-07 17:43:21 +00001831 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1832 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
1833 if (isUpdating)
1834 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001835 return NULL;
1836}
1837
Bob Wilson1c3ef902011-02-07 17:43:21 +00001838SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
1839 unsigned NumVecs, unsigned *Opcodes) {
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001840 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1841 DebugLoc dl = N->getDebugLoc();
1842
1843 SDValue MemAddr, Align;
1844 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1845 return NULL;
1846
Evan Chengb58a3402011-04-19 00:04:03 +00001847 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1848 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1849
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001850 SDValue Chain = N->getOperand(0);
1851 EVT VT = N->getValueType(0);
1852
1853 unsigned Alignment = 0;
1854 if (NumVecs != 3) {
1855 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1856 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1857 if (Alignment > NumBytes)
1858 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001859 if (Alignment < 8 && Alignment < NumBytes)
1860 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001861 // Alignment must be a power of two; make sure of that.
1862 Alignment = (Alignment & -Alignment);
1863 if (Alignment == 1)
1864 Alignment = 0;
1865 }
1866 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1867
1868 unsigned OpcodeIndex;
1869 switch (VT.getSimpleVT().SimpleTy) {
1870 default: llvm_unreachable("unhandled vld-dup type");
1871 case MVT::v8i8: OpcodeIndex = 0; break;
1872 case MVT::v4i16: OpcodeIndex = 1; break;
1873 case MVT::v2f32:
1874 case MVT::v2i32: OpcodeIndex = 2; break;
1875 }
1876
1877 SDValue Pred = getAL(CurDAG);
1878 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1879 SDValue SuperReg;
1880 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson1c3ef902011-02-07 17:43:21 +00001881 SmallVector<SDValue, 6> Ops;
1882 Ops.push_back(MemAddr);
1883 Ops.push_back(Align);
1884 if (isUpdating) {
1885 SDValue Inc = N->getOperand(2);
1886 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1887 }
1888 Ops.push_back(Pred);
1889 Ops.push_back(Reg0);
1890 Ops.push_back(Chain);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001891
1892 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001893 std::vector<EVT> ResTys;
Evan Chengb58a3402011-04-19 00:04:03 +00001894 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001895 if (isUpdating)
1896 ResTys.push_back(MVT::i32);
1897 ResTys.push_back(MVT::Other);
1898 SDNode *VLdDup =
1899 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001900 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001901 SuperReg = SDValue(VLdDup, 0);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001902
1903 // Extract the subregisters.
1904 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1905 unsigned SubIdx = ARM::dsub_0;
1906 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1907 ReplaceUses(SDValue(N, Vec),
1908 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001909 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
1910 if (isUpdating)
1911 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001912 return NULL;
1913}
1914
Bob Wilson78dfbc32010-07-07 00:08:54 +00001915SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1916 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001917 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1918 DebugLoc dl = N->getDebugLoc();
1919 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001920 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001921
1922 // Form a REG_SEQUENCE to force register allocation.
1923 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001924 SDValue V0 = N->getOperand(FirstTblReg + 0);
1925 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001926 if (NumVecs == 2)
1927 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1928 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001929 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001930 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00001931 // an undef.
1932 SDValue V3 = (NumVecs == 3)
1933 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001934 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001935 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1936 }
1937
Bob Wilson78dfbc32010-07-07 00:08:54 +00001938 SmallVector<SDValue, 6> Ops;
1939 if (IsExt)
1940 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00001941 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001942 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001943 Ops.push_back(getAL(CurDAG)); // predicate
1944 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001945 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001946}
1947
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001948SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001949 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001950 if (!Subtarget->hasV6T2Ops())
1951 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001952
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001953 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1954 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1955
1956
1957 // For unsigned extracts, check for a shift right and mask
1958 unsigned And_imm = 0;
1959 if (N->getOpcode() == ISD::AND) {
1960 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1961
1962 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1963 if (And_imm & (And_imm + 1))
1964 return NULL;
1965
1966 unsigned Srl_imm = 0;
1967 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1968 Srl_imm)) {
1969 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1970
1971 unsigned Width = CountTrailingOnes_32(And_imm);
1972 unsigned LSB = Srl_imm;
1973 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1974 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1975 CurDAG->getTargetConstant(LSB, MVT::i32),
1976 CurDAG->getTargetConstant(Width, MVT::i32),
1977 getAL(CurDAG), Reg0 };
1978 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1979 }
1980 }
1981 return NULL;
1982 }
1983
1984 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001985 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001986 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001987 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1988 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001989 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001990 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1991 unsigned Width = 32 - Srl_imm;
1992 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001993 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001994 return NULL;
1995 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001996 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001997 CurDAG->getTargetConstant(LSB, MVT::i32),
1998 CurDAG->getTargetConstant(Width, MVT::i32),
1999 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002000 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002001 }
2002 }
2003 return NULL;
2004}
2005
Evan Cheng9ef48352009-11-20 00:54:03 +00002006SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002007SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002008 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2009 SDValue CPTmp0;
2010 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00002011 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002012 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
2013 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
2014 unsigned Opc = 0;
2015 switch (SOShOp) {
2016 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
2017 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
2018 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
2019 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
2020 default:
2021 llvm_unreachable("Unknown so_reg opcode!");
2022 break;
2023 }
2024 SDValue SOShImm =
2025 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
2026 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2027 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002028 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00002029 }
2030 return 0;
2031}
2032
2033SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002034SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002035 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2036 SDValue CPTmp0;
2037 SDValue CPTmp1;
2038 SDValue CPTmp2;
Chris Lattner52a261b2010-09-21 20:31:19 +00002039 if (SelectShifterOperandReg(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002040 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2041 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002042 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00002043 }
2044 return 0;
2045}
2046
2047SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00002048SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002049 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002050 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00002051 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00002052 return 0;
2053
Evan Cheng63f35442010-11-13 02:25:14 +00002054 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00002055 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00002056 if (is_t2_so_imm(TrueImm)) {
2057 Opc = ARM::t2MOVCCi;
2058 } else if (TrueImm <= 0xffff) {
2059 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002060 } else if (is_t2_so_imm_not(TrueImm)) {
2061 TrueImm = ~TrueImm;
2062 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002063 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00002064 // Large immediate.
2065 Opc = ARM::t2MOVCCi32imm;
2066 }
2067
2068 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002069 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002070 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2071 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002072 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002073 }
Evan Cheng63f35442010-11-13 02:25:14 +00002074
Evan Cheng9ef48352009-11-20 00:54:03 +00002075 return 0;
2076}
2077
2078SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002079SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002080 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002081 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2082 if (!T)
2083 return 0;
2084
Evan Cheng63f35442010-11-13 02:25:14 +00002085 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002086 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002087 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002088 if (isSoImm) {
2089 Opc = ARM::MOVCCi;
2090 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2091 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002092 } else if (is_so_imm_not(TrueImm)) {
2093 TrueImm = ~TrueImm;
2094 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002095 } else if (TrueVal.getNode()->hasOneUse() &&
2096 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002097 // Large immediate.
2098 Opc = ARM::MOVCCi32imm;
2099 }
2100
2101 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002102 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002103 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2104 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002105 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002106 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002107
Evan Cheng9ef48352009-11-20 00:54:03 +00002108 return 0;
2109}
2110
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002111SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2112 EVT VT = N->getValueType(0);
2113 SDValue FalseVal = N->getOperand(0);
2114 SDValue TrueVal = N->getOperand(1);
2115 SDValue CC = N->getOperand(2);
2116 SDValue CCR = N->getOperand(3);
2117 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002118 assert(CC.getOpcode() == ISD::Constant);
2119 assert(CCR.getOpcode() == ISD::Register);
2120 ARMCC::CondCodes CCVal =
2121 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002122
2123 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2124 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2125 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2126 // Pattern complexity = 18 cost = 1 size = 0
2127 SDValue CPTmp0;
2128 SDValue CPTmp1;
2129 SDValue CPTmp2;
2130 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002131 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002132 CCVal, CCR, InFlag);
2133 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002134 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002135 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2136 if (Res)
2137 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002138 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002139 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002140 CCVal, CCR, InFlag);
2141 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002142 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002143 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2144 if (Res)
2145 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002146 }
2147
2148 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002149 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002150 // (imm:i32):$cc)
2151 // Emits: (MOVCCi:i32 GPR:i32:$false,
2152 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2153 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002154 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002155 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002156 CCVal, CCR, InFlag);
2157 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002158 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002159 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2160 if (Res)
2161 return Res;
2162 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002163 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002164 CCVal, CCR, InFlag);
2165 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002166 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002167 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2168 if (Res)
2169 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002170 }
2171 }
2172
2173 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2174 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2175 // Pattern complexity = 6 cost = 1 size = 0
2176 //
2177 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2178 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2179 // Pattern complexity = 6 cost = 11 size = 0
2180 //
Jim Grosbach3c5edaa2011-03-11 23:15:02 +00002181 // Also VMOVScc and VMOVDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002182 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2183 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002184 unsigned Opc = 0;
2185 switch (VT.getSimpleVT().SimpleTy) {
2186 default: assert(false && "Illegal conditional move type!");
2187 break;
2188 case MVT::i32:
2189 Opc = Subtarget->isThumb()
2190 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2191 : ARM::MOVCCr;
2192 break;
2193 case MVT::f32:
2194 Opc = ARM::VMOVScc;
2195 break;
2196 case MVT::f64:
2197 Opc = ARM::VMOVDcc;
2198 break;
2199 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002200 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002201}
2202
Evan Chengde8aa4e2010-05-05 18:28:36 +00002203SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2204 // The only time a CONCAT_VECTORS operation can have legal types is when
2205 // two 64-bit vectors are concatenated to a 128-bit vector.
2206 EVT VT = N->getValueType(0);
2207 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2208 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002209 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002210}
2211
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002212SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002213 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002214
Dan Gohmane8be6c62008-07-17 19:10:17 +00002215 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002216 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002217
2218 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002219 default: break;
2220 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002221 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002222 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002223 if (Subtarget->hasThumb2())
2224 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2225 // be done with MOV + MOVT, at worst.
2226 UseCP = 0;
2227 else {
2228 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002229 UseCP = (Val > 255 && // MOV
2230 ~Val > 255 && // MOV + MVN
2231 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002232 } else
2233 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2234 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2235 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2236 }
2237
Evan Chenga8e29892007-01-19 07:51:42 +00002238 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002239 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002240 CurDAG->getTargetConstantPool(ConstantInt::get(
2241 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002242 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002243
2244 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002245 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002246 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002247 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002248 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002249 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002250 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002251 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002252 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002253 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002254 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002255 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002256 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002257 CurDAG->getEntryNode()
2258 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002259 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002260 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002261 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002262 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002263 return NULL;
2264 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002265
Evan Chenga8e29892007-01-19 07:51:42 +00002266 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002267 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002268 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002269 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002270 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002271 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002272 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002273 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00002274 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
2275 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002276 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002277 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2278 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002279 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2280 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2281 CurDAG->getRegister(0, MVT::i32) };
2282 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002283 }
Evan Chenga8e29892007-01-19 07:51:42 +00002284 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002285 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002286 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002287 return I;
2288 break;
2289 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002290 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002291 return I;
2292 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002293 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002294 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002295 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002296 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002297 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002298 if (!RHSV) break;
2299 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002300 unsigned ShImm = Log2_32(RHSV-1);
2301 if (ShImm >= 32)
2302 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002303 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002304 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002305 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2306 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002307 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002308 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002309 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002310 } else {
2311 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002312 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002313 }
Evan Chenga8e29892007-01-19 07:51:42 +00002314 }
2315 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002316 unsigned ShImm = Log2_32(RHSV+1);
2317 if (ShImm >= 32)
2318 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002319 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002320 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002321 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2322 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002323 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002324 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2325 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002326 } else {
2327 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002328 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002329 }
Evan Chenga8e29892007-01-19 07:51:42 +00002330 }
2331 }
2332 break;
Evan Cheng20956592009-10-21 08:15:52 +00002333 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002334 // Check for unsigned bitfield extract
2335 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2336 return I;
2337
Evan Cheng20956592009-10-21 08:15:52 +00002338 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2339 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2340 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2341 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2342 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002343 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002344 if (VT != MVT::i32)
2345 break;
2346 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2347 ? ARM::t2MOVTi16
2348 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2349 if (!Opc)
2350 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002351 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002352 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2353 if (!N1C)
2354 break;
2355 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2356 SDValue N2 = N0.getOperand(1);
2357 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2358 if (!N2C)
2359 break;
2360 unsigned N1CVal = N1C->getZExtValue();
2361 unsigned N2CVal = N2C->getZExtValue();
2362 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2363 (N1CVal & 0xffffU) == 0xffffU &&
2364 (N2CVal & 0xffffU) == 0x0U) {
2365 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2366 MVT::i32);
2367 SDValue Ops[] = { N0.getOperand(0), Imm16,
2368 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2369 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2370 }
2371 }
2372 break;
2373 }
Jim Grosbache5165492009-11-09 00:11:35 +00002374 case ARMISD::VMOVRRD:
2375 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002376 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002377 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002378 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002379 if (Subtarget->isThumb1Only())
2380 break;
2381 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002382 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002383 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2384 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002385 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002386 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002387 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002388 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2389 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002390 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2391 ARM::UMULL : ARM::UMULLv5,
2392 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002393 }
Evan Chengee568cf2007-07-05 07:15:27 +00002394 }
Dan Gohman525178c2007-10-08 18:33:35 +00002395 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002396 if (Subtarget->isThumb1Only())
2397 break;
2398 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002399 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002400 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002401 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002402 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002403 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002404 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2405 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002406 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2407 ARM::SMULL : ARM::SMULLv5,
2408 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002409 }
Evan Chengee568cf2007-07-05 07:15:27 +00002410 }
Evan Chenga8e29892007-01-19 07:51:42 +00002411 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002412 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002413 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002414 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002415 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002416 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002417 if (ResNode)
2418 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002419 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002420 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002421 }
Evan Chengee568cf2007-07-05 07:15:27 +00002422 case ARMISD::BRCOND: {
2423 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2424 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2425 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002426
Evan Chengee568cf2007-07-05 07:15:27 +00002427 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2428 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2429 // Pattern complexity = 6 cost = 1 size = 0
2430
David Goodwin5e47a9a2009-06-30 18:04:13 +00002431 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2432 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2433 // Pattern complexity = 6 cost = 1 size = 0
2434
Jim Grosbach764ab522009-08-11 15:33:49 +00002435 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002436 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002437 SDValue Chain = N->getOperand(0);
2438 SDValue N1 = N->getOperand(1);
2439 SDValue N2 = N->getOperand(2);
2440 SDValue N3 = N->getOperand(3);
2441 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002442 assert(N1.getOpcode() == ISD::BasicBlock);
2443 assert(N2.getOpcode() == ISD::Constant);
2444 assert(N3.getOpcode() == ISD::Register);
2445
Dan Gohman475871a2008-07-27 21:46:04 +00002446 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002447 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002448 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002449 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002450 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002451 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002452 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002453 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002454 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002455 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002456 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002457 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002458 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002459 return NULL;
2460 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002461 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002462 return SelectCMOVOp(N);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002463 case ARMISD::VZIP: {
2464 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002465 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002466 switch (VT.getSimpleVT().SimpleTy) {
2467 default: return NULL;
2468 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2469 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2470 case MVT::v2f32:
2471 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2472 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2473 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2474 case MVT::v4f32:
2475 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2476 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002477 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002478 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2479 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2480 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002481 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002482 case ARMISD::VUZP: {
2483 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002484 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002485 switch (VT.getSimpleVT().SimpleTy) {
2486 default: return NULL;
2487 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2488 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2489 case MVT::v2f32:
2490 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2491 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2492 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2493 case MVT::v4f32:
2494 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2495 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002496 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002497 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2498 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2499 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002500 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002501 case ARMISD::VTRN: {
2502 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002503 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002504 switch (VT.getSimpleVT().SimpleTy) {
2505 default: return NULL;
2506 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2507 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2508 case MVT::v2f32:
2509 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2510 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2511 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2512 case MVT::v4f32:
2513 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2514 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002515 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002516 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2517 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2518 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002519 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002520 case ARMISD::BUILD_VECTOR: {
2521 EVT VecVT = N->getValueType(0);
2522 EVT EltVT = VecVT.getVectorElementType();
2523 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002524 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002525 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2526 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2527 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002528 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002529 if (NumElts == 2)
2530 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2531 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2532 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2533 N->getOperand(2), N->getOperand(3));
2534 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002535
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002536 case ARMISD::VLD2DUP: {
2537 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2538 ARM::VLD2DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002539 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002540 }
2541
Bob Wilson86c6d802010-11-29 19:35:29 +00002542 case ARMISD::VLD3DUP: {
2543 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2544 ARM::VLD3DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002545 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson86c6d802010-11-29 19:35:29 +00002546 }
2547
Bob Wilson6c4c9822010-11-30 00:00:35 +00002548 case ARMISD::VLD4DUP: {
2549 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2550 ARM::VLD4DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002551 return SelectVLDDup(N, false, 4, Opcodes);
2552 }
2553
2554 case ARMISD::VLD2DUP_UPD: {
2555 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo_UPD, ARM::VLD2DUPd16Pseudo_UPD,
2556 ARM::VLD2DUPd32Pseudo_UPD };
2557 return SelectVLDDup(N, true, 2, Opcodes);
2558 }
2559
2560 case ARMISD::VLD3DUP_UPD: {
2561 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD, ARM::VLD3DUPd16Pseudo_UPD,
2562 ARM::VLD3DUPd32Pseudo_UPD };
2563 return SelectVLDDup(N, true, 3, Opcodes);
2564 }
2565
2566 case ARMISD::VLD4DUP_UPD: {
2567 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD, ARM::VLD4DUPd16Pseudo_UPD,
2568 ARM::VLD4DUPd32Pseudo_UPD };
2569 return SelectVLDDup(N, true, 4, Opcodes);
2570 }
2571
2572 case ARMISD::VLD1_UPD: {
2573 unsigned DOpcodes[] = { ARM::VLD1d8_UPD, ARM::VLD1d16_UPD,
2574 ARM::VLD1d32_UPD, ARM::VLD1d64_UPD };
2575 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo_UPD, ARM::VLD1q16Pseudo_UPD,
2576 ARM::VLD1q32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2577 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2578 }
2579
2580 case ARMISD::VLD2_UPD: {
2581 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo_UPD, ARM::VLD2d16Pseudo_UPD,
2582 ARM::VLD2d32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2583 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo_UPD, ARM::VLD2q16Pseudo_UPD,
2584 ARM::VLD2q32Pseudo_UPD };
2585 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2586 }
2587
2588 case ARMISD::VLD3_UPD: {
2589 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo_UPD, ARM::VLD3d16Pseudo_UPD,
2590 ARM::VLD3d32Pseudo_UPD, ARM::VLD1d64TPseudo_UPD };
2591 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2592 ARM::VLD3q16Pseudo_UPD,
2593 ARM::VLD3q32Pseudo_UPD };
2594 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2595 ARM::VLD3q16oddPseudo_UPD,
2596 ARM::VLD3q32oddPseudo_UPD };
2597 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2598 }
2599
2600 case ARMISD::VLD4_UPD: {
2601 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo_UPD, ARM::VLD4d16Pseudo_UPD,
2602 ARM::VLD4d32Pseudo_UPD, ARM::VLD1d64QPseudo_UPD };
2603 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2604 ARM::VLD4q16Pseudo_UPD,
2605 ARM::VLD4q32Pseudo_UPD };
2606 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2607 ARM::VLD4q16oddPseudo_UPD,
2608 ARM::VLD4q32oddPseudo_UPD };
2609 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2610 }
2611
2612 case ARMISD::VLD2LN_UPD: {
2613 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD, ARM::VLD2LNd16Pseudo_UPD,
2614 ARM::VLD2LNd32Pseudo_UPD };
2615 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2616 ARM::VLD2LNq32Pseudo_UPD };
2617 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2618 }
2619
2620 case ARMISD::VLD3LN_UPD: {
2621 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD, ARM::VLD3LNd16Pseudo_UPD,
2622 ARM::VLD3LNd32Pseudo_UPD };
2623 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2624 ARM::VLD3LNq32Pseudo_UPD };
2625 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2626 }
2627
2628 case ARMISD::VLD4LN_UPD: {
2629 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD, ARM::VLD4LNd16Pseudo_UPD,
2630 ARM::VLD4LNd32Pseudo_UPD };
2631 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2632 ARM::VLD4LNq32Pseudo_UPD };
2633 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2634 }
2635
2636 case ARMISD::VST1_UPD: {
2637 unsigned DOpcodes[] = { ARM::VST1d8_UPD, ARM::VST1d16_UPD,
2638 ARM::VST1d32_UPD, ARM::VST1d64_UPD };
2639 unsigned QOpcodes[] = { ARM::VST1q8Pseudo_UPD, ARM::VST1q16Pseudo_UPD,
2640 ARM::VST1q32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2641 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2642 }
2643
2644 case ARMISD::VST2_UPD: {
2645 unsigned DOpcodes[] = { ARM::VST2d8Pseudo_UPD, ARM::VST2d16Pseudo_UPD,
2646 ARM::VST2d32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2647 unsigned QOpcodes[] = { ARM::VST2q8Pseudo_UPD, ARM::VST2q16Pseudo_UPD,
2648 ARM::VST2q32Pseudo_UPD };
2649 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2650 }
2651
2652 case ARMISD::VST3_UPD: {
2653 unsigned DOpcodes[] = { ARM::VST3d8Pseudo_UPD, ARM::VST3d16Pseudo_UPD,
2654 ARM::VST3d32Pseudo_UPD, ARM::VST1d64TPseudo_UPD };
2655 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2656 ARM::VST3q16Pseudo_UPD,
2657 ARM::VST3q32Pseudo_UPD };
2658 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2659 ARM::VST3q16oddPseudo_UPD,
2660 ARM::VST3q32oddPseudo_UPD };
2661 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2662 }
2663
2664 case ARMISD::VST4_UPD: {
2665 unsigned DOpcodes[] = { ARM::VST4d8Pseudo_UPD, ARM::VST4d16Pseudo_UPD,
2666 ARM::VST4d32Pseudo_UPD, ARM::VST1d64QPseudo_UPD };
2667 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2668 ARM::VST4q16Pseudo_UPD,
2669 ARM::VST4q32Pseudo_UPD };
2670 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2671 ARM::VST4q16oddPseudo_UPD,
2672 ARM::VST4q32oddPseudo_UPD };
2673 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2674 }
2675
2676 case ARMISD::VST2LN_UPD: {
2677 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD, ARM::VST2LNd16Pseudo_UPD,
2678 ARM::VST2LNd32Pseudo_UPD };
2679 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2680 ARM::VST2LNq32Pseudo_UPD };
2681 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2682 }
2683
2684 case ARMISD::VST3LN_UPD: {
2685 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD, ARM::VST3LNd16Pseudo_UPD,
2686 ARM::VST3LNd32Pseudo_UPD };
2687 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2688 ARM::VST3LNq32Pseudo_UPD };
2689 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2690 }
2691
2692 case ARMISD::VST4LN_UPD: {
2693 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD, ARM::VST4LNd16Pseudo_UPD,
2694 ARM::VST4LNd32Pseudo_UPD };
2695 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2696 ARM::VST4LNq32Pseudo_UPD };
2697 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson6c4c9822010-11-30 00:00:35 +00002698 }
2699
Bob Wilson31fb12f2009-08-26 17:39:53 +00002700 case ISD::INTRINSIC_VOID:
2701 case ISD::INTRINSIC_W_CHAIN: {
2702 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002703 switch (IntNo) {
2704 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002705 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002706
Bruno Cardoso Lopesa0112d02011-05-28 04:07:29 +00002707 case Intrinsic::arm_ldrexd: {
2708 SDValue MemAddr = N->getOperand(2);
2709 DebugLoc dl = N->getDebugLoc();
2710 SDValue Chain = N->getOperand(0);
2711
2712 unsigned NewOpc = ARM::LDREXD;
2713 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2714 NewOpc = ARM::t2LDREXD;
2715
2716 // arm_ldrexd returns a i64 value in {i32, i32}
2717 std::vector<EVT> ResTys;
2718 ResTys.push_back(MVT::i32);
2719 ResTys.push_back(MVT::i32);
2720 ResTys.push_back(MVT::Other);
2721
2722 // place arguments in the right order
2723 SmallVector<SDValue, 7> Ops;
2724 Ops.push_back(MemAddr);
2725 Ops.push_back(getAL(CurDAG));
2726 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2727 Ops.push_back(Chain);
2728 SDNode *Ld = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
2729 Ops.size());
2730 // Transfer memoperands.
2731 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2732 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2733 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
2734
2735 // Until there's support for specifing explicit register constraints
2736 // like the use of even/odd register pair, hardcode ldrexd to always
2737 // use the pair [R0, R1] to hold the load result.
2738 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R0,
2739 SDValue(Ld, 0), SDValue(0,0));
2740 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R1,
2741 SDValue(Ld, 1), Chain.getValue(1));
2742
2743 // Remap uses.
2744 SDValue Glue = Chain.getValue(1);
2745 if (!SDValue(N, 0).use_empty()) {
2746 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2747 ARM::R0, MVT::i32, Glue);
2748 Glue = Result.getValue(2);
2749 ReplaceUses(SDValue(N, 0), Result);
2750 }
2751 if (!SDValue(N, 1).use_empty()) {
2752 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2753 ARM::R1, MVT::i32, Glue);
2754 Glue = Result.getValue(2);
2755 ReplaceUses(SDValue(N, 1), Result);
2756 }
2757
2758 ReplaceUses(SDValue(N, 2), SDValue(Ld, 2));
2759 return NULL;
2760 }
2761
2762 case Intrinsic::arm_strexd: {
2763 DebugLoc dl = N->getDebugLoc();
2764 SDValue Chain = N->getOperand(0);
2765 SDValue Val0 = N->getOperand(2);
2766 SDValue Val1 = N->getOperand(3);
2767 SDValue MemAddr = N->getOperand(4);
2768
2769 // Until there's support for specifing explicit register constraints
2770 // like the use of even/odd register pair, hardcode strexd to always
2771 // use the pair [R2, R3] to hold the i64 (i32, i32) value to be stored.
2772 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R2, Val0,
2773 SDValue(0, 0));
2774 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R3, Val1, Chain.getValue(1));
2775
2776 SDValue Glue = Chain.getValue(1);
2777 Val0 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2778 ARM::R2, MVT::i32, Glue);
2779 Glue = Val0.getValue(1);
2780 Val1 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2781 ARM::R3, MVT::i32, Glue);
2782
2783 // Store exclusive double return a i32 value which is the return status
2784 // of the issued store.
2785 std::vector<EVT> ResTys;
2786 ResTys.push_back(MVT::i32);
2787 ResTys.push_back(MVT::Other);
2788
2789 // place arguments in the right order
2790 SmallVector<SDValue, 7> Ops;
2791 Ops.push_back(Val0);
2792 Ops.push_back(Val1);
2793 Ops.push_back(MemAddr);
2794 Ops.push_back(getAL(CurDAG));
2795 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2796 Ops.push_back(Chain);
2797
2798 unsigned NewOpc = ARM::STREXD;
2799 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2800 NewOpc = ARM::t2STREXD;
2801
2802 SDNode *St = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
2803 Ops.size());
2804 // Transfer memoperands.
2805 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2806 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2807 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
2808
2809 return St;
2810 }
2811
Bob Wilson621f1952010-03-23 05:25:43 +00002812 case Intrinsic::arm_neon_vld1: {
2813 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2814 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002815 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2816 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002817 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson621f1952010-03-23 05:25:43 +00002818 }
2819
Bob Wilson31fb12f2009-08-26 17:39:53 +00002820 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002821 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2822 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2823 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2824 ARM::VLD2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002825 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002826 }
2827
2828 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002829 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2830 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2831 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2832 ARM::VLD3q16Pseudo_UPD,
2833 ARM::VLD3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002834 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo,
2835 ARM::VLD3q16oddPseudo,
2836 ARM::VLD3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002837 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002838 }
2839
2840 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002841 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2842 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2843 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2844 ARM::VLD4q16Pseudo_UPD,
2845 ARM::VLD4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002846 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo,
2847 ARM::VLD4q16oddPseudo,
2848 ARM::VLD4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002849 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002850 }
2851
Bob Wilson243fcc52009-09-01 04:26:28 +00002852 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002853 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2854 ARM::VLD2LNd32Pseudo };
2855 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002856 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002857 }
2858
2859 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002860 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2861 ARM::VLD3LNd32Pseudo };
2862 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002863 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002864 }
2865
2866 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002867 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2868 ARM::VLD4LNd32Pseudo };
2869 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002870 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002871 }
2872
Bob Wilson11d98992010-03-23 06:20:33 +00002873 case Intrinsic::arm_neon_vst1: {
2874 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2875 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002876 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2877 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002878 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson11d98992010-03-23 06:20:33 +00002879 }
2880
Bob Wilson31fb12f2009-08-26 17:39:53 +00002881 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002882 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2883 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2884 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2885 ARM::VST2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002886 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002887 }
2888
2889 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002890 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2891 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2892 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2893 ARM::VST3q16Pseudo_UPD,
2894 ARM::VST3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002895 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo,
2896 ARM::VST3q16oddPseudo,
2897 ARM::VST3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002898 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002899 }
2900
2901 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002902 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002903 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002904 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2905 ARM::VST4q16Pseudo_UPD,
2906 ARM::VST4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002907 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo,
2908 ARM::VST4q16oddPseudo,
2909 ARM::VST4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002910 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002911 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002912
2913 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002914 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2915 ARM::VST2LNd32Pseudo };
2916 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002917 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002918 }
2919
2920 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002921 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2922 ARM::VST3LNd32Pseudo };
2923 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002924 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002925 }
2926
2927 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002928 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2929 ARM::VST4LNd32Pseudo };
2930 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002931 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002932 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002933 }
Bob Wilson429009b2010-05-06 16:05:26 +00002934 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002935 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002936
Bob Wilsond491d6e2010-07-06 23:36:25 +00002937 case ISD::INTRINSIC_WO_CHAIN: {
2938 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2939 switch (IntNo) {
2940 default:
2941 break;
2942
2943 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002944 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002945 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002946 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002947 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002948 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002949
2950 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002951 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002952 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002953 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002954 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002955 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002956 }
2957 break;
2958 }
2959
Bill Wendling69a05a72011-03-14 23:02:38 +00002960 case ARMISD::VTBL1: {
2961 DebugLoc dl = N->getDebugLoc();
2962 EVT VT = N->getValueType(0);
2963 SmallVector<SDValue, 6> Ops;
2964
2965 Ops.push_back(N->getOperand(0));
2966 Ops.push_back(N->getOperand(1));
2967 Ops.push_back(getAL(CurDAG)); // Predicate
2968 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
2969 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops.data(), Ops.size());
2970 }
2971 case ARMISD::VTBL2: {
2972 DebugLoc dl = N->getDebugLoc();
2973 EVT VT = N->getValueType(0);
2974
2975 // Form a REG_SEQUENCE to force register allocation.
2976 SDValue V0 = N->getOperand(0);
2977 SDValue V1 = N->getOperand(1);
2978 SDValue RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
2979
2980 SmallVector<SDValue, 6> Ops;
2981 Ops.push_back(RegSeq);
2982 Ops.push_back(N->getOperand(2));
2983 Ops.push_back(getAL(CurDAG)); // Predicate
2984 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
2985 return CurDAG->getMachineNode(ARM::VTBL2Pseudo, dl, VT,
2986 Ops.data(), Ops.size());
2987 }
2988
Bob Wilson429009b2010-05-06 16:05:26 +00002989 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002990 return SelectConcatVector(N);
2991 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002992
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002993 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002994}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002995
Bob Wilson224c2442009-05-19 05:53:42 +00002996bool ARMDAGToDAGISel::
2997SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2998 std::vector<SDValue> &OutOps) {
2999 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00003000 // Require the address to be in a register. That is safe for all ARM
3001 // variants and it is hard to do anything much smarter without knowing
3002 // how the operand is used.
3003 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00003004 return false;
3005}
3006
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003007/// createARMISelDag - This pass converts a legalized DAG into a
3008/// ARM-specific DAG, ready for instruction scheduling.
3009///
Bob Wilson522ce972009-09-28 14:30:20 +00003010FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
3011 CodeGenOpt::Level OptLevel) {
3012 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003013}