blob: 7bd0bace9090e346c12f7fb617d1802148c7036d [file] [log] [blame]
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001//===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the ARM target.
11//
12//===----------------------------------------------------------------------===//
13
Dale Johannesen51e28e62010-06-03 21:09:53 +000014#define DEBUG_TYPE "arm-isel"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000015#include "ARM.h"
Evan Cheng48575f62010-12-05 22:04:16 +000016#include "ARMBaseInstrInfo.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000017#include "ARMTargetMachine.h"
Evan Chengee04a6d2011-07-20 23:34:39 +000018#include "MCTargetDesc/ARMAddressingModes.h"
Rafael Espindola84b19be2006-07-16 01:02:57 +000019#include "llvm/CallingConv.h"
Evan Chenga8e29892007-01-19 07:51:42 +000020#include "llvm/Constants.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000021#include "llvm/DerivedTypes.h"
22#include "llvm/Function.h"
23#include "llvm/Intrinsics.h"
Owen Anderson9adc0ab2009-07-14 23:09:55 +000024#include "llvm/LLVMContext.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000025#include "llvm/CodeGen/MachineFrameInfo.h"
26#include "llvm/CodeGen/MachineFunction.h"
27#include "llvm/CodeGen/MachineInstrBuilder.h"
28#include "llvm/CodeGen/SelectionDAG.h"
29#include "llvm/CodeGen/SelectionDAGISel.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000030#include "llvm/Target/TargetLowering.h"
Chris Lattner72939122007-05-03 00:32:00 +000031#include "llvm/Target/TargetOptions.h"
Evan Cheng94cc6d32010-05-04 20:39:49 +000032#include "llvm/Support/CommandLine.h"
Chris Lattner3d62d782008-02-03 05:43:57 +000033#include "llvm/Support/Compiler.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000034#include "llvm/Support/Debug.h"
Torok Edwindac237e2009-07-08 20:53:28 +000035#include "llvm/Support/ErrorHandling.h"
36#include "llvm/Support/raw_ostream.h"
37
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000038using namespace llvm;
39
Evan Chenga2c519b2010-07-30 23:33:54 +000040static cl::opt<bool>
41DisableShifterOp("disable-shifter-op", cl::Hidden,
42 cl::desc("Disable isel of shifter-op"),
43 cl::init(false));
44
Evan Cheng48575f62010-12-05 22:04:16 +000045static cl::opt<bool>
46CheckVMLxHazard("check-vmlx-hazard", cl::Hidden,
47 cl::desc("Check fp vmla / vmls hazard at isel time"),
Bob Wilson84c5eed2011-04-19 18:11:57 +000048 cl::init(true));
Evan Cheng48575f62010-12-05 22:04:16 +000049
Bill Wendlingef2c86f2011-10-10 22:59:55 +000050static cl::opt<bool>
51DisableARMIntABS("disable-arm-int-abs", cl::Hidden,
52 cl::desc("Enable / disable ARM integer abs transform"),
53 cl::init(false));
54
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000055//===--------------------------------------------------------------------===//
56/// ARMDAGToDAGISel - ARM specific code to select ARM machine
57/// instructions for SelectionDAG operations.
58///
59namespace {
Jim Grosbach82891622010-09-29 19:03:54 +000060
61enum AddrMode2Type {
62 AM2_BASE, // Simple AM2 (+-imm12)
63 AM2_SHOP // Shifter-op AM2
64};
65
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000066class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000067 ARMBaseTargetMachine &TM;
Evan Cheng48575f62010-12-05 22:04:16 +000068 const ARMBaseInstrInfo *TII;
Evan Cheng3f7eb8e2008-09-18 07:24:33 +000069
Evan Chenga8e29892007-01-19 07:51:42 +000070 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
71 /// make the right decision when generating code for different targets.
72 const ARMSubtarget *Subtarget;
73
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000074public:
Bob Wilson522ce972009-09-28 14:30:20 +000075 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
76 CodeGenOpt::Level OptLevel)
77 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Cheng48575f62010-12-05 22:04:16 +000078 TII(static_cast<const ARMBaseInstrInfo*>(TM.getInstrInfo())),
79 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000080 }
81
Evan Chenga8e29892007-01-19 07:51:42 +000082 virtual const char *getPassName() const {
83 return "ARM Instruction Selection";
Anton Korobeynikov52237112009-06-17 18:13:58 +000084 }
85
Bob Wilsonaf4a8912009-10-08 18:51:31 +000086 /// getI32Imm - Return a target constant of type i32 with the specified
87 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000088 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000089 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000090 }
91
Dan Gohmaneeb3a002010-01-05 01:24:18 +000092 SDNode *Select(SDNode *N);
Evan Cheng014bf212010-02-15 19:41:07 +000093
Evan Cheng48575f62010-12-05 22:04:16 +000094
95 bool hasNoVMLxHazardUse(SDNode *N) const;
Evan Chengf40deed2010-10-27 23:41:30 +000096 bool isShifterOpProfitable(const SDValue &Shift,
97 ARM_AM::ShiftOpc ShOpcVal, unsigned ShAmt);
Owen Anderson92a20222011-07-21 18:54:16 +000098 bool SelectRegShifterOperand(SDValue N, SDValue &A,
99 SDValue &B, SDValue &C,
100 bool CheckProfitability = true);
101 bool SelectImmShifterOperand(SDValue N, SDValue &A,
Owen Anderson152d4a42011-07-21 23:38:37 +0000102 SDValue &B, bool CheckProfitability = true);
103 bool SelectShiftRegShifterOperand(SDValue N, SDValue &A,
Owen Anderson099e5552011-03-18 19:46:58 +0000104 SDValue &B, SDValue &C) {
105 // Don't apply the profitability check
Owen Anderson152d4a42011-07-21 23:38:37 +0000106 return SelectRegShifterOperand(N, A, B, C, false);
107 }
108 bool SelectShiftImmShifterOperand(SDValue N, SDValue &A,
109 SDValue &B) {
110 // Don't apply the profitability check
111 return SelectImmShifterOperand(N, A, B, false);
Owen Anderson099e5552011-03-18 19:46:58 +0000112 }
113
Jim Grosbach3e556122010-10-26 22:37:02 +0000114 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
115 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
116
Jim Grosbach82891622010-09-29 19:03:54 +0000117 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
118 SDValue &Offset, SDValue &Opc);
119 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
120 SDValue &Opc) {
121 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
122 }
123
124 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
125 SDValue &Opc) {
126 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
127 }
128
129 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
130 SDValue &Opc) {
131 SelectAddrMode2Worker(N, Base, Offset, Opc);
Jim Grosbach3e556122010-10-26 22:37:02 +0000132// return SelectAddrMode2ShOp(N, Base, Offset, Opc);
Jim Grosbach82891622010-09-29 19:03:54 +0000133 // This always matches one way or another.
134 return true;
135 }
136
Owen Anderson793e7962011-07-26 20:54:26 +0000137 bool SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
138 SDValue &Offset, SDValue &Opc);
139 bool SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000140 SDValue &Offset, SDValue &Opc);
Owen Andersonc4e16de2011-08-29 20:16:50 +0000141 bool SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
142 SDValue &Offset, SDValue &Opc);
Jim Grosbach19dec202011-08-05 20:35:44 +0000143 bool SelectAddrOffsetNone(SDValue N, SDValue &Base);
Chris Lattner52a261b2010-09-21 20:31:19 +0000144 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000145 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000146 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000147 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000148 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000149 SDValue &Offset);
Bob Wilson665814b2010-11-01 23:40:51 +0000150 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
Bob Wilsonda525062011-02-25 06:42:42 +0000151 bool SelectAddrMode6Offset(SDNode *Op, SDValue N, SDValue &Offset);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000152
Evan Cheng5de5d4b2011-01-17 08:03:18 +0000153 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +0000154
Bill Wendlingf4caf692010-12-14 03:36:38 +0000155 // Thumb Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000156 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000157 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
158 unsigned Scale);
159 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
160 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
161 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
162 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
163 SDValue &OffImm);
164 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
165 SDValue &OffImm);
166 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
167 SDValue &OffImm);
168 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
169 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000170 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000171
Bill Wendlingf4caf692010-12-14 03:36:38 +0000172 // Thumb 2 Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000173 bool SelectT2ShifterOperandReg(SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000174 SDValue &BaseReg, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000175 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
176 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000177 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000178 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000179 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000180 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000181 SDValue &OffReg, SDValue &ShImm);
182
Evan Cheng875a6ac2010-11-12 22:42:47 +0000183 inline bool is_so_imm(unsigned Imm) const {
184 return ARM_AM::getSOImmVal(Imm) != -1;
185 }
186
187 inline bool is_so_imm_not(unsigned Imm) const {
188 return ARM_AM::getSOImmVal(~Imm) != -1;
189 }
190
191 inline bool is_t2_so_imm(unsigned Imm) const {
192 return ARM_AM::getT2SOImmVal(Imm) != -1;
193 }
194
195 inline bool is_t2_so_imm_not(unsigned Imm) const {
196 return ARM_AM::getT2SOImmVal(~Imm) != -1;
197 }
198
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000199 // Include the pieces autogenerated from the target description.
200#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000201
202private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000203 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
204 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000205 SDNode *SelectARMIndexedLoad(SDNode *N);
206 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000207
Bob Wilson621f1952010-03-23 05:25:43 +0000208 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
209 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000210 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000211 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000212 SDNode *SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
213 unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000214 unsigned *QOpcodes0, unsigned *QOpcodes1);
215
Bob Wilson24f995d2009-10-14 18:32:29 +0000216 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000217 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000218 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000219 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000220 SDNode *SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
221 unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000222 unsigned *QOpcodes0, unsigned *QOpcodes1);
223
Bob Wilson96493442009-10-14 16:46:45 +0000224 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000225 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson8466fa12010-09-13 23:01:35 +0000226 /// load/store of D registers and Q registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000227 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad,
228 bool isUpdating, unsigned NumVecs,
Bob Wilson8466fa12010-09-13 23:01:35 +0000229 unsigned *DOpcodes, unsigned *QOpcodes);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000230
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000231 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
232 /// should be 2, 3 or 4. The opcode array specifies the instructions used
233 /// for loading D registers. (Q registers are not supported.)
Bob Wilson1c3ef902011-02-07 17:43:21 +0000234 SDNode *SelectVLDDup(SDNode *N, bool isUpdating, unsigned NumVecs,
235 unsigned *Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000236
Bob Wilson78dfbc32010-07-07 00:08:54 +0000237 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
238 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
239 /// generated to force the table registers to be consecutive.
240 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000241
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000242 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000243 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000244
Evan Cheng07ba9062009-11-19 21:45:22 +0000245 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000246 SDNode *SelectCMOVOp(SDNode *N);
247 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000248 ARMCC::CondCodes CCVal, SDValue CCR,
249 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000250 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000251 ARMCC::CondCodes CCVal, SDValue CCR,
252 SDValue InFlag);
Jim Grosbacha4257162010-10-07 00:53:56 +0000253 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000254 ARMCC::CondCodes CCVal, SDValue CCR,
255 SDValue InFlag);
Jim Grosbach3bbdcea2010-10-07 00:42:42 +0000256 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000257 ARMCC::CondCodes CCVal, SDValue CCR,
258 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000259
Bill Wendlingef2c86f2011-10-10 22:59:55 +0000260 // Select special operations if node forms integer ABS pattern
261 SDNode *SelectABSOp(SDNode *N);
262
Evan Chengde8aa4e2010-05-05 18:28:36 +0000263 SDNode *SelectConcatVector(SDNode *N);
264
Eli Friedman2bdffe42011-08-31 00:31:29 +0000265 SDNode *SelectAtomic64(SDNode *Node, unsigned Opc);
266
Evan Chengaf4550f2009-07-02 01:23:32 +0000267 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
268 /// inline asm expressions.
269 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
270 char ConstraintCode,
271 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000272
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000273 // Form pairs of consecutive S, D, or Q registers.
274 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000275 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000276 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
277
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000278 // Form sequences of 4 consecutive S, D, or Q registers.
279 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000280 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000281 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilson665814b2010-11-01 23:40:51 +0000282
283 // Get the alignment operand for a NEON VLD or VST instruction.
284 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000285};
Evan Chenga8e29892007-01-19 07:51:42 +0000286}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000287
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000288/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
289/// operand. If so Imm will receive the 32-bit value.
290static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
291 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
292 Imm = cast<ConstantSDNode>(N)->getZExtValue();
293 return true;
294 }
295 return false;
296}
297
298// isInt32Immediate - This method tests to see if a constant operand.
299// If so Imm will receive the 32 bit value.
300static bool isInt32Immediate(SDValue N, unsigned &Imm) {
301 return isInt32Immediate(N.getNode(), Imm);
302}
303
304// isOpcWithIntImmediate - This method tests to see if the node is a specific
305// opcode and that it has a immediate integer right operand.
306// If so Imm will receive the 32 bit value.
307static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
308 return N->getOpcode() == Opc &&
309 isInt32Immediate(N->getOperand(1).getNode(), Imm);
310}
311
Daniel Dunbarec91d522011-01-19 15:12:16 +0000312/// \brief Check whether a particular node is a constant value representable as
313/// (N * Scale) where (N in [\arg RangeMin, \arg RangeMax).
314///
315/// \param ScaledConstant [out] - On success, the pre-scaled constant value.
Jakob Stoklund Olesen11ebe3d2011-09-23 22:10:33 +0000316static bool isScaledConstantInRange(SDValue Node, int Scale,
Daniel Dunbarec91d522011-01-19 15:12:16 +0000317 int RangeMin, int RangeMax,
318 int &ScaledConstant) {
Jakob Stoklund Olesen11ebe3d2011-09-23 22:10:33 +0000319 assert(Scale > 0 && "Invalid scale!");
Daniel Dunbarec91d522011-01-19 15:12:16 +0000320
321 // Check that this is a constant.
322 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Node);
323 if (!C)
324 return false;
325
326 ScaledConstant = (int) C->getZExtValue();
327 if ((ScaledConstant % Scale) != 0)
328 return false;
329
330 ScaledConstant /= Scale;
331 return ScaledConstant >= RangeMin && ScaledConstant < RangeMax;
332}
333
Evan Cheng48575f62010-12-05 22:04:16 +0000334/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
335/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
336/// least on current ARM implementations) which should be avoidded.
337bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
338 if (OptLevel == CodeGenOpt::None)
339 return true;
340
341 if (!CheckVMLxHazard)
342 return true;
343
344 if (!Subtarget->isCortexA8() && !Subtarget->isCortexA9())
345 return true;
346
347 if (!N->hasOneUse())
348 return false;
349
350 SDNode *Use = *N->use_begin();
351 if (Use->getOpcode() == ISD::CopyToReg)
352 return true;
353 if (Use->isMachineOpcode()) {
Evan Chenge837dea2011-06-28 19:10:37 +0000354 const MCInstrDesc &MCID = TII->get(Use->getMachineOpcode());
355 if (MCID.mayStore())
Evan Cheng48575f62010-12-05 22:04:16 +0000356 return true;
Evan Chenge837dea2011-06-28 19:10:37 +0000357 unsigned Opcode = MCID.getOpcode();
Evan Cheng48575f62010-12-05 22:04:16 +0000358 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
359 return true;
360 // vmlx feeding into another vmlx. We actually want to unfold
361 // the use later in the MLxExpansion pass. e.g.
362 // vmla
363 // vmla (stall 8 cycles)
364 //
365 // vmul (5 cycles)
366 // vadd (5 cycles)
367 // vmla
368 // This adds up to about 18 - 19 cycles.
369 //
370 // vmla
371 // vmul (stall 4 cycles)
372 // vadd adds up to about 14 cycles.
373 return TII->isFpMLxInstruction(Opcode);
374 }
375
376 return false;
377}
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000378
Evan Chengf40deed2010-10-27 23:41:30 +0000379bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
380 ARM_AM::ShiftOpc ShOpcVal,
381 unsigned ShAmt) {
382 if (!Subtarget->isCortexA9())
383 return true;
384 if (Shift.hasOneUse())
385 return true;
386 // R << 2 is free.
387 return ShOpcVal == ARM_AM::lsl && ShAmt == 2;
388}
389
Owen Anderson92a20222011-07-21 18:54:16 +0000390bool ARMDAGToDAGISel::SelectImmShifterOperand(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000391 SDValue &BaseReg,
Owen Anderson099e5552011-03-18 19:46:58 +0000392 SDValue &Opc,
393 bool CheckProfitability) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000394 if (DisableShifterOp)
395 return false;
396
Evan Chengee04a6d2011-07-20 23:34:39 +0000397 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +0000398
399 // Don't match base register only case. That is matched to a separate
400 // lower complexity pattern with explicit register operand.
401 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000402
Evan Cheng055b0312009-06-29 07:51:04 +0000403 BaseReg = N.getOperand(0);
404 unsigned ShImmVal = 0;
Owen Anderson92a20222011-07-21 18:54:16 +0000405 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
406 if (!RHS) return false;
Owen Anderson92a20222011-07-21 18:54:16 +0000407 ShImmVal = RHS->getZExtValue() & 31;
Evan Chengf40deed2010-10-27 23:41:30 +0000408 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
409 MVT::i32);
410 return true;
411}
412
Owen Anderson92a20222011-07-21 18:54:16 +0000413bool ARMDAGToDAGISel::SelectRegShifterOperand(SDValue N,
414 SDValue &BaseReg,
415 SDValue &ShReg,
416 SDValue &Opc,
417 bool CheckProfitability) {
418 if (DisableShifterOp)
419 return false;
420
421 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
422
423 // Don't match base register only case. That is matched to a separate
424 // lower complexity pattern with explicit register operand.
425 if (ShOpcVal == ARM_AM::no_shift) return false;
426
427 BaseReg = N.getOperand(0);
428 unsigned ShImmVal = 0;
429 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
430 if (RHS) return false;
431
432 ShReg = N.getOperand(1);
433 if (CheckProfitability && !isShifterOpProfitable(N, ShOpcVal, ShImmVal))
434 return false;
435 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
436 MVT::i32);
437 return true;
438}
439
440
Jim Grosbach3e556122010-10-26 22:37:02 +0000441bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
442 SDValue &Base,
443 SDValue &OffImm) {
444 // Match simple R + imm12 operands.
445
446 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000447 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
448 !CurDAG->isBaseWithConstantOffset(N)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000449 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000450 // Match frame index.
Jim Grosbach3e556122010-10-26 22:37:02 +0000451 int FI = cast<FrameIndexSDNode>(N)->getIndex();
452 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
453 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
454 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000455 }
Owen Anderson099e5552011-03-18 19:46:58 +0000456
Chris Lattner0a9481f2011-02-13 22:25:43 +0000457 if (N.getOpcode() == ARMISD::Wrapper &&
458 !(Subtarget->useMovt() &&
459 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000460 Base = N.getOperand(0);
461 } else
462 Base = N;
463 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
464 return true;
465 }
466
467 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
468 int RHSC = (int)RHS->getZExtValue();
469 if (N.getOpcode() == ISD::SUB)
470 RHSC = -RHSC;
471
472 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
473 Base = N.getOperand(0);
474 if (Base.getOpcode() == ISD::FrameIndex) {
475 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
476 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
477 }
478 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
479 return true;
480 }
481 }
482
483 // Base only.
484 Base = N;
485 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
486 return true;
487}
488
489
490
491bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
492 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000493 if (N.getOpcode() == ISD::MUL &&
494 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000495 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
496 // X * [3,5,9] -> X + X * [2,4,8] etc.
497 int RHSC = (int)RHS->getZExtValue();
498 if (RHSC & 1) {
499 RHSC = RHSC & ~1;
500 ARM_AM::AddrOpc AddSub = ARM_AM::add;
501 if (RHSC < 0) {
502 AddSub = ARM_AM::sub;
503 RHSC = - RHSC;
504 }
505 if (isPowerOf2_32(RHSC)) {
506 unsigned ShAmt = Log2_32(RHSC);
507 Base = Offset = N.getOperand(0);
508 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
509 ARM_AM::lsl),
510 MVT::i32);
511 return true;
512 }
513 }
514 }
515 }
516
Chris Lattner0a9481f2011-02-13 22:25:43 +0000517 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
518 // ISD::OR that is equivalent to an ISD::ADD.
519 !CurDAG->isBaseWithConstantOffset(N))
Jim Grosbach3e556122010-10-26 22:37:02 +0000520 return false;
521
522 // Leave simple R +/- imm12 operands for LDRi12
Chris Lattner0a9481f2011-02-13 22:25:43 +0000523 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::OR) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000524 int RHSC;
525 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
526 -0x1000+1, 0x1000, RHSC)) // 12 bits.
527 return false;
Jim Grosbach3e556122010-10-26 22:37:02 +0000528 }
529
530 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000531 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::SUB ? ARM_AM::sub:ARM_AM::add;
Evan Chengee04a6d2011-07-20 23:34:39 +0000532 ARM_AM::ShiftOpc ShOpcVal =
533 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Jim Grosbach3e556122010-10-26 22:37:02 +0000534 unsigned ShAmt = 0;
535
536 Base = N.getOperand(0);
537 Offset = N.getOperand(1);
538
539 if (ShOpcVal != ARM_AM::no_shift) {
540 // Check to see if the RHS of the shift is a constant, if not, we can't fold
541 // it.
542 if (ConstantSDNode *Sh =
543 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
544 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000545 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
546 Offset = N.getOperand(1).getOperand(0);
547 else {
548 ShAmt = 0;
549 ShOpcVal = ARM_AM::no_shift;
550 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000551 } else {
552 ShOpcVal = ARM_AM::no_shift;
553 }
554 }
555
556 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000557 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000558 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000559 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Jim Grosbach3e556122010-10-26 22:37:02 +0000560 if (ShOpcVal != ARM_AM::no_shift) {
561 // Check to see if the RHS of the shift is a constant, if not, we can't
562 // fold it.
563 if (ConstantSDNode *Sh =
564 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
565 ShAmt = Sh->getZExtValue();
Cameron Zwarich8f8aa812011-10-05 23:39:02 +0000566 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
Evan Chengf40deed2010-10-27 23:41:30 +0000567 Offset = N.getOperand(0).getOperand(0);
568 Base = N.getOperand(1);
569 } else {
570 ShAmt = 0;
571 ShOpcVal = ARM_AM::no_shift;
572 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000573 } else {
574 ShOpcVal = ARM_AM::no_shift;
575 }
576 }
577 }
578
579 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
580 MVT::i32);
581 return true;
582}
583
584
585
586
587//-----
588
Jim Grosbach82891622010-09-29 19:03:54 +0000589AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
590 SDValue &Base,
591 SDValue &Offset,
592 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000593 if (N.getOpcode() == ISD::MUL &&
594 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000595 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
596 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000597 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000598 if (RHSC & 1) {
599 RHSC = RHSC & ~1;
600 ARM_AM::AddrOpc AddSub = ARM_AM::add;
601 if (RHSC < 0) {
602 AddSub = ARM_AM::sub;
603 RHSC = - RHSC;
604 }
605 if (isPowerOf2_32(RHSC)) {
606 unsigned ShAmt = Log2_32(RHSC);
607 Base = Offset = N.getOperand(0);
608 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
609 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000610 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000611 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000612 }
613 }
614 }
615 }
616
Chris Lattner0a9481f2011-02-13 22:25:43 +0000617 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
618 // ISD::OR that is equivalent to an ADD.
619 !CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000620 Base = N;
621 if (N.getOpcode() == ISD::FrameIndex) {
622 int FI = cast<FrameIndexSDNode>(N)->getIndex();
623 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000624 } else if (N.getOpcode() == ARMISD::Wrapper &&
625 !(Subtarget->useMovt() &&
626 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000627 Base = N.getOperand(0);
628 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000629 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000630 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
631 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000632 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000633 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000634 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000635
Evan Chenga8e29892007-01-19 07:51:42 +0000636 // Match simple R +/- imm12 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000637 if (N.getOpcode() != ISD::SUB) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000638 int RHSC;
639 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
640 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
641 Base = N.getOperand(0);
642 if (Base.getOpcode() == ISD::FrameIndex) {
643 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
644 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000645 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000646 Offset = CurDAG->getRegister(0, MVT::i32);
647
648 ARM_AM::AddrOpc AddSub = ARM_AM::add;
649 if (RHSC < 0) {
650 AddSub = ARM_AM::sub;
651 RHSC = - RHSC;
652 }
653 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
654 ARM_AM::no_shift),
655 MVT::i32);
656 return AM2_BASE;
Evan Chenga8e29892007-01-19 07:51:42 +0000657 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000658 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000659
Evan Chengf40deed2010-10-27 23:41:30 +0000660 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
661 // Compute R +/- (R << N) and reuse it.
662 Base = N;
663 Offset = CurDAG->getRegister(0, MVT::i32);
664 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
665 ARM_AM::no_shift),
666 MVT::i32);
667 return AM2_BASE;
668 }
669
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000670 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000671 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chengee04a6d2011-07-20 23:34:39 +0000672 ARM_AM::ShiftOpc ShOpcVal =
673 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000674 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000675
Evan Chenga8e29892007-01-19 07:51:42 +0000676 Base = N.getOperand(0);
677 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000678
Evan Chenga8e29892007-01-19 07:51:42 +0000679 if (ShOpcVal != ARM_AM::no_shift) {
680 // Check to see if the RHS of the shift is a constant, if not, we can't fold
681 // it.
682 if (ConstantSDNode *Sh =
683 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000684 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000685 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
686 Offset = N.getOperand(1).getOperand(0);
687 else {
688 ShAmt = 0;
689 ShOpcVal = ARM_AM::no_shift;
690 }
Evan Chenga8e29892007-01-19 07:51:42 +0000691 } else {
692 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000693 }
694 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000695
Evan Chenga8e29892007-01-19 07:51:42 +0000696 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000697 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000698 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000699 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000700 if (ShOpcVal != ARM_AM::no_shift) {
701 // Check to see if the RHS of the shift is a constant, if not, we can't
702 // fold it.
703 if (ConstantSDNode *Sh =
704 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000705 ShAmt = Sh->getZExtValue();
Cameron Zwarich8f8aa812011-10-05 23:39:02 +0000706 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
Evan Chengf40deed2010-10-27 23:41:30 +0000707 Offset = N.getOperand(0).getOperand(0);
708 Base = N.getOperand(1);
709 } else {
710 ShAmt = 0;
711 ShOpcVal = ARM_AM::no_shift;
712 }
Evan Chenga8e29892007-01-19 07:51:42 +0000713 } else {
714 ShOpcVal = ARM_AM::no_shift;
715 }
716 }
717 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000718
Evan Chenga8e29892007-01-19 07:51:42 +0000719 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000720 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000721 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000722}
723
Owen Anderson793e7962011-07-26 20:54:26 +0000724bool ARMDAGToDAGISel::SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000725 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000726 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000727 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
728 ? cast<LoadSDNode>(Op)->getAddressingMode()
729 : cast<StoreSDNode>(Op)->getAddressingMode();
730 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
731 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000732 int Val;
Owen Anderson793e7962011-07-26 20:54:26 +0000733 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val))
734 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000735
736 Offset = N;
Evan Chengee04a6d2011-07-20 23:34:39 +0000737 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000738 unsigned ShAmt = 0;
739 if (ShOpcVal != ARM_AM::no_shift) {
740 // Check to see if the RHS of the shift is a constant, if not, we can't fold
741 // it.
742 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000743 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000744 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
745 Offset = N.getOperand(0);
746 else {
747 ShAmt = 0;
748 ShOpcVal = ARM_AM::no_shift;
749 }
Evan Chenga8e29892007-01-19 07:51:42 +0000750 } else {
751 ShOpcVal = ARM_AM::no_shift;
752 }
753 }
754
755 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000756 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000757 return true;
758}
759
Owen Andersonc4e16de2011-08-29 20:16:50 +0000760bool ARMDAGToDAGISel::SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
761 SDValue &Offset, SDValue &Opc) {
Owen Andersond84192f2011-08-31 20:00:11 +0000762 unsigned Opcode = Op->getOpcode();
763 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
764 ? cast<LoadSDNode>(Op)->getAddressingMode()
765 : cast<StoreSDNode>(Op)->getAddressingMode();
766 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
767 ? ARM_AM::add : ARM_AM::sub;
Owen Andersonc4e16de2011-08-29 20:16:50 +0000768 int Val;
769 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
Owen Andersond84192f2011-08-31 20:00:11 +0000770 if (AddSub == ARM_AM::sub) Val *= -1;
Owen Andersonc4e16de2011-08-29 20:16:50 +0000771 Offset = CurDAG->getRegister(0, MVT::i32);
772 Opc = CurDAG->getTargetConstant(Val, MVT::i32);
773 return true;
774 }
775
776 return false;
777}
778
779
Owen Anderson793e7962011-07-26 20:54:26 +0000780bool ARMDAGToDAGISel::SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
781 SDValue &Offset, SDValue &Opc) {
782 unsigned Opcode = Op->getOpcode();
783 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
784 ? cast<LoadSDNode>(Op)->getAddressingMode()
785 : cast<StoreSDNode>(Op)->getAddressingMode();
786 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
787 ? ARM_AM::add : ARM_AM::sub;
788 int Val;
789 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
790 Offset = CurDAG->getRegister(0, MVT::i32);
791 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
792 ARM_AM::no_shift),
793 MVT::i32);
794 return true;
795 }
796
797 return false;
798}
799
Jim Grosbach19dec202011-08-05 20:35:44 +0000800bool ARMDAGToDAGISel::SelectAddrOffsetNone(SDValue N, SDValue &Base) {
801 Base = N;
802 return true;
803}
Evan Chenga8e29892007-01-19 07:51:42 +0000804
Chris Lattner52a261b2010-09-21 20:31:19 +0000805bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000806 SDValue &Base, SDValue &Offset,
807 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000808 if (N.getOpcode() == ISD::SUB) {
809 // X - C is canonicalize to X + -C, no need to handle it here.
810 Base = N.getOperand(0);
811 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000812 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000813 return true;
814 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000815
Chris Lattner0a9481f2011-02-13 22:25:43 +0000816 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000817 Base = N;
818 if (N.getOpcode() == ISD::FrameIndex) {
819 int FI = cast<FrameIndexSDNode>(N)->getIndex();
820 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
821 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000822 Offset = CurDAG->getRegister(0, MVT::i32);
823 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000824 return true;
825 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000826
Evan Chenga8e29892007-01-19 07:51:42 +0000827 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000828 int RHSC;
829 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
830 -256 + 1, 256, RHSC)) { // 8 bits.
831 Base = N.getOperand(0);
832 if (Base.getOpcode() == ISD::FrameIndex) {
833 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
834 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000835 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000836 Offset = CurDAG->getRegister(0, MVT::i32);
837
838 ARM_AM::AddrOpc AddSub = ARM_AM::add;
839 if (RHSC < 0) {
840 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000841 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000842 }
843 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
844 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000845 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000846
Evan Chenga8e29892007-01-19 07:51:42 +0000847 Base = N.getOperand(0);
848 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000849 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000850 return true;
851}
852
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000853bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000854 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000855 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000856 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
857 ? cast<LoadSDNode>(Op)->getAddressingMode()
858 : cast<StoreSDNode>(Op)->getAddressingMode();
859 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
860 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000861 int Val;
862 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
863 Offset = CurDAG->getRegister(0, MVT::i32);
864 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
865 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000866 }
867
868 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000869 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000870 return true;
871}
872
Jim Grosbach3ab56582010-10-21 19:38:40 +0000873bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000874 SDValue &Base, SDValue &Offset) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000875 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000876 Base = N;
877 if (N.getOpcode() == ISD::FrameIndex) {
878 int FI = cast<FrameIndexSDNode>(N)->getIndex();
879 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000880 } else if (N.getOpcode() == ARMISD::Wrapper &&
881 !(Subtarget->useMovt() &&
882 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000883 Base = N.getOperand(0);
884 }
885 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000886 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000887 return true;
888 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000889
Evan Chenga8e29892007-01-19 07:51:42 +0000890 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000891 int RHSC;
892 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
893 -256 + 1, 256, RHSC)) {
894 Base = N.getOperand(0);
895 if (Base.getOpcode() == ISD::FrameIndex) {
896 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
897 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000898 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000899
900 ARM_AM::AddrOpc AddSub = ARM_AM::add;
901 if (RHSC < 0) {
902 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000903 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000904 }
905 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
906 MVT::i32);
907 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000908 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000909
Evan Chenga8e29892007-01-19 07:51:42 +0000910 Base = N;
911 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000912 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000913 return true;
914}
915
Bob Wilson665814b2010-11-01 23:40:51 +0000916bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
917 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000918 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000919
920 unsigned Alignment = 0;
921 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
922 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
923 // The maximum alignment is equal to the memory size being referenced.
924 unsigned LSNAlign = LSN->getAlignment();
925 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
Jakob Stoklund Olesenb0117ee2011-10-27 22:39:16 +0000926 if (LSNAlign >= MemSize && MemSize > 1)
Bob Wilson665814b2010-11-01 23:40:51 +0000927 Alignment = MemSize;
928 } else {
929 // All other uses of addrmode6 are for intrinsics. For now just record
930 // the raw alignment value; it will be refined later based on the legal
931 // alignment operands for the intrinsic.
932 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
933 }
934
935 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000936 return true;
937}
938
Bob Wilsonda525062011-02-25 06:42:42 +0000939bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
940 SDValue &Offset) {
941 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
942 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
943 if (AM != ISD::POST_INC)
944 return false;
945 Offset = N;
946 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
947 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
948 Offset = CurDAG->getRegister(0, MVT::i32);
949 }
950 return true;
951}
952
Chris Lattner52a261b2010-09-21 20:31:19 +0000953bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000954 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000955 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
956 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000957 SDValue N1 = N.getOperand(1);
Evan Cheng9fe20092011-01-20 08:34:58 +0000958 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
959 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000960 return true;
961 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000962
Evan Chenga8e29892007-01-19 07:51:42 +0000963 return false;
964}
965
Bill Wendlingf4caf692010-12-14 03:36:38 +0000966
967//===----------------------------------------------------------------------===//
968// Thumb Addressing Modes
969//===----------------------------------------------------------------------===//
970
Chris Lattner52a261b2010-09-21 20:31:19 +0000971bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000972 SDValue &Base, SDValue &Offset){
Chris Lattner0a9481f2011-02-13 22:25:43 +0000973 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000974 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000975 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000976 return false;
977
978 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000979 return true;
980 }
981
Evan Chenga8e29892007-01-19 07:51:42 +0000982 Base = N.getOperand(0);
983 Offset = N.getOperand(1);
984 return true;
985}
986
Evan Cheng79d43262007-01-24 02:21:22 +0000987bool
Bill Wendlingf4caf692010-12-14 03:36:38 +0000988ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
989 SDValue &Offset, unsigned Scale) {
Evan Cheng79d43262007-01-24 02:21:22 +0000990 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000991 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000992 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000993 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendlingf4caf692010-12-14 03:36:38 +0000994
Evan Cheng012f2d92007-01-24 08:53:17 +0000995 if (N.getOpcode() == ARMISD::Wrapper &&
996 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
997 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000998 }
999
Chris Lattner0a9481f2011-02-13 22:25:43 +00001000 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001001 return false;
Evan Chenga8e29892007-01-19 07:51:42 +00001002
Evan Chengad0e4652007-02-06 00:22:06 +00001003 // Thumb does not have [sp, r] address mode.
1004 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1005 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1006 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001007 (RHSR && RHSR->getReg() == ARM::SP))
1008 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001009
Daniel Dunbarec91d522011-01-19 15:12:16 +00001010 // FIXME: Why do we explicitly check for a match here and then return false?
1011 // Presumably to allow something else to match, but shouldn't this be
1012 // documented?
1013 int RHSC;
1014 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
1015 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001016
1017 Base = N.getOperand(0);
1018 Offset = N.getOperand(1);
1019 return true;
1020}
1021
1022bool
1023ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
1024 SDValue &Base,
1025 SDValue &Offset) {
1026 return SelectThumbAddrModeRI(N, Base, Offset, 1);
1027}
1028
1029bool
1030ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
1031 SDValue &Base,
1032 SDValue &Offset) {
1033 return SelectThumbAddrModeRI(N, Base, Offset, 2);
1034}
1035
1036bool
1037ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
1038 SDValue &Base,
1039 SDValue &Offset) {
1040 return SelectThumbAddrModeRI(N, Base, Offset, 4);
1041}
1042
1043bool
1044ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
1045 SDValue &Base, SDValue &OffImm) {
1046 if (Scale == 4) {
1047 SDValue TmpBase, TmpOffImm;
1048 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
1049 return false; // We want to select tLDRspi / tSTRspi instead.
1050
1051 if (N.getOpcode() == ARMISD::Wrapper &&
1052 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1053 return false; // We want to select tLDRpci instead.
1054 }
1055
Chris Lattner0a9481f2011-02-13 22:25:43 +00001056 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendlingf4caf692010-12-14 03:36:38 +00001057 if (N.getOpcode() == ARMISD::Wrapper &&
1058 !(Subtarget->useMovt() &&
1059 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
1060 Base = N.getOperand(0);
1061 } else {
1062 Base = N;
1063 }
1064
Owen Anderson825b72b2009-08-11 20:47:22 +00001065 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +00001066 return true;
1067 }
1068
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001069 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1070 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1071 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1072 (RHSR && RHSR->getReg() == ARM::SP)) {
1073 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1074 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1075 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1076 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1077
1078 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1079 if (LHSC != 0 || RHSC != 0) return false;
1080
1081 Base = N;
1082 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1083 return true;
1084 }
1085
Evan Chenga8e29892007-01-19 07:51:42 +00001086 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001087 int RHSC;
1088 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1089 Base = N.getOperand(0);
1090 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1091 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001092 }
1093
Evan Chengc38f2bc2007-01-23 22:59:13 +00001094 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001095 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +00001096 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001097}
1098
Bill Wendlingf4caf692010-12-14 03:36:38 +00001099bool
1100ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1101 SDValue &OffImm) {
1102 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001103}
1104
Bill Wendlingf4caf692010-12-14 03:36:38 +00001105bool
1106ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1107 SDValue &OffImm) {
1108 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001109}
1110
Bill Wendlingf4caf692010-12-14 03:36:38 +00001111bool
1112ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1113 SDValue &OffImm) {
1114 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001115}
1116
Chris Lattner52a261b2010-09-21 20:31:19 +00001117bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1118 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +00001119 if (N.getOpcode() == ISD::FrameIndex) {
1120 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1121 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001122 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001123 return true;
1124 }
Evan Cheng79d43262007-01-24 02:21:22 +00001125
Chris Lattner0a9481f2011-02-13 22:25:43 +00001126 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Chengad0e4652007-02-06 00:22:06 +00001127 return false;
1128
1129 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001130 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1131 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +00001132 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001133 int RHSC;
1134 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1135 Base = N.getOperand(0);
1136 if (Base.getOpcode() == ISD::FrameIndex) {
1137 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1138 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng79d43262007-01-24 02:21:22 +00001139 }
Daniel Dunbarec91d522011-01-19 15:12:16 +00001140 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1141 return true;
Evan Cheng79d43262007-01-24 02:21:22 +00001142 }
1143 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001144
Evan Chenga8e29892007-01-19 07:51:42 +00001145 return false;
1146}
1147
Bill Wendlingf4caf692010-12-14 03:36:38 +00001148
1149//===----------------------------------------------------------------------===//
1150// Thumb 2 Addressing Modes
1151//===----------------------------------------------------------------------===//
1152
1153
Chris Lattner52a261b2010-09-21 20:31:19 +00001154bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001155 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001156 if (DisableShifterOp)
1157 return false;
1158
Evan Chengee04a6d2011-07-20 23:34:39 +00001159 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng9cb9e672009-06-27 02:26:13 +00001160
1161 // Don't match base register only case. That is matched to a separate
1162 // lower complexity pattern with explicit register operand.
1163 if (ShOpcVal == ARM_AM::no_shift) return false;
1164
1165 BaseReg = N.getOperand(0);
1166 unsigned ShImmVal = 0;
1167 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1168 ShImmVal = RHS->getZExtValue() & 31;
1169 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1170 return true;
1171 }
1172
1173 return false;
1174}
1175
Chris Lattner52a261b2010-09-21 20:31:19 +00001176bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001177 SDValue &Base, SDValue &OffImm) {
1178 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001179
Evan Cheng3a214252009-08-11 08:52:18 +00001180 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001181 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1182 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001183 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +00001184 // Match frame index.
David Goodwin31e7eba2009-07-20 15:55:39 +00001185 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1186 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001187 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001188 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +00001189 }
Owen Anderson099e5552011-03-18 19:46:58 +00001190
Chris Lattner0a9481f2011-02-13 22:25:43 +00001191 if (N.getOpcode() == ARMISD::Wrapper &&
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001192 !(Subtarget->useMovt() &&
1193 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +00001194 Base = N.getOperand(0);
1195 if (Base.getOpcode() == ISD::TargetConstantPool)
1196 return false; // We want to select t2LDRpci instead.
1197 } else
1198 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001199 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001200 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +00001201 }
Evan Cheng055b0312009-06-29 07:51:04 +00001202
1203 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +00001204 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +00001205 // Let t2LDRi8 handle (R - imm8).
1206 return false;
1207
Evan Cheng055b0312009-06-29 07:51:04 +00001208 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +00001209 if (N.getOpcode() == ISD::SUB)
1210 RHSC = -RHSC;
1211
1212 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001213 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001214 if (Base.getOpcode() == ISD::FrameIndex) {
1215 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1216 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1217 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001218 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001219 return true;
1220 }
1221 }
1222
Evan Cheng3a214252009-08-11 08:52:18 +00001223 // Base only.
1224 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001225 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001226 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001227}
1228
Chris Lattner52a261b2010-09-21 20:31:19 +00001229bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001230 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001231 // Match simple R - imm8 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001232 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1233 !CurDAG->isBaseWithConstantOffset(N))
1234 return false;
Owen Anderson099e5552011-03-18 19:46:58 +00001235
Chris Lattner0a9481f2011-02-13 22:25:43 +00001236 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1237 int RHSC = (int)RHS->getSExtValue();
1238 if (N.getOpcode() == ISD::SUB)
1239 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001240
Chris Lattner0a9481f2011-02-13 22:25:43 +00001241 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1242 Base = N.getOperand(0);
1243 if (Base.getOpcode() == ISD::FrameIndex) {
1244 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1245 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng055b0312009-06-29 07:51:04 +00001246 }
Chris Lattner0a9481f2011-02-13 22:25:43 +00001247 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1248 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001249 }
1250 }
1251
1252 return false;
1253}
1254
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001255bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001256 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001257 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001258 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1259 ? cast<LoadSDNode>(Op)->getAddressingMode()
1260 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbarec91d522011-01-19 15:12:16 +00001261 int RHSC;
1262 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1263 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1264 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1265 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1266 return true;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001267 }
1268
1269 return false;
1270}
1271
Chris Lattner52a261b2010-09-21 20:31:19 +00001272bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001273 SDValue &Base,
1274 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001275 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001276 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng3a214252009-08-11 08:52:18 +00001277 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001278
Evan Cheng3a214252009-08-11 08:52:18 +00001279 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1280 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1281 int RHSC = (int)RHS->getZExtValue();
1282 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1283 return false;
1284 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001285 return false;
1286 }
1287
Evan Cheng055b0312009-06-29 07:51:04 +00001288 // Look for (R + R) or (R + (R << [1,2,3])).
1289 unsigned ShAmt = 0;
1290 Base = N.getOperand(0);
1291 OffReg = N.getOperand(1);
1292
1293 // Swap if it is ((R << c) + R).
Evan Chengee04a6d2011-07-20 23:34:39 +00001294 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001295 if (ShOpcVal != ARM_AM::lsl) {
Evan Chengee04a6d2011-07-20 23:34:39 +00001296 ShOpcVal = ARM_AM::getShiftOpcForNode(Base.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001297 if (ShOpcVal == ARM_AM::lsl)
1298 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001299 }
1300
Evan Cheng055b0312009-06-29 07:51:04 +00001301 if (ShOpcVal == ARM_AM::lsl) {
1302 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1303 // it.
1304 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1305 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001306 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1307 OffReg = OffReg.getOperand(0);
1308 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001309 ShAmt = 0;
1310 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001311 }
Evan Cheng055b0312009-06-29 07:51:04 +00001312 } else {
1313 ShOpcVal = ARM_AM::no_shift;
1314 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001315 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001316
Owen Anderson825b72b2009-08-11 20:47:22 +00001317 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001318
1319 return true;
1320}
1321
1322//===--------------------------------------------------------------------===//
1323
Evan Chengee568cf2007-07-05 07:15:27 +00001324/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001325static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001326 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001327}
1328
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001329SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1330 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001331 ISD::MemIndexedMode AM = LD->getAddressingMode();
1332 if (AM == ISD::UNINDEXED)
1333 return NULL;
1334
Owen Andersone50ed302009-08-10 22:56:29 +00001335 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001336 SDValue Offset, AMOpc;
1337 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1338 unsigned Opcode = 0;
1339 bool Match = false;
Owen Andersonc4e16de2011-08-29 20:16:50 +00001340 if (LoadedVT == MVT::i32 && isPre &&
1341 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
1342 Opcode = ARM::LDR_PRE_IMM;
1343 Match = true;
1344 } else if (LoadedVT == MVT::i32 && !isPre &&
Owen Anderson793e7962011-07-26 20:54:26 +00001345 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
Owen Andersonc4e16de2011-08-29 20:16:50 +00001346 Opcode = ARM::LDR_POST_IMM;
Evan Chengaf4550f2009-07-02 01:23:32 +00001347 Match = true;
Owen Anderson793e7962011-07-26 20:54:26 +00001348 } else if (LoadedVT == MVT::i32 &&
1349 SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson9ab0f252011-08-26 20:43:14 +00001350 Opcode = isPre ? ARM::LDR_PRE_REG : ARM::LDR_POST_REG;
Owen Anderson793e7962011-07-26 20:54:26 +00001351 Match = true;
1352
Owen Anderson825b72b2009-08-11 20:47:22 +00001353 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001354 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001355 Match = true;
1356 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1357 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1358 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001359 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001360 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001361 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001362 Match = true;
1363 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1364 }
1365 } else {
Owen Andersonc4e16de2011-08-29 20:16:50 +00001366 if (isPre &&
1367 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001368 Match = true;
Owen Andersonc4e16de2011-08-29 20:16:50 +00001369 Opcode = ARM::LDRB_PRE_IMM;
1370 } else if (!isPre &&
1371 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
1372 Match = true;
1373 Opcode = ARM::LDRB_POST_IMM;
Owen Anderson793e7962011-07-26 20:54:26 +00001374 } else if (SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
1375 Match = true;
Owen Anderson9ab0f252011-08-26 20:43:14 +00001376 Opcode = isPre ? ARM::LDRB_PRE_REG : ARM::LDRB_POST_REG;
Evan Chengaf4550f2009-07-02 01:23:32 +00001377 }
1378 }
1379 }
1380
1381 if (Match) {
Owen Anderson2b568fb2011-08-26 21:12:37 +00001382 if (Opcode == ARM::LDR_PRE_IMM || Opcode == ARM::LDRB_PRE_IMM) {
1383 SDValue Chain = LD->getChain();
1384 SDValue Base = LD->getBasePtr();
1385 SDValue Ops[]= { Base, AMOpc, getAL(CurDAG),
1386 CurDAG->getRegister(0, MVT::i32), Chain };
Jim Grosbachb04546f2011-09-13 20:30:37 +00001387 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32,
1388 MVT::i32, MVT::Other, Ops, 5);
Owen Anderson2b568fb2011-08-26 21:12:37 +00001389 } else {
1390 SDValue Chain = LD->getChain();
1391 SDValue Base = LD->getBasePtr();
1392 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
1393 CurDAG->getRegister(0, MVT::i32), Chain };
Jim Grosbachb04546f2011-09-13 20:30:37 +00001394 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32,
1395 MVT::i32, MVT::Other, Ops, 6);
Owen Anderson2b568fb2011-08-26 21:12:37 +00001396 }
Evan Chengaf4550f2009-07-02 01:23:32 +00001397 }
1398
1399 return NULL;
1400}
1401
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001402SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1403 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001404 ISD::MemIndexedMode AM = LD->getAddressingMode();
1405 if (AM == ISD::UNINDEXED)
1406 return NULL;
1407
Owen Andersone50ed302009-08-10 22:56:29 +00001408 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001409 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001410 SDValue Offset;
1411 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1412 unsigned Opcode = 0;
1413 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001414 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001415 switch (LoadedVT.getSimpleVT().SimpleTy) {
1416 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001417 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1418 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001419 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001420 if (isSExtLd)
1421 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1422 else
1423 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001424 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001425 case MVT::i8:
1426 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001427 if (isSExtLd)
1428 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1429 else
1430 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001431 break;
1432 default:
1433 return NULL;
1434 }
1435 Match = true;
1436 }
1437
1438 if (Match) {
1439 SDValue Chain = LD->getChain();
1440 SDValue Base = LD->getBasePtr();
1441 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001442 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001443 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001444 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001445 }
1446
1447 return NULL;
1448}
1449
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001450/// PairSRegs - Form a D register from a pair of S registers.
1451///
1452SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1453 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001454 SDValue RegClass =
1455 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001456 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1457 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001458 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1459 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001460}
1461
Evan Cheng603afbf2010-05-10 17:34:18 +00001462/// PairDRegs - Form a quad register from a pair of D registers.
1463///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001464SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1465 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001466 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001467 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1468 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001469 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1470 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001471}
1472
Evan Cheng7f687192010-05-14 00:21:45 +00001473/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001474///
1475SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1476 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001477 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001478 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1479 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001480 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1481 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Evan Cheng603afbf2010-05-10 17:34:18 +00001482}
1483
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001484/// QuadSRegs - Form 4 consecutive S registers.
1485///
1486SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1487 SDValue V2, SDValue V3) {
1488 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001489 SDValue RegClass =
1490 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001491 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1492 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1493 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1494 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001495 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1496 V2, SubReg2, V3, SubReg3 };
1497 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001498}
1499
Evan Cheng7f687192010-05-14 00:21:45 +00001500/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001501///
1502SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1503 SDValue V2, SDValue V3) {
1504 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001505 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001506 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1507 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1508 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1509 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001510 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1511 V2, SubReg2, V3, SubReg3 };
1512 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng603afbf2010-05-10 17:34:18 +00001513}
1514
Evan Cheng8f6de382010-05-16 03:27:48 +00001515/// QuadQRegs - Form 4 consecutive Q registers.
1516///
1517SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1518 SDValue V2, SDValue V3) {
1519 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001520 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001521 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1522 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1523 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1524 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001525 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1526 V2, SubReg2, V3, SubReg3 };
1527 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng8f6de382010-05-16 03:27:48 +00001528}
1529
Bob Wilson2a6e6162010-09-23 23:42:37 +00001530/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1531/// of a NEON VLD or VST instruction. The supported values depend on the
1532/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001533SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1534 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001535 unsigned NumRegs = NumVecs;
1536 if (!is64BitVector && NumVecs < 3)
1537 NumRegs *= 2;
1538
Bob Wilson665814b2010-11-01 23:40:51 +00001539 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001540 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001541 Alignment = 32;
1542 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1543 Alignment = 16;
1544 else if (Alignment >= 8)
1545 Alignment = 8;
1546 else
1547 Alignment = 0;
1548
1549 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001550}
1551
Jim Grosbach10b90a92011-10-24 21:45:13 +00001552// Get the register stride update opcode of a VLD/VST instruction that
1553// is otherwise equivalent to the given fixed stride updating instruction.
1554static unsigned getVLDSTRegisterUpdateOpcode(unsigned Opc) {
1555 switch (Opc) {
1556 default: break;
1557 case ARM::VLD1d8wb_fixed: return ARM::VLD1d8wb_register;
1558 case ARM::VLD1d16wb_fixed: return ARM::VLD1d16wb_register;
1559 case ARM::VLD1d32wb_fixed: return ARM::VLD1d32wb_register;
1560 case ARM::VLD1d64wb_fixed: return ARM::VLD1d64wb_register;
1561 case ARM::VLD1q8wb_fixed: return ARM::VLD1q8wb_register;
1562 case ARM::VLD1q16wb_fixed: return ARM::VLD1q16wb_register;
1563 case ARM::VLD1q32wb_fixed: return ARM::VLD1q32wb_register;
1564 case ARM::VLD1q64wb_fixed: return ARM::VLD1q64wb_register;
Jim Grosbach55dabaa2011-10-27 22:25:42 +00001565 case ARM::VLD1q8PseudoWB_fixed: return ARM::VLD1q8PseudoWB_register;
1566 case ARM::VLD1q16PseudoWB_fixed: return ARM::VLD1q16PseudoWB_register;
1567 case ARM::VLD1q32PseudoWB_fixed: return ARM::VLD1q32PseudoWB_register;
1568 case ARM::VLD1q64PseudoWB_fixed: return ARM::VLD1q64PseudoWB_register;
Jim Grosbach4334e032011-10-31 21:50:31 +00001569
1570 case ARM::VST1d8wb_fixed: return ARM::VST1d8wb_register;
1571 case ARM::VST1d16wb_fixed: return ARM::VST1d16wb_register;
1572 case ARM::VST1d32wb_fixed: return ARM::VST1d32wb_register;
1573 case ARM::VST1d64wb_fixed: return ARM::VST1d64wb_register;
1574 case ARM::VST1q8wb_fixed: return ARM::VST1q8wb_register;
1575 case ARM::VST1q16wb_fixed: return ARM::VST1q16wb_register;
1576 case ARM::VST1q32wb_fixed: return ARM::VST1q32wb_register;
1577 case ARM::VST1q64wb_fixed: return ARM::VST1q64wb_register;
1578 case ARM::VST1q8PseudoWB_fixed: return ARM::VST1q8PseudoWB_register;
1579 case ARM::VST1q16PseudoWB_fixed: return ARM::VST1q16PseudoWB_register;
1580 case ARM::VST1q32PseudoWB_fixed: return ARM::VST1q32PseudoWB_register;
1581 case ARM::VST1q64PseudoWB_fixed: return ARM::VST1q64PseudoWB_register;
Jim Grosbachd5ca2012011-11-29 22:38:04 +00001582 case ARM::VST1d64TPseudoWB_fixed: return ARM::VST1d64TPseudoWB_register;
Jim Grosbach4c7edb32011-11-29 22:58:48 +00001583 case ARM::VST1d64QPseudoWB_fixed: return ARM::VST1d64QPseudoWB_register;
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001584
1585 case ARM::VLD2d8PseudoWB_fixed: return ARM::VLD2d8PseudoWB_register;
1586 case ARM::VLD2d16PseudoWB_fixed: return ARM::VLD2d16PseudoWB_register;
1587 case ARM::VLD2d32PseudoWB_fixed: return ARM::VLD2d32PseudoWB_register;
1588 case ARM::VLD2q8PseudoWB_fixed: return ARM::VLD2q8PseudoWB_register;
1589 case ARM::VLD2q16PseudoWB_fixed: return ARM::VLD2q16PseudoWB_register;
1590 case ARM::VLD2q32PseudoWB_fixed: return ARM::VLD2q32PseudoWB_register;
1591
Jim Grosbachbb3a2e42011-12-14 21:32:11 +00001592 case ARM::VST2d8PseudoWB_fixed: return ARM::VST2d8PseudoWB_register;
1593 case ARM::VST2d16PseudoWB_fixed: return ARM::VST2d16PseudoWB_register;
1594 case ARM::VST2d32PseudoWB_fixed: return ARM::VST2d32PseudoWB_register;
1595 case ARM::VST2q8PseudoWB_fixed: return ARM::VST2q8PseudoWB_register;
1596 case ARM::VST2q16PseudoWB_fixed: return ARM::VST2q16PseudoWB_register;
1597 case ARM::VST2q32PseudoWB_fixed: return ARM::VST2q32PseudoWB_register;
Jim Grosbache6949b12011-12-21 19:40:55 +00001598
1599 case ARM::VLD2DUPd8PseudoWB_fixed: return ARM::VLD2DUPd8PseudoWB_register;
1600 case ARM::VLD2DUPd16PseudoWB_fixed: return ARM::VLD2DUPd16PseudoWB_register;
1601 case ARM::VLD2DUPd32PseudoWB_fixed: return ARM::VLD2DUPd32PseudoWB_register;
Jim Grosbach10b90a92011-10-24 21:45:13 +00001602 }
1603 return Opc; // If not one we handle, return it unchanged.
1604}
1605
Bob Wilson1c3ef902011-02-07 17:43:21 +00001606SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001607 unsigned *DOpcodes, unsigned *QOpcodes0,
1608 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001609 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001610 DebugLoc dl = N->getDebugLoc();
1611
Bob Wilson226036e2010-03-20 22:13:40 +00001612 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001613 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1614 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001615 return NULL;
1616
1617 SDValue Chain = N->getOperand(0);
1618 EVT VT = N->getValueType(0);
1619 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001620 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001621
Bob Wilson3e36f132009-10-14 17:28:52 +00001622 unsigned OpcodeIndex;
1623 switch (VT.getSimpleVT().SimpleTy) {
1624 default: llvm_unreachable("unhandled vld type");
1625 // Double-register operations:
1626 case MVT::v8i8: OpcodeIndex = 0; break;
1627 case MVT::v4i16: OpcodeIndex = 1; break;
1628 case MVT::v2f32:
1629 case MVT::v2i32: OpcodeIndex = 2; break;
1630 case MVT::v1i64: OpcodeIndex = 3; break;
1631 // Quad-register operations:
1632 case MVT::v16i8: OpcodeIndex = 0; break;
1633 case MVT::v8i16: OpcodeIndex = 1; break;
1634 case MVT::v4f32:
1635 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001636 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001637 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001638 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001639 }
1640
Bob Wilsonf5721912010-09-03 18:16:02 +00001641 EVT ResTy;
1642 if (NumVecs == 1)
1643 ResTy = VT;
1644 else {
1645 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1646 if (!is64BitVector)
1647 ResTyElts *= 2;
1648 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1649 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001650 std::vector<EVT> ResTys;
1651 ResTys.push_back(ResTy);
1652 if (isUpdating)
1653 ResTys.push_back(MVT::i32);
1654 ResTys.push_back(MVT::Other);
Bob Wilsonf5721912010-09-03 18:16:02 +00001655
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001656 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001657 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001658 SDNode *VLd;
1659 SmallVector<SDValue, 7> Ops;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001660
Bob Wilson1c3ef902011-02-07 17:43:21 +00001661 // Double registers and VLD1/VLD2 quad registers are directly supported.
1662 if (is64BitVector || NumVecs <= 2) {
1663 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1664 QOpcodes0[OpcodeIndex]);
1665 Ops.push_back(MemAddr);
1666 Ops.push_back(Align);
1667 if (isUpdating) {
1668 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001669 // FIXME: VLD1/VLD2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach10b90a92011-10-24 21:45:13 +00001670 // case entirely when the rest are updated to that form, too.
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001671 if ((NumVecs == 1 || NumVecs == 2) && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach10b90a92011-10-24 21:45:13 +00001672 Opc = getVLDSTRegisterUpdateOpcode(Opc);
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001673 // We use a VLD1 for v1i64 even if the pseudo says vld2/3/4, so
Jim Grosbach4334e032011-10-31 21:50:31 +00001674 // check for that explicitly too. Horribly hacky, but temporary.
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001675 if ((NumVecs != 1 && NumVecs != 2 && Opc != ARM::VLD1q64PseudoWB_fixed) ||
Jim Grosbach4334e032011-10-31 21:50:31 +00001676 !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach10b90a92011-10-24 21:45:13 +00001677 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001678 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001679 Ops.push_back(Pred);
1680 Ops.push_back(Reg0);
1681 Ops.push_back(Chain);
1682 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonffde0802010-09-02 16:00:54 +00001683
Bob Wilson3e36f132009-10-14 17:28:52 +00001684 } else {
1685 // Otherwise, quad registers are loaded with two separate instructions,
1686 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001687 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001688
Bob Wilson1c3ef902011-02-07 17:43:21 +00001689 // Load the even subregs. This is always an updating load, so that it
1690 // provides the address to the second load for the odd subregs.
Bob Wilsonf5721912010-09-03 18:16:02 +00001691 SDValue ImplDef =
1692 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1693 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilson7de68142011-02-07 17:43:15 +00001694 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1695 ResTy, AddrTy, MVT::Other, OpsA, 7);
Bob Wilsonf5721912010-09-03 18:16:02 +00001696 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001697
Bob Wilson24f995d2009-10-14 18:32:29 +00001698 // Load the odd subregs.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001699 Ops.push_back(SDValue(VLdA, 1));
1700 Ops.push_back(Align);
1701 if (isUpdating) {
1702 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1703 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1704 "only constant post-increment update allowed for VLD3/4");
1705 (void)Inc;
1706 Ops.push_back(Reg0);
1707 }
1708 Ops.push_back(SDValue(VLdA, 0));
1709 Ops.push_back(Pred);
1710 Ops.push_back(Reg0);
1711 Ops.push_back(Chain);
1712 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1713 Ops.data(), Ops.size());
Bob Wilsonf5721912010-09-03 18:16:02 +00001714 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001715
Evan Chengb58a3402011-04-19 00:04:03 +00001716 // Transfer memoperands.
1717 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1718 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1719 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1720
Bob Wilson1c3ef902011-02-07 17:43:21 +00001721 if (NumVecs == 1)
1722 return VLd;
1723
1724 // Extract out the subregisters.
1725 SDValue SuperReg = SDValue(VLd, 0);
1726 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1727 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1728 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1729 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1730 ReplaceUses(SDValue(N, Vec),
1731 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1732 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1733 if (isUpdating)
1734 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson3e36f132009-10-14 17:28:52 +00001735 return NULL;
1736}
1737
Bob Wilson1c3ef902011-02-07 17:43:21 +00001738SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001739 unsigned *DOpcodes, unsigned *QOpcodes0,
1740 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001741 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001742 DebugLoc dl = N->getDebugLoc();
1743
Bob Wilson226036e2010-03-20 22:13:40 +00001744 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001745 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1746 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1747 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001748 return NULL;
1749
Evan Chengb58a3402011-04-19 00:04:03 +00001750 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1751 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1752
Bob Wilson24f995d2009-10-14 18:32:29 +00001753 SDValue Chain = N->getOperand(0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001754 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson24f995d2009-10-14 18:32:29 +00001755 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001756 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001757
Bob Wilson24f995d2009-10-14 18:32:29 +00001758 unsigned OpcodeIndex;
1759 switch (VT.getSimpleVT().SimpleTy) {
1760 default: llvm_unreachable("unhandled vst type");
1761 // Double-register operations:
1762 case MVT::v8i8: OpcodeIndex = 0; break;
1763 case MVT::v4i16: OpcodeIndex = 1; break;
1764 case MVT::v2f32:
1765 case MVT::v2i32: OpcodeIndex = 2; break;
1766 case MVT::v1i64: OpcodeIndex = 3; break;
1767 // Quad-register operations:
1768 case MVT::v16i8: OpcodeIndex = 0; break;
1769 case MVT::v8i16: OpcodeIndex = 1; break;
1770 case MVT::v4f32:
1771 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001772 case MVT::v2i64: OpcodeIndex = 3;
1773 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1774 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001775 }
1776
Bob Wilson1c3ef902011-02-07 17:43:21 +00001777 std::vector<EVT> ResTys;
1778 if (isUpdating)
1779 ResTys.push_back(MVT::i32);
1780 ResTys.push_back(MVT::Other);
1781
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001782 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001783 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001784 SmallVector<SDValue, 7> Ops;
Evan Chengac0869d2009-11-21 06:21:52 +00001785
Bob Wilson1c3ef902011-02-07 17:43:21 +00001786 // Double registers and VST1/VST2 quad registers are directly supported.
1787 if (is64BitVector || NumVecs <= 2) {
Bob Wilson7de68142011-02-07 17:43:15 +00001788 SDValue SrcReg;
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001789 if (NumVecs == 1) {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001790 SrcReg = N->getOperand(Vec0Idx);
1791 } else if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001792 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001793 SDValue V0 = N->getOperand(Vec0Idx + 0);
1794 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001795 if (NumVecs == 2)
Bob Wilson7de68142011-02-07 17:43:15 +00001796 SrcReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001797 else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001798 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson7de68142011-02-07 17:43:15 +00001799 // If it's a vst3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001800 // an undef.
1801 SDValue V3 = (NumVecs == 3)
1802 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001803 : N->getOperand(Vec0Idx + 3);
Bob Wilson7de68142011-02-07 17:43:15 +00001804 SrcReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001805 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001806 } else {
1807 // Form a QQ register.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001808 SDValue Q0 = N->getOperand(Vec0Idx);
1809 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Bob Wilson7de68142011-02-07 17:43:15 +00001810 SrcReg = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
Bob Wilson24f995d2009-10-14 18:32:29 +00001811 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001812
1813 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1814 QOpcodes0[OpcodeIndex]);
1815 Ops.push_back(MemAddr);
1816 Ops.push_back(Align);
1817 if (isUpdating) {
1818 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbachbb3a2e42011-12-14 21:32:11 +00001819 // FIXME: VST1/VST2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach4334e032011-10-31 21:50:31 +00001820 // case entirely when the rest are updated to that form, too.
Jim Grosbachbb3a2e42011-12-14 21:32:11 +00001821 if (NumVecs <= 2 && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach4334e032011-10-31 21:50:31 +00001822 Opc = getVLDSTRegisterUpdateOpcode(Opc);
1823 // We use a VST1 for v1i64 even if the pseudo says vld2/3/4, so
1824 // check for that explicitly too. Horribly hacky, but temporary.
1825 if ((NumVecs != 1 && Opc != ARM::VST1q64PseudoWB_fixed) ||
1826 !isa<ConstantSDNode>(Inc.getNode()))
1827 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001828 }
1829 Ops.push_back(SrcReg);
1830 Ops.push_back(Pred);
1831 Ops.push_back(Reg0);
1832 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001833 SDNode *VSt =
1834 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
1835
1836 // Transfer memoperands.
1837 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
1838
1839 return VSt;
Bob Wilson24f995d2009-10-14 18:32:29 +00001840 }
1841
1842 // Otherwise, quad registers are stored with two separate instructions,
1843 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001844
Bob Wilson07f6e802010-06-16 21:34:01 +00001845 // Form the QQQQ REG_SEQUENCE.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001846 SDValue V0 = N->getOperand(Vec0Idx + 0);
1847 SDValue V1 = N->getOperand(Vec0Idx + 1);
1848 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001849 SDValue V3 = (NumVecs == 3)
1850 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001851 : N->getOperand(Vec0Idx + 3);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001852 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001853
Bob Wilson1c3ef902011-02-07 17:43:21 +00001854 // Store the even D registers. This is always an updating store, so that it
1855 // provides the address to the second store for the odd subregs.
Bob Wilson7de68142011-02-07 17:43:15 +00001856 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1857 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1858 MemAddr.getValueType(),
1859 MVT::Other, OpsA, 7);
Evan Chengb58a3402011-04-19 00:04:03 +00001860 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson07f6e802010-06-16 21:34:01 +00001861 Chain = SDValue(VStA, 1);
1862
1863 // Store the odd D registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001864 Ops.push_back(SDValue(VStA, 0));
1865 Ops.push_back(Align);
1866 if (isUpdating) {
1867 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1868 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1869 "only constant post-increment update allowed for VST3/4");
1870 (void)Inc;
1871 Ops.push_back(Reg0);
1872 }
1873 Ops.push_back(RegSeq);
1874 Ops.push_back(Pred);
1875 Ops.push_back(Reg0);
1876 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001877 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1878 Ops.data(), Ops.size());
1879 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
1880 return VStB;
Bob Wilson24f995d2009-10-14 18:32:29 +00001881}
1882
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001883SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson1c3ef902011-02-07 17:43:21 +00001884 bool isUpdating, unsigned NumVecs,
1885 unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001886 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001887 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001888 DebugLoc dl = N->getDebugLoc();
1889
Bob Wilson226036e2010-03-20 22:13:40 +00001890 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001891 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1892 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1893 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001894 return NULL;
1895
Evan Chengb58a3402011-04-19 00:04:03 +00001896 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1897 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1898
Bob Wilsona7c397c2009-10-14 16:19:03 +00001899 SDValue Chain = N->getOperand(0);
1900 unsigned Lane =
Bob Wilson1c3ef902011-02-07 17:43:21 +00001901 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
1902 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001903 bool is64BitVector = VT.is64BitVector();
1904
Bob Wilson665814b2010-11-01 23:40:51 +00001905 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001906 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001907 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001908 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1909 if (Alignment > NumBytes)
1910 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001911 if (Alignment < 8 && Alignment < NumBytes)
1912 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001913 // Alignment must be a power of two; make sure of that.
1914 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001915 if (Alignment == 1)
1916 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001917 }
Bob Wilson665814b2010-11-01 23:40:51 +00001918 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001919
Bob Wilsona7c397c2009-10-14 16:19:03 +00001920 unsigned OpcodeIndex;
1921 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001922 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001923 // Double-register operations:
1924 case MVT::v8i8: OpcodeIndex = 0; break;
1925 case MVT::v4i16: OpcodeIndex = 1; break;
1926 case MVT::v2f32:
1927 case MVT::v2i32: OpcodeIndex = 2; break;
1928 // Quad-register operations:
1929 case MVT::v8i16: OpcodeIndex = 0; break;
1930 case MVT::v4f32:
1931 case MVT::v4i32: OpcodeIndex = 1; break;
1932 }
1933
Bob Wilson1c3ef902011-02-07 17:43:21 +00001934 std::vector<EVT> ResTys;
1935 if (IsLoad) {
1936 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1937 if (!is64BitVector)
1938 ResTyElts *= 2;
1939 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
1940 MVT::i64, ResTyElts));
1941 }
1942 if (isUpdating)
1943 ResTys.push_back(MVT::i32);
1944 ResTys.push_back(MVT::Other);
1945
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001946 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001947 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001948
Bob Wilson1c3ef902011-02-07 17:43:21 +00001949 SmallVector<SDValue, 8> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001950 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001951 Ops.push_back(Align);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001952 if (isUpdating) {
1953 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1954 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1955 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001956
Bob Wilson8466fa12010-09-13 23:01:35 +00001957 SDValue SuperReg;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001958 SDValue V0 = N->getOperand(Vec0Idx + 0);
1959 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilson8466fa12010-09-13 23:01:35 +00001960 if (NumVecs == 2) {
1961 if (is64BitVector)
1962 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1963 else
1964 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001965 } else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001966 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson8466fa12010-09-13 23:01:35 +00001967 SDValue V3 = (NumVecs == 3)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001968 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1969 : N->getOperand(Vec0Idx + 3);
Bob Wilson8466fa12010-09-13 23:01:35 +00001970 if (is64BitVector)
1971 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1972 else
1973 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001974 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001975 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001976 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001977 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001978 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001979 Ops.push_back(Chain);
1980
Bob Wilson1c3ef902011-02-07 17:43:21 +00001981 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1982 QOpcodes[OpcodeIndex]);
1983 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys,
1984 Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001985 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson96493442009-10-14 16:46:45 +00001986 if (!IsLoad)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001987 return VLdLn;
Evan Cheng7092c2b2010-05-15 01:36:29 +00001988
Bob Wilson8466fa12010-09-13 23:01:35 +00001989 // Extract the subregisters.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001990 SuperReg = SDValue(VLdLn, 0);
1991 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1992 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1993 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson07f6e802010-06-16 21:34:01 +00001994 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1995 ReplaceUses(SDValue(N, Vec),
Bob Wilson1c3ef902011-02-07 17:43:21 +00001996 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1997 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
1998 if (isUpdating)
1999 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilsona7c397c2009-10-14 16:19:03 +00002000 return NULL;
2001}
2002
Bob Wilson1c3ef902011-02-07 17:43:21 +00002003SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
2004 unsigned NumVecs, unsigned *Opcodes) {
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002005 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
2006 DebugLoc dl = N->getDebugLoc();
2007
2008 SDValue MemAddr, Align;
2009 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
2010 return NULL;
2011
Evan Chengb58a3402011-04-19 00:04:03 +00002012 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2013 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2014
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002015 SDValue Chain = N->getOperand(0);
2016 EVT VT = N->getValueType(0);
2017
2018 unsigned Alignment = 0;
2019 if (NumVecs != 3) {
2020 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
2021 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
2022 if (Alignment > NumBytes)
2023 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00002024 if (Alignment < 8 && Alignment < NumBytes)
2025 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002026 // Alignment must be a power of two; make sure of that.
2027 Alignment = (Alignment & -Alignment);
2028 if (Alignment == 1)
2029 Alignment = 0;
2030 }
2031 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
2032
2033 unsigned OpcodeIndex;
2034 switch (VT.getSimpleVT().SimpleTy) {
2035 default: llvm_unreachable("unhandled vld-dup type");
2036 case MVT::v8i8: OpcodeIndex = 0; break;
2037 case MVT::v4i16: OpcodeIndex = 1; break;
2038 case MVT::v2f32:
2039 case MVT::v2i32: OpcodeIndex = 2; break;
2040 }
2041
2042 SDValue Pred = getAL(CurDAG);
2043 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2044 SDValue SuperReg;
2045 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson1c3ef902011-02-07 17:43:21 +00002046 SmallVector<SDValue, 6> Ops;
2047 Ops.push_back(MemAddr);
2048 Ops.push_back(Align);
2049 if (isUpdating) {
Jim Grosbache6949b12011-12-21 19:40:55 +00002050 // fixed-stride update instructions don't have an explicit writeback
2051 // operand. It's implicit in the opcode itself.
Bob Wilson1c3ef902011-02-07 17:43:21 +00002052 SDValue Inc = N->getOperand(2);
Jim Grosbache6949b12011-12-21 19:40:55 +00002053 if (!isa<ConstantSDNode>(Inc.getNode()))
2054 Ops.push_back(Inc);
2055 // FIXME: VLD3 and VLD4 haven't been updated to that form yet.
2056 else if (NumVecs > 2)
2057 Ops.push_back(Reg0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00002058 }
2059 Ops.push_back(Pred);
2060 Ops.push_back(Reg0);
2061 Ops.push_back(Chain);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002062
2063 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson1c3ef902011-02-07 17:43:21 +00002064 std::vector<EVT> ResTys;
Evan Chengb58a3402011-04-19 00:04:03 +00002065 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson1c3ef902011-02-07 17:43:21 +00002066 if (isUpdating)
2067 ResTys.push_back(MVT::i32);
2068 ResTys.push_back(MVT::Other);
2069 SDNode *VLdDup =
2070 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00002071 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002072 SuperReg = SDValue(VLdDup, 0);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002073
2074 // Extract the subregisters.
2075 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
2076 unsigned SubIdx = ARM::dsub_0;
2077 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
2078 ReplaceUses(SDValue(N, Vec),
2079 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson1c3ef902011-02-07 17:43:21 +00002080 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
2081 if (isUpdating)
2082 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002083 return NULL;
2084}
2085
Bob Wilson78dfbc32010-07-07 00:08:54 +00002086SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
2087 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00002088 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
2089 DebugLoc dl = N->getDebugLoc();
2090 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002091 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00002092
2093 // Form a REG_SEQUENCE to force register allocation.
2094 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00002095 SDValue V0 = N->getOperand(FirstTblReg + 0);
2096 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002097 if (NumVecs == 2)
2098 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
2099 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00002100 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00002101 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00002102 // an undef.
2103 SDValue V3 = (NumVecs == 3)
2104 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00002105 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002106 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
2107 }
2108
Bob Wilson78dfbc32010-07-07 00:08:54 +00002109 SmallVector<SDValue, 6> Ops;
2110 if (IsExt)
2111 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00002112 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002113 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00002114 Ops.push_back(getAL(CurDAG)); // predicate
2115 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00002116 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00002117}
2118
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002119SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002120 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002121 if (!Subtarget->hasV6T2Ops())
2122 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00002123
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002124 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
2125 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
2126
2127
2128 // For unsigned extracts, check for a shift right and mask
2129 unsigned And_imm = 0;
2130 if (N->getOpcode() == ISD::AND) {
2131 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
2132
2133 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
2134 if (And_imm & (And_imm + 1))
2135 return NULL;
2136
2137 unsigned Srl_imm = 0;
2138 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
2139 Srl_imm)) {
2140 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2141
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002142 // Note: The width operand is encoded as width-1.
2143 unsigned Width = CountTrailingOnes_32(And_imm) - 1;
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002144 unsigned LSB = Srl_imm;
2145 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2146 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2147 CurDAG->getTargetConstant(LSB, MVT::i32),
2148 CurDAG->getTargetConstant(Width, MVT::i32),
2149 getAL(CurDAG), Reg0 };
2150 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2151 }
2152 }
2153 return NULL;
2154 }
2155
2156 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002157 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002158 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002159 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
2160 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002161 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002162 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002163 // Note: The width operand is encoded as width-1.
2164 unsigned Width = 32 - Srl_imm - 1;
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002165 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00002166 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002167 return NULL;
2168 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002169 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002170 CurDAG->getTargetConstant(LSB, MVT::i32),
2171 CurDAG->getTargetConstant(Width, MVT::i32),
2172 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002173 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002174 }
2175 }
2176 return NULL;
2177}
2178
Evan Cheng9ef48352009-11-20 00:54:03 +00002179SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002180SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002181 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2182 SDValue CPTmp0;
2183 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00002184 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002185 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
2186 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
2187 unsigned Opc = 0;
2188 switch (SOShOp) {
2189 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
2190 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
2191 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
2192 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
2193 default:
2194 llvm_unreachable("Unknown so_reg opcode!");
2195 break;
2196 }
2197 SDValue SOShImm =
2198 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
2199 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2200 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002201 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00002202 }
2203 return 0;
2204}
2205
2206SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002207SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002208 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2209 SDValue CPTmp0;
2210 SDValue CPTmp1;
2211 SDValue CPTmp2;
Owen Anderson152d4a42011-07-21 23:38:37 +00002212 if (SelectImmShifterOperand(TrueVal, CPTmp0, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002213 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
Owen Andersone0a03142011-07-22 18:30:30 +00002214 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp2, CC, CCR, InFlag };
2215 return CurDAG->SelectNodeTo(N, ARM::MOVCCsi, MVT::i32, Ops, 6);
Owen Anderson92a20222011-07-21 18:54:16 +00002216 }
2217
2218 if (SelectRegShifterOperand(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
2219 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2220 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
2221 return CurDAG->SelectNodeTo(N, ARM::MOVCCsr, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00002222 }
2223 return 0;
2224}
2225
2226SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00002227SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002228 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002229 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00002230 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00002231 return 0;
2232
Evan Cheng63f35442010-11-13 02:25:14 +00002233 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00002234 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00002235 if (is_t2_so_imm(TrueImm)) {
2236 Opc = ARM::t2MOVCCi;
2237 } else if (TrueImm <= 0xffff) {
2238 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002239 } else if (is_t2_so_imm_not(TrueImm)) {
2240 TrueImm = ~TrueImm;
2241 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002242 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00002243 // Large immediate.
2244 Opc = ARM::t2MOVCCi32imm;
2245 }
2246
2247 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002248 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002249 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2250 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002251 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002252 }
Evan Cheng63f35442010-11-13 02:25:14 +00002253
Evan Cheng9ef48352009-11-20 00:54:03 +00002254 return 0;
2255}
2256
2257SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002258SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002259 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002260 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2261 if (!T)
2262 return 0;
2263
Evan Cheng63f35442010-11-13 02:25:14 +00002264 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002265 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002266 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002267 if (isSoImm) {
2268 Opc = ARM::MOVCCi;
2269 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2270 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002271 } else if (is_so_imm_not(TrueImm)) {
2272 TrueImm = ~TrueImm;
2273 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002274 } else if (TrueVal.getNode()->hasOneUse() &&
2275 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002276 // Large immediate.
2277 Opc = ARM::MOVCCi32imm;
2278 }
2279
2280 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002281 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002282 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2283 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002284 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002285 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002286
Evan Cheng9ef48352009-11-20 00:54:03 +00002287 return 0;
2288}
2289
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002290SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2291 EVT VT = N->getValueType(0);
2292 SDValue FalseVal = N->getOperand(0);
2293 SDValue TrueVal = N->getOperand(1);
2294 SDValue CC = N->getOperand(2);
2295 SDValue CCR = N->getOperand(3);
2296 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002297 assert(CC.getOpcode() == ISD::Constant);
2298 assert(CCR.getOpcode() == ISD::Register);
2299 ARMCC::CondCodes CCVal =
2300 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002301
2302 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2303 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2304 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2305 // Pattern complexity = 18 cost = 1 size = 0
2306 SDValue CPTmp0;
2307 SDValue CPTmp1;
2308 SDValue CPTmp2;
2309 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002310 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002311 CCVal, CCR, InFlag);
2312 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002313 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002314 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2315 if (Res)
2316 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002317 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002318 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002319 CCVal, CCR, InFlag);
2320 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002321 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002322 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2323 if (Res)
2324 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002325 }
2326
2327 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002328 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002329 // (imm:i32):$cc)
2330 // Emits: (MOVCCi:i32 GPR:i32:$false,
2331 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2332 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002333 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002334 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002335 CCVal, CCR, InFlag);
2336 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002337 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002338 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2339 if (Res)
2340 return Res;
2341 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002342 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002343 CCVal, CCR, InFlag);
2344 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002345 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002346 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2347 if (Res)
2348 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002349 }
2350 }
2351
2352 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2353 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2354 // Pattern complexity = 6 cost = 1 size = 0
2355 //
2356 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2357 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2358 // Pattern complexity = 6 cost = 11 size = 0
2359 //
Jim Grosbach3c5edaa2011-03-11 23:15:02 +00002360 // Also VMOVScc and VMOVDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002361 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2362 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002363 unsigned Opc = 0;
2364 switch (VT.getSimpleVT().SimpleTy) {
2365 default: assert(false && "Illegal conditional move type!");
2366 break;
2367 case MVT::i32:
2368 Opc = Subtarget->isThumb()
2369 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2370 : ARM::MOVCCr;
2371 break;
2372 case MVT::f32:
2373 Opc = ARM::VMOVScc;
2374 break;
2375 case MVT::f64:
2376 Opc = ARM::VMOVDcc;
2377 break;
2378 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002379 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002380}
2381
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002382/// Target-specific DAG combining for ISD::XOR.
2383/// Target-independent combining lowers SELECT_CC nodes of the form
2384/// select_cc setg[ge] X, 0, X, -X
2385/// select_cc setgt X, -1, X, -X
2386/// select_cc setl[te] X, 0, -X, X
2387/// select_cc setlt X, 1, -X, X
2388/// which represent Integer ABS into:
2389/// Y = sra (X, size(X)-1); xor (add (X, Y), Y)
2390/// ARM instruction selection detects the latter and matches it to
2391/// ARM::ABS or ARM::t2ABS machine node.
2392SDNode *ARMDAGToDAGISel::SelectABSOp(SDNode *N){
2393 SDValue XORSrc0 = N->getOperand(0);
2394 SDValue XORSrc1 = N->getOperand(1);
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002395 EVT VT = N->getValueType(0);
2396
2397 if (DisableARMIntABS)
2398 return NULL;
2399
2400 if (Subtarget->isThumb1Only())
2401 return NULL;
2402
2403 if (XORSrc0.getOpcode() != ISD::ADD ||
2404 XORSrc1.getOpcode() != ISD::SRA)
2405 return NULL;
2406
2407 SDValue ADDSrc0 = XORSrc0.getOperand(0);
2408 SDValue ADDSrc1 = XORSrc0.getOperand(1);
2409 SDValue SRASrc0 = XORSrc1.getOperand(0);
2410 SDValue SRASrc1 = XORSrc1.getOperand(1);
2411 ConstantSDNode *SRAConstant = dyn_cast<ConstantSDNode>(SRASrc1);
2412 EVT XType = SRASrc0.getValueType();
2413 unsigned Size = XType.getSizeInBits() - 1;
2414
2415 if (ADDSrc1 == XORSrc1 &&
2416 ADDSrc0 == SRASrc0 &&
2417 XType.isInteger() &&
2418 SRAConstant != NULL &&
2419 Size == SRAConstant->getZExtValue()) {
2420
2421 unsigned Opcode = ARM::ABS;
2422 if (Subtarget->isThumb2())
2423 Opcode = ARM::t2ABS;
2424
2425 return CurDAG->SelectNodeTo(N, Opcode, VT, ADDSrc0);
2426 }
2427
2428 return NULL;
2429}
2430
Evan Chengde8aa4e2010-05-05 18:28:36 +00002431SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2432 // The only time a CONCAT_VECTORS operation can have legal types is when
2433 // two 64-bit vectors are concatenated to a 128-bit vector.
2434 EVT VT = N->getValueType(0);
2435 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2436 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002437 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002438}
2439
Eli Friedman2bdffe42011-08-31 00:31:29 +00002440SDNode *ARMDAGToDAGISel::SelectAtomic64(SDNode *Node, unsigned Opc) {
Eli Friedman4d3f3292011-08-31 17:52:22 +00002441 SmallVector<SDValue, 6> Ops;
2442 Ops.push_back(Node->getOperand(1)); // Ptr
2443 Ops.push_back(Node->getOperand(2)); // Low part of Val1
2444 Ops.push_back(Node->getOperand(3)); // High part of Val1
Owen Andersond84192f2011-08-31 20:00:11 +00002445 if (Opc == ARM::ATOMCMPXCHG6432) {
Eli Friedman4d3f3292011-08-31 17:52:22 +00002446 Ops.push_back(Node->getOperand(4)); // Low part of Val2
2447 Ops.push_back(Node->getOperand(5)); // High part of Val2
2448 }
2449 Ops.push_back(Node->getOperand(0)); // Chain
Eli Friedman2bdffe42011-08-31 00:31:29 +00002450 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2451 MemOp[0] = cast<MemSDNode>(Node)->getMemOperand();
Eli Friedman2bdffe42011-08-31 00:31:29 +00002452 SDNode *ResNode = CurDAG->getMachineNode(Opc, Node->getDebugLoc(),
Eli Friedman4d3f3292011-08-31 17:52:22 +00002453 MVT::i32, MVT::i32, MVT::Other,
2454 Ops.data() ,Ops.size());
Eli Friedman2bdffe42011-08-31 00:31:29 +00002455 cast<MachineSDNode>(ResNode)->setMemRefs(MemOp, MemOp + 1);
2456 return ResNode;
2457}
2458
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002459SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002460 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002461
Dan Gohmane8be6c62008-07-17 19:10:17 +00002462 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002463 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002464
2465 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002466 default: break;
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002467 case ISD::XOR: {
2468 // Select special operations if XOR node forms integer ABS pattern
2469 SDNode *ResNode = SelectABSOp(N);
2470 if (ResNode)
2471 return ResNode;
2472 // Other cases are autogenerated.
2473 break;
2474 }
Evan Chenga8e29892007-01-19 07:51:42 +00002475 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002476 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002477 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002478 if (Subtarget->hasThumb2())
2479 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2480 // be done with MOV + MOVT, at worst.
2481 UseCP = 0;
2482 else {
2483 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002484 UseCP = (Val > 255 && // MOV
2485 ~Val > 255 && // MOV + MVN
2486 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002487 } else
2488 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2489 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2490 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2491 }
2492
Evan Chenga8e29892007-01-19 07:51:42 +00002493 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002494 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002495 CurDAG->getTargetConstantPool(ConstantInt::get(
2496 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002497 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002498
2499 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002500 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002501 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002502 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002503 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002504 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002505 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002506 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002507 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002508 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002509 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002510 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002511 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002512 CurDAG->getEntryNode()
2513 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002514 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002515 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002516 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002517 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002518 return NULL;
2519 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002520
Evan Chenga8e29892007-01-19 07:51:42 +00002521 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002522 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002523 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002524 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002525 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002526 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002527 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002528 if (Subtarget->isThumb1Only()) {
Jim Grosbach5b815842011-08-24 17:46:13 +00002529 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2530 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2531 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, Ops, 4);
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002532 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002533 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2534 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002535 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2536 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2537 CurDAG->getRegister(0, MVT::i32) };
2538 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002539 }
Evan Chenga8e29892007-01-19 07:51:42 +00002540 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002541 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002542 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002543 return I;
2544 break;
2545 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002546 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002547 return I;
2548 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002549 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002550 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002551 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002552 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002553 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002554 if (!RHSV) break;
2555 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002556 unsigned ShImm = Log2_32(RHSV-1);
2557 if (ShImm >= 32)
2558 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002559 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002560 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002561 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2562 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002563 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002564 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002565 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002566 } else {
2567 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002568 return CurDAG->SelectNodeTo(N, ARM::ADDrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002569 }
Evan Chenga8e29892007-01-19 07:51:42 +00002570 }
2571 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002572 unsigned ShImm = Log2_32(RHSV+1);
2573 if (ShImm >= 32)
2574 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002575 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002576 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002577 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2578 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002579 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002580 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2581 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002582 } else {
2583 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002584 return CurDAG->SelectNodeTo(N, ARM::RSBrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002585 }
Evan Chenga8e29892007-01-19 07:51:42 +00002586 }
2587 }
2588 break;
Evan Cheng20956592009-10-21 08:15:52 +00002589 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002590 // Check for unsigned bitfield extract
2591 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2592 return I;
2593
Evan Cheng20956592009-10-21 08:15:52 +00002594 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2595 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2596 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2597 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2598 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002599 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002600 if (VT != MVT::i32)
2601 break;
2602 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2603 ? ARM::t2MOVTi16
2604 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2605 if (!Opc)
2606 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002607 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002608 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2609 if (!N1C)
2610 break;
2611 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2612 SDValue N2 = N0.getOperand(1);
2613 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2614 if (!N2C)
2615 break;
2616 unsigned N1CVal = N1C->getZExtValue();
2617 unsigned N2CVal = N2C->getZExtValue();
2618 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2619 (N1CVal & 0xffffU) == 0xffffU &&
2620 (N2CVal & 0xffffU) == 0x0U) {
2621 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2622 MVT::i32);
2623 SDValue Ops[] = { N0.getOperand(0), Imm16,
2624 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2625 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2626 }
2627 }
2628 break;
2629 }
Jim Grosbache5165492009-11-09 00:11:35 +00002630 case ARMISD::VMOVRRD:
2631 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002632 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002633 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002634 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002635 if (Subtarget->isThumb1Only())
2636 break;
2637 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002638 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002639 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2640 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002641 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002642 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002643 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002644 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2645 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002646 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2647 ARM::UMULL : ARM::UMULLv5,
2648 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002649 }
Evan Chengee568cf2007-07-05 07:15:27 +00002650 }
Dan Gohman525178c2007-10-08 18:33:35 +00002651 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002652 if (Subtarget->isThumb1Only())
2653 break;
2654 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002655 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002656 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002657 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002658 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002659 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002660 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2661 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002662 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2663 ARM::SMULL : ARM::SMULLv5,
2664 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002665 }
Evan Chengee568cf2007-07-05 07:15:27 +00002666 }
Evan Chenga8e29892007-01-19 07:51:42 +00002667 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002668 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002669 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002670 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002671 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002672 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002673 if (ResNode)
2674 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002675 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002676 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002677 }
Evan Chengee568cf2007-07-05 07:15:27 +00002678 case ARMISD::BRCOND: {
2679 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2680 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2681 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002682
Evan Chengee568cf2007-07-05 07:15:27 +00002683 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2684 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2685 // Pattern complexity = 6 cost = 1 size = 0
2686
David Goodwin5e47a9a2009-06-30 18:04:13 +00002687 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2688 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2689 // Pattern complexity = 6 cost = 1 size = 0
2690
Jim Grosbach764ab522009-08-11 15:33:49 +00002691 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002692 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002693 SDValue Chain = N->getOperand(0);
2694 SDValue N1 = N->getOperand(1);
2695 SDValue N2 = N->getOperand(2);
2696 SDValue N3 = N->getOperand(3);
2697 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002698 assert(N1.getOpcode() == ISD::BasicBlock);
2699 assert(N2.getOpcode() == ISD::Constant);
2700 assert(N3.getOpcode() == ISD::Register);
2701
Dan Gohman475871a2008-07-27 21:46:04 +00002702 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002703 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002704 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002705 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002706 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002707 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002708 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002709 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002710 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002711 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002712 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002713 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002714 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002715 return NULL;
2716 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002717 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002718 return SelectCMOVOp(N);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002719 case ARMISD::VZIP: {
2720 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002721 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002722 switch (VT.getSimpleVT().SimpleTy) {
2723 default: return NULL;
2724 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2725 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2726 case MVT::v2f32:
2727 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2728 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2729 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2730 case MVT::v4f32:
2731 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2732 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002733 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002734 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2735 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2736 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002737 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002738 case ARMISD::VUZP: {
2739 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002740 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002741 switch (VT.getSimpleVT().SimpleTy) {
2742 default: return NULL;
2743 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2744 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2745 case MVT::v2f32:
2746 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2747 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2748 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2749 case MVT::v4f32:
2750 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2751 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002752 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002753 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2754 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2755 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002756 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002757 case ARMISD::VTRN: {
2758 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002759 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002760 switch (VT.getSimpleVT().SimpleTy) {
2761 default: return NULL;
2762 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2763 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2764 case MVT::v2f32:
2765 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2766 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2767 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2768 case MVT::v4f32:
2769 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2770 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002771 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002772 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2773 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2774 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002775 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002776 case ARMISD::BUILD_VECTOR: {
2777 EVT VecVT = N->getValueType(0);
2778 EVT EltVT = VecVT.getVectorElementType();
2779 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002780 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002781 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2782 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2783 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002784 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002785 if (NumElts == 2)
2786 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2787 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2788 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2789 N->getOperand(2), N->getOperand(3));
2790 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002791
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002792 case ARMISD::VLD2DUP: {
2793 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2794 ARM::VLD2DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002795 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002796 }
2797
Bob Wilson86c6d802010-11-29 19:35:29 +00002798 case ARMISD::VLD3DUP: {
2799 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2800 ARM::VLD3DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002801 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson86c6d802010-11-29 19:35:29 +00002802 }
2803
Bob Wilson6c4c9822010-11-30 00:00:35 +00002804 case ARMISD::VLD4DUP: {
2805 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2806 ARM::VLD4DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002807 return SelectVLDDup(N, false, 4, Opcodes);
2808 }
2809
2810 case ARMISD::VLD2DUP_UPD: {
Jim Grosbache6949b12011-12-21 19:40:55 +00002811 unsigned Opcodes[] = { ARM::VLD2DUPd8PseudoWB_fixed,
2812 ARM::VLD2DUPd16PseudoWB_fixed,
2813 ARM::VLD2DUPd32PseudoWB_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002814 return SelectVLDDup(N, true, 2, Opcodes);
2815 }
2816
2817 case ARMISD::VLD3DUP_UPD: {
2818 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD, ARM::VLD3DUPd16Pseudo_UPD,
2819 ARM::VLD3DUPd32Pseudo_UPD };
2820 return SelectVLDDup(N, true, 3, Opcodes);
2821 }
2822
2823 case ARMISD::VLD4DUP_UPD: {
2824 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD, ARM::VLD4DUPd16Pseudo_UPD,
2825 ARM::VLD4DUPd32Pseudo_UPD };
2826 return SelectVLDDup(N, true, 4, Opcodes);
2827 }
2828
2829 case ARMISD::VLD1_UPD: {
Jim Grosbach10b90a92011-10-24 21:45:13 +00002830 unsigned DOpcodes[] = { ARM::VLD1d8wb_fixed, ARM::VLD1d16wb_fixed,
2831 ARM::VLD1d32wb_fixed, ARM::VLD1d64wb_fixed };
2832 unsigned QOpcodes[] = { ARM::VLD1q8PseudoWB_fixed,
2833 ARM::VLD1q16PseudoWB_fixed,
2834 ARM::VLD1q32PseudoWB_fixed,
2835 ARM::VLD1q64PseudoWB_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002836 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2837 }
2838
2839 case ARMISD::VLD2_UPD: {
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00002840 unsigned DOpcodes[] = { ARM::VLD2d8PseudoWB_fixed,
2841 ARM::VLD2d16PseudoWB_fixed,
2842 ARM::VLD2d32PseudoWB_fixed,
2843 ARM::VLD1q64PseudoWB_fixed};
2844 unsigned QOpcodes[] = { ARM::VLD2q8PseudoWB_fixed,
2845 ARM::VLD2q16PseudoWB_fixed,
2846 ARM::VLD2q32PseudoWB_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002847 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2848 }
2849
2850 case ARMISD::VLD3_UPD: {
2851 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo_UPD, ARM::VLD3d16Pseudo_UPD,
Jim Grosbach10b90a92011-10-24 21:45:13 +00002852 ARM::VLD3d32Pseudo_UPD, ARM::VLD1q64PseudoWB_fixed};
Bob Wilson1c3ef902011-02-07 17:43:21 +00002853 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2854 ARM::VLD3q16Pseudo_UPD,
2855 ARM::VLD3q32Pseudo_UPD };
2856 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2857 ARM::VLD3q16oddPseudo_UPD,
2858 ARM::VLD3q32oddPseudo_UPD };
2859 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2860 }
2861
2862 case ARMISD::VLD4_UPD: {
2863 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo_UPD, ARM::VLD4d16Pseudo_UPD,
Jim Grosbach10b90a92011-10-24 21:45:13 +00002864 ARM::VLD4d32Pseudo_UPD, ARM::VLD1q64PseudoWB_fixed};
Bob Wilson1c3ef902011-02-07 17:43:21 +00002865 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2866 ARM::VLD4q16Pseudo_UPD,
2867 ARM::VLD4q32Pseudo_UPD };
2868 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2869 ARM::VLD4q16oddPseudo_UPD,
2870 ARM::VLD4q32oddPseudo_UPD };
2871 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2872 }
2873
2874 case ARMISD::VLD2LN_UPD: {
2875 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD, ARM::VLD2LNd16Pseudo_UPD,
2876 ARM::VLD2LNd32Pseudo_UPD };
2877 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2878 ARM::VLD2LNq32Pseudo_UPD };
2879 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2880 }
2881
2882 case ARMISD::VLD3LN_UPD: {
2883 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD, ARM::VLD3LNd16Pseudo_UPD,
2884 ARM::VLD3LNd32Pseudo_UPD };
2885 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2886 ARM::VLD3LNq32Pseudo_UPD };
2887 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2888 }
2889
2890 case ARMISD::VLD4LN_UPD: {
2891 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD, ARM::VLD4LNd16Pseudo_UPD,
2892 ARM::VLD4LNd32Pseudo_UPD };
2893 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2894 ARM::VLD4LNq32Pseudo_UPD };
2895 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2896 }
2897
2898 case ARMISD::VST1_UPD: {
Jim Grosbach4334e032011-10-31 21:50:31 +00002899 unsigned DOpcodes[] = { ARM::VST1d8wb_fixed, ARM::VST1d16wb_fixed,
2900 ARM::VST1d32wb_fixed, ARM::VST1d64wb_fixed };
2901 unsigned QOpcodes[] = { ARM::VST1q8PseudoWB_fixed,
2902 ARM::VST1q16PseudoWB_fixed,
2903 ARM::VST1q32PseudoWB_fixed,
2904 ARM::VST1q64PseudoWB_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002905 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2906 }
2907
2908 case ARMISD::VST2_UPD: {
Jim Grosbachbb3a2e42011-12-14 21:32:11 +00002909 unsigned DOpcodes[] = { ARM::VST2d8PseudoWB_fixed,
2910 ARM::VST2d16PseudoWB_fixed,
2911 ARM::VST2d32PseudoWB_fixed,
2912 ARM::VST1q64PseudoWB_fixed};
2913 unsigned QOpcodes[] = { ARM::VST2q8PseudoWB_fixed,
2914 ARM::VST2q16PseudoWB_fixed,
2915 ARM::VST2q32PseudoWB_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002916 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2917 }
2918
2919 case ARMISD::VST3_UPD: {
2920 unsigned DOpcodes[] = { ARM::VST3d8Pseudo_UPD, ARM::VST3d16Pseudo_UPD,
Jim Grosbachd5ca2012011-11-29 22:38:04 +00002921 ARM::VST3d32Pseudo_UPD,ARM::VST1d64TPseudoWB_fixed};
Bob Wilson1c3ef902011-02-07 17:43:21 +00002922 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2923 ARM::VST3q16Pseudo_UPD,
2924 ARM::VST3q32Pseudo_UPD };
2925 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2926 ARM::VST3q16oddPseudo_UPD,
2927 ARM::VST3q32oddPseudo_UPD };
2928 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2929 }
2930
2931 case ARMISD::VST4_UPD: {
2932 unsigned DOpcodes[] = { ARM::VST4d8Pseudo_UPD, ARM::VST4d16Pseudo_UPD,
Jim Grosbach4c7edb32011-11-29 22:58:48 +00002933 ARM::VST4d32Pseudo_UPD,ARM::VST1d64QPseudoWB_fixed};
Bob Wilson1c3ef902011-02-07 17:43:21 +00002934 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2935 ARM::VST4q16Pseudo_UPD,
2936 ARM::VST4q32Pseudo_UPD };
2937 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2938 ARM::VST4q16oddPseudo_UPD,
2939 ARM::VST4q32oddPseudo_UPD };
2940 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2941 }
2942
2943 case ARMISD::VST2LN_UPD: {
2944 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD, ARM::VST2LNd16Pseudo_UPD,
2945 ARM::VST2LNd32Pseudo_UPD };
2946 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2947 ARM::VST2LNq32Pseudo_UPD };
2948 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2949 }
2950
2951 case ARMISD::VST3LN_UPD: {
2952 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD, ARM::VST3LNd16Pseudo_UPD,
2953 ARM::VST3LNd32Pseudo_UPD };
2954 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2955 ARM::VST3LNq32Pseudo_UPD };
2956 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2957 }
2958
2959 case ARMISD::VST4LN_UPD: {
2960 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD, ARM::VST4LNd16Pseudo_UPD,
2961 ARM::VST4LNd32Pseudo_UPD };
2962 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2963 ARM::VST4LNq32Pseudo_UPD };
2964 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson6c4c9822010-11-30 00:00:35 +00002965 }
2966
Bob Wilson31fb12f2009-08-26 17:39:53 +00002967 case ISD::INTRINSIC_VOID:
2968 case ISD::INTRINSIC_W_CHAIN: {
2969 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002970 switch (IntNo) {
2971 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002972 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002973
Bruno Cardoso Lopesa0112d02011-05-28 04:07:29 +00002974 case Intrinsic::arm_ldrexd: {
2975 SDValue MemAddr = N->getOperand(2);
2976 DebugLoc dl = N->getDebugLoc();
2977 SDValue Chain = N->getOperand(0);
2978
2979 unsigned NewOpc = ARM::LDREXD;
2980 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2981 NewOpc = ARM::t2LDREXD;
2982
2983 // arm_ldrexd returns a i64 value in {i32, i32}
2984 std::vector<EVT> ResTys;
2985 ResTys.push_back(MVT::i32);
2986 ResTys.push_back(MVT::i32);
2987 ResTys.push_back(MVT::Other);
2988
2989 // place arguments in the right order
2990 SmallVector<SDValue, 7> Ops;
2991 Ops.push_back(MemAddr);
2992 Ops.push_back(getAL(CurDAG));
2993 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2994 Ops.push_back(Chain);
2995 SDNode *Ld = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
2996 Ops.size());
2997 // Transfer memoperands.
2998 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2999 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
3000 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
3001
3002 // Until there's support for specifing explicit register constraints
3003 // like the use of even/odd register pair, hardcode ldrexd to always
3004 // use the pair [R0, R1] to hold the load result.
3005 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R0,
3006 SDValue(Ld, 0), SDValue(0,0));
3007 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R1,
3008 SDValue(Ld, 1), Chain.getValue(1));
3009
3010 // Remap uses.
3011 SDValue Glue = Chain.getValue(1);
3012 if (!SDValue(N, 0).use_empty()) {
3013 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3014 ARM::R0, MVT::i32, Glue);
3015 Glue = Result.getValue(2);
3016 ReplaceUses(SDValue(N, 0), Result);
3017 }
3018 if (!SDValue(N, 1).use_empty()) {
3019 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3020 ARM::R1, MVT::i32, Glue);
3021 Glue = Result.getValue(2);
3022 ReplaceUses(SDValue(N, 1), Result);
3023 }
3024
3025 ReplaceUses(SDValue(N, 2), SDValue(Ld, 2));
3026 return NULL;
3027 }
3028
3029 case Intrinsic::arm_strexd: {
3030 DebugLoc dl = N->getDebugLoc();
3031 SDValue Chain = N->getOperand(0);
3032 SDValue Val0 = N->getOperand(2);
3033 SDValue Val1 = N->getOperand(3);
3034 SDValue MemAddr = N->getOperand(4);
3035
3036 // Until there's support for specifing explicit register constraints
3037 // like the use of even/odd register pair, hardcode strexd to always
3038 // use the pair [R2, R3] to hold the i64 (i32, i32) value to be stored.
3039 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R2, Val0,
3040 SDValue(0, 0));
3041 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R3, Val1, Chain.getValue(1));
3042
3043 SDValue Glue = Chain.getValue(1);
3044 Val0 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3045 ARM::R2, MVT::i32, Glue);
3046 Glue = Val0.getValue(1);
3047 Val1 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3048 ARM::R3, MVT::i32, Glue);
3049
3050 // Store exclusive double return a i32 value which is the return status
3051 // of the issued store.
3052 std::vector<EVT> ResTys;
3053 ResTys.push_back(MVT::i32);
3054 ResTys.push_back(MVT::Other);
3055
3056 // place arguments in the right order
3057 SmallVector<SDValue, 7> Ops;
3058 Ops.push_back(Val0);
3059 Ops.push_back(Val1);
3060 Ops.push_back(MemAddr);
3061 Ops.push_back(getAL(CurDAG));
3062 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
3063 Ops.push_back(Chain);
3064
3065 unsigned NewOpc = ARM::STREXD;
3066 if (Subtarget->isThumb() && Subtarget->hasThumb2())
3067 NewOpc = ARM::t2STREXD;
3068
3069 SDNode *St = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
3070 Ops.size());
3071 // Transfer memoperands.
3072 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
3073 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
3074 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
3075
3076 return St;
3077 }
3078
Bob Wilson621f1952010-03-23 05:25:43 +00003079 case Intrinsic::arm_neon_vld1: {
3080 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
3081 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00003082 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
3083 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003084 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson621f1952010-03-23 05:25:43 +00003085 }
3086
Bob Wilson31fb12f2009-08-26 17:39:53 +00003087 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00003088 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
3089 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
3090 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
3091 ARM::VLD2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003092 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003093 }
3094
3095 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00003096 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
3097 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
3098 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
3099 ARM::VLD3q16Pseudo_UPD,
3100 ARM::VLD3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00003101 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo,
3102 ARM::VLD3q16oddPseudo,
3103 ARM::VLD3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003104 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003105 }
3106
3107 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00003108 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
3109 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
3110 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
3111 ARM::VLD4q16Pseudo_UPD,
3112 ARM::VLD4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00003113 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo,
3114 ARM::VLD4q16oddPseudo,
3115 ARM::VLD4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003116 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003117 }
3118
Bob Wilson243fcc52009-09-01 04:26:28 +00003119 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00003120 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
3121 ARM::VLD2LNd32Pseudo };
3122 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003123 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00003124 }
3125
3126 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00003127 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
3128 ARM::VLD3LNd32Pseudo };
3129 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003130 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00003131 }
3132
3133 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00003134 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
3135 ARM::VLD4LNd32Pseudo };
3136 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003137 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00003138 }
3139
Bob Wilson11d98992010-03-23 06:20:33 +00003140 case Intrinsic::arm_neon_vst1: {
3141 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
3142 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00003143 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
3144 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003145 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson11d98992010-03-23 06:20:33 +00003146 }
3147
Bob Wilson31fb12f2009-08-26 17:39:53 +00003148 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00003149 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
3150 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
3151 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
3152 ARM::VST2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003153 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003154 }
3155
3156 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00003157 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
3158 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
3159 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
3160 ARM::VST3q16Pseudo_UPD,
3161 ARM::VST3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00003162 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo,
3163 ARM::VST3q16oddPseudo,
3164 ARM::VST3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003165 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003166 }
3167
3168 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00003169 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00003170 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00003171 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
3172 ARM::VST4q16Pseudo_UPD,
3173 ARM::VST4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00003174 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo,
3175 ARM::VST4q16oddPseudo,
3176 ARM::VST4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003177 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003178 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00003179
3180 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00003181 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
3182 ARM::VST2LNd32Pseudo };
3183 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003184 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003185 }
3186
3187 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00003188 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
3189 ARM::VST3LNd32Pseudo };
3190 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003191 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003192 }
3193
3194 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00003195 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
3196 ARM::VST4LNd32Pseudo };
3197 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003198 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003199 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00003200 }
Bob Wilson429009b2010-05-06 16:05:26 +00003201 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00003202 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00003203
Bob Wilsond491d6e2010-07-06 23:36:25 +00003204 case ISD::INTRINSIC_WO_CHAIN: {
3205 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
3206 switch (IntNo) {
3207 default:
3208 break;
3209
3210 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003211 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003212 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003213 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003214 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003215 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003216
3217 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003218 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003219 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003220 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003221 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003222 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003223 }
3224 break;
3225 }
3226
Bill Wendling69a05a72011-03-14 23:02:38 +00003227 case ARMISD::VTBL1: {
3228 DebugLoc dl = N->getDebugLoc();
3229 EVT VT = N->getValueType(0);
3230 SmallVector<SDValue, 6> Ops;
3231
3232 Ops.push_back(N->getOperand(0));
3233 Ops.push_back(N->getOperand(1));
3234 Ops.push_back(getAL(CurDAG)); // Predicate
3235 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3236 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops.data(), Ops.size());
3237 }
3238 case ARMISD::VTBL2: {
3239 DebugLoc dl = N->getDebugLoc();
3240 EVT VT = N->getValueType(0);
3241
3242 // Form a REG_SEQUENCE to force register allocation.
3243 SDValue V0 = N->getOperand(0);
3244 SDValue V1 = N->getOperand(1);
3245 SDValue RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
3246
3247 SmallVector<SDValue, 6> Ops;
3248 Ops.push_back(RegSeq);
3249 Ops.push_back(N->getOperand(2));
3250 Ops.push_back(getAL(CurDAG)); // Predicate
3251 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3252 return CurDAG->getMachineNode(ARM::VTBL2Pseudo, dl, VT,
3253 Ops.data(), Ops.size());
3254 }
3255
Bob Wilson429009b2010-05-06 16:05:26 +00003256 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00003257 return SelectConcatVector(N);
Eli Friedman2bdffe42011-08-31 00:31:29 +00003258
3259 case ARMISD::ATOMOR64_DAG:
3260 return SelectAtomic64(N, ARM::ATOMOR6432);
3261 case ARMISD::ATOMXOR64_DAG:
3262 return SelectAtomic64(N, ARM::ATOMXOR6432);
3263 case ARMISD::ATOMADD64_DAG:
3264 return SelectAtomic64(N, ARM::ATOMADD6432);
3265 case ARMISD::ATOMSUB64_DAG:
3266 return SelectAtomic64(N, ARM::ATOMSUB6432);
3267 case ARMISD::ATOMNAND64_DAG:
3268 return SelectAtomic64(N, ARM::ATOMNAND6432);
3269 case ARMISD::ATOMAND64_DAG:
3270 return SelectAtomic64(N, ARM::ATOMAND6432);
3271 case ARMISD::ATOMSWAP64_DAG:
3272 return SelectAtomic64(N, ARM::ATOMSWAP6432);
Eli Friedman4d3f3292011-08-31 17:52:22 +00003273 case ARMISD::ATOMCMPXCHG64_DAG:
3274 return SelectAtomic64(N, ARM::ATOMCMPXCHG6432);
Evan Chengde8aa4e2010-05-05 18:28:36 +00003275 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00003276
Dan Gohmaneeb3a002010-01-05 01:24:18 +00003277 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00003278}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003279
Bob Wilson224c2442009-05-19 05:53:42 +00003280bool ARMDAGToDAGISel::
3281SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
3282 std::vector<SDValue> &OutOps) {
3283 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00003284 // Require the address to be in a register. That is safe for all ARM
3285 // variants and it is hard to do anything much smarter without knowing
3286 // how the operand is used.
3287 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00003288 return false;
3289}
3290
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003291/// createARMISelDag - This pass converts a legalized DAG into a
3292/// ARM-specific DAG, ready for instruction scheduling.
3293///
Bob Wilson522ce972009-09-28 14:30:20 +00003294FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
3295 CodeGenOpt::Level OptLevel) {
3296 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003297}