blob: f96f68fa16aae2fa70ce08c9efe583171510eef1 [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
Chris Lattner52a261b2010-09-21 20:31:19 +0000130 bool SelectAddrModePC(SDValue N, SDValue &Offset,
Bob Wilson8b024a52009-07-01 23:16:05 +0000131 SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +0000132
Chris Lattner52a261b2010-09-21 20:31:19 +0000133 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
134 bool SelectThumbAddrModeRI5(SDValue N, unsigned Scale,
Dan Gohman475871a2008-07-27 21:46:04 +0000135 SDValue &Base, SDValue &OffImm,
136 SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000137 bool SelectThumbAddrModeS1(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000138 SDValue &OffImm, SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000139 bool SelectThumbAddrModeS2(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000140 SDValue &OffImm, SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000141 bool SelectThumbAddrModeS4(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000142 SDValue &OffImm, SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000143 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000144
Chris Lattner52a261b2010-09-21 20:31:19 +0000145 bool SelectT2ShifterOperandReg(SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000146 SDValue &BaseReg, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000147 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
148 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000149 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000150 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000151 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000152 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000153 SDValue &OffReg, SDValue &ShImm);
154
Evan Cheng875a6ac2010-11-12 22:42:47 +0000155 inline bool is_so_imm(unsigned Imm) const {
156 return ARM_AM::getSOImmVal(Imm) != -1;
157 }
158
159 inline bool is_so_imm_not(unsigned Imm) const {
160 return ARM_AM::getSOImmVal(~Imm) != -1;
161 }
162
163 inline bool is_t2_so_imm(unsigned Imm) const {
164 return ARM_AM::getT2SOImmVal(Imm) != -1;
165 }
166
167 inline bool is_t2_so_imm_not(unsigned Imm) const {
168 return ARM_AM::getT2SOImmVal(~Imm) != -1;
169 }
170
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000171 inline bool Pred_so_imm(SDNode *inN) const {
172 ConstantSDNode *N = cast<ConstantSDNode>(inN);
Evan Cheng875a6ac2010-11-12 22:42:47 +0000173 return is_so_imm(N->getZExtValue());
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000174 }
175
176 inline bool Pred_t2_so_imm(SDNode *inN) const {
177 ConstantSDNode *N = cast<ConstantSDNode>(inN);
Evan Cheng875a6ac2010-11-12 22:42:47 +0000178 return is_t2_so_imm(N->getZExtValue());
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000179 }
180
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000181 // Include the pieces autogenerated from the target description.
182#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000183
184private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000185 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
186 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000187 SDNode *SelectARMIndexedLoad(SDNode *N);
188 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000189
Bob Wilson621f1952010-03-23 05:25:43 +0000190 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
191 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000192 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000193 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000194 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000195 unsigned *QOpcodes0, unsigned *QOpcodes1);
196
Bob Wilson24f995d2009-10-14 18:32:29 +0000197 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000198 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000199 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000200 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000201 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000202 unsigned *QOpcodes0, unsigned *QOpcodes1);
203
Bob Wilson96493442009-10-14 16:46:45 +0000204 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000205 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson8466fa12010-09-13 23:01:35 +0000206 /// load/store of D registers and Q registers.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000207 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
Bob Wilson8466fa12010-09-13 23:01:35 +0000208 unsigned *DOpcodes, unsigned *QOpcodes);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000209
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000210 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
211 /// should be 2, 3 or 4. The opcode array specifies the instructions used
212 /// for loading D registers. (Q registers are not supported.)
213 SDNode *SelectVLDDup(SDNode *N, unsigned NumVecs, unsigned *Opcodes);
214
Bob Wilson78dfbc32010-07-07 00:08:54 +0000215 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
216 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
217 /// generated to force the table registers to be consecutive.
218 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000219
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000220 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000221 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000222
Evan Cheng07ba9062009-11-19 21:45:22 +0000223 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000224 SDNode *SelectCMOVOp(SDNode *N);
225 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000226 ARMCC::CondCodes CCVal, SDValue CCR,
227 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000228 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000229 ARMCC::CondCodes CCVal, SDValue CCR,
230 SDValue InFlag);
Jim Grosbacha4257162010-10-07 00:53:56 +0000231 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000232 ARMCC::CondCodes CCVal, SDValue CCR,
233 SDValue InFlag);
Jim Grosbach3bbdcea2010-10-07 00:42:42 +0000234 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000235 ARMCC::CondCodes CCVal, SDValue CCR,
236 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000237
Evan Chengde8aa4e2010-05-05 18:28:36 +0000238 SDNode *SelectConcatVector(SDNode *N);
239
Evan Chengaf4550f2009-07-02 01:23:32 +0000240 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
241 /// inline asm expressions.
242 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
243 char ConstraintCode,
244 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000245
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000246 // Form pairs of consecutive S, D, or Q registers.
247 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000248 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000249 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
250
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000251 // Form sequences of 4 consecutive S, D, or Q registers.
252 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000253 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000254 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilson665814b2010-11-01 23:40:51 +0000255
256 // Get the alignment operand for a NEON VLD or VST instruction.
257 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000258};
Evan Chenga8e29892007-01-19 07:51:42 +0000259}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000260
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000261/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
262/// operand. If so Imm will receive the 32-bit value.
263static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
264 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
265 Imm = cast<ConstantSDNode>(N)->getZExtValue();
266 return true;
267 }
268 return false;
269}
270
271// isInt32Immediate - This method tests to see if a constant operand.
272// If so Imm will receive the 32 bit value.
273static bool isInt32Immediate(SDValue N, unsigned &Imm) {
274 return isInt32Immediate(N.getNode(), Imm);
275}
276
277// isOpcWithIntImmediate - This method tests to see if the node is a specific
278// opcode and that it has a immediate integer right operand.
279// If so Imm will receive the 32 bit value.
280static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
281 return N->getOpcode() == Opc &&
282 isInt32Immediate(N->getOperand(1).getNode(), Imm);
283}
284
Evan Cheng48575f62010-12-05 22:04:16 +0000285/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
286/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
287/// least on current ARM implementations) which should be avoidded.
288bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
289 if (OptLevel == CodeGenOpt::None)
290 return true;
291
292 if (!CheckVMLxHazard)
293 return true;
294
295 if (!Subtarget->isCortexA8() && !Subtarget->isCortexA9())
296 return true;
297
298 if (!N->hasOneUse())
299 return false;
300
301 SDNode *Use = *N->use_begin();
302 if (Use->getOpcode() == ISD::CopyToReg)
303 return true;
304 if (Use->isMachineOpcode()) {
305 const TargetInstrDesc &TID = TII->get(Use->getMachineOpcode());
306 if (TID.mayStore())
307 return true;
308 unsigned Opcode = TID.getOpcode();
309 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
310 return true;
311 // vmlx feeding into another vmlx. We actually want to unfold
312 // the use later in the MLxExpansion pass. e.g.
313 // vmla
314 // vmla (stall 8 cycles)
315 //
316 // vmul (5 cycles)
317 // vadd (5 cycles)
318 // vmla
319 // This adds up to about 18 - 19 cycles.
320 //
321 // vmla
322 // vmul (stall 4 cycles)
323 // vadd adds up to about 14 cycles.
324 return TII->isFpMLxInstruction(Opcode);
325 }
326
327 return false;
328}
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000329
Evan Chengf40deed2010-10-27 23:41:30 +0000330bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
331 ARM_AM::ShiftOpc ShOpcVal,
332 unsigned ShAmt) {
333 if (!Subtarget->isCortexA9())
334 return true;
335 if (Shift.hasOneUse())
336 return true;
337 // R << 2 is free.
338 return ShOpcVal == ARM_AM::lsl && ShAmt == 2;
339}
340
Chris Lattner52a261b2010-09-21 20:31:19 +0000341bool ARMDAGToDAGISel::SelectShifterOperandReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000342 SDValue &BaseReg,
343 SDValue &ShReg,
344 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000345 if (DisableShifterOp)
346 return false;
347
Evan Cheng055b0312009-06-29 07:51:04 +0000348 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
349
350 // Don't match base register only case. That is matched to a separate
351 // lower complexity pattern with explicit register operand.
352 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000353
Evan Cheng055b0312009-06-29 07:51:04 +0000354 BaseReg = N.getOperand(0);
355 unsigned ShImmVal = 0;
356 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000357 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000358 ShImmVal = RHS->getZExtValue() & 31;
359 } else {
360 ShReg = N.getOperand(1);
Evan Chengf40deed2010-10-27 23:41:30 +0000361 if (!isShifterOpProfitable(N, ShOpcVal, ShImmVal))
362 return false;
363 }
364 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
365 MVT::i32);
366 return true;
367}
368
369bool ARMDAGToDAGISel::SelectShiftShifterOperandReg(SDValue N,
370 SDValue &BaseReg,
371 SDValue &ShReg,
372 SDValue &Opc) {
373 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
374
375 // Don't match base register only case. That is matched to a separate
376 // lower complexity pattern with explicit register operand.
377 if (ShOpcVal == ARM_AM::no_shift) return false;
378
379 BaseReg = N.getOperand(0);
380 unsigned ShImmVal = 0;
381 // Do not check isShifterOpProfitable. This must return true.
382 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
383 ShReg = CurDAG->getRegister(0, MVT::i32);
384 ShImmVal = RHS->getZExtValue() & 31;
385 } else {
386 ShReg = N.getOperand(1);
Evan Cheng055b0312009-06-29 07:51:04 +0000387 }
388 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000389 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000390 return true;
391}
392
Jim Grosbach3e556122010-10-26 22:37:02 +0000393bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
394 SDValue &Base,
395 SDValue &OffImm) {
396 // Match simple R + imm12 operands.
397
398 // Base only.
399 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
400 if (N.getOpcode() == ISD::FrameIndex) {
401 // Match frame index...
402 int FI = cast<FrameIndexSDNode>(N)->getIndex();
403 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
404 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
405 return true;
406 } else if (N.getOpcode() == ARMISD::Wrapper &&
407 !(Subtarget->useMovt() &&
408 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
409 Base = N.getOperand(0);
410 } else
411 Base = N;
412 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
413 return true;
414 }
415
416 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
417 int RHSC = (int)RHS->getZExtValue();
418 if (N.getOpcode() == ISD::SUB)
419 RHSC = -RHSC;
420
421 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
422 Base = N.getOperand(0);
423 if (Base.getOpcode() == ISD::FrameIndex) {
424 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
425 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
426 }
427 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
428 return true;
429 }
430 }
431
432 // Base only.
433 Base = N;
434 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
435 return true;
436}
437
438
439
440bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
441 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000442 if (N.getOpcode() == ISD::MUL &&
443 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000444 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
445 // X * [3,5,9] -> X + X * [2,4,8] etc.
446 int RHSC = (int)RHS->getZExtValue();
447 if (RHSC & 1) {
448 RHSC = RHSC & ~1;
449 ARM_AM::AddrOpc AddSub = ARM_AM::add;
450 if (RHSC < 0) {
451 AddSub = ARM_AM::sub;
452 RHSC = - RHSC;
453 }
454 if (isPowerOf2_32(RHSC)) {
455 unsigned ShAmt = Log2_32(RHSC);
456 Base = Offset = N.getOperand(0);
457 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
458 ARM_AM::lsl),
459 MVT::i32);
460 return true;
461 }
462 }
463 }
464 }
465
466 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB)
467 return false;
468
469 // Leave simple R +/- imm12 operands for LDRi12
470 if (N.getOpcode() == ISD::ADD) {
471 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
472 int RHSC = (int)RHS->getZExtValue();
473 if ((RHSC >= 0 && RHSC < 0x1000) ||
474 (RHSC < 0 && RHSC > -0x1000)) // 12 bits.
475 return false;
476 }
477 }
478
Evan Chengf40deed2010-10-27 23:41:30 +0000479 if (Subtarget->isCortexA9() && !N.hasOneUse())
480 // Compute R +/- (R << N) and reuse it.
481 return false;
482
Jim Grosbach3e556122010-10-26 22:37:02 +0000483 // Otherwise this is R +/- [possibly shifted] R.
484 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
485 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
486 unsigned ShAmt = 0;
487
488 Base = N.getOperand(0);
489 Offset = N.getOperand(1);
490
491 if (ShOpcVal != ARM_AM::no_shift) {
492 // Check to see if the RHS of the shift is a constant, if not, we can't fold
493 // it.
494 if (ConstantSDNode *Sh =
495 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
496 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000497 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
498 Offset = N.getOperand(1).getOperand(0);
499 else {
500 ShAmt = 0;
501 ShOpcVal = ARM_AM::no_shift;
502 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000503 } else {
504 ShOpcVal = ARM_AM::no_shift;
505 }
506 }
507
508 // Try matching (R shl C) + (R).
Evan Chengf40deed2010-10-27 23:41:30 +0000509 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift &&
510 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000511 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
512 if (ShOpcVal != ARM_AM::no_shift) {
513 // Check to see if the RHS of the shift is a constant, if not, we can't
514 // fold it.
515 if (ConstantSDNode *Sh =
516 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
517 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000518 if (!Subtarget->isCortexA9() ||
519 (N.hasOneUse() &&
520 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
521 Offset = N.getOperand(0).getOperand(0);
522 Base = N.getOperand(1);
523 } else {
524 ShAmt = 0;
525 ShOpcVal = ARM_AM::no_shift;
526 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000527 } else {
528 ShOpcVal = ARM_AM::no_shift;
529 }
530 }
531 }
532
533 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
534 MVT::i32);
535 return true;
536}
537
538
539
540
541//-----
542
Jim Grosbach82891622010-09-29 19:03:54 +0000543AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
544 SDValue &Base,
545 SDValue &Offset,
546 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000547 if (N.getOpcode() == ISD::MUL &&
548 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000549 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
550 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000551 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000552 if (RHSC & 1) {
553 RHSC = RHSC & ~1;
554 ARM_AM::AddrOpc AddSub = ARM_AM::add;
555 if (RHSC < 0) {
556 AddSub = ARM_AM::sub;
557 RHSC = - RHSC;
558 }
559 if (isPowerOf2_32(RHSC)) {
560 unsigned ShAmt = Log2_32(RHSC);
561 Base = Offset = N.getOperand(0);
562 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
563 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000564 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000565 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000566 }
567 }
568 }
569 }
570
Evan Chenga8e29892007-01-19 07:51:42 +0000571 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
572 Base = N;
573 if (N.getOpcode() == ISD::FrameIndex) {
574 int FI = cast<FrameIndexSDNode>(N)->getIndex();
575 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000576 } else if (N.getOpcode() == ARMISD::Wrapper &&
577 !(Subtarget->useMovt() &&
578 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000579 Base = N.getOperand(0);
580 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000581 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000582 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
583 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000584 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000585 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000586 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000587
Evan Chenga8e29892007-01-19 07:51:42 +0000588 // Match simple R +/- imm12 operands.
Jim Grosbachbe912322010-09-29 17:32:29 +0000589 if (N.getOpcode() == ISD::ADD) {
Evan Chenga8e29892007-01-19 07:51:42 +0000590 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000591 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000592 if ((RHSC >= 0 && RHSC < 0x1000) ||
593 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000594 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000595 if (Base.getOpcode() == ISD::FrameIndex) {
596 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
597 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
598 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000599 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000600
601 ARM_AM::AddrOpc AddSub = ARM_AM::add;
602 if (RHSC < 0) {
603 AddSub = ARM_AM::sub;
604 RHSC = - RHSC;
605 }
606 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000607 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000608 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000609 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000610 }
Evan Chenga8e29892007-01-19 07:51:42 +0000611 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000612 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000613
Evan Chengf40deed2010-10-27 23:41:30 +0000614 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
615 // Compute R +/- (R << N) and reuse it.
616 Base = N;
617 Offset = CurDAG->getRegister(0, MVT::i32);
618 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
619 ARM_AM::no_shift),
620 MVT::i32);
621 return AM2_BASE;
622 }
623
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000624 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000625 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
626 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
627 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000628
Evan Chenga8e29892007-01-19 07:51:42 +0000629 Base = N.getOperand(0);
630 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000631
Evan Chenga8e29892007-01-19 07:51:42 +0000632 if (ShOpcVal != ARM_AM::no_shift) {
633 // Check to see if the RHS of the shift is a constant, if not, we can't fold
634 // it.
635 if (ConstantSDNode *Sh =
636 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000637 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000638 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
639 Offset = N.getOperand(1).getOperand(0);
640 else {
641 ShAmt = 0;
642 ShOpcVal = ARM_AM::no_shift;
643 }
Evan Chenga8e29892007-01-19 07:51:42 +0000644 } else {
645 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000646 }
647 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000648
Evan Chenga8e29892007-01-19 07:51:42 +0000649 // Try matching (R shl C) + (R).
Evan Chengf40deed2010-10-27 23:41:30 +0000650 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift &&
651 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chenga8e29892007-01-19 07:51:42 +0000652 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
653 if (ShOpcVal != ARM_AM::no_shift) {
654 // Check to see if the RHS of the shift is a constant, if not, we can't
655 // fold it.
656 if (ConstantSDNode *Sh =
657 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000658 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000659 if (!Subtarget->isCortexA9() ||
660 (N.hasOneUse() &&
661 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
662 Offset = N.getOperand(0).getOperand(0);
663 Base = N.getOperand(1);
664 } else {
665 ShAmt = 0;
666 ShOpcVal = ARM_AM::no_shift;
667 }
Evan Chenga8e29892007-01-19 07:51:42 +0000668 } else {
669 ShOpcVal = ARM_AM::no_shift;
670 }
671 }
672 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000673
Evan Chenga8e29892007-01-19 07:51:42 +0000674 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000675 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000676 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000677}
678
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000679bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000680 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000681 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000682 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
683 ? cast<LoadSDNode>(Op)->getAddressingMode()
684 : cast<StoreSDNode>(Op)->getAddressingMode();
685 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
686 ? ARM_AM::add : ARM_AM::sub;
687 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000688 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000689 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000690 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000691 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
692 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000693 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000694 return true;
695 }
696 }
697
698 Offset = N;
699 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
700 unsigned ShAmt = 0;
701 if (ShOpcVal != ARM_AM::no_shift) {
702 // Check to see if the RHS of the shift is a constant, if not, we can't fold
703 // it.
704 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000705 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000706 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
707 Offset = N.getOperand(0);
708 else {
709 ShAmt = 0;
710 ShOpcVal = ARM_AM::no_shift;
711 }
Evan Chenga8e29892007-01-19 07:51:42 +0000712 } else {
713 ShOpcVal = ARM_AM::no_shift;
714 }
715 }
716
717 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000718 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000719 return true;
720}
721
Evan Chenga8e29892007-01-19 07:51:42 +0000722
Chris Lattner52a261b2010-09-21 20:31:19 +0000723bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000724 SDValue &Base, SDValue &Offset,
725 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000726 if (N.getOpcode() == ISD::SUB) {
727 // X - C is canonicalize to X + -C, no need to handle it here.
728 Base = N.getOperand(0);
729 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000730 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000731 return true;
732 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000733
Evan Chenga8e29892007-01-19 07:51:42 +0000734 if (N.getOpcode() != ISD::ADD) {
735 Base = N;
736 if (N.getOpcode() == ISD::FrameIndex) {
737 int FI = cast<FrameIndexSDNode>(N)->getIndex();
738 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
739 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000740 Offset = CurDAG->getRegister(0, MVT::i32);
741 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000742 return true;
743 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000744
Evan Chenga8e29892007-01-19 07:51:42 +0000745 // If the RHS is +/- imm8, fold into addr mode.
746 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000747 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000748 if ((RHSC >= 0 && RHSC < 256) ||
749 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000750 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000751 if (Base.getOpcode() == ISD::FrameIndex) {
752 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
753 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
754 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000755 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000756
757 ARM_AM::AddrOpc AddSub = ARM_AM::add;
758 if (RHSC < 0) {
759 AddSub = ARM_AM::sub;
760 RHSC = - RHSC;
761 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000762 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000763 return true;
764 }
765 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000766
Evan Chenga8e29892007-01-19 07:51:42 +0000767 Base = N.getOperand(0);
768 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000769 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000770 return true;
771}
772
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000773bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000774 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000775 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000776 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
777 ? cast<LoadSDNode>(Op)->getAddressingMode()
778 : cast<StoreSDNode>(Op)->getAddressingMode();
779 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
780 ? ARM_AM::add : ARM_AM::sub;
781 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000782 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000783 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000784 Offset = CurDAG->getRegister(0, MVT::i32);
785 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000786 return true;
787 }
788 }
789
790 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000791 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000792 return true;
793}
794
Jim Grosbach3ab56582010-10-21 19:38:40 +0000795bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000796 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000797 if (N.getOpcode() != ISD::ADD) {
798 Base = N;
799 if (N.getOpcode() == ISD::FrameIndex) {
800 int FI = cast<FrameIndexSDNode>(N)->getIndex();
801 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000802 } else if (N.getOpcode() == ARMISD::Wrapper &&
803 !(Subtarget->useMovt() &&
804 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000805 Base = N.getOperand(0);
806 }
807 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000808 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000809 return true;
810 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000811
Evan Chenga8e29892007-01-19 07:51:42 +0000812 // If the RHS is +/- imm8, fold into addr mode.
813 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000814 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000815 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
816 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000817 if ((RHSC >= 0 && RHSC < 256) ||
818 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000819 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000820 if (Base.getOpcode() == ISD::FrameIndex) {
821 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
822 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
823 }
824
825 ARM_AM::AddrOpc AddSub = ARM_AM::add;
826 if (RHSC < 0) {
827 AddSub = ARM_AM::sub;
828 RHSC = - RHSC;
829 }
830 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000831 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000832 return true;
833 }
834 }
835 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000836
Evan Chenga8e29892007-01-19 07:51:42 +0000837 Base = N;
838 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000839 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000840 return true;
841}
842
Bob Wilson665814b2010-11-01 23:40:51 +0000843bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
844 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000845 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000846
847 unsigned Alignment = 0;
848 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
849 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
850 // The maximum alignment is equal to the memory size being referenced.
851 unsigned LSNAlign = LSN->getAlignment();
852 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
853 if (LSNAlign > MemSize && MemSize > 1)
854 Alignment = MemSize;
855 } else {
856 // All other uses of addrmode6 are for intrinsics. For now just record
857 // the raw alignment value; it will be refined later based on the legal
858 // alignment operands for the intrinsic.
859 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
860 }
861
862 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000863 return true;
864}
865
Chris Lattner52a261b2010-09-21 20:31:19 +0000866bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000867 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000868 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
869 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000870 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000871 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000872 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000873 return true;
874 }
875 return false;
876}
877
Chris Lattner52a261b2010-09-21 20:31:19 +0000878bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000879 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000880 // FIXME dl should come from the parent load or store, not the address
Evan Chengc38f2bc2007-01-23 22:59:13 +0000881 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000882 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000883 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000884 return false;
885
886 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000887 return true;
888 }
889
Evan Chenga8e29892007-01-19 07:51:42 +0000890 Base = N.getOperand(0);
891 Offset = N.getOperand(1);
892 return true;
893}
894
Evan Cheng79d43262007-01-24 02:21:22 +0000895bool
Chris Lattner52a261b2010-09-21 20:31:19 +0000896ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000897 unsigned Scale, SDValue &Base,
898 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000899 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000900 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000901 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000902 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000903 if (N.getOpcode() == ARMISD::Wrapper &&
904 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
905 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000906 }
907
Evan Chenga8e29892007-01-19 07:51:42 +0000908 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000909 if (N.getOpcode() == ARMISD::Wrapper &&
910 !(Subtarget->useMovt() &&
911 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
912 Base = N.getOperand(0);
913 } else
914 Base = N;
915
Owen Anderson825b72b2009-08-11 20:47:22 +0000916 Offset = CurDAG->getRegister(0, MVT::i32);
917 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000918 return true;
919 }
920
Evan Chengad0e4652007-02-06 00:22:06 +0000921 // Thumb does not have [sp, r] address mode.
922 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
923 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
924 if ((LHSR && LHSR->getReg() == ARM::SP) ||
925 (RHSR && RHSR->getReg() == ARM::SP)) {
926 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000927 Offset = CurDAG->getRegister(0, MVT::i32);
928 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000929 return true;
930 }
931
Evan Chenga8e29892007-01-19 07:51:42 +0000932 // If the RHS is + imm5 * scale, fold into addr mode.
933 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000934 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000935 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
936 RHSC /= Scale;
937 if (RHSC >= 0 && RHSC < 32) {
938 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000939 Offset = CurDAG->getRegister(0, MVT::i32);
940 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000941 return true;
942 }
943 }
944 }
945
Evan Chengc38f2bc2007-01-23 22:59:13 +0000946 Base = N.getOperand(0);
947 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000948 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000949 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000950}
951
Chris Lattner52a261b2010-09-21 20:31:19 +0000952bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000953 SDValue &Base, SDValue &OffImm,
954 SDValue &Offset) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000955 return SelectThumbAddrModeRI5(N, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000956}
957
Chris Lattner52a261b2010-09-21 20:31:19 +0000958bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000959 SDValue &Base, SDValue &OffImm,
960 SDValue &Offset) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000961 return SelectThumbAddrModeRI5(N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000962}
963
Chris Lattner52a261b2010-09-21 20:31:19 +0000964bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000965 SDValue &Base, SDValue &OffImm,
966 SDValue &Offset) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000967 return SelectThumbAddrModeRI5(N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000968}
969
Chris Lattner52a261b2010-09-21 20:31:19 +0000970bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
971 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000972 if (N.getOpcode() == ISD::FrameIndex) {
973 int FI = cast<FrameIndexSDNode>(N)->getIndex();
974 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000975 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000976 return true;
977 }
Evan Cheng79d43262007-01-24 02:21:22 +0000978
Evan Chengad0e4652007-02-06 00:22:06 +0000979 if (N.getOpcode() != ISD::ADD)
980 return false;
981
982 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000983 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
984 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000985 // If the RHS is + imm8 * scale, fold into addr mode.
986 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000987 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000988 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
989 RHSC >>= 2;
990 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000991 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000992 if (Base.getOpcode() == ISD::FrameIndex) {
993 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
994 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
995 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000996 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000997 return true;
998 }
999 }
1000 }
1001 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001002
Evan Chenga8e29892007-01-19 07:51:42 +00001003 return false;
1004}
1005
Chris Lattner52a261b2010-09-21 20:31:19 +00001006bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001007 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001008 if (DisableShifterOp)
1009 return false;
1010
Evan Cheng9cb9e672009-06-27 02:26:13 +00001011 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
1012
1013 // Don't match base register only case. That is matched to a separate
1014 // lower complexity pattern with explicit register operand.
1015 if (ShOpcVal == ARM_AM::no_shift) return false;
1016
1017 BaseReg = N.getOperand(0);
1018 unsigned ShImmVal = 0;
1019 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1020 ShImmVal = RHS->getZExtValue() & 31;
1021 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1022 return true;
1023 }
1024
1025 return false;
1026}
1027
Chris Lattner52a261b2010-09-21 20:31:19 +00001028bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001029 SDValue &Base, SDValue &OffImm) {
1030 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001031
Evan Cheng3a214252009-08-11 08:52:18 +00001032 // Base only.
1033 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001034 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +00001035 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +00001036 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1037 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001038 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001039 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001040 } else if (N.getOpcode() == ARMISD::Wrapper &&
1041 !(Subtarget->useMovt() &&
1042 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +00001043 Base = N.getOperand(0);
1044 if (Base.getOpcode() == ISD::TargetConstantPool)
1045 return false; // We want to select t2LDRpci instead.
1046 } else
1047 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001048 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001049 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +00001050 }
Evan Cheng055b0312009-06-29 07:51:04 +00001051
1052 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +00001053 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +00001054 // Let t2LDRi8 handle (R - imm8).
1055 return false;
1056
Evan Cheng055b0312009-06-29 07:51:04 +00001057 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +00001058 if (N.getOpcode() == ISD::SUB)
1059 RHSC = -RHSC;
1060
1061 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001062 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001063 if (Base.getOpcode() == ISD::FrameIndex) {
1064 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1065 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1066 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001067 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001068 return true;
1069 }
1070 }
1071
Evan Cheng3a214252009-08-11 08:52:18 +00001072 // Base only.
1073 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001074 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001075 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001076}
1077
Chris Lattner52a261b2010-09-21 20:31:19 +00001078bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001079 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001080 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +00001081 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +00001082 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1083 int RHSC = (int)RHS->getSExtValue();
1084 if (N.getOpcode() == ISD::SUB)
1085 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001086
Evan Cheng3a214252009-08-11 08:52:18 +00001087 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1088 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +00001089 if (Base.getOpcode() == ISD::FrameIndex) {
1090 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1091 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1092 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001093 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +00001094 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001095 }
Evan Cheng055b0312009-06-29 07:51:04 +00001096 }
1097 }
1098
1099 return false;
1100}
1101
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001102bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001103 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001104 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001105 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1106 ? cast<LoadSDNode>(Op)->getAddressingMode()
1107 : cast<StoreSDNode>(Op)->getAddressingMode();
1108 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
1109 int RHSC = (int)RHS->getZExtValue();
1110 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +00001111 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +00001112 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1113 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001114 return true;
1115 }
1116 }
1117
1118 return false;
1119}
1120
Chris Lattner52a261b2010-09-21 20:31:19 +00001121bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001122 SDValue &Base,
1123 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001124 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
1125 if (N.getOpcode() != ISD::ADD)
1126 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001127
Evan Cheng3a214252009-08-11 08:52:18 +00001128 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1129 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1130 int RHSC = (int)RHS->getZExtValue();
1131 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1132 return false;
1133 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001134 return false;
1135 }
1136
Evan Chengf40deed2010-10-27 23:41:30 +00001137 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
1138 // Compute R + (R << [1,2,3]) and reuse it.
1139 Base = N;
1140 return false;
1141 }
1142
Evan Cheng055b0312009-06-29 07:51:04 +00001143 // Look for (R + R) or (R + (R << [1,2,3])).
1144 unsigned ShAmt = 0;
1145 Base = N.getOperand(0);
1146 OffReg = N.getOperand(1);
1147
1148 // Swap if it is ((R << c) + R).
1149 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
1150 if (ShOpcVal != ARM_AM::lsl) {
1151 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
1152 if (ShOpcVal == ARM_AM::lsl)
1153 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001154 }
1155
Evan Cheng055b0312009-06-29 07:51:04 +00001156 if (ShOpcVal == ARM_AM::lsl) {
1157 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1158 // it.
1159 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1160 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001161 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1162 OffReg = OffReg.getOperand(0);
1163 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001164 ShAmt = 0;
1165 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001166 }
Evan Cheng055b0312009-06-29 07:51:04 +00001167 } else {
1168 ShOpcVal = ARM_AM::no_shift;
1169 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001170 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001171
Owen Anderson825b72b2009-08-11 20:47:22 +00001172 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001173
1174 return true;
1175}
1176
1177//===--------------------------------------------------------------------===//
1178
Evan Chengee568cf2007-07-05 07:15:27 +00001179/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001180static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001181 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001182}
1183
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001184SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1185 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001186 ISD::MemIndexedMode AM = LD->getAddressingMode();
1187 if (AM == ISD::UNINDEXED)
1188 return NULL;
1189
Owen Andersone50ed302009-08-10 22:56:29 +00001190 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001191 SDValue Offset, AMOpc;
1192 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1193 unsigned Opcode = 0;
1194 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +00001195 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001196 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001197 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
1198 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +00001199 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001200 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001201 Match = true;
1202 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1203 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1204 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001205 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001206 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001207 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001208 Match = true;
1209 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1210 }
1211 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001212 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001213 Match = true;
1214 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
1215 }
1216 }
1217 }
1218
1219 if (Match) {
1220 SDValue Chain = LD->getChain();
1221 SDValue Base = LD->getBasePtr();
1222 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001223 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001224 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001225 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +00001226 }
1227
1228 return NULL;
1229}
1230
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001231SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1232 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001233 ISD::MemIndexedMode AM = LD->getAddressingMode();
1234 if (AM == ISD::UNINDEXED)
1235 return NULL;
1236
Owen Andersone50ed302009-08-10 22:56:29 +00001237 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001238 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001239 SDValue Offset;
1240 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1241 unsigned Opcode = 0;
1242 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001243 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001244 switch (LoadedVT.getSimpleVT().SimpleTy) {
1245 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001246 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1247 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001248 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001249 if (isSExtLd)
1250 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1251 else
1252 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001253 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001254 case MVT::i8:
1255 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001256 if (isSExtLd)
1257 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1258 else
1259 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001260 break;
1261 default:
1262 return NULL;
1263 }
1264 Match = true;
1265 }
1266
1267 if (Match) {
1268 SDValue Chain = LD->getChain();
1269 SDValue Base = LD->getBasePtr();
1270 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001271 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001272 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001273 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001274 }
1275
1276 return NULL;
1277}
1278
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001279/// PairSRegs - Form a D register from a pair of S registers.
1280///
1281SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1282 DebugLoc dl = V0.getNode()->getDebugLoc();
1283 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1284 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001285 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1286 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001287}
1288
Evan Cheng603afbf2010-05-10 17:34:18 +00001289/// PairDRegs - Form a quad register from a pair of D registers.
1290///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001291SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1292 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001293 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1294 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001295 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1296 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001297}
1298
Evan Cheng7f687192010-05-14 00:21:45 +00001299/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001300///
1301SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1302 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001303 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1304 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001305 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1306 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1307}
1308
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001309/// QuadSRegs - Form 4 consecutive S registers.
1310///
1311SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1312 SDValue V2, SDValue V3) {
1313 DebugLoc dl = V0.getNode()->getDebugLoc();
1314 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1315 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1316 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1317 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
1318 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1319 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1320}
1321
Evan Cheng7f687192010-05-14 00:21:45 +00001322/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001323///
1324SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1325 SDValue V2, SDValue V3) {
1326 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001327 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1328 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1329 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1330 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001331 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1332 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1333}
1334
Evan Cheng8f6de382010-05-16 03:27:48 +00001335/// QuadQRegs - Form 4 consecutive Q registers.
1336///
1337SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1338 SDValue V2, SDValue V3) {
1339 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001340 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1341 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1342 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1343 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Evan Cheng8f6de382010-05-16 03:27:48 +00001344 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1345 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1346}
1347
Bob Wilson2a6e6162010-09-23 23:42:37 +00001348/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1349/// of a NEON VLD or VST instruction. The supported values depend on the
1350/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001351SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1352 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001353 unsigned NumRegs = NumVecs;
1354 if (!is64BitVector && NumVecs < 3)
1355 NumRegs *= 2;
1356
Bob Wilson665814b2010-11-01 23:40:51 +00001357 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001358 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001359 Alignment = 32;
1360 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1361 Alignment = 16;
1362 else if (Alignment >= 8)
1363 Alignment = 8;
1364 else
1365 Alignment = 0;
1366
1367 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001368}
1369
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001370SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001371 unsigned *DOpcodes, unsigned *QOpcodes0,
1372 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001373 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001374 DebugLoc dl = N->getDebugLoc();
1375
Bob Wilson226036e2010-03-20 22:13:40 +00001376 SDValue MemAddr, Align;
Bob Wilson665814b2010-11-01 23:40:51 +00001377 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001378 return NULL;
1379
1380 SDValue Chain = N->getOperand(0);
1381 EVT VT = N->getValueType(0);
1382 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001383 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001384
Bob Wilson3e36f132009-10-14 17:28:52 +00001385 unsigned OpcodeIndex;
1386 switch (VT.getSimpleVT().SimpleTy) {
1387 default: llvm_unreachable("unhandled vld type");
1388 // Double-register operations:
1389 case MVT::v8i8: OpcodeIndex = 0; break;
1390 case MVT::v4i16: OpcodeIndex = 1; break;
1391 case MVT::v2f32:
1392 case MVT::v2i32: OpcodeIndex = 2; break;
1393 case MVT::v1i64: OpcodeIndex = 3; break;
1394 // Quad-register operations:
1395 case MVT::v16i8: OpcodeIndex = 0; break;
1396 case MVT::v8i16: OpcodeIndex = 1; break;
1397 case MVT::v4f32:
1398 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001399 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001400 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001401 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001402 }
1403
Bob Wilsonf5721912010-09-03 18:16:02 +00001404 EVT ResTy;
1405 if (NumVecs == 1)
1406 ResTy = VT;
1407 else {
1408 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1409 if (!is64BitVector)
1410 ResTyElts *= 2;
1411 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1412 }
1413
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001414 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001415 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilsonf5721912010-09-03 18:16:02 +00001416 SDValue SuperReg;
Bob Wilson3e36f132009-10-14 17:28:52 +00001417 if (is64BitVector) {
1418 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001419 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilsonf5721912010-09-03 18:16:02 +00001420 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
Bob Wilsonffde0802010-09-02 16:00:54 +00001421 if (NumVecs == 1)
Evan Chenge9e2ba02010-05-10 21:26:24 +00001422 return VLd;
1423
Bob Wilsonf5721912010-09-03 18:16:02 +00001424 SuperReg = SDValue(VLd, 0);
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001425 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
Evan Cheng5c6aba22010-05-14 18:54:59 +00001426 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001427 SDValue D = CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec,
Bob Wilsonffde0802010-09-02 16:00:54 +00001428 dl, VT, SuperReg);
Evan Cheng5c6aba22010-05-14 18:54:59 +00001429 ReplaceUses(SDValue(N, Vec), D);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001430 }
Bob Wilsonf5721912010-09-03 18:16:02 +00001431 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
Evan Chenge9e2ba02010-05-10 21:26:24 +00001432 return NULL;
Bob Wilson3e36f132009-10-14 17:28:52 +00001433 }
1434
Bob Wilson621f1952010-03-23 05:25:43 +00001435 if (NumVecs <= 2) {
1436 // Quad registers are directly supported for VLD1 and VLD2,
1437 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001438 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001439 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilsonffde0802010-09-02 16:00:54 +00001440 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
Bob Wilsonffde0802010-09-02 16:00:54 +00001441 if (NumVecs == 1)
1442 return VLd;
1443
Bob Wilsonf5721912010-09-03 18:16:02 +00001444 SuperReg = SDValue(VLd, 0);
Bob Wilsonffde0802010-09-02 16:00:54 +00001445 Chain = SDValue(VLd, 1);
1446
Bob Wilson3e36f132009-10-14 17:28:52 +00001447 } else {
1448 // Otherwise, quad registers are loaded with two separate instructions,
1449 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001450 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001451
Bob Wilson24f995d2009-10-14 18:32:29 +00001452 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001453 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsonf5721912010-09-03 18:16:02 +00001454 SDValue ImplDef =
1455 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1456 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
1457 SDNode *VLdA =
1458 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsA, 7);
1459 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001460
Bob Wilson24f995d2009-10-14 18:32:29 +00001461 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001462 Opc = QOpcodes1[OpcodeIndex];
Bob Wilsonf5721912010-09-03 18:16:02 +00001463 const SDValue OpsB[] = { SDValue(VLdA, 1), Align, Reg0, SDValue(VLdA, 0),
1464 Pred, Reg0, Chain };
1465 SDNode *VLdB =
1466 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsB, 7);
1467 SuperReg = SDValue(VLdB, 0);
1468 Chain = SDValue(VLdB, 2);
1469 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001470
Bob Wilsonf5721912010-09-03 18:16:02 +00001471 // Extract out the Q registers.
1472 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1473 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1474 SDValue Q = CurDAG->getTargetExtractSubreg(ARM::qsub_0+Vec,
1475 dl, VT, SuperReg);
1476 ReplaceUses(SDValue(N, Vec), Q);
Bob Wilson3e36f132009-10-14 17:28:52 +00001477 }
1478 ReplaceUses(SDValue(N, NumVecs), Chain);
1479 return NULL;
1480}
1481
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001482SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001483 unsigned *DOpcodes, unsigned *QOpcodes0,
1484 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001485 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001486 DebugLoc dl = N->getDebugLoc();
1487
Bob Wilson226036e2010-03-20 22:13:40 +00001488 SDValue MemAddr, Align;
Bob Wilson665814b2010-11-01 23:40:51 +00001489 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001490 return NULL;
1491
1492 SDValue Chain = N->getOperand(0);
1493 EVT VT = N->getOperand(3).getValueType();
1494 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001495 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001496
Bob Wilson24f995d2009-10-14 18:32:29 +00001497 unsigned OpcodeIndex;
1498 switch (VT.getSimpleVT().SimpleTy) {
1499 default: llvm_unreachable("unhandled vst type");
1500 // Double-register operations:
1501 case MVT::v8i8: OpcodeIndex = 0; break;
1502 case MVT::v4i16: OpcodeIndex = 1; break;
1503 case MVT::v2f32:
1504 case MVT::v2i32: OpcodeIndex = 2; break;
1505 case MVT::v1i64: OpcodeIndex = 3; break;
1506 // Quad-register operations:
1507 case MVT::v16i8: OpcodeIndex = 0; break;
1508 case MVT::v8i16: OpcodeIndex = 1; break;
1509 case MVT::v4f32:
1510 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001511 case MVT::v2i64: OpcodeIndex = 3;
1512 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1513 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001514 }
1515
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001516 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001517 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001518
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001519 SmallVector<SDValue, 7> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001520 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001521 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001522
1523 if (is64BitVector) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001524 if (NumVecs == 1) {
1525 Ops.push_back(N->getOperand(3));
1526 } else {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001527 SDValue RegSeq;
1528 SDValue V0 = N->getOperand(0+3);
1529 SDValue V1 = N->getOperand(1+3);
1530
1531 // Form a REG_SEQUENCE to force register allocation.
1532 if (NumVecs == 2)
1533 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1534 else {
1535 SDValue V2 = N->getOperand(2+3);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001536 // If it's a vld3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001537 // an undef.
1538 SDValue V3 = (NumVecs == 3)
1539 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1540 : N->getOperand(3+3);
1541 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1542 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001543 Ops.push_back(RegSeq);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001544 }
Evan Chengac0869d2009-11-21 06:21:52 +00001545 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001546 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001547 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001548 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001549 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001550 }
1551
Bob Wilson11d98992010-03-23 06:20:33 +00001552 if (NumVecs <= 2) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001553 // Quad registers are directly supported for VST1 and VST2.
Bob Wilson24f995d2009-10-14 18:32:29 +00001554 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001555 if (NumVecs == 1) {
1556 Ops.push_back(N->getOperand(3));
1557 } else {
1558 // Form a QQ register.
Evan Cheng603afbf2010-05-10 17:34:18 +00001559 SDValue Q0 = N->getOperand(3);
1560 SDValue Q1 = N->getOperand(4);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001561 Ops.push_back(SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0));
Bob Wilson24f995d2009-10-14 18:32:29 +00001562 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001563 Ops.push_back(Pred);
1564 Ops.push_back(Reg0); // predicate register
1565 Ops.push_back(Chain);
1566 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001567 }
1568
1569 // Otherwise, quad registers are stored with two separate instructions,
1570 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001571
Bob Wilson07f6e802010-06-16 21:34:01 +00001572 // Form the QQQQ REG_SEQUENCE.
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001573 SDValue V0 = N->getOperand(0+3);
1574 SDValue V1 = N->getOperand(1+3);
1575 SDValue V2 = N->getOperand(2+3);
1576 SDValue V3 = (NumVecs == 3)
1577 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1578 : N->getOperand(3+3);
1579 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001580
1581 // Store the even D registers.
Bob Wilson07f6e802010-06-16 21:34:01 +00001582 Ops.push_back(Reg0); // post-access address offset
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001583 Ops.push_back(RegSeq);
Bob Wilson07f6e802010-06-16 21:34:01 +00001584 Ops.push_back(Pred);
1585 Ops.push_back(Reg0); // predicate register
1586 Ops.push_back(Chain);
1587 unsigned Opc = QOpcodes0[OpcodeIndex];
1588 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001589 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001590 Chain = SDValue(VStA, 1);
1591
1592 // Store the odd D registers.
1593 Ops[0] = SDValue(VStA, 0); // MemAddr
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001594 Ops[6] = Chain;
Bob Wilson07f6e802010-06-16 21:34:01 +00001595 Opc = QOpcodes1[OpcodeIndex];
1596 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001597 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001598 Chain = SDValue(VStB, 1);
1599 ReplaceUses(SDValue(N, 0), Chain);
1600 return NULL;
Bob Wilson24f995d2009-10-14 18:32:29 +00001601}
1602
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001603SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001604 unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001605 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001606 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001607 DebugLoc dl = N->getDebugLoc();
1608
Bob Wilson226036e2010-03-20 22:13:40 +00001609 SDValue MemAddr, Align;
Bob Wilson665814b2010-11-01 23:40:51 +00001610 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001611 return NULL;
1612
1613 SDValue Chain = N->getOperand(0);
1614 unsigned Lane =
1615 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001616 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001617 bool is64BitVector = VT.is64BitVector();
1618
Bob Wilson665814b2010-11-01 23:40:51 +00001619 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001620 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001621 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001622 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1623 if (Alignment > NumBytes)
1624 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001625 if (Alignment < 8 && Alignment < NumBytes)
1626 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001627 // Alignment must be a power of two; make sure of that.
1628 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001629 if (Alignment == 1)
1630 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001631 }
Bob Wilson665814b2010-11-01 23:40:51 +00001632 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001633
Bob Wilsona7c397c2009-10-14 16:19:03 +00001634 unsigned OpcodeIndex;
1635 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001636 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001637 // Double-register operations:
1638 case MVT::v8i8: OpcodeIndex = 0; break;
1639 case MVT::v4i16: OpcodeIndex = 1; break;
1640 case MVT::v2f32:
1641 case MVT::v2i32: OpcodeIndex = 2; break;
1642 // Quad-register operations:
1643 case MVT::v8i16: OpcodeIndex = 0; break;
1644 case MVT::v4f32:
1645 case MVT::v4i32: OpcodeIndex = 1; break;
1646 }
1647
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001648 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001649 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001650
Bob Wilson8466fa12010-09-13 23:01:35 +00001651 SmallVector<SDValue, 7> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001652 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001653 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001654
Jim Grosbach3ab56582010-10-21 19:38:40 +00001655 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
Eric Christopher23da0b22010-09-14 08:31:25 +00001656 QOpcodes[OpcodeIndex]);
Bob Wilson07f6e802010-06-16 21:34:01 +00001657
Bob Wilson8466fa12010-09-13 23:01:35 +00001658 SDValue SuperReg;
1659 SDValue V0 = N->getOperand(0+3);
1660 SDValue V1 = N->getOperand(1+3);
1661 if (NumVecs == 2) {
1662 if (is64BitVector)
1663 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1664 else
1665 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001666 } else {
Bob Wilson8466fa12010-09-13 23:01:35 +00001667 SDValue V2 = N->getOperand(2+3);
1668 SDValue V3 = (NumVecs == 3)
1669 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1670 : N->getOperand(3+3);
1671 if (is64BitVector)
1672 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1673 else
1674 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001675 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001676 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001677 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001678 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001679 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001680 Ops.push_back(Chain);
1681
Bob Wilson96493442009-10-14 16:46:45 +00001682 if (!IsLoad)
Bob Wilson8466fa12010-09-13 23:01:35 +00001683 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 7);
Bob Wilson96493442009-10-14 16:46:45 +00001684
Bob Wilson8466fa12010-09-13 23:01:35 +00001685 EVT ResTy;
1686 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1687 if (!is64BitVector)
1688 ResTyElts *= 2;
1689 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001690
Bob Wilson8466fa12010-09-13 23:01:35 +00001691 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other,
1692 Ops.data(), 7);
1693 SuperReg = SDValue(VLdLn, 0);
1694 Chain = SDValue(VLdLn, 1);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001695
Bob Wilson8466fa12010-09-13 23:01:35 +00001696 // Extract the subregisters.
Bob Wilson07f6e802010-06-16 21:34:01 +00001697 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1698 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1699 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
1700 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1701 ReplaceUses(SDValue(N, Vec),
Bob Wilson8466fa12010-09-13 23:01:35 +00001702 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
1703 ReplaceUses(SDValue(N, NumVecs), Chain);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001704 return NULL;
1705}
1706
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001707SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, unsigned NumVecs,
1708 unsigned *Opcodes) {
1709 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1710 DebugLoc dl = N->getDebugLoc();
1711
1712 SDValue MemAddr, Align;
1713 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1714 return NULL;
1715
1716 SDValue Chain = N->getOperand(0);
1717 EVT VT = N->getValueType(0);
1718
1719 unsigned Alignment = 0;
1720 if (NumVecs != 3) {
1721 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1722 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1723 if (Alignment > NumBytes)
1724 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001725 if (Alignment < 8 && Alignment < NumBytes)
1726 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001727 // Alignment must be a power of two; make sure of that.
1728 Alignment = (Alignment & -Alignment);
1729 if (Alignment == 1)
1730 Alignment = 0;
1731 }
1732 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1733
1734 unsigned OpcodeIndex;
1735 switch (VT.getSimpleVT().SimpleTy) {
1736 default: llvm_unreachable("unhandled vld-dup type");
1737 case MVT::v8i8: OpcodeIndex = 0; break;
1738 case MVT::v4i16: OpcodeIndex = 1; break;
1739 case MVT::v2f32:
1740 case MVT::v2i32: OpcodeIndex = 2; break;
1741 }
1742
1743 SDValue Pred = getAL(CurDAG);
1744 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1745 SDValue SuperReg;
1746 unsigned Opc = Opcodes[OpcodeIndex];
1747 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
1748
1749 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1750 EVT ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1751 SDNode *VLdDup = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
1752 SuperReg = SDValue(VLdDup, 0);
1753 Chain = SDValue(VLdDup, 1);
1754
1755 // Extract the subregisters.
1756 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1757 unsigned SubIdx = ARM::dsub_0;
1758 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1759 ReplaceUses(SDValue(N, Vec),
1760 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
1761 ReplaceUses(SDValue(N, NumVecs), Chain);
1762 return NULL;
1763}
1764
Bob Wilson78dfbc32010-07-07 00:08:54 +00001765SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1766 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001767 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1768 DebugLoc dl = N->getDebugLoc();
1769 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001770 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001771
1772 // Form a REG_SEQUENCE to force register allocation.
1773 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001774 SDValue V0 = N->getOperand(FirstTblReg + 0);
1775 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001776 if (NumVecs == 2)
1777 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1778 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001779 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001780 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00001781 // an undef.
1782 SDValue V3 = (NumVecs == 3)
1783 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001784 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001785 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1786 }
1787
Bob Wilson78dfbc32010-07-07 00:08:54 +00001788 SmallVector<SDValue, 6> Ops;
1789 if (IsExt)
1790 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00001791 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001792 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001793 Ops.push_back(getAL(CurDAG)); // predicate
1794 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001795 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001796}
1797
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001798SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001799 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001800 if (!Subtarget->hasV6T2Ops())
1801 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001802
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001803 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1804 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1805
1806
1807 // For unsigned extracts, check for a shift right and mask
1808 unsigned And_imm = 0;
1809 if (N->getOpcode() == ISD::AND) {
1810 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1811
1812 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1813 if (And_imm & (And_imm + 1))
1814 return NULL;
1815
1816 unsigned Srl_imm = 0;
1817 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1818 Srl_imm)) {
1819 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1820
1821 unsigned Width = CountTrailingOnes_32(And_imm);
1822 unsigned LSB = Srl_imm;
1823 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1824 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1825 CurDAG->getTargetConstant(LSB, MVT::i32),
1826 CurDAG->getTargetConstant(Width, MVT::i32),
1827 getAL(CurDAG), Reg0 };
1828 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1829 }
1830 }
1831 return NULL;
1832 }
1833
1834 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001835 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001836 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001837 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1838 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001839 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001840 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1841 unsigned Width = 32 - Srl_imm;
1842 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001843 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001844 return NULL;
1845 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001846 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001847 CurDAG->getTargetConstant(LSB, MVT::i32),
1848 CurDAG->getTargetConstant(Width, MVT::i32),
1849 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001850 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001851 }
1852 }
1853 return NULL;
1854}
1855
Evan Cheng9ef48352009-11-20 00:54:03 +00001856SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001857SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001858 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1859 SDValue CPTmp0;
1860 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00001861 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001862 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1863 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1864 unsigned Opc = 0;
1865 switch (SOShOp) {
1866 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1867 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1868 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1869 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1870 default:
1871 llvm_unreachable("Unknown so_reg opcode!");
1872 break;
1873 }
1874 SDValue SOShImm =
1875 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1876 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1877 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001878 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001879 }
1880 return 0;
1881}
1882
1883SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001884SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001885 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1886 SDValue CPTmp0;
1887 SDValue CPTmp1;
1888 SDValue CPTmp2;
Chris Lattner52a261b2010-09-21 20:31:19 +00001889 if (SelectShifterOperandReg(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001890 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1891 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001892 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001893 }
1894 return 0;
1895}
1896
1897SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00001898SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00001899 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001900 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00001901 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00001902 return 0;
1903
Evan Cheng63f35442010-11-13 02:25:14 +00001904 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00001905 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00001906 if (is_t2_so_imm(TrueImm)) {
1907 Opc = ARM::t2MOVCCi;
1908 } else if (TrueImm <= 0xffff) {
1909 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00001910 } else if (is_t2_so_imm_not(TrueImm)) {
1911 TrueImm = ~TrueImm;
1912 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00001913 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00001914 // Large immediate.
1915 Opc = ARM::t2MOVCCi32imm;
1916 }
1917
1918 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00001919 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00001920 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1921 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00001922 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00001923 }
Evan Cheng63f35442010-11-13 02:25:14 +00001924
Evan Cheng9ef48352009-11-20 00:54:03 +00001925 return 0;
1926}
1927
1928SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001929SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00001930 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001931 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1932 if (!T)
1933 return 0;
1934
Evan Cheng63f35442010-11-13 02:25:14 +00001935 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001936 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00001937 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00001938 if (isSoImm) {
1939 Opc = ARM::MOVCCi;
1940 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
1941 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00001942 } else if (is_so_imm_not(TrueImm)) {
1943 TrueImm = ~TrueImm;
1944 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00001945 } else if (TrueVal.getNode()->hasOneUse() &&
1946 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00001947 // Large immediate.
1948 Opc = ARM::MOVCCi32imm;
1949 }
1950
1951 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001952 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00001953 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1954 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00001955 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00001956 }
Evan Cheng63f35442010-11-13 02:25:14 +00001957
Evan Cheng9ef48352009-11-20 00:54:03 +00001958 return 0;
1959}
1960
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001961SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1962 EVT VT = N->getValueType(0);
1963 SDValue FalseVal = N->getOperand(0);
1964 SDValue TrueVal = N->getOperand(1);
1965 SDValue CC = N->getOperand(2);
1966 SDValue CCR = N->getOperand(3);
1967 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001968 assert(CC.getOpcode() == ISD::Constant);
1969 assert(CCR.getOpcode() == ISD::Register);
1970 ARMCC::CondCodes CCVal =
1971 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001972
1973 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1974 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1975 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1976 // Pattern complexity = 18 cost = 1 size = 0
1977 SDValue CPTmp0;
1978 SDValue CPTmp1;
1979 SDValue CPTmp2;
1980 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001981 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001982 CCVal, CCR, InFlag);
1983 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001984 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001985 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1986 if (Res)
1987 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001988 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001989 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001990 CCVal, CCR, InFlag);
1991 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001992 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001993 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1994 if (Res)
1995 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001996 }
1997
1998 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00001999 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002000 // (imm:i32):$cc)
2001 // Emits: (MOVCCi:i32 GPR:i32:$false,
2002 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2003 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002004 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002005 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002006 CCVal, CCR, InFlag);
2007 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002008 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002009 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2010 if (Res)
2011 return Res;
2012 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002013 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002014 CCVal, CCR, InFlag);
2015 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002016 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002017 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2018 if (Res)
2019 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002020 }
2021 }
2022
2023 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2024 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2025 // Pattern complexity = 6 cost = 1 size = 0
2026 //
2027 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2028 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2029 // Pattern complexity = 6 cost = 11 size = 0
2030 //
2031 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002032 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2033 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002034 unsigned Opc = 0;
2035 switch (VT.getSimpleVT().SimpleTy) {
2036 default: assert(false && "Illegal conditional move type!");
2037 break;
2038 case MVT::i32:
2039 Opc = Subtarget->isThumb()
2040 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2041 : ARM::MOVCCr;
2042 break;
2043 case MVT::f32:
2044 Opc = ARM::VMOVScc;
2045 break;
2046 case MVT::f64:
2047 Opc = ARM::VMOVDcc;
2048 break;
2049 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002050 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002051}
2052
Evan Chengde8aa4e2010-05-05 18:28:36 +00002053SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2054 // The only time a CONCAT_VECTORS operation can have legal types is when
2055 // two 64-bit vectors are concatenated to a 128-bit vector.
2056 EVT VT = N->getValueType(0);
2057 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2058 llvm_unreachable("unexpected CONCAT_VECTORS");
2059 DebugLoc dl = N->getDebugLoc();
2060 SDValue V0 = N->getOperand(0);
2061 SDValue V1 = N->getOperand(1);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00002062 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
2063 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +00002064 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
2065 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
2066}
2067
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002068SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002069 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002070
Dan Gohmane8be6c62008-07-17 19:10:17 +00002071 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002072 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002073
2074 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002075 default: break;
2076 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002077 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002078 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002079 if (Subtarget->hasThumb2())
2080 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2081 // be done with MOV + MOVT, at worst.
2082 UseCP = 0;
2083 else {
2084 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002085 UseCP = (Val > 255 && // MOV
2086 ~Val > 255 && // MOV + MVN
2087 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002088 } else
2089 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2090 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2091 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2092 }
2093
Evan Chenga8e29892007-01-19 07:51:42 +00002094 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002095 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002096 CurDAG->getTargetConstantPool(ConstantInt::get(
2097 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002098 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002099
2100 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002101 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002102 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002103 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002104 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00002105 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
2106 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002107 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002108 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002109 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002110 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002111 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002112 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002113 CurDAG->getEntryNode()
2114 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002115 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002116 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002117 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002118 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002119 return NULL;
2120 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002121
Evan Chenga8e29892007-01-19 07:51:42 +00002122 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002123 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002124 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002125 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002126 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002127 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002128 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002129 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00002130 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
2131 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002132 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002133 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2134 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002135 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2136 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2137 CurDAG->getRegister(0, MVT::i32) };
2138 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002139 }
Evan Chenga8e29892007-01-19 07:51:42 +00002140 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002141 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002142 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002143 return I;
2144 break;
2145 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002146 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002147 return I;
2148 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002149 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002150 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002151 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002152 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002153 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002154 if (!RHSV) break;
2155 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002156 unsigned ShImm = Log2_32(RHSV-1);
2157 if (ShImm >= 32)
2158 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002159 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002160 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002161 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2162 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002163 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002164 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002165 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002166 } else {
2167 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002168 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002169 }
Evan Chenga8e29892007-01-19 07:51:42 +00002170 }
2171 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002172 unsigned ShImm = Log2_32(RHSV+1);
2173 if (ShImm >= 32)
2174 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002175 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002176 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002177 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2178 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002179 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002180 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2181 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002182 } else {
2183 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002184 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002185 }
Evan Chenga8e29892007-01-19 07:51:42 +00002186 }
2187 }
2188 break;
Evan Cheng20956592009-10-21 08:15:52 +00002189 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002190 // Check for unsigned bitfield extract
2191 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2192 return I;
2193
Evan Cheng20956592009-10-21 08:15:52 +00002194 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2195 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2196 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2197 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2198 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002199 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002200 if (VT != MVT::i32)
2201 break;
2202 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2203 ? ARM::t2MOVTi16
2204 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2205 if (!Opc)
2206 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002207 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002208 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2209 if (!N1C)
2210 break;
2211 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2212 SDValue N2 = N0.getOperand(1);
2213 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2214 if (!N2C)
2215 break;
2216 unsigned N1CVal = N1C->getZExtValue();
2217 unsigned N2CVal = N2C->getZExtValue();
2218 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2219 (N1CVal & 0xffffU) == 0xffffU &&
2220 (N2CVal & 0xffffU) == 0x0U) {
2221 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2222 MVT::i32);
2223 SDValue Ops[] = { N0.getOperand(0), Imm16,
2224 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2225 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2226 }
2227 }
2228 break;
2229 }
Jim Grosbache5165492009-11-09 00:11:35 +00002230 case ARMISD::VMOVRRD:
2231 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002232 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002233 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002234 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002235 if (Subtarget->isThumb1Only())
2236 break;
2237 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002238 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002239 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2240 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002241 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002242 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002243 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002244 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2245 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002246 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002247 }
Evan Chengee568cf2007-07-05 07:15:27 +00002248 }
Dan Gohman525178c2007-10-08 18:33:35 +00002249 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002250 if (Subtarget->isThumb1Only())
2251 break;
2252 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002253 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002254 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002255 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002256 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002257 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002258 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2259 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002260 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002261 }
Evan Chengee568cf2007-07-05 07:15:27 +00002262 }
Evan Chenga8e29892007-01-19 07:51:42 +00002263 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002264 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002265 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002266 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002267 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002268 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002269 if (ResNode)
2270 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002271 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002272 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002273 }
Evan Chengee568cf2007-07-05 07:15:27 +00002274 case ARMISD::BRCOND: {
2275 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2276 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2277 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002278
Evan Chengee568cf2007-07-05 07:15:27 +00002279 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2280 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2281 // Pattern complexity = 6 cost = 1 size = 0
2282
David Goodwin5e47a9a2009-06-30 18:04:13 +00002283 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2284 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2285 // Pattern complexity = 6 cost = 1 size = 0
2286
Jim Grosbach764ab522009-08-11 15:33:49 +00002287 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002288 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002289 SDValue Chain = N->getOperand(0);
2290 SDValue N1 = N->getOperand(1);
2291 SDValue N2 = N->getOperand(2);
2292 SDValue N3 = N->getOperand(3);
2293 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002294 assert(N1.getOpcode() == ISD::BasicBlock);
2295 assert(N2.getOpcode() == ISD::Constant);
2296 assert(N3.getOpcode() == ISD::Register);
2297
Dan Gohman475871a2008-07-27 21:46:04 +00002298 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002299 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002300 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002301 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002302 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
2303 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002304 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002305 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002306 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002307 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002308 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002309 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002310 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002311 return NULL;
2312 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002313 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002314 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002315 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002316 EVT VT = N->getValueType(0);
2317 SDValue N0 = N->getOperand(0);
2318 SDValue N1 = N->getOperand(1);
2319 SDValue N2 = N->getOperand(2);
2320 SDValue N3 = N->getOperand(3);
2321 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002322 assert(N2.getOpcode() == ISD::Constant);
2323 assert(N3.getOpcode() == ISD::Register);
2324
Dan Gohman475871a2008-07-27 21:46:04 +00002325 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002326 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002327 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002328 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002329 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002330 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002331 default: assert(false && "Illegal conditional move type!");
2332 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002333 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002334 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002335 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002336 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002337 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002338 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002339 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002340 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002341 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002342
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002343 case ARMISD::VZIP: {
2344 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002345 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002346 switch (VT.getSimpleVT().SimpleTy) {
2347 default: return NULL;
2348 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2349 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2350 case MVT::v2f32:
2351 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2352 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2353 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2354 case MVT::v4f32:
2355 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2356 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002357 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002358 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2359 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2360 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002361 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002362 case ARMISD::VUZP: {
2363 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002364 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002365 switch (VT.getSimpleVT().SimpleTy) {
2366 default: return NULL;
2367 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2368 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2369 case MVT::v2f32:
2370 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2371 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2372 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2373 case MVT::v4f32:
2374 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2375 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002376 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002377 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2378 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2379 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002380 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002381 case ARMISD::VTRN: {
2382 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002383 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002384 switch (VT.getSimpleVT().SimpleTy) {
2385 default: return NULL;
2386 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2387 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2388 case MVT::v2f32:
2389 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2390 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2391 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2392 case MVT::v4f32:
2393 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2394 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002395 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002396 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2397 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2398 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002399 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002400 case ARMISD::BUILD_VECTOR: {
2401 EVT VecVT = N->getValueType(0);
2402 EVT EltVT = VecVT.getVectorElementType();
2403 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002404 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002405 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2406 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2407 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002408 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002409 if (NumElts == 2)
2410 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2411 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2412 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2413 N->getOperand(2), N->getOperand(3));
2414 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002415
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002416 case ARMISD::VLD2DUP: {
2417 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2418 ARM::VLD2DUPd32Pseudo };
2419 return SelectVLDDup(N, 2, Opcodes);
2420 }
2421
Bob Wilson86c6d802010-11-29 19:35:29 +00002422 case ARMISD::VLD3DUP: {
2423 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2424 ARM::VLD3DUPd32Pseudo };
2425 return SelectVLDDup(N, 3, Opcodes);
2426 }
2427
Bob Wilson6c4c9822010-11-30 00:00:35 +00002428 case ARMISD::VLD4DUP: {
2429 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2430 ARM::VLD4DUPd32Pseudo };
2431 return SelectVLDDup(N, 4, Opcodes);
2432 }
2433
Bob Wilson31fb12f2009-08-26 17:39:53 +00002434 case ISD::INTRINSIC_VOID:
2435 case ISD::INTRINSIC_W_CHAIN: {
2436 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002437 switch (IntNo) {
2438 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002439 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002440
Bob Wilson621f1952010-03-23 05:25:43 +00002441 case Intrinsic::arm_neon_vld1: {
2442 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2443 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002444 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2445 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson621f1952010-03-23 05:25:43 +00002446 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2447 }
2448
Bob Wilson31fb12f2009-08-26 17:39:53 +00002449 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002450 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2451 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2452 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2453 ARM::VLD2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002454 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002455 }
2456
2457 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002458 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2459 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2460 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2461 ARM::VLD3q16Pseudo_UPD,
2462 ARM::VLD3q32Pseudo_UPD };
2463 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2464 ARM::VLD3q16oddPseudo_UPD,
2465 ARM::VLD3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002466 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002467 }
2468
2469 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002470 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2471 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2472 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2473 ARM::VLD4q16Pseudo_UPD,
2474 ARM::VLD4q32Pseudo_UPD };
2475 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2476 ARM::VLD4q16oddPseudo_UPD,
2477 ARM::VLD4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002478 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002479 }
2480
Bob Wilson243fcc52009-09-01 04:26:28 +00002481 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002482 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2483 ARM::VLD2LNd32Pseudo };
2484 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
2485 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002486 }
2487
2488 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002489 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2490 ARM::VLD3LNd32Pseudo };
2491 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
2492 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002493 }
2494
2495 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002496 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2497 ARM::VLD4LNd32Pseudo };
2498 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
2499 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002500 }
2501
Bob Wilson11d98992010-03-23 06:20:33 +00002502 case Intrinsic::arm_neon_vst1: {
2503 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2504 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002505 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2506 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson11d98992010-03-23 06:20:33 +00002507 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2508 }
2509
Bob Wilson31fb12f2009-08-26 17:39:53 +00002510 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002511 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2512 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2513 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2514 ARM::VST2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002515 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002516 }
2517
2518 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002519 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2520 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2521 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2522 ARM::VST3q16Pseudo_UPD,
2523 ARM::VST3q32Pseudo_UPD };
2524 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2525 ARM::VST3q16oddPseudo_UPD,
2526 ARM::VST3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002527 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002528 }
2529
2530 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002531 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002532 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002533 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2534 ARM::VST4q16Pseudo_UPD,
2535 ARM::VST4q32Pseudo_UPD };
2536 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2537 ARM::VST4q16oddPseudo_UPD,
2538 ARM::VST4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002539 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002540 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002541
2542 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002543 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2544 ARM::VST2LNd32Pseudo };
2545 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
2546 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002547 }
2548
2549 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002550 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2551 ARM::VST3LNd32Pseudo };
2552 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
2553 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002554 }
2555
2556 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002557 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2558 ARM::VST4LNd32Pseudo };
2559 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
2560 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002561 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002562 }
Bob Wilson429009b2010-05-06 16:05:26 +00002563 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002564 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002565
Bob Wilsond491d6e2010-07-06 23:36:25 +00002566 case ISD::INTRINSIC_WO_CHAIN: {
2567 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2568 switch (IntNo) {
2569 default:
2570 break;
2571
2572 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002573 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002574 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002575 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002576 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002577 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002578
2579 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002580 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002581 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002582 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002583 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002584 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002585 }
2586 break;
2587 }
2588
Bob Wilson429009b2010-05-06 16:05:26 +00002589 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002590 return SelectConcatVector(N);
2591 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002592
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002593 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002594}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002595
Bob Wilson224c2442009-05-19 05:53:42 +00002596bool ARMDAGToDAGISel::
2597SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2598 std::vector<SDValue> &OutOps) {
2599 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002600 // Require the address to be in a register. That is safe for all ARM
2601 // variants and it is hard to do anything much smarter without knowing
2602 // how the operand is used.
2603 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002604 return false;
2605}
2606
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002607/// createARMISelDag - This pass converts a legalized DAG into a
2608/// ARM-specific DAG, ready for instruction scheduling.
2609///
Bob Wilson522ce972009-09-28 14:30:20 +00002610FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2611 CodeGenOpt::Level OptLevel) {
2612 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002613}