blob: 299174b6edd4d6fbad706c7ffacb6be28b3d4a33 [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"),
48 cl::init(false));
49
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,
Evan Cheng055b0312009-06-29 07:51:04 +000094 SDValue &B, SDValue &C);
Evan Chengf40deed2010-10-27 23:41:30 +000095 bool SelectShiftShifterOperandReg(SDValue N, SDValue &A,
96 SDValue &B, SDValue &C);
Jim Grosbach3e556122010-10-26 22:37:02 +000097 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
98 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
99
Jim Grosbach82891622010-09-29 19:03:54 +0000100 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
101 SDValue &Offset, SDValue &Opc);
102 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
103 SDValue &Opc) {
104 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
105 }
106
107 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
108 SDValue &Opc) {
109 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
110 }
111
112 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
113 SDValue &Opc) {
114 SelectAddrMode2Worker(N, Base, Offset, Opc);
Jim Grosbach3e556122010-10-26 22:37:02 +0000115// return SelectAddrMode2ShOp(N, Base, Offset, Opc);
Jim Grosbach82891622010-09-29 19:03:54 +0000116 // This always matches one way or another.
117 return true;
118 }
119
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000120 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000121 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000122 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000123 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000124 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000125 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000126 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000127 SDValue &Offset);
Bob Wilson665814b2010-11-01 23:40:51 +0000128 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000129
Evan Cheng5de5d4b2011-01-17 08:03:18 +0000130 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +0000131
Bill Wendlingf4caf692010-12-14 03:36:38 +0000132 // Thumb Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000133 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000134 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
135 unsigned Scale);
136 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
137 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
138 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
139 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
140 SDValue &OffImm);
141 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
142 SDValue &OffImm);
143 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
144 SDValue &OffImm);
145 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
146 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000147 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000148
Bill Wendlingf4caf692010-12-14 03:36:38 +0000149 // Thumb 2 Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000150 bool SelectT2ShifterOperandReg(SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000151 SDValue &BaseReg, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000152 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
153 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000154 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000155 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000156 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000157 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000158 SDValue &OffReg, SDValue &ShImm);
159
Evan Cheng875a6ac2010-11-12 22:42:47 +0000160 inline bool is_so_imm(unsigned Imm) const {
161 return ARM_AM::getSOImmVal(Imm) != -1;
162 }
163
164 inline bool is_so_imm_not(unsigned Imm) const {
165 return ARM_AM::getSOImmVal(~Imm) != -1;
166 }
167
168 inline bool is_t2_so_imm(unsigned Imm) const {
169 return ARM_AM::getT2SOImmVal(Imm) != -1;
170 }
171
172 inline bool is_t2_so_imm_not(unsigned Imm) const {
173 return ARM_AM::getT2SOImmVal(~Imm) != -1;
174 }
175
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000176 inline bool Pred_so_imm(SDNode *inN) const {
177 ConstantSDNode *N = cast<ConstantSDNode>(inN);
Evan Cheng875a6ac2010-11-12 22:42:47 +0000178 return is_so_imm(N->getZExtValue());
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000179 }
180
181 inline bool Pred_t2_so_imm(SDNode *inN) const {
182 ConstantSDNode *N = cast<ConstantSDNode>(inN);
Evan Cheng875a6ac2010-11-12 22:42:47 +0000183 return is_t2_so_imm(N->getZExtValue());
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000184 }
185
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000186 // Include the pieces autogenerated from the target description.
187#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000188
189private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000190 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
191 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000192 SDNode *SelectARMIndexedLoad(SDNode *N);
193 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000194
Bob Wilson621f1952010-03-23 05:25:43 +0000195 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
196 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000197 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000198 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000199 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000200 unsigned *QOpcodes0, unsigned *QOpcodes1);
201
Bob Wilson24f995d2009-10-14 18:32:29 +0000202 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000203 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000204 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000205 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000206 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000207 unsigned *QOpcodes0, unsigned *QOpcodes1);
208
Bob Wilson96493442009-10-14 16:46:45 +0000209 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000210 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson8466fa12010-09-13 23:01:35 +0000211 /// load/store of D registers and Q registers.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000212 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
Bob Wilson8466fa12010-09-13 23:01:35 +0000213 unsigned *DOpcodes, unsigned *QOpcodes);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000214
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000215 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
216 /// should be 2, 3 or 4. The opcode array specifies the instructions used
217 /// for loading D registers. (Q registers are not supported.)
218 SDNode *SelectVLDDup(SDNode *N, unsigned NumVecs, unsigned *Opcodes);
219
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()) {
332 const TargetInstrDesc &TID = TII->get(Use->getMachineOpcode());
333 if (TID.mayStore())
334 return true;
335 unsigned Opcode = TID.getOpcode();
336 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,
371 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000372 if (DisableShifterOp)
373 return false;
374
Evan Cheng055b0312009-06-29 07:51:04 +0000375 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
376
377 // Don't match base register only case. That is matched to a separate
378 // lower complexity pattern with explicit register operand.
379 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000380
Evan Cheng055b0312009-06-29 07:51:04 +0000381 BaseReg = N.getOperand(0);
382 unsigned ShImmVal = 0;
383 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000384 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000385 ShImmVal = RHS->getZExtValue() & 31;
386 } else {
387 ShReg = N.getOperand(1);
Evan Chengf40deed2010-10-27 23:41:30 +0000388 if (!isShifterOpProfitable(N, ShOpcVal, ShImmVal))
389 return false;
390 }
391 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
392 MVT::i32);
393 return true;
394}
395
396bool ARMDAGToDAGISel::SelectShiftShifterOperandReg(SDValue N,
397 SDValue &BaseReg,
398 SDValue &ShReg,
399 SDValue &Opc) {
400 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
401
402 // Don't match base register only case. That is matched to a separate
403 // lower complexity pattern with explicit register operand.
404 if (ShOpcVal == ARM_AM::no_shift) return false;
405
406 BaseReg = N.getOperand(0);
407 unsigned ShImmVal = 0;
408 // Do not check isShifterOpProfitable. This must return true.
409 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
410 ShReg = CurDAG->getRegister(0, MVT::i32);
411 ShImmVal = RHS->getZExtValue() & 31;
412 } else {
413 ShReg = N.getOperand(1);
Evan Cheng055b0312009-06-29 07:51:04 +0000414 }
415 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000416 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000417 return true;
418}
419
Jim Grosbach3e556122010-10-26 22:37:02 +0000420bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
421 SDValue &Base,
422 SDValue &OffImm) {
423 // Match simple R + imm12 operands.
424
425 // Base only.
426 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
427 if (N.getOpcode() == ISD::FrameIndex) {
428 // Match frame index...
429 int FI = cast<FrameIndexSDNode>(N)->getIndex();
430 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
431 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
432 return true;
433 } else if (N.getOpcode() == ARMISD::Wrapper &&
434 !(Subtarget->useMovt() &&
435 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
436 Base = N.getOperand(0);
437 } else
438 Base = N;
439 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
440 return true;
441 }
442
443 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
444 int RHSC = (int)RHS->getZExtValue();
445 if (N.getOpcode() == ISD::SUB)
446 RHSC = -RHSC;
447
448 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
449 Base = N.getOperand(0);
450 if (Base.getOpcode() == ISD::FrameIndex) {
451 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
452 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
453 }
454 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
455 return true;
456 }
457 }
458
459 // Base only.
460 Base = N;
461 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
462 return true;
463}
464
465
466
467bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
468 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000469 if (N.getOpcode() == ISD::MUL &&
470 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000471 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
472 // X * [3,5,9] -> X + X * [2,4,8] etc.
473 int RHSC = (int)RHS->getZExtValue();
474 if (RHSC & 1) {
475 RHSC = RHSC & ~1;
476 ARM_AM::AddrOpc AddSub = ARM_AM::add;
477 if (RHSC < 0) {
478 AddSub = ARM_AM::sub;
479 RHSC = - RHSC;
480 }
481 if (isPowerOf2_32(RHSC)) {
482 unsigned ShAmt = Log2_32(RHSC);
483 Base = Offset = N.getOperand(0);
484 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
485 ARM_AM::lsl),
486 MVT::i32);
487 return true;
488 }
489 }
490 }
491 }
492
493 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB)
494 return false;
495
496 // Leave simple R +/- imm12 operands for LDRi12
497 if (N.getOpcode() == ISD::ADD) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000498 int RHSC;
499 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
500 -0x1000+1, 0x1000, RHSC)) // 12 bits.
501 return false;
Jim Grosbach3e556122010-10-26 22:37:02 +0000502 }
503
Evan Chengf40deed2010-10-27 23:41:30 +0000504 if (Subtarget->isCortexA9() && !N.hasOneUse())
505 // Compute R +/- (R << N) and reuse it.
506 return false;
507
Jim Grosbach3e556122010-10-26 22:37:02 +0000508 // Otherwise this is R +/- [possibly shifted] R.
509 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
510 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
511 unsigned ShAmt = 0;
512
513 Base = N.getOperand(0);
514 Offset = N.getOperand(1);
515
516 if (ShOpcVal != ARM_AM::no_shift) {
517 // Check to see if the RHS of the shift is a constant, if not, we can't fold
518 // it.
519 if (ConstantSDNode *Sh =
520 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
521 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000522 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
523 Offset = N.getOperand(1).getOperand(0);
524 else {
525 ShAmt = 0;
526 ShOpcVal = ARM_AM::no_shift;
527 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000528 } else {
529 ShOpcVal = ARM_AM::no_shift;
530 }
531 }
532
533 // Try matching (R shl C) + (R).
Evan Chengf40deed2010-10-27 23:41:30 +0000534 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift &&
535 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000536 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
537 if (ShOpcVal != ARM_AM::no_shift) {
538 // Check to see if the RHS of the shift is a constant, if not, we can't
539 // fold it.
540 if (ConstantSDNode *Sh =
541 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
542 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000543 if (!Subtarget->isCortexA9() ||
544 (N.hasOneUse() &&
545 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
546 Offset = N.getOperand(0).getOperand(0);
547 Base = N.getOperand(1);
548 } else {
549 ShAmt = 0;
550 ShOpcVal = ARM_AM::no_shift;
551 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000552 } else {
553 ShOpcVal = ARM_AM::no_shift;
554 }
555 }
556 }
557
558 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
559 MVT::i32);
560 return true;
561}
562
563
564
565
566//-----
567
Jim Grosbach82891622010-09-29 19:03:54 +0000568AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
569 SDValue &Base,
570 SDValue &Offset,
571 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000572 if (N.getOpcode() == ISD::MUL &&
573 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000574 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
575 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000576 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000577 if (RHSC & 1) {
578 RHSC = RHSC & ~1;
579 ARM_AM::AddrOpc AddSub = ARM_AM::add;
580 if (RHSC < 0) {
581 AddSub = ARM_AM::sub;
582 RHSC = - RHSC;
583 }
584 if (isPowerOf2_32(RHSC)) {
585 unsigned ShAmt = Log2_32(RHSC);
586 Base = Offset = N.getOperand(0);
587 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
588 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000589 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000590 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000591 }
592 }
593 }
594 }
595
Evan Chenga8e29892007-01-19 07:51:42 +0000596 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
597 Base = N;
598 if (N.getOpcode() == ISD::FrameIndex) {
599 int FI = cast<FrameIndexSDNode>(N)->getIndex();
600 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000601 } else if (N.getOpcode() == ARMISD::Wrapper &&
602 !(Subtarget->useMovt() &&
603 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000604 Base = N.getOperand(0);
605 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000606 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000607 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
608 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000609 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000610 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000611 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000612
Evan Chenga8e29892007-01-19 07:51:42 +0000613 // Match simple R +/- imm12 operands.
Jim Grosbachbe912322010-09-29 17:32:29 +0000614 if (N.getOpcode() == ISD::ADD) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000615 int RHSC;
616 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
617 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
618 Base = N.getOperand(0);
619 if (Base.getOpcode() == ISD::FrameIndex) {
620 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
621 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000622 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000623 Offset = CurDAG->getRegister(0, MVT::i32);
624
625 ARM_AM::AddrOpc AddSub = ARM_AM::add;
626 if (RHSC < 0) {
627 AddSub = ARM_AM::sub;
628 RHSC = - RHSC;
629 }
630 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
631 ARM_AM::no_shift),
632 MVT::i32);
633 return AM2_BASE;
Evan Chenga8e29892007-01-19 07:51:42 +0000634 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000635 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000636
Evan Chengf40deed2010-10-27 23:41:30 +0000637 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
638 // Compute R +/- (R << N) and reuse it.
639 Base = N;
640 Offset = CurDAG->getRegister(0, MVT::i32);
641 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
642 ARM_AM::no_shift),
643 MVT::i32);
644 return AM2_BASE;
645 }
646
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000647 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000648 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
649 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
650 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000651
Evan Chenga8e29892007-01-19 07:51:42 +0000652 Base = N.getOperand(0);
653 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000654
Evan Chenga8e29892007-01-19 07:51:42 +0000655 if (ShOpcVal != ARM_AM::no_shift) {
656 // Check to see if the RHS of the shift is a constant, if not, we can't fold
657 // it.
658 if (ConstantSDNode *Sh =
659 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000660 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000661 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
662 Offset = N.getOperand(1).getOperand(0);
663 else {
664 ShAmt = 0;
665 ShOpcVal = ARM_AM::no_shift;
666 }
Evan Chenga8e29892007-01-19 07:51:42 +0000667 } else {
668 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000669 }
670 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000671
Evan Chenga8e29892007-01-19 07:51:42 +0000672 // Try matching (R shl C) + (R).
Evan Chengf40deed2010-10-27 23:41:30 +0000673 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift &&
674 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chenga8e29892007-01-19 07:51:42 +0000675 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
676 if (ShOpcVal != ARM_AM::no_shift) {
677 // Check to see if the RHS of the shift is a constant, if not, we can't
678 // fold it.
679 if (ConstantSDNode *Sh =
680 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000681 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000682 if (!Subtarget->isCortexA9() ||
683 (N.hasOneUse() &&
684 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
685 Offset = N.getOperand(0).getOperand(0);
686 Base = N.getOperand(1);
687 } else {
688 ShAmt = 0;
689 ShOpcVal = ARM_AM::no_shift;
690 }
Evan Chenga8e29892007-01-19 07:51:42 +0000691 } else {
692 ShOpcVal = ARM_AM::no_shift;
693 }
694 }
695 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000696
Evan Chenga8e29892007-01-19 07:51:42 +0000697 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000698 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000699 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000700}
701
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000702bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000703 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000704 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000705 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
706 ? cast<LoadSDNode>(Op)->getAddressingMode()
707 : cast<StoreSDNode>(Op)->getAddressingMode();
708 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
709 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000710 int Val;
711 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
712 Offset = CurDAG->getRegister(0, MVT::i32);
713 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
714 ARM_AM::no_shift),
715 MVT::i32);
716 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000717 }
718
719 Offset = N;
720 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
721 unsigned ShAmt = 0;
722 if (ShOpcVal != ARM_AM::no_shift) {
723 // Check to see if the RHS of the shift is a constant, if not, we can't fold
724 // it.
725 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000726 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000727 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
728 Offset = N.getOperand(0);
729 else {
730 ShAmt = 0;
731 ShOpcVal = ARM_AM::no_shift;
732 }
Evan Chenga8e29892007-01-19 07:51:42 +0000733 } else {
734 ShOpcVal = ARM_AM::no_shift;
735 }
736 }
737
738 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000739 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000740 return true;
741}
742
Evan Chenga8e29892007-01-19 07:51:42 +0000743
Chris Lattner52a261b2010-09-21 20:31:19 +0000744bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000745 SDValue &Base, SDValue &Offset,
746 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000747 if (N.getOpcode() == ISD::SUB) {
748 // X - C is canonicalize to X + -C, no need to handle it here.
749 Base = N.getOperand(0);
750 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000751 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000752 return true;
753 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000754
Evan Chenga8e29892007-01-19 07:51:42 +0000755 if (N.getOpcode() != ISD::ADD) {
756 Base = N;
757 if (N.getOpcode() == ISD::FrameIndex) {
758 int FI = cast<FrameIndexSDNode>(N)->getIndex();
759 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
760 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000761 Offset = CurDAG->getRegister(0, MVT::i32);
762 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000763 return true;
764 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000765
Evan Chenga8e29892007-01-19 07:51:42 +0000766 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000767 int RHSC;
768 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
769 -256 + 1, 256, RHSC)) { // 8 bits.
770 Base = N.getOperand(0);
771 if (Base.getOpcode() == ISD::FrameIndex) {
772 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
773 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000774 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000775 Offset = CurDAG->getRegister(0, MVT::i32);
776
777 ARM_AM::AddrOpc AddSub = ARM_AM::add;
778 if (RHSC < 0) {
779 AddSub = ARM_AM::sub;
780 RHSC = - RHSC;
781 }
782 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
783 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000784 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000785
Evan Chenga8e29892007-01-19 07:51:42 +0000786 Base = N.getOperand(0);
787 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000788 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000789 return true;
790}
791
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000792bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000793 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000794 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000795 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
796 ? cast<LoadSDNode>(Op)->getAddressingMode()
797 : cast<StoreSDNode>(Op)->getAddressingMode();
798 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
799 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000800 int Val;
801 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
802 Offset = CurDAG->getRegister(0, MVT::i32);
803 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
804 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000805 }
806
807 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000808 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000809 return true;
810}
811
Jim Grosbach3ab56582010-10-21 19:38:40 +0000812bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000813 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000814 if (N.getOpcode() != ISD::ADD) {
815 Base = N;
816 if (N.getOpcode() == ISD::FrameIndex) {
817 int FI = cast<FrameIndexSDNode>(N)->getIndex();
818 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000819 } else if (N.getOpcode() == ARMISD::Wrapper &&
820 !(Subtarget->useMovt() &&
821 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000822 Base = N.getOperand(0);
823 }
824 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000825 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000826 return true;
827 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000828
Evan Chenga8e29892007-01-19 07:51:42 +0000829 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000830 int RHSC;
831 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
832 -256 + 1, 256, RHSC)) {
833 Base = N.getOperand(0);
834 if (Base.getOpcode() == ISD::FrameIndex) {
835 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
836 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000837 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000838
839 ARM_AM::AddrOpc AddSub = ARM_AM::add;
840 if (RHSC < 0) {
841 AddSub = ARM_AM::sub;
842 RHSC = - RHSC;
843 }
844 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
845 MVT::i32);
846 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000847 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000848
Evan Chenga8e29892007-01-19 07:51:42 +0000849 Base = N;
850 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000851 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000852 return true;
853}
854
Bob Wilson665814b2010-11-01 23:40:51 +0000855bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
856 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000857 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000858
859 unsigned Alignment = 0;
860 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
861 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
862 // The maximum alignment is equal to the memory size being referenced.
863 unsigned LSNAlign = LSN->getAlignment();
864 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
865 if (LSNAlign > MemSize && MemSize > 1)
866 Alignment = MemSize;
867 } else {
868 // All other uses of addrmode6 are for intrinsics. For now just record
869 // the raw alignment value; it will be refined later based on the legal
870 // alignment operands for the intrinsic.
871 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
872 }
873
874 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000875 return true;
876}
877
Chris Lattner52a261b2010-09-21 20:31:19 +0000878bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000879 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000880 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
881 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000882 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000883 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000884 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000885 return true;
886 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000887
Evan Chenga8e29892007-01-19 07:51:42 +0000888 return false;
889}
890
Bill Wendlingf4caf692010-12-14 03:36:38 +0000891
892//===----------------------------------------------------------------------===//
893// Thumb Addressing Modes
894//===----------------------------------------------------------------------===//
895
Chris Lattner52a261b2010-09-21 20:31:19 +0000896bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000897 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000898 // FIXME dl should come from the parent load or store, not the address
Evan Chengc38f2bc2007-01-23 22:59:13 +0000899 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000900 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000901 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000902 return false;
903
904 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000905 return true;
906 }
907
Evan Chenga8e29892007-01-19 07:51:42 +0000908 Base = N.getOperand(0);
909 Offset = N.getOperand(1);
910 return true;
911}
912
Evan Cheng79d43262007-01-24 02:21:22 +0000913bool
Bill Wendlingf4caf692010-12-14 03:36:38 +0000914ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
915 SDValue &Offset, unsigned Scale) {
Evan Cheng79d43262007-01-24 02:21:22 +0000916 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000917 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000918 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000919 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendlingf4caf692010-12-14 03:36:38 +0000920
Evan Cheng012f2d92007-01-24 08:53:17 +0000921 if (N.getOpcode() == ARMISD::Wrapper &&
922 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
923 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000924 }
925
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000926 if (N.getOpcode() != ISD::ADD)
927 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000928
Evan Chengad0e4652007-02-06 00:22:06 +0000929 // Thumb does not have [sp, r] address mode.
930 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
931 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
932 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000933 (RHSR && RHSR->getReg() == ARM::SP))
934 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000935
Daniel Dunbarec91d522011-01-19 15:12:16 +0000936 // FIXME: Why do we explicitly check for a match here and then return false?
937 // Presumably to allow something else to match, but shouldn't this be
938 // documented?
939 int RHSC;
940 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
941 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000942
943 Base = N.getOperand(0);
944 Offset = N.getOperand(1);
945 return true;
946}
947
948bool
949ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
950 SDValue &Base,
951 SDValue &Offset) {
952 return SelectThumbAddrModeRI(N, Base, Offset, 1);
953}
954
955bool
956ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
957 SDValue &Base,
958 SDValue &Offset) {
959 return SelectThumbAddrModeRI(N, Base, Offset, 2);
960}
961
962bool
963ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
964 SDValue &Base,
965 SDValue &Offset) {
966 return SelectThumbAddrModeRI(N, Base, Offset, 4);
967}
968
969bool
970ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
971 SDValue &Base, SDValue &OffImm) {
972 if (Scale == 4) {
973 SDValue TmpBase, TmpOffImm;
974 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
975 return false; // We want to select tLDRspi / tSTRspi instead.
976
977 if (N.getOpcode() == ARMISD::Wrapper &&
978 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
979 return false; // We want to select tLDRpci instead.
980 }
981
982 if (N.getOpcode() != ISD::ADD) {
983 if (N.getOpcode() == ARMISD::Wrapper &&
984 !(Subtarget->useMovt() &&
985 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
986 Base = N.getOperand(0);
987 } else {
988 Base = N;
989 }
990
Owen Anderson825b72b2009-08-11 20:47:22 +0000991 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000992 return true;
993 }
994
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000995 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
996 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
997 if ((LHSR && LHSR->getReg() == ARM::SP) ||
998 (RHSR && RHSR->getReg() == ARM::SP)) {
999 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1000 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1001 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1002 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1003
1004 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1005 if (LHSC != 0 || RHSC != 0) return false;
1006
1007 Base = N;
1008 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1009 return true;
1010 }
1011
Evan Chenga8e29892007-01-19 07:51:42 +00001012 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001013 int RHSC;
1014 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1015 Base = N.getOperand(0);
1016 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1017 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001018 }
1019
Evan Chengc38f2bc2007-01-23 22:59:13 +00001020 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001021 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +00001022 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001023}
1024
Bill Wendlingf4caf692010-12-14 03:36:38 +00001025bool
1026ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1027 SDValue &OffImm) {
1028 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001029}
1030
Bill Wendlingf4caf692010-12-14 03:36:38 +00001031bool
1032ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1033 SDValue &OffImm) {
1034 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001035}
1036
Bill Wendlingf4caf692010-12-14 03:36:38 +00001037bool
1038ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1039 SDValue &OffImm) {
1040 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001041}
1042
Chris Lattner52a261b2010-09-21 20:31:19 +00001043bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1044 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +00001045 if (N.getOpcode() == ISD::FrameIndex) {
1046 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1047 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001048 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001049 return true;
1050 }
Evan Cheng79d43262007-01-24 02:21:22 +00001051
Evan Chengad0e4652007-02-06 00:22:06 +00001052 if (N.getOpcode() != ISD::ADD)
1053 return false;
1054
1055 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001056 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1057 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +00001058 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001059 int RHSC;
1060 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1061 Base = N.getOperand(0);
1062 if (Base.getOpcode() == ISD::FrameIndex) {
1063 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1064 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng79d43262007-01-24 02:21:22 +00001065 }
Daniel Dunbarec91d522011-01-19 15:12:16 +00001066 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1067 return true;
Evan Cheng79d43262007-01-24 02:21:22 +00001068 }
1069 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001070
Evan Chenga8e29892007-01-19 07:51:42 +00001071 return false;
1072}
1073
Bill Wendlingf4caf692010-12-14 03:36:38 +00001074
1075//===----------------------------------------------------------------------===//
1076// Thumb 2 Addressing Modes
1077//===----------------------------------------------------------------------===//
1078
1079
Chris Lattner52a261b2010-09-21 20:31:19 +00001080bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001081 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001082 if (DisableShifterOp)
1083 return false;
1084
Evan Cheng9cb9e672009-06-27 02:26:13 +00001085 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
1086
1087 // Don't match base register only case. That is matched to a separate
1088 // lower complexity pattern with explicit register operand.
1089 if (ShOpcVal == ARM_AM::no_shift) return false;
1090
1091 BaseReg = N.getOperand(0);
1092 unsigned ShImmVal = 0;
1093 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1094 ShImmVal = RHS->getZExtValue() & 31;
1095 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1096 return true;
1097 }
1098
1099 return false;
1100}
1101
Chris Lattner52a261b2010-09-21 20:31:19 +00001102bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001103 SDValue &Base, SDValue &OffImm) {
1104 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001105
Evan Cheng3a214252009-08-11 08:52:18 +00001106 // Base only.
1107 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001108 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +00001109 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +00001110 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1111 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001112 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001113 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001114 } else if (N.getOpcode() == ARMISD::Wrapper &&
1115 !(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.
Evan Cheng3a214252009-08-11 08:52:18 +00001155 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +00001156 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1157 int RHSC = (int)RHS->getSExtValue();
1158 if (N.getOpcode() == ISD::SUB)
1159 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001160
Evan Cheng3a214252009-08-11 08:52:18 +00001161 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1162 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +00001163 if (Base.getOpcode() == ISD::FrameIndex) {
1164 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1165 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1166 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001167 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +00001168 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001169 }
Evan Cheng055b0312009-06-29 07:51:04 +00001170 }
1171 }
1172
1173 return false;
1174}
1175
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001176bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001177 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001178 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001179 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1180 ? cast<LoadSDNode>(Op)->getAddressingMode()
1181 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbarec91d522011-01-19 15:12:16 +00001182 int RHSC;
1183 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1184 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1185 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1186 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1187 return true;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001188 }
1189
1190 return false;
1191}
1192
Chris Lattner52a261b2010-09-21 20:31:19 +00001193bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001194 SDValue &Base,
1195 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001196 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
1197 if (N.getOpcode() != ISD::ADD)
1198 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001199
Evan Cheng3a214252009-08-11 08:52:18 +00001200 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1201 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1202 int RHSC = (int)RHS->getZExtValue();
1203 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1204 return false;
1205 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001206 return false;
1207 }
1208
Evan Chengf40deed2010-10-27 23:41:30 +00001209 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
1210 // Compute R + (R << [1,2,3]) and reuse it.
1211 Base = N;
1212 return false;
1213 }
1214
Evan Cheng055b0312009-06-29 07:51:04 +00001215 // Look for (R + R) or (R + (R << [1,2,3])).
1216 unsigned ShAmt = 0;
1217 Base = N.getOperand(0);
1218 OffReg = N.getOperand(1);
1219
1220 // Swap if it is ((R << c) + R).
1221 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
1222 if (ShOpcVal != ARM_AM::lsl) {
1223 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
1224 if (ShOpcVal == ARM_AM::lsl)
1225 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001226 }
1227
Evan Cheng055b0312009-06-29 07:51:04 +00001228 if (ShOpcVal == ARM_AM::lsl) {
1229 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1230 // it.
1231 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1232 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001233 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1234 OffReg = OffReg.getOperand(0);
1235 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001236 ShAmt = 0;
1237 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001238 }
Evan Cheng055b0312009-06-29 07:51:04 +00001239 } else {
1240 ShOpcVal = ARM_AM::no_shift;
1241 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001242 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001243
Owen Anderson825b72b2009-08-11 20:47:22 +00001244 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001245
1246 return true;
1247}
1248
1249//===--------------------------------------------------------------------===//
1250
Evan Chengee568cf2007-07-05 07:15:27 +00001251/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001252static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001253 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001254}
1255
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001256SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1257 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001258 ISD::MemIndexedMode AM = LD->getAddressingMode();
1259 if (AM == ISD::UNINDEXED)
1260 return NULL;
1261
Owen Andersone50ed302009-08-10 22:56:29 +00001262 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001263 SDValue Offset, AMOpc;
1264 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1265 unsigned Opcode = 0;
1266 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +00001267 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001268 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001269 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
1270 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +00001271 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001272 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001273 Match = true;
1274 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1275 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1276 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001277 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001278 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001279 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001280 Match = true;
1281 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1282 }
1283 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001284 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001285 Match = true;
1286 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
1287 }
1288 }
1289 }
1290
1291 if (Match) {
1292 SDValue Chain = LD->getChain();
1293 SDValue Base = LD->getBasePtr();
1294 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001295 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001296 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001297 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +00001298 }
1299
1300 return NULL;
1301}
1302
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001303SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1304 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001305 ISD::MemIndexedMode AM = LD->getAddressingMode();
1306 if (AM == ISD::UNINDEXED)
1307 return NULL;
1308
Owen Andersone50ed302009-08-10 22:56:29 +00001309 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001310 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001311 SDValue Offset;
1312 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1313 unsigned Opcode = 0;
1314 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001315 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001316 switch (LoadedVT.getSimpleVT().SimpleTy) {
1317 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001318 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1319 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001320 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001321 if (isSExtLd)
1322 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1323 else
1324 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001325 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001326 case MVT::i8:
1327 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001328 if (isSExtLd)
1329 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1330 else
1331 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001332 break;
1333 default:
1334 return NULL;
1335 }
1336 Match = true;
1337 }
1338
1339 if (Match) {
1340 SDValue Chain = LD->getChain();
1341 SDValue Base = LD->getBasePtr();
1342 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001343 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001344 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001345 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001346 }
1347
1348 return NULL;
1349}
1350
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001351/// PairSRegs - Form a D register from a pair of S registers.
1352///
1353SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1354 DebugLoc dl = V0.getNode()->getDebugLoc();
1355 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1356 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001357 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1358 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001359}
1360
Evan Cheng603afbf2010-05-10 17:34:18 +00001361/// PairDRegs - Form a quad register from a pair of D registers.
1362///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001363SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1364 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001365 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1366 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001367 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1368 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001369}
1370
Evan Cheng7f687192010-05-14 00:21:45 +00001371/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001372///
1373SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1374 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001375 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1376 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001377 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1378 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1379}
1380
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001381/// QuadSRegs - Form 4 consecutive S registers.
1382///
1383SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1384 SDValue V2, SDValue V3) {
1385 DebugLoc dl = V0.getNode()->getDebugLoc();
1386 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1387 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1388 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1389 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
1390 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1391 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1392}
1393
Evan Cheng7f687192010-05-14 00:21:45 +00001394/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001395///
1396SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1397 SDValue V2, SDValue V3) {
1398 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001399 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1400 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1401 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1402 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001403 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1404 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1405}
1406
Evan Cheng8f6de382010-05-16 03:27:48 +00001407/// QuadQRegs - Form 4 consecutive Q registers.
1408///
1409SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1410 SDValue V2, SDValue V3) {
1411 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001412 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1413 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1414 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1415 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Evan Cheng8f6de382010-05-16 03:27:48 +00001416 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1417 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1418}
1419
Bob Wilson2a6e6162010-09-23 23:42:37 +00001420/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1421/// of a NEON VLD or VST instruction. The supported values depend on the
1422/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001423SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1424 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001425 unsigned NumRegs = NumVecs;
1426 if (!is64BitVector && NumVecs < 3)
1427 NumRegs *= 2;
1428
Bob Wilson665814b2010-11-01 23:40:51 +00001429 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001430 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001431 Alignment = 32;
1432 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1433 Alignment = 16;
1434 else if (Alignment >= 8)
1435 Alignment = 8;
1436 else
1437 Alignment = 0;
1438
1439 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001440}
1441
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001442SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001443 unsigned *DOpcodes, unsigned *QOpcodes0,
1444 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001445 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001446 DebugLoc dl = N->getDebugLoc();
1447
Bob Wilson226036e2010-03-20 22:13:40 +00001448 SDValue MemAddr, Align;
Bob Wilson665814b2010-11-01 23:40:51 +00001449 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001450 return NULL;
1451
1452 SDValue Chain = N->getOperand(0);
1453 EVT VT = N->getValueType(0);
1454 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001455 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001456
Bob Wilson3e36f132009-10-14 17:28:52 +00001457 unsigned OpcodeIndex;
1458 switch (VT.getSimpleVT().SimpleTy) {
1459 default: llvm_unreachable("unhandled vld type");
1460 // Double-register operations:
1461 case MVT::v8i8: OpcodeIndex = 0; break;
1462 case MVT::v4i16: OpcodeIndex = 1; break;
1463 case MVT::v2f32:
1464 case MVT::v2i32: OpcodeIndex = 2; break;
1465 case MVT::v1i64: OpcodeIndex = 3; break;
1466 // Quad-register operations:
1467 case MVT::v16i8: OpcodeIndex = 0; break;
1468 case MVT::v8i16: OpcodeIndex = 1; break;
1469 case MVT::v4f32:
1470 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001471 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001472 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001473 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001474 }
1475
Bob Wilsonf5721912010-09-03 18:16:02 +00001476 EVT ResTy;
1477 if (NumVecs == 1)
1478 ResTy = VT;
1479 else {
1480 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1481 if (!is64BitVector)
1482 ResTyElts *= 2;
1483 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1484 }
1485
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001486 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001487 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilsonf5721912010-09-03 18:16:02 +00001488 SDValue SuperReg;
Bob Wilson3e36f132009-10-14 17:28:52 +00001489 if (is64BitVector) {
1490 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001491 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilsonf5721912010-09-03 18:16:02 +00001492 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
Bob Wilsonffde0802010-09-02 16:00:54 +00001493 if (NumVecs == 1)
Evan Chenge9e2ba02010-05-10 21:26:24 +00001494 return VLd;
1495
Bob Wilsonf5721912010-09-03 18:16:02 +00001496 SuperReg = SDValue(VLd, 0);
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001497 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
Evan Cheng5c6aba22010-05-14 18:54:59 +00001498 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001499 SDValue D = CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec,
Bob Wilsonffde0802010-09-02 16:00:54 +00001500 dl, VT, SuperReg);
Evan Cheng5c6aba22010-05-14 18:54:59 +00001501 ReplaceUses(SDValue(N, Vec), D);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001502 }
Bob Wilsonf5721912010-09-03 18:16:02 +00001503 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
Evan Chenge9e2ba02010-05-10 21:26:24 +00001504 return NULL;
Bob Wilson3e36f132009-10-14 17:28:52 +00001505 }
1506
Bob Wilson621f1952010-03-23 05:25:43 +00001507 if (NumVecs <= 2) {
1508 // Quad registers are directly supported for VLD1 and VLD2,
1509 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001510 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001511 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilsonffde0802010-09-02 16:00:54 +00001512 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
Bob Wilsonffde0802010-09-02 16:00:54 +00001513 if (NumVecs == 1)
1514 return VLd;
1515
Bob Wilsonf5721912010-09-03 18:16:02 +00001516 SuperReg = SDValue(VLd, 0);
Bob Wilsonffde0802010-09-02 16:00:54 +00001517 Chain = SDValue(VLd, 1);
1518
Bob Wilson3e36f132009-10-14 17:28:52 +00001519 } else {
1520 // Otherwise, quad registers are loaded with two separate instructions,
1521 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001522 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001523
Bob Wilson24f995d2009-10-14 18:32:29 +00001524 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001525 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsonf5721912010-09-03 18:16:02 +00001526 SDValue ImplDef =
1527 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1528 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
1529 SDNode *VLdA =
1530 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsA, 7);
1531 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001532
Bob Wilson24f995d2009-10-14 18:32:29 +00001533 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001534 Opc = QOpcodes1[OpcodeIndex];
Bob Wilsonf5721912010-09-03 18:16:02 +00001535 const SDValue OpsB[] = { SDValue(VLdA, 1), Align, Reg0, SDValue(VLdA, 0),
1536 Pred, Reg0, Chain };
1537 SDNode *VLdB =
1538 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsB, 7);
1539 SuperReg = SDValue(VLdB, 0);
1540 Chain = SDValue(VLdB, 2);
1541 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001542
Bob Wilsonf5721912010-09-03 18:16:02 +00001543 // Extract out the Q registers.
1544 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1545 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1546 SDValue Q = CurDAG->getTargetExtractSubreg(ARM::qsub_0+Vec,
1547 dl, VT, SuperReg);
1548 ReplaceUses(SDValue(N, Vec), Q);
Bob Wilson3e36f132009-10-14 17:28:52 +00001549 }
1550 ReplaceUses(SDValue(N, NumVecs), Chain);
1551 return NULL;
1552}
1553
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001554SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001555 unsigned *DOpcodes, unsigned *QOpcodes0,
1556 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001557 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001558 DebugLoc dl = N->getDebugLoc();
1559
Bob Wilson226036e2010-03-20 22:13:40 +00001560 SDValue MemAddr, Align;
Bob Wilson665814b2010-11-01 23:40:51 +00001561 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001562 return NULL;
1563
1564 SDValue Chain = N->getOperand(0);
1565 EVT VT = N->getOperand(3).getValueType();
1566 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001567 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001568
Bob Wilson24f995d2009-10-14 18:32:29 +00001569 unsigned OpcodeIndex;
1570 switch (VT.getSimpleVT().SimpleTy) {
1571 default: llvm_unreachable("unhandled vst type");
1572 // Double-register operations:
1573 case MVT::v8i8: OpcodeIndex = 0; break;
1574 case MVT::v4i16: OpcodeIndex = 1; break;
1575 case MVT::v2f32:
1576 case MVT::v2i32: OpcodeIndex = 2; break;
1577 case MVT::v1i64: OpcodeIndex = 3; break;
1578 // Quad-register operations:
1579 case MVT::v16i8: OpcodeIndex = 0; break;
1580 case MVT::v8i16: OpcodeIndex = 1; break;
1581 case MVT::v4f32:
1582 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001583 case MVT::v2i64: OpcodeIndex = 3;
1584 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1585 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001586 }
1587
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001588 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001589 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001590
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001591 SmallVector<SDValue, 7> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001592 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001593 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001594
1595 if (is64BitVector) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001596 if (NumVecs == 1) {
1597 Ops.push_back(N->getOperand(3));
1598 } else {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001599 SDValue RegSeq;
1600 SDValue V0 = N->getOperand(0+3);
1601 SDValue V1 = N->getOperand(1+3);
1602
1603 // Form a REG_SEQUENCE to force register allocation.
1604 if (NumVecs == 2)
1605 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1606 else {
1607 SDValue V2 = N->getOperand(2+3);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001608 // If it's a vld3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001609 // an undef.
1610 SDValue V3 = (NumVecs == 3)
1611 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1612 : N->getOperand(3+3);
1613 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1614 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001615 Ops.push_back(RegSeq);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001616 }
Evan Chengac0869d2009-11-21 06:21:52 +00001617 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001618 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001619 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001620 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001621 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001622 }
1623
Bob Wilson11d98992010-03-23 06:20:33 +00001624 if (NumVecs <= 2) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001625 // Quad registers are directly supported for VST1 and VST2.
Bob Wilson24f995d2009-10-14 18:32:29 +00001626 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001627 if (NumVecs == 1) {
1628 Ops.push_back(N->getOperand(3));
1629 } else {
1630 // Form a QQ register.
Evan Cheng603afbf2010-05-10 17:34:18 +00001631 SDValue Q0 = N->getOperand(3);
1632 SDValue Q1 = N->getOperand(4);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001633 Ops.push_back(SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0));
Bob Wilson24f995d2009-10-14 18:32:29 +00001634 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001635 Ops.push_back(Pred);
1636 Ops.push_back(Reg0); // predicate register
1637 Ops.push_back(Chain);
1638 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001639 }
1640
1641 // Otherwise, quad registers are stored with two separate instructions,
1642 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001643
Bob Wilson07f6e802010-06-16 21:34:01 +00001644 // Form the QQQQ REG_SEQUENCE.
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001645 SDValue V0 = N->getOperand(0+3);
1646 SDValue V1 = N->getOperand(1+3);
1647 SDValue V2 = N->getOperand(2+3);
1648 SDValue V3 = (NumVecs == 3)
1649 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1650 : N->getOperand(3+3);
1651 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001652
1653 // Store the even D registers.
Bob Wilson07f6e802010-06-16 21:34:01 +00001654 Ops.push_back(Reg0); // post-access address offset
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001655 Ops.push_back(RegSeq);
Bob Wilson07f6e802010-06-16 21:34:01 +00001656 Ops.push_back(Pred);
1657 Ops.push_back(Reg0); // predicate register
1658 Ops.push_back(Chain);
1659 unsigned Opc = QOpcodes0[OpcodeIndex];
1660 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001661 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001662 Chain = SDValue(VStA, 1);
1663
1664 // Store the odd D registers.
1665 Ops[0] = SDValue(VStA, 0); // MemAddr
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001666 Ops[6] = Chain;
Bob Wilson07f6e802010-06-16 21:34:01 +00001667 Opc = QOpcodes1[OpcodeIndex];
1668 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001669 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001670 Chain = SDValue(VStB, 1);
1671 ReplaceUses(SDValue(N, 0), Chain);
1672 return NULL;
Bob Wilson24f995d2009-10-14 18:32:29 +00001673}
1674
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001675SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001676 unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001677 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001678 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001679 DebugLoc dl = N->getDebugLoc();
1680
Bob Wilson226036e2010-03-20 22:13:40 +00001681 SDValue MemAddr, Align;
Bob Wilson665814b2010-11-01 23:40:51 +00001682 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001683 return NULL;
1684
1685 SDValue Chain = N->getOperand(0);
1686 unsigned Lane =
1687 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001688 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001689 bool is64BitVector = VT.is64BitVector();
1690
Bob Wilson665814b2010-11-01 23:40:51 +00001691 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001692 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001693 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001694 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1695 if (Alignment > NumBytes)
1696 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001697 if (Alignment < 8 && Alignment < NumBytes)
1698 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001699 // Alignment must be a power of two; make sure of that.
1700 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001701 if (Alignment == 1)
1702 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001703 }
Bob Wilson665814b2010-11-01 23:40:51 +00001704 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001705
Bob Wilsona7c397c2009-10-14 16:19:03 +00001706 unsigned OpcodeIndex;
1707 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001708 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001709 // Double-register operations:
1710 case MVT::v8i8: OpcodeIndex = 0; break;
1711 case MVT::v4i16: OpcodeIndex = 1; break;
1712 case MVT::v2f32:
1713 case MVT::v2i32: OpcodeIndex = 2; break;
1714 // Quad-register operations:
1715 case MVT::v8i16: OpcodeIndex = 0; break;
1716 case MVT::v4f32:
1717 case MVT::v4i32: OpcodeIndex = 1; break;
1718 }
1719
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001720 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001721 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001722
Bob Wilson8466fa12010-09-13 23:01:35 +00001723 SmallVector<SDValue, 7> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001724 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001725 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001726
Jim Grosbach3ab56582010-10-21 19:38:40 +00001727 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
Eric Christopher23da0b22010-09-14 08:31:25 +00001728 QOpcodes[OpcodeIndex]);
Bob Wilson07f6e802010-06-16 21:34:01 +00001729
Bob Wilson8466fa12010-09-13 23:01:35 +00001730 SDValue SuperReg;
1731 SDValue V0 = N->getOperand(0+3);
1732 SDValue V1 = N->getOperand(1+3);
1733 if (NumVecs == 2) {
1734 if (is64BitVector)
1735 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1736 else
1737 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001738 } else {
Bob Wilson8466fa12010-09-13 23:01:35 +00001739 SDValue V2 = N->getOperand(2+3);
1740 SDValue V3 = (NumVecs == 3)
1741 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1742 : N->getOperand(3+3);
1743 if (is64BitVector)
1744 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1745 else
1746 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001747 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001748 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001749 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001750 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001751 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001752 Ops.push_back(Chain);
1753
Bob Wilson96493442009-10-14 16:46:45 +00001754 if (!IsLoad)
Bob Wilson8466fa12010-09-13 23:01:35 +00001755 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 7);
Bob Wilson96493442009-10-14 16:46:45 +00001756
Bob Wilson8466fa12010-09-13 23:01:35 +00001757 EVT ResTy;
1758 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1759 if (!is64BitVector)
1760 ResTyElts *= 2;
1761 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001762
Bob Wilson8466fa12010-09-13 23:01:35 +00001763 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other,
1764 Ops.data(), 7);
1765 SuperReg = SDValue(VLdLn, 0);
1766 Chain = SDValue(VLdLn, 1);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001767
Bob Wilson8466fa12010-09-13 23:01:35 +00001768 // Extract the subregisters.
Bob Wilson07f6e802010-06-16 21:34:01 +00001769 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1770 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1771 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
1772 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1773 ReplaceUses(SDValue(N, Vec),
Bob Wilson8466fa12010-09-13 23:01:35 +00001774 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
1775 ReplaceUses(SDValue(N, NumVecs), Chain);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001776 return NULL;
1777}
1778
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001779SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, unsigned NumVecs,
1780 unsigned *Opcodes) {
1781 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1782 DebugLoc dl = N->getDebugLoc();
1783
1784 SDValue MemAddr, Align;
1785 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1786 return NULL;
1787
1788 SDValue Chain = N->getOperand(0);
1789 EVT VT = N->getValueType(0);
1790
1791 unsigned Alignment = 0;
1792 if (NumVecs != 3) {
1793 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1794 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1795 if (Alignment > NumBytes)
1796 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001797 if (Alignment < 8 && Alignment < NumBytes)
1798 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001799 // Alignment must be a power of two; make sure of that.
1800 Alignment = (Alignment & -Alignment);
1801 if (Alignment == 1)
1802 Alignment = 0;
1803 }
1804 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1805
1806 unsigned OpcodeIndex;
1807 switch (VT.getSimpleVT().SimpleTy) {
1808 default: llvm_unreachable("unhandled vld-dup type");
1809 case MVT::v8i8: OpcodeIndex = 0; break;
1810 case MVT::v4i16: OpcodeIndex = 1; break;
1811 case MVT::v2f32:
1812 case MVT::v2i32: OpcodeIndex = 2; break;
1813 }
1814
1815 SDValue Pred = getAL(CurDAG);
1816 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1817 SDValue SuperReg;
1818 unsigned Opc = Opcodes[OpcodeIndex];
1819 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
1820
1821 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1822 EVT ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1823 SDNode *VLdDup = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
1824 SuperReg = SDValue(VLdDup, 0);
1825 Chain = SDValue(VLdDup, 1);
1826
1827 // Extract the subregisters.
1828 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1829 unsigned SubIdx = ARM::dsub_0;
1830 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1831 ReplaceUses(SDValue(N, Vec),
1832 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
1833 ReplaceUses(SDValue(N, NumVecs), Chain);
1834 return NULL;
1835}
1836
Bob Wilson78dfbc32010-07-07 00:08:54 +00001837SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1838 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001839 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1840 DebugLoc dl = N->getDebugLoc();
1841 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001842 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001843
1844 // Form a REG_SEQUENCE to force register allocation.
1845 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001846 SDValue V0 = N->getOperand(FirstTblReg + 0);
1847 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001848 if (NumVecs == 2)
1849 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1850 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001851 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001852 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00001853 // an undef.
1854 SDValue V3 = (NumVecs == 3)
1855 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001856 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001857 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1858 }
1859
Bob Wilson78dfbc32010-07-07 00:08:54 +00001860 SmallVector<SDValue, 6> Ops;
1861 if (IsExt)
1862 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00001863 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001864 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001865 Ops.push_back(getAL(CurDAG)); // predicate
1866 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001867 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001868}
1869
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001870SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001871 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001872 if (!Subtarget->hasV6T2Ops())
1873 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001874
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001875 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1876 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1877
1878
1879 // For unsigned extracts, check for a shift right and mask
1880 unsigned And_imm = 0;
1881 if (N->getOpcode() == ISD::AND) {
1882 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1883
1884 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1885 if (And_imm & (And_imm + 1))
1886 return NULL;
1887
1888 unsigned Srl_imm = 0;
1889 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1890 Srl_imm)) {
1891 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1892
1893 unsigned Width = CountTrailingOnes_32(And_imm);
1894 unsigned LSB = Srl_imm;
1895 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1896 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1897 CurDAG->getTargetConstant(LSB, MVT::i32),
1898 CurDAG->getTargetConstant(Width, MVT::i32),
1899 getAL(CurDAG), Reg0 };
1900 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1901 }
1902 }
1903 return NULL;
1904 }
1905
1906 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001907 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001908 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001909 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1910 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001911 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001912 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1913 unsigned Width = 32 - Srl_imm;
1914 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001915 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001916 return NULL;
1917 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001918 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001919 CurDAG->getTargetConstant(LSB, MVT::i32),
1920 CurDAG->getTargetConstant(Width, MVT::i32),
1921 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001922 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001923 }
1924 }
1925 return NULL;
1926}
1927
Evan Cheng9ef48352009-11-20 00:54:03 +00001928SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001929SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001930 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1931 SDValue CPTmp0;
1932 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00001933 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001934 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1935 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1936 unsigned Opc = 0;
1937 switch (SOShOp) {
1938 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1939 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1940 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1941 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1942 default:
1943 llvm_unreachable("Unknown so_reg opcode!");
1944 break;
1945 }
1946 SDValue SOShImm =
1947 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1948 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1949 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001950 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001951 }
1952 return 0;
1953}
1954
1955SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001956SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001957 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1958 SDValue CPTmp0;
1959 SDValue CPTmp1;
1960 SDValue CPTmp2;
Chris Lattner52a261b2010-09-21 20:31:19 +00001961 if (SelectShifterOperandReg(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001962 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1963 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001964 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001965 }
1966 return 0;
1967}
1968
1969SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00001970SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00001971 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001972 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00001973 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00001974 return 0;
1975
Evan Cheng63f35442010-11-13 02:25:14 +00001976 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00001977 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00001978 if (is_t2_so_imm(TrueImm)) {
1979 Opc = ARM::t2MOVCCi;
1980 } else if (TrueImm <= 0xffff) {
1981 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00001982 } else if (is_t2_so_imm_not(TrueImm)) {
1983 TrueImm = ~TrueImm;
1984 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00001985 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00001986 // Large immediate.
1987 Opc = ARM::t2MOVCCi32imm;
1988 }
1989
1990 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00001991 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00001992 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1993 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00001994 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00001995 }
Evan Cheng63f35442010-11-13 02:25:14 +00001996
Evan Cheng9ef48352009-11-20 00:54:03 +00001997 return 0;
1998}
1999
2000SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002001SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002002 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002003 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2004 if (!T)
2005 return 0;
2006
Evan Cheng63f35442010-11-13 02:25:14 +00002007 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002008 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002009 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002010 if (isSoImm) {
2011 Opc = ARM::MOVCCi;
2012 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2013 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002014 } else if (is_so_imm_not(TrueImm)) {
2015 TrueImm = ~TrueImm;
2016 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002017 } else if (TrueVal.getNode()->hasOneUse() &&
2018 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002019 // Large immediate.
2020 Opc = ARM::MOVCCi32imm;
2021 }
2022
2023 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002024 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002025 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2026 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002027 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002028 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002029
Evan Cheng9ef48352009-11-20 00:54:03 +00002030 return 0;
2031}
2032
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002033SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2034 EVT VT = N->getValueType(0);
2035 SDValue FalseVal = N->getOperand(0);
2036 SDValue TrueVal = N->getOperand(1);
2037 SDValue CC = N->getOperand(2);
2038 SDValue CCR = N->getOperand(3);
2039 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002040 assert(CC.getOpcode() == ISD::Constant);
2041 assert(CCR.getOpcode() == ISD::Register);
2042 ARMCC::CondCodes CCVal =
2043 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002044
2045 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2046 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2047 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2048 // Pattern complexity = 18 cost = 1 size = 0
2049 SDValue CPTmp0;
2050 SDValue CPTmp1;
2051 SDValue CPTmp2;
2052 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002053 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002054 CCVal, CCR, InFlag);
2055 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002056 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002057 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2058 if (Res)
2059 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002060 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002061 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002062 CCVal, CCR, InFlag);
2063 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002064 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002065 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2066 if (Res)
2067 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002068 }
2069
2070 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002071 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002072 // (imm:i32):$cc)
2073 // Emits: (MOVCCi:i32 GPR:i32:$false,
2074 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2075 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002076 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002077 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002078 CCVal, CCR, InFlag);
2079 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002080 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002081 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2082 if (Res)
2083 return Res;
2084 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002085 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002086 CCVal, CCR, InFlag);
2087 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002088 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002089 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2090 if (Res)
2091 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002092 }
2093 }
2094
2095 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2096 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2097 // Pattern complexity = 6 cost = 1 size = 0
2098 //
2099 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2100 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2101 // Pattern complexity = 6 cost = 11 size = 0
2102 //
2103 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002104 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2105 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002106 unsigned Opc = 0;
2107 switch (VT.getSimpleVT().SimpleTy) {
2108 default: assert(false && "Illegal conditional move type!");
2109 break;
2110 case MVT::i32:
2111 Opc = Subtarget->isThumb()
2112 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2113 : ARM::MOVCCr;
2114 break;
2115 case MVT::f32:
2116 Opc = ARM::VMOVScc;
2117 break;
2118 case MVT::f64:
2119 Opc = ARM::VMOVDcc;
2120 break;
2121 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002122 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002123}
2124
Evan Chengde8aa4e2010-05-05 18:28:36 +00002125SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2126 // The only time a CONCAT_VECTORS operation can have legal types is when
2127 // two 64-bit vectors are concatenated to a 128-bit vector.
2128 EVT VT = N->getValueType(0);
2129 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2130 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002131 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002132}
2133
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002134SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002135 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002136
Dan Gohmane8be6c62008-07-17 19:10:17 +00002137 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002138 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002139
2140 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002141 default: break;
2142 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002143 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002144 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002145 if (Subtarget->hasThumb2())
2146 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2147 // be done with MOV + MOVT, at worst.
2148 UseCP = 0;
2149 else {
2150 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002151 UseCP = (Val > 255 && // MOV
2152 ~Val > 255 && // MOV + MVN
2153 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002154 } else
2155 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2156 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2157 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2158 }
2159
Evan Chenga8e29892007-01-19 07:51:42 +00002160 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002161 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002162 CurDAG->getTargetConstantPool(ConstantInt::get(
2163 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002164 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002165
2166 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002167 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002168 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002169 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002170 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002171 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002172 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002173 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002174 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002175 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002176 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002177 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002178 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002179 CurDAG->getEntryNode()
2180 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002181 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002182 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002183 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002184 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002185 return NULL;
2186 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002187
Evan Chenga8e29892007-01-19 07:51:42 +00002188 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002189 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002190 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002191 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002192 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002193 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002194 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002195 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00002196 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
2197 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002198 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002199 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2200 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002201 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2202 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2203 CurDAG->getRegister(0, MVT::i32) };
2204 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002205 }
Evan Chenga8e29892007-01-19 07:51:42 +00002206 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002207 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002208 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002209 return I;
2210 break;
2211 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002212 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002213 return I;
2214 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002215 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002216 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002217 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002218 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002219 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002220 if (!RHSV) break;
2221 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002222 unsigned ShImm = Log2_32(RHSV-1);
2223 if (ShImm >= 32)
2224 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002225 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002226 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002227 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2228 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002229 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002230 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002231 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002232 } else {
2233 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002234 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002235 }
Evan Chenga8e29892007-01-19 07:51:42 +00002236 }
2237 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002238 unsigned ShImm = Log2_32(RHSV+1);
2239 if (ShImm >= 32)
2240 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002241 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002242 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002243 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2244 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002245 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002246 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2247 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002248 } else {
2249 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002250 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002251 }
Evan Chenga8e29892007-01-19 07:51:42 +00002252 }
2253 }
2254 break;
Evan Cheng20956592009-10-21 08:15:52 +00002255 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002256 // Check for unsigned bitfield extract
2257 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2258 return I;
2259
Evan Cheng20956592009-10-21 08:15:52 +00002260 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2261 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2262 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2263 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2264 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002265 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002266 if (VT != MVT::i32)
2267 break;
2268 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2269 ? ARM::t2MOVTi16
2270 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2271 if (!Opc)
2272 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002273 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002274 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2275 if (!N1C)
2276 break;
2277 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2278 SDValue N2 = N0.getOperand(1);
2279 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2280 if (!N2C)
2281 break;
2282 unsigned N1CVal = N1C->getZExtValue();
2283 unsigned N2CVal = N2C->getZExtValue();
2284 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2285 (N1CVal & 0xffffU) == 0xffffU &&
2286 (N2CVal & 0xffffU) == 0x0U) {
2287 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2288 MVT::i32);
2289 SDValue Ops[] = { N0.getOperand(0), Imm16,
2290 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2291 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2292 }
2293 }
2294 break;
2295 }
Jim Grosbache5165492009-11-09 00:11:35 +00002296 case ARMISD::VMOVRRD:
2297 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002298 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002299 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002300 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002301 if (Subtarget->isThumb1Only())
2302 break;
2303 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002304 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002305 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2306 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002307 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002308 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002309 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002310 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2311 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002312 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2313 ARM::UMULL : ARM::UMULLv5,
2314 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002315 }
Evan Chengee568cf2007-07-05 07:15:27 +00002316 }
Dan Gohman525178c2007-10-08 18:33:35 +00002317 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002318 if (Subtarget->isThumb1Only())
2319 break;
2320 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002321 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002322 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002323 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002324 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002325 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002326 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2327 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002328 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2329 ARM::SMULL : ARM::SMULLv5,
2330 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002331 }
Evan Chengee568cf2007-07-05 07:15:27 +00002332 }
Evan Chenga8e29892007-01-19 07:51:42 +00002333 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002334 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002335 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002336 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002337 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002338 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002339 if (ResNode)
2340 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002341 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002342 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002343 }
Evan Chengee568cf2007-07-05 07:15:27 +00002344 case ARMISD::BRCOND: {
2345 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2346 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2347 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002348
Evan Chengee568cf2007-07-05 07:15:27 +00002349 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2350 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2351 // Pattern complexity = 6 cost = 1 size = 0
2352
David Goodwin5e47a9a2009-06-30 18:04:13 +00002353 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2354 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2355 // Pattern complexity = 6 cost = 1 size = 0
2356
Jim Grosbach764ab522009-08-11 15:33:49 +00002357 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002358 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002359 SDValue Chain = N->getOperand(0);
2360 SDValue N1 = N->getOperand(1);
2361 SDValue N2 = N->getOperand(2);
2362 SDValue N3 = N->getOperand(3);
2363 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002364 assert(N1.getOpcode() == ISD::BasicBlock);
2365 assert(N2.getOpcode() == ISD::Constant);
2366 assert(N3.getOpcode() == ISD::Register);
2367
Dan Gohman475871a2008-07-27 21:46:04 +00002368 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002369 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002370 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002371 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002372 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002373 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002374 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002375 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002376 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002377 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002378 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002379 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002380 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002381 return NULL;
2382 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002383 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002384 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002385 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002386 EVT VT = N->getValueType(0);
2387 SDValue N0 = N->getOperand(0);
2388 SDValue N1 = N->getOperand(1);
2389 SDValue N2 = N->getOperand(2);
2390 SDValue N3 = N->getOperand(3);
2391 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002392 assert(N2.getOpcode() == ISD::Constant);
2393 assert(N3.getOpcode() == ISD::Register);
2394
Dan Gohman475871a2008-07-27 21:46:04 +00002395 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002396 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002397 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002398 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002399 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002400 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002401 default: assert(false && "Illegal conditional move type!");
2402 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002403 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002404 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002405 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002406 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002407 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002408 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002409 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002410 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002411 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002412
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002413 case ARMISD::VZIP: {
2414 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002415 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002416 switch (VT.getSimpleVT().SimpleTy) {
2417 default: return NULL;
2418 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2419 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2420 case MVT::v2f32:
2421 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2422 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2423 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2424 case MVT::v4f32:
2425 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2426 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002427 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002428 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2429 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2430 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002431 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002432 case ARMISD::VUZP: {
2433 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002434 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002435 switch (VT.getSimpleVT().SimpleTy) {
2436 default: return NULL;
2437 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2438 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2439 case MVT::v2f32:
2440 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2441 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2442 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2443 case MVT::v4f32:
2444 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2445 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002446 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002447 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2448 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2449 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002450 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002451 case ARMISD::VTRN: {
2452 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002453 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002454 switch (VT.getSimpleVT().SimpleTy) {
2455 default: return NULL;
2456 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2457 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2458 case MVT::v2f32:
2459 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2460 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2461 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2462 case MVT::v4f32:
2463 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2464 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002465 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002466 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2467 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2468 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002469 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002470 case ARMISD::BUILD_VECTOR: {
2471 EVT VecVT = N->getValueType(0);
2472 EVT EltVT = VecVT.getVectorElementType();
2473 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002474 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002475 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2476 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2477 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002478 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002479 if (NumElts == 2)
2480 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2481 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2482 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2483 N->getOperand(2), N->getOperand(3));
2484 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002485
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002486 case ARMISD::VLD2DUP: {
2487 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2488 ARM::VLD2DUPd32Pseudo };
2489 return SelectVLDDup(N, 2, Opcodes);
2490 }
2491
Bob Wilson86c6d802010-11-29 19:35:29 +00002492 case ARMISD::VLD3DUP: {
2493 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2494 ARM::VLD3DUPd32Pseudo };
2495 return SelectVLDDup(N, 3, Opcodes);
2496 }
2497
Bob Wilson6c4c9822010-11-30 00:00:35 +00002498 case ARMISD::VLD4DUP: {
2499 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2500 ARM::VLD4DUPd32Pseudo };
2501 return SelectVLDDup(N, 4, Opcodes);
2502 }
2503
Bob Wilson31fb12f2009-08-26 17:39:53 +00002504 case ISD::INTRINSIC_VOID:
2505 case ISD::INTRINSIC_W_CHAIN: {
2506 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002507 switch (IntNo) {
2508 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002509 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002510
Bob Wilson621f1952010-03-23 05:25:43 +00002511 case Intrinsic::arm_neon_vld1: {
2512 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2513 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002514 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2515 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson621f1952010-03-23 05:25:43 +00002516 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2517 }
2518
Bob Wilson31fb12f2009-08-26 17:39:53 +00002519 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002520 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2521 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2522 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2523 ARM::VLD2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002524 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002525 }
2526
2527 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002528 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2529 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2530 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2531 ARM::VLD3q16Pseudo_UPD,
2532 ARM::VLD3q32Pseudo_UPD };
2533 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2534 ARM::VLD3q16oddPseudo_UPD,
2535 ARM::VLD3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002536 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002537 }
2538
2539 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002540 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2541 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2542 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2543 ARM::VLD4q16Pseudo_UPD,
2544 ARM::VLD4q32Pseudo_UPD };
2545 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2546 ARM::VLD4q16oddPseudo_UPD,
2547 ARM::VLD4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002548 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002549 }
2550
Bob Wilson243fcc52009-09-01 04:26:28 +00002551 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002552 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2553 ARM::VLD2LNd32Pseudo };
2554 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
2555 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002556 }
2557
2558 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002559 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2560 ARM::VLD3LNd32Pseudo };
2561 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
2562 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002563 }
2564
2565 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002566 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2567 ARM::VLD4LNd32Pseudo };
2568 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
2569 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002570 }
2571
Bob Wilson11d98992010-03-23 06:20:33 +00002572 case Intrinsic::arm_neon_vst1: {
2573 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2574 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002575 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2576 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson11d98992010-03-23 06:20:33 +00002577 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2578 }
2579
Bob Wilson31fb12f2009-08-26 17:39:53 +00002580 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002581 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2582 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2583 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2584 ARM::VST2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002585 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002586 }
2587
2588 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002589 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2590 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2591 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2592 ARM::VST3q16Pseudo_UPD,
2593 ARM::VST3q32Pseudo_UPD };
2594 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2595 ARM::VST3q16oddPseudo_UPD,
2596 ARM::VST3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002597 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002598 }
2599
2600 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002601 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002602 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002603 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2604 ARM::VST4q16Pseudo_UPD,
2605 ARM::VST4q32Pseudo_UPD };
2606 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2607 ARM::VST4q16oddPseudo_UPD,
2608 ARM::VST4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002609 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002610 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002611
2612 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002613 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2614 ARM::VST2LNd32Pseudo };
2615 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
2616 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002617 }
2618
2619 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002620 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2621 ARM::VST3LNd32Pseudo };
2622 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
2623 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002624 }
2625
2626 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002627 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2628 ARM::VST4LNd32Pseudo };
2629 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
2630 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002631 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002632 }
Bob Wilson429009b2010-05-06 16:05:26 +00002633 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002634 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002635
Bob Wilsond491d6e2010-07-06 23:36:25 +00002636 case ISD::INTRINSIC_WO_CHAIN: {
2637 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2638 switch (IntNo) {
2639 default:
2640 break;
2641
2642 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002643 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002644 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002645 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002646 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002647 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002648
2649 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002650 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002651 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002652 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002653 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002654 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002655 }
2656 break;
2657 }
2658
Bob Wilson429009b2010-05-06 16:05:26 +00002659 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002660 return SelectConcatVector(N);
2661 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002662
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002663 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002664}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002665
Bob Wilson224c2442009-05-19 05:53:42 +00002666bool ARMDAGToDAGISel::
2667SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2668 std::vector<SDValue> &OutOps) {
2669 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002670 // Require the address to be in a register. That is safe for all ARM
2671 // variants and it is hard to do anything much smarter without knowing
2672 // how the operand is used.
2673 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002674 return false;
2675}
2676
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002677/// createARMISelDag - This pass converts a legalized DAG into a
2678/// ARM-specific DAG, ready for instruction scheduling.
2679///
Bob Wilson522ce972009-09-28 14:30:20 +00002680FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2681 CodeGenOpt::Level OptLevel) {
2682 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002683}