blob: bfba11449f4269ed9fde1c995282febe156264ab [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;
1625 // Alignment must be a power of two; make sure of that.
1626 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001627 if (Alignment == 1)
1628 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001629 }
Bob Wilson665814b2010-11-01 23:40:51 +00001630 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001631
Bob Wilsona7c397c2009-10-14 16:19:03 +00001632 unsigned OpcodeIndex;
1633 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001634 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001635 // Double-register operations:
1636 case MVT::v8i8: OpcodeIndex = 0; break;
1637 case MVT::v4i16: OpcodeIndex = 1; break;
1638 case MVT::v2f32:
1639 case MVT::v2i32: OpcodeIndex = 2; break;
1640 // Quad-register operations:
1641 case MVT::v8i16: OpcodeIndex = 0; break;
1642 case MVT::v4f32:
1643 case MVT::v4i32: OpcodeIndex = 1; break;
1644 }
1645
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001646 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001647 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001648
Bob Wilson8466fa12010-09-13 23:01:35 +00001649 SmallVector<SDValue, 7> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001650 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001651 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001652
Jim Grosbach3ab56582010-10-21 19:38:40 +00001653 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
Eric Christopher23da0b22010-09-14 08:31:25 +00001654 QOpcodes[OpcodeIndex]);
Bob Wilson07f6e802010-06-16 21:34:01 +00001655
Bob Wilson8466fa12010-09-13 23:01:35 +00001656 SDValue SuperReg;
1657 SDValue V0 = N->getOperand(0+3);
1658 SDValue V1 = N->getOperand(1+3);
1659 if (NumVecs == 2) {
1660 if (is64BitVector)
1661 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1662 else
1663 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001664 } else {
Bob Wilson8466fa12010-09-13 23:01:35 +00001665 SDValue V2 = N->getOperand(2+3);
1666 SDValue V3 = (NumVecs == 3)
1667 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1668 : N->getOperand(3+3);
1669 if (is64BitVector)
1670 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1671 else
1672 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001673 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001674 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001675 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001676 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001677 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001678 Ops.push_back(Chain);
1679
Bob Wilson96493442009-10-14 16:46:45 +00001680 if (!IsLoad)
Bob Wilson8466fa12010-09-13 23:01:35 +00001681 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 7);
Bob Wilson96493442009-10-14 16:46:45 +00001682
Bob Wilson8466fa12010-09-13 23:01:35 +00001683 EVT ResTy;
1684 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1685 if (!is64BitVector)
1686 ResTyElts *= 2;
1687 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001688
Bob Wilson8466fa12010-09-13 23:01:35 +00001689 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other,
1690 Ops.data(), 7);
1691 SuperReg = SDValue(VLdLn, 0);
1692 Chain = SDValue(VLdLn, 1);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001693
Bob Wilson8466fa12010-09-13 23:01:35 +00001694 // Extract the subregisters.
Bob Wilson07f6e802010-06-16 21:34:01 +00001695 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1696 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1697 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
1698 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1699 ReplaceUses(SDValue(N, Vec),
Bob Wilson8466fa12010-09-13 23:01:35 +00001700 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
1701 ReplaceUses(SDValue(N, NumVecs), Chain);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001702 return NULL;
1703}
1704
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001705SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, unsigned NumVecs,
1706 unsigned *Opcodes) {
1707 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1708 DebugLoc dl = N->getDebugLoc();
1709
1710 SDValue MemAddr, Align;
1711 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1712 return NULL;
1713
1714 SDValue Chain = N->getOperand(0);
1715 EVT VT = N->getValueType(0);
1716
1717 unsigned Alignment = 0;
1718 if (NumVecs != 3) {
1719 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1720 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1721 if (Alignment > NumBytes)
1722 Alignment = NumBytes;
1723 // Alignment must be a power of two; make sure of that.
1724 Alignment = (Alignment & -Alignment);
1725 if (Alignment == 1)
1726 Alignment = 0;
1727 }
1728 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1729
1730 unsigned OpcodeIndex;
1731 switch (VT.getSimpleVT().SimpleTy) {
1732 default: llvm_unreachable("unhandled vld-dup type");
1733 case MVT::v8i8: OpcodeIndex = 0; break;
1734 case MVT::v4i16: OpcodeIndex = 1; break;
1735 case MVT::v2f32:
1736 case MVT::v2i32: OpcodeIndex = 2; break;
1737 }
1738
1739 SDValue Pred = getAL(CurDAG);
1740 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1741 SDValue SuperReg;
1742 unsigned Opc = Opcodes[OpcodeIndex];
1743 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
1744
1745 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1746 EVT ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1747 SDNode *VLdDup = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
1748 SuperReg = SDValue(VLdDup, 0);
1749 Chain = SDValue(VLdDup, 1);
1750
1751 // Extract the subregisters.
1752 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1753 unsigned SubIdx = ARM::dsub_0;
1754 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1755 ReplaceUses(SDValue(N, Vec),
1756 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
1757 ReplaceUses(SDValue(N, NumVecs), Chain);
1758 return NULL;
1759}
1760
Bob Wilson78dfbc32010-07-07 00:08:54 +00001761SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1762 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001763 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1764 DebugLoc dl = N->getDebugLoc();
1765 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001766 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001767
1768 // Form a REG_SEQUENCE to force register allocation.
1769 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001770 SDValue V0 = N->getOperand(FirstTblReg + 0);
1771 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001772 if (NumVecs == 2)
1773 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1774 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001775 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001776 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00001777 // an undef.
1778 SDValue V3 = (NumVecs == 3)
1779 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001780 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001781 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1782 }
1783
Bob Wilson78dfbc32010-07-07 00:08:54 +00001784 SmallVector<SDValue, 6> Ops;
1785 if (IsExt)
1786 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00001787 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001788 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001789 Ops.push_back(getAL(CurDAG)); // predicate
1790 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001791 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001792}
1793
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001794SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001795 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001796 if (!Subtarget->hasV6T2Ops())
1797 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001798
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001799 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1800 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1801
1802
1803 // For unsigned extracts, check for a shift right and mask
1804 unsigned And_imm = 0;
1805 if (N->getOpcode() == ISD::AND) {
1806 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1807
1808 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1809 if (And_imm & (And_imm + 1))
1810 return NULL;
1811
1812 unsigned Srl_imm = 0;
1813 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1814 Srl_imm)) {
1815 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1816
1817 unsigned Width = CountTrailingOnes_32(And_imm);
1818 unsigned LSB = Srl_imm;
1819 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1820 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1821 CurDAG->getTargetConstant(LSB, MVT::i32),
1822 CurDAG->getTargetConstant(Width, MVT::i32),
1823 getAL(CurDAG), Reg0 };
1824 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1825 }
1826 }
1827 return NULL;
1828 }
1829
1830 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001831 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001832 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001833 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1834 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001835 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001836 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1837 unsigned Width = 32 - Srl_imm;
1838 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001839 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001840 return NULL;
1841 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001842 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001843 CurDAG->getTargetConstant(LSB, MVT::i32),
1844 CurDAG->getTargetConstant(Width, MVT::i32),
1845 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001846 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001847 }
1848 }
1849 return NULL;
1850}
1851
Evan Cheng9ef48352009-11-20 00:54:03 +00001852SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001853SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001854 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1855 SDValue CPTmp0;
1856 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00001857 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001858 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1859 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1860 unsigned Opc = 0;
1861 switch (SOShOp) {
1862 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1863 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1864 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1865 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1866 default:
1867 llvm_unreachable("Unknown so_reg opcode!");
1868 break;
1869 }
1870 SDValue SOShImm =
1871 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1872 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1873 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001874 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001875 }
1876 return 0;
1877}
1878
1879SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001880SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001881 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1882 SDValue CPTmp0;
1883 SDValue CPTmp1;
1884 SDValue CPTmp2;
Chris Lattner52a261b2010-09-21 20:31:19 +00001885 if (SelectShifterOperandReg(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001886 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1887 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001888 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001889 }
1890 return 0;
1891}
1892
1893SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00001894SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00001895 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001896 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00001897 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00001898 return 0;
1899
Evan Cheng63f35442010-11-13 02:25:14 +00001900 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00001901 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00001902 if (is_t2_so_imm(TrueImm)) {
1903 Opc = ARM::t2MOVCCi;
1904 } else if (TrueImm <= 0xffff) {
1905 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00001906 } else if (is_t2_so_imm_not(TrueImm)) {
1907 TrueImm = ~TrueImm;
1908 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00001909 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00001910 // Large immediate.
1911 Opc = ARM::t2MOVCCi32imm;
1912 }
1913
1914 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00001915 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00001916 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1917 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00001918 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00001919 }
Evan Cheng63f35442010-11-13 02:25:14 +00001920
Evan Cheng9ef48352009-11-20 00:54:03 +00001921 return 0;
1922}
1923
1924SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001925SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00001926 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001927 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1928 if (!T)
1929 return 0;
1930
Evan Cheng63f35442010-11-13 02:25:14 +00001931 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001932 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00001933 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00001934 if (isSoImm) {
1935 Opc = ARM::MOVCCi;
1936 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
1937 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00001938 } else if (is_so_imm_not(TrueImm)) {
1939 TrueImm = ~TrueImm;
1940 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00001941 } else if (TrueVal.getNode()->hasOneUse() &&
1942 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00001943 // Large immediate.
1944 Opc = ARM::MOVCCi32imm;
1945 }
1946
1947 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001948 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00001949 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1950 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00001951 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00001952 }
Evan Cheng63f35442010-11-13 02:25:14 +00001953
Evan Cheng9ef48352009-11-20 00:54:03 +00001954 return 0;
1955}
1956
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001957SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1958 EVT VT = N->getValueType(0);
1959 SDValue FalseVal = N->getOperand(0);
1960 SDValue TrueVal = N->getOperand(1);
1961 SDValue CC = N->getOperand(2);
1962 SDValue CCR = N->getOperand(3);
1963 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001964 assert(CC.getOpcode() == ISD::Constant);
1965 assert(CCR.getOpcode() == ISD::Register);
1966 ARMCC::CondCodes CCVal =
1967 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001968
1969 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1970 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1971 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1972 // Pattern complexity = 18 cost = 1 size = 0
1973 SDValue CPTmp0;
1974 SDValue CPTmp1;
1975 SDValue CPTmp2;
1976 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001977 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001978 CCVal, CCR, InFlag);
1979 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001980 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001981 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1982 if (Res)
1983 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001984 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001985 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001986 CCVal, CCR, InFlag);
1987 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001988 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001989 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1990 if (Res)
1991 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001992 }
1993
1994 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00001995 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00001996 // (imm:i32):$cc)
1997 // Emits: (MOVCCi:i32 GPR:i32:$false,
1998 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1999 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002000 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002001 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002002 CCVal, CCR, InFlag);
2003 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002004 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002005 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2006 if (Res)
2007 return Res;
2008 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002009 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002010 CCVal, CCR, InFlag);
2011 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002012 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002013 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2014 if (Res)
2015 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002016 }
2017 }
2018
2019 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2020 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2021 // Pattern complexity = 6 cost = 1 size = 0
2022 //
2023 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2024 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2025 // Pattern complexity = 6 cost = 11 size = 0
2026 //
2027 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002028 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2029 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002030 unsigned Opc = 0;
2031 switch (VT.getSimpleVT().SimpleTy) {
2032 default: assert(false && "Illegal conditional move type!");
2033 break;
2034 case MVT::i32:
2035 Opc = Subtarget->isThumb()
2036 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2037 : ARM::MOVCCr;
2038 break;
2039 case MVT::f32:
2040 Opc = ARM::VMOVScc;
2041 break;
2042 case MVT::f64:
2043 Opc = ARM::VMOVDcc;
2044 break;
2045 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002046 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002047}
2048
Evan Chengde8aa4e2010-05-05 18:28:36 +00002049SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2050 // The only time a CONCAT_VECTORS operation can have legal types is when
2051 // two 64-bit vectors are concatenated to a 128-bit vector.
2052 EVT VT = N->getValueType(0);
2053 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2054 llvm_unreachable("unexpected CONCAT_VECTORS");
2055 DebugLoc dl = N->getDebugLoc();
2056 SDValue V0 = N->getOperand(0);
2057 SDValue V1 = N->getOperand(1);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00002058 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
2059 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +00002060 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
2061 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
2062}
2063
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002064SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002065 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002066
Dan Gohmane8be6c62008-07-17 19:10:17 +00002067 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002068 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002069
2070 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002071 default: break;
2072 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002073 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002074 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002075 if (Subtarget->hasThumb2())
2076 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2077 // be done with MOV + MOVT, at worst.
2078 UseCP = 0;
2079 else {
2080 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002081 UseCP = (Val > 255 && // MOV
2082 ~Val > 255 && // MOV + MVN
2083 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002084 } else
2085 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2086 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2087 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2088 }
2089
Evan Chenga8e29892007-01-19 07:51:42 +00002090 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002091 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002092 CurDAG->getTargetConstantPool(ConstantInt::get(
2093 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002094 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002095
2096 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002097 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002098 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002099 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002100 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00002101 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
2102 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002103 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002104 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002105 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002106 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002107 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002108 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002109 CurDAG->getEntryNode()
2110 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002111 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002112 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002113 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002114 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002115 return NULL;
2116 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002117
Evan Chenga8e29892007-01-19 07:51:42 +00002118 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002119 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002120 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002121 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002122 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002123 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002124 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002125 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00002126 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
2127 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002128 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002129 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2130 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002131 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2132 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2133 CurDAG->getRegister(0, MVT::i32) };
2134 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002135 }
Evan Chenga8e29892007-01-19 07:51:42 +00002136 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002137 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002138 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002139 return I;
2140 break;
2141 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002142 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002143 return I;
2144 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002145 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002146 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002147 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002148 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002149 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002150 if (!RHSV) break;
2151 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002152 unsigned ShImm = Log2_32(RHSV-1);
2153 if (ShImm >= 32)
2154 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002155 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002156 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002157 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2158 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002159 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002160 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002161 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002162 } else {
2163 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002164 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002165 }
Evan Chenga8e29892007-01-19 07:51:42 +00002166 }
2167 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002168 unsigned ShImm = Log2_32(RHSV+1);
2169 if (ShImm >= 32)
2170 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002171 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002172 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002173 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2174 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002175 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002176 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2177 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002178 } else {
2179 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002180 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002181 }
Evan Chenga8e29892007-01-19 07:51:42 +00002182 }
2183 }
2184 break;
Evan Cheng20956592009-10-21 08:15:52 +00002185 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002186 // Check for unsigned bitfield extract
2187 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2188 return I;
2189
Evan Cheng20956592009-10-21 08:15:52 +00002190 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2191 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2192 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2193 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2194 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002195 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002196 if (VT != MVT::i32)
2197 break;
2198 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2199 ? ARM::t2MOVTi16
2200 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2201 if (!Opc)
2202 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002203 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002204 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2205 if (!N1C)
2206 break;
2207 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2208 SDValue N2 = N0.getOperand(1);
2209 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2210 if (!N2C)
2211 break;
2212 unsigned N1CVal = N1C->getZExtValue();
2213 unsigned N2CVal = N2C->getZExtValue();
2214 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2215 (N1CVal & 0xffffU) == 0xffffU &&
2216 (N2CVal & 0xffffU) == 0x0U) {
2217 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2218 MVT::i32);
2219 SDValue Ops[] = { N0.getOperand(0), Imm16,
2220 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2221 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2222 }
2223 }
2224 break;
2225 }
Jim Grosbache5165492009-11-09 00:11:35 +00002226 case ARMISD::VMOVRRD:
2227 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002228 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002229 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002230 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002231 if (Subtarget->isThumb1Only())
2232 break;
2233 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002234 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002235 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2236 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002237 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002238 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002239 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002240 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2241 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002242 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002243 }
Evan Chengee568cf2007-07-05 07:15:27 +00002244 }
Dan Gohman525178c2007-10-08 18:33:35 +00002245 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002246 if (Subtarget->isThumb1Only())
2247 break;
2248 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002249 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002250 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002251 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002252 } else {
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),
2255 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002256 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002257 }
Evan Chengee568cf2007-07-05 07:15:27 +00002258 }
Evan Chenga8e29892007-01-19 07:51:42 +00002259 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002260 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002261 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002262 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002263 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002264 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002265 if (ResNode)
2266 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002267 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002268 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002269 }
Evan Chengee568cf2007-07-05 07:15:27 +00002270 case ARMISD::BRCOND: {
2271 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2272 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2273 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002274
Evan Chengee568cf2007-07-05 07:15:27 +00002275 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2276 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2277 // Pattern complexity = 6 cost = 1 size = 0
2278
David Goodwin5e47a9a2009-06-30 18:04:13 +00002279 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2280 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2281 // Pattern complexity = 6 cost = 1 size = 0
2282
Jim Grosbach764ab522009-08-11 15:33:49 +00002283 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002284 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002285 SDValue Chain = N->getOperand(0);
2286 SDValue N1 = N->getOperand(1);
2287 SDValue N2 = N->getOperand(2);
2288 SDValue N3 = N->getOperand(3);
2289 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002290 assert(N1.getOpcode() == ISD::BasicBlock);
2291 assert(N2.getOpcode() == ISD::Constant);
2292 assert(N3.getOpcode() == ISD::Register);
2293
Dan Gohman475871a2008-07-27 21:46:04 +00002294 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002295 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002296 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002297 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002298 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
2299 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002300 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002301 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002302 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002303 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002304 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002305 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002306 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002307 return NULL;
2308 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002309 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002310 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002311 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002312 EVT VT = N->getValueType(0);
2313 SDValue N0 = N->getOperand(0);
2314 SDValue N1 = N->getOperand(1);
2315 SDValue N2 = N->getOperand(2);
2316 SDValue N3 = N->getOperand(3);
2317 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002318 assert(N2.getOpcode() == ISD::Constant);
2319 assert(N3.getOpcode() == ISD::Register);
2320
Dan Gohman475871a2008-07-27 21:46:04 +00002321 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002322 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002323 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002324 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002325 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002326 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002327 default: assert(false && "Illegal conditional move type!");
2328 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002329 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002330 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002331 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002332 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002333 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002334 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002335 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002336 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002337 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002338
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002339 case ARMISD::VZIP: {
2340 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002341 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002342 switch (VT.getSimpleVT().SimpleTy) {
2343 default: return NULL;
2344 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2345 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2346 case MVT::v2f32:
2347 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2348 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2349 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2350 case MVT::v4f32:
2351 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2352 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002353 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002354 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2355 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2356 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002357 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002358 case ARMISD::VUZP: {
2359 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002360 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002361 switch (VT.getSimpleVT().SimpleTy) {
2362 default: return NULL;
2363 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2364 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2365 case MVT::v2f32:
2366 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2367 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2368 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2369 case MVT::v4f32:
2370 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2371 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002372 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002373 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2374 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2375 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002376 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002377 case ARMISD::VTRN: {
2378 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002379 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002380 switch (VT.getSimpleVT().SimpleTy) {
2381 default: return NULL;
2382 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2383 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2384 case MVT::v2f32:
2385 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2386 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2387 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2388 case MVT::v4f32:
2389 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2390 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002391 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002392 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2393 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2394 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002395 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002396 case ARMISD::BUILD_VECTOR: {
2397 EVT VecVT = N->getValueType(0);
2398 EVT EltVT = VecVT.getVectorElementType();
2399 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002400 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002401 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2402 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2403 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002404 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002405 if (NumElts == 2)
2406 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2407 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2408 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2409 N->getOperand(2), N->getOperand(3));
2410 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002411
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002412 case ARMISD::VLD2DUP: {
2413 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2414 ARM::VLD2DUPd32Pseudo };
2415 return SelectVLDDup(N, 2, Opcodes);
2416 }
2417
Bob Wilson86c6d802010-11-29 19:35:29 +00002418 case ARMISD::VLD3DUP: {
2419 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2420 ARM::VLD3DUPd32Pseudo };
2421 return SelectVLDDup(N, 3, Opcodes);
2422 }
2423
Bob Wilson6c4c9822010-11-30 00:00:35 +00002424 case ARMISD::VLD4DUP: {
2425 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2426 ARM::VLD4DUPd32Pseudo };
2427 return SelectVLDDup(N, 4, Opcodes);
2428 }
2429
Bob Wilson31fb12f2009-08-26 17:39:53 +00002430 case ISD::INTRINSIC_VOID:
2431 case ISD::INTRINSIC_W_CHAIN: {
2432 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002433 switch (IntNo) {
2434 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002435 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002436
Bob Wilson621f1952010-03-23 05:25:43 +00002437 case Intrinsic::arm_neon_vld1: {
2438 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2439 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002440 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2441 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson621f1952010-03-23 05:25:43 +00002442 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2443 }
2444
Bob Wilson31fb12f2009-08-26 17:39:53 +00002445 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002446 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2447 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2448 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2449 ARM::VLD2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002450 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002451 }
2452
2453 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002454 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2455 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2456 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2457 ARM::VLD3q16Pseudo_UPD,
2458 ARM::VLD3q32Pseudo_UPD };
2459 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2460 ARM::VLD3q16oddPseudo_UPD,
2461 ARM::VLD3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002462 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002463 }
2464
2465 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002466 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2467 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2468 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2469 ARM::VLD4q16Pseudo_UPD,
2470 ARM::VLD4q32Pseudo_UPD };
2471 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2472 ARM::VLD4q16oddPseudo_UPD,
2473 ARM::VLD4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002474 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002475 }
2476
Bob Wilson243fcc52009-09-01 04:26:28 +00002477 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002478 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2479 ARM::VLD2LNd32Pseudo };
2480 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
2481 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002482 }
2483
2484 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002485 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2486 ARM::VLD3LNd32Pseudo };
2487 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
2488 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002489 }
2490
2491 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002492 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2493 ARM::VLD4LNd32Pseudo };
2494 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
2495 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002496 }
2497
Bob Wilson11d98992010-03-23 06:20:33 +00002498 case Intrinsic::arm_neon_vst1: {
2499 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2500 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002501 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2502 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson11d98992010-03-23 06:20:33 +00002503 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2504 }
2505
Bob Wilson31fb12f2009-08-26 17:39:53 +00002506 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002507 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2508 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2509 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2510 ARM::VST2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002511 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002512 }
2513
2514 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002515 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2516 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2517 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2518 ARM::VST3q16Pseudo_UPD,
2519 ARM::VST3q32Pseudo_UPD };
2520 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2521 ARM::VST3q16oddPseudo_UPD,
2522 ARM::VST3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002523 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002524 }
2525
2526 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002527 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002528 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002529 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2530 ARM::VST4q16Pseudo_UPD,
2531 ARM::VST4q32Pseudo_UPD };
2532 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2533 ARM::VST4q16oddPseudo_UPD,
2534 ARM::VST4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002535 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002536 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002537
2538 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002539 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2540 ARM::VST2LNd32Pseudo };
2541 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
2542 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002543 }
2544
2545 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002546 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2547 ARM::VST3LNd32Pseudo };
2548 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
2549 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002550 }
2551
2552 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002553 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2554 ARM::VST4LNd32Pseudo };
2555 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
2556 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002557 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002558 }
Bob Wilson429009b2010-05-06 16:05:26 +00002559 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002560 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002561
Bob Wilsond491d6e2010-07-06 23:36:25 +00002562 case ISD::INTRINSIC_WO_CHAIN: {
2563 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2564 switch (IntNo) {
2565 default:
2566 break;
2567
2568 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002569 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002570 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002571 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002572 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002573 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002574
2575 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002576 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002577 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002578 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002579 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002580 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002581 }
2582 break;
2583 }
2584
Bob Wilson429009b2010-05-06 16:05:26 +00002585 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002586 return SelectConcatVector(N);
2587 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002588
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002589 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002590}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002591
Bob Wilson224c2442009-05-19 05:53:42 +00002592bool ARMDAGToDAGISel::
2593SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2594 std::vector<SDValue> &OutOps) {
2595 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002596 // Require the address to be in a register. That is safe for all ARM
2597 // variants and it is hard to do anything much smarter without knowing
2598 // how the operand is used.
2599 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002600 return false;
2601}
2602
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002603/// createARMISelDag - This pass converts a legalized DAG into a
2604/// ARM-specific DAG, ready for instruction scheduling.
2605///
Bob Wilson522ce972009-09-28 14:30:20 +00002606FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2607 CodeGenOpt::Level OptLevel) {
2608 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002609}