blob: 2c9481b86c557830fd6f195a8f81fdd16cad0857 [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"
Evan Chenge5ad88e2008-12-10 21:54:21 +000017#include "ARMAddressingModes.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000018#include "ARMTargetMachine.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 Cheng055b0312009-06-29 07:51:04 +0000376 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
377
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;
Jim Grosbach3e556122010-10-26 22:37:02 +0000492 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
493 unsigned ShAmt = 0;
494
495 Base = N.getOperand(0);
496 Offset = N.getOperand(1);
497
498 if (ShOpcVal != ARM_AM::no_shift) {
499 // Check to see if the RHS of the shift is a constant, if not, we can't fold
500 // it.
501 if (ConstantSDNode *Sh =
502 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
503 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000504 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
505 Offset = N.getOperand(1).getOperand(0);
506 else {
507 ShAmt = 0;
508 ShOpcVal = ARM_AM::no_shift;
509 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000510 } else {
511 ShOpcVal = ARM_AM::no_shift;
512 }
513 }
514
515 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000516 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000517 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000518 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
519 if (ShOpcVal != ARM_AM::no_shift) {
520 // Check to see if the RHS of the shift is a constant, if not, we can't
521 // fold it.
522 if (ConstantSDNode *Sh =
523 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
524 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000525 if (!Subtarget->isCortexA9() ||
526 (N.hasOneUse() &&
527 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
528 Offset = N.getOperand(0).getOperand(0);
529 Base = N.getOperand(1);
530 } else {
531 ShAmt = 0;
532 ShOpcVal = ARM_AM::no_shift;
533 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000534 } else {
535 ShOpcVal = ARM_AM::no_shift;
536 }
537 }
538 }
539
540 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
541 MVT::i32);
542 return true;
543}
544
545
546
547
548//-----
549
Jim Grosbach82891622010-09-29 19:03:54 +0000550AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
551 SDValue &Base,
552 SDValue &Offset,
553 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000554 if (N.getOpcode() == ISD::MUL &&
555 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000556 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
557 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000558 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000559 if (RHSC & 1) {
560 RHSC = RHSC & ~1;
561 ARM_AM::AddrOpc AddSub = ARM_AM::add;
562 if (RHSC < 0) {
563 AddSub = ARM_AM::sub;
564 RHSC = - RHSC;
565 }
566 if (isPowerOf2_32(RHSC)) {
567 unsigned ShAmt = Log2_32(RHSC);
568 Base = Offset = N.getOperand(0);
569 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
570 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000571 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000572 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000573 }
574 }
575 }
576 }
577
Chris Lattner0a9481f2011-02-13 22:25:43 +0000578 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
579 // ISD::OR that is equivalent to an ADD.
580 !CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000581 Base = N;
582 if (N.getOpcode() == ISD::FrameIndex) {
583 int FI = cast<FrameIndexSDNode>(N)->getIndex();
584 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000585 } else if (N.getOpcode() == ARMISD::Wrapper &&
586 !(Subtarget->useMovt() &&
587 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000588 Base = N.getOperand(0);
589 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000590 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000591 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
592 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000593 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000594 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000595 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000596
Evan Chenga8e29892007-01-19 07:51:42 +0000597 // Match simple R +/- imm12 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000598 if (N.getOpcode() != ISD::SUB) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000599 int RHSC;
600 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
601 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
602 Base = N.getOperand(0);
603 if (Base.getOpcode() == ISD::FrameIndex) {
604 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
605 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000606 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000607 Offset = CurDAG->getRegister(0, MVT::i32);
608
609 ARM_AM::AddrOpc AddSub = ARM_AM::add;
610 if (RHSC < 0) {
611 AddSub = ARM_AM::sub;
612 RHSC = - RHSC;
613 }
614 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
615 ARM_AM::no_shift),
616 MVT::i32);
617 return AM2_BASE;
Evan Chenga8e29892007-01-19 07:51:42 +0000618 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000619 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000620
Evan Chengf40deed2010-10-27 23:41:30 +0000621 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
622 // Compute R +/- (R << N) and reuse it.
623 Base = N;
624 Offset = CurDAG->getRegister(0, MVT::i32);
625 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
626 ARM_AM::no_shift),
627 MVT::i32);
628 return AM2_BASE;
629 }
630
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000631 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000632 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chenga8e29892007-01-19 07:51:42 +0000633 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
634 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000635
Evan Chenga8e29892007-01-19 07:51:42 +0000636 Base = N.getOperand(0);
637 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000638
Evan Chenga8e29892007-01-19 07:51:42 +0000639 if (ShOpcVal != ARM_AM::no_shift) {
640 // Check to see if the RHS of the shift is a constant, if not, we can't fold
641 // it.
642 if (ConstantSDNode *Sh =
643 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000644 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000645 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
646 Offset = N.getOperand(1).getOperand(0);
647 else {
648 ShAmt = 0;
649 ShOpcVal = ARM_AM::no_shift;
650 }
Evan Chenga8e29892007-01-19 07:51:42 +0000651 } else {
652 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000653 }
654 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000655
Evan Chenga8e29892007-01-19 07:51:42 +0000656 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000657 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000658 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chenga8e29892007-01-19 07:51:42 +0000659 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
660 if (ShOpcVal != ARM_AM::no_shift) {
661 // Check to see if the RHS of the shift is a constant, if not, we can't
662 // fold it.
663 if (ConstantSDNode *Sh =
664 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000665 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000666 if (!Subtarget->isCortexA9() ||
667 (N.hasOneUse() &&
668 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
669 Offset = N.getOperand(0).getOperand(0);
670 Base = N.getOperand(1);
671 } else {
672 ShAmt = 0;
673 ShOpcVal = ARM_AM::no_shift;
674 }
Evan Chenga8e29892007-01-19 07:51:42 +0000675 } else {
676 ShOpcVal = ARM_AM::no_shift;
677 }
678 }
679 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000680
Evan Chenga8e29892007-01-19 07:51:42 +0000681 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000682 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000683 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000684}
685
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000686bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000687 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000688 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000689 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
690 ? cast<LoadSDNode>(Op)->getAddressingMode()
691 : cast<StoreSDNode>(Op)->getAddressingMode();
692 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
693 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000694 int Val;
695 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
696 Offset = CurDAG->getRegister(0, MVT::i32);
697 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
698 ARM_AM::no_shift),
699 MVT::i32);
700 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000701 }
702
703 Offset = N;
704 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
705 unsigned ShAmt = 0;
706 if (ShOpcVal != ARM_AM::no_shift) {
707 // Check to see if the RHS of the shift is a constant, if not, we can't fold
708 // it.
709 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000710 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000711 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
712 Offset = N.getOperand(0);
713 else {
714 ShAmt = 0;
715 ShOpcVal = ARM_AM::no_shift;
716 }
Evan Chenga8e29892007-01-19 07:51:42 +0000717 } else {
718 ShOpcVal = ARM_AM::no_shift;
719 }
720 }
721
722 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000723 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000724 return true;
725}
726
Evan Chenga8e29892007-01-19 07:51:42 +0000727
Chris Lattner52a261b2010-09-21 20:31:19 +0000728bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000729 SDValue &Base, SDValue &Offset,
730 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000731 if (N.getOpcode() == ISD::SUB) {
732 // X - C is canonicalize to X + -C, no need to handle it here.
733 Base = N.getOperand(0);
734 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000735 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000736 return true;
737 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000738
Chris Lattner0a9481f2011-02-13 22:25:43 +0000739 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000740 Base = N;
741 if (N.getOpcode() == ISD::FrameIndex) {
742 int FI = cast<FrameIndexSDNode>(N)->getIndex();
743 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
744 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000745 Offset = CurDAG->getRegister(0, MVT::i32);
746 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000747 return true;
748 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000749
Evan Chenga8e29892007-01-19 07:51:42 +0000750 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000751 int RHSC;
752 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
753 -256 + 1, 256, RHSC)) { // 8 bits.
754 Base = N.getOperand(0);
755 if (Base.getOpcode() == ISD::FrameIndex) {
756 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
757 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000758 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000759 Offset = CurDAG->getRegister(0, MVT::i32);
760
761 ARM_AM::AddrOpc AddSub = ARM_AM::add;
762 if (RHSC < 0) {
763 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000764 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000765 }
766 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
767 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000768 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000769
Evan Chenga8e29892007-01-19 07:51:42 +0000770 Base = N.getOperand(0);
771 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000772 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000773 return true;
774}
775
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000776bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000777 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000778 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000779 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
780 ? cast<LoadSDNode>(Op)->getAddressingMode()
781 : cast<StoreSDNode>(Op)->getAddressingMode();
782 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
783 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000784 int Val;
785 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
786 Offset = CurDAG->getRegister(0, MVT::i32);
787 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
788 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000789 }
790
791 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000792 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000793 return true;
794}
795
Jim Grosbach3ab56582010-10-21 19:38:40 +0000796bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000797 SDValue &Base, SDValue &Offset) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000798 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000799 Base = N;
800 if (N.getOpcode() == ISD::FrameIndex) {
801 int FI = cast<FrameIndexSDNode>(N)->getIndex();
802 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000803 } else if (N.getOpcode() == ARMISD::Wrapper &&
804 !(Subtarget->useMovt() &&
805 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000806 Base = N.getOperand(0);
807 }
808 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000809 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000810 return true;
811 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000812
Evan Chenga8e29892007-01-19 07:51:42 +0000813 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000814 int RHSC;
815 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
816 -256 + 1, 256, RHSC)) {
817 Base = N.getOperand(0);
818 if (Base.getOpcode() == ISD::FrameIndex) {
819 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
820 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000821 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000822
823 ARM_AM::AddrOpc AddSub = ARM_AM::add;
824 if (RHSC < 0) {
825 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000826 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000827 }
828 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
829 MVT::i32);
830 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000831 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000832
Evan Chenga8e29892007-01-19 07:51:42 +0000833 Base = N;
834 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000835 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000836 return true;
837}
838
Bob Wilson665814b2010-11-01 23:40:51 +0000839bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
840 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000841 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000842
843 unsigned Alignment = 0;
844 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
845 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
846 // The maximum alignment is equal to the memory size being referenced.
847 unsigned LSNAlign = LSN->getAlignment();
848 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
849 if (LSNAlign > MemSize && MemSize > 1)
850 Alignment = MemSize;
851 } else {
852 // All other uses of addrmode6 are for intrinsics. For now just record
853 // the raw alignment value; it will be refined later based on the legal
854 // alignment operands for the intrinsic.
855 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
856 }
857
858 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000859 return true;
860}
861
Bob Wilsonda525062011-02-25 06:42:42 +0000862bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
863 SDValue &Offset) {
864 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
865 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
866 if (AM != ISD::POST_INC)
867 return false;
868 Offset = N;
869 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
870 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
871 Offset = CurDAG->getRegister(0, MVT::i32);
872 }
873 return true;
874}
875
Chris Lattner52a261b2010-09-21 20:31:19 +0000876bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000877 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000878 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
879 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000880 SDValue N1 = N.getOperand(1);
Evan Cheng9fe20092011-01-20 08:34:58 +0000881 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
882 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000883 return true;
884 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000885
Evan Chenga8e29892007-01-19 07:51:42 +0000886 return false;
887}
888
Bill Wendlingf4caf692010-12-14 03:36:38 +0000889
890//===----------------------------------------------------------------------===//
891// Thumb Addressing Modes
892//===----------------------------------------------------------------------===//
893
Chris Lattner52a261b2010-09-21 20:31:19 +0000894bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000895 SDValue &Base, SDValue &Offset){
Chris Lattner0a9481f2011-02-13 22:25:43 +0000896 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000897 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000898 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000899 return false;
900
901 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000902 return true;
903 }
904
Evan Chenga8e29892007-01-19 07:51:42 +0000905 Base = N.getOperand(0);
906 Offset = N.getOperand(1);
907 return true;
908}
909
Evan Cheng79d43262007-01-24 02:21:22 +0000910bool
Bill Wendlingf4caf692010-12-14 03:36:38 +0000911ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
912 SDValue &Offset, unsigned Scale) {
Evan Cheng79d43262007-01-24 02:21:22 +0000913 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000914 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000915 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000916 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendlingf4caf692010-12-14 03:36:38 +0000917
Evan Cheng012f2d92007-01-24 08:53:17 +0000918 if (N.getOpcode() == ARMISD::Wrapper &&
919 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
920 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000921 }
922
Chris Lattner0a9481f2011-02-13 22:25:43 +0000923 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000924 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000925
Evan Chengad0e4652007-02-06 00:22:06 +0000926 // Thumb does not have [sp, r] address mode.
927 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
928 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
929 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000930 (RHSR && RHSR->getReg() == ARM::SP))
931 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000932
Daniel Dunbarec91d522011-01-19 15:12:16 +0000933 // FIXME: Why do we explicitly check for a match here and then return false?
934 // Presumably to allow something else to match, but shouldn't this be
935 // documented?
936 int RHSC;
937 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
938 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000939
940 Base = N.getOperand(0);
941 Offset = N.getOperand(1);
942 return true;
943}
944
945bool
946ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
947 SDValue &Base,
948 SDValue &Offset) {
949 return SelectThumbAddrModeRI(N, Base, Offset, 1);
950}
951
952bool
953ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
954 SDValue &Base,
955 SDValue &Offset) {
956 return SelectThumbAddrModeRI(N, Base, Offset, 2);
957}
958
959bool
960ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
961 SDValue &Base,
962 SDValue &Offset) {
963 return SelectThumbAddrModeRI(N, Base, Offset, 4);
964}
965
966bool
967ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
968 SDValue &Base, SDValue &OffImm) {
969 if (Scale == 4) {
970 SDValue TmpBase, TmpOffImm;
971 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
972 return false; // We want to select tLDRspi / tSTRspi instead.
973
974 if (N.getOpcode() == ARMISD::Wrapper &&
975 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
976 return false; // We want to select tLDRpci instead.
977 }
978
Chris Lattner0a9481f2011-02-13 22:25:43 +0000979 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000980 if (N.getOpcode() == ARMISD::Wrapper &&
981 !(Subtarget->useMovt() &&
982 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
983 Base = N.getOperand(0);
984 } else {
985 Base = N;
986 }
987
Owen Anderson825b72b2009-08-11 20:47:22 +0000988 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000989 return true;
990 }
991
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000992 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
993 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
994 if ((LHSR && LHSR->getReg() == ARM::SP) ||
995 (RHSR && RHSR->getReg() == ARM::SP)) {
996 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
997 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
998 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
999 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1000
1001 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1002 if (LHSC != 0 || RHSC != 0) return false;
1003
1004 Base = N;
1005 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1006 return true;
1007 }
1008
Evan Chenga8e29892007-01-19 07:51:42 +00001009 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001010 int RHSC;
1011 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1012 Base = N.getOperand(0);
1013 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1014 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001015 }
1016
Evan Chengc38f2bc2007-01-23 22:59:13 +00001017 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001018 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +00001019 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001020}
1021
Bill Wendlingf4caf692010-12-14 03:36:38 +00001022bool
1023ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1024 SDValue &OffImm) {
1025 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001026}
1027
Bill Wendlingf4caf692010-12-14 03:36:38 +00001028bool
1029ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1030 SDValue &OffImm) {
1031 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001032}
1033
Bill Wendlingf4caf692010-12-14 03:36:38 +00001034bool
1035ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1036 SDValue &OffImm) {
1037 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001038}
1039
Chris Lattner52a261b2010-09-21 20:31:19 +00001040bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1041 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +00001042 if (N.getOpcode() == ISD::FrameIndex) {
1043 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1044 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001045 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001046 return true;
1047 }
Evan Cheng79d43262007-01-24 02:21:22 +00001048
Chris Lattner0a9481f2011-02-13 22:25:43 +00001049 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Chengad0e4652007-02-06 00:22:06 +00001050 return false;
1051
1052 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001053 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1054 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +00001055 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001056 int RHSC;
1057 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1058 Base = N.getOperand(0);
1059 if (Base.getOpcode() == ISD::FrameIndex) {
1060 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1061 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng79d43262007-01-24 02:21:22 +00001062 }
Daniel Dunbarec91d522011-01-19 15:12:16 +00001063 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1064 return true;
Evan Cheng79d43262007-01-24 02:21:22 +00001065 }
1066 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001067
Evan Chenga8e29892007-01-19 07:51:42 +00001068 return false;
1069}
1070
Bill Wendlingf4caf692010-12-14 03:36:38 +00001071
1072//===----------------------------------------------------------------------===//
1073// Thumb 2 Addressing Modes
1074//===----------------------------------------------------------------------===//
1075
1076
Chris Lattner52a261b2010-09-21 20:31:19 +00001077bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001078 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001079 if (DisableShifterOp)
1080 return false;
1081
Evan Cheng9cb9e672009-06-27 02:26:13 +00001082 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
1083
1084 // Don't match base register only case. That is matched to a separate
1085 // lower complexity pattern with explicit register operand.
1086 if (ShOpcVal == ARM_AM::no_shift) return false;
1087
1088 BaseReg = N.getOperand(0);
1089 unsigned ShImmVal = 0;
1090 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1091 ShImmVal = RHS->getZExtValue() & 31;
1092 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1093 return true;
1094 }
1095
1096 return false;
1097}
1098
Chris Lattner52a261b2010-09-21 20:31:19 +00001099bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001100 SDValue &Base, SDValue &OffImm) {
1101 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001102
Evan Cheng3a214252009-08-11 08:52:18 +00001103 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001104 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1105 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001106 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +00001107 // Match frame index.
David Goodwin31e7eba2009-07-20 15:55:39 +00001108 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1109 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001110 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001111 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +00001112 }
Owen Anderson099e5552011-03-18 19:46:58 +00001113
Chris Lattner0a9481f2011-02-13 22:25:43 +00001114 if (N.getOpcode() == ARMISD::Wrapper &&
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001115 !(Subtarget->useMovt() &&
1116 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +00001117 Base = N.getOperand(0);
1118 if (Base.getOpcode() == ISD::TargetConstantPool)
1119 return false; // We want to select t2LDRpci instead.
1120 } else
1121 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001122 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001123 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +00001124 }
Evan Cheng055b0312009-06-29 07:51:04 +00001125
1126 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +00001127 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +00001128 // Let t2LDRi8 handle (R - imm8).
1129 return false;
1130
Evan Cheng055b0312009-06-29 07:51:04 +00001131 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +00001132 if (N.getOpcode() == ISD::SUB)
1133 RHSC = -RHSC;
1134
1135 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001136 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001137 if (Base.getOpcode() == ISD::FrameIndex) {
1138 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1139 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1140 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001141 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001142 return true;
1143 }
1144 }
1145
Evan Cheng3a214252009-08-11 08:52:18 +00001146 // Base only.
1147 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001148 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001149 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001150}
1151
Chris Lattner52a261b2010-09-21 20:31:19 +00001152bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001153 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001154 // Match simple R - imm8 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001155 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1156 !CurDAG->isBaseWithConstantOffset(N))
1157 return false;
Owen Anderson099e5552011-03-18 19:46:58 +00001158
Chris Lattner0a9481f2011-02-13 22:25:43 +00001159 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1160 int RHSC = (int)RHS->getSExtValue();
1161 if (N.getOpcode() == ISD::SUB)
1162 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001163
Chris Lattner0a9481f2011-02-13 22:25:43 +00001164 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1165 Base = N.getOperand(0);
1166 if (Base.getOpcode() == ISD::FrameIndex) {
1167 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1168 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng055b0312009-06-29 07:51:04 +00001169 }
Chris Lattner0a9481f2011-02-13 22:25:43 +00001170 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1171 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001172 }
1173 }
1174
1175 return false;
1176}
1177
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001178bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001179 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001180 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001181 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1182 ? cast<LoadSDNode>(Op)->getAddressingMode()
1183 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbarec91d522011-01-19 15:12:16 +00001184 int RHSC;
1185 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1186 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1187 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1188 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1189 return true;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001190 }
1191
1192 return false;
1193}
1194
Chris Lattner52a261b2010-09-21 20:31:19 +00001195bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001196 SDValue &Base,
1197 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001198 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001199 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng3a214252009-08-11 08:52:18 +00001200 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001201
Evan Cheng3a214252009-08-11 08:52:18 +00001202 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1203 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1204 int RHSC = (int)RHS->getZExtValue();
1205 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1206 return false;
1207 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001208 return false;
1209 }
1210
Evan Chengf40deed2010-10-27 23:41:30 +00001211 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
1212 // Compute R + (R << [1,2,3]) and reuse it.
1213 Base = N;
1214 return false;
1215 }
1216
Evan Cheng055b0312009-06-29 07:51:04 +00001217 // Look for (R + R) or (R + (R << [1,2,3])).
1218 unsigned ShAmt = 0;
1219 Base = N.getOperand(0);
1220 OffReg = N.getOperand(1);
1221
1222 // Swap if it is ((R << c) + R).
1223 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
1224 if (ShOpcVal != ARM_AM::lsl) {
1225 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
1226 if (ShOpcVal == ARM_AM::lsl)
1227 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001228 }
1229
Evan Cheng055b0312009-06-29 07:51:04 +00001230 if (ShOpcVal == ARM_AM::lsl) {
1231 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1232 // it.
1233 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1234 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001235 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1236 OffReg = OffReg.getOperand(0);
1237 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001238 ShAmt = 0;
1239 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001240 }
Evan Cheng055b0312009-06-29 07:51:04 +00001241 } else {
1242 ShOpcVal = ARM_AM::no_shift;
1243 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001244 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001245
Owen Anderson825b72b2009-08-11 20:47:22 +00001246 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001247
1248 return true;
1249}
1250
1251//===--------------------------------------------------------------------===//
1252
Evan Chengee568cf2007-07-05 07:15:27 +00001253/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001254static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001255 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001256}
1257
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001258SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1259 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001260 ISD::MemIndexedMode AM = LD->getAddressingMode();
1261 if (AM == ISD::UNINDEXED)
1262 return NULL;
1263
Owen Andersone50ed302009-08-10 22:56:29 +00001264 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001265 SDValue Offset, AMOpc;
1266 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1267 unsigned Opcode = 0;
1268 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +00001269 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001270 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001271 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
1272 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +00001273 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001274 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001275 Match = true;
1276 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1277 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1278 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001279 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001280 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001281 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001282 Match = true;
1283 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1284 }
1285 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001286 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001287 Match = true;
1288 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
1289 }
1290 }
1291 }
1292
1293 if (Match) {
1294 SDValue Chain = LD->getChain();
1295 SDValue Base = LD->getBasePtr();
1296 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001297 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001298 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001299 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +00001300 }
1301
1302 return NULL;
1303}
1304
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001305SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1306 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001307 ISD::MemIndexedMode AM = LD->getAddressingMode();
1308 if (AM == ISD::UNINDEXED)
1309 return NULL;
1310
Owen Andersone50ed302009-08-10 22:56:29 +00001311 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001312 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001313 SDValue Offset;
1314 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1315 unsigned Opcode = 0;
1316 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001317 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001318 switch (LoadedVT.getSimpleVT().SimpleTy) {
1319 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001320 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1321 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001322 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001323 if (isSExtLd)
1324 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1325 else
1326 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001327 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001328 case MVT::i8:
1329 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001330 if (isSExtLd)
1331 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1332 else
1333 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001334 break;
1335 default:
1336 return NULL;
1337 }
1338 Match = true;
1339 }
1340
1341 if (Match) {
1342 SDValue Chain = LD->getChain();
1343 SDValue Base = LD->getBasePtr();
1344 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001345 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001346 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001347 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001348 }
1349
1350 return NULL;
1351}
1352
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001353/// PairSRegs - Form a D register from a pair of S registers.
1354///
1355SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1356 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001357 SDValue RegClass =
1358 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001359 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1360 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001361 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1362 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001363}
1364
Evan Cheng603afbf2010-05-10 17:34:18 +00001365/// PairDRegs - Form a quad register from a pair of D registers.
1366///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001367SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1368 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001369 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001370 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1371 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001372 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1373 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001374}
1375
Evan Cheng7f687192010-05-14 00:21:45 +00001376/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001377///
1378SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1379 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001380 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001381 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1382 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001383 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1384 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Evan Cheng603afbf2010-05-10 17:34:18 +00001385}
1386
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001387/// QuadSRegs - Form 4 consecutive S registers.
1388///
1389SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1390 SDValue V2, SDValue V3) {
1391 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001392 SDValue RegClass =
1393 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001394 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1395 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1396 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1397 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001398 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1399 V2, SubReg2, V3, SubReg3 };
1400 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001401}
1402
Evan Cheng7f687192010-05-14 00:21:45 +00001403/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001404///
1405SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1406 SDValue V2, SDValue V3) {
1407 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001408 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001409 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1410 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1411 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1412 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001413 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1414 V2, SubReg2, V3, SubReg3 };
1415 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng603afbf2010-05-10 17:34:18 +00001416}
1417
Evan Cheng8f6de382010-05-16 03:27:48 +00001418/// QuadQRegs - Form 4 consecutive Q registers.
1419///
1420SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1421 SDValue V2, SDValue V3) {
1422 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001423 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001424 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1425 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1426 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1427 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001428 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1429 V2, SubReg2, V3, SubReg3 };
1430 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng8f6de382010-05-16 03:27:48 +00001431}
1432
Bob Wilson2a6e6162010-09-23 23:42:37 +00001433/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1434/// of a NEON VLD or VST instruction. The supported values depend on the
1435/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001436SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1437 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001438 unsigned NumRegs = NumVecs;
1439 if (!is64BitVector && NumVecs < 3)
1440 NumRegs *= 2;
1441
Bob Wilson665814b2010-11-01 23:40:51 +00001442 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001443 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001444 Alignment = 32;
1445 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1446 Alignment = 16;
1447 else if (Alignment >= 8)
1448 Alignment = 8;
1449 else
1450 Alignment = 0;
1451
1452 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001453}
1454
Bob Wilson1c3ef902011-02-07 17:43:21 +00001455SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001456 unsigned *DOpcodes, unsigned *QOpcodes0,
1457 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001458 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001459 DebugLoc dl = N->getDebugLoc();
1460
Bob Wilson226036e2010-03-20 22:13:40 +00001461 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001462 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1463 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001464 return NULL;
1465
1466 SDValue Chain = N->getOperand(0);
1467 EVT VT = N->getValueType(0);
1468 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001469 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001470
Bob Wilson3e36f132009-10-14 17:28:52 +00001471 unsigned OpcodeIndex;
1472 switch (VT.getSimpleVT().SimpleTy) {
1473 default: llvm_unreachable("unhandled vld type");
1474 // Double-register operations:
1475 case MVT::v8i8: OpcodeIndex = 0; break;
1476 case MVT::v4i16: OpcodeIndex = 1; break;
1477 case MVT::v2f32:
1478 case MVT::v2i32: OpcodeIndex = 2; break;
1479 case MVT::v1i64: OpcodeIndex = 3; break;
1480 // Quad-register operations:
1481 case MVT::v16i8: OpcodeIndex = 0; break;
1482 case MVT::v8i16: OpcodeIndex = 1; break;
1483 case MVT::v4f32:
1484 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001485 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001486 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001487 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001488 }
1489
Bob Wilsonf5721912010-09-03 18:16:02 +00001490 EVT ResTy;
1491 if (NumVecs == 1)
1492 ResTy = VT;
1493 else {
1494 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1495 if (!is64BitVector)
1496 ResTyElts *= 2;
1497 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1498 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001499 std::vector<EVT> ResTys;
1500 ResTys.push_back(ResTy);
1501 if (isUpdating)
1502 ResTys.push_back(MVT::i32);
1503 ResTys.push_back(MVT::Other);
Bob Wilsonf5721912010-09-03 18:16:02 +00001504
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001505 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001506 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001507 SDNode *VLd;
1508 SmallVector<SDValue, 7> Ops;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001509
Bob Wilson1c3ef902011-02-07 17:43:21 +00001510 // Double registers and VLD1/VLD2 quad registers are directly supported.
1511 if (is64BitVector || NumVecs <= 2) {
1512 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1513 QOpcodes0[OpcodeIndex]);
1514 Ops.push_back(MemAddr);
1515 Ops.push_back(Align);
1516 if (isUpdating) {
1517 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1518 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001519 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001520 Ops.push_back(Pred);
1521 Ops.push_back(Reg0);
1522 Ops.push_back(Chain);
1523 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonffde0802010-09-02 16:00:54 +00001524
Bob Wilson3e36f132009-10-14 17:28:52 +00001525 } else {
1526 // Otherwise, quad registers are loaded with two separate instructions,
1527 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001528 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001529
Bob Wilson1c3ef902011-02-07 17:43:21 +00001530 // Load the even subregs. This is always an updating load, so that it
1531 // provides the address to the second load for the odd subregs.
Bob Wilsonf5721912010-09-03 18:16:02 +00001532 SDValue ImplDef =
1533 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1534 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilson7de68142011-02-07 17:43:15 +00001535 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1536 ResTy, AddrTy, MVT::Other, OpsA, 7);
Bob Wilsonf5721912010-09-03 18:16:02 +00001537 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001538
Bob Wilson24f995d2009-10-14 18:32:29 +00001539 // Load the odd subregs.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001540 Ops.push_back(SDValue(VLdA, 1));
1541 Ops.push_back(Align);
1542 if (isUpdating) {
1543 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1544 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1545 "only constant post-increment update allowed for VLD3/4");
1546 (void)Inc;
1547 Ops.push_back(Reg0);
1548 }
1549 Ops.push_back(SDValue(VLdA, 0));
1550 Ops.push_back(Pred);
1551 Ops.push_back(Reg0);
1552 Ops.push_back(Chain);
1553 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1554 Ops.data(), Ops.size());
Bob Wilsonf5721912010-09-03 18:16:02 +00001555 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001556
Evan Chengb58a3402011-04-19 00:04:03 +00001557 // Transfer memoperands.
1558 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1559 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1560 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1561
Bob Wilson1c3ef902011-02-07 17:43:21 +00001562 if (NumVecs == 1)
1563 return VLd;
1564
1565 // Extract out the subregisters.
1566 SDValue SuperReg = SDValue(VLd, 0);
1567 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1568 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1569 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1570 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1571 ReplaceUses(SDValue(N, Vec),
1572 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1573 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1574 if (isUpdating)
1575 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson3e36f132009-10-14 17:28:52 +00001576 return NULL;
1577}
1578
Bob Wilson1c3ef902011-02-07 17:43:21 +00001579SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001580 unsigned *DOpcodes, unsigned *QOpcodes0,
1581 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001582 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001583 DebugLoc dl = N->getDebugLoc();
1584
Bob Wilson226036e2010-03-20 22:13:40 +00001585 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001586 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1587 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1588 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001589 return NULL;
1590
Evan Chengb58a3402011-04-19 00:04:03 +00001591 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1592 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1593
Bob Wilson24f995d2009-10-14 18:32:29 +00001594 SDValue Chain = N->getOperand(0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001595 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson24f995d2009-10-14 18:32:29 +00001596 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001597 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001598
Bob Wilson24f995d2009-10-14 18:32:29 +00001599 unsigned OpcodeIndex;
1600 switch (VT.getSimpleVT().SimpleTy) {
1601 default: llvm_unreachable("unhandled vst type");
1602 // Double-register operations:
1603 case MVT::v8i8: OpcodeIndex = 0; break;
1604 case MVT::v4i16: OpcodeIndex = 1; break;
1605 case MVT::v2f32:
1606 case MVT::v2i32: OpcodeIndex = 2; break;
1607 case MVT::v1i64: OpcodeIndex = 3; break;
1608 // Quad-register operations:
1609 case MVT::v16i8: OpcodeIndex = 0; break;
1610 case MVT::v8i16: OpcodeIndex = 1; break;
1611 case MVT::v4f32:
1612 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001613 case MVT::v2i64: OpcodeIndex = 3;
1614 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1615 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001616 }
1617
Bob Wilson1c3ef902011-02-07 17:43:21 +00001618 std::vector<EVT> ResTys;
1619 if (isUpdating)
1620 ResTys.push_back(MVT::i32);
1621 ResTys.push_back(MVT::Other);
1622
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001623 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001624 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001625 SmallVector<SDValue, 7> Ops;
Evan Chengac0869d2009-11-21 06:21:52 +00001626
Bob Wilson1c3ef902011-02-07 17:43:21 +00001627 // Double registers and VST1/VST2 quad registers are directly supported.
1628 if (is64BitVector || NumVecs <= 2) {
Bob Wilson7de68142011-02-07 17:43:15 +00001629 SDValue SrcReg;
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001630 if (NumVecs == 1) {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001631 SrcReg = N->getOperand(Vec0Idx);
1632 } else if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001633 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001634 SDValue V0 = N->getOperand(Vec0Idx + 0);
1635 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001636 if (NumVecs == 2)
Bob Wilson7de68142011-02-07 17:43:15 +00001637 SrcReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001638 else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001639 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson7de68142011-02-07 17:43:15 +00001640 // If it's a vst3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001641 // an undef.
1642 SDValue V3 = (NumVecs == 3)
1643 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001644 : N->getOperand(Vec0Idx + 3);
Bob Wilson7de68142011-02-07 17:43:15 +00001645 SrcReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001646 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001647 } else {
1648 // Form a QQ register.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001649 SDValue Q0 = N->getOperand(Vec0Idx);
1650 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Bob Wilson7de68142011-02-07 17:43:15 +00001651 SrcReg = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
Bob Wilson24f995d2009-10-14 18:32:29 +00001652 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001653
1654 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1655 QOpcodes0[OpcodeIndex]);
1656 Ops.push_back(MemAddr);
1657 Ops.push_back(Align);
1658 if (isUpdating) {
1659 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1660 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1661 }
1662 Ops.push_back(SrcReg);
1663 Ops.push_back(Pred);
1664 Ops.push_back(Reg0);
1665 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001666 SDNode *VSt =
1667 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
1668
1669 // Transfer memoperands.
1670 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
1671
1672 return VSt;
Bob Wilson24f995d2009-10-14 18:32:29 +00001673 }
1674
1675 // Otherwise, quad registers are stored with two separate instructions,
1676 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001677
Bob Wilson07f6e802010-06-16 21:34:01 +00001678 // Form the QQQQ REG_SEQUENCE.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001679 SDValue V0 = N->getOperand(Vec0Idx + 0);
1680 SDValue V1 = N->getOperand(Vec0Idx + 1);
1681 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001682 SDValue V3 = (NumVecs == 3)
1683 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001684 : N->getOperand(Vec0Idx + 3);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001685 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001686
Bob Wilson1c3ef902011-02-07 17:43:21 +00001687 // Store the even D registers. This is always an updating store, so that it
1688 // provides the address to the second store for the odd subregs.
Bob Wilson7de68142011-02-07 17:43:15 +00001689 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1690 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1691 MemAddr.getValueType(),
1692 MVT::Other, OpsA, 7);
Evan Chengb58a3402011-04-19 00:04:03 +00001693 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson07f6e802010-06-16 21:34:01 +00001694 Chain = SDValue(VStA, 1);
1695
1696 // Store the odd D registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001697 Ops.push_back(SDValue(VStA, 0));
1698 Ops.push_back(Align);
1699 if (isUpdating) {
1700 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1701 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1702 "only constant post-increment update allowed for VST3/4");
1703 (void)Inc;
1704 Ops.push_back(Reg0);
1705 }
1706 Ops.push_back(RegSeq);
1707 Ops.push_back(Pred);
1708 Ops.push_back(Reg0);
1709 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001710 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1711 Ops.data(), Ops.size());
1712 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
1713 return VStB;
Bob Wilson24f995d2009-10-14 18:32:29 +00001714}
1715
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001716SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson1c3ef902011-02-07 17:43:21 +00001717 bool isUpdating, unsigned NumVecs,
1718 unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001719 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001720 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001721 DebugLoc dl = N->getDebugLoc();
1722
Bob Wilson226036e2010-03-20 22:13:40 +00001723 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001724 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1725 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1726 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001727 return NULL;
1728
Evan Chengb58a3402011-04-19 00:04:03 +00001729 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1730 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1731
Bob Wilsona7c397c2009-10-14 16:19:03 +00001732 SDValue Chain = N->getOperand(0);
1733 unsigned Lane =
Bob Wilson1c3ef902011-02-07 17:43:21 +00001734 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
1735 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001736 bool is64BitVector = VT.is64BitVector();
1737
Bob Wilson665814b2010-11-01 23:40:51 +00001738 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001739 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001740 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001741 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1742 if (Alignment > NumBytes)
1743 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001744 if (Alignment < 8 && Alignment < NumBytes)
1745 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001746 // Alignment must be a power of two; make sure of that.
1747 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001748 if (Alignment == 1)
1749 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001750 }
Bob Wilson665814b2010-11-01 23:40:51 +00001751 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001752
Bob Wilsona7c397c2009-10-14 16:19:03 +00001753 unsigned OpcodeIndex;
1754 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001755 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001756 // Double-register operations:
1757 case MVT::v8i8: OpcodeIndex = 0; break;
1758 case MVT::v4i16: OpcodeIndex = 1; break;
1759 case MVT::v2f32:
1760 case MVT::v2i32: OpcodeIndex = 2; break;
1761 // Quad-register operations:
1762 case MVT::v8i16: OpcodeIndex = 0; break;
1763 case MVT::v4f32:
1764 case MVT::v4i32: OpcodeIndex = 1; break;
1765 }
1766
Bob Wilson1c3ef902011-02-07 17:43:21 +00001767 std::vector<EVT> ResTys;
1768 if (IsLoad) {
1769 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1770 if (!is64BitVector)
1771 ResTyElts *= 2;
1772 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
1773 MVT::i64, ResTyElts));
1774 }
1775 if (isUpdating)
1776 ResTys.push_back(MVT::i32);
1777 ResTys.push_back(MVT::Other);
1778
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001779 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001780 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001781
Bob Wilson1c3ef902011-02-07 17:43:21 +00001782 SmallVector<SDValue, 8> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001783 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001784 Ops.push_back(Align);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001785 if (isUpdating) {
1786 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1787 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1788 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001789
Bob Wilson8466fa12010-09-13 23:01:35 +00001790 SDValue SuperReg;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001791 SDValue V0 = N->getOperand(Vec0Idx + 0);
1792 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilson8466fa12010-09-13 23:01:35 +00001793 if (NumVecs == 2) {
1794 if (is64BitVector)
1795 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1796 else
1797 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001798 } else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001799 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson8466fa12010-09-13 23:01:35 +00001800 SDValue V3 = (NumVecs == 3)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001801 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1802 : N->getOperand(Vec0Idx + 3);
Bob Wilson8466fa12010-09-13 23:01:35 +00001803 if (is64BitVector)
1804 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1805 else
1806 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001807 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001808 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001809 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001810 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001811 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001812 Ops.push_back(Chain);
1813
Bob Wilson1c3ef902011-02-07 17:43:21 +00001814 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1815 QOpcodes[OpcodeIndex]);
1816 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys,
1817 Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001818 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson96493442009-10-14 16:46:45 +00001819 if (!IsLoad)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001820 return VLdLn;
Evan Cheng7092c2b2010-05-15 01:36:29 +00001821
Bob Wilson8466fa12010-09-13 23:01:35 +00001822 // Extract the subregisters.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001823 SuperReg = SDValue(VLdLn, 0);
1824 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1825 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1826 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson07f6e802010-06-16 21:34:01 +00001827 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1828 ReplaceUses(SDValue(N, Vec),
Bob Wilson1c3ef902011-02-07 17:43:21 +00001829 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1830 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
1831 if (isUpdating)
1832 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001833 return NULL;
1834}
1835
Bob Wilson1c3ef902011-02-07 17:43:21 +00001836SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
1837 unsigned NumVecs, unsigned *Opcodes) {
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001838 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1839 DebugLoc dl = N->getDebugLoc();
1840
1841 SDValue MemAddr, Align;
1842 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1843 return NULL;
1844
Evan Chengb58a3402011-04-19 00:04:03 +00001845 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1846 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1847
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001848 SDValue Chain = N->getOperand(0);
1849 EVT VT = N->getValueType(0);
1850
1851 unsigned Alignment = 0;
1852 if (NumVecs != 3) {
1853 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1854 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1855 if (Alignment > NumBytes)
1856 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001857 if (Alignment < 8 && Alignment < NumBytes)
1858 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001859 // Alignment must be a power of two; make sure of that.
1860 Alignment = (Alignment & -Alignment);
1861 if (Alignment == 1)
1862 Alignment = 0;
1863 }
1864 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1865
1866 unsigned OpcodeIndex;
1867 switch (VT.getSimpleVT().SimpleTy) {
1868 default: llvm_unreachable("unhandled vld-dup type");
1869 case MVT::v8i8: OpcodeIndex = 0; break;
1870 case MVT::v4i16: OpcodeIndex = 1; break;
1871 case MVT::v2f32:
1872 case MVT::v2i32: OpcodeIndex = 2; break;
1873 }
1874
1875 SDValue Pred = getAL(CurDAG);
1876 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1877 SDValue SuperReg;
1878 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson1c3ef902011-02-07 17:43:21 +00001879 SmallVector<SDValue, 6> Ops;
1880 Ops.push_back(MemAddr);
1881 Ops.push_back(Align);
1882 if (isUpdating) {
1883 SDValue Inc = N->getOperand(2);
1884 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1885 }
1886 Ops.push_back(Pred);
1887 Ops.push_back(Reg0);
1888 Ops.push_back(Chain);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001889
1890 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001891 std::vector<EVT> ResTys;
Evan Chengb58a3402011-04-19 00:04:03 +00001892 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001893 if (isUpdating)
1894 ResTys.push_back(MVT::i32);
1895 ResTys.push_back(MVT::Other);
1896 SDNode *VLdDup =
1897 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001898 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001899 SuperReg = SDValue(VLdDup, 0);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001900
1901 // Extract the subregisters.
1902 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1903 unsigned SubIdx = ARM::dsub_0;
1904 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1905 ReplaceUses(SDValue(N, Vec),
1906 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001907 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
1908 if (isUpdating)
1909 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001910 return NULL;
1911}
1912
Bob Wilson78dfbc32010-07-07 00:08:54 +00001913SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1914 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001915 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1916 DebugLoc dl = N->getDebugLoc();
1917 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001918 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001919
1920 // Form a REG_SEQUENCE to force register allocation.
1921 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001922 SDValue V0 = N->getOperand(FirstTblReg + 0);
1923 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001924 if (NumVecs == 2)
1925 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1926 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001927 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001928 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00001929 // an undef.
1930 SDValue V3 = (NumVecs == 3)
1931 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001932 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001933 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1934 }
1935
Bob Wilson78dfbc32010-07-07 00:08:54 +00001936 SmallVector<SDValue, 6> Ops;
1937 if (IsExt)
1938 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00001939 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001940 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001941 Ops.push_back(getAL(CurDAG)); // predicate
1942 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001943 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001944}
1945
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001946SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001947 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001948 if (!Subtarget->hasV6T2Ops())
1949 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001950
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001951 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1952 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1953
1954
1955 // For unsigned extracts, check for a shift right and mask
1956 unsigned And_imm = 0;
1957 if (N->getOpcode() == ISD::AND) {
1958 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1959
1960 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1961 if (And_imm & (And_imm + 1))
1962 return NULL;
1963
1964 unsigned Srl_imm = 0;
1965 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1966 Srl_imm)) {
1967 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1968
1969 unsigned Width = CountTrailingOnes_32(And_imm);
1970 unsigned LSB = Srl_imm;
1971 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1972 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1973 CurDAG->getTargetConstant(LSB, MVT::i32),
1974 CurDAG->getTargetConstant(Width, MVT::i32),
1975 getAL(CurDAG), Reg0 };
1976 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1977 }
1978 }
1979 return NULL;
1980 }
1981
1982 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001983 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001984 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001985 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1986 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001987 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001988 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1989 unsigned Width = 32 - Srl_imm;
1990 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001991 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001992 return NULL;
1993 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001994 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001995 CurDAG->getTargetConstant(LSB, MVT::i32),
1996 CurDAG->getTargetConstant(Width, MVT::i32),
1997 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001998 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001999 }
2000 }
2001 return NULL;
2002}
2003
Evan Cheng9ef48352009-11-20 00:54:03 +00002004SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002005SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002006 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2007 SDValue CPTmp0;
2008 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00002009 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002010 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
2011 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
2012 unsigned Opc = 0;
2013 switch (SOShOp) {
2014 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
2015 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
2016 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
2017 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
2018 default:
2019 llvm_unreachable("Unknown so_reg opcode!");
2020 break;
2021 }
2022 SDValue SOShImm =
2023 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
2024 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2025 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002026 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00002027 }
2028 return 0;
2029}
2030
2031SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002032SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002033 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2034 SDValue CPTmp0;
2035 SDValue CPTmp1;
2036 SDValue CPTmp2;
Chris Lattner52a261b2010-09-21 20:31:19 +00002037 if (SelectShifterOperandReg(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002038 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2039 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002040 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00002041 }
2042 return 0;
2043}
2044
2045SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00002046SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002047 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002048 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00002049 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00002050 return 0;
2051
Evan Cheng63f35442010-11-13 02:25:14 +00002052 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00002053 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00002054 if (is_t2_so_imm(TrueImm)) {
2055 Opc = ARM::t2MOVCCi;
2056 } else if (TrueImm <= 0xffff) {
2057 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002058 } else if (is_t2_so_imm_not(TrueImm)) {
2059 TrueImm = ~TrueImm;
2060 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002061 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00002062 // Large immediate.
2063 Opc = ARM::t2MOVCCi32imm;
2064 }
2065
2066 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002067 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002068 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2069 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002070 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002071 }
Evan Cheng63f35442010-11-13 02:25:14 +00002072
Evan Cheng9ef48352009-11-20 00:54:03 +00002073 return 0;
2074}
2075
2076SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002077SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002078 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002079 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2080 if (!T)
2081 return 0;
2082
Evan Cheng63f35442010-11-13 02:25:14 +00002083 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002084 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002085 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002086 if (isSoImm) {
2087 Opc = ARM::MOVCCi;
2088 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2089 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002090 } else if (is_so_imm_not(TrueImm)) {
2091 TrueImm = ~TrueImm;
2092 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002093 } else if (TrueVal.getNode()->hasOneUse() &&
2094 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002095 // Large immediate.
2096 Opc = ARM::MOVCCi32imm;
2097 }
2098
2099 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002100 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002101 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2102 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002103 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002104 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002105
Evan Cheng9ef48352009-11-20 00:54:03 +00002106 return 0;
2107}
2108
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002109SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2110 EVT VT = N->getValueType(0);
2111 SDValue FalseVal = N->getOperand(0);
2112 SDValue TrueVal = N->getOperand(1);
2113 SDValue CC = N->getOperand(2);
2114 SDValue CCR = N->getOperand(3);
2115 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002116 assert(CC.getOpcode() == ISD::Constant);
2117 assert(CCR.getOpcode() == ISD::Register);
2118 ARMCC::CondCodes CCVal =
2119 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002120
2121 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2122 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2123 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2124 // Pattern complexity = 18 cost = 1 size = 0
2125 SDValue CPTmp0;
2126 SDValue CPTmp1;
2127 SDValue CPTmp2;
2128 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002129 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002130 CCVal, CCR, InFlag);
2131 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002132 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002133 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2134 if (Res)
2135 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002136 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002137 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002138 CCVal, CCR, InFlag);
2139 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002140 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002141 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2142 if (Res)
2143 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002144 }
2145
2146 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002147 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002148 // (imm:i32):$cc)
2149 // Emits: (MOVCCi:i32 GPR:i32:$false,
2150 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2151 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002152 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002153 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002154 CCVal, CCR, InFlag);
2155 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002156 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002157 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2158 if (Res)
2159 return Res;
2160 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002161 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002162 CCVal, CCR, InFlag);
2163 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002164 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002165 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2166 if (Res)
2167 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002168 }
2169 }
2170
2171 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2172 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2173 // Pattern complexity = 6 cost = 1 size = 0
2174 //
2175 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2176 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2177 // Pattern complexity = 6 cost = 11 size = 0
2178 //
Jim Grosbach3c5edaa2011-03-11 23:15:02 +00002179 // Also VMOVScc and VMOVDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002180 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2181 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002182 unsigned Opc = 0;
2183 switch (VT.getSimpleVT().SimpleTy) {
2184 default: assert(false && "Illegal conditional move type!");
2185 break;
2186 case MVT::i32:
2187 Opc = Subtarget->isThumb()
2188 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2189 : ARM::MOVCCr;
2190 break;
2191 case MVT::f32:
2192 Opc = ARM::VMOVScc;
2193 break;
2194 case MVT::f64:
2195 Opc = ARM::VMOVDcc;
2196 break;
2197 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002198 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002199}
2200
Evan Chengde8aa4e2010-05-05 18:28:36 +00002201SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2202 // The only time a CONCAT_VECTORS operation can have legal types is when
2203 // two 64-bit vectors are concatenated to a 128-bit vector.
2204 EVT VT = N->getValueType(0);
2205 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2206 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002207 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002208}
2209
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002210SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002211 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002212
Dan Gohmane8be6c62008-07-17 19:10:17 +00002213 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002214 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002215
2216 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002217 default: break;
2218 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002219 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002220 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002221 if (Subtarget->hasThumb2())
2222 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2223 // be done with MOV + MOVT, at worst.
2224 UseCP = 0;
2225 else {
2226 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002227 UseCP = (Val > 255 && // MOV
2228 ~Val > 255 && // MOV + MVN
2229 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002230 } else
2231 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2232 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2233 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2234 }
2235
Evan Chenga8e29892007-01-19 07:51:42 +00002236 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002237 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002238 CurDAG->getTargetConstantPool(ConstantInt::get(
2239 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002240 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002241
2242 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002243 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002244 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002245 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002246 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002247 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002248 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002249 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002250 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002251 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002252 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002253 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002254 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002255 CurDAG->getEntryNode()
2256 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002257 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002258 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002259 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002260 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002261 return NULL;
2262 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002263
Evan Chenga8e29892007-01-19 07:51:42 +00002264 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002265 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002266 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002267 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002268 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002269 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002270 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002271 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00002272 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
2273 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002274 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002275 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2276 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002277 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2278 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2279 CurDAG->getRegister(0, MVT::i32) };
2280 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002281 }
Evan Chenga8e29892007-01-19 07:51:42 +00002282 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002283 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002284 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002285 return I;
2286 break;
2287 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002288 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002289 return I;
2290 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002291 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002292 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002293 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002294 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002295 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002296 if (!RHSV) break;
2297 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002298 unsigned ShImm = Log2_32(RHSV-1);
2299 if (ShImm >= 32)
2300 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002301 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002302 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002303 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2304 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002305 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002306 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002307 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002308 } else {
2309 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002310 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002311 }
Evan Chenga8e29892007-01-19 07:51:42 +00002312 }
2313 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002314 unsigned ShImm = Log2_32(RHSV+1);
2315 if (ShImm >= 32)
2316 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002317 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002318 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002319 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2320 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002321 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002322 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2323 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002324 } else {
2325 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002326 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002327 }
Evan Chenga8e29892007-01-19 07:51:42 +00002328 }
2329 }
2330 break;
Evan Cheng20956592009-10-21 08:15:52 +00002331 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002332 // Check for unsigned bitfield extract
2333 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2334 return I;
2335
Evan Cheng20956592009-10-21 08:15:52 +00002336 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2337 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2338 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2339 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2340 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002341 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002342 if (VT != MVT::i32)
2343 break;
2344 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2345 ? ARM::t2MOVTi16
2346 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2347 if (!Opc)
2348 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002349 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002350 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2351 if (!N1C)
2352 break;
2353 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2354 SDValue N2 = N0.getOperand(1);
2355 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2356 if (!N2C)
2357 break;
2358 unsigned N1CVal = N1C->getZExtValue();
2359 unsigned N2CVal = N2C->getZExtValue();
2360 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2361 (N1CVal & 0xffffU) == 0xffffU &&
2362 (N2CVal & 0xffffU) == 0x0U) {
2363 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2364 MVT::i32);
2365 SDValue Ops[] = { N0.getOperand(0), Imm16,
2366 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2367 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2368 }
2369 }
2370 break;
2371 }
Jim Grosbache5165492009-11-09 00:11:35 +00002372 case ARMISD::VMOVRRD:
2373 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002374 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002375 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002376 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002377 if (Subtarget->isThumb1Only())
2378 break;
2379 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002380 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002381 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2382 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002383 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002384 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002385 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002386 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2387 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002388 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2389 ARM::UMULL : ARM::UMULLv5,
2390 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002391 }
Evan Chengee568cf2007-07-05 07:15:27 +00002392 }
Dan Gohman525178c2007-10-08 18:33:35 +00002393 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002394 if (Subtarget->isThumb1Only())
2395 break;
2396 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002397 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002398 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002399 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002400 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002401 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002402 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2403 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002404 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2405 ARM::SMULL : ARM::SMULLv5,
2406 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002407 }
Evan Chengee568cf2007-07-05 07:15:27 +00002408 }
Evan Chenga8e29892007-01-19 07:51:42 +00002409 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002410 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002411 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002412 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002413 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002414 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002415 if (ResNode)
2416 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002417 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002418 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002419 }
Evan Chengee568cf2007-07-05 07:15:27 +00002420 case ARMISD::BRCOND: {
2421 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2422 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2423 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002424
Evan Chengee568cf2007-07-05 07:15:27 +00002425 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2426 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2427 // Pattern complexity = 6 cost = 1 size = 0
2428
David Goodwin5e47a9a2009-06-30 18:04:13 +00002429 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2430 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2431 // Pattern complexity = 6 cost = 1 size = 0
2432
Jim Grosbach764ab522009-08-11 15:33:49 +00002433 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002434 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002435 SDValue Chain = N->getOperand(0);
2436 SDValue N1 = N->getOperand(1);
2437 SDValue N2 = N->getOperand(2);
2438 SDValue N3 = N->getOperand(3);
2439 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002440 assert(N1.getOpcode() == ISD::BasicBlock);
2441 assert(N2.getOpcode() == ISD::Constant);
2442 assert(N3.getOpcode() == ISD::Register);
2443
Dan Gohman475871a2008-07-27 21:46:04 +00002444 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002445 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002446 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002447 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002448 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002449 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002450 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002451 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002452 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002453 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002454 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002455 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002456 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002457 return NULL;
2458 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002459 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002460 return SelectCMOVOp(N);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002461 case ARMISD::VZIP: {
2462 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002463 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002464 switch (VT.getSimpleVT().SimpleTy) {
2465 default: return NULL;
2466 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2467 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2468 case MVT::v2f32:
2469 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2470 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2471 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2472 case MVT::v4f32:
2473 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2474 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002475 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002476 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2477 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2478 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002479 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002480 case ARMISD::VUZP: {
2481 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002482 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002483 switch (VT.getSimpleVT().SimpleTy) {
2484 default: return NULL;
2485 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2486 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2487 case MVT::v2f32:
2488 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2489 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2490 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2491 case MVT::v4f32:
2492 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2493 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002494 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002495 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2496 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2497 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002498 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002499 case ARMISD::VTRN: {
2500 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002501 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002502 switch (VT.getSimpleVT().SimpleTy) {
2503 default: return NULL;
2504 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2505 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2506 case MVT::v2f32:
2507 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2508 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2509 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2510 case MVT::v4f32:
2511 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2512 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002513 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002514 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2515 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2516 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002517 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002518 case ARMISD::BUILD_VECTOR: {
2519 EVT VecVT = N->getValueType(0);
2520 EVT EltVT = VecVT.getVectorElementType();
2521 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002522 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002523 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2524 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2525 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002526 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002527 if (NumElts == 2)
2528 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2529 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2530 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2531 N->getOperand(2), N->getOperand(3));
2532 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002533
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002534 case ARMISD::VLD2DUP: {
2535 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2536 ARM::VLD2DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002537 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002538 }
2539
Bob Wilson86c6d802010-11-29 19:35:29 +00002540 case ARMISD::VLD3DUP: {
2541 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2542 ARM::VLD3DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002543 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson86c6d802010-11-29 19:35:29 +00002544 }
2545
Bob Wilson6c4c9822010-11-30 00:00:35 +00002546 case ARMISD::VLD4DUP: {
2547 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2548 ARM::VLD4DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002549 return SelectVLDDup(N, false, 4, Opcodes);
2550 }
2551
2552 case ARMISD::VLD2DUP_UPD: {
2553 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo_UPD, ARM::VLD2DUPd16Pseudo_UPD,
2554 ARM::VLD2DUPd32Pseudo_UPD };
2555 return SelectVLDDup(N, true, 2, Opcodes);
2556 }
2557
2558 case ARMISD::VLD3DUP_UPD: {
2559 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD, ARM::VLD3DUPd16Pseudo_UPD,
2560 ARM::VLD3DUPd32Pseudo_UPD };
2561 return SelectVLDDup(N, true, 3, Opcodes);
2562 }
2563
2564 case ARMISD::VLD4DUP_UPD: {
2565 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD, ARM::VLD4DUPd16Pseudo_UPD,
2566 ARM::VLD4DUPd32Pseudo_UPD };
2567 return SelectVLDDup(N, true, 4, Opcodes);
2568 }
2569
2570 case ARMISD::VLD1_UPD: {
2571 unsigned DOpcodes[] = { ARM::VLD1d8_UPD, ARM::VLD1d16_UPD,
2572 ARM::VLD1d32_UPD, ARM::VLD1d64_UPD };
2573 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo_UPD, ARM::VLD1q16Pseudo_UPD,
2574 ARM::VLD1q32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2575 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2576 }
2577
2578 case ARMISD::VLD2_UPD: {
2579 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo_UPD, ARM::VLD2d16Pseudo_UPD,
2580 ARM::VLD2d32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2581 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo_UPD, ARM::VLD2q16Pseudo_UPD,
2582 ARM::VLD2q32Pseudo_UPD };
2583 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2584 }
2585
2586 case ARMISD::VLD3_UPD: {
2587 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo_UPD, ARM::VLD3d16Pseudo_UPD,
2588 ARM::VLD3d32Pseudo_UPD, ARM::VLD1d64TPseudo_UPD };
2589 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2590 ARM::VLD3q16Pseudo_UPD,
2591 ARM::VLD3q32Pseudo_UPD };
2592 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2593 ARM::VLD3q16oddPseudo_UPD,
2594 ARM::VLD3q32oddPseudo_UPD };
2595 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2596 }
2597
2598 case ARMISD::VLD4_UPD: {
2599 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo_UPD, ARM::VLD4d16Pseudo_UPD,
2600 ARM::VLD4d32Pseudo_UPD, ARM::VLD1d64QPseudo_UPD };
2601 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2602 ARM::VLD4q16Pseudo_UPD,
2603 ARM::VLD4q32Pseudo_UPD };
2604 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2605 ARM::VLD4q16oddPseudo_UPD,
2606 ARM::VLD4q32oddPseudo_UPD };
2607 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2608 }
2609
2610 case ARMISD::VLD2LN_UPD: {
2611 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD, ARM::VLD2LNd16Pseudo_UPD,
2612 ARM::VLD2LNd32Pseudo_UPD };
2613 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2614 ARM::VLD2LNq32Pseudo_UPD };
2615 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2616 }
2617
2618 case ARMISD::VLD3LN_UPD: {
2619 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD, ARM::VLD3LNd16Pseudo_UPD,
2620 ARM::VLD3LNd32Pseudo_UPD };
2621 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2622 ARM::VLD3LNq32Pseudo_UPD };
2623 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2624 }
2625
2626 case ARMISD::VLD4LN_UPD: {
2627 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD, ARM::VLD4LNd16Pseudo_UPD,
2628 ARM::VLD4LNd32Pseudo_UPD };
2629 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2630 ARM::VLD4LNq32Pseudo_UPD };
2631 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2632 }
2633
2634 case ARMISD::VST1_UPD: {
2635 unsigned DOpcodes[] = { ARM::VST1d8_UPD, ARM::VST1d16_UPD,
2636 ARM::VST1d32_UPD, ARM::VST1d64_UPD };
2637 unsigned QOpcodes[] = { ARM::VST1q8Pseudo_UPD, ARM::VST1q16Pseudo_UPD,
2638 ARM::VST1q32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2639 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2640 }
2641
2642 case ARMISD::VST2_UPD: {
2643 unsigned DOpcodes[] = { ARM::VST2d8Pseudo_UPD, ARM::VST2d16Pseudo_UPD,
2644 ARM::VST2d32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2645 unsigned QOpcodes[] = { ARM::VST2q8Pseudo_UPD, ARM::VST2q16Pseudo_UPD,
2646 ARM::VST2q32Pseudo_UPD };
2647 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2648 }
2649
2650 case ARMISD::VST3_UPD: {
2651 unsigned DOpcodes[] = { ARM::VST3d8Pseudo_UPD, ARM::VST3d16Pseudo_UPD,
2652 ARM::VST3d32Pseudo_UPD, ARM::VST1d64TPseudo_UPD };
2653 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2654 ARM::VST3q16Pseudo_UPD,
2655 ARM::VST3q32Pseudo_UPD };
2656 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2657 ARM::VST3q16oddPseudo_UPD,
2658 ARM::VST3q32oddPseudo_UPD };
2659 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2660 }
2661
2662 case ARMISD::VST4_UPD: {
2663 unsigned DOpcodes[] = { ARM::VST4d8Pseudo_UPD, ARM::VST4d16Pseudo_UPD,
2664 ARM::VST4d32Pseudo_UPD, ARM::VST1d64QPseudo_UPD };
2665 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2666 ARM::VST4q16Pseudo_UPD,
2667 ARM::VST4q32Pseudo_UPD };
2668 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2669 ARM::VST4q16oddPseudo_UPD,
2670 ARM::VST4q32oddPseudo_UPD };
2671 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2672 }
2673
2674 case ARMISD::VST2LN_UPD: {
2675 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD, ARM::VST2LNd16Pseudo_UPD,
2676 ARM::VST2LNd32Pseudo_UPD };
2677 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2678 ARM::VST2LNq32Pseudo_UPD };
2679 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2680 }
2681
2682 case ARMISD::VST3LN_UPD: {
2683 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD, ARM::VST3LNd16Pseudo_UPD,
2684 ARM::VST3LNd32Pseudo_UPD };
2685 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2686 ARM::VST3LNq32Pseudo_UPD };
2687 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2688 }
2689
2690 case ARMISD::VST4LN_UPD: {
2691 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD, ARM::VST4LNd16Pseudo_UPD,
2692 ARM::VST4LNd32Pseudo_UPD };
2693 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2694 ARM::VST4LNq32Pseudo_UPD };
2695 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson6c4c9822010-11-30 00:00:35 +00002696 }
2697
Bob Wilson31fb12f2009-08-26 17:39:53 +00002698 case ISD::INTRINSIC_VOID:
2699 case ISD::INTRINSIC_W_CHAIN: {
2700 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002701 switch (IntNo) {
2702 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002703 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002704
Bruno Cardoso Lopesa0112d02011-05-28 04:07:29 +00002705 case Intrinsic::arm_ldrexd: {
2706 SDValue MemAddr = N->getOperand(2);
2707 DebugLoc dl = N->getDebugLoc();
2708 SDValue Chain = N->getOperand(0);
2709
2710 unsigned NewOpc = ARM::LDREXD;
2711 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2712 NewOpc = ARM::t2LDREXD;
2713
2714 // arm_ldrexd returns a i64 value in {i32, i32}
2715 std::vector<EVT> ResTys;
2716 ResTys.push_back(MVT::i32);
2717 ResTys.push_back(MVT::i32);
2718 ResTys.push_back(MVT::Other);
2719
2720 // place arguments in the right order
2721 SmallVector<SDValue, 7> Ops;
2722 Ops.push_back(MemAddr);
2723 Ops.push_back(getAL(CurDAG));
2724 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2725 Ops.push_back(Chain);
2726 SDNode *Ld = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
2727 Ops.size());
2728 // Transfer memoperands.
2729 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2730 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2731 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
2732
2733 // Until there's support for specifing explicit register constraints
2734 // like the use of even/odd register pair, hardcode ldrexd to always
2735 // use the pair [R0, R1] to hold the load result.
2736 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R0,
2737 SDValue(Ld, 0), SDValue(0,0));
2738 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R1,
2739 SDValue(Ld, 1), Chain.getValue(1));
2740
2741 // Remap uses.
2742 SDValue Glue = Chain.getValue(1);
2743 if (!SDValue(N, 0).use_empty()) {
2744 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2745 ARM::R0, MVT::i32, Glue);
2746 Glue = Result.getValue(2);
2747 ReplaceUses(SDValue(N, 0), Result);
2748 }
2749 if (!SDValue(N, 1).use_empty()) {
2750 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2751 ARM::R1, MVT::i32, Glue);
2752 Glue = Result.getValue(2);
2753 ReplaceUses(SDValue(N, 1), Result);
2754 }
2755
2756 ReplaceUses(SDValue(N, 2), SDValue(Ld, 2));
2757 return NULL;
2758 }
2759
2760 case Intrinsic::arm_strexd: {
2761 DebugLoc dl = N->getDebugLoc();
2762 SDValue Chain = N->getOperand(0);
2763 SDValue Val0 = N->getOperand(2);
2764 SDValue Val1 = N->getOperand(3);
2765 SDValue MemAddr = N->getOperand(4);
2766
2767 // Until there's support for specifing explicit register constraints
2768 // like the use of even/odd register pair, hardcode strexd to always
2769 // use the pair [R2, R3] to hold the i64 (i32, i32) value to be stored.
2770 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R2, Val0,
2771 SDValue(0, 0));
2772 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R3, Val1, Chain.getValue(1));
2773
2774 SDValue Glue = Chain.getValue(1);
2775 Val0 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2776 ARM::R2, MVT::i32, Glue);
2777 Glue = Val0.getValue(1);
2778 Val1 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2779 ARM::R3, MVT::i32, Glue);
2780
2781 // Store exclusive double return a i32 value which is the return status
2782 // of the issued store.
2783 std::vector<EVT> ResTys;
2784 ResTys.push_back(MVT::i32);
2785 ResTys.push_back(MVT::Other);
2786
2787 // place arguments in the right order
2788 SmallVector<SDValue, 7> Ops;
2789 Ops.push_back(Val0);
2790 Ops.push_back(Val1);
2791 Ops.push_back(MemAddr);
2792 Ops.push_back(getAL(CurDAG));
2793 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2794 Ops.push_back(Chain);
2795
2796 unsigned NewOpc = ARM::STREXD;
2797 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2798 NewOpc = ARM::t2STREXD;
2799
2800 SDNode *St = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
2801 Ops.size());
2802 // Transfer memoperands.
2803 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2804 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2805 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
2806
2807 return St;
2808 }
2809
Bob Wilson621f1952010-03-23 05:25:43 +00002810 case Intrinsic::arm_neon_vld1: {
2811 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2812 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002813 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2814 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002815 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson621f1952010-03-23 05:25:43 +00002816 }
2817
Bob Wilson31fb12f2009-08-26 17:39:53 +00002818 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002819 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2820 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2821 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2822 ARM::VLD2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002823 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002824 }
2825
2826 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002827 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2828 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2829 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2830 ARM::VLD3q16Pseudo_UPD,
2831 ARM::VLD3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002832 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo,
2833 ARM::VLD3q16oddPseudo,
2834 ARM::VLD3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002835 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002836 }
2837
2838 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002839 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2840 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2841 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2842 ARM::VLD4q16Pseudo_UPD,
2843 ARM::VLD4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002844 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo,
2845 ARM::VLD4q16oddPseudo,
2846 ARM::VLD4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002847 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002848 }
2849
Bob Wilson243fcc52009-09-01 04:26:28 +00002850 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002851 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2852 ARM::VLD2LNd32Pseudo };
2853 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002854 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002855 }
2856
2857 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002858 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2859 ARM::VLD3LNd32Pseudo };
2860 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002861 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002862 }
2863
2864 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002865 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2866 ARM::VLD4LNd32Pseudo };
2867 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002868 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002869 }
2870
Bob Wilson11d98992010-03-23 06:20:33 +00002871 case Intrinsic::arm_neon_vst1: {
2872 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2873 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002874 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2875 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002876 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson11d98992010-03-23 06:20:33 +00002877 }
2878
Bob Wilson31fb12f2009-08-26 17:39:53 +00002879 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002880 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2881 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2882 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2883 ARM::VST2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002884 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002885 }
2886
2887 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002888 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2889 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2890 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2891 ARM::VST3q16Pseudo_UPD,
2892 ARM::VST3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002893 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo,
2894 ARM::VST3q16oddPseudo,
2895 ARM::VST3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002896 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002897 }
2898
2899 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002900 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002901 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002902 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2903 ARM::VST4q16Pseudo_UPD,
2904 ARM::VST4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002905 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo,
2906 ARM::VST4q16oddPseudo,
2907 ARM::VST4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002908 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002909 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002910
2911 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002912 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2913 ARM::VST2LNd32Pseudo };
2914 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002915 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002916 }
2917
2918 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002919 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2920 ARM::VST3LNd32Pseudo };
2921 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002922 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002923 }
2924
2925 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002926 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2927 ARM::VST4LNd32Pseudo };
2928 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002929 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002930 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002931 }
Bob Wilson429009b2010-05-06 16:05:26 +00002932 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002933 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002934
Bob Wilsond491d6e2010-07-06 23:36:25 +00002935 case ISD::INTRINSIC_WO_CHAIN: {
2936 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2937 switch (IntNo) {
2938 default:
2939 break;
2940
2941 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002942 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002943 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002944 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002945 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002946 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002947
2948 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002949 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002950 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002951 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002952 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002953 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002954 }
2955 break;
2956 }
2957
Bill Wendling69a05a72011-03-14 23:02:38 +00002958 case ARMISD::VTBL1: {
2959 DebugLoc dl = N->getDebugLoc();
2960 EVT VT = N->getValueType(0);
2961 SmallVector<SDValue, 6> Ops;
2962
2963 Ops.push_back(N->getOperand(0));
2964 Ops.push_back(N->getOperand(1));
2965 Ops.push_back(getAL(CurDAG)); // Predicate
2966 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
2967 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops.data(), Ops.size());
2968 }
2969 case ARMISD::VTBL2: {
2970 DebugLoc dl = N->getDebugLoc();
2971 EVT VT = N->getValueType(0);
2972
2973 // Form a REG_SEQUENCE to force register allocation.
2974 SDValue V0 = N->getOperand(0);
2975 SDValue V1 = N->getOperand(1);
2976 SDValue RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
2977
2978 SmallVector<SDValue, 6> Ops;
2979 Ops.push_back(RegSeq);
2980 Ops.push_back(N->getOperand(2));
2981 Ops.push_back(getAL(CurDAG)); // Predicate
2982 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
2983 return CurDAG->getMachineNode(ARM::VTBL2Pseudo, dl, VT,
2984 Ops.data(), Ops.size());
2985 }
2986
Bob Wilson429009b2010-05-06 16:05:26 +00002987 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002988 return SelectConcatVector(N);
2989 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002990
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002991 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002992}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002993
Bob Wilson224c2442009-05-19 05:53:42 +00002994bool ARMDAGToDAGISel::
2995SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2996 std::vector<SDValue> &OutOps) {
2997 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002998 // Require the address to be in a register. That is safe for all ARM
2999 // variants and it is hard to do anything much smarter without knowing
3000 // how the operand is used.
3001 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00003002 return false;
3003}
3004
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003005/// createARMISelDag - This pass converts a legalized DAG into a
3006/// ARM-specific DAG, ready for instruction scheduling.
3007///
Bob Wilson522ce972009-09-28 14:30:20 +00003008FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
3009 CodeGenOpt::Level OptLevel) {
3010 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003011}