blob: 962368d07ff1a0577103e8fafd03be9ffd687216 [file] [log] [blame]
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00001//===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Espindolaffdc24b2006-05-14 22:18:28 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the ARM target.
11//
12//===----------------------------------------------------------------------===//
13
Dale Johannesend679ff72010-06-03 21:09:53 +000014#define DEBUG_TYPE "arm-isel"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000015#include "ARM.h"
Evan Cheng62c7b5b2010-12-05 22:04:16 +000016#include "ARMBaseInstrInfo.h"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000017#include "ARMTargetMachine.h"
Evan Chenga20cde32011-07-20 23:34:39 +000018#include "MCTargetDesc/ARMAddressingModes.h"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000019#include "llvm/CodeGen/MachineFrameInfo.h"
20#include "llvm/CodeGen/MachineFunction.h"
21#include "llvm/CodeGen/MachineInstrBuilder.h"
Weiming Zhaoc5987002013-02-14 18:10:21 +000022#include "llvm/CodeGen/MachineRegisterInfo.h"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000023#include "llvm/CodeGen/SelectionDAG.h"
24#include "llvm/CodeGen/SelectionDAGISel.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000025#include "llvm/IR/CallingConv.h"
26#include "llvm/IR/Constants.h"
27#include "llvm/IR/DerivedTypes.h"
28#include "llvm/IR/Function.h"
29#include "llvm/IR/Intrinsics.h"
30#include "llvm/IR/LLVMContext.h"
Evan Cheng8e6b40a2010-05-04 20:39:49 +000031#include "llvm/Support/CommandLine.h"
Chris Lattner1770fb82008-02-03 05:43:57 +000032#include "llvm/Support/Compiler.h"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000033#include "llvm/Support/Debug.h"
Torok Edwinfb8d6d52009-07-08 20:53:28 +000034#include "llvm/Support/ErrorHandling.h"
35#include "llvm/Support/raw_ostream.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000036#include "llvm/Target/TargetLowering.h"
37#include "llvm/Target/TargetOptions.h"
Torok Edwinfb8d6d52009-07-08 20:53:28 +000038
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000039using namespace llvm;
40
Evan Cheng59069ec2010-07-30 23:33:54 +000041static cl::opt<bool>
42DisableShifterOp("disable-shifter-op", cl::Hidden,
43 cl::desc("Disable isel of shifter-op"),
44 cl::init(false));
45
Evan Cheng62c7b5b2010-12-05 22:04:16 +000046static cl::opt<bool>
47CheckVMLxHazard("check-vmlx-hazard", cl::Hidden,
48 cl::desc("Check fp vmla / vmls hazard at isel time"),
Bob Wilson0858c3a2011-04-19 18:11:57 +000049 cl::init(true));
Evan Cheng62c7b5b2010-12-05 22:04:16 +000050
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000051//===--------------------------------------------------------------------===//
52/// ARMDAGToDAGISel - ARM specific code to select ARM machine
53/// instructions for SelectionDAG operations.
54///
55namespace {
Jim Grosbach08605202010-09-29 19:03:54 +000056
57enum AddrMode2Type {
58 AM2_BASE, // Simple AM2 (+-imm12)
59 AM2_SHOP // Shifter-op AM2
60};
61
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000062class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikov99152f32009-06-26 21:28:53 +000063 ARMBaseTargetMachine &TM;
Evan Cheng62c7b5b2010-12-05 22:04:16 +000064 const ARMBaseInstrInfo *TII;
Evan Chengbc0d0ec2008-09-18 07:24:33 +000065
Evan Cheng10043e22007-01-19 07:51:42 +000066 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
67 /// make the right decision when generating code for different targets.
68 const ARMSubtarget *Subtarget;
69
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000070public:
Bob Wilson2dd957f2009-09-28 14:30:20 +000071 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
72 CodeGenOpt::Level OptLevel)
73 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Cheng62c7b5b2010-12-05 22:04:16 +000074 TII(static_cast<const ARMBaseInstrInfo*>(TM.getInstrInfo())),
75 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000076 }
77
Evan Cheng10043e22007-01-19 07:51:42 +000078 virtual const char *getPassName() const {
79 return "ARM Instruction Selection";
Anton Korobeynikov02bb33c2009-06-17 18:13:58 +000080 }
81
Evan Chengeae6d2c2012-12-19 20:16:09 +000082 virtual void PreprocessISelDAG();
83
Bob Wilson4facd962009-10-08 18:51:31 +000084 /// getI32Imm - Return a target constant of type i32 with the specified
85 /// value.
Anton Korobeynikov02bb33c2009-06-17 18:13:58 +000086 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson9f944592009-08-11 20:47:22 +000087 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov02bb33c2009-06-17 18:13:58 +000088 }
89
Dan Gohmanea6f91f2010-01-05 01:24:18 +000090 SDNode *Select(SDNode *N);
Evan Cheng5e73ff22010-02-15 19:41:07 +000091
Evan Cheng62c7b5b2010-12-05 22:04:16 +000092
93 bool hasNoVMLxHazardUse(SDNode *N) const;
Evan Cheng59bbc542010-10-27 23:41:30 +000094 bool isShifterOpProfitable(const SDValue &Shift,
95 ARM_AM::ShiftOpc ShOpcVal, unsigned ShAmt);
Owen Andersonb595ed02011-07-21 18:54:16 +000096 bool SelectRegShifterOperand(SDValue N, SDValue &A,
97 SDValue &B, SDValue &C,
98 bool CheckProfitability = true);
99 bool SelectImmShifterOperand(SDValue N, SDValue &A,
Owen Anderson04912702011-07-21 23:38:37 +0000100 SDValue &B, bool CheckProfitability = true);
101 bool SelectShiftRegShifterOperand(SDValue N, SDValue &A,
Owen Anderson6d557452011-03-18 19:46:58 +0000102 SDValue &B, SDValue &C) {
103 // Don't apply the profitability check
Owen Anderson04912702011-07-21 23:38:37 +0000104 return SelectRegShifterOperand(N, A, B, C, false);
105 }
106 bool SelectShiftImmShifterOperand(SDValue N, SDValue &A,
107 SDValue &B) {
108 // Don't apply the profitability check
109 return SelectImmShifterOperand(N, A, B, false);
Owen Anderson6d557452011-03-18 19:46:58 +0000110 }
111
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000112 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
113 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
114
Jim Grosbach08605202010-09-29 19:03:54 +0000115 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
116 SDValue &Offset, SDValue &Opc);
117 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
118 SDValue &Opc) {
119 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
120 }
121
122 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
123 SDValue &Opc) {
124 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
125 }
126
127 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
128 SDValue &Opc) {
129 SelectAddrMode2Worker(N, Base, Offset, Opc);
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000130// return SelectAddrMode2ShOp(N, Base, Offset, Opc);
Jim Grosbach08605202010-09-29 19:03:54 +0000131 // This always matches one way or another.
132 return true;
133 }
134
Owen Anderson2aedba62011-07-26 20:54:26 +0000135 bool SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
136 SDValue &Offset, SDValue &Opc);
137 bool SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000138 SDValue &Offset, SDValue &Opc);
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000139 bool SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
140 SDValue &Offset, SDValue &Opc);
Jim Grosbachf0c95ca2011-08-05 20:35:44 +0000141 bool SelectAddrOffsetNone(SDValue N, SDValue &Base);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000142 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000143 SDValue &Offset, SDValue &Opc);
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000144 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000145 SDValue &Offset, SDValue &Opc);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000146 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000147 SDValue &Offset);
Bob Wilsondd9fbaa2010-11-01 23:40:51 +0000148 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
Bob Wilsone3ecd5f2011-02-25 06:42:42 +0000149 bool SelectAddrMode6Offset(SDNode *Op, SDValue N, SDValue &Offset);
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000150
Evan Chengdfce83c2011-01-17 08:03:18 +0000151 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
Evan Cheng10043e22007-01-19 07:51:42 +0000152
Bill Wendling092a7bd2010-12-14 03:36:38 +0000153 // Thumb Addressing Modes:
Chris Lattner0e023ea2010-09-21 20:31:19 +0000154 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000155 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
156 unsigned Scale);
157 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
158 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
159 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
160 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
161 SDValue &OffImm);
162 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
163 SDValue &OffImm);
164 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
165 SDValue &OffImm);
166 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
167 SDValue &OffImm);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000168 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +0000169
Bill Wendling092a7bd2010-12-14 03:36:38 +0000170 // Thumb 2 Addressing Modes:
Chris Lattner0e023ea2010-09-21 20:31:19 +0000171 bool SelectT2ShifterOperandReg(SDValue N,
Evan Chengeab9ca72009-06-27 02:26:13 +0000172 SDValue &BaseReg, SDValue &Opc);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000173 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
174 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Chengb23b50d2009-06-29 07:51:04 +0000175 SDValue &OffImm);
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000176 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Cheng84c6cda2009-07-02 07:28:31 +0000177 SDValue &OffImm);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000178 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Chengb23b50d2009-06-29 07:51:04 +0000179 SDValue &OffReg, SDValue &ShImm);
180
Evan Cheng0fc80842010-11-12 22:42:47 +0000181 inline bool is_so_imm(unsigned Imm) const {
182 return ARM_AM::getSOImmVal(Imm) != -1;
183 }
184
185 inline bool is_so_imm_not(unsigned Imm) const {
186 return ARM_AM::getSOImmVal(~Imm) != -1;
187 }
188
189 inline bool is_t2_so_imm(unsigned Imm) const {
190 return ARM_AM::getT2SOImmVal(Imm) != -1;
191 }
192
193 inline bool is_t2_so_imm_not(unsigned Imm) const {
194 return ARM_AM::getT2SOImmVal(~Imm) != -1;
195 }
196
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000197 // Include the pieces autogenerated from the target description.
198#include "ARMGenDAGISel.inc"
Bob Wilsona2c462b2009-05-19 05:53:42 +0000199
200private:
Evan Cheng84c6cda2009-07-02 07:28:31 +0000201 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
202 /// ARM.
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000203 SDNode *SelectARMIndexedLoad(SDNode *N);
204 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Cheng84c6cda2009-07-02 07:28:31 +0000205
Bob Wilson340861d2010-03-23 05:25:43 +0000206 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
207 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson12b47992009-10-14 17:28:52 +0000208 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson340861d2010-03-23 05:25:43 +0000209 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson06fce872011-02-07 17:43:21 +0000210 SDNode *SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000211 const uint16_t *DOpcodes,
212 const uint16_t *QOpcodes0, const uint16_t *QOpcodes1);
Bob Wilson12b47992009-10-14 17:28:52 +0000213
Bob Wilsonc350cdf2009-10-14 18:32:29 +0000214 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilsoncc0a2a72010-03-23 06:20:33 +0000215 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilsonc350cdf2009-10-14 18:32:29 +0000216 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilsoncc0a2a72010-03-23 06:20:33 +0000217 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson06fce872011-02-07 17:43:21 +0000218 SDNode *SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000219 const uint16_t *DOpcodes,
220 const uint16_t *QOpcodes0, const uint16_t *QOpcodes1);
Bob Wilsonc350cdf2009-10-14 18:32:29 +0000221
Bob Wilson93117bc2009-10-14 16:46:45 +0000222 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilson4145e3a2009-10-14 16:19:03 +0000223 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilsond5c57a52010-09-13 23:01:35 +0000224 /// load/store of D registers and Q registers.
Bob Wilson06fce872011-02-07 17:43:21 +0000225 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad,
226 bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000227 const uint16_t *DOpcodes, const uint16_t *QOpcodes);
Bob Wilson4145e3a2009-10-14 16:19:03 +0000228
Bob Wilson2d790df2010-11-28 06:51:26 +0000229 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
230 /// should be 2, 3 or 4. The opcode array specifies the instructions used
231 /// for loading D registers. (Q registers are not supported.)
Bob Wilson06fce872011-02-07 17:43:21 +0000232 SDNode *SelectVLDDup(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000233 const uint16_t *Opcodes);
Bob Wilson2d790df2010-11-28 06:51:26 +0000234
Bob Wilson5bc8a792010-07-07 00:08:54 +0000235 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
236 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
237 /// generated to force the table registers to be consecutive.
238 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilson3ed511b2010-07-06 23:36:25 +0000239
Sandeep Patel7460e082009-10-13 20:25:58 +0000240 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach825cb292010-04-22 23:24:18 +0000241 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel423e42b2009-10-13 18:59:48 +0000242
Evan Chengb6c77042009-11-19 21:45:22 +0000243 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000244 SDNode *SelectCMOVOp(SDNode *N);
245 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng81a28512009-11-20 00:54:03 +0000246 ARMCC::CondCodes CCVal, SDValue CCR,
247 SDValue InFlag);
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000248 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng81a28512009-11-20 00:54:03 +0000249 ARMCC::CondCodes CCVal, SDValue CCR,
250 SDValue InFlag);
Jim Grosbach5b255c22010-10-07 00:53:56 +0000251 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng81a28512009-11-20 00:54:03 +0000252 ARMCC::CondCodes CCVal, SDValue CCR,
253 SDValue InFlag);
Jim Grosbach742adc32010-10-07 00:42:42 +0000254 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng81a28512009-11-20 00:54:03 +0000255 ARMCC::CondCodes CCVal, SDValue CCR,
256 SDValue InFlag);
Evan Chengb6c77042009-11-19 21:45:22 +0000257
Bill Wendlinga7d697e2011-10-10 22:59:55 +0000258 // Select special operations if node forms integer ABS pattern
259 SDNode *SelectABSOp(SDNode *N);
260
Weiming Zhaoc5987002013-02-14 18:10:21 +0000261 SDNode *SelectInlineAsm(SDNode *N);
262
Evan Chengd85631e2010-05-05 18:28:36 +0000263 SDNode *SelectConcatVector(SDNode *N);
264
Eli Friedmanc3f9c4a2011-08-31 00:31:29 +0000265 SDNode *SelectAtomic64(SDNode *Node, unsigned Opc);
266
Evan Chengd9c55362009-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 Wilsone6b778d2009-10-06 22:01:59 +0000272
Weiming Zhao95782222012-11-17 00:23:35 +0000273 // Form pairs of consecutive R, S, D, or Q registers.
Weiming Zhao8f56f882012-11-16 21:55:34 +0000274 SDNode *createGPRPairNode(EVT VT, SDValue V0, SDValue V1);
Weiming Zhao95782222012-11-17 00:23:35 +0000275 SDNode *createSRegPairNode(EVT VT, SDValue V0, SDValue V1);
276 SDNode *createDRegPairNode(EVT VT, SDValue V0, SDValue V1);
277 SDNode *createQRegPairNode(EVT VT, SDValue V0, SDValue V1);
Evan Chengc2ae5f52010-05-10 17:34:18 +0000278
Bob Wilsond8a9a042010-06-04 00:04:02 +0000279 // Form sequences of 4 consecutive S, D, or Q registers.
Weiming Zhao95782222012-11-17 00:23:35 +0000280 SDNode *createQuadSRegsNode(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
281 SDNode *createQuadDRegsNode(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
282 SDNode *createQuadQRegsNode(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilsondd9fbaa2010-11-01 23:40:51 +0000283
284 // Get the alignment operand for a NEON VLD or VST instruction.
285 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000286};
Evan Cheng10043e22007-01-19 07:51:42 +0000287}
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000288
Sandeep Patel423e42b2009-10-13 18:59:48 +0000289/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
290/// operand. If so Imm will receive the 32-bit value.
291static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
292 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
293 Imm = cast<ConstantSDNode>(N)->getZExtValue();
294 return true;
295 }
296 return false;
297}
298
299// isInt32Immediate - This method tests to see if a constant operand.
300// If so Imm will receive the 32 bit value.
301static bool isInt32Immediate(SDValue N, unsigned &Imm) {
302 return isInt32Immediate(N.getNode(), Imm);
303}
304
305// isOpcWithIntImmediate - This method tests to see if the node is a specific
306// opcode and that it has a immediate integer right operand.
307// If so Imm will receive the 32 bit value.
308static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
309 return N->getOpcode() == Opc &&
310 isInt32Immediate(N->getOperand(1).getNode(), Imm);
311}
312
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000313/// \brief Check whether a particular node is a constant value representable as
Dmitri Gribenko5485acd2012-09-14 14:57:36 +0000314/// (N * Scale) where (N in [\p RangeMin, \p RangeMax).
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000315///
316/// \param ScaledConstant [out] - On success, the pre-scaled constant value.
Jakob Stoklund Olesen2056d152011-09-23 22:10:33 +0000317static bool isScaledConstantInRange(SDValue Node, int Scale,
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000318 int RangeMin, int RangeMax,
319 int &ScaledConstant) {
Jakob Stoklund Olesen2056d152011-09-23 22:10:33 +0000320 assert(Scale > 0 && "Invalid scale!");
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000321
322 // Check that this is a constant.
323 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Node);
324 if (!C)
325 return false;
326
327 ScaledConstant = (int) C->getZExtValue();
328 if ((ScaledConstant % Scale) != 0)
329 return false;
330
331 ScaledConstant /= Scale;
332 return ScaledConstant >= RangeMin && ScaledConstant < RangeMax;
333}
334
Evan Chengeae6d2c2012-12-19 20:16:09 +0000335void ARMDAGToDAGISel::PreprocessISelDAG() {
336 if (!Subtarget->hasV6T2Ops())
337 return;
338
339 bool isThumb2 = Subtarget->isThumb();
340 for (SelectionDAG::allnodes_iterator I = CurDAG->allnodes_begin(),
341 E = CurDAG->allnodes_end(); I != E; ) {
342 SDNode *N = I++; // Preincrement iterator to avoid invalidation issues.
343
344 if (N->getOpcode() != ISD::ADD)
345 continue;
346
347 // Look for (add X1, (and (srl X2, c1), c2)) where c2 is constant with
348 // leading zeros, followed by consecutive set bits, followed by 1 or 2
349 // trailing zeros, e.g. 1020.
350 // Transform the expression to
351 // (add X1, (shl (and (srl X2, c1), (c2>>tz)), tz)) where tz is the number
352 // of trailing zeros of c2. The left shift would be folded as an shifter
353 // operand of 'add' and the 'and' and 'srl' would become a bits extraction
354 // node (UBFX).
355
356 SDValue N0 = N->getOperand(0);
357 SDValue N1 = N->getOperand(1);
358 unsigned And_imm = 0;
359 if (!isOpcWithIntImmediate(N1.getNode(), ISD::AND, And_imm)) {
360 if (isOpcWithIntImmediate(N0.getNode(), ISD::AND, And_imm))
361 std::swap(N0, N1);
362 }
363 if (!And_imm)
364 continue;
365
366 // Check if the AND mask is an immediate of the form: 000.....1111111100
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +0000367 unsigned TZ = countTrailingZeros(And_imm);
Evan Chengeae6d2c2012-12-19 20:16:09 +0000368 if (TZ != 1 && TZ != 2)
369 // Be conservative here. Shifter operands aren't always free. e.g. On
370 // Swift, left shifter operand of 1 / 2 for free but others are not.
371 // e.g.
372 // ubfx r3, r1, #16, #8
373 // ldr.w r3, [r0, r3, lsl #2]
374 // vs.
375 // mov.w r9, #1020
376 // and.w r2, r9, r1, lsr #14
377 // ldr r2, [r0, r2]
378 continue;
379 And_imm >>= TZ;
380 if (And_imm & (And_imm + 1))
381 continue;
382
383 // Look for (and (srl X, c1), c2).
384 SDValue Srl = N1.getOperand(0);
385 unsigned Srl_imm = 0;
386 if (!isOpcWithIntImmediate(Srl.getNode(), ISD::SRL, Srl_imm) ||
387 (Srl_imm <= 2))
388 continue;
389
390 // Make sure first operand is not a shifter operand which would prevent
391 // folding of the left shift.
392 SDValue CPTmp0;
393 SDValue CPTmp1;
394 SDValue CPTmp2;
395 if (isThumb2) {
396 if (SelectT2ShifterOperandReg(N0, CPTmp0, CPTmp1))
397 continue;
398 } else {
399 if (SelectImmShifterOperand(N0, CPTmp0, CPTmp1) ||
400 SelectRegShifterOperand(N0, CPTmp0, CPTmp1, CPTmp2))
401 continue;
402 }
403
404 // Now make the transformation.
Andrew Trickef9de2a2013-05-25 02:42:55 +0000405 Srl = CurDAG->getNode(ISD::SRL, SDLoc(Srl), MVT::i32,
Evan Chengeae6d2c2012-12-19 20:16:09 +0000406 Srl.getOperand(0),
407 CurDAG->getConstant(Srl_imm+TZ, MVT::i32));
Andrew Trickef9de2a2013-05-25 02:42:55 +0000408 N1 = CurDAG->getNode(ISD::AND, SDLoc(N1), MVT::i32,
Evan Chengeae6d2c2012-12-19 20:16:09 +0000409 Srl, CurDAG->getConstant(And_imm, MVT::i32));
Andrew Trickef9de2a2013-05-25 02:42:55 +0000410 N1 = CurDAG->getNode(ISD::SHL, SDLoc(N1), MVT::i32,
Evan Chengeae6d2c2012-12-19 20:16:09 +0000411 N1, CurDAG->getConstant(TZ, MVT::i32));
412 CurDAG->UpdateNodeOperands(N, N0, N1);
413 }
414}
415
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000416/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
417/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
418/// least on current ARM implementations) which should be avoidded.
419bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
420 if (OptLevel == CodeGenOpt::None)
421 return true;
422
423 if (!CheckVMLxHazard)
424 return true;
Bob Wilsone8a549c2012-09-29 21:43:49 +0000425
426 if (!Subtarget->isCortexA8() && !Subtarget->isLikeA9() &&
427 !Subtarget->isSwift())
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000428 return true;
429
430 if (!N->hasOneUse())
431 return false;
432
433 SDNode *Use = *N->use_begin();
434 if (Use->getOpcode() == ISD::CopyToReg)
435 return true;
436 if (Use->isMachineOpcode()) {
Evan Cheng6cc775f2011-06-28 19:10:37 +0000437 const MCInstrDesc &MCID = TII->get(Use->getMachineOpcode());
438 if (MCID.mayStore())
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000439 return true;
Evan Cheng6cc775f2011-06-28 19:10:37 +0000440 unsigned Opcode = MCID.getOpcode();
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000441 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
442 return true;
443 // vmlx feeding into another vmlx. We actually want to unfold
444 // the use later in the MLxExpansion pass. e.g.
445 // vmla
446 // vmla (stall 8 cycles)
447 //
448 // vmul (5 cycles)
449 // vadd (5 cycles)
450 // vmla
451 // This adds up to about 18 - 19 cycles.
452 //
453 // vmla
454 // vmul (stall 4 cycles)
455 // vadd adds up to about 14 cycles.
456 return TII->isFpMLxInstruction(Opcode);
457 }
458
459 return false;
460}
Sandeep Patel423e42b2009-10-13 18:59:48 +0000461
Evan Cheng59bbc542010-10-27 23:41:30 +0000462bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
463 ARM_AM::ShiftOpc ShOpcVal,
464 unsigned ShAmt) {
Bob Wilsone8a549c2012-09-29 21:43:49 +0000465 if (!Subtarget->isLikeA9() && !Subtarget->isSwift())
Evan Cheng59bbc542010-10-27 23:41:30 +0000466 return true;
467 if (Shift.hasOneUse())
468 return true;
469 // R << 2 is free.
Bob Wilsone8a549c2012-09-29 21:43:49 +0000470 return ShOpcVal == ARM_AM::lsl &&
471 (ShAmt == 2 || (Subtarget->isSwift() && ShAmt == 1));
Evan Cheng59bbc542010-10-27 23:41:30 +0000472}
473
Owen Andersonb595ed02011-07-21 18:54:16 +0000474bool ARMDAGToDAGISel::SelectImmShifterOperand(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +0000475 SDValue &BaseReg,
Owen Anderson6d557452011-03-18 19:46:58 +0000476 SDValue &Opc,
477 bool CheckProfitability) {
Evan Cheng59069ec2010-07-30 23:33:54 +0000478 if (DisableShifterOp)
479 return false;
480
Evan Chenga20cde32011-07-20 23:34:39 +0000481 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chengb23b50d2009-06-29 07:51:04 +0000482
483 // Don't match base register only case. That is matched to a separate
484 // lower complexity pattern with explicit register operand.
485 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000486
Evan Chengb23b50d2009-06-29 07:51:04 +0000487 BaseReg = N.getOperand(0);
488 unsigned ShImmVal = 0;
Owen Andersonb595ed02011-07-21 18:54:16 +0000489 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
490 if (!RHS) return false;
Owen Andersonb595ed02011-07-21 18:54:16 +0000491 ShImmVal = RHS->getZExtValue() & 31;
Evan Cheng59bbc542010-10-27 23:41:30 +0000492 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
493 MVT::i32);
494 return true;
495}
496
Owen Andersonb595ed02011-07-21 18:54:16 +0000497bool ARMDAGToDAGISel::SelectRegShifterOperand(SDValue N,
498 SDValue &BaseReg,
499 SDValue &ShReg,
500 SDValue &Opc,
501 bool CheckProfitability) {
502 if (DisableShifterOp)
503 return false;
504
505 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
506
507 // Don't match base register only case. That is matched to a separate
508 // lower complexity pattern with explicit register operand.
509 if (ShOpcVal == ARM_AM::no_shift) return false;
510
511 BaseReg = N.getOperand(0);
512 unsigned ShImmVal = 0;
513 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
514 if (RHS) return false;
515
516 ShReg = N.getOperand(1);
517 if (CheckProfitability && !isShifterOpProfitable(N, ShOpcVal, ShImmVal))
518 return false;
519 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
520 MVT::i32);
521 return true;
522}
523
524
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000525bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
526 SDValue &Base,
527 SDValue &OffImm) {
528 // Match simple R + imm12 operands.
529
530 // Base only.
Chris Lattner46c01a32011-02-13 22:25:43 +0000531 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
532 !CurDAG->isBaseWithConstantOffset(N)) {
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000533 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner46c01a32011-02-13 22:25:43 +0000534 // Match frame index.
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000535 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlingf7719082013-06-06 00:43:09 +0000536 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000537 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
538 return true;
Chris Lattner46c01a32011-02-13 22:25:43 +0000539 }
Owen Anderson6d557452011-03-18 19:46:58 +0000540
Chris Lattner46c01a32011-02-13 22:25:43 +0000541 if (N.getOpcode() == ARMISD::Wrapper &&
542 !(Subtarget->useMovt() &&
543 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000544 Base = N.getOperand(0);
545 } else
546 Base = N;
547 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
548 return true;
549 }
550
551 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
552 int RHSC = (int)RHS->getZExtValue();
553 if (N.getOpcode() == ISD::SUB)
554 RHSC = -RHSC;
555
556 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
557 Base = N.getOperand(0);
558 if (Base.getOpcode() == ISD::FrameIndex) {
559 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlingf7719082013-06-06 00:43:09 +0000560 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000561 }
562 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
563 return true;
564 }
565 }
566
567 // Base only.
568 Base = N;
569 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
570 return true;
571}
572
573
574
575bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
576 SDValue &Opc) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000577 if (N.getOpcode() == ISD::MUL &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000578 ((!Subtarget->isLikeA9() && !Subtarget->isSwift()) || N.hasOneUse())) {
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000579 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
580 // X * [3,5,9] -> X + X * [2,4,8] etc.
581 int RHSC = (int)RHS->getZExtValue();
582 if (RHSC & 1) {
583 RHSC = RHSC & ~1;
584 ARM_AM::AddrOpc AddSub = ARM_AM::add;
585 if (RHSC < 0) {
586 AddSub = ARM_AM::sub;
587 RHSC = - RHSC;
588 }
589 if (isPowerOf2_32(RHSC)) {
590 unsigned ShAmt = Log2_32(RHSC);
591 Base = Offset = N.getOperand(0);
592 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
593 ARM_AM::lsl),
594 MVT::i32);
595 return true;
596 }
597 }
598 }
599 }
600
Chris Lattner46c01a32011-02-13 22:25:43 +0000601 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
602 // ISD::OR that is equivalent to an ISD::ADD.
603 !CurDAG->isBaseWithConstantOffset(N))
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000604 return false;
605
606 // Leave simple R +/- imm12 operands for LDRi12
Chris Lattner46c01a32011-02-13 22:25:43 +0000607 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::OR) {
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000608 int RHSC;
609 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
610 -0x1000+1, 0x1000, RHSC)) // 12 bits.
611 return false;
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000612 }
613
614 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner46c01a32011-02-13 22:25:43 +0000615 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::SUB ? ARM_AM::sub:ARM_AM::add;
Evan Chenga20cde32011-07-20 23:34:39 +0000616 ARM_AM::ShiftOpc ShOpcVal =
617 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000618 unsigned ShAmt = 0;
619
620 Base = N.getOperand(0);
621 Offset = N.getOperand(1);
622
623 if (ShOpcVal != ARM_AM::no_shift) {
624 // Check to see if the RHS of the shift is a constant, if not, we can't fold
625 // it.
626 if (ConstantSDNode *Sh =
627 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
628 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +0000629 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
630 Offset = N.getOperand(1).getOperand(0);
631 else {
632 ShAmt = 0;
633 ShOpcVal = ARM_AM::no_shift;
634 }
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000635 } else {
636 ShOpcVal = ARM_AM::no_shift;
637 }
638 }
639
640 // Try matching (R shl C) + (R).
Chris Lattner46c01a32011-02-13 22:25:43 +0000641 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000642 !(Subtarget->isLikeA9() || Subtarget->isSwift() ||
643 N.getOperand(0).hasOneUse())) {
Evan Chenga20cde32011-07-20 23:34:39 +0000644 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000645 if (ShOpcVal != ARM_AM::no_shift) {
646 // Check to see if the RHS of the shift is a constant, if not, we can't
647 // fold it.
648 if (ConstantSDNode *Sh =
649 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
650 ShAmt = Sh->getZExtValue();
Cameron Zwarich842f99a2011-10-05 23:39:02 +0000651 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000652 Offset = N.getOperand(0).getOperand(0);
653 Base = N.getOperand(1);
654 } else {
655 ShAmt = 0;
656 ShOpcVal = ARM_AM::no_shift;
657 }
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000658 } else {
659 ShOpcVal = ARM_AM::no_shift;
660 }
661 }
662 }
663
664 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
665 MVT::i32);
666 return true;
667}
668
669
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000670//-----
671
Jim Grosbach08605202010-09-29 19:03:54 +0000672AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
673 SDValue &Base,
674 SDValue &Offset,
675 SDValue &Opc) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000676 if (N.getOpcode() == ISD::MUL &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000677 (!(Subtarget->isLikeA9() || Subtarget->isSwift()) || N.hasOneUse())) {
Evan Cheng72a8bcf2007-03-13 21:05:54 +0000678 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
679 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmaneffb8942008-09-12 16:56:44 +0000680 int RHSC = (int)RHS->getZExtValue();
Evan Cheng72a8bcf2007-03-13 21:05:54 +0000681 if (RHSC & 1) {
682 RHSC = RHSC & ~1;
683 ARM_AM::AddrOpc AddSub = ARM_AM::add;
684 if (RHSC < 0) {
685 AddSub = ARM_AM::sub;
686 RHSC = - RHSC;
687 }
688 if (isPowerOf2_32(RHSC)) {
689 unsigned ShAmt = Log2_32(RHSC);
690 Base = Offset = N.getOperand(0);
691 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
692 ARM_AM::lsl),
Owen Anderson9f944592009-08-11 20:47:22 +0000693 MVT::i32);
Jim Grosbach08605202010-09-29 19:03:54 +0000694 return AM2_SHOP;
Evan Cheng72a8bcf2007-03-13 21:05:54 +0000695 }
696 }
697 }
698 }
699
Chris Lattner46c01a32011-02-13 22:25:43 +0000700 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
701 // ISD::OR that is equivalent to an ADD.
702 !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng10043e22007-01-19 07:51:42 +0000703 Base = N;
704 if (N.getOpcode() == ISD::FrameIndex) {
705 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlingf7719082013-06-06 00:43:09 +0000706 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Anton Korobeynikov25229082009-11-24 00:44:37 +0000707 } else if (N.getOpcode() == ARMISD::Wrapper &&
708 !(Subtarget->useMovt() &&
709 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng10043e22007-01-19 07:51:42 +0000710 Base = N.getOperand(0);
711 }
Owen Anderson9f944592009-08-11 20:47:22 +0000712 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000713 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
714 ARM_AM::no_shift),
Owen Anderson9f944592009-08-11 20:47:22 +0000715 MVT::i32);
Jim Grosbach08605202010-09-29 19:03:54 +0000716 return AM2_BASE;
Rafael Espindola708cb602006-11-08 17:07:32 +0000717 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000718
Evan Cheng10043e22007-01-19 07:51:42 +0000719 // Match simple R +/- imm12 operands.
Chris Lattner46c01a32011-02-13 22:25:43 +0000720 if (N.getOpcode() != ISD::SUB) {
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000721 int RHSC;
722 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
723 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
724 Base = N.getOperand(0);
725 if (Base.getOpcode() == ISD::FrameIndex) {
726 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlingf7719082013-06-06 00:43:09 +0000727 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Rafael Espindola708cb602006-11-08 17:07:32 +0000728 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000729 Offset = CurDAG->getRegister(0, MVT::i32);
730
731 ARM_AM::AddrOpc AddSub = ARM_AM::add;
732 if (RHSC < 0) {
733 AddSub = ARM_AM::sub;
734 RHSC = - RHSC;
735 }
736 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
737 ARM_AM::no_shift),
738 MVT::i32);
739 return AM2_BASE;
Evan Cheng10043e22007-01-19 07:51:42 +0000740 }
Jim Grosbachc7b10f32010-09-29 17:32:29 +0000741 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000742
Bob Wilsone8a549c2012-09-29 21:43:49 +0000743 if ((Subtarget->isLikeA9() || Subtarget->isSwift()) && !N.hasOneUse()) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000744 // Compute R +/- (R << N) and reuse it.
745 Base = N;
746 Offset = CurDAG->getRegister(0, MVT::i32);
747 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
748 ARM_AM::no_shift),
749 MVT::i32);
750 return AM2_BASE;
751 }
752
Johnny Chenb678a562009-10-27 17:25:15 +0000753 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner46c01a32011-02-13 22:25:43 +0000754 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chenga20cde32011-07-20 23:34:39 +0000755 ARM_AM::ShiftOpc ShOpcVal =
756 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Evan Cheng10043e22007-01-19 07:51:42 +0000757 unsigned ShAmt = 0;
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000758
Evan Cheng10043e22007-01-19 07:51:42 +0000759 Base = N.getOperand(0);
760 Offset = N.getOperand(1);
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000761
Evan Cheng10043e22007-01-19 07:51:42 +0000762 if (ShOpcVal != ARM_AM::no_shift) {
763 // Check to see if the RHS of the shift is a constant, if not, we can't fold
764 // it.
765 if (ConstantSDNode *Sh =
766 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +0000767 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +0000768 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
769 Offset = N.getOperand(1).getOperand(0);
770 else {
771 ShAmt = 0;
772 ShOpcVal = ARM_AM::no_shift;
773 }
Evan Cheng10043e22007-01-19 07:51:42 +0000774 } else {
775 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola708cb602006-11-08 17:07:32 +0000776 }
777 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000778
Evan Cheng10043e22007-01-19 07:51:42 +0000779 // Try matching (R shl C) + (R).
Chris Lattner46c01a32011-02-13 22:25:43 +0000780 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000781 !(Subtarget->isLikeA9() || Subtarget->isSwift() ||
782 N.getOperand(0).hasOneUse())) {
Evan Chenga20cde32011-07-20 23:34:39 +0000783 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Evan Cheng10043e22007-01-19 07:51:42 +0000784 if (ShOpcVal != ARM_AM::no_shift) {
785 // Check to see if the RHS of the shift is a constant, if not, we can't
786 // fold it.
787 if (ConstantSDNode *Sh =
788 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +0000789 ShAmt = Sh->getZExtValue();
Cameron Zwarich842f99a2011-10-05 23:39:02 +0000790 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000791 Offset = N.getOperand(0).getOperand(0);
792 Base = N.getOperand(1);
793 } else {
794 ShAmt = 0;
795 ShOpcVal = ARM_AM::no_shift;
796 }
Evan Cheng10043e22007-01-19 07:51:42 +0000797 } else {
798 ShOpcVal = ARM_AM::no_shift;
799 }
800 }
801 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000802
Evan Cheng10043e22007-01-19 07:51:42 +0000803 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson9f944592009-08-11 20:47:22 +0000804 MVT::i32);
Jim Grosbach08605202010-09-29 19:03:54 +0000805 return AM2_SHOP;
Rafael Espindola708cb602006-11-08 17:07:32 +0000806}
807
Owen Anderson2aedba62011-07-26 20:54:26 +0000808bool ARMDAGToDAGISel::SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000809 SDValue &Offset, SDValue &Opc) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000810 unsigned Opcode = Op->getOpcode();
Evan Cheng10043e22007-01-19 07:51:42 +0000811 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
812 ? cast<LoadSDNode>(Op)->getAddressingMode()
813 : cast<StoreSDNode>(Op)->getAddressingMode();
814 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
815 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000816 int Val;
Owen Anderson2aedba62011-07-26 20:54:26 +0000817 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val))
818 return false;
Evan Cheng10043e22007-01-19 07:51:42 +0000819
820 Offset = N;
Evan Chenga20cde32011-07-20 23:34:39 +0000821 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng10043e22007-01-19 07:51:42 +0000822 unsigned ShAmt = 0;
823 if (ShOpcVal != ARM_AM::no_shift) {
824 // Check to see if the RHS of the shift is a constant, if not, we can't fold
825 // it.
826 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +0000827 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +0000828 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
829 Offset = N.getOperand(0);
830 else {
831 ShAmt = 0;
832 ShOpcVal = ARM_AM::no_shift;
833 }
Evan Cheng10043e22007-01-19 07:51:42 +0000834 } else {
835 ShOpcVal = ARM_AM::no_shift;
836 }
837 }
838
839 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson9f944592009-08-11 20:47:22 +0000840 MVT::i32);
Rafael Espindola19398ec2006-10-17 18:04:53 +0000841 return true;
842}
843
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000844bool ARMDAGToDAGISel::SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
845 SDValue &Offset, SDValue &Opc) {
Owen Anderson939cd212011-08-31 20:00:11 +0000846 unsigned Opcode = Op->getOpcode();
847 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
848 ? cast<LoadSDNode>(Op)->getAddressingMode()
849 : cast<StoreSDNode>(Op)->getAddressingMode();
850 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
851 ? ARM_AM::add : ARM_AM::sub;
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000852 int Val;
853 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
Owen Anderson939cd212011-08-31 20:00:11 +0000854 if (AddSub == ARM_AM::sub) Val *= -1;
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000855 Offset = CurDAG->getRegister(0, MVT::i32);
856 Opc = CurDAG->getTargetConstant(Val, MVT::i32);
857 return true;
858 }
859
860 return false;
861}
862
863
Owen Anderson2aedba62011-07-26 20:54:26 +0000864bool ARMDAGToDAGISel::SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
865 SDValue &Offset, SDValue &Opc) {
866 unsigned Opcode = Op->getOpcode();
867 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
868 ? cast<LoadSDNode>(Op)->getAddressingMode()
869 : cast<StoreSDNode>(Op)->getAddressingMode();
870 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
871 ? ARM_AM::add : ARM_AM::sub;
872 int Val;
873 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
874 Offset = CurDAG->getRegister(0, MVT::i32);
875 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
876 ARM_AM::no_shift),
877 MVT::i32);
878 return true;
879 }
880
881 return false;
882}
883
Jim Grosbachf0c95ca2011-08-05 20:35:44 +0000884bool ARMDAGToDAGISel::SelectAddrOffsetNone(SDValue N, SDValue &Base) {
885 Base = N;
886 return true;
887}
Evan Cheng10043e22007-01-19 07:51:42 +0000888
Chris Lattner0e023ea2010-09-21 20:31:19 +0000889bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000890 SDValue &Base, SDValue &Offset,
891 SDValue &Opc) {
Evan Cheng10043e22007-01-19 07:51:42 +0000892 if (N.getOpcode() == ISD::SUB) {
893 // X - C is canonicalize to X + -C, no need to handle it here.
894 Base = N.getOperand(0);
895 Offset = N.getOperand(1);
Owen Anderson9f944592009-08-11 20:47:22 +0000896 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000897 return true;
898 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000899
Chris Lattner46c01a32011-02-13 22:25:43 +0000900 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng10043e22007-01-19 07:51:42 +0000901 Base = N;
902 if (N.getOpcode() == ISD::FrameIndex) {
903 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlingf7719082013-06-06 00:43:09 +0000904 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Evan Cheng10043e22007-01-19 07:51:42 +0000905 }
Owen Anderson9f944592009-08-11 20:47:22 +0000906 Offset = CurDAG->getRegister(0, MVT::i32);
907 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000908 return true;
909 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000910
Evan Cheng10043e22007-01-19 07:51:42 +0000911 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000912 int RHSC;
913 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
914 -256 + 1, 256, RHSC)) { // 8 bits.
915 Base = N.getOperand(0);
916 if (Base.getOpcode() == ISD::FrameIndex) {
917 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlingf7719082013-06-06 00:43:09 +0000918 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Evan Cheng10043e22007-01-19 07:51:42 +0000919 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000920 Offset = CurDAG->getRegister(0, MVT::i32);
921
922 ARM_AM::AddrOpc AddSub = ARM_AM::add;
923 if (RHSC < 0) {
924 AddSub = ARM_AM::sub;
Chris Lattner46c01a32011-02-13 22:25:43 +0000925 RHSC = -RHSC;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000926 }
927 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
928 return true;
Evan Cheng10043e22007-01-19 07:51:42 +0000929 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000930
Evan Cheng10043e22007-01-19 07:51:42 +0000931 Base = N.getOperand(0);
932 Offset = N.getOperand(1);
Owen Anderson9f944592009-08-11 20:47:22 +0000933 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000934 return true;
935}
936
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000937bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000938 SDValue &Offset, SDValue &Opc) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000939 unsigned Opcode = Op->getOpcode();
Evan Cheng10043e22007-01-19 07:51:42 +0000940 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
941 ? cast<LoadSDNode>(Op)->getAddressingMode()
942 : cast<StoreSDNode>(Op)->getAddressingMode();
943 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
944 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000945 int Val;
946 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
947 Offset = CurDAG->getRegister(0, MVT::i32);
948 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
949 return true;
Evan Cheng10043e22007-01-19 07:51:42 +0000950 }
951
952 Offset = N;
Owen Anderson9f944592009-08-11 20:47:22 +0000953 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000954 return true;
955}
956
Jim Grosbachd37f0712010-10-21 19:38:40 +0000957bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000958 SDValue &Base, SDValue &Offset) {
Chris Lattner46c01a32011-02-13 22:25:43 +0000959 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng10043e22007-01-19 07:51:42 +0000960 Base = N;
961 if (N.getOpcode() == ISD::FrameIndex) {
962 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlingf7719082013-06-06 00:43:09 +0000963 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Anton Korobeynikov25229082009-11-24 00:44:37 +0000964 } else if (N.getOpcode() == ARMISD::Wrapper &&
965 !(Subtarget->useMovt() &&
966 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng10043e22007-01-19 07:51:42 +0000967 Base = N.getOperand(0);
968 }
969 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson9f944592009-08-11 20:47:22 +0000970 MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000971 return true;
972 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000973
Evan Cheng10043e22007-01-19 07:51:42 +0000974 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000975 int RHSC;
976 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
977 -256 + 1, 256, RHSC)) {
978 Base = N.getOperand(0);
979 if (Base.getOpcode() == ISD::FrameIndex) {
980 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlingf7719082013-06-06 00:43:09 +0000981 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Evan Cheng10043e22007-01-19 07:51:42 +0000982 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000983
984 ARM_AM::AddrOpc AddSub = ARM_AM::add;
985 if (RHSC < 0) {
986 AddSub = ARM_AM::sub;
Chris Lattner46c01a32011-02-13 22:25:43 +0000987 RHSC = -RHSC;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000988 }
989 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
990 MVT::i32);
991 return true;
Evan Cheng10043e22007-01-19 07:51:42 +0000992 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000993
Evan Cheng10043e22007-01-19 07:51:42 +0000994 Base = N;
995 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson9f944592009-08-11 20:47:22 +0000996 MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000997 return true;
998}
999
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001000bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
1001 SDValue &Align) {
Bob Wilsondeb35af2009-07-01 23:16:05 +00001002 Addr = N;
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001003
1004 unsigned Alignment = 0;
1005 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
1006 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
1007 // The maximum alignment is equal to the memory size being referenced.
1008 unsigned LSNAlign = LSN->getAlignment();
1009 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
Jakob Stoklund Olesene5a6adc2011-10-27 22:39:16 +00001010 if (LSNAlign >= MemSize && MemSize > 1)
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001011 Alignment = MemSize;
1012 } else {
1013 // All other uses of addrmode6 are for intrinsics. For now just record
1014 // the raw alignment value; it will be refined later based on the legal
1015 // alignment operands for the intrinsic.
1016 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
1017 }
1018
1019 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilsondeb35af2009-07-01 23:16:05 +00001020 return true;
1021}
1022
Bob Wilsone3ecd5f2011-02-25 06:42:42 +00001023bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
1024 SDValue &Offset) {
1025 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
1026 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
1027 if (AM != ISD::POST_INC)
1028 return false;
1029 Offset = N;
1030 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
1031 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
1032 Offset = CurDAG->getRegister(0, MVT::i32);
1033 }
1034 return true;
1035}
1036
Chris Lattner0e023ea2010-09-21 20:31:19 +00001037bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Cheng9a58aff2009-08-14 19:01:37 +00001038 SDValue &Offset, SDValue &Label) {
Evan Cheng10043e22007-01-19 07:51:42 +00001039 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
1040 Offset = N.getOperand(0);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001041 SDValue N1 = N.getOperand(1);
Evan Chengb8b0ad82011-01-20 08:34:58 +00001042 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
1043 MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +00001044 return true;
1045 }
Bill Wendling092a7bd2010-12-14 03:36:38 +00001046
Evan Cheng10043e22007-01-19 07:51:42 +00001047 return false;
1048}
1049
Bill Wendling092a7bd2010-12-14 03:36:38 +00001050
1051//===----------------------------------------------------------------------===//
1052// Thumb Addressing Modes
1053//===----------------------------------------------------------------------===//
1054
Chris Lattner0e023ea2010-09-21 20:31:19 +00001055bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001056 SDValue &Base, SDValue &Offset){
Chris Lattner46c01a32011-02-13 22:25:43 +00001057 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng0794c6a2009-07-11 07:08:13 +00001058 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmanf1d83042010-06-18 14:22:04 +00001059 if (!NC || !NC->isNullValue())
Evan Cheng0794c6a2009-07-11 07:08:13 +00001060 return false;
1061
1062 Base = Offset = N;
Evan Chengc0b73662007-01-23 22:59:13 +00001063 return true;
1064 }
1065
Evan Cheng10043e22007-01-19 07:51:42 +00001066 Base = N.getOperand(0);
1067 Offset = N.getOperand(1);
1068 return true;
1069}
1070
Evan Cheng139edae2007-01-24 02:21:22 +00001071bool
Bill Wendling092a7bd2010-12-14 03:36:38 +00001072ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
1073 SDValue &Offset, unsigned Scale) {
Evan Cheng139edae2007-01-24 02:21:22 +00001074 if (Scale == 4) {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001075 SDValue TmpBase, TmpOffImm;
Chris Lattner0e023ea2010-09-21 20:31:19 +00001076 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng139edae2007-01-24 02:21:22 +00001077 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendling092a7bd2010-12-14 03:36:38 +00001078
Evan Cheng1526ba52007-01-24 08:53:17 +00001079 if (N.getOpcode() == ARMISD::Wrapper &&
1080 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1081 return false; // We want to select tLDRpci instead.
Evan Cheng139edae2007-01-24 02:21:22 +00001082 }
1083
Chris Lattner46c01a32011-02-13 22:25:43 +00001084 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendling832a5da2010-12-15 01:03:19 +00001085 return false;
Evan Cheng10043e22007-01-19 07:51:42 +00001086
Evan Cheng650d0672007-02-06 00:22:06 +00001087 // Thumb does not have [sp, r] address mode.
1088 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1089 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1090 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendling832a5da2010-12-15 01:03:19 +00001091 (RHSR && RHSR->getReg() == ARM::SP))
1092 return false;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001093
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001094 // FIXME: Why do we explicitly check for a match here and then return false?
1095 // Presumably to allow something else to match, but shouldn't this be
1096 // documented?
1097 int RHSC;
1098 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
1099 return false;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001100
1101 Base = N.getOperand(0);
1102 Offset = N.getOperand(1);
1103 return true;
1104}
1105
1106bool
1107ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
1108 SDValue &Base,
1109 SDValue &Offset) {
1110 return SelectThumbAddrModeRI(N, Base, Offset, 1);
1111}
1112
1113bool
1114ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
1115 SDValue &Base,
1116 SDValue &Offset) {
1117 return SelectThumbAddrModeRI(N, Base, Offset, 2);
1118}
1119
1120bool
1121ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
1122 SDValue &Base,
1123 SDValue &Offset) {
1124 return SelectThumbAddrModeRI(N, Base, Offset, 4);
1125}
1126
1127bool
1128ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
1129 SDValue &Base, SDValue &OffImm) {
1130 if (Scale == 4) {
1131 SDValue TmpBase, TmpOffImm;
1132 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
1133 return false; // We want to select tLDRspi / tSTRspi instead.
1134
1135 if (N.getOpcode() == ARMISD::Wrapper &&
1136 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1137 return false; // We want to select tLDRpci instead.
1138 }
1139
Chris Lattner46c01a32011-02-13 22:25:43 +00001140 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendling092a7bd2010-12-14 03:36:38 +00001141 if (N.getOpcode() == ARMISD::Wrapper &&
1142 !(Subtarget->useMovt() &&
1143 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
1144 Base = N.getOperand(0);
1145 } else {
1146 Base = N;
1147 }
1148
Owen Anderson9f944592009-08-11 20:47:22 +00001149 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng650d0672007-02-06 00:22:06 +00001150 return true;
1151 }
1152
Bill Wendling832a5da2010-12-15 01:03:19 +00001153 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1154 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1155 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1156 (RHSR && RHSR->getReg() == ARM::SP)) {
1157 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1158 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1159 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1160 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1161
1162 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1163 if (LHSC != 0 || RHSC != 0) return false;
1164
1165 Base = N;
1166 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1167 return true;
1168 }
1169
Evan Cheng10043e22007-01-19 07:51:42 +00001170 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001171 int RHSC;
1172 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1173 Base = N.getOperand(0);
1174 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1175 return true;
Evan Cheng10043e22007-01-19 07:51:42 +00001176 }
1177
Evan Chengc0b73662007-01-23 22:59:13 +00001178 Base = N.getOperand(0);
Owen Anderson9f944592009-08-11 20:47:22 +00001179 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc0b73662007-01-23 22:59:13 +00001180 return true;
Evan Cheng10043e22007-01-19 07:51:42 +00001181}
1182
Bill Wendling092a7bd2010-12-14 03:36:38 +00001183bool
1184ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1185 SDValue &OffImm) {
1186 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +00001187}
1188
Bill Wendling092a7bd2010-12-14 03:36:38 +00001189bool
1190ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1191 SDValue &OffImm) {
1192 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +00001193}
1194
Bill Wendling092a7bd2010-12-14 03:36:38 +00001195bool
1196ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1197 SDValue &OffImm) {
1198 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +00001199}
1200
Chris Lattner0e023ea2010-09-21 20:31:19 +00001201bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1202 SDValue &Base, SDValue &OffImm) {
Evan Cheng10043e22007-01-19 07:51:42 +00001203 if (N.getOpcode() == ISD::FrameIndex) {
1204 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlingf7719082013-06-06 00:43:09 +00001205 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Owen Anderson9f944592009-08-11 20:47:22 +00001206 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +00001207 return true;
1208 }
Evan Cheng139edae2007-01-24 02:21:22 +00001209
Chris Lattner46c01a32011-02-13 22:25:43 +00001210 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Cheng650d0672007-02-06 00:22:06 +00001211 return false;
1212
1213 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Chenga9740312007-02-06 09:11:20 +00001214 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1215 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng139edae2007-01-24 02:21:22 +00001216 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001217 int RHSC;
1218 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1219 Base = N.getOperand(0);
1220 if (Base.getOpcode() == ISD::FrameIndex) {
1221 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlingf7719082013-06-06 00:43:09 +00001222 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Evan Cheng139edae2007-01-24 02:21:22 +00001223 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001224 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1225 return true;
Evan Cheng139edae2007-01-24 02:21:22 +00001226 }
1227 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001228
Evan Cheng10043e22007-01-19 07:51:42 +00001229 return false;
1230}
1231
Bill Wendling092a7bd2010-12-14 03:36:38 +00001232
1233//===----------------------------------------------------------------------===//
1234// Thumb 2 Addressing Modes
1235//===----------------------------------------------------------------------===//
1236
1237
Chris Lattner0e023ea2010-09-21 20:31:19 +00001238bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Chengeab9ca72009-06-27 02:26:13 +00001239 SDValue &Opc) {
Evan Cheng59069ec2010-07-30 23:33:54 +00001240 if (DisableShifterOp)
1241 return false;
1242
Evan Chenga20cde32011-07-20 23:34:39 +00001243 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chengeab9ca72009-06-27 02:26:13 +00001244
1245 // Don't match base register only case. That is matched to a separate
1246 // lower complexity pattern with explicit register operand.
1247 if (ShOpcVal == ARM_AM::no_shift) return false;
1248
1249 BaseReg = N.getOperand(0);
1250 unsigned ShImmVal = 0;
1251 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1252 ShImmVal = RHS->getZExtValue() & 31;
1253 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1254 return true;
1255 }
1256
1257 return false;
1258}
1259
Chris Lattner0e023ea2010-09-21 20:31:19 +00001260bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +00001261 SDValue &Base, SDValue &OffImm) {
1262 // Match simple R + imm12 operands.
David Goodwin802a0b52009-07-20 15:55:39 +00001263
Evan Cheng36064672009-08-11 08:52:18 +00001264 // Base only.
Chris Lattner46c01a32011-02-13 22:25:43 +00001265 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1266 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin802a0b52009-07-20 15:55:39 +00001267 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner46c01a32011-02-13 22:25:43 +00001268 // Match frame index.
David Goodwin802a0b52009-07-20 15:55:39 +00001269 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlingf7719082013-06-06 00:43:09 +00001270 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Owen Anderson9f944592009-08-11 20:47:22 +00001271 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin802a0b52009-07-20 15:55:39 +00001272 return true;
Chris Lattner46c01a32011-02-13 22:25:43 +00001273 }
Owen Anderson6d557452011-03-18 19:46:58 +00001274
Chris Lattner46c01a32011-02-13 22:25:43 +00001275 if (N.getOpcode() == ARMISD::Wrapper &&
Anton Korobeynikov25229082009-11-24 00:44:37 +00001276 !(Subtarget->useMovt() &&
1277 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng36064672009-08-11 08:52:18 +00001278 Base = N.getOperand(0);
1279 if (Base.getOpcode() == ISD::TargetConstantPool)
1280 return false; // We want to select t2LDRpci instead.
1281 } else
1282 Base = N;
Owen Anderson9f944592009-08-11 20:47:22 +00001283 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng36064672009-08-11 08:52:18 +00001284 return true;
David Goodwin802a0b52009-07-20 15:55:39 +00001285 }
Evan Chengb23b50d2009-06-29 07:51:04 +00001286
1287 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner0e023ea2010-09-21 20:31:19 +00001288 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng36064672009-08-11 08:52:18 +00001289 // Let t2LDRi8 handle (R - imm8).
1290 return false;
1291
Evan Chengb23b50d2009-06-29 07:51:04 +00001292 int RHSC = (int)RHS->getZExtValue();
David Goodwin79c079b2009-07-30 18:56:48 +00001293 if (N.getOpcode() == ISD::SUB)
1294 RHSC = -RHSC;
1295
1296 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Chengb23b50d2009-06-29 07:51:04 +00001297 Base = N.getOperand(0);
David Goodwin79c079b2009-07-30 18:56:48 +00001298 if (Base.getOpcode() == ISD::FrameIndex) {
1299 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlingf7719082013-06-06 00:43:09 +00001300 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
David Goodwin79c079b2009-07-30 18:56:48 +00001301 }
Owen Anderson9f944592009-08-11 20:47:22 +00001302 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chengb23b50d2009-06-29 07:51:04 +00001303 return true;
1304 }
1305 }
1306
Evan Cheng36064672009-08-11 08:52:18 +00001307 // Base only.
1308 Base = N;
Owen Anderson9f944592009-08-11 20:47:22 +00001309 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng36064672009-08-11 08:52:18 +00001310 return true;
Evan Chengb23b50d2009-06-29 07:51:04 +00001311}
1312
Chris Lattner0e023ea2010-09-21 20:31:19 +00001313bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +00001314 SDValue &Base, SDValue &OffImm) {
David Goodwin79c079b2009-07-30 18:56:48 +00001315 // Match simple R - imm8 operands.
Chris Lattner46c01a32011-02-13 22:25:43 +00001316 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1317 !CurDAG->isBaseWithConstantOffset(N))
1318 return false;
Owen Anderson6d557452011-03-18 19:46:58 +00001319
Chris Lattner46c01a32011-02-13 22:25:43 +00001320 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1321 int RHSC = (int)RHS->getSExtValue();
1322 if (N.getOpcode() == ISD::SUB)
1323 RHSC = -RHSC;
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001324
Chris Lattner46c01a32011-02-13 22:25:43 +00001325 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1326 Base = N.getOperand(0);
1327 if (Base.getOpcode() == ISD::FrameIndex) {
1328 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlingf7719082013-06-06 00:43:09 +00001329 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Evan Chengb23b50d2009-06-29 07:51:04 +00001330 }
Chris Lattner46c01a32011-02-13 22:25:43 +00001331 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1332 return true;
Evan Chengb23b50d2009-06-29 07:51:04 +00001333 }
1334 }
1335
1336 return false;
1337}
1338
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001339bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Cheng84c6cda2009-07-02 07:28:31 +00001340 SDValue &OffImm){
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001341 unsigned Opcode = Op->getOpcode();
Evan Cheng84c6cda2009-07-02 07:28:31 +00001342 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1343 ? cast<LoadSDNode>(Op)->getAddressingMode()
1344 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001345 int RHSC;
1346 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1347 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1348 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1349 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1350 return true;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001351 }
1352
1353 return false;
1354}
1355
Chris Lattner0e023ea2010-09-21 20:31:19 +00001356bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +00001357 SDValue &Base,
1358 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng36064672009-08-11 08:52:18 +00001359 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner46c01a32011-02-13 22:25:43 +00001360 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng36064672009-08-11 08:52:18 +00001361 return false;
Evan Chengb23b50d2009-06-29 07:51:04 +00001362
Evan Cheng36064672009-08-11 08:52:18 +00001363 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1364 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1365 int RHSC = (int)RHS->getZExtValue();
1366 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1367 return false;
1368 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwin79c079b2009-07-30 18:56:48 +00001369 return false;
1370 }
1371
Evan Chengb23b50d2009-06-29 07:51:04 +00001372 // Look for (R + R) or (R + (R << [1,2,3])).
1373 unsigned ShAmt = 0;
1374 Base = N.getOperand(0);
1375 OffReg = N.getOperand(1);
1376
1377 // Swap if it is ((R << c) + R).
Evan Chenga20cde32011-07-20 23:34:39 +00001378 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg.getOpcode());
Evan Chengb23b50d2009-06-29 07:51:04 +00001379 if (ShOpcVal != ARM_AM::lsl) {
Evan Chenga20cde32011-07-20 23:34:39 +00001380 ShOpcVal = ARM_AM::getShiftOpcForNode(Base.getOpcode());
Evan Chengb23b50d2009-06-29 07:51:04 +00001381 if (ShOpcVal == ARM_AM::lsl)
1382 std::swap(Base, OffReg);
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001383 }
1384
Evan Chengb23b50d2009-06-29 07:51:04 +00001385 if (ShOpcVal == ARM_AM::lsl) {
1386 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1387 // it.
1388 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1389 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +00001390 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1391 OffReg = OffReg.getOperand(0);
1392 else {
Evan Chengb23b50d2009-06-29 07:51:04 +00001393 ShAmt = 0;
1394 ShOpcVal = ARM_AM::no_shift;
Evan Cheng59bbc542010-10-27 23:41:30 +00001395 }
Evan Chengb23b50d2009-06-29 07:51:04 +00001396 } else {
1397 ShOpcVal = ARM_AM::no_shift;
1398 }
David Goodwinf3912052009-07-15 15:50:19 +00001399 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001400
Owen Anderson9f944592009-08-11 20:47:22 +00001401 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Chengb23b50d2009-06-29 07:51:04 +00001402
1403 return true;
1404}
1405
1406//===--------------------------------------------------------------------===//
1407
Evan Cheng7e90b112007-07-05 07:15:27 +00001408/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001409static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson9f944592009-08-11 20:47:22 +00001410 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng0f7cbe82007-05-15 01:29:07 +00001411}
1412
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001413SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1414 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengd9c55362009-07-02 01:23:32 +00001415 ISD::MemIndexedMode AM = LD->getAddressingMode();
1416 if (AM == ISD::UNINDEXED)
1417 return NULL;
1418
Owen Anderson53aa7a92009-08-10 22:56:29 +00001419 EVT LoadedVT = LD->getMemoryVT();
Evan Chengd9c55362009-07-02 01:23:32 +00001420 SDValue Offset, AMOpc;
1421 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1422 unsigned Opcode = 0;
1423 bool Match = false;
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001424 if (LoadedVT == MVT::i32 && isPre &&
1425 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
1426 Opcode = ARM::LDR_PRE_IMM;
1427 Match = true;
1428 } else if (LoadedVT == MVT::i32 && !isPre &&
Owen Anderson2aedba62011-07-26 20:54:26 +00001429 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001430 Opcode = ARM::LDR_POST_IMM;
Evan Chengd9c55362009-07-02 01:23:32 +00001431 Match = true;
Owen Anderson2aedba62011-07-26 20:54:26 +00001432 } else if (LoadedVT == MVT::i32 &&
1433 SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson16d33f32011-08-26 20:43:14 +00001434 Opcode = isPre ? ARM::LDR_PRE_REG : ARM::LDR_POST_REG;
Owen Anderson2aedba62011-07-26 20:54:26 +00001435 Match = true;
1436
Owen Anderson9f944592009-08-11 20:47:22 +00001437 } else if (LoadedVT == MVT::i16 &&
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001438 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengd9c55362009-07-02 01:23:32 +00001439 Match = true;
1440 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1441 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1442 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson9f944592009-08-11 20:47:22 +00001443 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengd9c55362009-07-02 01:23:32 +00001444 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001445 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengd9c55362009-07-02 01:23:32 +00001446 Match = true;
1447 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1448 }
1449 } else {
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001450 if (isPre &&
1451 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengd9c55362009-07-02 01:23:32 +00001452 Match = true;
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001453 Opcode = ARM::LDRB_PRE_IMM;
1454 } else if (!isPre &&
1455 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
1456 Match = true;
1457 Opcode = ARM::LDRB_POST_IMM;
Owen Anderson2aedba62011-07-26 20:54:26 +00001458 } else if (SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
1459 Match = true;
Owen Anderson16d33f32011-08-26 20:43:14 +00001460 Opcode = isPre ? ARM::LDRB_PRE_REG : ARM::LDRB_POST_REG;
Evan Chengd9c55362009-07-02 01:23:32 +00001461 }
1462 }
1463 }
1464
1465 if (Match) {
Owen Andersonfd60f602011-08-26 21:12:37 +00001466 if (Opcode == ARM::LDR_PRE_IMM || Opcode == ARM::LDRB_PRE_IMM) {
1467 SDValue Chain = LD->getChain();
1468 SDValue Base = LD->getBasePtr();
1469 SDValue Ops[]= { Base, AMOpc, getAL(CurDAG),
1470 CurDAG->getRegister(0, MVT::i32), Chain };
Andrew Trickef9de2a2013-05-25 02:42:55 +00001471 return CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i32,
Michael Liaob53d8962013-04-19 22:22:57 +00001472 MVT::i32, MVT::Other, Ops);
Owen Andersonfd60f602011-08-26 21:12:37 +00001473 } else {
1474 SDValue Chain = LD->getChain();
1475 SDValue Base = LD->getBasePtr();
1476 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
1477 CurDAG->getRegister(0, MVT::i32), Chain };
Andrew Trickef9de2a2013-05-25 02:42:55 +00001478 return CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i32,
Michael Liaob53d8962013-04-19 22:22:57 +00001479 MVT::i32, MVT::Other, Ops);
Owen Andersonfd60f602011-08-26 21:12:37 +00001480 }
Evan Chengd9c55362009-07-02 01:23:32 +00001481 }
1482
1483 return NULL;
1484}
1485
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001486SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1487 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Cheng84c6cda2009-07-02 07:28:31 +00001488 ISD::MemIndexedMode AM = LD->getAddressingMode();
1489 if (AM == ISD::UNINDEXED)
1490 return NULL;
1491
Owen Anderson53aa7a92009-08-10 22:56:29 +00001492 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng8ecd7eb2009-07-02 23:16:11 +00001493 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001494 SDValue Offset;
1495 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1496 unsigned Opcode = 0;
1497 bool Match = false;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001498 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson9f944592009-08-11 20:47:22 +00001499 switch (LoadedVT.getSimpleVT().SimpleTy) {
1500 case MVT::i32:
Evan Cheng84c6cda2009-07-02 07:28:31 +00001501 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1502 break;
Owen Anderson9f944592009-08-11 20:47:22 +00001503 case MVT::i16:
Evan Cheng8ecd7eb2009-07-02 23:16:11 +00001504 if (isSExtLd)
1505 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1506 else
1507 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001508 break;
Owen Anderson9f944592009-08-11 20:47:22 +00001509 case MVT::i8:
1510 case MVT::i1:
Evan Cheng8ecd7eb2009-07-02 23:16:11 +00001511 if (isSExtLd)
1512 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1513 else
1514 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001515 break;
1516 default:
1517 return NULL;
1518 }
1519 Match = true;
1520 }
1521
1522 if (Match) {
1523 SDValue Chain = LD->getChain();
1524 SDValue Base = LD->getBasePtr();
1525 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson9f944592009-08-11 20:47:22 +00001526 CurDAG->getRegister(0, MVT::i32), Chain };
Andrew Trickef9de2a2013-05-25 02:42:55 +00001527 return CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i32, MVT::i32,
Michael Liaob53d8962013-04-19 22:22:57 +00001528 MVT::Other, Ops);
Evan Cheng84c6cda2009-07-02 07:28:31 +00001529 }
1530
1531 return NULL;
1532}
1533
Weiming Zhao8f56f882012-11-16 21:55:34 +00001534/// \brief Form a GPRPair pseudo register from a pair of GPR regs.
1535SDNode *ARMDAGToDAGISel::createGPRPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001536 SDLoc dl(V0.getNode());
Weiming Zhao8f56f882012-11-16 21:55:34 +00001537 SDValue RegClass =
1538 CurDAG->getTargetConstant(ARM::GPRPairRegClassID, MVT::i32);
1539 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::gsub_0, MVT::i32);
1540 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::gsub_1, MVT::i32);
1541 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001542 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Weiming Zhao8f56f882012-11-16 21:55:34 +00001543}
1544
Weiming Zhao95782222012-11-17 00:23:35 +00001545/// \brief Form a D register from a pair of S registers.
1546SDNode *ARMDAGToDAGISel::createSRegPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001547 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001548 SDValue RegClass =
1549 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, MVT::i32);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001550 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1551 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001552 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001553 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001554}
1555
Weiming Zhao95782222012-11-17 00:23:35 +00001556/// \brief Form a quad register from a pair of D registers.
1557SDNode *ARMDAGToDAGISel::createDRegPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001558 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001559 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, MVT::i32);
Jakob Stoklund Olesen6c47d642010-05-24 16:54:32 +00001560 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1561 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001562 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001563 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Bob Wilsone6b778d2009-10-06 22:01:59 +00001564}
1565
Weiming Zhao95782222012-11-17 00:23:35 +00001566/// \brief Form 4 consecutive D registers from a pair of Q registers.
1567SDNode *ARMDAGToDAGISel::createQRegPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001568 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001569 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen6c47d642010-05-24 16:54:32 +00001570 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1571 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001572 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001573 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Evan Chengc2ae5f52010-05-10 17:34:18 +00001574}
1575
Weiming Zhao95782222012-11-17 00:23:35 +00001576/// \brief Form 4 consecutive S registers.
1577SDNode *ARMDAGToDAGISel::createQuadSRegsNode(EVT VT, SDValue V0, SDValue V1,
Bob Wilsond8a9a042010-06-04 00:04:02 +00001578 SDValue V2, SDValue V3) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001579 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001580 SDValue RegClass =
1581 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, MVT::i32);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001582 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1583 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1584 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1585 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001586 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1587 V2, SubReg2, V3, SubReg3 };
Michael Liaob53d8962013-04-19 22:22:57 +00001588 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001589}
1590
Weiming Zhao95782222012-11-17 00:23:35 +00001591/// \brief Form 4 consecutive D registers.
1592SDNode *ARMDAGToDAGISel::createQuadDRegsNode(EVT VT, SDValue V0, SDValue V1,
Evan Chengc2ae5f52010-05-10 17:34:18 +00001593 SDValue V2, SDValue V3) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001594 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001595 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen6c47d642010-05-24 16:54:32 +00001596 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1597 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1598 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1599 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001600 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1601 V2, SubReg2, V3, SubReg3 };
Michael Liaob53d8962013-04-19 22:22:57 +00001602 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Evan Chengc2ae5f52010-05-10 17:34:18 +00001603}
1604
Weiming Zhao95782222012-11-17 00:23:35 +00001605/// \brief Form 4 consecutive Q registers.
1606SDNode *ARMDAGToDAGISel::createQuadQRegsNode(EVT VT, SDValue V0, SDValue V1,
Evan Cheng298e6b82010-05-16 03:27:48 +00001607 SDValue V2, SDValue V3) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001608 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001609 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen6c47d642010-05-24 16:54:32 +00001610 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1611 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1612 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1613 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001614 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1615 V2, SubReg2, V3, SubReg3 };
Michael Liaob53d8962013-04-19 22:22:57 +00001616 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Evan Cheng298e6b82010-05-16 03:27:48 +00001617}
1618
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001619/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1620/// of a NEON VLD or VST instruction. The supported values depend on the
1621/// number of registers being loaded.
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001622SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1623 bool is64BitVector) {
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001624 unsigned NumRegs = NumVecs;
1625 if (!is64BitVector && NumVecs < 3)
1626 NumRegs *= 2;
1627
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001628 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001629 if (Alignment >= 32 && NumRegs == 4)
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001630 Alignment = 32;
1631 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1632 Alignment = 16;
1633 else if (Alignment >= 8)
1634 Alignment = 8;
1635 else
1636 Alignment = 0;
1637
1638 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001639}
1640
Jim Grosbach2098cb12011-10-24 21:45:13 +00001641// Get the register stride update opcode of a VLD/VST instruction that
1642// is otherwise equivalent to the given fixed stride updating instruction.
1643static unsigned getVLDSTRegisterUpdateOpcode(unsigned Opc) {
1644 switch (Opc) {
1645 default: break;
1646 case ARM::VLD1d8wb_fixed: return ARM::VLD1d8wb_register;
1647 case ARM::VLD1d16wb_fixed: return ARM::VLD1d16wb_register;
1648 case ARM::VLD1d32wb_fixed: return ARM::VLD1d32wb_register;
1649 case ARM::VLD1d64wb_fixed: return ARM::VLD1d64wb_register;
1650 case ARM::VLD1q8wb_fixed: return ARM::VLD1q8wb_register;
1651 case ARM::VLD1q16wb_fixed: return ARM::VLD1q16wb_register;
1652 case ARM::VLD1q32wb_fixed: return ARM::VLD1q32wb_register;
1653 case ARM::VLD1q64wb_fixed: return ARM::VLD1q64wb_register;
Jim Grosbach05df4602011-10-31 21:50:31 +00001654
1655 case ARM::VST1d8wb_fixed: return ARM::VST1d8wb_register;
1656 case ARM::VST1d16wb_fixed: return ARM::VST1d16wb_register;
1657 case ARM::VST1d32wb_fixed: return ARM::VST1d32wb_register;
1658 case ARM::VST1d64wb_fixed: return ARM::VST1d64wb_register;
1659 case ARM::VST1q8wb_fixed: return ARM::VST1q8wb_register;
1660 case ARM::VST1q16wb_fixed: return ARM::VST1q16wb_register;
1661 case ARM::VST1q32wb_fixed: return ARM::VST1q32wb_register;
1662 case ARM::VST1q64wb_fixed: return ARM::VST1q64wb_register;
Jim Grosbach98d032f2011-11-29 22:38:04 +00001663 case ARM::VST1d64TPseudoWB_fixed: return ARM::VST1d64TPseudoWB_register;
Jim Grosbach5ee209c2011-11-29 22:58:48 +00001664 case ARM::VST1d64QPseudoWB_fixed: return ARM::VST1d64QPseudoWB_register;
Jim Grosbachd146a022011-12-09 21:28:25 +00001665
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001666 case ARM::VLD2d8wb_fixed: return ARM::VLD2d8wb_register;
1667 case ARM::VLD2d16wb_fixed: return ARM::VLD2d16wb_register;
1668 case ARM::VLD2d32wb_fixed: return ARM::VLD2d32wb_register;
Jim Grosbachd146a022011-12-09 21:28:25 +00001669 case ARM::VLD2q8PseudoWB_fixed: return ARM::VLD2q8PseudoWB_register;
1670 case ARM::VLD2q16PseudoWB_fixed: return ARM::VLD2q16PseudoWB_register;
1671 case ARM::VLD2q32PseudoWB_fixed: return ARM::VLD2q32PseudoWB_register;
1672
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001673 case ARM::VST2d8wb_fixed: return ARM::VST2d8wb_register;
1674 case ARM::VST2d16wb_fixed: return ARM::VST2d16wb_register;
1675 case ARM::VST2d32wb_fixed: return ARM::VST2d32wb_register;
Jim Grosbach88ac7612011-12-14 21:32:11 +00001676 case ARM::VST2q8PseudoWB_fixed: return ARM::VST2q8PseudoWB_register;
1677 case ARM::VST2q16PseudoWB_fixed: return ARM::VST2q16PseudoWB_register;
1678 case ARM::VST2q32PseudoWB_fixed: return ARM::VST2q32PseudoWB_register;
Jim Grosbachc80a2642011-12-21 19:40:55 +00001679
Jim Grosbach13a292c2012-03-06 22:01:44 +00001680 case ARM::VLD2DUPd8wb_fixed: return ARM::VLD2DUPd8wb_register;
1681 case ARM::VLD2DUPd16wb_fixed: return ARM::VLD2DUPd16wb_register;
1682 case ARM::VLD2DUPd32wb_fixed: return ARM::VLD2DUPd32wb_register;
Jim Grosbach2098cb12011-10-24 21:45:13 +00001683 }
1684 return Opc; // If not one we handle, return it unchanged.
1685}
1686
Bob Wilson06fce872011-02-07 17:43:21 +00001687SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +00001688 const uint16_t *DOpcodes,
1689 const uint16_t *QOpcodes0,
1690 const uint16_t *QOpcodes1) {
Bob Wilson340861d2010-03-23 05:25:43 +00001691 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00001692 SDLoc dl(N);
Bob Wilson12b47992009-10-14 17:28:52 +00001693
Bob Wilsonae08a732010-03-20 22:13:40 +00001694 SDValue MemAddr, Align;
Bob Wilson06fce872011-02-07 17:43:21 +00001695 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1696 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson12b47992009-10-14 17:28:52 +00001697 return NULL;
1698
1699 SDValue Chain = N->getOperand(0);
1700 EVT VT = N->getValueType(0);
1701 bool is64BitVector = VT.is64BitVector();
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001702 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson9eeb8902010-09-23 21:43:54 +00001703
Bob Wilson12b47992009-10-14 17:28:52 +00001704 unsigned OpcodeIndex;
1705 switch (VT.getSimpleVT().SimpleTy) {
1706 default: llvm_unreachable("unhandled vld type");
1707 // Double-register operations:
1708 case MVT::v8i8: OpcodeIndex = 0; break;
1709 case MVT::v4i16: OpcodeIndex = 1; break;
1710 case MVT::v2f32:
1711 case MVT::v2i32: OpcodeIndex = 2; break;
1712 case MVT::v1i64: OpcodeIndex = 3; break;
1713 // Quad-register operations:
1714 case MVT::v16i8: OpcodeIndex = 0; break;
1715 case MVT::v8i16: OpcodeIndex = 1; break;
1716 case MVT::v4f32:
1717 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson340861d2010-03-23 05:25:43 +00001718 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00001719 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson340861d2010-03-23 05:25:43 +00001720 break;
Bob Wilson12b47992009-10-14 17:28:52 +00001721 }
1722
Bob Wilson35fafca2010-09-03 18:16:02 +00001723 EVT ResTy;
1724 if (NumVecs == 1)
1725 ResTy = VT;
1726 else {
1727 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1728 if (!is64BitVector)
1729 ResTyElts *= 2;
1730 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1731 }
Bob Wilson06fce872011-02-07 17:43:21 +00001732 std::vector<EVT> ResTys;
1733 ResTys.push_back(ResTy);
1734 if (isUpdating)
1735 ResTys.push_back(MVT::i32);
1736 ResTys.push_back(MVT::Other);
Bob Wilson35fafca2010-09-03 18:16:02 +00001737
Evan Cheng3da64f762010-04-16 05:46:06 +00001738 SDValue Pred = getAL(CurDAG);
Bob Wilsonae08a732010-03-20 22:13:40 +00001739 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson06fce872011-02-07 17:43:21 +00001740 SDNode *VLd;
1741 SmallVector<SDValue, 7> Ops;
Evan Cheng630063a2010-05-10 21:26:24 +00001742
Bob Wilson06fce872011-02-07 17:43:21 +00001743 // Double registers and VLD1/VLD2 quad registers are directly supported.
1744 if (is64BitVector || NumVecs <= 2) {
1745 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1746 QOpcodes0[OpcodeIndex]);
1747 Ops.push_back(MemAddr);
1748 Ops.push_back(Align);
1749 if (isUpdating) {
1750 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbachd146a022011-12-09 21:28:25 +00001751 // FIXME: VLD1/VLD2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach2098cb12011-10-24 21:45:13 +00001752 // case entirely when the rest are updated to that form, too.
Jim Grosbachd146a022011-12-09 21:28:25 +00001753 if ((NumVecs == 1 || NumVecs == 2) && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach2098cb12011-10-24 21:45:13 +00001754 Opc = getVLDSTRegisterUpdateOpcode(Opc);
Jim Grosbachd146a022011-12-09 21:28:25 +00001755 // We use a VLD1 for v1i64 even if the pseudo says vld2/3/4, so
Jim Grosbach05df4602011-10-31 21:50:31 +00001756 // check for that explicitly too. Horribly hacky, but temporary.
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001757 if ((NumVecs != 1 && NumVecs != 2 && Opc != ARM::VLD1q64wb_fixed) ||
Jim Grosbach05df4602011-10-31 21:50:31 +00001758 !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach2098cb12011-10-24 21:45:13 +00001759 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Cheng630063a2010-05-10 21:26:24 +00001760 }
Bob Wilson06fce872011-02-07 17:43:21 +00001761 Ops.push_back(Pred);
1762 Ops.push_back(Reg0);
1763 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00001764 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Bob Wilson75a64082010-09-02 16:00:54 +00001765
Bob Wilson12b47992009-10-14 17:28:52 +00001766 } else {
1767 // Otherwise, quad registers are loaded with two separate instructions,
1768 // where one loads the even registers and the other loads the odd registers.
Bob Wilson35fafca2010-09-03 18:16:02 +00001769 EVT AddrTy = MemAddr.getValueType();
Bob Wilson12b47992009-10-14 17:28:52 +00001770
Bob Wilson06fce872011-02-07 17:43:21 +00001771 // Load the even subregs. This is always an updating load, so that it
1772 // provides the address to the second load for the odd subregs.
Bob Wilson35fafca2010-09-03 18:16:02 +00001773 SDValue ImplDef =
1774 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1775 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilsona609b892011-02-07 17:43:15 +00001776 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
Michael Liaob53d8962013-04-19 22:22:57 +00001777 ResTy, AddrTy, MVT::Other, OpsA);
Bob Wilson35fafca2010-09-03 18:16:02 +00001778 Chain = SDValue(VLdA, 2);
Bob Wilson12b47992009-10-14 17:28:52 +00001779
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001780 // Load the odd subregs.
Bob Wilson06fce872011-02-07 17:43:21 +00001781 Ops.push_back(SDValue(VLdA, 1));
1782 Ops.push_back(Align);
1783 if (isUpdating) {
1784 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1785 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1786 "only constant post-increment update allowed for VLD3/4");
1787 (void)Inc;
1788 Ops.push_back(Reg0);
1789 }
1790 Ops.push_back(SDValue(VLdA, 0));
1791 Ops.push_back(Pred);
1792 Ops.push_back(Reg0);
1793 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00001794 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys, Ops);
Bob Wilson35fafca2010-09-03 18:16:02 +00001795 }
Bob Wilson12b47992009-10-14 17:28:52 +00001796
Evan Cheng40791332011-04-19 00:04:03 +00001797 // Transfer memoperands.
1798 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1799 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1800 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1801
Bob Wilson06fce872011-02-07 17:43:21 +00001802 if (NumVecs == 1)
1803 return VLd;
1804
1805 // Extract out the subregisters.
1806 SDValue SuperReg = SDValue(VLd, 0);
1807 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1808 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1809 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1810 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1811 ReplaceUses(SDValue(N, Vec),
1812 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1813 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1814 if (isUpdating)
1815 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson12b47992009-10-14 17:28:52 +00001816 return NULL;
1817}
1818
Bob Wilson06fce872011-02-07 17:43:21 +00001819SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +00001820 const uint16_t *DOpcodes,
1821 const uint16_t *QOpcodes0,
1822 const uint16_t *QOpcodes1) {
Bob Wilson3ed511b2010-07-06 23:36:25 +00001823 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00001824 SDLoc dl(N);
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001825
Bob Wilsonae08a732010-03-20 22:13:40 +00001826 SDValue MemAddr, Align;
Bob Wilson06fce872011-02-07 17:43:21 +00001827 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1828 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1829 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001830 return NULL;
1831
Evan Cheng40791332011-04-19 00:04:03 +00001832 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1833 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1834
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001835 SDValue Chain = N->getOperand(0);
Bob Wilson06fce872011-02-07 17:43:21 +00001836 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001837 bool is64BitVector = VT.is64BitVector();
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001838 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001839
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001840 unsigned OpcodeIndex;
1841 switch (VT.getSimpleVT().SimpleTy) {
1842 default: llvm_unreachable("unhandled vst type");
1843 // Double-register operations:
1844 case MVT::v8i8: OpcodeIndex = 0; break;
1845 case MVT::v4i16: OpcodeIndex = 1; break;
1846 case MVT::v2f32:
1847 case MVT::v2i32: OpcodeIndex = 2; break;
1848 case MVT::v1i64: OpcodeIndex = 3; break;
1849 // Quad-register operations:
1850 case MVT::v16i8: OpcodeIndex = 0; break;
1851 case MVT::v8i16: OpcodeIndex = 1; break;
1852 case MVT::v4f32:
1853 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00001854 case MVT::v2i64: OpcodeIndex = 3;
1855 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1856 break;
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001857 }
1858
Bob Wilson06fce872011-02-07 17:43:21 +00001859 std::vector<EVT> ResTys;
1860 if (isUpdating)
1861 ResTys.push_back(MVT::i32);
1862 ResTys.push_back(MVT::Other);
1863
Evan Cheng3da64f762010-04-16 05:46:06 +00001864 SDValue Pred = getAL(CurDAG);
Bob Wilsonae08a732010-03-20 22:13:40 +00001865 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson06fce872011-02-07 17:43:21 +00001866 SmallVector<SDValue, 7> Ops;
Evan Chenga33fc862009-11-21 06:21:52 +00001867
Bob Wilson06fce872011-02-07 17:43:21 +00001868 // Double registers and VST1/VST2 quad registers are directly supported.
1869 if (is64BitVector || NumVecs <= 2) {
Bob Wilsona609b892011-02-07 17:43:15 +00001870 SDValue SrcReg;
Bob Wilson950882b2010-08-28 05:12:57 +00001871 if (NumVecs == 1) {
Bob Wilson06fce872011-02-07 17:43:21 +00001872 SrcReg = N->getOperand(Vec0Idx);
1873 } else if (is64BitVector) {
Evan Chenge276c182010-05-11 01:19:40 +00001874 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson06fce872011-02-07 17:43:21 +00001875 SDValue V0 = N->getOperand(Vec0Idx + 0);
1876 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Chenge276c182010-05-11 01:19:40 +00001877 if (NumVecs == 2)
Weiming Zhao95782222012-11-17 00:23:35 +00001878 SrcReg = SDValue(createDRegPairNode(MVT::v2i64, V0, V1), 0);
Evan Chenge276c182010-05-11 01:19:40 +00001879 else {
Bob Wilson06fce872011-02-07 17:43:21 +00001880 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsona609b892011-02-07 17:43:15 +00001881 // If it's a vst3, form a quad D-register and leave the last part as
Evan Chenge276c182010-05-11 01:19:40 +00001882 // an undef.
1883 SDValue V3 = (NumVecs == 3)
1884 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson06fce872011-02-07 17:43:21 +00001885 : N->getOperand(Vec0Idx + 3);
Weiming Zhao95782222012-11-17 00:23:35 +00001886 SrcReg = SDValue(createQuadDRegsNode(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Chenge276c182010-05-11 01:19:40 +00001887 }
Bob Wilson950882b2010-08-28 05:12:57 +00001888 } else {
1889 // Form a QQ register.
Bob Wilson06fce872011-02-07 17:43:21 +00001890 SDValue Q0 = N->getOperand(Vec0Idx);
1891 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Weiming Zhao95782222012-11-17 00:23:35 +00001892 SrcReg = SDValue(createQRegPairNode(MVT::v4i64, Q0, Q1), 0);
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001893 }
Bob Wilson06fce872011-02-07 17:43:21 +00001894
1895 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1896 QOpcodes0[OpcodeIndex]);
1897 Ops.push_back(MemAddr);
1898 Ops.push_back(Align);
1899 if (isUpdating) {
1900 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbach88ac7612011-12-14 21:32:11 +00001901 // FIXME: VST1/VST2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach05df4602011-10-31 21:50:31 +00001902 // case entirely when the rest are updated to that form, too.
Jim Grosbach88ac7612011-12-14 21:32:11 +00001903 if (NumVecs <= 2 && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach05df4602011-10-31 21:50:31 +00001904 Opc = getVLDSTRegisterUpdateOpcode(Opc);
1905 // We use a VST1 for v1i64 even if the pseudo says vld2/3/4, so
1906 // check for that explicitly too. Horribly hacky, but temporary.
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001907 if ((NumVecs > 2 && Opc != ARM::VST1q64wb_fixed) ||
Jim Grosbach05df4602011-10-31 21:50:31 +00001908 !isa<ConstantSDNode>(Inc.getNode()))
1909 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Bob Wilson06fce872011-02-07 17:43:21 +00001910 }
1911 Ops.push_back(SrcReg);
1912 Ops.push_back(Pred);
1913 Ops.push_back(Reg0);
1914 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00001915 SDNode *VSt = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Evan Cheng40791332011-04-19 00:04:03 +00001916
1917 // Transfer memoperands.
1918 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
1919
1920 return VSt;
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001921 }
1922
1923 // Otherwise, quad registers are stored with two separate instructions,
1924 // where one stores the even registers and the other stores the odd registers.
Evan Cheng9e688cb2010-05-15 07:53:37 +00001925
Bob Wilson01ac8f92010-06-16 21:34:01 +00001926 // Form the QQQQ REG_SEQUENCE.
Bob Wilson06fce872011-02-07 17:43:21 +00001927 SDValue V0 = N->getOperand(Vec0Idx + 0);
1928 SDValue V1 = N->getOperand(Vec0Idx + 1);
1929 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson950882b2010-08-28 05:12:57 +00001930 SDValue V3 = (NumVecs == 3)
1931 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson06fce872011-02-07 17:43:21 +00001932 : N->getOperand(Vec0Idx + 3);
Weiming Zhao95782222012-11-17 00:23:35 +00001933 SDValue RegSeq = SDValue(createQuadQRegsNode(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson01ac8f92010-06-16 21:34:01 +00001934
Bob Wilson06fce872011-02-07 17:43:21 +00001935 // Store the even D registers. This is always an updating store, so that it
1936 // provides the address to the second store for the odd subregs.
Bob Wilsona609b892011-02-07 17:43:15 +00001937 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1938 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1939 MemAddr.getValueType(),
Michael Liaob53d8962013-04-19 22:22:57 +00001940 MVT::Other, OpsA);
Evan Cheng40791332011-04-19 00:04:03 +00001941 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson01ac8f92010-06-16 21:34:01 +00001942 Chain = SDValue(VStA, 1);
1943
1944 // Store the odd D registers.
Bob Wilson06fce872011-02-07 17:43:21 +00001945 Ops.push_back(SDValue(VStA, 0));
1946 Ops.push_back(Align);
1947 if (isUpdating) {
1948 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1949 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1950 "only constant post-increment update allowed for VST3/4");
1951 (void)Inc;
1952 Ops.push_back(Reg0);
1953 }
1954 Ops.push_back(RegSeq);
1955 Ops.push_back(Pred);
1956 Ops.push_back(Reg0);
1957 Ops.push_back(Chain);
Evan Cheng40791332011-04-19 00:04:03 +00001958 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
Michael Liaob53d8962013-04-19 22:22:57 +00001959 Ops);
Evan Cheng40791332011-04-19 00:04:03 +00001960 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
1961 return VStB;
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001962}
1963
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001964SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson06fce872011-02-07 17:43:21 +00001965 bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +00001966 const uint16_t *DOpcodes,
1967 const uint16_t *QOpcodes) {
Bob Wilson93117bc2009-10-14 16:46:45 +00001968 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00001969 SDLoc dl(N);
Bob Wilson4145e3a2009-10-14 16:19:03 +00001970
Bob Wilsonae08a732010-03-20 22:13:40 +00001971 SDValue MemAddr, Align;
Bob Wilson06fce872011-02-07 17:43:21 +00001972 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1973 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1974 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson4145e3a2009-10-14 16:19:03 +00001975 return NULL;
1976
Evan Cheng40791332011-04-19 00:04:03 +00001977 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1978 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1979
Bob Wilson4145e3a2009-10-14 16:19:03 +00001980 SDValue Chain = N->getOperand(0);
1981 unsigned Lane =
Bob Wilson06fce872011-02-07 17:43:21 +00001982 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
1983 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson4145e3a2009-10-14 16:19:03 +00001984 bool is64BitVector = VT.is64BitVector();
1985
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001986 unsigned Alignment = 0;
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00001987 if (NumVecs != 3) {
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001988 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00001989 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1990 if (Alignment > NumBytes)
1991 Alignment = NumBytes;
Bob Wilsond29b38c2010-12-10 19:37:42 +00001992 if (Alignment < 8 && Alignment < NumBytes)
1993 Alignment = 0;
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00001994 // Alignment must be a power of two; make sure of that.
1995 Alignment = (Alignment & -Alignment);
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001996 if (Alignment == 1)
1997 Alignment = 0;
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00001998 }
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001999 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002000
Bob Wilson4145e3a2009-10-14 16:19:03 +00002001 unsigned OpcodeIndex;
2002 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson93117bc2009-10-14 16:46:45 +00002003 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilson4145e3a2009-10-14 16:19:03 +00002004 // Double-register operations:
2005 case MVT::v8i8: OpcodeIndex = 0; break;
2006 case MVT::v4i16: OpcodeIndex = 1; break;
2007 case MVT::v2f32:
2008 case MVT::v2i32: OpcodeIndex = 2; break;
2009 // Quad-register operations:
2010 case MVT::v8i16: OpcodeIndex = 0; break;
2011 case MVT::v4f32:
2012 case MVT::v4i32: OpcodeIndex = 1; break;
2013 }
2014
Bob Wilson06fce872011-02-07 17:43:21 +00002015 std::vector<EVT> ResTys;
2016 if (IsLoad) {
2017 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
2018 if (!is64BitVector)
2019 ResTyElts *= 2;
2020 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
2021 MVT::i64, ResTyElts));
2022 }
2023 if (isUpdating)
2024 ResTys.push_back(MVT::i32);
2025 ResTys.push_back(MVT::Other);
2026
Evan Cheng3da64f762010-04-16 05:46:06 +00002027 SDValue Pred = getAL(CurDAG);
Bob Wilsonae08a732010-03-20 22:13:40 +00002028 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chenga33fc862009-11-21 06:21:52 +00002029
Bob Wilson06fce872011-02-07 17:43:21 +00002030 SmallVector<SDValue, 8> Ops;
Bob Wilson4145e3a2009-10-14 16:19:03 +00002031 Ops.push_back(MemAddr);
Jim Grosbachd1d002a2009-11-07 21:25:39 +00002032 Ops.push_back(Align);
Bob Wilson06fce872011-02-07 17:43:21 +00002033 if (isUpdating) {
2034 SDValue Inc = N->getOperand(AddrOpIdx + 1);
2035 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
2036 }
Bob Wilson01ac8f92010-06-16 21:34:01 +00002037
Bob Wilsond5c57a52010-09-13 23:01:35 +00002038 SDValue SuperReg;
Bob Wilson06fce872011-02-07 17:43:21 +00002039 SDValue V0 = N->getOperand(Vec0Idx + 0);
2040 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002041 if (NumVecs == 2) {
2042 if (is64BitVector)
Weiming Zhao95782222012-11-17 00:23:35 +00002043 SuperReg = SDValue(createDRegPairNode(MVT::v2i64, V0, V1), 0);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002044 else
Weiming Zhao95782222012-11-17 00:23:35 +00002045 SuperReg = SDValue(createQRegPairNode(MVT::v4i64, V0, V1), 0);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002046 } else {
Bob Wilson06fce872011-02-07 17:43:21 +00002047 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002048 SDValue V3 = (NumVecs == 3)
Bob Wilson06fce872011-02-07 17:43:21 +00002049 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
2050 : N->getOperand(Vec0Idx + 3);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002051 if (is64BitVector)
Weiming Zhao95782222012-11-17 00:23:35 +00002052 SuperReg = SDValue(createQuadDRegsNode(MVT::v4i64, V0, V1, V2, V3), 0);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002053 else
Weiming Zhao95782222012-11-17 00:23:35 +00002054 SuperReg = SDValue(createQuadQRegsNode(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002055 }
Bob Wilsond5c57a52010-09-13 23:01:35 +00002056 Ops.push_back(SuperReg);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002057 Ops.push_back(getI32Imm(Lane));
Evan Chenga33fc862009-11-21 06:21:52 +00002058 Ops.push_back(Pred);
Bob Wilsonae08a732010-03-20 22:13:40 +00002059 Ops.push_back(Reg0);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002060 Ops.push_back(Chain);
2061
Bob Wilson06fce872011-02-07 17:43:21 +00002062 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
2063 QOpcodes[OpcodeIndex]);
Michael Liaob53d8962013-04-19 22:22:57 +00002064 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Evan Cheng40791332011-04-19 00:04:03 +00002065 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson93117bc2009-10-14 16:46:45 +00002066 if (!IsLoad)
Bob Wilson06fce872011-02-07 17:43:21 +00002067 return VLdLn;
Evan Cheng0cbd11d2010-05-15 01:36:29 +00002068
Bob Wilsond5c57a52010-09-13 23:01:35 +00002069 // Extract the subregisters.
Bob Wilson06fce872011-02-07 17:43:21 +00002070 SuperReg = SDValue(VLdLn, 0);
2071 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
2072 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
2073 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson01ac8f92010-06-16 21:34:01 +00002074 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
2075 ReplaceUses(SDValue(N, Vec),
Bob Wilson06fce872011-02-07 17:43:21 +00002076 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
2077 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
2078 if (isUpdating)
2079 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilson4145e3a2009-10-14 16:19:03 +00002080 return NULL;
2081}
2082
Bob Wilson06fce872011-02-07 17:43:21 +00002083SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
Craig Topper01736f82012-05-24 05:17:00 +00002084 unsigned NumVecs,
2085 const uint16_t *Opcodes) {
Bob Wilson2d790df2010-11-28 06:51:26 +00002086 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00002087 SDLoc dl(N);
Bob Wilson2d790df2010-11-28 06:51:26 +00002088
2089 SDValue MemAddr, Align;
2090 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
2091 return NULL;
2092
Evan Cheng40791332011-04-19 00:04:03 +00002093 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2094 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2095
Bob Wilson2d790df2010-11-28 06:51:26 +00002096 SDValue Chain = N->getOperand(0);
2097 EVT VT = N->getValueType(0);
2098
2099 unsigned Alignment = 0;
2100 if (NumVecs != 3) {
2101 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
2102 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
2103 if (Alignment > NumBytes)
2104 Alignment = NumBytes;
Bob Wilsond29b38c2010-12-10 19:37:42 +00002105 if (Alignment < 8 && Alignment < NumBytes)
2106 Alignment = 0;
Bob Wilson2d790df2010-11-28 06:51:26 +00002107 // Alignment must be a power of two; make sure of that.
2108 Alignment = (Alignment & -Alignment);
2109 if (Alignment == 1)
2110 Alignment = 0;
2111 }
2112 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
2113
2114 unsigned OpcodeIndex;
2115 switch (VT.getSimpleVT().SimpleTy) {
2116 default: llvm_unreachable("unhandled vld-dup type");
2117 case MVT::v8i8: OpcodeIndex = 0; break;
2118 case MVT::v4i16: OpcodeIndex = 1; break;
2119 case MVT::v2f32:
2120 case MVT::v2i32: OpcodeIndex = 2; break;
2121 }
2122
2123 SDValue Pred = getAL(CurDAG);
2124 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2125 SDValue SuperReg;
2126 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson06fce872011-02-07 17:43:21 +00002127 SmallVector<SDValue, 6> Ops;
2128 Ops.push_back(MemAddr);
2129 Ops.push_back(Align);
2130 if (isUpdating) {
Jim Grosbachc80a2642011-12-21 19:40:55 +00002131 // fixed-stride update instructions don't have an explicit writeback
2132 // operand. It's implicit in the opcode itself.
Bob Wilson06fce872011-02-07 17:43:21 +00002133 SDValue Inc = N->getOperand(2);
Jim Grosbachc80a2642011-12-21 19:40:55 +00002134 if (!isa<ConstantSDNode>(Inc.getNode()))
2135 Ops.push_back(Inc);
2136 // FIXME: VLD3 and VLD4 haven't been updated to that form yet.
2137 else if (NumVecs > 2)
2138 Ops.push_back(Reg0);
Bob Wilson06fce872011-02-07 17:43:21 +00002139 }
2140 Ops.push_back(Pred);
2141 Ops.push_back(Reg0);
2142 Ops.push_back(Chain);
Bob Wilson2d790df2010-11-28 06:51:26 +00002143
2144 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson06fce872011-02-07 17:43:21 +00002145 std::vector<EVT> ResTys;
Evan Cheng40791332011-04-19 00:04:03 +00002146 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson06fce872011-02-07 17:43:21 +00002147 if (isUpdating)
2148 ResTys.push_back(MVT::i32);
2149 ResTys.push_back(MVT::Other);
Michael Liaob53d8962013-04-19 22:22:57 +00002150 SDNode *VLdDup = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Evan Cheng40791332011-04-19 00:04:03 +00002151 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson2d790df2010-11-28 06:51:26 +00002152 SuperReg = SDValue(VLdDup, 0);
Bob Wilson2d790df2010-11-28 06:51:26 +00002153
2154 // Extract the subregisters.
2155 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
2156 unsigned SubIdx = ARM::dsub_0;
2157 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
2158 ReplaceUses(SDValue(N, Vec),
2159 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson06fce872011-02-07 17:43:21 +00002160 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
2161 if (isUpdating)
2162 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilson2d790df2010-11-28 06:51:26 +00002163 return NULL;
2164}
2165
Bob Wilson5bc8a792010-07-07 00:08:54 +00002166SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
2167 unsigned Opc) {
Bob Wilson3ed511b2010-07-06 23:36:25 +00002168 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00002169 SDLoc dl(N);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002170 EVT VT = N->getValueType(0);
Bob Wilson5bc8a792010-07-07 00:08:54 +00002171 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilson3ed511b2010-07-06 23:36:25 +00002172
2173 // Form a REG_SEQUENCE to force register allocation.
2174 SDValue RegSeq;
Bob Wilson5bc8a792010-07-07 00:08:54 +00002175 SDValue V0 = N->getOperand(FirstTblReg + 0);
2176 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002177 if (NumVecs == 2)
Weiming Zhao95782222012-11-17 00:23:35 +00002178 RegSeq = SDValue(createDRegPairNode(MVT::v16i8, V0, V1), 0);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002179 else {
Bob Wilson5bc8a792010-07-07 00:08:54 +00002180 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbachd37f0712010-10-21 19:38:40 +00002181 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilson3ed511b2010-07-06 23:36:25 +00002182 // an undef.
2183 SDValue V3 = (NumVecs == 3)
2184 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson5bc8a792010-07-07 00:08:54 +00002185 : N->getOperand(FirstTblReg + 3);
Weiming Zhao95782222012-11-17 00:23:35 +00002186 RegSeq = SDValue(createQuadDRegsNode(MVT::v4i64, V0, V1, V2, V3), 0);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002187 }
2188
Bob Wilson5bc8a792010-07-07 00:08:54 +00002189 SmallVector<SDValue, 6> Ops;
2190 if (IsExt)
2191 Ops.push_back(N->getOperand(1));
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00002192 Ops.push_back(RegSeq);
Bob Wilson5bc8a792010-07-07 00:08:54 +00002193 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilson3ed511b2010-07-06 23:36:25 +00002194 Ops.push_back(getAL(CurDAG)); // predicate
2195 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Michael Liaob53d8962013-04-19 22:22:57 +00002196 return CurDAG->getMachineNode(Opc, dl, VT, Ops);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002197}
2198
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002199SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach825cb292010-04-22 23:24:18 +00002200 bool isSigned) {
Sandeep Patel423e42b2009-10-13 18:59:48 +00002201 if (!Subtarget->hasV6T2Ops())
2202 return NULL;
Bob Wilson93117bc2009-10-14 16:46:45 +00002203
Evan Chengeae6d2c2012-12-19 20:16:09 +00002204 unsigned Opc = isSigned
2205 ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
Jim Grosbach825cb292010-04-22 23:24:18 +00002206 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
2207
Jim Grosbach825cb292010-04-22 23:24:18 +00002208 // For unsigned extracts, check for a shift right and mask
2209 unsigned And_imm = 0;
2210 if (N->getOpcode() == ISD::AND) {
2211 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
2212
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00002213 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
Jim Grosbach825cb292010-04-22 23:24:18 +00002214 if (And_imm & (And_imm + 1))
2215 return NULL;
2216
2217 unsigned Srl_imm = 0;
2218 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
2219 Srl_imm)) {
2220 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2221
Jim Grosbach03f56d92011-07-27 21:09:25 +00002222 // Note: The width operand is encoded as width-1.
2223 unsigned Width = CountTrailingOnes_32(And_imm) - 1;
Jim Grosbach825cb292010-04-22 23:24:18 +00002224 unsigned LSB = Srl_imm;
Evan Chengeae6d2c2012-12-19 20:16:09 +00002225
Jim Grosbach825cb292010-04-22 23:24:18 +00002226 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengeae6d2c2012-12-19 20:16:09 +00002227
2228 if ((LSB + Width + 1) == N->getValueType(0).getSizeInBits()) {
2229 // It's cheaper to use a right shift to extract the top bits.
2230 if (Subtarget->isThumb()) {
2231 Opc = isSigned ? ARM::t2ASRri : ARM::t2LSRri;
2232 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2233 CurDAG->getTargetConstant(LSB, MVT::i32),
2234 getAL(CurDAG), Reg0, Reg0 };
2235 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2236 }
2237
2238 // ARM models shift instructions as MOVsi with shifter operand.
2239 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(ISD::SRL);
2240 SDValue ShOpc =
2241 CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, LSB),
2242 MVT::i32);
2243 SDValue Ops[] = { N->getOperand(0).getOperand(0), ShOpc,
2244 getAL(CurDAG), Reg0, Reg0 };
2245 return CurDAG->SelectNodeTo(N, ARM::MOVsi, MVT::i32, Ops, 5);
2246 }
2247
Jim Grosbach825cb292010-04-22 23:24:18 +00002248 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2249 CurDAG->getTargetConstant(LSB, MVT::i32),
2250 CurDAG->getTargetConstant(Width, MVT::i32),
2251 getAL(CurDAG), Reg0 };
2252 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2253 }
2254 }
2255 return NULL;
2256 }
2257
2258 // Otherwise, we're looking for a shift of a shift
Sandeep Patel423e42b2009-10-13 18:59:48 +00002259 unsigned Shl_imm = 0;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002260 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel423e42b2009-10-13 18:59:48 +00002261 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
2262 unsigned Srl_imm = 0;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002263 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel423e42b2009-10-13 18:59:48 +00002264 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
Jim Grosbach03f56d92011-07-27 21:09:25 +00002265 // Note: The width operand is encoded as width-1.
2266 unsigned Width = 32 - Srl_imm - 1;
Sandeep Patel423e42b2009-10-13 18:59:48 +00002267 int LSB = Srl_imm - Shl_imm;
Evan Cheng0f55e9c2009-10-22 00:40:00 +00002268 if (LSB < 0)
Sandeep Patel423e42b2009-10-13 18:59:48 +00002269 return NULL;
2270 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002271 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel423e42b2009-10-13 18:59:48 +00002272 CurDAG->getTargetConstant(LSB, MVT::i32),
2273 CurDAG->getTargetConstant(Width, MVT::i32),
2274 getAL(CurDAG), Reg0 };
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002275 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel423e42b2009-10-13 18:59:48 +00002276 }
2277 }
2278 return NULL;
2279}
2280
Evan Cheng81a28512009-11-20 00:54:03 +00002281SDNode *ARMDAGToDAGISel::
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002282SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng81a28512009-11-20 00:54:03 +00002283 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2284 SDValue CPTmp0;
2285 SDValue CPTmp1;
Chris Lattner0e023ea2010-09-21 20:31:19 +00002286 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng81a28512009-11-20 00:54:03 +00002287 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
2288 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
2289 unsigned Opc = 0;
2290 switch (SOShOp) {
2291 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
2292 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
2293 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
2294 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
2295 default:
2296 llvm_unreachable("Unknown so_reg opcode!");
Evan Cheng81a28512009-11-20 00:54:03 +00002297 }
2298 SDValue SOShImm =
2299 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
2300 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2301 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002302 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng81a28512009-11-20 00:54:03 +00002303 }
2304 return 0;
2305}
2306
2307SDNode *ARMDAGToDAGISel::
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002308SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng81a28512009-11-20 00:54:03 +00002309 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2310 SDValue CPTmp0;
2311 SDValue CPTmp1;
2312 SDValue CPTmp2;
Owen Anderson04912702011-07-21 23:38:37 +00002313 if (SelectImmShifterOperand(TrueVal, CPTmp0, CPTmp2)) {
Evan Cheng81a28512009-11-20 00:54:03 +00002314 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
Owen Anderson3fa7ca82011-07-22 18:30:30 +00002315 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp2, CC, CCR, InFlag };
2316 return CurDAG->SelectNodeTo(N, ARM::MOVCCsi, MVT::i32, Ops, 6);
Owen Andersonb595ed02011-07-21 18:54:16 +00002317 }
2318
2319 if (SelectRegShifterOperand(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
2320 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2321 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
2322 return CurDAG->SelectNodeTo(N, ARM::MOVCCsr, MVT::i32, Ops, 7);
Evan Cheng81a28512009-11-20 00:54:03 +00002323 }
2324 return 0;
2325}
2326
2327SDNode *ARMDAGToDAGISel::
Jim Grosbach5b255c22010-10-07 00:53:56 +00002328SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng39c81c02010-11-17 20:56:30 +00002329 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng81a28512009-11-20 00:54:03 +00002330 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chenga5f04842010-11-19 23:01:16 +00002331 if (!T)
Evan Cheng81a28512009-11-20 00:54:03 +00002332 return 0;
2333
Evan Cheng2bcb8da2010-11-13 02:25:14 +00002334 unsigned Opc = 0;
Jim Grosbach5b255c22010-10-07 00:53:56 +00002335 unsigned TrueImm = T->getZExtValue();
Evan Cheng39c81c02010-11-17 20:56:30 +00002336 if (is_t2_so_imm(TrueImm)) {
2337 Opc = ARM::t2MOVCCi;
2338 } else if (TrueImm <= 0xffff) {
2339 Opc = ARM::t2MOVCCi16;
Evan Cheng2bcb8da2010-11-13 02:25:14 +00002340 } else if (is_t2_so_imm_not(TrueImm)) {
2341 TrueImm = ~TrueImm;
2342 Opc = ARM::t2MVNCCi;
Evan Cheng39c81c02010-11-17 20:56:30 +00002343 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng2bcb8da2010-11-13 02:25:14 +00002344 // Large immediate.
2345 Opc = ARM::t2MOVCCi32imm;
2346 }
2347
2348 if (Opc) {
Evan Cheng0fc80842010-11-12 22:42:47 +00002349 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng81a28512009-11-20 00:54:03 +00002350 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2351 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng2bcb8da2010-11-13 02:25:14 +00002352 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng81a28512009-11-20 00:54:03 +00002353 }
Evan Cheng2bcb8da2010-11-13 02:25:14 +00002354
Evan Cheng81a28512009-11-20 00:54:03 +00002355 return 0;
2356}
2357
2358SDNode *ARMDAGToDAGISel::
Jim Grosbach742adc32010-10-07 00:42:42 +00002359SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng39c81c02010-11-17 20:56:30 +00002360 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng81a28512009-11-20 00:54:03 +00002361 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2362 if (!T)
2363 return 0;
2364
Evan Cheng2bcb8da2010-11-13 02:25:14 +00002365 unsigned Opc = 0;
Jim Grosbach742adc32010-10-07 00:42:42 +00002366 unsigned TrueImm = T->getZExtValue();
Evan Cheng0fc80842010-11-12 22:42:47 +00002367 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng39c81c02010-11-17 20:56:30 +00002368 if (isSoImm) {
2369 Opc = ARM::MOVCCi;
2370 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2371 Opc = ARM::MOVCCi16;
Evan Cheng2bcb8da2010-11-13 02:25:14 +00002372 } else if (is_so_imm_not(TrueImm)) {
2373 TrueImm = ~TrueImm;
2374 Opc = ARM::MVNCCi;
Evan Cheng39c81c02010-11-17 20:56:30 +00002375 } else if (TrueVal.getNode()->hasOneUse() &&
2376 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng2bcb8da2010-11-13 02:25:14 +00002377 // Large immediate.
2378 Opc = ARM::MOVCCi32imm;
2379 }
2380
2381 if (Opc) {
Jim Grosbach742adc32010-10-07 00:42:42 +00002382 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng81a28512009-11-20 00:54:03 +00002383 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2384 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng2bcb8da2010-11-13 02:25:14 +00002385 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng81a28512009-11-20 00:54:03 +00002386 }
Andrew Trickc416ba62010-12-24 04:28:06 +00002387
Evan Cheng81a28512009-11-20 00:54:03 +00002388 return 0;
2389}
2390
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002391SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2392 EVT VT = N->getValueType(0);
2393 SDValue FalseVal = N->getOperand(0);
2394 SDValue TrueVal = N->getOperand(1);
2395 SDValue CC = N->getOperand(2);
2396 SDValue CCR = N->getOperand(3);
2397 SDValue InFlag = N->getOperand(4);
Evan Cheng81a28512009-11-20 00:54:03 +00002398 assert(CC.getOpcode() == ISD::Constant);
2399 assert(CCR.getOpcode() == ISD::Register);
2400 ARMCC::CondCodes CCVal =
2401 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Chengb6c77042009-11-19 21:45:22 +00002402
2403 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2404 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2405 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2406 // Pattern complexity = 18 cost = 1 size = 0
Evan Chengb6c77042009-11-19 21:45:22 +00002407 if (Subtarget->isThumb()) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002408 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng81a28512009-11-20 00:54:03 +00002409 CCVal, CCR, InFlag);
2410 if (!Res)
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002411 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng81a28512009-11-20 00:54:03 +00002412 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2413 if (Res)
2414 return Res;
Evan Chengb6c77042009-11-19 21:45:22 +00002415 } else {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002416 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng81a28512009-11-20 00:54:03 +00002417 CCVal, CCR, InFlag);
2418 if (!Res)
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002419 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng81a28512009-11-20 00:54:03 +00002420 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2421 if (Res)
2422 return Res;
Evan Chengb6c77042009-11-19 21:45:22 +00002423 }
2424
2425 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesene2cbaf62010-08-17 20:39:04 +00002426 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Chengb6c77042009-11-19 21:45:22 +00002427 // (imm:i32):$cc)
2428 // Emits: (MOVCCi:i32 GPR:i32:$false,
2429 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2430 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng81a28512009-11-20 00:54:03 +00002431 if (Subtarget->isThumb()) {
Jim Grosbach5b255c22010-10-07 00:53:56 +00002432 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng81a28512009-11-20 00:54:03 +00002433 CCVal, CCR, InFlag);
2434 if (!Res)
Jim Grosbach5b255c22010-10-07 00:53:56 +00002435 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng81a28512009-11-20 00:54:03 +00002436 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2437 if (Res)
2438 return Res;
2439 } else {
Jim Grosbach742adc32010-10-07 00:42:42 +00002440 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng81a28512009-11-20 00:54:03 +00002441 CCVal, CCR, InFlag);
2442 if (!Res)
Jim Grosbach742adc32010-10-07 00:42:42 +00002443 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng81a28512009-11-20 00:54:03 +00002444 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2445 if (Res)
2446 return Res;
Evan Chengb6c77042009-11-19 21:45:22 +00002447 }
2448 }
2449
2450 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2451 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2452 // Pattern complexity = 6 cost = 1 size = 0
2453 //
2454 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2455 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2456 // Pattern complexity = 6 cost = 11 size = 0
2457 //
Jim Grosbach2fee5322011-03-11 23:15:02 +00002458 // Also VMOVScc and VMOVDcc.
Evan Cheng81a28512009-11-20 00:54:03 +00002459 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2460 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Chengb6c77042009-11-19 21:45:22 +00002461 unsigned Opc = 0;
2462 switch (VT.getSimpleVT().SimpleTy) {
Craig Toppere55c5562012-02-07 02:50:20 +00002463 default: llvm_unreachable("Illegal conditional move type!");
Evan Chengb6c77042009-11-19 21:45:22 +00002464 case MVT::i32:
2465 Opc = Subtarget->isThumb()
2466 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2467 : ARM::MOVCCr;
2468 break;
2469 case MVT::f32:
2470 Opc = ARM::VMOVScc;
2471 break;
2472 case MVT::f64:
2473 Opc = ARM::VMOVDcc;
2474 break;
2475 }
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002476 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengb6c77042009-11-19 21:45:22 +00002477}
2478
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002479/// Target-specific DAG combining for ISD::XOR.
2480/// Target-independent combining lowers SELECT_CC nodes of the form
2481/// select_cc setg[ge] X, 0, X, -X
2482/// select_cc setgt X, -1, X, -X
2483/// select_cc setl[te] X, 0, -X, X
2484/// select_cc setlt X, 1, -X, X
2485/// which represent Integer ABS into:
2486/// Y = sra (X, size(X)-1); xor (add (X, Y), Y)
2487/// ARM instruction selection detects the latter and matches it to
2488/// ARM::ABS or ARM::t2ABS machine node.
2489SDNode *ARMDAGToDAGISel::SelectABSOp(SDNode *N){
2490 SDValue XORSrc0 = N->getOperand(0);
2491 SDValue XORSrc1 = N->getOperand(1);
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002492 EVT VT = N->getValueType(0);
2493
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002494 if (Subtarget->isThumb1Only())
2495 return NULL;
2496
Jim Grosbachb437a8c2012-08-01 20:33:00 +00002497 if (XORSrc0.getOpcode() != ISD::ADD || XORSrc1.getOpcode() != ISD::SRA)
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002498 return NULL;
2499
2500 SDValue ADDSrc0 = XORSrc0.getOperand(0);
2501 SDValue ADDSrc1 = XORSrc0.getOperand(1);
2502 SDValue SRASrc0 = XORSrc1.getOperand(0);
2503 SDValue SRASrc1 = XORSrc1.getOperand(1);
2504 ConstantSDNode *SRAConstant = dyn_cast<ConstantSDNode>(SRASrc1);
2505 EVT XType = SRASrc0.getValueType();
2506 unsigned Size = XType.getSizeInBits() - 1;
2507
Jim Grosbachb437a8c2012-08-01 20:33:00 +00002508 if (ADDSrc1 == XORSrc1 && ADDSrc0 == SRASrc0 &&
2509 XType.isInteger() && SRAConstant != NULL &&
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002510 Size == SRAConstant->getZExtValue()) {
Jim Grosbachb437a8c2012-08-01 20:33:00 +00002511 unsigned Opcode = Subtarget->isThumb2() ? ARM::t2ABS : ARM::ABS;
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002512 return CurDAG->SelectNodeTo(N, Opcode, VT, ADDSrc0);
2513 }
2514
2515 return NULL;
2516}
2517
Evan Chengd85631e2010-05-05 18:28:36 +00002518SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2519 // The only time a CONCAT_VECTORS operation can have legal types is when
2520 // two 64-bit vectors are concatenated to a 128-bit vector.
2521 EVT VT = N->getValueType(0);
2522 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2523 llvm_unreachable("unexpected CONCAT_VECTORS");
Weiming Zhao95782222012-11-17 00:23:35 +00002524 return createDRegPairNode(VT, N->getOperand(0), N->getOperand(1));
Evan Chengd85631e2010-05-05 18:28:36 +00002525}
2526
Eli Friedmanc3f9c4a2011-08-31 00:31:29 +00002527SDNode *ARMDAGToDAGISel::SelectAtomic64(SDNode *Node, unsigned Opc) {
Eli Friedman1ccecbb2011-08-31 17:52:22 +00002528 SmallVector<SDValue, 6> Ops;
2529 Ops.push_back(Node->getOperand(1)); // Ptr
2530 Ops.push_back(Node->getOperand(2)); // Low part of Val1
2531 Ops.push_back(Node->getOperand(3)); // High part of Val1
Owen Anderson939cd212011-08-31 20:00:11 +00002532 if (Opc == ARM::ATOMCMPXCHG6432) {
Eli Friedman1ccecbb2011-08-31 17:52:22 +00002533 Ops.push_back(Node->getOperand(4)); // Low part of Val2
2534 Ops.push_back(Node->getOperand(5)); // High part of Val2
2535 }
2536 Ops.push_back(Node->getOperand(0)); // Chain
Eli Friedmanc3f9c4a2011-08-31 00:31:29 +00002537 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2538 MemOp[0] = cast<MemSDNode>(Node)->getMemOperand();
Andrew Trickef9de2a2013-05-25 02:42:55 +00002539 SDNode *ResNode = CurDAG->getMachineNode(Opc, SDLoc(Node),
Eli Friedman1ccecbb2011-08-31 17:52:22 +00002540 MVT::i32, MVT::i32, MVT::Other,
Michael Liaob53d8962013-04-19 22:22:57 +00002541 Ops);
Eli Friedmanc3f9c4a2011-08-31 00:31:29 +00002542 cast<MachineSDNode>(ResNode)->setMemRefs(MemOp, MemOp + 1);
2543 return ResNode;
2544}
2545
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002546SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00002547 SDLoc dl(N);
Evan Cheng10043e22007-01-19 07:51:42 +00002548
Dan Gohman17059682008-07-17 19:10:17 +00002549 if (N->isMachineOpcode())
Evan Cheng10043e22007-01-19 07:51:42 +00002550 return NULL; // Already selected.
Rafael Espindola4e760152006-06-12 12:28:08 +00002551
2552 switch (N->getOpcode()) {
Evan Cheng10043e22007-01-19 07:51:42 +00002553 default: break;
Weiming Zhaoc5987002013-02-14 18:10:21 +00002554 case ISD::INLINEASM: {
2555 SDNode *ResNode = SelectInlineAsm(N);
2556 if (ResNode)
2557 return ResNode;
2558 break;
2559 }
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002560 case ISD::XOR: {
2561 // Select special operations if XOR node forms integer ABS pattern
2562 SDNode *ResNode = SelectABSOp(N);
2563 if (ResNode)
2564 return ResNode;
2565 // Other cases are autogenerated.
2566 break;
2567 }
Evan Cheng10043e22007-01-19 07:51:42 +00002568 case ISD::Constant: {
Dan Gohmaneffb8942008-09-12 16:56:44 +00002569 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Cheng10043e22007-01-19 07:51:42 +00002570 bool UseCP = true;
Anton Korobeynikov7c2b1e72009-09-27 23:52:58 +00002571 if (Subtarget->hasThumb2())
2572 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2573 // be done with MOV + MOVT, at worst.
2574 UseCP = 0;
2575 else {
2576 if (Subtarget->isThumb()) {
Bob Wilson360eef02009-06-22 17:29:13 +00002577 UseCP = (Val > 255 && // MOV
2578 ~Val > 255 && // MOV + MVN
2579 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov7c2b1e72009-09-27 23:52:58 +00002580 } else
2581 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2582 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2583 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2584 }
2585
Evan Cheng10043e22007-01-19 07:51:42 +00002586 if (UseCP) {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002587 SDValue CPIdx =
Owen Anderson55f1c092009-08-13 21:58:54 +00002588 CurDAG->getTargetConstantPool(ConstantInt::get(
2589 Type::getInt32Ty(*CurDAG->getContext()), Val),
Bill Wendlingf7719082013-06-06 00:43:09 +00002590 TLI->getPointerTy());
Evan Cheng1526ba52007-01-24 08:53:17 +00002591
2592 SDNode *ResNode;
Evan Chengcd4cdd12009-07-11 06:43:01 +00002593 if (Subtarget->isThumb1Only()) {
Evan Cheng3da64f762010-04-16 05:46:06 +00002594 SDValue Pred = getAL(CurDAG);
Owen Anderson9f944592009-08-11 20:47:22 +00002595 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Chengcd4cdd12009-07-11 06:43:01 +00002596 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbachbfef3092010-12-15 23:52:36 +00002597 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Michael Liaob53d8962013-04-19 22:22:57 +00002598 Ops);
Evan Chengcd4cdd12009-07-11 06:43:01 +00002599 } else {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002600 SDValue Ops[] = {
Jim Grosbachf24f9d92009-08-11 15:33:49 +00002601 CPIdx,
Owen Anderson9f944592009-08-11 20:47:22 +00002602 CurDAG->getTargetConstant(0, MVT::i32),
Evan Cheng7e90b112007-07-05 07:15:27 +00002603 getAL(CurDAG),
Owen Anderson9f944592009-08-11 20:47:22 +00002604 CurDAG->getRegister(0, MVT::i32),
Evan Cheng1526ba52007-01-24 08:53:17 +00002605 CurDAG->getEntryNode()
2606 };
Dan Gohman32f71d72009-09-25 18:54:59 +00002607 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Michael Liaob53d8962013-04-19 22:22:57 +00002608 Ops);
Evan Cheng1526ba52007-01-24 08:53:17 +00002609 }
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002610 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Cheng10043e22007-01-19 07:51:42 +00002611 return NULL;
2612 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +00002613
Evan Cheng10043e22007-01-19 07:51:42 +00002614 // Other cases are autogenerated.
Rafael Espindola4e760152006-06-12 12:28:08 +00002615 break;
Evan Cheng10043e22007-01-19 07:51:42 +00002616 }
Rafael Espindola5f7ab1b2006-11-09 13:58:55 +00002617 case ISD::FrameIndex: {
Evan Cheng10043e22007-01-19 07:51:42 +00002618 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindola5f7ab1b2006-11-09 13:58:55 +00002619 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlingf7719082013-06-06 00:43:09 +00002620 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
David Goodwin22c2fba2009-07-08 23:10:31 +00002621 if (Subtarget->isThumb1Only()) {
Jim Grosbach1b8457a2011-08-24 17:46:13 +00002622 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2623 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2624 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, Ops, 4);
Jim Grosbachfde21102009-04-07 20:34:09 +00002625 } else {
David Goodwin4ad77972009-07-14 18:48:51 +00002626 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2627 ARM::t2ADDri : ARM::ADDri);
Owen Anderson9f944592009-08-11 20:47:22 +00002628 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2629 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2630 CurDAG->getRegister(0, MVT::i32) };
2631 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng7e90b112007-07-05 07:15:27 +00002632 }
Evan Cheng10043e22007-01-19 07:51:42 +00002633 }
Sandeep Patel423e42b2009-10-13 18:59:48 +00002634 case ISD::SRL:
Jim Grosbach825cb292010-04-22 23:24:18 +00002635 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel423e42b2009-10-13 18:59:48 +00002636 return I;
2637 break;
2638 case ISD::SRA:
Jim Grosbach825cb292010-04-22 23:24:18 +00002639 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel423e42b2009-10-13 18:59:48 +00002640 return I;
2641 break;
Evan Cheng10043e22007-01-19 07:51:42 +00002642 case ISD::MUL:
Evan Chengb24e51e2009-07-07 01:17:28 +00002643 if (Subtarget->isThumb1Only())
Evan Cheng139edae2007-01-24 02:21:22 +00002644 break;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002645 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +00002646 unsigned RHSV = C->getZExtValue();
Evan Cheng10043e22007-01-19 07:51:42 +00002647 if (!RHSV) break;
2648 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002649 unsigned ShImm = Log2_32(RHSV-1);
2650 if (ShImm >= 32)
2651 break;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002652 SDValue V = N->getOperand(0);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002653 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson9f944592009-08-11 20:47:22 +00002654 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2655 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng1ec43962009-07-22 18:08:05 +00002656 if (Subtarget->isThumb()) {
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002657 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson9f944592009-08-11 20:47:22 +00002658 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002659 } else {
2660 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Andersonb595ed02011-07-21 18:54:16 +00002661 return CurDAG->SelectNodeTo(N, ARM::ADDrsi, MVT::i32, Ops, 7);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002662 }
Evan Cheng10043e22007-01-19 07:51:42 +00002663 }
2664 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002665 unsigned ShImm = Log2_32(RHSV+1);
2666 if (ShImm >= 32)
2667 break;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002668 SDValue V = N->getOperand(0);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002669 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson9f944592009-08-11 20:47:22 +00002670 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2671 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng1ec43962009-07-22 18:08:05 +00002672 if (Subtarget->isThumb()) {
Bob Wilsonb6112e82010-05-28 00:27:15 +00002673 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2674 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002675 } else {
2676 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Andersonb595ed02011-07-21 18:54:16 +00002677 return CurDAG->SelectNodeTo(N, ARM::RSBrsi, MVT::i32, Ops, 7);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002678 }
Evan Cheng10043e22007-01-19 07:51:42 +00002679 }
2680 }
2681 break;
Evan Cheng786b15f2009-10-21 08:15:52 +00002682 case ISD::AND: {
Jim Grosbach825cb292010-04-22 23:24:18 +00002683 // Check for unsigned bitfield extract
2684 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2685 return I;
2686
Evan Cheng786b15f2009-10-21 08:15:52 +00002687 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2688 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2689 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2690 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2691 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002692 EVT VT = N->getValueType(0);
Evan Cheng786b15f2009-10-21 08:15:52 +00002693 if (VT != MVT::i32)
2694 break;
2695 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2696 ? ARM::t2MOVTi16
2697 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2698 if (!Opc)
2699 break;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002700 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng786b15f2009-10-21 08:15:52 +00002701 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2702 if (!N1C)
2703 break;
2704 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2705 SDValue N2 = N0.getOperand(1);
2706 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2707 if (!N2C)
2708 break;
2709 unsigned N1CVal = N1C->getZExtValue();
2710 unsigned N2CVal = N2C->getZExtValue();
2711 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2712 (N1CVal & 0xffffU) == 0xffffU &&
2713 (N2CVal & 0xffffU) == 0x0U) {
2714 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2715 MVT::i32);
2716 SDValue Ops[] = { N0.getOperand(0), Imm16,
2717 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Michael Liaob53d8962013-04-19 22:22:57 +00002718 return CurDAG->getMachineNode(Opc, dl, VT, Ops);
Evan Cheng786b15f2009-10-21 08:15:52 +00002719 }
2720 }
2721 break;
2722 }
Jim Grosbachd7cf55c2009-11-09 00:11:35 +00002723 case ARMISD::VMOVRRD:
2724 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002725 N->getOperand(0), getAL(CurDAG),
Dan Gohman32f71d72009-09-25 18:54:59 +00002726 CurDAG->getRegister(0, MVT::i32));
Dan Gohmana1603612007-10-08 18:33:35 +00002727 case ISD::UMUL_LOHI: {
Evan Chengb24e51e2009-07-07 01:17:28 +00002728 if (Subtarget->isThumb1Only())
2729 break;
2730 if (Subtarget->isThumb()) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002731 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Michael Liaob53d8962013-04-19 22:22:57 +00002732 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2733 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32, Ops);
Evan Chengb24e51e2009-07-07 01:17:28 +00002734 } else {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002735 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson9f944592009-08-11 20:47:22 +00002736 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2737 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov62acecd2011-01-01 20:38:38 +00002738 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2739 ARM::UMULL : ARM::UMULLv5,
Michael Liaob53d8962013-04-19 22:22:57 +00002740 dl, MVT::i32, MVT::i32, Ops);
Evan Chengb24e51e2009-07-07 01:17:28 +00002741 }
Evan Cheng7e90b112007-07-05 07:15:27 +00002742 }
Dan Gohmana1603612007-10-08 18:33:35 +00002743 case ISD::SMUL_LOHI: {
Evan Chengb24e51e2009-07-07 01:17:28 +00002744 if (Subtarget->isThumb1Only())
2745 break;
2746 if (Subtarget->isThumb()) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002747 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson9f944592009-08-11 20:47:22 +00002748 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Michael Liaob53d8962013-04-19 22:22:57 +00002749 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32, Ops);
Evan Chengb24e51e2009-07-07 01:17:28 +00002750 } else {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002751 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson9f944592009-08-11 20:47:22 +00002752 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2753 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov62acecd2011-01-01 20:38:38 +00002754 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2755 ARM::SMULL : ARM::SMULLv5,
Michael Liaob53d8962013-04-19 22:22:57 +00002756 dl, MVT::i32, MVT::i32, Ops);
Evan Chengb24e51e2009-07-07 01:17:28 +00002757 }
Evan Cheng7e90b112007-07-05 07:15:27 +00002758 }
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002759 case ARMISD::UMLAL:{
2760 if (Subtarget->isThumb()) {
2761 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2762 N->getOperand(3), getAL(CurDAG),
2763 CurDAG->getRegister(0, MVT::i32)};
Michael Liaob53d8962013-04-19 22:22:57 +00002764 return CurDAG->getMachineNode(ARM::t2UMLAL, dl, MVT::i32, MVT::i32, Ops);
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002765 }else{
2766 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2767 N->getOperand(3), getAL(CurDAG),
2768 CurDAG->getRegister(0, MVT::i32),
2769 CurDAG->getRegister(0, MVT::i32) };
2770 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2771 ARM::UMLAL : ARM::UMLALv5,
Michael Liaob53d8962013-04-19 22:22:57 +00002772 dl, MVT::i32, MVT::i32, Ops);
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002773 }
2774 }
2775 case ARMISD::SMLAL:{
2776 if (Subtarget->isThumb()) {
2777 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2778 N->getOperand(3), getAL(CurDAG),
2779 CurDAG->getRegister(0, MVT::i32)};
Michael Liaob53d8962013-04-19 22:22:57 +00002780 return CurDAG->getMachineNode(ARM::t2SMLAL, dl, MVT::i32, MVT::i32, Ops);
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002781 }else{
2782 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2783 N->getOperand(3), getAL(CurDAG),
2784 CurDAG->getRegister(0, MVT::i32),
2785 CurDAG->getRegister(0, MVT::i32) };
2786 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2787 ARM::SMLAL : ARM::SMLALv5,
Michael Liaob53d8962013-04-19 22:22:57 +00002788 dl, MVT::i32, MVT::i32, Ops);
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002789 }
2790 }
Evan Cheng10043e22007-01-19 07:51:42 +00002791 case ISD::LOAD: {
Evan Cheng84c6cda2009-07-02 07:28:31 +00002792 SDNode *ResNode = 0;
Evan Chengb24e51e2009-07-07 01:17:28 +00002793 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002794 ResNode = SelectT2IndexedLoad(N);
Evan Cheng84c6cda2009-07-02 07:28:31 +00002795 else
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002796 ResNode = SelectARMIndexedLoad(N);
Evan Chengd9c55362009-07-02 01:23:32 +00002797 if (ResNode)
2798 return ResNode;
Evan Cheng10043e22007-01-19 07:51:42 +00002799 // Other cases are autogenerated.
Rafael Espindola5f7ab1b2006-11-09 13:58:55 +00002800 break;
Rafael Espindola4e760152006-06-12 12:28:08 +00002801 }
Evan Cheng7e90b112007-07-05 07:15:27 +00002802 case ARMISD::BRCOND: {
2803 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2804 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2805 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00002806
Evan Cheng7e90b112007-07-05 07:15:27 +00002807 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2808 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2809 // Pattern complexity = 6 cost = 1 size = 0
2810
David Goodwin27303cd2009-06-30 18:04:13 +00002811 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2812 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2813 // Pattern complexity = 6 cost = 1 size = 0
2814
Jim Grosbachf24f9d92009-08-11 15:33:49 +00002815 unsigned Opc = Subtarget->isThumb() ?
David Goodwin27303cd2009-06-30 18:04:13 +00002816 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002817 SDValue Chain = N->getOperand(0);
2818 SDValue N1 = N->getOperand(1);
2819 SDValue N2 = N->getOperand(2);
2820 SDValue N3 = N->getOperand(3);
2821 SDValue InFlag = N->getOperand(4);
Evan Cheng7e90b112007-07-05 07:15:27 +00002822 assert(N1.getOpcode() == ISD::BasicBlock);
2823 assert(N2.getOpcode() == ISD::Constant);
2824 assert(N3.getOpcode() == ISD::Register);
2825
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002826 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmaneffb8942008-09-12 16:56:44 +00002827 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson9f944592009-08-11 20:47:22 +00002828 MVT::i32);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002829 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman32f71d72009-09-25 18:54:59 +00002830 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Michael Liaob53d8962013-04-19 22:22:57 +00002831 MVT::Glue, Ops);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002832 Chain = SDValue(ResNode, 0);
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002833 if (N->getNumValues() == 2) {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002834 InFlag = SDValue(ResNode, 1);
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002835 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnere99faac2008-02-03 03:20:59 +00002836 }
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002837 ReplaceUses(SDValue(N, 0),
Evan Cheng82adca82009-11-19 08:16:50 +00002838 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Cheng7e90b112007-07-05 07:15:27 +00002839 return NULL;
2840 }
Evan Chengb6c77042009-11-19 21:45:22 +00002841 case ARMISD::CMOV:
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002842 return SelectCMOVOp(N);
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002843 case ARMISD::VZIP: {
2844 unsigned Opc = 0;
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002845 EVT VT = N->getValueType(0);
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002846 switch (VT.getSimpleVT().SimpleTy) {
2847 default: return NULL;
2848 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2849 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2850 case MVT::v2f32:
Jim Grosbach4640c812012-04-11 16:53:25 +00002851 // vzip.32 Dd, Dm is a pseudo-instruction expanded to vtrn.32 Dd, Dm.
2852 case MVT::v2i32: Opc = ARM::VTRNd32; break;
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002853 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2854 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2855 case MVT::v4f32:
2856 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2857 }
Evan Cheng3da64f762010-04-16 05:46:06 +00002858 SDValue Pred = getAL(CurDAG);
Evan Chenga33fc862009-11-21 06:21:52 +00002859 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2860 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
Michael Liaob53d8962013-04-19 22:22:57 +00002861 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops);
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002862 }
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002863 case ARMISD::VUZP: {
2864 unsigned Opc = 0;
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002865 EVT VT = N->getValueType(0);
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002866 switch (VT.getSimpleVT().SimpleTy) {
2867 default: return NULL;
2868 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2869 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2870 case MVT::v2f32:
Jim Grosbach6e536de2012-04-11 17:40:18 +00002871 // vuzp.32 Dd, Dm is a pseudo-instruction expanded to vtrn.32 Dd, Dm.
2872 case MVT::v2i32: Opc = ARM::VTRNd32; break;
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002873 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2874 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2875 case MVT::v4f32:
2876 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2877 }
Evan Cheng3da64f762010-04-16 05:46:06 +00002878 SDValue Pred = getAL(CurDAG);
Evan Chenga33fc862009-11-21 06:21:52 +00002879 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2880 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
Michael Liaob53d8962013-04-19 22:22:57 +00002881 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops);
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002882 }
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002883 case ARMISD::VTRN: {
2884 unsigned Opc = 0;
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002885 EVT VT = N->getValueType(0);
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002886 switch (VT.getSimpleVT().SimpleTy) {
2887 default: return NULL;
2888 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2889 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2890 case MVT::v2f32:
2891 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2892 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2893 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2894 case MVT::v4f32:
2895 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2896 }
Evan Cheng3da64f762010-04-16 05:46:06 +00002897 SDValue Pred = getAL(CurDAG);
Evan Chenga33fc862009-11-21 06:21:52 +00002898 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2899 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
Michael Liaob53d8962013-04-19 22:22:57 +00002900 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops);
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002901 }
Bob Wilsond8a9a042010-06-04 00:04:02 +00002902 case ARMISD::BUILD_VECTOR: {
2903 EVT VecVT = N->getValueType(0);
2904 EVT EltVT = VecVT.getVectorElementType();
2905 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sands14627772010-11-03 12:17:33 +00002906 if (EltVT == MVT::f64) {
Bob Wilsond8a9a042010-06-04 00:04:02 +00002907 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
Weiming Zhao95782222012-11-17 00:23:35 +00002908 return createDRegPairNode(VecVT, N->getOperand(0), N->getOperand(1));
Bob Wilsond8a9a042010-06-04 00:04:02 +00002909 }
Duncan Sands14627772010-11-03 12:17:33 +00002910 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilsond8a9a042010-06-04 00:04:02 +00002911 if (NumElts == 2)
Weiming Zhao95782222012-11-17 00:23:35 +00002912 return createSRegPairNode(VecVT, N->getOperand(0), N->getOperand(1));
Bob Wilsond8a9a042010-06-04 00:04:02 +00002913 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
Weiming Zhao95782222012-11-17 00:23:35 +00002914 return createQuadSRegsNode(VecVT, N->getOperand(0), N->getOperand(1),
Bob Wilsond8a9a042010-06-04 00:04:02 +00002915 N->getOperand(2), N->getOperand(3));
2916 }
Bob Wilsone0636a72009-08-26 17:39:53 +00002917
Bob Wilson2d790df2010-11-28 06:51:26 +00002918 case ARMISD::VLD2DUP: {
Craig Topper01736f82012-05-24 05:17:00 +00002919 static const uint16_t Opcodes[] = { ARM::VLD2DUPd8, ARM::VLD2DUPd16,
2920 ARM::VLD2DUPd32 };
Bob Wilson06fce872011-02-07 17:43:21 +00002921 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilson2d790df2010-11-28 06:51:26 +00002922 }
2923
Bob Wilson77ab1652010-11-29 19:35:29 +00002924 case ARMISD::VLD3DUP: {
Craig Topper01736f82012-05-24 05:17:00 +00002925 static const uint16_t Opcodes[] = { ARM::VLD3DUPd8Pseudo,
2926 ARM::VLD3DUPd16Pseudo,
2927 ARM::VLD3DUPd32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00002928 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson77ab1652010-11-29 19:35:29 +00002929 }
2930
Bob Wilson431ac4ef2010-11-30 00:00:35 +00002931 case ARMISD::VLD4DUP: {
Craig Topper01736f82012-05-24 05:17:00 +00002932 static const uint16_t Opcodes[] = { ARM::VLD4DUPd8Pseudo,
2933 ARM::VLD4DUPd16Pseudo,
2934 ARM::VLD4DUPd32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00002935 return SelectVLDDup(N, false, 4, Opcodes);
2936 }
2937
2938 case ARMISD::VLD2DUP_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002939 static const uint16_t Opcodes[] = { ARM::VLD2DUPd8wb_fixed,
2940 ARM::VLD2DUPd16wb_fixed,
2941 ARM::VLD2DUPd32wb_fixed };
Bob Wilson06fce872011-02-07 17:43:21 +00002942 return SelectVLDDup(N, true, 2, Opcodes);
2943 }
2944
2945 case ARMISD::VLD3DUP_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002946 static const uint16_t Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD,
2947 ARM::VLD3DUPd16Pseudo_UPD,
2948 ARM::VLD3DUPd32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002949 return SelectVLDDup(N, true, 3, Opcodes);
2950 }
2951
2952 case ARMISD::VLD4DUP_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002953 static const uint16_t Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD,
2954 ARM::VLD4DUPd16Pseudo_UPD,
2955 ARM::VLD4DUPd32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002956 return SelectVLDDup(N, true, 4, Opcodes);
2957 }
2958
2959 case ARMISD::VLD1_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002960 static const uint16_t DOpcodes[] = { ARM::VLD1d8wb_fixed,
2961 ARM::VLD1d16wb_fixed,
2962 ARM::VLD1d32wb_fixed,
2963 ARM::VLD1d64wb_fixed };
2964 static const uint16_t QOpcodes[] = { ARM::VLD1q8wb_fixed,
2965 ARM::VLD1q16wb_fixed,
2966 ARM::VLD1q32wb_fixed,
2967 ARM::VLD1q64wb_fixed };
Bob Wilson06fce872011-02-07 17:43:21 +00002968 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2969 }
2970
2971 case ARMISD::VLD2_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002972 static const uint16_t DOpcodes[] = { ARM::VLD2d8wb_fixed,
2973 ARM::VLD2d16wb_fixed,
2974 ARM::VLD2d32wb_fixed,
2975 ARM::VLD1q64wb_fixed};
2976 static const uint16_t QOpcodes[] = { ARM::VLD2q8PseudoWB_fixed,
2977 ARM::VLD2q16PseudoWB_fixed,
2978 ARM::VLD2q32PseudoWB_fixed };
Bob Wilson06fce872011-02-07 17:43:21 +00002979 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2980 }
2981
2982 case ARMISD::VLD3_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002983 static const uint16_t DOpcodes[] = { ARM::VLD3d8Pseudo_UPD,
2984 ARM::VLD3d16Pseudo_UPD,
2985 ARM::VLD3d32Pseudo_UPD,
2986 ARM::VLD1q64wb_fixed};
2987 static const uint16_t QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2988 ARM::VLD3q16Pseudo_UPD,
2989 ARM::VLD3q32Pseudo_UPD };
2990 static const uint16_t QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2991 ARM::VLD3q16oddPseudo_UPD,
2992 ARM::VLD3q32oddPseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002993 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2994 }
2995
2996 case ARMISD::VLD4_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002997 static const uint16_t DOpcodes[] = { ARM::VLD4d8Pseudo_UPD,
2998 ARM::VLD4d16Pseudo_UPD,
2999 ARM::VLD4d32Pseudo_UPD,
3000 ARM::VLD1q64wb_fixed};
3001 static const uint16_t QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
3002 ARM::VLD4q16Pseudo_UPD,
3003 ARM::VLD4q32Pseudo_UPD };
3004 static const uint16_t QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
3005 ARM::VLD4q16oddPseudo_UPD,
3006 ARM::VLD4q32oddPseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00003007 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
3008 }
3009
3010 case ARMISD::VLD2LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00003011 static const uint16_t DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD,
3012 ARM::VLD2LNd16Pseudo_UPD,
3013 ARM::VLD2LNd32Pseudo_UPD };
3014 static const uint16_t QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
3015 ARM::VLD2LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00003016 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
3017 }
3018
3019 case ARMISD::VLD3LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00003020 static const uint16_t DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD,
3021 ARM::VLD3LNd16Pseudo_UPD,
3022 ARM::VLD3LNd32Pseudo_UPD };
3023 static const uint16_t QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
3024 ARM::VLD3LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00003025 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
3026 }
3027
3028 case ARMISD::VLD4LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00003029 static const uint16_t DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD,
3030 ARM::VLD4LNd16Pseudo_UPD,
3031 ARM::VLD4LNd32Pseudo_UPD };
3032 static const uint16_t QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
3033 ARM::VLD4LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00003034 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
3035 }
3036
3037 case ARMISD::VST1_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00003038 static const uint16_t DOpcodes[] = { ARM::VST1d8wb_fixed,
3039 ARM::VST1d16wb_fixed,
3040 ARM::VST1d32wb_fixed,
3041 ARM::VST1d64wb_fixed };
3042 static const uint16_t QOpcodes[] = { ARM::VST1q8wb_fixed,
3043 ARM::VST1q16wb_fixed,
3044 ARM::VST1q32wb_fixed,
3045 ARM::VST1q64wb_fixed };
Bob Wilson06fce872011-02-07 17:43:21 +00003046 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
3047 }
3048
3049 case ARMISD::VST2_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00003050 static const uint16_t DOpcodes[] = { ARM::VST2d8wb_fixed,
3051 ARM::VST2d16wb_fixed,
3052 ARM::VST2d32wb_fixed,
3053 ARM::VST1q64wb_fixed};
3054 static const uint16_t QOpcodes[] = { ARM::VST2q8PseudoWB_fixed,
3055 ARM::VST2q16PseudoWB_fixed,
3056 ARM::VST2q32PseudoWB_fixed };
Bob Wilson06fce872011-02-07 17:43:21 +00003057 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
3058 }
3059
3060 case ARMISD::VST3_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00003061 static const uint16_t DOpcodes[] = { ARM::VST3d8Pseudo_UPD,
3062 ARM::VST3d16Pseudo_UPD,
3063 ARM::VST3d32Pseudo_UPD,
3064 ARM::VST1d64TPseudoWB_fixed};
3065 static const uint16_t QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
3066 ARM::VST3q16Pseudo_UPD,
3067 ARM::VST3q32Pseudo_UPD };
3068 static const uint16_t QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
3069 ARM::VST3q16oddPseudo_UPD,
3070 ARM::VST3q32oddPseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00003071 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
3072 }
3073
3074 case ARMISD::VST4_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00003075 static const uint16_t DOpcodes[] = { ARM::VST4d8Pseudo_UPD,
3076 ARM::VST4d16Pseudo_UPD,
3077 ARM::VST4d32Pseudo_UPD,
3078 ARM::VST1d64QPseudoWB_fixed};
3079 static const uint16_t QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
3080 ARM::VST4q16Pseudo_UPD,
3081 ARM::VST4q32Pseudo_UPD };
3082 static const uint16_t QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
3083 ARM::VST4q16oddPseudo_UPD,
3084 ARM::VST4q32oddPseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00003085 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
3086 }
3087
3088 case ARMISD::VST2LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00003089 static const uint16_t DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD,
3090 ARM::VST2LNd16Pseudo_UPD,
3091 ARM::VST2LNd32Pseudo_UPD };
3092 static const uint16_t QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
3093 ARM::VST2LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00003094 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
3095 }
3096
3097 case ARMISD::VST3LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00003098 static const uint16_t DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD,
3099 ARM::VST3LNd16Pseudo_UPD,
3100 ARM::VST3LNd32Pseudo_UPD };
3101 static const uint16_t QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
3102 ARM::VST3LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00003103 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
3104 }
3105
3106 case ARMISD::VST4LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00003107 static const uint16_t DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD,
3108 ARM::VST4LNd16Pseudo_UPD,
3109 ARM::VST4LNd32Pseudo_UPD };
3110 static const uint16_t QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
3111 ARM::VST4LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00003112 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson431ac4ef2010-11-30 00:00:35 +00003113 }
3114
Bob Wilsone0636a72009-08-26 17:39:53 +00003115 case ISD::INTRINSIC_VOID:
3116 case ISD::INTRINSIC_W_CHAIN: {
3117 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilsone0636a72009-08-26 17:39:53 +00003118 switch (IntNo) {
3119 default:
Bob Wilsonf765e1f2010-05-06 16:05:26 +00003120 break;
Bob Wilsone0636a72009-08-26 17:39:53 +00003121
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003122 case Intrinsic::arm_ldrexd: {
3123 SDValue MemAddr = N->getOperand(2);
Andrew Trickef9de2a2013-05-25 02:42:55 +00003124 SDLoc dl(N);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003125 SDValue Chain = N->getOperand(0);
3126
Weiming Zhao8f56f882012-11-16 21:55:34 +00003127 bool isThumb = Subtarget->isThumb() && Subtarget->hasThumb2();
3128 unsigned NewOpc = isThumb ? ARM::t2LDREXD :ARM::LDREXD;
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003129
3130 // arm_ldrexd returns a i64 value in {i32, i32}
3131 std::vector<EVT> ResTys;
Weiming Zhao8f56f882012-11-16 21:55:34 +00003132 if (isThumb) {
3133 ResTys.push_back(MVT::i32);
3134 ResTys.push_back(MVT::i32);
3135 } else
3136 ResTys.push_back(MVT::Untyped);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003137 ResTys.push_back(MVT::Other);
3138
Weiming Zhao8f56f882012-11-16 21:55:34 +00003139 // Place arguments in the right order.
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003140 SmallVector<SDValue, 7> Ops;
3141 Ops.push_back(MemAddr);
3142 Ops.push_back(getAL(CurDAG));
3143 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
3144 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00003145 SDNode *Ld = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003146 // Transfer memoperands.
3147 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
3148 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
3149 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
3150
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003151 // Remap uses.
Lang Hamesbe3d9712013-03-09 22:56:09 +00003152 SDValue OutChain = isThumb ? SDValue(Ld, 2) : SDValue(Ld, 1);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003153 if (!SDValue(N, 0).use_empty()) {
Weiming Zhao8f56f882012-11-16 21:55:34 +00003154 SDValue Result;
3155 if (isThumb)
3156 Result = SDValue(Ld, 0);
3157 else {
3158 SDValue SubRegIdx = CurDAG->getTargetConstant(ARM::gsub_0, MVT::i32);
3159 SDNode *ResNode = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Lang Hamesbe3d9712013-03-09 22:56:09 +00003160 dl, MVT::i32, SDValue(Ld, 0), SubRegIdx);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003161 Result = SDValue(ResNode,0);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003162 }
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003163 ReplaceUses(SDValue(N, 0), Result);
3164 }
3165 if (!SDValue(N, 1).use_empty()) {
Weiming Zhao8f56f882012-11-16 21:55:34 +00003166 SDValue Result;
3167 if (isThumb)
3168 Result = SDValue(Ld, 1);
3169 else {
3170 SDValue SubRegIdx = CurDAG->getTargetConstant(ARM::gsub_1, MVT::i32);
3171 SDNode *ResNode = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Lang Hamesbe3d9712013-03-09 22:56:09 +00003172 dl, MVT::i32, SDValue(Ld, 0), SubRegIdx);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003173 Result = SDValue(ResNode,0);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003174 }
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003175 ReplaceUses(SDValue(N, 1), Result);
3176 }
Lang Hamesbe3d9712013-03-09 22:56:09 +00003177 ReplaceUses(SDValue(N, 2), OutChain);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003178 return NULL;
3179 }
3180
3181 case Intrinsic::arm_strexd: {
Andrew Trickef9de2a2013-05-25 02:42:55 +00003182 SDLoc dl(N);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003183 SDValue Chain = N->getOperand(0);
3184 SDValue Val0 = N->getOperand(2);
3185 SDValue Val1 = N->getOperand(3);
3186 SDValue MemAddr = N->getOperand(4);
3187
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003188 // Store exclusive double return a i32 value which is the return status
3189 // of the issued store.
Benjamin Kramerfdf362b2013-03-07 20:33:29 +00003190 EVT ResTys[] = { MVT::i32, MVT::Other };
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003191
Weiming Zhao8f56f882012-11-16 21:55:34 +00003192 bool isThumb = Subtarget->isThumb() && Subtarget->hasThumb2();
3193 // Place arguments in the right order.
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003194 SmallVector<SDValue, 7> Ops;
Weiming Zhao8f56f882012-11-16 21:55:34 +00003195 if (isThumb) {
3196 Ops.push_back(Val0);
3197 Ops.push_back(Val1);
3198 } else
3199 // arm_strexd uses GPRPair.
3200 Ops.push_back(SDValue(createGPRPairNode(MVT::Untyped, Val0, Val1), 0));
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003201 Ops.push_back(MemAddr);
3202 Ops.push_back(getAL(CurDAG));
3203 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
3204 Ops.push_back(Chain);
3205
Weiming Zhao8f56f882012-11-16 21:55:34 +00003206 unsigned NewOpc = isThumb ? ARM::t2STREXD : ARM::STREXD;
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003207
Michael Liaob53d8962013-04-19 22:22:57 +00003208 SDNode *St = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003209 // Transfer memoperands.
3210 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
3211 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
3212 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
3213
3214 return St;
3215 }
3216
Bob Wilson340861d2010-03-23 05:25:43 +00003217 case Intrinsic::arm_neon_vld1: {
Craig Topper01736f82012-05-24 05:17:00 +00003218 static const uint16_t DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
3219 ARM::VLD1d32, ARM::VLD1d64 };
3220 static const uint16_t QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
3221 ARM::VLD1q32, ARM::VLD1q64};
Bob Wilson06fce872011-02-07 17:43:21 +00003222 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson340861d2010-03-23 05:25:43 +00003223 }
3224
Bob Wilsone0636a72009-08-26 17:39:53 +00003225 case Intrinsic::arm_neon_vld2: {
Craig Topper01736f82012-05-24 05:17:00 +00003226 static const uint16_t DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
3227 ARM::VLD2d32, ARM::VLD1q64 };
3228 static const uint16_t QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
3229 ARM::VLD2q32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003230 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilsone0636a72009-08-26 17:39:53 +00003231 }
3232
3233 case Intrinsic::arm_neon_vld3: {
Craig Topper01736f82012-05-24 05:17:00 +00003234 static const uint16_t DOpcodes[] = { ARM::VLD3d8Pseudo,
3235 ARM::VLD3d16Pseudo,
3236 ARM::VLD3d32Pseudo,
3237 ARM::VLD1d64TPseudo };
3238 static const uint16_t QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
3239 ARM::VLD3q16Pseudo_UPD,
3240 ARM::VLD3q32Pseudo_UPD };
3241 static const uint16_t QOpcodes1[] = { ARM::VLD3q8oddPseudo,
3242 ARM::VLD3q16oddPseudo,
3243 ARM::VLD3q32oddPseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003244 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilsone0636a72009-08-26 17:39:53 +00003245 }
3246
3247 case Intrinsic::arm_neon_vld4: {
Craig Topper01736f82012-05-24 05:17:00 +00003248 static const uint16_t DOpcodes[] = { ARM::VLD4d8Pseudo,
3249 ARM::VLD4d16Pseudo,
3250 ARM::VLD4d32Pseudo,
3251 ARM::VLD1d64QPseudo };
3252 static const uint16_t QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
3253 ARM::VLD4q16Pseudo_UPD,
3254 ARM::VLD4q32Pseudo_UPD };
3255 static const uint16_t QOpcodes1[] = { ARM::VLD4q8oddPseudo,
3256 ARM::VLD4q16oddPseudo,
3257 ARM::VLD4q32oddPseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003258 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilsone0636a72009-08-26 17:39:53 +00003259 }
3260
Bob Wilsonda9817c2009-09-01 04:26:28 +00003261 case Intrinsic::arm_neon_vld2lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003262 static const uint16_t DOpcodes[] = { ARM::VLD2LNd8Pseudo,
3263 ARM::VLD2LNd16Pseudo,
3264 ARM::VLD2LNd32Pseudo };
3265 static const uint16_t QOpcodes[] = { ARM::VLD2LNq16Pseudo,
3266 ARM::VLD2LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003267 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilsonda9817c2009-09-01 04:26:28 +00003268 }
3269
3270 case Intrinsic::arm_neon_vld3lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003271 static const uint16_t DOpcodes[] = { ARM::VLD3LNd8Pseudo,
3272 ARM::VLD3LNd16Pseudo,
3273 ARM::VLD3LNd32Pseudo };
3274 static const uint16_t QOpcodes[] = { ARM::VLD3LNq16Pseudo,
3275 ARM::VLD3LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003276 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilsonda9817c2009-09-01 04:26:28 +00003277 }
3278
3279 case Intrinsic::arm_neon_vld4lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003280 static const uint16_t DOpcodes[] = { ARM::VLD4LNd8Pseudo,
3281 ARM::VLD4LNd16Pseudo,
3282 ARM::VLD4LNd32Pseudo };
3283 static const uint16_t QOpcodes[] = { ARM::VLD4LNq16Pseudo,
3284 ARM::VLD4LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003285 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilsonda9817c2009-09-01 04:26:28 +00003286 }
3287
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00003288 case Intrinsic::arm_neon_vst1: {
Craig Topper01736f82012-05-24 05:17:00 +00003289 static const uint16_t DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
3290 ARM::VST1d32, ARM::VST1d64 };
3291 static const uint16_t QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
3292 ARM::VST1q32, ARM::VST1q64 };
Bob Wilson06fce872011-02-07 17:43:21 +00003293 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00003294 }
3295
Bob Wilsone0636a72009-08-26 17:39:53 +00003296 case Intrinsic::arm_neon_vst2: {
Craig Topper01736f82012-05-24 05:17:00 +00003297 static const uint16_t DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
3298 ARM::VST2d32, ARM::VST1q64 };
3299 static uint16_t QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
3300 ARM::VST2q32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003301 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilsone0636a72009-08-26 17:39:53 +00003302 }
3303
3304 case Intrinsic::arm_neon_vst3: {
Craig Topper01736f82012-05-24 05:17:00 +00003305 static const uint16_t DOpcodes[] = { ARM::VST3d8Pseudo,
3306 ARM::VST3d16Pseudo,
3307 ARM::VST3d32Pseudo,
3308 ARM::VST1d64TPseudo };
3309 static const uint16_t QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
3310 ARM::VST3q16Pseudo_UPD,
3311 ARM::VST3q32Pseudo_UPD };
3312 static const uint16_t QOpcodes1[] = { ARM::VST3q8oddPseudo,
3313 ARM::VST3q16oddPseudo,
3314 ARM::VST3q32oddPseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003315 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilsone0636a72009-08-26 17:39:53 +00003316 }
3317
3318 case Intrinsic::arm_neon_vst4: {
Craig Topper01736f82012-05-24 05:17:00 +00003319 static const uint16_t DOpcodes[] = { ARM::VST4d8Pseudo,
3320 ARM::VST4d16Pseudo,
3321 ARM::VST4d32Pseudo,
3322 ARM::VST1d64QPseudo };
3323 static const uint16_t QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
3324 ARM::VST4q16Pseudo_UPD,
3325 ARM::VST4q32Pseudo_UPD };
3326 static const uint16_t QOpcodes1[] = { ARM::VST4q8oddPseudo,
3327 ARM::VST4q16oddPseudo,
3328 ARM::VST4q32oddPseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003329 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilsone0636a72009-08-26 17:39:53 +00003330 }
Bob Wilsond7797752009-09-01 18:51:56 +00003331
3332 case Intrinsic::arm_neon_vst2lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003333 static const uint16_t DOpcodes[] = { ARM::VST2LNd8Pseudo,
3334 ARM::VST2LNd16Pseudo,
3335 ARM::VST2LNd32Pseudo };
3336 static const uint16_t QOpcodes[] = { ARM::VST2LNq16Pseudo,
3337 ARM::VST2LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003338 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilsond7797752009-09-01 18:51:56 +00003339 }
3340
3341 case Intrinsic::arm_neon_vst3lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003342 static const uint16_t DOpcodes[] = { ARM::VST3LNd8Pseudo,
3343 ARM::VST3LNd16Pseudo,
3344 ARM::VST3LNd32Pseudo };
3345 static const uint16_t QOpcodes[] = { ARM::VST3LNq16Pseudo,
3346 ARM::VST3LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003347 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilsond7797752009-09-01 18:51:56 +00003348 }
3349
3350 case Intrinsic::arm_neon_vst4lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003351 static const uint16_t DOpcodes[] = { ARM::VST4LNd8Pseudo,
3352 ARM::VST4LNd16Pseudo,
3353 ARM::VST4LNd32Pseudo };
3354 static const uint16_t QOpcodes[] = { ARM::VST4LNq16Pseudo,
3355 ARM::VST4LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003356 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilsond7797752009-09-01 18:51:56 +00003357 }
Bob Wilsone0636a72009-08-26 17:39:53 +00003358 }
Bob Wilsonf765e1f2010-05-06 16:05:26 +00003359 break;
Bob Wilsone0636a72009-08-26 17:39:53 +00003360 }
Evan Chengd85631e2010-05-05 18:28:36 +00003361
Bob Wilson3ed511b2010-07-06 23:36:25 +00003362 case ISD::INTRINSIC_WO_CHAIN: {
3363 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
3364 switch (IntNo) {
3365 default:
3366 break;
3367
3368 case Intrinsic::arm_neon_vtbl2:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003369 return SelectVTBL(N, false, 2, ARM::VTBL2);
Bob Wilson3ed511b2010-07-06 23:36:25 +00003370 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00003371 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilson3ed511b2010-07-06 23:36:25 +00003372 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00003373 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson5bc8a792010-07-07 00:08:54 +00003374
3375 case Intrinsic::arm_neon_vtbx2:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003376 return SelectVTBL(N, true, 2, ARM::VTBX2);
Bob Wilson5bc8a792010-07-07 00:08:54 +00003377 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00003378 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson5bc8a792010-07-07 00:08:54 +00003379 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00003380 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilson3ed511b2010-07-06 23:36:25 +00003381 }
3382 break;
3383 }
3384
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003385 case ARMISD::VTBL1: {
Andrew Trickef9de2a2013-05-25 02:42:55 +00003386 SDLoc dl(N);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003387 EVT VT = N->getValueType(0);
3388 SmallVector<SDValue, 6> Ops;
3389
3390 Ops.push_back(N->getOperand(0));
3391 Ops.push_back(N->getOperand(1));
3392 Ops.push_back(getAL(CurDAG)); // Predicate
3393 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
Michael Liaob53d8962013-04-19 22:22:57 +00003394 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003395 }
3396 case ARMISD::VTBL2: {
Andrew Trickef9de2a2013-05-25 02:42:55 +00003397 SDLoc dl(N);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003398 EVT VT = N->getValueType(0);
3399
3400 // Form a REG_SEQUENCE to force register allocation.
3401 SDValue V0 = N->getOperand(0);
3402 SDValue V1 = N->getOperand(1);
Weiming Zhao95782222012-11-17 00:23:35 +00003403 SDValue RegSeq = SDValue(createDRegPairNode(MVT::v16i8, V0, V1), 0);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003404
3405 SmallVector<SDValue, 6> Ops;
3406 Ops.push_back(RegSeq);
3407 Ops.push_back(N->getOperand(2));
3408 Ops.push_back(getAL(CurDAG)); // Predicate
3409 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
Michael Liaob53d8962013-04-19 22:22:57 +00003410 return CurDAG->getMachineNode(ARM::VTBL2, dl, VT, Ops);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003411 }
3412
Bob Wilsonf765e1f2010-05-06 16:05:26 +00003413 case ISD::CONCAT_VECTORS:
Evan Chengd85631e2010-05-05 18:28:36 +00003414 return SelectConcatVector(N);
Eli Friedmanc3f9c4a2011-08-31 00:31:29 +00003415
3416 case ARMISD::ATOMOR64_DAG:
3417 return SelectAtomic64(N, ARM::ATOMOR6432);
3418 case ARMISD::ATOMXOR64_DAG:
3419 return SelectAtomic64(N, ARM::ATOMXOR6432);
3420 case ARMISD::ATOMADD64_DAG:
3421 return SelectAtomic64(N, ARM::ATOMADD6432);
3422 case ARMISD::ATOMSUB64_DAG:
3423 return SelectAtomic64(N, ARM::ATOMSUB6432);
3424 case ARMISD::ATOMNAND64_DAG:
3425 return SelectAtomic64(N, ARM::ATOMNAND6432);
3426 case ARMISD::ATOMAND64_DAG:
3427 return SelectAtomic64(N, ARM::ATOMAND6432);
3428 case ARMISD::ATOMSWAP64_DAG:
3429 return SelectAtomic64(N, ARM::ATOMSWAP6432);
Eli Friedman1ccecbb2011-08-31 17:52:22 +00003430 case ARMISD::ATOMCMPXCHG64_DAG:
3431 return SelectAtomic64(N, ARM::ATOMCMPXCHG6432);
Silviu Baranga93aefa52012-11-29 14:41:25 +00003432
3433 case ARMISD::ATOMMIN64_DAG:
3434 return SelectAtomic64(N, ARM::ATOMMIN6432);
3435 case ARMISD::ATOMUMIN64_DAG:
3436 return SelectAtomic64(N, ARM::ATOMUMIN6432);
3437 case ARMISD::ATOMMAX64_DAG:
3438 return SelectAtomic64(N, ARM::ATOMMAX6432);
3439 case ARMISD::ATOMUMAX64_DAG:
3440 return SelectAtomic64(N, ARM::ATOMUMAX6432);
Evan Chengd85631e2010-05-05 18:28:36 +00003441 }
Evan Chengd5021732008-12-10 21:54:21 +00003442
Dan Gohmanea6f91f2010-01-05 01:24:18 +00003443 return SelectCode(N);
Evan Cheng10043e22007-01-19 07:51:42 +00003444}
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00003445
Weiming Zhaoc5987002013-02-14 18:10:21 +00003446SDNode *ARMDAGToDAGISel::SelectInlineAsm(SDNode *N){
3447 std::vector<SDValue> AsmNodeOperands;
3448 unsigned Flag, Kind;
3449 bool Changed = false;
3450 unsigned NumOps = N->getNumOperands();
3451
3452 ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(
3453 N->getOperand(InlineAsm::Op_AsmString));
3454 StringRef AsmString = StringRef(S->getSymbol());
3455
3456 // Normally, i64 data is bounded to two arbitrary GRPs for "%r" constraint.
3457 // However, some instrstions (e.g. ldrexd/strexd in ARM mode) require
3458 // (even/even+1) GPRs and use %n and %Hn to refer to the individual regs
3459 // respectively. Since there is no constraint to explicitly specify a
3460 // reg pair, we search %H operand inside the asm string. If it is found, the
3461 // transformation below enforces a GPRPair reg class for "%r" for 64-bit data.
3462 if (AsmString.find(":H}") == StringRef::npos)
3463 return NULL;
3464
Andrew Trickef9de2a2013-05-25 02:42:55 +00003465 SDLoc dl(N);
Weiming Zhaoc5987002013-02-14 18:10:21 +00003466 SDValue Glue = N->getOperand(NumOps-1);
3467
3468 // Glue node will be appended late.
3469 for(unsigned i = 0; i < NumOps -1; ++i) {
3470 SDValue op = N->getOperand(i);
3471 AsmNodeOperands.push_back(op);
3472
3473 if (i < InlineAsm::Op_FirstOperand)
3474 continue;
3475
3476 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(i))) {
3477 Flag = C->getZExtValue();
3478 Kind = InlineAsm::getKind(Flag);
3479 }
3480 else
3481 continue;
3482
3483 if (Kind != InlineAsm::Kind_RegUse && Kind != InlineAsm::Kind_RegDef
3484 && Kind != InlineAsm::Kind_RegDefEarlyClobber)
3485 continue;
3486
3487 unsigned RegNum = InlineAsm::getNumOperandRegisters(Flag);
3488 unsigned RC;
3489 bool HasRC = InlineAsm::hasRegClassConstraint(Flag, RC);
3490 if (!HasRC || RC != ARM::GPRRegClassID || RegNum != 2)
3491 continue;
3492
3493 assert((i+2 < NumOps-1) && "Invalid number of operands in inline asm");
3494 SDValue V0 = N->getOperand(i+1);
3495 SDValue V1 = N->getOperand(i+2);
3496 unsigned Reg0 = cast<RegisterSDNode>(V0)->getReg();
3497 unsigned Reg1 = cast<RegisterSDNode>(V1)->getReg();
3498 SDValue PairedReg;
3499 MachineRegisterInfo &MRI = MF->getRegInfo();
3500
3501 if (Kind == InlineAsm::Kind_RegDef ||
3502 Kind == InlineAsm::Kind_RegDefEarlyClobber) {
3503 // Replace the two GPRs with 1 GPRPair and copy values from GPRPair to
3504 // the original GPRs.
3505
3506 unsigned GPVR = MRI.createVirtualRegister(&ARM::GPRPairRegClass);
3507 PairedReg = CurDAG->getRegister(GPVR, MVT::Untyped);
3508 SDValue Chain = SDValue(N,0);
3509
3510 SDNode *GU = N->getGluedUser();
3511 SDValue RegCopy = CurDAG->getCopyFromReg(Chain, dl, GPVR, MVT::Untyped,
3512 Chain.getValue(1));
3513
3514 // Extract values from a GPRPair reg and copy to the original GPR reg.
3515 SDValue Sub0 = CurDAG->getTargetExtractSubreg(ARM::gsub_0, dl, MVT::i32,
3516 RegCopy);
3517 SDValue Sub1 = CurDAG->getTargetExtractSubreg(ARM::gsub_1, dl, MVT::i32,
3518 RegCopy);
3519 SDValue T0 = CurDAG->getCopyToReg(Sub0, dl, Reg0, Sub0,
3520 RegCopy.getValue(1));
3521 SDValue T1 = CurDAG->getCopyToReg(Sub1, dl, Reg1, Sub1, T0.getValue(1));
3522
3523 // Update the original glue user.
3524 std::vector<SDValue> Ops(GU->op_begin(), GU->op_end()-1);
3525 Ops.push_back(T1.getValue(1));
3526 CurDAG->UpdateNodeOperands(GU, &Ops[0], Ops.size());
3527 GU = T1.getNode();
3528 }
3529 else {
3530 // For Kind == InlineAsm::Kind_RegUse, we first copy two GPRs into a
3531 // GPRPair and then pass the GPRPair to the inline asm.
3532 SDValue Chain = AsmNodeOperands[InlineAsm::Op_InputChain];
3533
3534 // As REG_SEQ doesn't take RegisterSDNode, we copy them first.
3535 SDValue T0 = CurDAG->getCopyFromReg(Chain, dl, Reg0, MVT::i32,
3536 Chain.getValue(1));
3537 SDValue T1 = CurDAG->getCopyFromReg(Chain, dl, Reg1, MVT::i32,
3538 T0.getValue(1));
3539 SDValue Pair = SDValue(createGPRPairNode(MVT::Untyped, T0, T1), 0);
3540
3541 // Copy REG_SEQ into a GPRPair-typed VR and replace the original two
3542 // i32 VRs of inline asm with it.
3543 unsigned GPVR = MRI.createVirtualRegister(&ARM::GPRPairRegClass);
3544 PairedReg = CurDAG->getRegister(GPVR, MVT::Untyped);
3545 Chain = CurDAG->getCopyToReg(T1, dl, GPVR, Pair, T1.getValue(1));
3546
3547 AsmNodeOperands[InlineAsm::Op_InputChain] = Chain;
3548 Glue = Chain.getValue(1);
3549 }
3550
3551 Changed = true;
3552
3553 if(PairedReg.getNode()) {
3554 Flag = InlineAsm::getFlagWord(Kind, 1 /* RegNum*/);
3555 Flag = InlineAsm::getFlagWordForRegClass(Flag, ARM::GPRPairRegClassID);
3556 // Replace the current flag.
3557 AsmNodeOperands[AsmNodeOperands.size() -1] = CurDAG->getTargetConstant(
3558 Flag, MVT::i32);
3559 // Add the new register node and skip the original two GPRs.
3560 AsmNodeOperands.push_back(PairedReg);
3561 // Skip the next two GPRs.
3562 i += 2;
3563 }
3564 }
3565
3566 AsmNodeOperands.push_back(Glue);
3567 if (!Changed)
3568 return NULL;
3569
Andrew Trickef9de2a2013-05-25 02:42:55 +00003570 SDValue New = CurDAG->getNode(ISD::INLINEASM, SDLoc(N),
Weiming Zhaoc5987002013-02-14 18:10:21 +00003571 CurDAG->getVTList(MVT::Other, MVT::Glue), &AsmNodeOperands[0],
3572 AsmNodeOperands.size());
3573 New->setNodeId(-1);
3574 return New.getNode();
3575}
3576
3577
Bob Wilsona2c462b2009-05-19 05:53:42 +00003578bool ARMDAGToDAGISel::
3579SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
3580 std::vector<SDValue> &OutOps) {
3581 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson3b515602009-10-13 20:50:28 +00003582 // Require the address to be in a register. That is safe for all ARM
3583 // variants and it is hard to do anything much smarter without knowing
3584 // how the operand is used.
3585 OutOps.push_back(Op);
Bob Wilsona2c462b2009-05-19 05:53:42 +00003586 return false;
3587}
3588
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00003589/// createARMISelDag - This pass converts a legalized DAG into a
3590/// ARM-specific DAG, ready for instruction scheduling.
3591///
Bob Wilson2dd957f2009-09-28 14:30:20 +00003592FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
3593 CodeGenOpt::Level OptLevel) {
3594 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00003595}