Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1 | //===-- ARMISelLowering.cpp - ARM DAG Lowering Implementation -------------===// |
2 | // | ||||
3 | // The LLVM Compiler Infrastructure | ||||
4 | // | ||||
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
6 | // License. See LICENSE.TXT for details. | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7 | // |
8 | //===----------------------------------------------------------------------===// | ||||
9 | // | ||||
10 | // This file defines the interfaces that ARM uses to lower LLVM code into a | ||||
11 | // selection DAG. | ||||
12 | // | ||||
13 | //===----------------------------------------------------------------------===// | ||||
14 | |||||
Craig Topper | 188ed9d | 2012-03-17 07:33:42 +0000 | [diff] [blame] | 15 | #include "ARMISelLowering.h" |
Eric Christopher | 1c06917 | 2010-09-10 22:42:06 +0000 | [diff] [blame] | 16 | #include "ARMCallingConv.h" |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 17 | #include "ARMConstantPoolValue.h" |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 18 | #include "ARMMachineFunctionInfo.h" |
Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 19 | #include "ARMPerfectShuffle.h" |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 20 | #include "ARMSubtarget.h" |
21 | #include "ARMTargetMachine.h" | ||||
Chris Lattner | 4e7dfaf | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 22 | #include "ARMTargetObjectFile.h" |
Evan Cheng | a20cde3 | 2011-07-20 23:34:39 +0000 | [diff] [blame] | 23 | #include "MCTargetDesc/ARMAddressingModes.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/Statistic.h" |
25 | #include "llvm/ADT/StringExtras.h" | ||||
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/CallingConvLower.h" |
Evan Cheng | 078b0b0 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 27 | #include "llvm/CodeGen/IntrinsicLowering.h" |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/MachineBasicBlock.h" |
29 | #include "llvm/CodeGen/MachineFrameInfo.h" | ||||
30 | #include "llvm/CodeGen/MachineFunction.h" | ||||
31 | #include "llvm/CodeGen/MachineInstrBuilder.h" | ||||
Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Chris Lattner | a10fff5 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 33 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 34 | #include "llvm/CodeGen/SelectionDAG.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 35 | #include "llvm/IR/CallingConv.h" |
36 | #include "llvm/IR/Constants.h" | ||||
37 | #include "llvm/IR/Function.h" | ||||
38 | #include "llvm/IR/GlobalValue.h" | ||||
Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 39 | #include "llvm/IR/IRBuilder.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 40 | #include "llvm/IR/Instruction.h" |
41 | #include "llvm/IR/Instructions.h" | ||||
42 | #include "llvm/IR/Intrinsics.h" | ||||
43 | #include "llvm/IR/Type.h" | ||||
Bill Wendling | 46ffefc | 2010-03-09 02:46:12 +0000 | [diff] [blame] | 44 | #include "llvm/MC/MCSectionMachO.h" |
Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 45 | #include "llvm/Support/CommandLine.h" |
Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 46 | #include "llvm/Support/Debug.h" |
Torok Edwin | 6dd2730 | 2009-07-08 18:01:40 +0000 | [diff] [blame] | 47 | #include "llvm/Support/ErrorHandling.h" |
Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 48 | #include "llvm/Support/MathExtras.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 49 | #include "llvm/Target/TargetOptions.h" |
David Peixotto | c32e24a | 2013-10-17 19:49:22 +0000 | [diff] [blame] | 50 | #include <utility> |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 51 | using namespace llvm; |
52 | |||||
Chandler Carruth | 84e68b2 | 2014-04-22 02:41:26 +0000 | [diff] [blame] | 53 | #define DEBUG_TYPE "arm-isel" |
54 | |||||
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 55 | STATISTIC(NumTailCalls, "Number of tail calls"); |
Evan Cheng | 68aec14 | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 56 | STATISTIC(NumMovwMovt, "Number of GAs materialized with movw + movt"); |
Manman Ren | 9f91116 | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 57 | STATISTIC(NumLoopByVals, "Number of loops generated for byval arguments"); |
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 58 | |
Eric Christopher | 347f4c3 | 2010-12-15 23:47:29 +0000 | [diff] [blame] | 59 | cl::opt<bool> |
Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 60 | EnableARMLongCalls("arm-long-calls", cl::Hidden, |
Evan Cheng | 25f9364 | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 61 | cl::desc("Generate calls via indirect call instructions"), |
Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 62 | cl::init(false)); |
63 | |||||
Evan Cheng | f128bdc | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 64 | static cl::opt<bool> |
65 | ARMInterworking("arm-interworking", cl::Hidden, | ||||
66 | cl::desc("Enable / disable ARM interworking (for debugging only)"), | ||||
67 | cl::init(true)); | ||||
68 | |||||
Benjamin Kramer | 7ba71be | 2011-11-26 23:01:57 +0000 | [diff] [blame] | 69 | namespace { |
Cameron Zwarich | 8901978 | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 70 | class ARMCCState : public CCState { |
71 | public: | ||||
72 | ARMCCState(CallingConv::ID CC, bool isVarArg, MachineFunction &MF, | ||||
Craig Topper | b94011f | 2013-07-14 04:42:23 +0000 | [diff] [blame] | 73 | const TargetMachine &TM, SmallVectorImpl<CCValAssign> &locs, |
Cameron Zwarich | 8901978 | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 74 | LLVMContext &C, ParmContext PC) |
75 | : CCState(CC, isVarArg, MF, TM, locs, C) { | ||||
76 | assert(((PC == Call) || (PC == Prologue)) && | ||||
77 | "ARMCCState users must specify whether their context is call" | ||||
78 | "or prologue generation."); | ||||
79 | CallOrPrologue = PC; | ||||
80 | } | ||||
81 | }; | ||||
82 | } | ||||
83 | |||||
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 84 | // The APCS parameter registers. |
Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 85 | static const MCPhysReg GPRArgRegs[] = { |
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 86 | ARM::R0, ARM::R1, ARM::R2, ARM::R3 |
87 | }; | ||||
88 | |||||
Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 89 | void ARMTargetLowering::addTypeForNEON(MVT VT, MVT PromotedLdStVT, |
90 | MVT PromotedBitwiseVT) { | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 91 | if (VT != PromotedLdStVT) { |
Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 92 | setOperationAction(ISD::LOAD, VT, Promote); |
93 | AddPromotedToType (ISD::LOAD, VT, PromotedLdStVT); | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 94 | |
Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 95 | setOperationAction(ISD::STORE, VT, Promote); |
96 | AddPromotedToType (ISD::STORE, VT, PromotedLdStVT); | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 97 | } |
98 | |||||
Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 99 | MVT ElemTy = VT.getVectorElementType(); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 100 | if (ElemTy != MVT::i64 && ElemTy != MVT::f64) |
Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 101 | setOperationAction(ISD::SETCC, VT, Custom); |
102 | setOperationAction(ISD::INSERT_VECTOR_ELT, VT, Custom); | ||||
103 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, VT, Custom); | ||||
Eli Friedman | 2d4055b | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 104 | if (ElemTy == MVT::i32) { |
Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 105 | setOperationAction(ISD::SINT_TO_FP, VT, Custom); |
106 | setOperationAction(ISD::UINT_TO_FP, VT, Custom); | ||||
107 | setOperationAction(ISD::FP_TO_SINT, VT, Custom); | ||||
108 | setOperationAction(ISD::FP_TO_UINT, VT, Custom); | ||||
Eli Friedman | 2d4055b | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 109 | } else { |
Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 110 | setOperationAction(ISD::SINT_TO_FP, VT, Expand); |
111 | setOperationAction(ISD::UINT_TO_FP, VT, Expand); | ||||
112 | setOperationAction(ISD::FP_TO_SINT, VT, Expand); | ||||
113 | setOperationAction(ISD::FP_TO_UINT, VT, Expand); | ||||
Bob Wilson | 5d8cfb2 | 2009-09-16 20:20:44 +0000 | [diff] [blame] | 114 | } |
Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 115 | setOperationAction(ISD::BUILD_VECTOR, VT, Custom); |
116 | setOperationAction(ISD::VECTOR_SHUFFLE, VT, Custom); | ||||
117 | setOperationAction(ISD::CONCAT_VECTORS, VT, Legal); | ||||
118 | setOperationAction(ISD::EXTRACT_SUBVECTOR, VT, Legal); | ||||
119 | setOperationAction(ISD::SELECT, VT, Expand); | ||||
120 | setOperationAction(ISD::SELECT_CC, VT, Expand); | ||||
Jim Grosbach | 30af442 | 2012-10-12 22:59:21 +0000 | [diff] [blame] | 121 | setOperationAction(ISD::VSELECT, VT, Expand); |
Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 122 | setOperationAction(ISD::SIGN_EXTEND_INREG, VT, Expand); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 123 | if (VT.isInteger()) { |
Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 124 | setOperationAction(ISD::SHL, VT, Custom); |
125 | setOperationAction(ISD::SRA, VT, Custom); | ||||
126 | setOperationAction(ISD::SRL, VT, Custom); | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 127 | } |
128 | |||||
129 | // Promote all bit-wise operations. | ||||
130 | if (VT.isInteger() && VT != PromotedBitwiseVT) { | ||||
Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 131 | setOperationAction(ISD::AND, VT, Promote); |
132 | AddPromotedToType (ISD::AND, VT, PromotedBitwiseVT); | ||||
133 | setOperationAction(ISD::OR, VT, Promote); | ||||
134 | AddPromotedToType (ISD::OR, VT, PromotedBitwiseVT); | ||||
135 | setOperationAction(ISD::XOR, VT, Promote); | ||||
136 | AddPromotedToType (ISD::XOR, VT, PromotedBitwiseVT); | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 137 | } |
Bob Wilson | 4ed397c | 2009-09-16 00:17:28 +0000 | [diff] [blame] | 138 | |
139 | // Neon does not support vector divide/remainder operations. | ||||
Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 140 | setOperationAction(ISD::SDIV, VT, Expand); |
141 | setOperationAction(ISD::UDIV, VT, Expand); | ||||
142 | setOperationAction(ISD::FDIV, VT, Expand); | ||||
143 | setOperationAction(ISD::SREM, VT, Expand); | ||||
144 | setOperationAction(ISD::UREM, VT, Expand); | ||||
145 | setOperationAction(ISD::FREM, VT, Expand); | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 146 | } |
147 | |||||
Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 148 | void ARMTargetLowering::addDRTypeForNEON(MVT VT) { |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 149 | addRegisterClass(VT, &ARM::DPRRegClass); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 150 | addTypeForNEON(VT, MVT::f64, MVT::v2i32); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 151 | } |
152 | |||||
Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 153 | void ARMTargetLowering::addQRTypeForNEON(MVT VT) { |
Jakob Stoklund Olesen | 2091206 | 2014-01-14 06:18:34 +0000 | [diff] [blame] | 154 | addRegisterClass(VT, &ARM::DPairRegClass); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 155 | addTypeForNEON(VT, MVT::v2f64, MVT::v4i32); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 156 | } |
157 | |||||
Chris Lattner | 5e693ed | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 158 | static TargetLoweringObjectFile *createTLOF(TargetMachine &TM) { |
Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 159 | if (TM.getSubtarget<ARMSubtarget>().isTargetMachO()) |
Bill Wendling | bbcaa40 | 2010-03-15 21:09:38 +0000 | [diff] [blame] | 160 | return new TargetLoweringObjectFileMachO(); |
Bill Wendling | 46ffefc | 2010-03-09 02:46:12 +0000 | [diff] [blame] | 161 | |
Chris Lattner | 4e7dfaf | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 162 | return new ARMElfTargetObjectFile(); |
Chris Lattner | 5e693ed | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 163 | } |
164 | |||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 165 | ARMTargetLowering::ARMTargetLowering(TargetMachine &TM) |
Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 166 | : TargetLowering(TM, createTLOF(TM)) { |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 167 | Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
Evan Cheng | df907f4 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 168 | RegInfo = TM.getRegisterInfo(); |
Evan Cheng | bf40707 | 2010-09-10 01:29:16 +0000 | [diff] [blame] | 169 | Itins = TM.getInstrItineraryData(); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 170 | |
Duncan Sands | f2641e1 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 171 | setBooleanVectorContents(ZeroOrNegativeOneBooleanContent); |
172 | |||||
Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 173 | if (Subtarget->isTargetMachO()) { |
Evan Cheng | c9f22fd1 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 174 | // Uses VFP for Thumb libfuncs if available. |
Jim Grosbach | 1d1d6d4 | 2013-10-24 23:07:11 +0000 | [diff] [blame] | 175 | if (Subtarget->isThumb() && Subtarget->hasVFP2() && |
Tim Northover | 978d25f | 2014-04-22 10:10:09 +0000 | [diff] [blame] | 176 | Subtarget->hasARMOps() && !TM.Options.UseSoftFloat) { |
Evan Cheng | c9f22fd1 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 177 | // Single-precision floating-point arithmetic. |
178 | setLibcallName(RTLIB::ADD_F32, "__addsf3vfp"); | ||||
179 | setLibcallName(RTLIB::SUB_F32, "__subsf3vfp"); | ||||
180 | setLibcallName(RTLIB::MUL_F32, "__mulsf3vfp"); | ||||
181 | setLibcallName(RTLIB::DIV_F32, "__divsf3vfp"); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 182 | |
Evan Cheng | c9f22fd1 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 183 | // Double-precision floating-point arithmetic. |
184 | setLibcallName(RTLIB::ADD_F64, "__adddf3vfp"); | ||||
185 | setLibcallName(RTLIB::SUB_F64, "__subdf3vfp"); | ||||
186 | setLibcallName(RTLIB::MUL_F64, "__muldf3vfp"); | ||||
187 | setLibcallName(RTLIB::DIV_F64, "__divdf3vfp"); | ||||
Evan Cheng | 143576d | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 188 | |
Evan Cheng | c9f22fd1 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 189 | // Single-precision comparisons. |
190 | setLibcallName(RTLIB::OEQ_F32, "__eqsf2vfp"); | ||||
191 | setLibcallName(RTLIB::UNE_F32, "__nesf2vfp"); | ||||
192 | setLibcallName(RTLIB::OLT_F32, "__ltsf2vfp"); | ||||
193 | setLibcallName(RTLIB::OLE_F32, "__lesf2vfp"); | ||||
194 | setLibcallName(RTLIB::OGE_F32, "__gesf2vfp"); | ||||
195 | setLibcallName(RTLIB::OGT_F32, "__gtsf2vfp"); | ||||
196 | setLibcallName(RTLIB::UO_F32, "__unordsf2vfp"); | ||||
197 | setLibcallName(RTLIB::O_F32, "__unordsf2vfp"); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 198 | |
Evan Cheng | c9f22fd1 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 199 | setCmpLibcallCC(RTLIB::OEQ_F32, ISD::SETNE); |
200 | setCmpLibcallCC(RTLIB::UNE_F32, ISD::SETNE); | ||||
201 | setCmpLibcallCC(RTLIB::OLT_F32, ISD::SETNE); | ||||
202 | setCmpLibcallCC(RTLIB::OLE_F32, ISD::SETNE); | ||||
203 | setCmpLibcallCC(RTLIB::OGE_F32, ISD::SETNE); | ||||
204 | setCmpLibcallCC(RTLIB::OGT_F32, ISD::SETNE); | ||||
205 | setCmpLibcallCC(RTLIB::UO_F32, ISD::SETNE); | ||||
206 | setCmpLibcallCC(RTLIB::O_F32, ISD::SETEQ); | ||||
Evan Cheng | 143576d | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 207 | |
Evan Cheng | c9f22fd1 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 208 | // Double-precision comparisons. |
209 | setLibcallName(RTLIB::OEQ_F64, "__eqdf2vfp"); | ||||
210 | setLibcallName(RTLIB::UNE_F64, "__nedf2vfp"); | ||||
211 | setLibcallName(RTLIB::OLT_F64, "__ltdf2vfp"); | ||||
212 | setLibcallName(RTLIB::OLE_F64, "__ledf2vfp"); | ||||
213 | setLibcallName(RTLIB::OGE_F64, "__gedf2vfp"); | ||||
214 | setLibcallName(RTLIB::OGT_F64, "__gtdf2vfp"); | ||||
215 | setLibcallName(RTLIB::UO_F64, "__unorddf2vfp"); | ||||
216 | setLibcallName(RTLIB::O_F64, "__unorddf2vfp"); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 217 | |
Evan Cheng | c9f22fd1 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 218 | setCmpLibcallCC(RTLIB::OEQ_F64, ISD::SETNE); |
219 | setCmpLibcallCC(RTLIB::UNE_F64, ISD::SETNE); | ||||
220 | setCmpLibcallCC(RTLIB::OLT_F64, ISD::SETNE); | ||||
221 | setCmpLibcallCC(RTLIB::OLE_F64, ISD::SETNE); | ||||
222 | setCmpLibcallCC(RTLIB::OGE_F64, ISD::SETNE); | ||||
223 | setCmpLibcallCC(RTLIB::OGT_F64, ISD::SETNE); | ||||
224 | setCmpLibcallCC(RTLIB::UO_F64, ISD::SETNE); | ||||
225 | setCmpLibcallCC(RTLIB::O_F64, ISD::SETEQ); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 226 | |
Evan Cheng | c9f22fd1 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 227 | // Floating-point to integer conversions. |
228 | // i64 conversions are done via library routines even when generating VFP | ||||
229 | // instructions, so use the same ones. | ||||
230 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__fixdfsivfp"); | ||||
231 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__fixunsdfsivfp"); | ||||
232 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__fixsfsivfp"); | ||||
233 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__fixunssfsivfp"); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 234 | |
Evan Cheng | c9f22fd1 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 235 | // Conversions between floating types. |
236 | setLibcallName(RTLIB::FPROUND_F64_F32, "__truncdfsf2vfp"); | ||||
237 | setLibcallName(RTLIB::FPEXT_F32_F64, "__extendsfdf2vfp"); | ||||
238 | |||||
239 | // Integer to floating-point conversions. | ||||
240 | // i64 conversions are done via library routines even when generating VFP | ||||
241 | // instructions, so use the same ones. | ||||
Bob Wilson | dc40d5a | 2009-03-20 23:16:43 +0000 | [diff] [blame] | 242 | // FIXME: There appears to be some naming inconsistency in ARM libgcc: |
243 | // e.g., __floatunsidf vs. __floatunssidfvfp. | ||||
Evan Cheng | c9f22fd1 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 244 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__floatsidfvfp"); |
245 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__floatunssidfvfp"); | ||||
246 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__floatsisfvfp"); | ||||
247 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__floatunssisfvfp"); | ||||
248 | } | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 249 | } |
250 | |||||
Bob Wilson | ccbc17b | 2009-05-22 17:38:41 +0000 | [diff] [blame] | 251 | // These libcalls are not available in 32-bit. |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 252 | setLibcallName(RTLIB::SHL_I128, nullptr); |
253 | setLibcallName(RTLIB::SRL_I128, nullptr); | ||||
254 | setLibcallName(RTLIB::SRA_I128, nullptr); | ||||
Bob Wilson | ccbc17b | 2009-05-22 17:38:41 +0000 | [diff] [blame] | 255 | |
Saleem Abdulrasool | cd13082 | 2014-04-02 20:32:05 +0000 | [diff] [blame] | 256 | if (Subtarget->isAAPCS_ABI() && !Subtarget->isTargetMachO() && |
257 | !Subtarget->isTargetWindows()) { | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 258 | // Double-precision floating-point arithmetic helper functions |
Anton Korobeynikov | 81bdc93 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 259 | // RTABI chapter 4.1.2, Table 2 |
260 | setLibcallName(RTLIB::ADD_F64, "__aeabi_dadd"); | ||||
261 | setLibcallName(RTLIB::DIV_F64, "__aeabi_ddiv"); | ||||
262 | setLibcallName(RTLIB::MUL_F64, "__aeabi_dmul"); | ||||
263 | setLibcallName(RTLIB::SUB_F64, "__aeabi_dsub"); | ||||
264 | setLibcallCallingConv(RTLIB::ADD_F64, CallingConv::ARM_AAPCS); | ||||
265 | setLibcallCallingConv(RTLIB::DIV_F64, CallingConv::ARM_AAPCS); | ||||
266 | setLibcallCallingConv(RTLIB::MUL_F64, CallingConv::ARM_AAPCS); | ||||
267 | setLibcallCallingConv(RTLIB::SUB_F64, CallingConv::ARM_AAPCS); | ||||
268 | |||||
269 | // Double-precision floating-point comparison helper functions | ||||
270 | // RTABI chapter 4.1.2, Table 3 | ||||
271 | setLibcallName(RTLIB::OEQ_F64, "__aeabi_dcmpeq"); | ||||
272 | setCmpLibcallCC(RTLIB::OEQ_F64, ISD::SETNE); | ||||
273 | setLibcallName(RTLIB::UNE_F64, "__aeabi_dcmpeq"); | ||||
274 | setCmpLibcallCC(RTLIB::UNE_F64, ISD::SETEQ); | ||||
275 | setLibcallName(RTLIB::OLT_F64, "__aeabi_dcmplt"); | ||||
276 | setCmpLibcallCC(RTLIB::OLT_F64, ISD::SETNE); | ||||
277 | setLibcallName(RTLIB::OLE_F64, "__aeabi_dcmple"); | ||||
278 | setCmpLibcallCC(RTLIB::OLE_F64, ISD::SETNE); | ||||
279 | setLibcallName(RTLIB::OGE_F64, "__aeabi_dcmpge"); | ||||
280 | setCmpLibcallCC(RTLIB::OGE_F64, ISD::SETNE); | ||||
281 | setLibcallName(RTLIB::OGT_F64, "__aeabi_dcmpgt"); | ||||
282 | setCmpLibcallCC(RTLIB::OGT_F64, ISD::SETNE); | ||||
283 | setLibcallName(RTLIB::UO_F64, "__aeabi_dcmpun"); | ||||
284 | setCmpLibcallCC(RTLIB::UO_F64, ISD::SETNE); | ||||
285 | setLibcallName(RTLIB::O_F64, "__aeabi_dcmpun"); | ||||
286 | setCmpLibcallCC(RTLIB::O_F64, ISD::SETEQ); | ||||
287 | setLibcallCallingConv(RTLIB::OEQ_F64, CallingConv::ARM_AAPCS); | ||||
288 | setLibcallCallingConv(RTLIB::UNE_F64, CallingConv::ARM_AAPCS); | ||||
289 | setLibcallCallingConv(RTLIB::OLT_F64, CallingConv::ARM_AAPCS); | ||||
290 | setLibcallCallingConv(RTLIB::OLE_F64, CallingConv::ARM_AAPCS); | ||||
291 | setLibcallCallingConv(RTLIB::OGE_F64, CallingConv::ARM_AAPCS); | ||||
292 | setLibcallCallingConv(RTLIB::OGT_F64, CallingConv::ARM_AAPCS); | ||||
293 | setLibcallCallingConv(RTLIB::UO_F64, CallingConv::ARM_AAPCS); | ||||
294 | setLibcallCallingConv(RTLIB::O_F64, CallingConv::ARM_AAPCS); | ||||
295 | |||||
296 | // Single-precision floating-point arithmetic helper functions | ||||
297 | // RTABI chapter 4.1.2, Table 4 | ||||
298 | setLibcallName(RTLIB::ADD_F32, "__aeabi_fadd"); | ||||
299 | setLibcallName(RTLIB::DIV_F32, "__aeabi_fdiv"); | ||||
300 | setLibcallName(RTLIB::MUL_F32, "__aeabi_fmul"); | ||||
301 | setLibcallName(RTLIB::SUB_F32, "__aeabi_fsub"); | ||||
302 | setLibcallCallingConv(RTLIB::ADD_F32, CallingConv::ARM_AAPCS); | ||||
303 | setLibcallCallingConv(RTLIB::DIV_F32, CallingConv::ARM_AAPCS); | ||||
304 | setLibcallCallingConv(RTLIB::MUL_F32, CallingConv::ARM_AAPCS); | ||||
305 | setLibcallCallingConv(RTLIB::SUB_F32, CallingConv::ARM_AAPCS); | ||||
306 | |||||
307 | // Single-precision floating-point comparison helper functions | ||||
308 | // RTABI chapter 4.1.2, Table 5 | ||||
309 | setLibcallName(RTLIB::OEQ_F32, "__aeabi_fcmpeq"); | ||||
310 | setCmpLibcallCC(RTLIB::OEQ_F32, ISD::SETNE); | ||||
311 | setLibcallName(RTLIB::UNE_F32, "__aeabi_fcmpeq"); | ||||
312 | setCmpLibcallCC(RTLIB::UNE_F32, ISD::SETEQ); | ||||
313 | setLibcallName(RTLIB::OLT_F32, "__aeabi_fcmplt"); | ||||
314 | setCmpLibcallCC(RTLIB::OLT_F32, ISD::SETNE); | ||||
315 | setLibcallName(RTLIB::OLE_F32, "__aeabi_fcmple"); | ||||
316 | setCmpLibcallCC(RTLIB::OLE_F32, ISD::SETNE); | ||||
317 | setLibcallName(RTLIB::OGE_F32, "__aeabi_fcmpge"); | ||||
318 | setCmpLibcallCC(RTLIB::OGE_F32, ISD::SETNE); | ||||
319 | setLibcallName(RTLIB::OGT_F32, "__aeabi_fcmpgt"); | ||||
320 | setCmpLibcallCC(RTLIB::OGT_F32, ISD::SETNE); | ||||
321 | setLibcallName(RTLIB::UO_F32, "__aeabi_fcmpun"); | ||||
322 | setCmpLibcallCC(RTLIB::UO_F32, ISD::SETNE); | ||||
323 | setLibcallName(RTLIB::O_F32, "__aeabi_fcmpun"); | ||||
324 | setCmpLibcallCC(RTLIB::O_F32, ISD::SETEQ); | ||||
325 | setLibcallCallingConv(RTLIB::OEQ_F32, CallingConv::ARM_AAPCS); | ||||
326 | setLibcallCallingConv(RTLIB::UNE_F32, CallingConv::ARM_AAPCS); | ||||
327 | setLibcallCallingConv(RTLIB::OLT_F32, CallingConv::ARM_AAPCS); | ||||
328 | setLibcallCallingConv(RTLIB::OLE_F32, CallingConv::ARM_AAPCS); | ||||
329 | setLibcallCallingConv(RTLIB::OGE_F32, CallingConv::ARM_AAPCS); | ||||
330 | setLibcallCallingConv(RTLIB::OGT_F32, CallingConv::ARM_AAPCS); | ||||
331 | setLibcallCallingConv(RTLIB::UO_F32, CallingConv::ARM_AAPCS); | ||||
332 | setLibcallCallingConv(RTLIB::O_F32, CallingConv::ARM_AAPCS); | ||||
333 | |||||
334 | // Floating-point to integer conversions. | ||||
335 | // RTABI chapter 4.1.2, Table 6 | ||||
336 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__aeabi_d2iz"); | ||||
337 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__aeabi_d2uiz"); | ||||
338 | setLibcallName(RTLIB::FPTOSINT_F64_I64, "__aeabi_d2lz"); | ||||
339 | setLibcallName(RTLIB::FPTOUINT_F64_I64, "__aeabi_d2ulz"); | ||||
340 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__aeabi_f2iz"); | ||||
341 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__aeabi_f2uiz"); | ||||
342 | setLibcallName(RTLIB::FPTOSINT_F32_I64, "__aeabi_f2lz"); | ||||
343 | setLibcallName(RTLIB::FPTOUINT_F32_I64, "__aeabi_f2ulz"); | ||||
344 | setLibcallCallingConv(RTLIB::FPTOSINT_F64_I32, CallingConv::ARM_AAPCS); | ||||
345 | setLibcallCallingConv(RTLIB::FPTOUINT_F64_I32, CallingConv::ARM_AAPCS); | ||||
346 | setLibcallCallingConv(RTLIB::FPTOSINT_F64_I64, CallingConv::ARM_AAPCS); | ||||
347 | setLibcallCallingConv(RTLIB::FPTOUINT_F64_I64, CallingConv::ARM_AAPCS); | ||||
348 | setLibcallCallingConv(RTLIB::FPTOSINT_F32_I32, CallingConv::ARM_AAPCS); | ||||
349 | setLibcallCallingConv(RTLIB::FPTOUINT_F32_I32, CallingConv::ARM_AAPCS); | ||||
350 | setLibcallCallingConv(RTLIB::FPTOSINT_F32_I64, CallingConv::ARM_AAPCS); | ||||
351 | setLibcallCallingConv(RTLIB::FPTOUINT_F32_I64, CallingConv::ARM_AAPCS); | ||||
352 | |||||
353 | // Conversions between floating types. | ||||
354 | // RTABI chapter 4.1.2, Table 7 | ||||
355 | setLibcallName(RTLIB::FPROUND_F64_F32, "__aeabi_d2f"); | ||||
356 | setLibcallName(RTLIB::FPEXT_F32_F64, "__aeabi_f2d"); | ||||
357 | setLibcallCallingConv(RTLIB::FPROUND_F64_F32, CallingConv::ARM_AAPCS); | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 358 | setLibcallCallingConv(RTLIB::FPEXT_F32_F64, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 81bdc93 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 359 | |
360 | // Integer to floating-point conversions. | ||||
361 | // RTABI chapter 4.1.2, Table 8 | ||||
362 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__aeabi_i2d"); | ||||
363 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__aeabi_ui2d"); | ||||
364 | setLibcallName(RTLIB::SINTTOFP_I64_F64, "__aeabi_l2d"); | ||||
365 | setLibcallName(RTLIB::UINTTOFP_I64_F64, "__aeabi_ul2d"); | ||||
366 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__aeabi_i2f"); | ||||
367 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__aeabi_ui2f"); | ||||
368 | setLibcallName(RTLIB::SINTTOFP_I64_F32, "__aeabi_l2f"); | ||||
369 | setLibcallName(RTLIB::UINTTOFP_I64_F32, "__aeabi_ul2f"); | ||||
370 | setLibcallCallingConv(RTLIB::SINTTOFP_I32_F64, CallingConv::ARM_AAPCS); | ||||
371 | setLibcallCallingConv(RTLIB::UINTTOFP_I32_F64, CallingConv::ARM_AAPCS); | ||||
372 | setLibcallCallingConv(RTLIB::SINTTOFP_I64_F64, CallingConv::ARM_AAPCS); | ||||
373 | setLibcallCallingConv(RTLIB::UINTTOFP_I64_F64, CallingConv::ARM_AAPCS); | ||||
374 | setLibcallCallingConv(RTLIB::SINTTOFP_I32_F32, CallingConv::ARM_AAPCS); | ||||
375 | setLibcallCallingConv(RTLIB::UINTTOFP_I32_F32, CallingConv::ARM_AAPCS); | ||||
376 | setLibcallCallingConv(RTLIB::SINTTOFP_I64_F32, CallingConv::ARM_AAPCS); | ||||
377 | setLibcallCallingConv(RTLIB::UINTTOFP_I64_F32, CallingConv::ARM_AAPCS); | ||||
378 | |||||
379 | // Long long helper functions | ||||
380 | // RTABI chapter 4.2, Table 9 | ||||
381 | setLibcallName(RTLIB::MUL_I64, "__aeabi_lmul"); | ||||
Anton Korobeynikov | 81bdc93 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 382 | setLibcallName(RTLIB::SHL_I64, "__aeabi_llsl"); |
383 | setLibcallName(RTLIB::SRL_I64, "__aeabi_llsr"); | ||||
384 | setLibcallName(RTLIB::SRA_I64, "__aeabi_lasr"); | ||||
385 | setLibcallCallingConv(RTLIB::MUL_I64, CallingConv::ARM_AAPCS); | ||||
386 | setLibcallCallingConv(RTLIB::SDIV_I64, CallingConv::ARM_AAPCS); | ||||
387 | setLibcallCallingConv(RTLIB::UDIV_I64, CallingConv::ARM_AAPCS); | ||||
388 | setLibcallCallingConv(RTLIB::SHL_I64, CallingConv::ARM_AAPCS); | ||||
389 | setLibcallCallingConv(RTLIB::SRL_I64, CallingConv::ARM_AAPCS); | ||||
390 | setLibcallCallingConv(RTLIB::SRA_I64, CallingConv::ARM_AAPCS); | ||||
391 | |||||
392 | // Integer division functions | ||||
393 | // RTABI chapter 4.3.1 | ||||
394 | setLibcallName(RTLIB::SDIV_I8, "__aeabi_idiv"); | ||||
395 | setLibcallName(RTLIB::SDIV_I16, "__aeabi_idiv"); | ||||
396 | setLibcallName(RTLIB::SDIV_I32, "__aeabi_idiv"); | ||||
Anton Korobeynikov | d0c4655 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 397 | setLibcallName(RTLIB::SDIV_I64, "__aeabi_ldivmod"); |
Anton Korobeynikov | 81bdc93 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 398 | setLibcallName(RTLIB::UDIV_I8, "__aeabi_uidiv"); |
399 | setLibcallName(RTLIB::UDIV_I16, "__aeabi_uidiv"); | ||||
400 | setLibcallName(RTLIB::UDIV_I32, "__aeabi_uidiv"); | ||||
Anton Korobeynikov | d0c4655 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 401 | setLibcallName(RTLIB::UDIV_I64, "__aeabi_uldivmod"); |
Anton Korobeynikov | 81bdc93 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 402 | setLibcallCallingConv(RTLIB::SDIV_I8, CallingConv::ARM_AAPCS); |
403 | setLibcallCallingConv(RTLIB::SDIV_I16, CallingConv::ARM_AAPCS); | ||||
404 | setLibcallCallingConv(RTLIB::SDIV_I32, CallingConv::ARM_AAPCS); | ||||
Anton Korobeynikov | d0c4655 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 405 | setLibcallCallingConv(RTLIB::SDIV_I64, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 81bdc93 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 406 | setLibcallCallingConv(RTLIB::UDIV_I8, CallingConv::ARM_AAPCS); |
407 | setLibcallCallingConv(RTLIB::UDIV_I16, CallingConv::ARM_AAPCS); | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 408 | setLibcallCallingConv(RTLIB::UDIV_I32, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | d0c4655 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 409 | setLibcallCallingConv(RTLIB::UDIV_I64, CallingConv::ARM_AAPCS); |
Renato Golin | 4cd5187 | 2011-05-22 21:41:23 +0000 | [diff] [blame] | 410 | |
411 | // Memory operations | ||||
412 | // RTABI chapter 4.3.4 | ||||
413 | setLibcallName(RTLIB::MEMCPY, "__aeabi_memcpy"); | ||||
414 | setLibcallName(RTLIB::MEMMOVE, "__aeabi_memmove"); | ||||
415 | setLibcallName(RTLIB::MEMSET, "__aeabi_memset"); | ||||
Anton Korobeynikov | d0c4655 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 416 | setLibcallCallingConv(RTLIB::MEMCPY, CallingConv::ARM_AAPCS); |
417 | setLibcallCallingConv(RTLIB::MEMMOVE, CallingConv::ARM_AAPCS); | ||||
418 | setLibcallCallingConv(RTLIB::MEMSET, CallingConv::ARM_AAPCS); | ||||
Anton Korobeynikov | a6b3ce2 | 2009-08-14 20:10:52 +0000 | [diff] [blame] | 419 | } |
420 | |||||
Bob Wilson | bc15899 | 2011-10-07 16:59:21 +0000 | [diff] [blame] | 421 | // Use divmod compiler-rt calls for iOS 5.0 and later. |
Cameron Esfahani | 943908b | 2013-08-29 20:23:14 +0000 | [diff] [blame] | 422 | if (Subtarget->getTargetTriple().isiOS() && |
Bob Wilson | bc15899 | 2011-10-07 16:59:21 +0000 | [diff] [blame] | 423 | !Subtarget->getTargetTriple().isOSVersionLT(5, 0)) { |
424 | setLibcallName(RTLIB::SDIVREM_I32, "__divmodsi4"); | ||||
425 | setLibcallName(RTLIB::UDIVREM_I32, "__udivmodsi4"); | ||||
426 | } | ||||
427 | |||||
David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 428 | if (Subtarget->isThumb1Only()) |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 429 | addRegisterClass(MVT::i32, &ARM::tGPRRegClass); |
Jim Grosbach | fde2110 | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 430 | else |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 431 | addRegisterClass(MVT::i32, &ARM::GPRRegClass); |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 432 | if (!TM.Options.UseSoftFloat && Subtarget->hasVFP2() && |
433 | !Subtarget->isThumb1Only()) { | ||||
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 434 | addRegisterClass(MVT::f32, &ARM::SPRRegClass); |
Jim Grosbach | 4d5dc3e | 2010-08-11 15:44:15 +0000 | [diff] [blame] | 435 | if (!Subtarget->isFPOnlySP()) |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 436 | addRegisterClass(MVT::f64, &ARM::DPRRegClass); |
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 437 | |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 438 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 439 | } |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 440 | |
Eli Friedman | 6f84fed | 2011-11-08 01:43:53 +0000 | [diff] [blame] | 441 | for (unsigned VT = (unsigned)MVT::FIRST_VECTOR_VALUETYPE; |
442 | VT <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++VT) { | ||||
443 | for (unsigned InnerVT = (unsigned)MVT::FIRST_VECTOR_VALUETYPE; | ||||
444 | InnerVT <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++InnerVT) | ||||
445 | setTruncStoreAction((MVT::SimpleValueType)VT, | ||||
446 | (MVT::SimpleValueType)InnerVT, Expand); | ||||
447 | setLoadExtAction(ISD::SEXTLOAD, (MVT::SimpleValueType)VT, Expand); | ||||
448 | setLoadExtAction(ISD::ZEXTLOAD, (MVT::SimpleValueType)VT, Expand); | ||||
449 | setLoadExtAction(ISD::EXTLOAD, (MVT::SimpleValueType)VT, Expand); | ||||
Benjamin Kramer | 4dae598 | 2014-04-26 12:06:28 +0000 | [diff] [blame] | 450 | |
451 | setOperationAction(ISD::MULHS, (MVT::SimpleValueType)VT, Expand); | ||||
452 | setOperationAction(ISD::SMUL_LOHI, (MVT::SimpleValueType)VT, Expand); | ||||
453 | setOperationAction(ISD::MULHU, (MVT::SimpleValueType)VT, Expand); | ||||
454 | setOperationAction(ISD::UMUL_LOHI, (MVT::SimpleValueType)VT, Expand); | ||||
Eli Friedman | 6f84fed | 2011-11-08 01:43:53 +0000 | [diff] [blame] | 455 | } |
456 | |||||
Lang Hames | c35ee8b | 2012-03-15 18:49:02 +0000 | [diff] [blame] | 457 | setOperationAction(ISD::ConstantFP, MVT::f32, Custom); |
Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 458 | setOperationAction(ISD::ConstantFP, MVT::f64, Custom); |
Lang Hames | c35ee8b | 2012-03-15 18:49:02 +0000 | [diff] [blame] | 459 | |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 460 | if (Subtarget->hasNEON()) { |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 461 | addDRTypeForNEON(MVT::v2f32); |
462 | addDRTypeForNEON(MVT::v8i8); | ||||
463 | addDRTypeForNEON(MVT::v4i16); | ||||
464 | addDRTypeForNEON(MVT::v2i32); | ||||
465 | addDRTypeForNEON(MVT::v1i64); | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 466 | |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 467 | addQRTypeForNEON(MVT::v4f32); |
468 | addQRTypeForNEON(MVT::v2f64); | ||||
469 | addQRTypeForNEON(MVT::v16i8); | ||||
470 | addQRTypeForNEON(MVT::v8i16); | ||||
471 | addQRTypeForNEON(MVT::v4i32); | ||||
472 | addQRTypeForNEON(MVT::v2i64); | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 473 | |
Bob Wilson | 194a251 | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 474 | // v2f64 is legal so that QR subregs can be extracted as f64 elements, but |
475 | // neither Neon nor VFP support any arithmetic operations on it. | ||||
Stepan Dyatkovskiy | 4683740 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 476 | // The same with v4f32. But keep in mind that vadd, vsub, vmul are natively |
477 | // supported for v4f32. | ||||
Bob Wilson | 194a251 | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 478 | setOperationAction(ISD::FADD, MVT::v2f64, Expand); |
479 | setOperationAction(ISD::FSUB, MVT::v2f64, Expand); | ||||
480 | setOperationAction(ISD::FMUL, MVT::v2f64, Expand); | ||||
Stepan Dyatkovskiy | 4683740 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 481 | // FIXME: Code duplication: FDIV and FREM are expanded always, see |
482 | // ARMTargetLowering::addTypeForNEON method for details. | ||||
Bob Wilson | 194a251 | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 483 | setOperationAction(ISD::FDIV, MVT::v2f64, Expand); |
484 | setOperationAction(ISD::FREM, MVT::v2f64, Expand); | ||||
Stepan Dyatkovskiy | 4683740 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 485 | // FIXME: Create unittest. |
486 | // In another words, find a way when "copysign" appears in DAG with vector | ||||
487 | // operands. | ||||
Bob Wilson | 194a251 | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 488 | setOperationAction(ISD::FCOPYSIGN, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 4683740 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 489 | // FIXME: Code duplication: SETCC has custom operation action, see |
490 | // ARMTargetLowering::addTypeForNEON method for details. | ||||
Duncan Sands | f2641e1 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 491 | setOperationAction(ISD::SETCC, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 4683740 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 492 | // FIXME: Create unittest for FNEG and for FABS. |
Bob Wilson | 194a251 | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 493 | setOperationAction(ISD::FNEG, MVT::v2f64, Expand); |
494 | setOperationAction(ISD::FABS, MVT::v2f64, Expand); | ||||
495 | setOperationAction(ISD::FSQRT, MVT::v2f64, Expand); | ||||
496 | setOperationAction(ISD::FSIN, MVT::v2f64, Expand); | ||||
497 | setOperationAction(ISD::FCOS, MVT::v2f64, Expand); | ||||
498 | setOperationAction(ISD::FPOWI, MVT::v2f64, Expand); | ||||
499 | setOperationAction(ISD::FPOW, MVT::v2f64, Expand); | ||||
500 | setOperationAction(ISD::FLOG, MVT::v2f64, Expand); | ||||
501 | setOperationAction(ISD::FLOG2, MVT::v2f64, Expand); | ||||
502 | setOperationAction(ISD::FLOG10, MVT::v2f64, Expand); | ||||
503 | setOperationAction(ISD::FEXP, MVT::v2f64, Expand); | ||||
504 | setOperationAction(ISD::FEXP2, MVT::v2f64, Expand); | ||||
Stepan Dyatkovskiy | 4683740 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 505 | // FIXME: Create unittest for FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR. |
Bob Wilson | 194a251 | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 506 | setOperationAction(ISD::FCEIL, MVT::v2f64, Expand); |
507 | setOperationAction(ISD::FTRUNC, MVT::v2f64, Expand); | ||||
508 | setOperationAction(ISD::FRINT, MVT::v2f64, Expand); | ||||
509 | setOperationAction(ISD::FNEARBYINT, MVT::v2f64, Expand); | ||||
510 | setOperationAction(ISD::FFLOOR, MVT::v2f64, Expand); | ||||
Arnold Schwaighofer | 99cba96 | 2013-03-02 19:38:33 +0000 | [diff] [blame] | 511 | setOperationAction(ISD::FMA, MVT::v2f64, Expand); |
Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 512 | |
Stepan Dyatkovskiy | 4683740 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 513 | setOperationAction(ISD::FSQRT, MVT::v4f32, Expand); |
514 | setOperationAction(ISD::FSIN, MVT::v4f32, Expand); | ||||
515 | setOperationAction(ISD::FCOS, MVT::v4f32, Expand); | ||||
516 | setOperationAction(ISD::FPOWI, MVT::v4f32, Expand); | ||||
517 | setOperationAction(ISD::FPOW, MVT::v4f32, Expand); | ||||
518 | setOperationAction(ISD::FLOG, MVT::v4f32, Expand); | ||||
519 | setOperationAction(ISD::FLOG2, MVT::v4f32, Expand); | ||||
520 | setOperationAction(ISD::FLOG10, MVT::v4f32, Expand); | ||||
521 | setOperationAction(ISD::FEXP, MVT::v4f32, Expand); | ||||
522 | setOperationAction(ISD::FEXP2, MVT::v4f32, Expand); | ||||
Craig Topper | 61d0457 | 2012-11-15 06:51:10 +0000 | [diff] [blame] | 523 | setOperationAction(ISD::FCEIL, MVT::v4f32, Expand); |
524 | setOperationAction(ISD::FTRUNC, MVT::v4f32, Expand); | ||||
525 | setOperationAction(ISD::FRINT, MVT::v4f32, Expand); | ||||
526 | setOperationAction(ISD::FNEARBYINT, MVT::v4f32, Expand); | ||||
Craig Topper | 3e41a5b | 2012-09-08 04:58:43 +0000 | [diff] [blame] | 527 | setOperationAction(ISD::FFLOOR, MVT::v4f32, Expand); |
Bob Wilson | 194a251 | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 528 | |
Arnold Schwaighofer | 99cba96 | 2013-03-02 19:38:33 +0000 | [diff] [blame] | 529 | // Mark v2f32 intrinsics. |
530 | setOperationAction(ISD::FSQRT, MVT::v2f32, Expand); | ||||
531 | setOperationAction(ISD::FSIN, MVT::v2f32, Expand); | ||||
532 | setOperationAction(ISD::FCOS, MVT::v2f32, Expand); | ||||
533 | setOperationAction(ISD::FPOWI, MVT::v2f32, Expand); | ||||
534 | setOperationAction(ISD::FPOW, MVT::v2f32, Expand); | ||||
535 | setOperationAction(ISD::FLOG, MVT::v2f32, Expand); | ||||
536 | setOperationAction(ISD::FLOG2, MVT::v2f32, Expand); | ||||
537 | setOperationAction(ISD::FLOG10, MVT::v2f32, Expand); | ||||
538 | setOperationAction(ISD::FEXP, MVT::v2f32, Expand); | ||||
539 | setOperationAction(ISD::FEXP2, MVT::v2f32, Expand); | ||||
540 | setOperationAction(ISD::FCEIL, MVT::v2f32, Expand); | ||||
541 | setOperationAction(ISD::FTRUNC, MVT::v2f32, Expand); | ||||
542 | setOperationAction(ISD::FRINT, MVT::v2f32, Expand); | ||||
543 | setOperationAction(ISD::FNEARBYINT, MVT::v2f32, Expand); | ||||
544 | setOperationAction(ISD::FFLOOR, MVT::v2f32, Expand); | ||||
545 | |||||
Bob Wilson | 6cc4657 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 546 | // Neon does not support some operations on v1i64 and v2i64 types. |
547 | setOperationAction(ISD::MUL, MVT::v1i64, Expand); | ||||
Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 548 | // Custom handling for some quad-vector types to detect VMULL. |
549 | setOperationAction(ISD::MUL, MVT::v8i16, Custom); | ||||
550 | setOperationAction(ISD::MUL, MVT::v4i32, Custom); | ||||
551 | setOperationAction(ISD::MUL, MVT::v2i64, Custom); | ||||
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 552 | // Custom handling for some vector types to avoid expensive expansions |
553 | setOperationAction(ISD::SDIV, MVT::v4i16, Custom); | ||||
554 | setOperationAction(ISD::SDIV, MVT::v8i8, Custom); | ||||
555 | setOperationAction(ISD::UDIV, MVT::v4i16, Custom); | ||||
556 | setOperationAction(ISD::UDIV, MVT::v8i8, Custom); | ||||
Duncan Sands | f2641e1 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 557 | setOperationAction(ISD::SETCC, MVT::v1i64, Expand); |
558 | setOperationAction(ISD::SETCC, MVT::v2i64, Expand); | ||||
Cameron Zwarich | 143f9ae | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 559 | // Neon does not have single instruction SINT_TO_FP and UINT_TO_FP with |
James Molloy | 547d4c0 | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 560 | // a destination type that is wider than the source, and nor does |
561 | // it have a FP_TO_[SU]INT instruction with a narrower destination than | ||||
562 | // source. | ||||
Cameron Zwarich | 143f9ae | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 563 | setOperationAction(ISD::SINT_TO_FP, MVT::v4i16, Custom); |
564 | setOperationAction(ISD::UINT_TO_FP, MVT::v4i16, Custom); | ||||
James Molloy | 547d4c0 | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 565 | setOperationAction(ISD::FP_TO_UINT, MVT::v4i16, Custom); |
566 | setOperationAction(ISD::FP_TO_SINT, MVT::v4i16, Custom); | ||||
Bob Wilson | 6cc4657 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 567 | |
Eli Friedman | e6385e6 | 2012-11-15 22:44:27 +0000 | [diff] [blame] | 568 | setOperationAction(ISD::FP_ROUND, MVT::v2f32, Expand); |
Eli Friedman | 3083494 | 2012-11-17 01:52:46 +0000 | [diff] [blame] | 569 | setOperationAction(ISD::FP_EXTEND, MVT::v2f64, Expand); |
Eli Friedman | e6385e6 | 2012-11-15 22:44:27 +0000 | [diff] [blame] | 570 | |
Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 571 | // NEON does not have single instruction CTPOP for vectors with element |
572 | // types wider than 8-bits. However, custom lowering can leverage the | ||||
573 | // v8i8/v16i8 vcnt instruction. | ||||
574 | setOperationAction(ISD::CTPOP, MVT::v2i32, Custom); | ||||
575 | setOperationAction(ISD::CTPOP, MVT::v4i32, Custom); | ||||
576 | setOperationAction(ISD::CTPOP, MVT::v4i16, Custom); | ||||
577 | setOperationAction(ISD::CTPOP, MVT::v8i16, Custom); | ||||
578 | |||||
Jim Grosbach | 5f21587 | 2013-02-27 21:31:12 +0000 | [diff] [blame] | 579 | // NEON only has FMA instructions as of VFP4. |
580 | if (!Subtarget->hasVFP4()) { | ||||
581 | setOperationAction(ISD::FMA, MVT::v2f32, Expand); | ||||
582 | setOperationAction(ISD::FMA, MVT::v4f32, Expand); | ||||
583 | } | ||||
584 | |||||
Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 585 | setTargetDAGCombine(ISD::INTRINSIC_VOID); |
586 | setTargetDAGCombine(ISD::INTRINSIC_W_CHAIN); | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 587 | setTargetDAGCombine(ISD::INTRINSIC_WO_CHAIN); |
588 | setTargetDAGCombine(ISD::SHL); | ||||
589 | setTargetDAGCombine(ISD::SRL); | ||||
590 | setTargetDAGCombine(ISD::SRA); | ||||
591 | setTargetDAGCombine(ISD::SIGN_EXTEND); | ||||
592 | setTargetDAGCombine(ISD::ZERO_EXTEND); | ||||
593 | setTargetDAGCombine(ISD::ANY_EXTEND); | ||||
Bob Wilson | c6c13a3 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 594 | setTargetDAGCombine(ISD::SELECT_CC); |
Bob Wilson | cb6db98 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 595 | setTargetDAGCombine(ISD::BUILD_VECTOR); |
Bob Wilson | c7334a1 | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 596 | setTargetDAGCombine(ISD::VECTOR_SHUFFLE); |
Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 597 | setTargetDAGCombine(ISD::INSERT_VECTOR_ELT); |
598 | setTargetDAGCombine(ISD::STORE); | ||||
Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 599 | setTargetDAGCombine(ISD::FP_TO_SINT); |
600 | setTargetDAGCombine(ISD::FP_TO_UINT); | ||||
601 | setTargetDAGCombine(ISD::FDIV); | ||||
Nadav Rotem | 097106b | 2011-10-15 20:03:12 +0000 | [diff] [blame] | 602 | |
James Molloy | 547d4c0 | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 603 | // It is legal to extload from v4i8 to v4i16 or v4i32. |
604 | MVT Tys[6] = {MVT::v8i8, MVT::v4i8, MVT::v2i8, | ||||
605 | MVT::v4i16, MVT::v2i16, | ||||
606 | MVT::v2i32}; | ||||
607 | for (unsigned i = 0; i < 6; ++i) { | ||||
608 | setLoadExtAction(ISD::EXTLOAD, Tys[i], Legal); | ||||
609 | setLoadExtAction(ISD::ZEXTLOAD, Tys[i], Legal); | ||||
610 | setLoadExtAction(ISD::SEXTLOAD, Tys[i], Legal); | ||||
611 | } | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 612 | } |
613 | |||||
Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 614 | // ARM and Thumb2 support UMLAL/SMLAL. |
615 | if (!Subtarget->isThumb1Only()) | ||||
616 | setTargetDAGCombine(ISD::ADDC); | ||||
617 | |||||
618 | |||||
Evan Cheng | 6addd65 | 2007-05-18 00:19:34 +0000 | [diff] [blame] | 619 | computeRegisterProperties(); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 620 | |
621 | // ARM does not have f32 extending load. | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 622 | setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 623 | |
Duncan Sands | 95d46ef | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 624 | // ARM does not have i1 sign extending load. |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 625 | setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote); |
Duncan Sands | 95d46ef | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 626 | |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 627 | // ARM supports all 4 flavors of integer indexed load / store. |
Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 628 | if (!Subtarget->isThumb1Only()) { |
629 | for (unsigned im = (unsigned)ISD::PRE_INC; | ||||
630 | im != (unsigned)ISD::LAST_INDEXED_MODE; ++im) { | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 631 | setIndexedLoadAction(im, MVT::i1, Legal); |
632 | setIndexedLoadAction(im, MVT::i8, Legal); | ||||
633 | setIndexedLoadAction(im, MVT::i16, Legal); | ||||
634 | setIndexedLoadAction(im, MVT::i32, Legal); | ||||
635 | setIndexedStoreAction(im, MVT::i1, Legal); | ||||
636 | setIndexedStoreAction(im, MVT::i8, Legal); | ||||
637 | setIndexedStoreAction(im, MVT::i16, Legal); | ||||
638 | setIndexedStoreAction(im, MVT::i32, Legal); | ||||
Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 639 | } |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 640 | } |
641 | |||||
Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 642 | setOperationAction(ISD::SADDO, MVT::i32, Custom); |
643 | setOperationAction(ISD::UADDO, MVT::i32, Custom); | ||||
644 | setOperationAction(ISD::SSUBO, MVT::i32, Custom); | ||||
645 | setOperationAction(ISD::USUBO, MVT::i32, Custom); | ||||
646 | |||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 647 | // i64 operation support. |
Eric Christopher | c721b0db | 2011-04-19 18:49:19 +0000 | [diff] [blame] | 648 | setOperationAction(ISD::MUL, MVT::i64, Expand); |
649 | setOperationAction(ISD::MULHU, MVT::i32, Expand); | ||||
Evan Cheng | b24e51e | 2009-07-07 01:17:28 +0000 | [diff] [blame] | 650 | if (Subtarget->isThumb1Only()) { |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 651 | setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand); |
652 | setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 653 | } |
Jim Grosbach | cf1464d | 2011-07-01 21:12:19 +0000 | [diff] [blame] | 654 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6Ops() |
655 | || (Subtarget->isThumb2() && !Subtarget->hasThumb2DSP())) | ||||
Eric Christopher | c721b0db | 2011-04-19 18:49:19 +0000 | [diff] [blame] | 656 | setOperationAction(ISD::MULHS, MVT::i32, Expand); |
657 | |||||
Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 658 | setOperationAction(ISD::SHL_PARTS, MVT::i32, Custom); |
Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 659 | setOperationAction(ISD::SRA_PARTS, MVT::i32, Custom); |
Jim Grosbach | 8fe6fd7 | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 660 | setOperationAction(ISD::SRL_PARTS, MVT::i32, Custom); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 661 | setOperationAction(ISD::SRL, MVT::i64, Custom); |
662 | setOperationAction(ISD::SRA, MVT::i64, Custom); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 663 | |
Evan Cheng | e891654 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 664 | if (!Subtarget->isThumb1Only()) { |
665 | // FIXME: We should do this for Thumb1 as well. | ||||
666 | setOperationAction(ISD::ADDC, MVT::i32, Custom); | ||||
667 | setOperationAction(ISD::ADDE, MVT::i32, Custom); | ||||
668 | setOperationAction(ISD::SUBC, MVT::i32, Custom); | ||||
669 | setOperationAction(ISD::SUBE, MVT::i32, Custom); | ||||
670 | } | ||||
671 | |||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 672 | // ARM does not have ROTL. |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 673 | setOperationAction(ISD::ROTL, MVT::i32, Expand); |
Jim Grosbach | 8546ec9 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 674 | setOperationAction(ISD::CTTZ, MVT::i32, Custom); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 675 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
David Goodwin | aa294c5 | 2009-06-26 20:47:43 +0000 | [diff] [blame] | 676 | if (!Subtarget->hasV5TOps() || Subtarget->isThumb1Only()) |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 677 | setOperationAction(ISD::CTLZ, MVT::i32, Expand); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 678 | |
Chandler Carruth | 637cc6a | 2011-12-13 01:56:10 +0000 | [diff] [blame] | 679 | // These just redirect to CTTZ and CTLZ on ARM. |
680 | setOperationAction(ISD::CTTZ_ZERO_UNDEF , MVT::i32 , Expand); | ||||
681 | setOperationAction(ISD::CTLZ_ZERO_UNDEF , MVT::i32 , Expand); | ||||
682 | |||||
Tim Northover | bc93308 | 2013-05-23 19:11:20 +0000 | [diff] [blame] | 683 | setOperationAction(ISD::READCYCLECOUNTER, MVT::i64, Custom); |
684 | |||||
Lauro Ramos Venancio | 25d4052 | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 685 | // Only ARMv6 has BSWAP. |
686 | if (!Subtarget->hasV6Ops()) | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 687 | setOperationAction(ISD::BSWAP, MVT::i32, Expand); |
Lauro Ramos Venancio | 25d4052 | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 688 | |
Bob Wilson | e8a549c | 2012-09-29 21:43:49 +0000 | [diff] [blame] | 689 | if (!(Subtarget->hasDivide() && Subtarget->isThumb2()) && |
690 | !(Subtarget->hasDivideInARMMode() && !Subtarget->isThumb())) { | ||||
691 | // These are expanded into libcalls if the cpu doesn't have HW divider. | ||||
Jim Grosbach | 92d99900 | 2010-05-05 20:44:35 +0000 | [diff] [blame] | 692 | setOperationAction(ISD::SDIV, MVT::i32, Expand); |
693 | setOperationAction(ISD::UDIV, MVT::i32, Expand); | ||||
694 | } | ||||
Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 695 | |
696 | // FIXME: Also set divmod for SREM on EABI | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 697 | setOperationAction(ISD::SREM, MVT::i32, Expand); |
698 | setOperationAction(ISD::UREM, MVT::i32, Expand); | ||||
Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 699 | // Register based DivRem for AEABI (RTABI 4.2) |
700 | if (Subtarget->isTargetAEABI()) { | ||||
701 | setLibcallName(RTLIB::SDIVREM_I8, "__aeabi_idivmod"); | ||||
702 | setLibcallName(RTLIB::SDIVREM_I16, "__aeabi_idivmod"); | ||||
703 | setLibcallName(RTLIB::SDIVREM_I32, "__aeabi_idivmod"); | ||||
704 | setLibcallName(RTLIB::SDIVREM_I64, "__aeabi_ldivmod"); | ||||
705 | setLibcallName(RTLIB::UDIVREM_I8, "__aeabi_uidivmod"); | ||||
706 | setLibcallName(RTLIB::UDIVREM_I16, "__aeabi_uidivmod"); | ||||
707 | setLibcallName(RTLIB::UDIVREM_I32, "__aeabi_uidivmod"); | ||||
708 | setLibcallName(RTLIB::UDIVREM_I64, "__aeabi_uldivmod"); | ||||
709 | |||||
710 | setLibcallCallingConv(RTLIB::SDIVREM_I8, CallingConv::ARM_AAPCS); | ||||
711 | setLibcallCallingConv(RTLIB::SDIVREM_I16, CallingConv::ARM_AAPCS); | ||||
712 | setLibcallCallingConv(RTLIB::SDIVREM_I32, CallingConv::ARM_AAPCS); | ||||
713 | setLibcallCallingConv(RTLIB::SDIVREM_I64, CallingConv::ARM_AAPCS); | ||||
714 | setLibcallCallingConv(RTLIB::UDIVREM_I8, CallingConv::ARM_AAPCS); | ||||
715 | setLibcallCallingConv(RTLIB::UDIVREM_I16, CallingConv::ARM_AAPCS); | ||||
716 | setLibcallCallingConv(RTLIB::UDIVREM_I32, CallingConv::ARM_AAPCS); | ||||
717 | setLibcallCallingConv(RTLIB::UDIVREM_I64, CallingConv::ARM_AAPCS); | ||||
718 | |||||
719 | setOperationAction(ISD::SDIVREM, MVT::i32, Custom); | ||||
720 | setOperationAction(ISD::UDIVREM, MVT::i32, Custom); | ||||
721 | } else { | ||||
722 | setOperationAction(ISD::SDIVREM, MVT::i32, Expand); | ||||
723 | setOperationAction(ISD::UDIVREM, MVT::i32, Expand); | ||||
724 | } | ||||
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 725 | |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 726 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
727 | setOperationAction(ISD::ConstantPool, MVT::i32, Custom); | ||||
728 | setOperationAction(ISD::GLOBAL_OFFSET_TABLE, MVT::i32, Custom); | ||||
729 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); | ||||
Bob Wilson | 1cf0b03 | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 730 | setOperationAction(ISD::BlockAddress, MVT::i32, Custom); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 731 | |
Evan Cheng | 74d92c1 | 2011-04-08 21:37:21 +0000 | [diff] [blame] | 732 | setOperationAction(ISD::TRAP, MVT::Other, Legal); |
Evan Cheng | 2fa5a7e | 2010-05-11 07:26:32 +0000 | [diff] [blame] | 733 | |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 734 | // Use the default implementation. |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 735 | setOperationAction(ISD::VASTART, MVT::Other, Custom); |
736 | setOperationAction(ISD::VAARG, MVT::Other, Expand); | ||||
737 | setOperationAction(ISD::VACOPY, MVT::Other, Expand); | ||||
738 | setOperationAction(ISD::VAEND, MVT::Other, Expand); | ||||
739 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); | ||||
740 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); | ||||
Bill Wendling | 05d6f2f | 2012-02-13 23:47:16 +0000 | [diff] [blame] | 741 | |
Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 742 | if (!Subtarget->isTargetMachO()) { |
743 | // Non-MachO platforms may return values in these registers via the | ||||
Bill Wendling | 05d6f2f | 2012-02-13 23:47:16 +0000 | [diff] [blame] | 744 | // personality function. |
Bill Wendling | 05d6f2f | 2012-02-13 23:47:16 +0000 | [diff] [blame] | 745 | setExceptionPointerRegister(ARM::R0); |
746 | setExceptionSelectorRegister(ARM::R1); | ||||
747 | } | ||||
Anton Korobeynikov | f3a6231 | 2011-01-24 22:38:45 +0000 | [diff] [blame] | 748 | |
Evan Cheng | f7f97b4 | 2010-04-15 22:20:34 +0000 | [diff] [blame] | 749 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Expand); |
Evan Cheng | 6e809de | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 750 | // ARMv6 Thumb1 (except for CPUs that support dmb / dsb) and earlier use |
751 | // the default expansion. | ||||
Tim Northover | c7ea804 | 2013-10-25 09:30:24 +0000 | [diff] [blame] | 752 | if (Subtarget->hasAnyDataBarrier() && !Subtarget->isThumb1Only()) { |
Tim Northover | c882eb0 | 2014-04-03 11:44:58 +0000 | [diff] [blame] | 753 | // ATOMIC_FENCE needs custom lowering; the others should have been expanded |
754 | // to ldrex/strex loops already. | ||||
Tim Northover | c7ea804 | 2013-10-25 09:30:24 +0000 | [diff] [blame] | 755 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Custom); |
Tim Northover | c882eb0 | 2014-04-03 11:44:58 +0000 | [diff] [blame] | 756 | |
Amara Emerson | b4ad2f3 | 2013-09-26 12:22:36 +0000 | [diff] [blame] | 757 | // On v8, we have particularly efficient implementations of atomic fences |
758 | // if they can be combined with nearby atomic loads and stores. | ||||
759 | if (!Subtarget->hasV8Ops()) { | ||||
760 | // Automatically insert fences (dmb ist) around ATOMIC_SWAP etc. | ||||
761 | setInsertFencesForAtomic(true); | ||||
762 | } | ||||
Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 763 | } else { |
Tim Northover | c7ea804 | 2013-10-25 09:30:24 +0000 | [diff] [blame] | 764 | // If there's anything we can use as a barrier, go through custom lowering |
765 | // for ATOMIC_FENCE. | ||||
766 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, | ||||
767 | Subtarget->hasAnyDataBarrier() ? Custom : Expand); | ||||
768 | |||||
Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 769 | // Set them all for expansion, which will force libcalls. |
Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 770 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i32, Expand); |
Jim Grosbach | a57c288 | 2010-06-18 23:03:10 +0000 | [diff] [blame] | 771 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i32, Expand); |
Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 772 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i32, Expand); |
Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 773 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i32, Expand); |
Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 774 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i32, Expand); |
Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 775 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i32, Expand); |
Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 776 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i32, Expand); |
Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 777 | setOperationAction(ISD::ATOMIC_LOAD_NAND, MVT::i32, Expand); |
Jim Grosbach | d4b733e | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 778 | setOperationAction(ISD::ATOMIC_LOAD_MIN, MVT::i32, Expand); |
Jim Grosbach | d4b733e | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 779 | setOperationAction(ISD::ATOMIC_LOAD_MAX, MVT::i32, Expand); |
Jim Grosbach | d4b733e | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 780 | setOperationAction(ISD::ATOMIC_LOAD_UMIN, MVT::i32, Expand); |
Jim Grosbach | d4b733e | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 781 | setOperationAction(ISD::ATOMIC_LOAD_UMAX, MVT::i32, Expand); |
Eli Friedman | ba912e0 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 782 | // Mark ATOMIC_LOAD and ATOMIC_STORE custom so we can handle the |
783 | // Unordered/Monotonic case. | ||||
784 | setOperationAction(ISD::ATOMIC_LOAD, MVT::i32, Custom); | ||||
785 | setOperationAction(ISD::ATOMIC_STORE, MVT::i32, Custom); | ||||
Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 786 | } |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 787 | |
Evan Cheng | 21acf9f | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 788 | setOperationAction(ISD::PREFETCH, MVT::Other, Custom); |
Evan Cheng | 6f36042 | 2010-11-03 05:14:24 +0000 | [diff] [blame] | 789 | |
Eli Friedman | 8cfa771 | 2010-06-26 04:36:50 +0000 | [diff] [blame] | 790 | // Requires SXTB/SXTH, available on v6 and up in both ARM and Thumb modes. |
791 | if (!Subtarget->hasV6Ops()) { | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 792 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand); |
793 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 794 | } |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 795 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 796 | |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 797 | if (!TM.Options.UseSoftFloat && Subtarget->hasVFP2() && |
798 | !Subtarget->isThumb1Only()) { | ||||
Bob Wilson | 6a4491b | 2010-01-19 22:56:26 +0000 | [diff] [blame] | 799 | // Turn f64->i64 into VMOVRRD, i64 -> f64 to VMOVDRR |
Sylvestre Ledru | 91ce36c | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 800 | // iff target supports vfp2. |
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 801 | setOperationAction(ISD::BITCAST, MVT::i64, Custom); |
Nate Begeman | b69b182 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 802 | setOperationAction(ISD::FLT_ROUNDS_, MVT::i32, Custom); |
803 | } | ||||
Lauro Ramos Venancio | f6a67bf | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 804 | |
805 | // We want to custom lower some of our intrinsics. | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 806 | setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); |
Jim Grosbach | 3198483 | 2010-07-07 00:07:57 +0000 | [diff] [blame] | 807 | if (Subtarget->isTargetDarwin()) { |
808 | setOperationAction(ISD::EH_SJLJ_SETJMP, MVT::i32, Custom); | ||||
809 | setOperationAction(ISD::EH_SJLJ_LONGJMP, MVT::Other, Custom); | ||||
John McCall | 7d84ece | 2011-05-29 19:50:32 +0000 | [diff] [blame] | 810 | setLibcallName(RTLIB::UNWIND_RESUME, "_Unwind_SjLj_Resume"); |
Jim Grosbach | 3198483 | 2010-07-07 00:07:57 +0000 | [diff] [blame] | 811 | } |
Lauro Ramos Venancio | f6a67bf | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 812 | |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 813 | setOperationAction(ISD::SETCC, MVT::i32, Expand); |
814 | setOperationAction(ISD::SETCC, MVT::f32, Expand); | ||||
815 | setOperationAction(ISD::SETCC, MVT::f64, Expand); | ||||
Bill Wendling | 6a98131 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 816 | setOperationAction(ISD::SELECT, MVT::i32, Custom); |
817 | setOperationAction(ISD::SELECT, MVT::f32, Custom); | ||||
818 | setOperationAction(ISD::SELECT, MVT::f64, Custom); | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 819 | setOperationAction(ISD::SELECT_CC, MVT::i32, Custom); |
820 | setOperationAction(ISD::SELECT_CC, MVT::f32, Custom); | ||||
821 | setOperationAction(ISD::SELECT_CC, MVT::f64, Custom); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 822 | |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 823 | setOperationAction(ISD::BRCOND, MVT::Other, Expand); |
824 | setOperationAction(ISD::BR_CC, MVT::i32, Custom); | ||||
825 | setOperationAction(ISD::BR_CC, MVT::f32, Custom); | ||||
826 | setOperationAction(ISD::BR_CC, MVT::f64, Custom); | ||||
827 | setOperationAction(ISD::BR_JT, MVT::Other, Custom); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 828 | |
Dan Gohman | 482732a | 2007-10-11 23:21:31 +0000 | [diff] [blame] | 829 | // We don't support sin/cos/fmod/copysign/pow |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 830 | setOperationAction(ISD::FSIN, MVT::f64, Expand); |
831 | setOperationAction(ISD::FSIN, MVT::f32, Expand); | ||||
832 | setOperationAction(ISD::FCOS, MVT::f32, Expand); | ||||
833 | setOperationAction(ISD::FCOS, MVT::f64, Expand); | ||||
Evan Cheng | 0e88c7d | 2013-01-29 02:32:37 +0000 | [diff] [blame] | 834 | setOperationAction(ISD::FSINCOS, MVT::f64, Expand); |
835 | setOperationAction(ISD::FSINCOS, MVT::f32, Expand); | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 836 | setOperationAction(ISD::FREM, MVT::f64, Expand); |
837 | setOperationAction(ISD::FREM, MVT::f32, Expand); | ||||
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 838 | if (!TM.Options.UseSoftFloat && Subtarget->hasVFP2() && |
839 | !Subtarget->isThumb1Only()) { | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 840 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Custom); |
841 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Custom); | ||||
Evan Cheng | 86e476b | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 842 | } |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 843 | setOperationAction(ISD::FPOW, MVT::f64, Expand); |
844 | setOperationAction(ISD::FPOW, MVT::f32, Expand); | ||||
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 845 | |
Evan Cheng | d0007f3 | 2012-04-10 21:40:28 +0000 | [diff] [blame] | 846 | if (!Subtarget->hasVFP4()) { |
847 | setOperationAction(ISD::FMA, MVT::f64, Expand); | ||||
848 | setOperationAction(ISD::FMA, MVT::f32, Expand); | ||||
849 | } | ||||
Cameron Zwarich | f03fa18 | 2011-07-08 21:39:21 +0000 | [diff] [blame] | 850 | |
Anton Korobeynikov | d7fece3 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 851 | // Various VFP goodness |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 852 | if (!TM.Options.UseSoftFloat && !Subtarget->isThumb1Only()) { |
Bob Wilson | e4191e7 | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 853 | // int <-> fp are custom expanded into bit_convert + ARMISD ops. |
854 | if (Subtarget->hasVFP2()) { | ||||
855 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom); | ||||
856 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Custom); | ||||
857 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom); | ||||
858 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); | ||||
859 | } | ||||
Anton Korobeynikov | d7fece3 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 860 | // Special handling for half-precision FP. |
Anton Korobeynikov | 64578d5 | 2010-03-18 22:35:37 +0000 | [diff] [blame] | 861 | if (!Subtarget->hasFP16()) { |
862 | setOperationAction(ISD::FP16_TO_FP32, MVT::f32, Expand); | ||||
863 | setOperationAction(ISD::FP32_TO_FP16, MVT::i32, Expand); | ||||
Anton Korobeynikov | d7fece3 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 864 | } |
Evan Cheng | 86e476b | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 865 | } |
Jim Grosbach | 1a59711 | 2014-04-03 23:43:18 +0000 | [diff] [blame] | 866 | |
Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 867 | // Combine sin / cos into one node or libcall if possible. |
868 | if (Subtarget->hasSinCos()) { | ||||
869 | setLibcallName(RTLIB::SINCOS_F32, "sincosf"); | ||||
870 | setLibcallName(RTLIB::SINCOS_F64, "sincos"); | ||||
871 | if (Subtarget->getTargetTriple().getOS() == Triple::IOS) { | ||||
872 | // For iOS, we don't want to the normal expansion of a libcall to | ||||
873 | // sincos. We want to issue a libcall to __sincos_stret. | ||||
874 | setOperationAction(ISD::FSINCOS, MVT::f64, Custom); | ||||
875 | setOperationAction(ISD::FSINCOS, MVT::f32, Custom); | ||||
876 | } | ||||
877 | } | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 878 | |
Chris Lattner | f3f4ad9 | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 879 | // We have target-specific dag combine patterns for the following nodes: |
Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 880 | // ARMISD::VMOVRRD - No need to call setTargetDAGCombine |
Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 881 | setTargetDAGCombine(ISD::ADD); |
882 | setTargetDAGCombine(ISD::SUB); | ||||
Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 883 | setTargetDAGCombine(ISD::MUL); |
Jakob Stoklund Olesen | e45e22b | 2012-09-07 17:34:15 +0000 | [diff] [blame] | 884 | setTargetDAGCombine(ISD::AND); |
885 | setTargetDAGCombine(ISD::OR); | ||||
886 | setTargetDAGCombine(ISD::XOR); | ||||
Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 887 | |
Evan Cheng | f258a15 | 2012-02-23 02:58:19 +0000 | [diff] [blame] | 888 | if (Subtarget->hasV6Ops()) |
889 | setTargetDAGCombine(ISD::SRL); | ||||
890 | |||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 891 | setStackPointerRegisterToSaveRestore(ARM::SP); |
Evan Cheng | 4401f88 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 892 | |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 893 | if (TM.Options.UseSoftFloat || Subtarget->isThumb1Only() || |
894 | !Subtarget->hasVFP2()) | ||||
Evan Cheng | 34c2604 | 2010-05-21 00:43:17 +0000 | [diff] [blame] | 895 | setSchedulingPreference(Sched::RegPressure); |
896 | else | ||||
897 | setSchedulingPreference(Sched::Hybrid); | ||||
Dale Johannesen | 58698d2 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 898 | |
Evan Cheng | 3ae2b79 | 2011-01-06 06:52:41 +0000 | [diff] [blame] | 899 | //// temporary - rewrite interface to use type |
Jim Grosbach | 341ad3e | 2013-02-20 21:13:59 +0000 | [diff] [blame] | 900 | MaxStoresPerMemset = 8; |
901 | MaxStoresPerMemsetOptSize = Subtarget->isTargetDarwin() ? 8 : 4; | ||||
902 | MaxStoresPerMemcpy = 4; // For @llvm.memcpy -> sequence of stores | ||||
903 | MaxStoresPerMemcpyOptSize = Subtarget->isTargetDarwin() ? 4 : 2; | ||||
904 | MaxStoresPerMemmove = 4; // For @llvm.memmove -> sequence of stores | ||||
905 | MaxStoresPerMemmoveOptSize = Subtarget->isTargetDarwin() ? 4 : 2; | ||||
Evan Cheng | b71233f | 2010-06-26 01:52:05 +0000 | [diff] [blame] | 906 | |
Rafael Espindola | a76eccf | 2010-07-11 04:01:49 +0000 | [diff] [blame] | 907 | // On ARM arguments smaller than 4 bytes are extended, so all arguments |
908 | // are at least 4 bytes aligned. | ||||
909 | setMinStackArgumentAlignment(4); | ||||
910 | |||||
Benjamin Kramer | e31f31e | 2012-05-05 12:49:14 +0000 | [diff] [blame] | 911 | // Prefer likely predicted branches to selects on out-of-order cores. |
Jim Grosbach | 341ad3e | 2013-02-20 21:13:59 +0000 | [diff] [blame] | 912 | PredictableSelectIsExpensive = Subtarget->isLikeA9(); |
Benjamin Kramer | e31f31e | 2012-05-05 12:49:14 +0000 | [diff] [blame] | 913 | |
Eli Friedman | 2518f83 | 2011-05-06 20:34:06 +0000 | [diff] [blame] | 914 | setMinFunctionAlignment(Subtarget->isThumb() ? 1 : 2); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 915 | } |
916 | |||||
Andrew Trick | 43f2563 | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 917 | // FIXME: It might make sense to define the representative register class as the |
918 | // nearest super-register that has a non-null superset. For example, DPR_VFP2 is | ||||
919 | // a super-register of SPR, and DPR is a superset if DPR_VFP2. Consequently, | ||||
920 | // SPR's representative would be DPR_VFP2. This should work well if register | ||||
921 | // pressure tracking were modified such that a register use would increment the | ||||
922 | // pressure of the register class's representative and all of it's super | ||||
923 | // classes' representatives transitively. We have not implemented this because | ||||
924 | // of the difficulty prior to coalescing of modeling operand register classes | ||||
Chris Lattner | 0ab5e2c | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 925 | // due to the common occurrence of cross class copies and subregister insertions |
Andrew Trick | 43f2563 | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 926 | // and extractions. |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 927 | std::pair<const TargetRegisterClass*, uint8_t> |
Patrik Hagglund | f9eb168 | 2012-12-19 11:30:36 +0000 | [diff] [blame] | 928 | ARMTargetLowering::findRepresentativeClass(MVT VT) const{ |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 929 | const TargetRegisterClass *RRC = nullptr; |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 930 | uint8_t Cost = 1; |
Patrik Hagglund | f9eb168 | 2012-12-19 11:30:36 +0000 | [diff] [blame] | 931 | switch (VT.SimpleTy) { |
Evan Cheng | 10f99a3 | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 932 | default: |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 933 | return TargetLowering::findRepresentativeClass(VT); |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 934 | // Use DPR as representative register class for all floating point |
935 | // and vector types. Since there are 32 SPR registers and 32 DPR registers so | ||||
936 | // the cost is 1 for both f32 and f64. | ||||
937 | case MVT::f32: case MVT::f64: case MVT::v8i8: case MVT::v4i16: | ||||
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 938 | case MVT::v2i32: case MVT::v1i64: case MVT::v2f32: |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 939 | RRC = &ARM::DPRRegClass; |
Andrew Trick | 43f2563 | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 940 | // When NEON is used for SP, only half of the register file is available |
941 | // because operations that define both SP and DP results will be constrained | ||||
942 | // to the VFP2 class (D0-D15). We currently model this constraint prior to | ||||
943 | // coalescing by double-counting the SP regs. See the FIXME above. | ||||
944 | if (Subtarget->useNEONForSinglePrecisionFP()) | ||||
945 | Cost = 2; | ||||
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 946 | break; |
947 | case MVT::v16i8: case MVT::v8i16: case MVT::v4i32: case MVT::v2i64: | ||||
948 | case MVT::v4f32: case MVT::v2f64: | ||||
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 949 | RRC = &ARM::DPRRegClass; |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 950 | Cost = 2; |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 951 | break; |
952 | case MVT::v4i64: | ||||
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 953 | RRC = &ARM::DPRRegClass; |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 954 | Cost = 4; |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 955 | break; |
956 | case MVT::v8i64: | ||||
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 957 | RRC = &ARM::DPRRegClass; |
Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 958 | Cost = 8; |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 959 | break; |
Evan Cheng | 10f99a3 | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 960 | } |
Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 961 | return std::make_pair(RRC, Cost); |
Evan Cheng | 10f99a3 | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 962 | } |
963 | |||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 964 | const char *ARMTargetLowering::getTargetNodeName(unsigned Opcode) const { |
965 | switch (Opcode) { | ||||
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 966 | default: return nullptr; |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 967 | case ARMISD::Wrapper: return "ARMISD::Wrapper"; |
Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 968 | case ARMISD::WrapperPIC: return "ARMISD::WrapperPIC"; |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 969 | case ARMISD::WrapperJT: return "ARMISD::WrapperJT"; |
970 | case ARMISD::CALL: return "ARMISD::CALL"; | ||||
Evan Cheng | c3c949b4 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 971 | case ARMISD::CALL_PRED: return "ARMISD::CALL_PRED"; |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 972 | case ARMISD::CALL_NOLINK: return "ARMISD::CALL_NOLINK"; |
973 | case ARMISD::tCALL: return "ARMISD::tCALL"; | ||||
974 | case ARMISD::BRCOND: return "ARMISD::BRCOND"; | ||||
975 | case ARMISD::BR_JT: return "ARMISD::BR_JT"; | ||||
Evan Cheng | c6d70ae | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 976 | case ARMISD::BR2_JT: return "ARMISD::BR2_JT"; |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 977 | case ARMISD::RET_FLAG: return "ARMISD::RET_FLAG"; |
Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 978 | case ARMISD::INTRET_FLAG: return "ARMISD::INTRET_FLAG"; |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 979 | case ARMISD::PIC_ADD: return "ARMISD::PIC_ADD"; |
980 | case ARMISD::CMP: return "ARMISD::CMP"; | ||||
Bill Wendling | 4b79647 | 2012-06-11 08:07:26 +0000 | [diff] [blame] | 981 | case ARMISD::CMN: return "ARMISD::CMN"; |
David Goodwin | dbf11ba | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 982 | case ARMISD::CMPZ: return "ARMISD::CMPZ"; |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 983 | case ARMISD::CMPFP: return "ARMISD::CMPFP"; |
984 | case ARMISD::CMPFPw0: return "ARMISD::CMPFPw0"; | ||||
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 985 | case ARMISD::BCC_i64: return "ARMISD::BCC_i64"; |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 986 | case ARMISD::FMSTAT: return "ARMISD::FMSTAT"; |
Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 987 | |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 988 | case ARMISD::CMOV: return "ARMISD::CMOV"; |
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 989 | |
Jim Grosbach | 8546ec9 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 990 | case ARMISD::RBIT: return "ARMISD::RBIT"; |
991 | |||||
Bob Wilson | e4191e7 | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 992 | case ARMISD::FTOSI: return "ARMISD::FTOSI"; |
993 | case ARMISD::FTOUI: return "ARMISD::FTOUI"; | ||||
994 | case ARMISD::SITOF: return "ARMISD::SITOF"; | ||||
995 | case ARMISD::UITOF: return "ARMISD::UITOF"; | ||||
996 | |||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 997 | case ARMISD::SRL_FLAG: return "ARMISD::SRL_FLAG"; |
998 | case ARMISD::SRA_FLAG: return "ARMISD::SRA_FLAG"; | ||||
999 | case ARMISD::RRX: return "ARMISD::RRX"; | ||||
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1000 | |
Evan Cheng | e891654 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 1001 | case ARMISD::ADDC: return "ARMISD::ADDC"; |
1002 | case ARMISD::ADDE: return "ARMISD::ADDE"; | ||||
1003 | case ARMISD::SUBC: return "ARMISD::SUBC"; | ||||
1004 | case ARMISD::SUBE: return "ARMISD::SUBE"; | ||||
1005 | |||||
Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 1006 | case ARMISD::VMOVRRD: return "ARMISD::VMOVRRD"; |
1007 | case ARMISD::VMOVDRR: return "ARMISD::VMOVDRR"; | ||||
Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1008 | |
Evan Cheng | ec6d7c9 | 2009-10-28 06:55:03 +0000 | [diff] [blame] | 1009 | case ARMISD::EH_SJLJ_SETJMP: return "ARMISD::EH_SJLJ_SETJMP"; |
1010 | case ARMISD::EH_SJLJ_LONGJMP:return "ARMISD::EH_SJLJ_LONGJMP"; | ||||
1011 | |||||
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1012 | case ARMISD::TC_RETURN: return "ARMISD::TC_RETURN"; |
Jim Grosbach | 535d3b4 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 1013 | |
Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1014 | case ARMISD::THREAD_POINTER:return "ARMISD::THREAD_POINTER"; |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1015 | |
Evan Cheng | b972e56 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 1016 | case ARMISD::DYN_ALLOC: return "ARMISD::DYN_ALLOC"; |
1017 | |||||
Bob Wilson | 7ed5971 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 1018 | case ARMISD::MEMBARRIER_MCR: return "ARMISD::MEMBARRIER_MCR"; |
Jim Grosbach | 53e8854 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 1019 | |
Evan Cheng | 8740ee3 | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 1020 | case ARMISD::PRELOAD: return "ARMISD::PRELOAD"; |
1021 | |||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1022 | case ARMISD::VCEQ: return "ARMISD::VCEQ"; |
Bob Wilson | f268d03 | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 1023 | case ARMISD::VCEQZ: return "ARMISD::VCEQZ"; |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1024 | case ARMISD::VCGE: return "ARMISD::VCGE"; |
Bob Wilson | f268d03 | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 1025 | case ARMISD::VCGEZ: return "ARMISD::VCGEZ"; |
1026 | case ARMISD::VCLEZ: return "ARMISD::VCLEZ"; | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1027 | case ARMISD::VCGEU: return "ARMISD::VCGEU"; |
1028 | case ARMISD::VCGT: return "ARMISD::VCGT"; | ||||
Bob Wilson | f268d03 | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 1029 | case ARMISD::VCGTZ: return "ARMISD::VCGTZ"; |
1030 | case ARMISD::VCLTZ: return "ARMISD::VCLTZ"; | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1031 | case ARMISD::VCGTU: return "ARMISD::VCGTU"; |
1032 | case ARMISD::VTST: return "ARMISD::VTST"; | ||||
1033 | |||||
1034 | case ARMISD::VSHL: return "ARMISD::VSHL"; | ||||
1035 | case ARMISD::VSHRs: return "ARMISD::VSHRs"; | ||||
1036 | case ARMISD::VSHRu: return "ARMISD::VSHRu"; | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1037 | case ARMISD::VRSHRs: return "ARMISD::VRSHRs"; |
1038 | case ARMISD::VRSHRu: return "ARMISD::VRSHRu"; | ||||
1039 | case ARMISD::VRSHRN: return "ARMISD::VRSHRN"; | ||||
1040 | case ARMISD::VQSHLs: return "ARMISD::VQSHLs"; | ||||
1041 | case ARMISD::VQSHLu: return "ARMISD::VQSHLu"; | ||||
1042 | case ARMISD::VQSHLsu: return "ARMISD::VQSHLsu"; | ||||
1043 | case ARMISD::VQSHRNs: return "ARMISD::VQSHRNs"; | ||||
1044 | case ARMISD::VQSHRNu: return "ARMISD::VQSHRNu"; | ||||
1045 | case ARMISD::VQSHRNsu: return "ARMISD::VQSHRNsu"; | ||||
1046 | case ARMISD::VQRSHRNs: return "ARMISD::VQRSHRNs"; | ||||
1047 | case ARMISD::VQRSHRNu: return "ARMISD::VQRSHRNu"; | ||||
1048 | case ARMISD::VQRSHRNsu: return "ARMISD::VQRSHRNsu"; | ||||
1049 | case ARMISD::VGETLANEu: return "ARMISD::VGETLANEu"; | ||||
1050 | case ARMISD::VGETLANEs: return "ARMISD::VGETLANEs"; | ||||
Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 1051 | case ARMISD::VMOVIMM: return "ARMISD::VMOVIMM"; |
Bob Wilson | bad47f6 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 1052 | case ARMISD::VMVNIMM: return "ARMISD::VMVNIMM"; |
Evan Cheng | 7ca4b6e | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 1053 | case ARMISD::VMOVFPIMM: return "ARMISD::VMOVFPIMM"; |
Bob Wilson | eb54d51 | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 1054 | case ARMISD::VDUP: return "ARMISD::VDUP"; |
Bob Wilson | cce31f6 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 1055 | case ARMISD::VDUPLANE: return "ARMISD::VDUPLANE"; |
Bob Wilson | 32cd855 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 1056 | case ARMISD::VEXT: return "ARMISD::VEXT"; |
Bob Wilson | ea3a402 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 1057 | case ARMISD::VREV64: return "ARMISD::VREV64"; |
1058 | case ARMISD::VREV32: return "ARMISD::VREV32"; | ||||
1059 | case ARMISD::VREV16: return "ARMISD::VREV16"; | ||||
Anton Korobeynikov | 232b19c | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 1060 | case ARMISD::VZIP: return "ARMISD::VZIP"; |
1061 | case ARMISD::VUZP: return "ARMISD::VUZP"; | ||||
1062 | case ARMISD::VTRN: return "ARMISD::VTRN"; | ||||
Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 1063 | case ARMISD::VTBL1: return "ARMISD::VTBL1"; |
1064 | case ARMISD::VTBL2: return "ARMISD::VTBL2"; | ||||
Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 1065 | case ARMISD::VMULLs: return "ARMISD::VMULLs"; |
1066 | case ARMISD::VMULLu: return "ARMISD::VMULLu"; | ||||
Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 1067 | case ARMISD::UMLAL: return "ARMISD::UMLAL"; |
1068 | case ARMISD::SMLAL: return "ARMISD::SMLAL"; | ||||
Bob Wilson | d8a9a04 | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 1069 | case ARMISD::BUILD_VECTOR: return "ARMISD::BUILD_VECTOR"; |
Bob Wilson | c6c13a3 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 1070 | case ARMISD::FMAX: return "ARMISD::FMAX"; |
1071 | case ARMISD::FMIN: return "ARMISD::FMIN"; | ||||
Joey Gouly | e3dd684 | 2013-08-23 12:01:13 +0000 | [diff] [blame] | 1072 | case ARMISD::VMAXNM: return "ARMISD::VMAX"; |
1073 | case ARMISD::VMINNM: return "ARMISD::VMIN"; | ||||
Jim Grosbach | 6e3b5fa | 2010-07-17 01:50:57 +0000 | [diff] [blame] | 1074 | case ARMISD::BFI: return "ARMISD::BFI"; |
Bob Wilson | 62a6f7e | 2010-11-28 06:51:11 +0000 | [diff] [blame] | 1075 | case ARMISD::VORRIMM: return "ARMISD::VORRIMM"; |
1076 | case ARMISD::VBICIMM: return "ARMISD::VBICIMM"; | ||||
Cameron Zwarich | 53dd03d | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 1077 | case ARMISD::VBSL: return "ARMISD::VBSL"; |
Bob Wilson | 2d790df | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 1078 | case ARMISD::VLD2DUP: return "ARMISD::VLD2DUP"; |
1079 | case ARMISD::VLD3DUP: return "ARMISD::VLD3DUP"; | ||||
1080 | case ARMISD::VLD4DUP: return "ARMISD::VLD4DUP"; | ||||
Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 1081 | case ARMISD::VLD1_UPD: return "ARMISD::VLD1_UPD"; |
1082 | case ARMISD::VLD2_UPD: return "ARMISD::VLD2_UPD"; | ||||
1083 | case ARMISD::VLD3_UPD: return "ARMISD::VLD3_UPD"; | ||||
1084 | case ARMISD::VLD4_UPD: return "ARMISD::VLD4_UPD"; | ||||
1085 | case ARMISD::VLD2LN_UPD: return "ARMISD::VLD2LN_UPD"; | ||||
1086 | case ARMISD::VLD3LN_UPD: return "ARMISD::VLD3LN_UPD"; | ||||
1087 | case ARMISD::VLD4LN_UPD: return "ARMISD::VLD4LN_UPD"; | ||||
1088 | case ARMISD::VLD2DUP_UPD: return "ARMISD::VLD2DUP_UPD"; | ||||
1089 | case ARMISD::VLD3DUP_UPD: return "ARMISD::VLD3DUP_UPD"; | ||||
1090 | case ARMISD::VLD4DUP_UPD: return "ARMISD::VLD4DUP_UPD"; | ||||
1091 | case ARMISD::VST1_UPD: return "ARMISD::VST1_UPD"; | ||||
1092 | case ARMISD::VST2_UPD: return "ARMISD::VST2_UPD"; | ||||
1093 | case ARMISD::VST3_UPD: return "ARMISD::VST3_UPD"; | ||||
1094 | case ARMISD::VST4_UPD: return "ARMISD::VST4_UPD"; | ||||
1095 | case ARMISD::VST2LN_UPD: return "ARMISD::VST2LN_UPD"; | ||||
1096 | case ARMISD::VST3LN_UPD: return "ARMISD::VST3LN_UPD"; | ||||
1097 | case ARMISD::VST4LN_UPD: return "ARMISD::VST4LN_UPD"; | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1098 | } |
1099 | } | ||||
1100 | |||||
Matt Arsenault | 75865923 | 2013-05-18 00:21:46 +0000 | [diff] [blame] | 1101 | EVT ARMTargetLowering::getSetCCResultType(LLVMContext &, EVT VT) const { |
Duncan Sands | f2641e1 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 1102 | if (!VT.isVector()) return getPointerTy(); |
1103 | return VT.changeVectorElementTypeToInteger(); | ||||
1104 | } | ||||
1105 | |||||
Evan Cheng | 4cad68e | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1106 | /// getRegClassFor - Return the register class that should be used for the |
1107 | /// specified value type. | ||||
Patrik Hagglund | 5e6c361 | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 1108 | const TargetRegisterClass *ARMTargetLowering::getRegClassFor(MVT VT) const { |
Evan Cheng | 4cad68e | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1109 | // Map v4i64 to QQ registers but do not make the type legal. Similarly map |
1110 | // v8i64 to QQQQ registers. v4i64 and v8i64 are only used for REG_SEQUENCE to | ||||
1111 | // load / store 4 to 8 consecutive D registers. | ||||
Evan Cheng | 3d214cd | 2010-05-15 02:20:21 +0000 | [diff] [blame] | 1112 | if (Subtarget->hasNEON()) { |
1113 | if (VT == MVT::v4i64) | ||||
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1114 | return &ARM::QQPRRegClass; |
1115 | if (VT == MVT::v8i64) | ||||
1116 | return &ARM::QQQQPRRegClass; | ||||
Evan Cheng | 3d214cd | 2010-05-15 02:20:21 +0000 | [diff] [blame] | 1117 | } |
Evan Cheng | 4cad68e | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1118 | return TargetLowering::getRegClassFor(VT); |
1119 | } | ||||
1120 | |||||
Eric Christopher | 84bdfd8 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1121 | // Create a fast isel object. |
1122 | FastISel * | ||||
Bob Wilson | 3e6fa46 | 2012-08-03 04:06:28 +0000 | [diff] [blame] | 1123 | ARMTargetLowering::createFastISel(FunctionLoweringInfo &funcInfo, |
1124 | const TargetLibraryInfo *libInfo) const { | ||||
1125 | return ARM::createFastISel(funcInfo, libInfo); | ||||
Eric Christopher | 84bdfd8 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1126 | } |
1127 | |||||
Anton Korobeynikov | 19edda0 | 2010-07-24 21:52:08 +0000 | [diff] [blame] | 1128 | /// getMaximalGlobalOffset - Returns the maximal possible offset which can |
1129 | /// be used for loads / stores from the global. | ||||
1130 | unsigned ARMTargetLowering::getMaximalGlobalOffset() const { | ||||
1131 | return (Subtarget->isThumb1Only() ? 127 : 4095); | ||||
1132 | } | ||||
1133 | |||||
Evan Cheng | 4401f88 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1134 | Sched::Preference ARMTargetLowering::getSchedulingPreference(SDNode *N) const { |
Evan Cheng | bf91499 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1135 | unsigned NumVals = N->getNumValues(); |
1136 | if (!NumVals) | ||||
1137 | return Sched::RegPressure; | ||||
1138 | |||||
1139 | for (unsigned i = 0; i != NumVals; ++i) { | ||||
Evan Cheng | 4401f88 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1140 | EVT VT = N->getValueType(i); |
Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1141 | if (VT == MVT::Glue || VT == MVT::Other) |
Evan Cheng | 0c4c5ca | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1142 | continue; |
Evan Cheng | 4401f88 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1143 | if (VT.isFloatingPoint() || VT.isVector()) |
Dan Gohman | 4ed1afa | 2011-10-24 17:55:11 +0000 | [diff] [blame] | 1144 | return Sched::ILP; |
Evan Cheng | 4401f88 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1145 | } |
Evan Cheng | bf91499 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1146 | |
1147 | if (!N->isMachineOpcode()) | ||||
1148 | return Sched::RegPressure; | ||||
1149 | |||||
1150 | // Load are scheduled for latency even if there instruction itinerary | ||||
1151 | // is not available. | ||||
1152 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); | ||||
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1153 | const MCInstrDesc &MCID = TII->get(N->getMachineOpcode()); |
Evan Cheng | 0c4c5ca | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1154 | |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1155 | if (MCID.getNumDefs() == 0) |
Evan Cheng | 0c4c5ca | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1156 | return Sched::RegPressure; |
1157 | if (!Itins->isEmpty() && | ||||
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1158 | Itins->getOperandCycle(MCID.getSchedClass(), 0) > 2) |
Dan Gohman | 4ed1afa | 2011-10-24 17:55:11 +0000 | [diff] [blame] | 1159 | return Sched::ILP; |
Evan Cheng | bf91499 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1160 | |
Evan Cheng | 4401f88 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1161 | return Sched::RegPressure; |
1162 | } | ||||
1163 | |||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1164 | //===----------------------------------------------------------------------===// |
1165 | // Lowering Code | ||||
1166 | //===----------------------------------------------------------------------===// | ||||
1167 | |||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1168 | /// IntCCToARMCC - Convert a DAG integer condition code to an ARM CC |
1169 | static ARMCC::CondCodes IntCCToARMCC(ISD::CondCode CC) { | ||||
1170 | switch (CC) { | ||||
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1171 | default: llvm_unreachable("Unknown condition code!"); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1172 | case ISD::SETNE: return ARMCC::NE; |
1173 | case ISD::SETEQ: return ARMCC::EQ; | ||||
1174 | case ISD::SETGT: return ARMCC::GT; | ||||
1175 | case ISD::SETGE: return ARMCC::GE; | ||||
1176 | case ISD::SETLT: return ARMCC::LT; | ||||
1177 | case ISD::SETLE: return ARMCC::LE; | ||||
1178 | case ISD::SETUGT: return ARMCC::HI; | ||||
1179 | case ISD::SETUGE: return ARMCC::HS; | ||||
1180 | case ISD::SETULT: return ARMCC::LO; | ||||
1181 | case ISD::SETULE: return ARMCC::LS; | ||||
1182 | } | ||||
1183 | } | ||||
1184 | |||||
Bob Wilson | a2e8333 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 1185 | /// FPCCToARMCC - Convert a DAG fp condition code to an ARM CC. |
1186 | static void FPCCToARMCC(ISD::CondCode CC, ARMCC::CondCodes &CondCode, | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1187 | ARMCC::CondCodes &CondCode2) { |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1188 | CondCode2 = ARMCC::AL; |
1189 | switch (CC) { | ||||
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1190 | default: llvm_unreachable("Unknown FP condition!"); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1191 | case ISD::SETEQ: |
1192 | case ISD::SETOEQ: CondCode = ARMCC::EQ; break; | ||||
1193 | case ISD::SETGT: | ||||
1194 | case ISD::SETOGT: CondCode = ARMCC::GT; break; | ||||
1195 | case ISD::SETGE: | ||||
1196 | case ISD::SETOGE: CondCode = ARMCC::GE; break; | ||||
1197 | case ISD::SETOLT: CondCode = ARMCC::MI; break; | ||||
Bob Wilson | a2e8333 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 1198 | case ISD::SETOLE: CondCode = ARMCC::LS; break; |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1199 | case ISD::SETONE: CondCode = ARMCC::MI; CondCode2 = ARMCC::GT; break; |
1200 | case ISD::SETO: CondCode = ARMCC::VC; break; | ||||
1201 | case ISD::SETUO: CondCode = ARMCC::VS; break; | ||||
1202 | case ISD::SETUEQ: CondCode = ARMCC::EQ; CondCode2 = ARMCC::VS; break; | ||||
1203 | case ISD::SETUGT: CondCode = ARMCC::HI; break; | ||||
1204 | case ISD::SETUGE: CondCode = ARMCC::PL; break; | ||||
1205 | case ISD::SETLT: | ||||
1206 | case ISD::SETULT: CondCode = ARMCC::LT; break; | ||||
1207 | case ISD::SETLE: | ||||
1208 | case ISD::SETULE: CondCode = ARMCC::LE; break; | ||||
1209 | case ISD::SETNE: | ||||
1210 | case ISD::SETUNE: CondCode = ARMCC::NE; break; | ||||
1211 | } | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1212 | } |
1213 | |||||
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1214 | //===----------------------------------------------------------------------===// |
1215 | // Calling Convention Implementation | ||||
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1216 | //===----------------------------------------------------------------------===// |
1217 | |||||
1218 | #include "ARMGenCallingConv.inc" | ||||
1219 | |||||
Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 1220 | /// getEffectiveCallingConv - Get the effective calling convention, taking into |
1221 | /// account presence of floating point hardware and calling convention | ||||
1222 | /// limitations, such as support for variadic functions. | ||||
1223 | CallingConv::ID | ||||
1224 | ARMTargetLowering::getEffectiveCallingConv(CallingConv::ID CC, | ||||
1225 | bool isVarArg) const { | ||||
Anton Korobeynikov | a8fd40b | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1226 | switch (CC) { |
1227 | default: | ||||
Anton Korobeynikov | 22ef751 | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1228 | llvm_unreachable("Unsupported calling convention"); |
Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 1229 | case CallingConv::ARM_AAPCS: |
1230 | case CallingConv::ARM_APCS: | ||||
1231 | case CallingConv::GHC: | ||||
1232 | return CC; | ||||
1233 | case CallingConv::ARM_AAPCS_VFP: | ||||
1234 | return isVarArg ? CallingConv::ARM_AAPCS : CallingConv::ARM_AAPCS_VFP; | ||||
1235 | case CallingConv::C: | ||||
Evan Cheng | 08dd8c8 | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1236 | if (!Subtarget->isAAPCS_ABI()) |
Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 1237 | return CallingConv::ARM_APCS; |
Evan Cheng | 08dd8c8 | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1238 | else if (Subtarget->hasVFP2() && |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 1239 | getTargetMachine().Options.FloatABIType == FloatABI::Hard && |
1240 | !isVarArg) | ||||
Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 1241 | return CallingConv::ARM_AAPCS_VFP; |
1242 | else | ||||
1243 | return CallingConv::ARM_AAPCS; | ||||
1244 | case CallingConv::Fast: | ||||
1245 | if (!Subtarget->isAAPCS_ABI()) { | ||||
1246 | if (Subtarget->hasVFP2() && !isVarArg) | ||||
1247 | return CallingConv::Fast; | ||||
1248 | return CallingConv::ARM_APCS; | ||||
1249 | } else if (Subtarget->hasVFP2() && !isVarArg) | ||||
1250 | return CallingConv::ARM_AAPCS_VFP; | ||||
1251 | else | ||||
1252 | return CallingConv::ARM_AAPCS; | ||||
Evan Cheng | 08dd8c8 | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1253 | } |
Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 1254 | } |
1255 | |||||
1256 | /// CCAssignFnForNode - Selects the correct CCAssignFn for the given | ||||
1257 | /// CallingConvention. | ||||
1258 | CCAssignFn *ARMTargetLowering::CCAssignFnForNode(CallingConv::ID CC, | ||||
1259 | bool Return, | ||||
1260 | bool isVarArg) const { | ||||
1261 | switch (getEffectiveCallingConv(CC, isVarArg)) { | ||||
1262 | default: | ||||
1263 | llvm_unreachable("Unsupported calling convention"); | ||||
Anton Korobeynikov | a8fd40b | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1264 | case CallingConv::ARM_APCS: |
Evan Cheng | 08dd8c8 | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1265 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS); |
Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 1266 | case CallingConv::ARM_AAPCS: |
1267 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); | ||||
1268 | case CallingConv::ARM_AAPCS_VFP: | ||||
1269 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); | ||||
1270 | case CallingConv::Fast: | ||||
1271 | return (Return ? RetFastCC_ARM_APCS : FastCC_ARM_APCS); | ||||
Eric Christopher | b332236 | 2012-08-03 00:05:53 +0000 | [diff] [blame] | 1272 | case CallingConv::GHC: |
1273 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS_GHC); | ||||
Anton Korobeynikov | a8fd40b | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1274 | } |
1275 | } | ||||
1276 | |||||
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1277 | /// LowerCallResult - Lower the result values of a call into the |
1278 | /// appropriate copies out of appropriate physical registers. | ||||
1279 | SDValue | ||||
1280 | ARMTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag, | ||||
Sandeep Patel | 68c5f47 | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1281 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1282 | const SmallVectorImpl<ISD::InputArg> &Ins, |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1283 | SDLoc dl, SelectionDAG &DAG, |
Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1284 | SmallVectorImpl<SDValue> &InVals, |
1285 | bool isThisReturn, SDValue ThisVal) const { | ||||
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1286 | |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1287 | // Assign locations to each value returned by this call. |
1288 | SmallVector<CCValAssign, 16> RVLocs; | ||||
Cameron Zwarich | 8901978 | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1289 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
1290 | getTargetMachine(), RVLocs, *DAG.getContext(), Call); | ||||
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1291 | CCInfo.AnalyzeCallResult(Ins, |
Anton Korobeynikov | 22ef751 | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1292 | CCAssignFnForNode(CallConv, /* Return*/ true, |
1293 | isVarArg)); | ||||
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1294 | |
1295 | // Copy all of the result registers out of their specified physreg. | ||||
1296 | for (unsigned i = 0; i != RVLocs.size(); ++i) { | ||||
1297 | CCValAssign VA = RVLocs[i]; | ||||
1298 | |||||
Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1299 | // Pass 'this' value directly from the argument to return value, to avoid |
1300 | // reg unit interference | ||||
1301 | if (i == 0 && isThisReturn) { | ||||
Stephen Lin | 8118e0b | 2013-04-23 19:42:25 +0000 | [diff] [blame] | 1302 | assert(!VA.needsCustom() && VA.getLocVT() == MVT::i32 && |
1303 | "unexpected return calling convention register assignment"); | ||||
Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1304 | InVals.push_back(ThisVal); |
1305 | continue; | ||||
1306 | } | ||||
1307 | |||||
Bob Wilson | 0041bd3 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1308 | SDValue Val; |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1309 | if (VA.needsCustom()) { |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1310 | // Handle f64 or half of a v2f64. |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1311 | SDValue Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1312 | InFlag); |
Bob Wilson | f134b2d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1313 | Chain = Lo.getValue(1); |
1314 | InFlag = Lo.getValue(2); | ||||
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1315 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1316 | SDValue Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | f134b2d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1317 | InFlag); |
1318 | Chain = Hi.getValue(1); | ||||
1319 | InFlag = Hi.getValue(2); | ||||
Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 1320 | if (!Subtarget->isLittle()) |
1321 | std::swap (Lo, Hi); | ||||
Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1322 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1323 | |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1324 | if (VA.getLocVT() == MVT::v2f64) { |
1325 | SDValue Vec = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); | ||||
1326 | Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, | ||||
1327 | DAG.getConstant(0, MVT::i32)); | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1328 | |
1329 | VA = RVLocs[++i]; // skip ahead to next loc | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1330 | Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1331 | Chain = Lo.getValue(1); |
1332 | InFlag = Lo.getValue(2); | ||||
1333 | VA = RVLocs[++i]; // skip ahead to next loc | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1334 | Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1335 | Chain = Hi.getValue(1); |
1336 | InFlag = Hi.getValue(2); | ||||
Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 1337 | if (!Subtarget->isLittle()) |
1338 | std::swap (Lo, Hi); | ||||
Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1339 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1340 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
1341 | DAG.getConstant(1, MVT::i32)); | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1342 | } |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1343 | } else { |
Bob Wilson | 0041bd3 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1344 | Val = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), VA.getLocVT(), |
1345 | InFlag); | ||||
Bob Wilson | f134b2d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1346 | Chain = Val.getValue(1); |
1347 | InFlag = Val.getValue(2); | ||||
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1348 | } |
Bob Wilson | 0041bd3 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1349 | |
1350 | switch (VA.getLocInfo()) { | ||||
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1351 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 0041bd3 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1352 | case CCValAssign::Full: break; |
1353 | case CCValAssign::BCvt: | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1354 | Val = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), Val); |
Bob Wilson | 0041bd3 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1355 | break; |
1356 | } | ||||
1357 | |||||
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1358 | InVals.push_back(Val); |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1359 | } |
1360 | |||||
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1361 | return Chain; |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1362 | } |
1363 | |||||
Bob Wilson | ea09d4a | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1364 | /// LowerMemOpCallTo - Store the argument to the stack. |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1365 | SDValue |
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1366 | ARMTargetLowering::LowerMemOpCallTo(SDValue Chain, |
1367 | SDValue StackPtr, SDValue Arg, | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1368 | SDLoc dl, SelectionDAG &DAG, |
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1369 | const CCValAssign &VA, |
Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1370 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1371 | unsigned LocMemOffset = VA.getLocMemOffset(); |
1372 | SDValue PtrOff = DAG.getIntPtrConstant(LocMemOffset); | ||||
1373 | PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, PtrOff); | ||||
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1374 | return DAG.getStore(Chain, dl, Arg, PtrOff, |
Chris Lattner | 886250c | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 1375 | MachinePointerInfo::getStack(LocMemOffset), |
David Greene | 0d0149f | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1376 | false, false, 0); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1377 | } |
1378 | |||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1379 | void ARMTargetLowering::PassF64ArgInRegs(SDLoc dl, SelectionDAG &DAG, |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1380 | SDValue Chain, SDValue &Arg, |
1381 | RegsToPassVector &RegsToPass, | ||||
1382 | CCValAssign &VA, CCValAssign &NextVA, | ||||
1383 | SDValue &StackPtr, | ||||
Craig Topper | b94011f | 2013-07-14 04:42:23 +0000 | [diff] [blame] | 1384 | SmallVectorImpl<SDValue> &MemOpChains, |
Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1385 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1386 | |
Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1387 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1388 | DAG.getVTList(MVT::i32, MVT::i32), Arg); |
Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 1389 | unsigned id = Subtarget->isLittle() ? 0 : 1; |
1390 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), fmrrd.getValue(id))); | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1391 | |
1392 | if (NextVA.isRegLoc()) | ||||
Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 1393 | RegsToPass.push_back(std::make_pair(NextVA.getLocReg(), fmrrd.getValue(1-id))); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1394 | else { |
1395 | assert(NextVA.isMemLoc()); | ||||
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1396 | if (!StackPtr.getNode()) |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1397 | StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
1398 | |||||
Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 1399 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, fmrrd.getValue(1-id), |
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1400 | dl, DAG, NextVA, |
1401 | Flags)); | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1402 | } |
1403 | } | ||||
1404 | |||||
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1405 | /// LowerCall - Lowering a call into a callseq_start <- |
Evan Cheng | 4b6c8f7 | 2007-02-03 08:53:01 +0000 | [diff] [blame] | 1406 | /// ARMISD:CALL <- callseq_end chain. Also add input and output parameter |
1407 | /// nodes. | ||||
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1408 | SDValue |
Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 1409 | ARMTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, |
Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1410 | SmallVectorImpl<SDValue> &InVals) const { |
Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 1411 | SelectionDAG &DAG = CLI.DAG; |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1412 | SDLoc &dl = CLI.DL; |
Craig Topper | b94011f | 2013-07-14 04:42:23 +0000 | [diff] [blame] | 1413 | SmallVectorImpl<ISD::OutputArg> &Outs = CLI.Outs; |
1414 | SmallVectorImpl<SDValue> &OutVals = CLI.OutVals; | ||||
1415 | SmallVectorImpl<ISD::InputArg> &Ins = CLI.Ins; | ||||
Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 1416 | SDValue Chain = CLI.Chain; |
1417 | SDValue Callee = CLI.Callee; | ||||
1418 | bool &isTailCall = CLI.IsTailCall; | ||||
1419 | CallingConv::ID CallConv = CLI.CallConv; | ||||
1420 | bool doesNotRet = CLI.DoesNotReturn; | ||||
1421 | bool isVarArg = CLI.IsVarArg; | ||||
1422 | |||||
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1423 | MachineFunction &MF = DAG.getMachineFunction(); |
Stephen Lin | 4eedb29 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1424 | bool isStructRet = (Outs.empty()) ? false : Outs[0].Flags.isSRet(); |
1425 | bool isThisReturn = false; | ||||
1426 | bool isSibCall = false; | ||||
Saleem Abdulrasool | 0d96f3d | 2014-03-11 15:09:54 +0000 | [diff] [blame] | 1427 | |
Bob Wilson | 8decdc4 | 2011-10-07 17:17:49 +0000 | [diff] [blame] | 1428 | // Disable tail calls if they're not supported. |
Saleem Abdulrasool | 0d96f3d | 2014-03-11 15:09:54 +0000 | [diff] [blame] | 1429 | if (!Subtarget->supportsTailCall() || MF.getTarget().Options.DisableTailCalls) |
Bob Wilson | 3c9ed76 | 2010-08-13 22:43:33 +0000 | [diff] [blame] | 1430 | isTailCall = false; |
Saleem Abdulrasool | 0d96f3d | 2014-03-11 15:09:54 +0000 | [diff] [blame] | 1431 | |
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1432 | if (isTailCall) { |
1433 | // Check if it's really possible to do a tail call. | ||||
1434 | isTailCall = IsEligibleForTailCallOptimization(Callee, CallConv, | ||||
Stephen Lin | 4eedb29 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1435 | isVarArg, isStructRet, MF.getFunction()->hasStructRetAttr(), |
Dan Gohman | fe7532a | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1436 | Outs, OutVals, Ins, DAG); |
Reid Kleckner | 5772b77 | 2014-04-24 20:14:34 +0000 | [diff] [blame] | 1437 | if (!isTailCall && CLI.CS && CLI.CS->isMustTailCall()) |
1438 | report_fatal_error("failed to perform tail call elimination on a call " | ||||
1439 | "site marked musttail"); | ||||
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1440 | // We don't support GuaranteedTailCallOpt for ARM, only automatically |
1441 | // detected sibcalls. | ||||
1442 | if (isTailCall) { | ||||
1443 | ++NumTailCalls; | ||||
Stephen Lin | 4eedb29 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1444 | isSibCall = true; |
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1445 | } |
1446 | } | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1447 | |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1448 | // Analyze operands of the call, assigning locations to each operand. |
1449 | SmallVector<CCValAssign, 16> ArgLocs; | ||||
Cameron Zwarich | 8901978 | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1450 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
1451 | getTargetMachine(), ArgLocs, *DAG.getContext(), Call); | ||||
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1452 | CCInfo.AnalyzeCallOperands(Outs, |
Anton Korobeynikov | 22ef751 | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1453 | CCAssignFnForNode(CallConv, /* Return*/ false, |
1454 | isVarArg)); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1455 | |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1456 | // Get a count of how many bytes are to be pushed on the stack. |
1457 | unsigned NumBytes = CCInfo.getNextStackOffset(); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1458 | |
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1459 | // For tail calls, memory operands are available in our caller's stack. |
Stephen Lin | 4eedb29 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1460 | if (isSibCall) |
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1461 | NumBytes = 0; |
1462 | |||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1463 | // Adjust the stack pointer for the new arguments... |
1464 | // These operations are automatically eliminated by the prolog/epilog pass | ||||
Stephen Lin | 4eedb29 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1465 | if (!isSibCall) |
Andrew Trick | ad6d08a | 2013-05-29 22:03:55 +0000 | [diff] [blame] | 1466 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumBytes, true), |
1467 | dl); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1468 | |
Jim Grosbach | 6ad4bcb | 2010-02-24 01:43:03 +0000 | [diff] [blame] | 1469 | SDValue StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1470 | |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1471 | RegsToPassVector RegsToPass; |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1472 | SmallVector<SDValue, 8> MemOpChains; |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1473 | |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1474 | // Walk the register/memloc assignments, inserting copies/loads. In the case |
Bob Wilson | ea09d4a | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1475 | // of tail call optimization, arguments are handled later. |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1476 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
1477 | i != e; | ||||
1478 | ++i, ++realArgIdx) { | ||||
1479 | CCValAssign &VA = ArgLocs[i]; | ||||
Dan Gohman | fe7532a | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1480 | SDValue Arg = OutVals[realArgIdx]; |
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1481 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1482 | bool isByVal = Flags.isByVal(); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1483 | |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1484 | // Promote the value if needed. |
1485 | switch (VA.getLocInfo()) { | ||||
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1486 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1487 | case CCValAssign::Full: break; |
1488 | case CCValAssign::SExt: | ||||
1489 | Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); | ||||
1490 | break; | ||||
1491 | case CCValAssign::ZExt: | ||||
1492 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); | ||||
1493 | break; | ||||
1494 | case CCValAssign::AExt: | ||||
1495 | Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); | ||||
1496 | break; | ||||
1497 | case CCValAssign::BCvt: | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1498 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1499 | break; |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1500 | } |
1501 | |||||
Anton Korobeynikov | 22ef751 | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1502 | // f64 and v2f64 might be passed in i32 pairs and must be split into pieces |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1503 | if (VA.needsCustom()) { |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1504 | if (VA.getLocVT() == MVT::v2f64) { |
1505 | SDValue Op0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, | ||||
1506 | DAG.getConstant(0, MVT::i32)); | ||||
1507 | SDValue Op1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, | ||||
1508 | DAG.getConstant(1, MVT::i32)); | ||||
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1509 | |
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1510 | PassF64ArgInRegs(dl, DAG, Chain, Op0, RegsToPass, |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1511 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
1512 | |||||
1513 | VA = ArgLocs[++i]; // skip ahead to next loc | ||||
1514 | if (VA.isRegLoc()) { | ||||
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1515 | PassF64ArgInRegs(dl, DAG, Chain, Op1, RegsToPass, |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1516 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
1517 | } else { | ||||
1518 | assert(VA.isMemLoc()); | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1519 | |
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1520 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Op1, |
1521 | dl, DAG, VA, Flags)); | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1522 | } |
1523 | } else { | ||||
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1524 | PassF64ArgInRegs(dl, DAG, Chain, Arg, RegsToPass, VA, ArgLocs[++i], |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1525 | StackPtr, MemOpChains, Flags); |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1526 | } |
1527 | } else if (VA.isRegLoc()) { | ||||
Stephen Lin | 8118e0b | 2013-04-23 19:42:25 +0000 | [diff] [blame] | 1528 | if (realArgIdx == 0 && Flags.isReturned() && Outs[0].VT == MVT::i32) { |
1529 | assert(VA.getLocVT() == MVT::i32 && | ||||
1530 | "unexpected calling convention register assignment"); | ||||
1531 | assert(!Ins.empty() && Ins[0].VT == MVT::i32 && | ||||
Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1532 | "unexpected use of 'returned'"); |
Stephen Lin | 4eedb29 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1533 | isThisReturn = true; |
Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1534 | } |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1535 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1536 | } else if (isByVal) { |
1537 | assert(VA.isMemLoc()); | ||||
1538 | unsigned offset = 0; | ||||
1539 | |||||
1540 | // True if this byval aggregate will be split between registers | ||||
1541 | // and memory. | ||||
Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1542 | unsigned ByValArgsCount = CCInfo.getInRegsParamsCount(); |
1543 | unsigned CurByValIdx = CCInfo.getInRegsParamsProceed(); | ||||
1544 | |||||
1545 | if (CurByValIdx < ByValArgsCount) { | ||||
1546 | |||||
1547 | unsigned RegBegin, RegEnd; | ||||
1548 | CCInfo.getInRegsParamInfo(CurByValIdx, RegBegin, RegEnd); | ||||
1549 | |||||
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1550 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
1551 | unsigned int i, j; | ||||
Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1552 | for (i = 0, j = RegBegin; j < RegEnd; i++, j++) { |
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1553 | SDValue Const = DAG.getConstant(4*i, MVT::i32); |
1554 | SDValue AddArg = DAG.getNode(ISD::ADD, dl, PtrVT, Arg, Const); | ||||
1555 | SDValue Load = DAG.getLoad(PtrVT, dl, Chain, AddArg, | ||||
1556 | MachinePointerInfo(), | ||||
Manman Ren | 5a78755 | 2013-10-07 19:47:53 +0000 | [diff] [blame] | 1557 | false, false, false, |
1558 | DAG.InferPtrAlignment(AddArg)); | ||||
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1559 | MemOpChains.push_back(Load.getValue(1)); |
1560 | RegsToPass.push_back(std::make_pair(j, Load)); | ||||
1561 | } | ||||
Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1562 | |
1563 | // If parameter size outsides register area, "offset" value | ||||
1564 | // helps us to calculate stack slot for remained part properly. | ||||
1565 | offset = RegEnd - RegBegin; | ||||
1566 | |||||
1567 | CCInfo.nextInRegsParam(); | ||||
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1568 | } |
1569 | |||||
Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1570 | if (Flags.getByValSize() > 4*offset) { |
Manman Ren | 9f91116 | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 1571 | unsigned LocMemOffset = VA.getLocMemOffset(); |
1572 | SDValue StkPtrOff = DAG.getIntPtrConstant(LocMemOffset); | ||||
1573 | SDValue Dst = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, | ||||
1574 | StkPtrOff); | ||||
1575 | SDValue SrcOffset = DAG.getIntPtrConstant(4*offset); | ||||
1576 | SDValue Src = DAG.getNode(ISD::ADD, dl, getPointerTy(), Arg, SrcOffset); | ||||
1577 | SDValue SizeNode = DAG.getConstant(Flags.getByValSize() - 4*offset, | ||||
1578 | MVT::i32); | ||||
Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 1579 | SDValue AlignNode = DAG.getConstant(Flags.getByValAlign(), MVT::i32); |
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1580 | |
Manman Ren | 9f91116 | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 1581 | SDVTList VTs = DAG.getVTList(MVT::Other, MVT::Glue); |
Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 1582 | SDValue Ops[] = { Chain, Dst, Src, SizeNode, AlignNode}; |
Manman Ren | 9f91116 | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 1583 | MemOpChains.push_back(DAG.getNode(ARMISD::COPY_STRUCT_BYVAL, dl, VTs, |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 1584 | Ops)); |
Manman Ren | 9f91116 | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 1585 | } |
Stephen Lin | 4eedb29 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1586 | } else if (!isSibCall) { |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1587 | assert(VA.isMemLoc()); |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1588 | |
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1589 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Arg, |
1590 | dl, DAG, VA, Flags)); | ||||
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1591 | } |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1592 | } |
1593 | |||||
1594 | if (!MemOpChains.empty()) | ||||
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 1595 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOpChains); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1596 | |
1597 | // Build a sequence of copy-to-reg nodes chained together with token chain | ||||
1598 | // and flag operands which copy the outgoing args into the appropriate regs. | ||||
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1599 | SDValue InFlag; |
Dale Johannesen | 44f9dfc | 2010-06-15 22:08:33 +0000 | [diff] [blame] | 1600 | // Tail call byval lowering might overwrite argument registers so in case of |
1601 | // tail call optimization the copies to registers are lowered later. | ||||
1602 | if (!isTailCall) | ||||
1603 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { | ||||
1604 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, | ||||
1605 | RegsToPass[i].second, InFlag); | ||||
1606 | InFlag = Chain.getValue(1); | ||||
1607 | } | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1608 | |
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1609 | // For tail calls lower the arguments to the 'real' stack slot. |
1610 | if (isTailCall) { | ||||
1611 | // Force all the incoming stack arguments to be loaded from the stack | ||||
1612 | // before any new outgoing arguments are stored to the stack, because the | ||||
1613 | // outgoing stack slots may alias the incoming argument stack slots, and | ||||
1614 | // the alias isn't otherwise explicit. This is slightly more conservative | ||||
1615 | // than necessary, because it means that each store effectively depends | ||||
1616 | // on every argument instead of just those arguments it would clobber. | ||||
1617 | |||||
Chris Lattner | 0ab5e2c | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 1618 | // Do not flag preceding copytoreg stuff together with the following stuff. |
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1619 | InFlag = SDValue(); |
1620 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { | ||||
1621 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, | ||||
1622 | RegsToPass[i].second, InFlag); | ||||
1623 | InFlag = Chain.getValue(1); | ||||
1624 | } | ||||
Stephen Lin | d36fd2c | 2013-04-20 00:47:48 +0000 | [diff] [blame] | 1625 | InFlag = SDValue(); |
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1626 | } |
1627 | |||||
Bill Wendling | 24c79f2 | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1628 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
1629 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol | ||||
1630 | // node so that legalize doesn't hack it. | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1631 | bool isDirect = false; |
1632 | bool isARMFunc = false; | ||||
Evan Cheng | c3c949b4 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1633 | bool isLocalARMFunc = false; |
Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1634 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1635 | |
1636 | if (EnableARMLongCalls) { | ||||
1637 | assert (getTargetMachine().getRelocationModel() == Reloc::Static | ||||
1638 | && "long-calls with non-static relocation model!"); | ||||
1639 | // Handle a global address or an external symbol. If it's not one of | ||||
1640 | // those, the target's already in a register, so we don't need to do | ||||
1641 | // anything extra. | ||||
1642 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { | ||||
Anders Carlsson | 47bccf7 | 2010-04-15 03:11:28 +0000 | [diff] [blame] | 1643 | const GlobalValue *GV = G->getGlobal(); |
Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1644 | // Create a constant pool entry for the callee address |
Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1645 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | 7753d66 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 1646 | ARMConstantPoolValue *CPV = |
1647 | ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex, ARMCP::CPValue, 0); | ||||
1648 | |||||
Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1649 | // Get the address of the callee into a register |
1650 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); | ||||
1651 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); | ||||
1652 | Callee = DAG.getLoad(getPointerTy(), dl, | ||||
1653 | DAG.getEntryNode(), CPAddr, | ||||
Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1654 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1655 | false, false, false, 0); |
Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1656 | } else if (ExternalSymbolSDNode *S=dyn_cast<ExternalSymbolSDNode>(Callee)) { |
1657 | const char *Sym = S->getSymbol(); | ||||
1658 | |||||
1659 | // Create a constant pool entry for the callee address | ||||
Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1660 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | c214cb0 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 1661 | ARMConstantPoolValue *CPV = |
1662 | ARMConstantPoolSymbol::Create(*DAG.getContext(), Sym, | ||||
1663 | ARMPCLabelIndex, 0); | ||||
Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1664 | // Get the address of the callee into a register |
1665 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); | ||||
1666 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); | ||||
1667 | Callee = DAG.getLoad(getPointerTy(), dl, | ||||
1668 | DAG.getEntryNode(), CPAddr, | ||||
Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1669 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1670 | false, false, false, 0); |
Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1671 | } |
1672 | } else if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { | ||||
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1673 | const GlobalValue *GV = G->getGlobal(); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1674 | isDirect = true; |
Chris Lattner | 55452c2 | 2009-07-15 04:12:33 +0000 | [diff] [blame] | 1675 | bool isExt = GV->isDeclaration() || GV->isWeakForLinker(); |
Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 1676 | bool isStub = (isExt && Subtarget->isTargetMachO()) && |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1677 | getTargetMachine().getRelocationModel() != Reloc::Static; |
1678 | isARMFunc = !Subtarget->isThumb() || isStub; | ||||
Evan Cheng | c3c949b4 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1679 | // ARM call to a local ARM function is predicable. |
Evan Cheng | f128bdc | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 1680 | isLocalARMFunc = !Subtarget->isThumb() && (!isExt || !ARMInterworking); |
Evan Cheng | 83f3517 | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1681 | // tBX takes a register source operand. |
Tim Northover | 72360d2 | 2013-12-02 10:35:41 +0000 | [diff] [blame] | 1682 | if (isStub && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 1683 | assert(Subtarget->isTargetMachO() && "WrapperPIC use on non-MachO?"); |
Tim Northover | 72360d2 | 2013-12-02 10:35:41 +0000 | [diff] [blame] | 1684 | Callee = DAG.getNode(ARMISD::WrapperPIC, dl, getPointerTy(), |
1685 | DAG.getTargetGlobalAddress(GV, dl, getPointerTy())); | ||||
Jim Grosbach | 85dcd3d | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1686 | } else { |
1687 | // On ELF targets for PIC code, direct calls should go through the PLT | ||||
1688 | unsigned OpFlags = 0; | ||||
1689 | if (Subtarget->isTargetELF() && | ||||
Chad Rosier | 537ff50 | 2013-02-28 19:16:42 +0000 | [diff] [blame] | 1690 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
Jim Grosbach | 85dcd3d | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1691 | OpFlags = ARMII::MO_PLT; |
1692 | Callee = DAG.getTargetGlobalAddress(GV, dl, getPointerTy(), 0, OpFlags); | ||||
1693 | } | ||||
Bill Wendling | 24c79f2 | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1694 | } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) { |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1695 | isDirect = true; |
Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 1696 | bool isStub = Subtarget->isTargetMachO() && |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1697 | getTargetMachine().getRelocationModel() != Reloc::Static; |
1698 | isARMFunc = !Subtarget->isThumb() || isStub; | ||||
Evan Cheng | 83f3517 | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1699 | // tBX takes a register source operand. |
1700 | const char *Sym = S->getSymbol(); | ||||
David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1701 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1702 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | c214cb0 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 1703 | ARMConstantPoolValue *CPV = |
1704 | ARMConstantPoolSymbol::Create(*DAG.getContext(), Sym, | ||||
1705 | ARMPCLabelIndex, 4); | ||||
Evan Cheng | 1fb8aed | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1706 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1707 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1708 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | cdbb70c | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1709 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1710 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1711 | false, false, false, 0); |
Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1712 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1713 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1714 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | 85dcd3d | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1715 | } else { |
1716 | unsigned OpFlags = 0; | ||||
1717 | // On ELF targets for PIC code, direct calls should go through the PLT | ||||
1718 | if (Subtarget->isTargetELF() && | ||||
1719 | getTargetMachine().getRelocationModel() == Reloc::PIC_) | ||||
1720 | OpFlags = ARMII::MO_PLT; | ||||
1721 | Callee = DAG.getTargetExternalSymbol(Sym, getPointerTy(), OpFlags); | ||||
1722 | } | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1723 | } |
1724 | |||||
Lauro Ramos Venancio | a88c4a7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1725 | // FIXME: handle tail calls differently. |
1726 | unsigned CallOpc; | ||||
Tim Northover | dee8604 | 2013-12-02 14:46:26 +0000 | [diff] [blame] | 1727 | bool HasMinSizeAttr = Subtarget->isMinSize(); |
Evan Cheng | 6ab54fd | 2009-08-01 00:16:10 +0000 | [diff] [blame] | 1728 | if (Subtarget->isThumb()) { |
1729 | if ((!isDirect || isARMFunc) && !Subtarget->hasV5TOps()) | ||||
Lauro Ramos Venancio | a88c4a7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1730 | CallOpc = ARMISD::CALL_NOLINK; |
1731 | else | ||||
1732 | CallOpc = isARMFunc ? ARMISD::CALL : ARMISD::tCALL; | ||||
1733 | } else { | ||||
Evan Cheng | 21b0348 | 2012-11-10 02:09:05 +0000 | [diff] [blame] | 1734 | if (!isDirect && !Subtarget->hasV5TOps()) |
Evan Cheng | 65f9d19 | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 1735 | CallOpc = ARMISD::CALL_NOLINK; |
Evan Cheng | 21b0348 | 2012-11-10 02:09:05 +0000 | [diff] [blame] | 1736 | else if (doesNotRet && isDirect && Subtarget->hasRAS() && |
Quentin Colombet | 8e1fe84 | 2012-11-02 21:32:17 +0000 | [diff] [blame] | 1737 | // Emit regular call when code size is the priority |
1738 | !HasMinSizeAttr) | ||||
Evan Cheng | 65f9d19 | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 1739 | // "mov lr, pc; b _foo" to avoid confusing the RSP |
1740 | CallOpc = ARMISD::CALL_NOLINK; | ||||
1741 | else | ||||
1742 | CallOpc = isLocalARMFunc ? ARMISD::CALL_PRED : ARMISD::CALL; | ||||
Lauro Ramos Venancio | a88c4a7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1743 | } |
Lauro Ramos Venancio | a88c4a7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1744 | |
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1745 | std::vector<SDValue> Ops; |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1746 | Ops.push_back(Chain); |
1747 | Ops.push_back(Callee); | ||||
1748 | |||||
1749 | // Add argument registers to the end of the list so that they are known live | ||||
1750 | // into the call. | ||||
1751 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) | ||||
1752 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, | ||||
1753 | RegsToPass[i].second.getValueType())); | ||||
1754 | |||||
Jakob Stoklund Olesen | fa7a537 | 2012-02-24 01:19:29 +0000 | [diff] [blame] | 1755 | // Add a register mask operand representing the call-preserved registers. |
Matthias Braun | c22630e | 2013-10-04 16:52:54 +0000 | [diff] [blame] | 1756 | if (!isTailCall) { |
1757 | const uint32_t *Mask; | ||||
1758 | const TargetRegisterInfo *TRI = getTargetMachine().getRegisterInfo(); | ||||
1759 | const ARMBaseRegisterInfo *ARI = static_cast<const ARMBaseRegisterInfo*>(TRI); | ||||
1760 | if (isThisReturn) { | ||||
1761 | // For 'this' returns, use the R0-preserving mask if applicable | ||||
1762 | Mask = ARI->getThisReturnPreservedMask(CallConv); | ||||
1763 | if (!Mask) { | ||||
1764 | // Set isThisReturn to false if the calling convention is not one that | ||||
1765 | // allows 'returned' to be modeled in this way, so LowerCallResult does | ||||
1766 | // not try to pass 'this' straight through | ||||
1767 | isThisReturn = false; | ||||
1768 | Mask = ARI->getCallPreservedMask(CallConv); | ||||
1769 | } | ||||
1770 | } else | ||||
Stephen Lin | ff7fcee | 2013-06-26 21:42:14 +0000 | [diff] [blame] | 1771 | Mask = ARI->getCallPreservedMask(CallConv); |
Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1772 | |
Matthias Braun | c22630e | 2013-10-04 16:52:54 +0000 | [diff] [blame] | 1773 | assert(Mask && "Missing call preserved mask for calling convention"); |
1774 | Ops.push_back(DAG.getRegisterMask(Mask)); | ||||
1775 | } | ||||
Jakob Stoklund Olesen | fa7a537 | 2012-02-24 01:19:29 +0000 | [diff] [blame] | 1776 | |
Gabor Greif | f304a7a | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1777 | if (InFlag.getNode()) |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1778 | Ops.push_back(InFlag); |
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1779 | |
Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1780 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
Dale Johannesen | 81ef35b | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1781 | if (isTailCall) |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 1782 | return DAG.getNode(ARMISD::TC_RETURN, dl, NodeTys, Ops); |
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1783 | |
Duncan Sands | 739a054 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1784 | // Returns a chain and a flag for retval copy to use. |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 1785 | Chain = DAG.getNode(CallOpc, dl, NodeTys, Ops); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1786 | InFlag = Chain.getValue(1); |
1787 | |||||
Chris Lattner | 2753955 | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1788 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, true), |
Andrew Trick | ad6d08a | 2013-05-29 22:03:55 +0000 | [diff] [blame] | 1789 | DAG.getIntPtrConstant(0, true), InFlag, dl); |
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1790 | if (!Ins.empty()) |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1791 | InFlag = Chain.getValue(1); |
1792 | |||||
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1793 | // Handle result values, copying them out of physregs into vregs that we |
1794 | // return. | ||||
Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1795 | return LowerCallResult(Chain, InFlag, CallConv, isVarArg, Ins, dl, DAG, |
Stephen Lin | 4eedb29 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1796 | InVals, isThisReturn, |
1797 | isThisReturn ? OutVals[0] : SDValue()); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1798 | } |
1799 | |||||
Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1800 | /// HandleByVal - Every parameter *after* a byval parameter is passed |
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1801 | /// on the stack. Remember the next parameter register to allocate, |
1802 | /// and then confiscate the rest of the parameter registers to insure | ||||
Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1803 | /// this. |
1804 | void | ||||
Stepan Dyatkovskiy | e59a920 | 2012-10-16 07:16:47 +0000 | [diff] [blame] | 1805 | ARMTargetLowering::HandleByVal( |
1806 | CCState *State, unsigned &size, unsigned Align) const { | ||||
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1807 | unsigned reg = State->AllocateReg(GPRArgRegs, 4); |
1808 | assert((State->getCallOrPrologue() == Prologue || | ||||
1809 | State->getCallOrPrologue() == Call) && | ||||
1810 | "unhandled ParmContext"); | ||||
Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1811 | |
Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1812 | if ((ARM::R0 <= reg) && (reg <= ARM::R3)) { |
Stepan Dyatkovskiy | e59a920 | 2012-10-16 07:16:47 +0000 | [diff] [blame] | 1813 | if (Subtarget->isAAPCS_ABI() && Align > 4) { |
1814 | unsigned AlignInRegs = Align / 4; | ||||
1815 | unsigned Waste = (ARM::R4 - reg) % AlignInRegs; | ||||
1816 | for (unsigned i = 0; i < Waste; ++i) | ||||
1817 | reg = State->AllocateReg(GPRArgRegs, 4); | ||||
1818 | } | ||||
1819 | if (reg != 0) { | ||||
Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1820 | unsigned excess = 4 * (ARM::R4 - reg); |
1821 | |||||
1822 | // Special case when NSAA != SP and parameter size greater than size of | ||||
1823 | // all remained GPR regs. In that case we can't split parameter, we must | ||||
1824 | // send it to stack. We also must set NCRN to R4, so waste all | ||||
1825 | // remained registers. | ||||
Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 1826 | const unsigned NSAAOffset = State->getNextStackOffset(); |
Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1827 | if (Subtarget->isAAPCS_ABI() && NSAAOffset != 0 && size > excess) { |
1828 | while (State->AllocateReg(GPRArgRegs, 4)) | ||||
1829 | ; | ||||
1830 | return; | ||||
1831 | } | ||||
1832 | |||||
1833 | // First register for byval parameter is the first register that wasn't | ||||
1834 | // allocated before this method call, so it would be "reg". | ||||
1835 | // If parameter is small enough to be saved in range [reg, r4), then | ||||
1836 | // the end (first after last) register would be reg + param-size-in-regs, | ||||
1837 | // else parameter would be splitted between registers and stack, | ||||
1838 | // end register would be r4 in this case. | ||||
1839 | unsigned ByValRegBegin = reg; | ||||
Stepan Dyatkovskiy | 2703bca | 2013-05-08 14:51:27 +0000 | [diff] [blame] | 1840 | unsigned ByValRegEnd = (size < excess) ? reg + size/4 : (unsigned)ARM::R4; |
Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1841 | State->addInRegsParamInfo(ByValRegBegin, ByValRegEnd); |
1842 | // Note, first register is allocated in the beginning of function already, | ||||
1843 | // allocate remained amount of registers we need. | ||||
1844 | for (unsigned i = reg+1; i != ByValRegEnd; ++i) | ||||
1845 | State->AllocateReg(GPRArgRegs, 4); | ||||
Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 1846 | // A byval parameter that is split between registers and memory needs its |
1847 | // size truncated here. | ||||
1848 | // In the case where the entire structure fits in registers, we set the | ||||
1849 | // size in memory to zero. | ||||
1850 | if (size < excess) | ||||
1851 | size = 0; | ||||
1852 | else | ||||
1853 | size -= excess; | ||||
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1854 | } |
1855 | } | ||||
Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1856 | } |
1857 | |||||
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1858 | /// MatchingStackOffset - Return true if the given stack call argument is |
1859 | /// already available in the same position (relatively) of the caller's | ||||
1860 | /// incoming argument stack. | ||||
1861 | static | ||||
1862 | bool MatchingStackOffset(SDValue Arg, unsigned Offset, ISD::ArgFlagsTy Flags, | ||||
1863 | MachineFrameInfo *MFI, const MachineRegisterInfo *MRI, | ||||
Craig Topper | 07720d8 | 2012-03-25 23:49:58 +0000 | [diff] [blame] | 1864 | const TargetInstrInfo *TII) { |
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1865 | unsigned Bytes = Arg.getValueType().getSizeInBits() / 8; |
1866 | int FI = INT_MAX; | ||||
1867 | if (Arg.getOpcode() == ISD::CopyFromReg) { | ||||
1868 | unsigned VR = cast<RegisterSDNode>(Arg.getOperand(1))->getReg(); | ||||
Jakob Stoklund Olesen | 2fb5b31 | 2011-01-10 02:58:51 +0000 | [diff] [blame] | 1869 | if (!TargetRegisterInfo::isVirtualRegister(VR)) |
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1870 | return false; |
1871 | MachineInstr *Def = MRI->getVRegDef(VR); | ||||
1872 | if (!Def) | ||||
1873 | return false; | ||||
1874 | if (!Flags.isByVal()) { | ||||
1875 | if (!TII->isLoadFromStackSlot(Def, FI)) | ||||
1876 | return false; | ||||
1877 | } else { | ||||
Dale Johannesen | e228928 | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1878 | return false; |
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1879 | } |
1880 | } else if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Arg)) { | ||||
1881 | if (Flags.isByVal()) | ||||
1882 | // ByVal argument is passed in as a pointer but it's now being | ||||
1883 | // dereferenced. e.g. | ||||
1884 | // define @foo(%struct.X* %A) { | ||||
1885 | // tail call @bar(%struct.X* byval %A) | ||||
1886 | // } | ||||
1887 | return false; | ||||
1888 | SDValue Ptr = Ld->getBasePtr(); | ||||
1889 | FrameIndexSDNode *FINode = dyn_cast<FrameIndexSDNode>(Ptr); | ||||
1890 | if (!FINode) | ||||
1891 | return false; | ||||
1892 | FI = FINode->getIndex(); | ||||
1893 | } else | ||||
1894 | return false; | ||||
1895 | |||||
1896 | assert(FI != INT_MAX); | ||||
1897 | if (!MFI->isFixedObjectIndex(FI)) | ||||
1898 | return false; | ||||
1899 | return Offset == MFI->getObjectOffset(FI) && Bytes == MFI->getObjectSize(FI); | ||||
1900 | } | ||||
1901 | |||||
1902 | /// IsEligibleForTailCallOptimization - Check whether the call is eligible | ||||
1903 | /// for tail call optimization. Targets which want to do tail call | ||||
1904 | /// optimization should implement this function. | ||||
1905 | bool | ||||
1906 | ARMTargetLowering::IsEligibleForTailCallOptimization(SDValue Callee, | ||||
1907 | CallingConv::ID CalleeCC, | ||||
1908 | bool isVarArg, | ||||
1909 | bool isCalleeStructRet, | ||||
1910 | bool isCallerStructRet, | ||||
1911 | const SmallVectorImpl<ISD::OutputArg> &Outs, | ||||
Dan Gohman | fe7532a | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1912 | const SmallVectorImpl<SDValue> &OutVals, |
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1913 | const SmallVectorImpl<ISD::InputArg> &Ins, |
1914 | SelectionDAG& DAG) const { | ||||
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1915 | const Function *CallerF = DAG.getMachineFunction().getFunction(); |
1916 | CallingConv::ID CallerCC = CallerF->getCallingConv(); | ||||
1917 | bool CCMatch = CallerCC == CalleeCC; | ||||
1918 | |||||
1919 | // Look for obvious safe cases to perform tail call optimization that do not | ||||
1920 | // require ABI changes. This is what gcc calls sibcall. | ||||
1921 | |||||
Jim Grosbach | e3864cc | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 1922 | // Do not sibcall optimize vararg calls unless the call site is not passing |
1923 | // any arguments. | ||||
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1924 | if (isVarArg && !Outs.empty()) |
1925 | return false; | ||||
1926 | |||||
Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 1927 | // Exception-handling functions need a special set of instructions to indicate |
1928 | // a return to the hardware. Tail-calling another function would probably | ||||
1929 | // break this. | ||||
1930 | if (CallerF->hasFnAttribute("interrupt")) | ||||
1931 | return false; | ||||
1932 | |||||
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1933 | // Also avoid sibcall optimization if either caller or callee uses struct |
1934 | // return semantics. | ||||
1935 | if (isCalleeStructRet || isCallerStructRet) | ||||
1936 | return false; | ||||
1937 | |||||
Dale Johannesen | d24c66b | 2010-06-23 18:52:34 +0000 | [diff] [blame] | 1938 | // FIXME: Completely disable sibcall for Thumb1 since Thumb1RegisterInfo:: |
Jim Grosbach | 3840c90 | 2011-07-08 20:18:11 +0000 | [diff] [blame] | 1939 | // emitEpilogue is not ready for them. Thumb tail calls also use t2B, as |
1940 | // the Thumb1 16-bit unconditional branch doesn't have sufficient relocation | ||||
1941 | // support in the assembler and linker to be used. This would need to be | ||||
1942 | // fixed to fully support tail calls in Thumb1. | ||||
1943 | // | ||||
Dale Johannesen | e228928 | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1944 | // Doing this is tricky, since the LDM/POP instruction on Thumb doesn't take |
1945 | // LR. This means if we need to reload LR, it takes an extra instructions, | ||||
1946 | // which outweighs the value of the tail call; but here we don't know yet | ||||
1947 | // whether LR is going to be used. Probably the right approach is to | ||||
Jim Grosbach | 535d3b4 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 1948 | // generate the tail call here and turn it back into CALL/RET in |
Dale Johannesen | e228928 | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1949 | // emitEpilogue if LR is used. |
Dale Johannesen | e228928 | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1950 | |
1951 | // Thumb1 PIC calls to external symbols use BX, so they can be tail calls, | ||||
1952 | // but we need to make sure there are enough registers; the only valid | ||||
1953 | // registers are the 4 used for parameters. We don't currently do this | ||||
1954 | // case. | ||||
Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1955 | if (Subtarget->isThumb1Only()) |
1956 | return false; | ||||
Dale Johannesen | 3ac52b3 | 2010-06-18 18:13:11 +0000 | [diff] [blame] | 1957 | |
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1958 | // If the calling conventions do not match, then we'd better make sure the |
1959 | // results are returned in the same way as what the caller expects. | ||||
1960 | if (!CCMatch) { | ||||
1961 | SmallVector<CCValAssign, 16> RVLocs1; | ||||
Cameron Zwarich | 8901978 | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1962 | ARMCCState CCInfo1(CalleeCC, false, DAG.getMachineFunction(), |
1963 | getTargetMachine(), RVLocs1, *DAG.getContext(), Call); | ||||
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1964 | CCInfo1.AnalyzeCallResult(Ins, CCAssignFnForNode(CalleeCC, true, isVarArg)); |
1965 | |||||
1966 | SmallVector<CCValAssign, 16> RVLocs2; | ||||
Cameron Zwarich | 8901978 | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1967 | ARMCCState CCInfo2(CallerCC, false, DAG.getMachineFunction(), |
1968 | getTargetMachine(), RVLocs2, *DAG.getContext(), Call); | ||||
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1969 | CCInfo2.AnalyzeCallResult(Ins, CCAssignFnForNode(CallerCC, true, isVarArg)); |
1970 | |||||
1971 | if (RVLocs1.size() != RVLocs2.size()) | ||||
1972 | return false; | ||||
1973 | for (unsigned i = 0, e = RVLocs1.size(); i != e; ++i) { | ||||
1974 | if (RVLocs1[i].isRegLoc() != RVLocs2[i].isRegLoc()) | ||||
1975 | return false; | ||||
1976 | if (RVLocs1[i].getLocInfo() != RVLocs2[i].getLocInfo()) | ||||
1977 | return false; | ||||
1978 | if (RVLocs1[i].isRegLoc()) { | ||||
1979 | if (RVLocs1[i].getLocReg() != RVLocs2[i].getLocReg()) | ||||
1980 | return false; | ||||
1981 | } else { | ||||
1982 | if (RVLocs1[i].getLocMemOffset() != RVLocs2[i].getLocMemOffset()) | ||||
1983 | return false; | ||||
1984 | } | ||||
1985 | } | ||||
1986 | } | ||||
1987 | |||||
Manman Ren | 7e48b25 | 2012-10-12 23:39:43 +0000 | [diff] [blame] | 1988 | // If Caller's vararg or byval argument has been split between registers and |
1989 | // stack, do not perform tail call, since part of the argument is in caller's | ||||
1990 | // local frame. | ||||
1991 | const ARMFunctionInfo *AFI_Caller = DAG.getMachineFunction(). | ||||
1992 | getInfo<ARMFunctionInfo>(); | ||||
Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 1993 | if (AFI_Caller->getArgRegsSaveSize()) |
Manman Ren | 7e48b25 | 2012-10-12 23:39:43 +0000 | [diff] [blame] | 1994 | return false; |
1995 | |||||
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1996 | // If the callee takes no arguments then go on to check the results of the |
1997 | // call. | ||||
1998 | if (!Outs.empty()) { | ||||
1999 | // Check if stack adjustment is needed. For now, do not do this if any | ||||
2000 | // argument is passed on the stack. | ||||
2001 | SmallVector<CCValAssign, 16> ArgLocs; | ||||
Cameron Zwarich | 8901978 | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 2002 | ARMCCState CCInfo(CalleeCC, isVarArg, DAG.getMachineFunction(), |
2003 | getTargetMachine(), ArgLocs, *DAG.getContext(), Call); | ||||
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2004 | CCInfo.AnalyzeCallOperands(Outs, |
2005 | CCAssignFnForNode(CalleeCC, false, isVarArg)); | ||||
2006 | if (CCInfo.getNextStackOffset()) { | ||||
2007 | MachineFunction &MF = DAG.getMachineFunction(); | ||||
2008 | |||||
2009 | // Check if the arguments are already laid out in the right way as | ||||
2010 | // the caller's fixed stack objects. | ||||
2011 | MachineFrameInfo *MFI = MF.getFrameInfo(); | ||||
2012 | const MachineRegisterInfo *MRI = &MF.getRegInfo(); | ||||
Craig Topper | 07720d8 | 2012-03-25 23:49:58 +0000 | [diff] [blame] | 2013 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Dale Johannesen | 81ef35b | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 2014 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
2015 | i != e; | ||||
2016 | ++i, ++realArgIdx) { | ||||
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2017 | CCValAssign &VA = ArgLocs[i]; |
2018 | EVT RegVT = VA.getLocVT(); | ||||
Dan Gohman | fe7532a | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 2019 | SDValue Arg = OutVals[realArgIdx]; |
Dale Johannesen | 81ef35b | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 2020 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2021 | if (VA.getLocInfo() == CCValAssign::Indirect) |
2022 | return false; | ||||
Dale Johannesen | 81ef35b | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 2023 | if (VA.needsCustom()) { |
2024 | // f64 and vector types are split into multiple registers or | ||||
2025 | // register/stack-slot combinations. The types will not match | ||||
2026 | // the registers; give up on memory f64 refs until we figure | ||||
2027 | // out what to do about this. | ||||
2028 | if (!VA.isRegLoc()) | ||||
2029 | return false; | ||||
2030 | if (!ArgLocs[++i].isRegLoc()) | ||||
Jim Grosbach | 535d3b4 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 2031 | return false; |
Dale Johannesen | 81ef35b | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 2032 | if (RegVT == MVT::v2f64) { |
2033 | if (!ArgLocs[++i].isRegLoc()) | ||||
2034 | return false; | ||||
2035 | if (!ArgLocs[++i].isRegLoc()) | ||||
2036 | return false; | ||||
2037 | } | ||||
2038 | } else if (!VA.isRegLoc()) { | ||||
Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2039 | if (!MatchingStackOffset(Arg, VA.getLocMemOffset(), Flags, |
2040 | MFI, MRI, TII)) | ||||
2041 | return false; | ||||
2042 | } | ||||
2043 | } | ||||
2044 | } | ||||
2045 | } | ||||
2046 | |||||
2047 | return true; | ||||
2048 | } | ||||
2049 | |||||
Benjamin Kramer | b1996da | 2012-11-28 20:55:10 +0000 | [diff] [blame] | 2050 | bool |
2051 | ARMTargetLowering::CanLowerReturn(CallingConv::ID CallConv, | ||||
2052 | MachineFunction &MF, bool isVarArg, | ||||
2053 | const SmallVectorImpl<ISD::OutputArg> &Outs, | ||||
2054 | LLVMContext &Context) const { | ||||
2055 | SmallVector<CCValAssign, 16> RVLocs; | ||||
2056 | CCState CCInfo(CallConv, isVarArg, MF, getTargetMachine(), RVLocs, Context); | ||||
2057 | return CCInfo.CheckReturn(Outs, CCAssignFnForNode(CallConv, /*Return=*/true, | ||||
2058 | isVarArg)); | ||||
2059 | } | ||||
2060 | |||||
Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 2061 | static SDValue LowerInterruptReturn(SmallVectorImpl<SDValue> &RetOps, |
2062 | SDLoc DL, SelectionDAG &DAG) { | ||||
2063 | const MachineFunction &MF = DAG.getMachineFunction(); | ||||
2064 | const Function *F = MF.getFunction(); | ||||
2065 | |||||
2066 | StringRef IntKind = F->getFnAttribute("interrupt").getValueAsString(); | ||||
2067 | |||||
2068 | // See ARM ARM v7 B1.8.3. On exception entry LR is set to a possibly offset | ||||
2069 | // version of the "preferred return address". These offsets affect the return | ||||
2070 | // instruction if this is a return from PL1 without hypervisor extensions. | ||||
2071 | // IRQ/FIQ: +4 "subs pc, lr, #4" | ||||
2072 | // SWI: 0 "subs pc, lr, #0" | ||||
2073 | // ABORT: +4 "subs pc, lr, #4" | ||||
2074 | // UNDEF: +4/+2 "subs pc, lr, #0" | ||||
2075 | // UNDEF varies depending on where the exception came from ARM or Thumb | ||||
2076 | // mode. Alongside GCC, we throw our hands up in disgust and pretend it's 0. | ||||
2077 | |||||
2078 | int64_t LROffset; | ||||
2079 | if (IntKind == "" || IntKind == "IRQ" || IntKind == "FIQ" || | ||||
2080 | IntKind == "ABORT") | ||||
2081 | LROffset = 4; | ||||
2082 | else if (IntKind == "SWI" || IntKind == "UNDEF") | ||||
2083 | LROffset = 0; | ||||
2084 | else | ||||
2085 | report_fatal_error("Unsupported interrupt attribute. If present, value " | ||||
2086 | "must be one of: IRQ, FIQ, SWI, ABORT or UNDEF"); | ||||
2087 | |||||
2088 | RetOps.insert(RetOps.begin() + 1, DAG.getConstant(LROffset, MVT::i32, false)); | ||||
2089 | |||||
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 2090 | return DAG.getNode(ARMISD::INTRET_FLAG, DL, MVT::Other, RetOps); |
Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 2091 | } |
2092 | |||||
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2093 | SDValue |
2094 | ARMTargetLowering::LowerReturn(SDValue Chain, | ||||
Sandeep Patel | 68c5f47 | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 2095 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2096 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | fe7532a | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 2097 | const SmallVectorImpl<SDValue> &OutVals, |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2098 | SDLoc dl, SelectionDAG &DAG) const { |
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2099 | |
Bob Wilson | ea09d4a | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2100 | // CCValAssign - represent the assignment of the return value to a location. |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2101 | SmallVector<CCValAssign, 16> RVLocs; |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2102 | |
Bob Wilson | ea09d4a | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2103 | // CCState - Info about the registers and stack slots. |
Cameron Zwarich | 8901978 | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 2104 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
2105 | getTargetMachine(), RVLocs, *DAG.getContext(), Call); | ||||
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2106 | |
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2107 | // Analyze outgoing return values. |
Anton Korobeynikov | 22ef751 | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2108 | CCInfo.AnalyzeReturn(Outs, CCAssignFnForNode(CallConv, /* Return */ true, |
2109 | isVarArg)); | ||||
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2110 | |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2111 | SDValue Flag; |
Jakob Stoklund Olesen | f90fb6e | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2112 | SmallVector<SDValue, 4> RetOps; |
2113 | RetOps.push_back(Chain); // Operand #0 = Chain (updated below) | ||||
Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 2114 | bool isLittleEndian = Subtarget->isLittle(); |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2115 | |
2116 | // Copy the result values into the output registers. | ||||
2117 | for (unsigned i = 0, realRVLocIdx = 0; | ||||
2118 | i != RVLocs.size(); | ||||
2119 | ++i, ++realRVLocIdx) { | ||||
2120 | CCValAssign &VA = RVLocs[i]; | ||||
2121 | assert(VA.isRegLoc() && "Can only return in registers!"); | ||||
2122 | |||||
Dan Gohman | fe7532a | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 2123 | SDValue Arg = OutVals[realRVLocIdx]; |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2124 | |
2125 | switch (VA.getLocInfo()) { | ||||
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2126 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2127 | case CCValAssign::Full: break; |
2128 | case CCValAssign::BCvt: | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2129 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2130 | break; |
2131 | } | ||||
2132 | |||||
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2133 | if (VA.needsCustom()) { |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2134 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2135 | // Extract the first half and return it in two registers. |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2136 | SDValue Half = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
2137 | DAG.getConstant(0, MVT::i32)); | ||||
Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2138 | SDValue HalfGPRs = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2139 | DAG.getVTList(MVT::i32, MVT::i32), Half); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2140 | |
Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 2141 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
2142 | HalfGPRs.getValue(isLittleEndian ? 0 : 1), | ||||
2143 | Flag); | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2144 | Flag = Chain.getValue(1); |
Jakob Stoklund Olesen | f90fb6e | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2145 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2146 | VA = RVLocs[++i]; // skip ahead to next loc |
2147 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), | ||||
Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 2148 | HalfGPRs.getValue(isLittleEndian ? 1 : 0), |
2149 | Flag); | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2150 | Flag = Chain.getValue(1); |
Jakob Stoklund Olesen | f90fb6e | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2151 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2152 | VA = RVLocs[++i]; // skip ahead to next loc |
2153 | |||||
2154 | // Extract the 2nd half and fall through to handle it as an f64 value. | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2155 | Arg = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
2156 | DAG.getConstant(1, MVT::i32)); | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2157 | } |
2158 | // Legalize ret f64 -> ret 2 x i32. We always have fmrrd if f64 is | ||||
2159 | // available. | ||||
Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2160 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 2161 | DAG.getVTList(MVT::i32, MVT::i32), Arg); |
Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 2162 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
2163 | fmrrd.getValue(isLittleEndian ? 0 : 1), | ||||
2164 | Flag); | ||||
Bob Wilson | f134b2d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 2165 | Flag = Chain.getValue(1); |
Jakob Stoklund Olesen | f90fb6e | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2166 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2167 | VA = RVLocs[++i]; // skip ahead to next loc |
Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 2168 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
2169 | fmrrd.getValue(isLittleEndian ? 1 : 0), | ||||
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2170 | Flag); |
2171 | } else | ||||
2172 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), Arg, Flag); | ||||
2173 | |||||
Bob Wilson | ea09d4a | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2174 | // Guarantee that all emitted copies are |
2175 | // stuck together, avoiding something bad. | ||||
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2176 | Flag = Chain.getValue(1); |
Jakob Stoklund Olesen | f90fb6e | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2177 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2178 | } |
2179 | |||||
Jakob Stoklund Olesen | f90fb6e | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2180 | // Update chain and glue. |
2181 | RetOps[0] = Chain; | ||||
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2182 | if (Flag.getNode()) |
Jakob Stoklund Olesen | f90fb6e | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2183 | RetOps.push_back(Flag); |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2184 | |
Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 2185 | // CPUs which aren't M-class use a special sequence to return from |
2186 | // exceptions (roughly, any instruction setting pc and cpsr simultaneously, | ||||
2187 | // though we use "subs pc, lr, #N"). | ||||
2188 | // | ||||
2189 | // M-class CPUs actually use a normal return sequence with a special | ||||
2190 | // (hardware-provided) value in LR, so the normal code path works. | ||||
2191 | if (DAG.getMachineFunction().getFunction()->hasFnAttribute("interrupt") && | ||||
2192 | !Subtarget->isMClass()) { | ||||
2193 | if (Subtarget->isThumb1Only()) | ||||
2194 | report_fatal_error("interrupt attribute is not supported in Thumb1"); | ||||
2195 | return LowerInterruptReturn(RetOps, dl, DAG); | ||||
2196 | } | ||||
2197 | |||||
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 2198 | return DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, RetOps); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2199 | } |
2200 | |||||
Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2201 | bool ARMTargetLowering::isUsedByReturnOnly(SDNode *N, SDValue &Chain) const { |
Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2202 | if (N->getNumValues() != 1) |
2203 | return false; | ||||
2204 | if (!N->hasNUsesOfValue(1, 0)) | ||||
2205 | return false; | ||||
2206 | |||||
Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2207 | SDValue TCChain = Chain; |
2208 | SDNode *Copy = *N->use_begin(); | ||||
2209 | if (Copy->getOpcode() == ISD::CopyToReg) { | ||||
2210 | // If the copy has a glue operand, we conservatively assume it isn't safe to | ||||
2211 | // perform a tail call. | ||||
2212 | if (Copy->getOperand(Copy->getNumOperands()-1).getValueType() == MVT::Glue) | ||||
2213 | return false; | ||||
2214 | TCChain = Copy->getOperand(0); | ||||
2215 | } else if (Copy->getOpcode() == ARMISD::VMOVRRD) { | ||||
2216 | SDNode *VMov = Copy; | ||||
Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2217 | // f64 returned in a pair of GPRs. |
Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2218 | SmallPtrSet<SDNode*, 2> Copies; |
2219 | for (SDNode::use_iterator UI = VMov->use_begin(), UE = VMov->use_end(); | ||||
Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2220 | UI != UE; ++UI) { |
2221 | if (UI->getOpcode() != ISD::CopyToReg) | ||||
2222 | return false; | ||||
Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2223 | Copies.insert(*UI); |
Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2224 | } |
Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2225 | if (Copies.size() > 2) |
2226 | return false; | ||||
2227 | |||||
2228 | for (SDNode::use_iterator UI = VMov->use_begin(), UE = VMov->use_end(); | ||||
2229 | UI != UE; ++UI) { | ||||
2230 | SDValue UseChain = UI->getOperand(0); | ||||
2231 | if (Copies.count(UseChain.getNode())) | ||||
2232 | // Second CopyToReg | ||||
2233 | Copy = *UI; | ||||
2234 | else | ||||
2235 | // First CopyToReg | ||||
2236 | TCChain = UseChain; | ||||
2237 | } | ||||
2238 | } else if (Copy->getOpcode() == ISD::BITCAST) { | ||||
Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2239 | // f32 returned in a single GPR. |
Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2240 | if (!Copy->hasOneUse()) |
Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2241 | return false; |
Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2242 | Copy = *Copy->use_begin(); |
2243 | if (Copy->getOpcode() != ISD::CopyToReg || !Copy->hasNUsesOfValue(1, 0)) | ||||
Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2244 | return false; |
Lang Hames | 67c09b3 | 2013-05-13 10:21:19 +0000 | [diff] [blame] | 2245 | TCChain = Copy->getOperand(0); |
Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2246 | } else { |
2247 | return false; | ||||
2248 | } | ||||
2249 | |||||
Evan Cheng | 419ea28 | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 2250 | bool HasRet = false; |
Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2251 | for (SDNode::use_iterator UI = Copy->use_begin(), UE = Copy->use_end(); |
2252 | UI != UE; ++UI) { | ||||
Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 2253 | if (UI->getOpcode() != ARMISD::RET_FLAG && |
2254 | UI->getOpcode() != ARMISD::INTRET_FLAG) | ||||
Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2255 | return false; |
2256 | HasRet = true; | ||||
Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2257 | } |
2258 | |||||
Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2259 | if (!HasRet) |
2260 | return false; | ||||
2261 | |||||
2262 | Chain = TCChain; | ||||
2263 | return true; | ||||
Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2264 | } |
2265 | |||||
Evan Cheng | 0663f23 | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 2266 | bool ARMTargetLowering::mayBeEmittedAsTailCall(CallInst *CI) const { |
Saleem Abdulrasool | b720a6b | 2014-03-11 15:09:49 +0000 | [diff] [blame] | 2267 | if (!Subtarget->supportsTailCall()) |
Evan Cheng | 0663f23 | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 2268 | return false; |
2269 | |||||
Saleem Abdulrasool | 0d96f3d | 2014-03-11 15:09:54 +0000 | [diff] [blame] | 2270 | if (!CI->isTailCall() || getTargetMachine().Options.DisableTailCalls) |
Evan Cheng | 0663f23 | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 2271 | return false; |
2272 | |||||
2273 | return !Subtarget->isThumb1Only(); | ||||
2274 | } | ||||
2275 | |||||
Bob Wilson | b389f2a | 2009-11-03 00:02:05 +0000 | [diff] [blame] | 2276 | // ConstantPool, JumpTable, GlobalAddress, and ExternalSymbol are lowered as |
2277 | // their target counterpart wrapped in the ARMISD::Wrapper node. Suppose N is | ||||
2278 | // one of the above mentioned nodes. It has to be wrapped because otherwise | ||||
2279 | // Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only | ||||
2280 | // be used to form addressing mode. These wrapped nodes will be selected | ||||
2281 | // into MOVi. | ||||
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2282 | static SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) { |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2283 | EVT PtrVT = Op.getValueType(); |
Dale Johannesen | 62fd95d | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 2284 | // FIXME there is no actual debug info here |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2285 | SDLoc dl(Op); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2286 | ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); |
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2287 | SDValue Res; |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2288 | if (CP->isMachineConstantPoolEntry()) |
2289 | Res = DAG.getTargetConstantPool(CP->getMachineCPVal(), PtrVT, | ||||
2290 | CP->getAlignment()); | ||||
2291 | else | ||||
2292 | Res = DAG.getTargetConstantPool(CP->getConstVal(), PtrVT, | ||||
2293 | CP->getAlignment()); | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2294 | return DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Res); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2295 | } |
2296 | |||||
Jim Grosbach | 8d3ba73 | 2010-07-19 17:20:38 +0000 | [diff] [blame] | 2297 | unsigned ARMTargetLowering::getJumpTableEncoding() const { |
2298 | return MachineJumpTableInfo::EK_Inline; | ||||
2299 | } | ||||
2300 | |||||
Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2301 | SDValue ARMTargetLowering::LowerBlockAddress(SDValue Op, |
2302 | SelectionDAG &DAG) const { | ||||
Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2303 | MachineFunction &MF = DAG.getMachineFunction(); |
2304 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); | ||||
2305 | unsigned ARMPCLabelIndex = 0; | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2306 | SDLoc DL(Op); |
Bob Wilson | 1c66e8a | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2307 | EVT PtrVT = getPointerTy(); |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2308 | const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress(); |
Bob Wilson | 1c66e8a | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2309 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
2310 | SDValue CPAddr; | ||||
2311 | if (RelocM == Reloc::Static) { | ||||
2312 | CPAddr = DAG.getTargetConstantPool(BA, PtrVT, 4); | ||||
2313 | } else { | ||||
2314 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; | ||||
Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2315 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | 7753d66 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2316 | ARMConstantPoolValue *CPV = |
2317 | ARMConstantPoolConstant::Create(BA, ARMPCLabelIndex, | ||||
2318 | ARMCP::CPBlockAddress, PCAdj); | ||||
Bob Wilson | 1c66e8a | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2319 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
2320 | } | ||||
2321 | CPAddr = DAG.getNode(ARMISD::Wrapper, DL, PtrVT, CPAddr); | ||||
2322 | SDValue Result = DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), CPAddr, | ||||
Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2323 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2324 | false, false, false, 0); |
Bob Wilson | 1c66e8a | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2325 | if (RelocM == Reloc::Static) |
2326 | return Result; | ||||
Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2327 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 1c66e8a | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2328 | return DAG.getNode(ARMISD::PIC_ADD, DL, PtrVT, Result, PICLabel); |
Bob Wilson | 1cf0b03 | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 2329 | } |
2330 | |||||
Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2331 | // Lower ISD::GlobalTLSAddress using the "general dynamic" model |
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2332 | SDValue |
Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2333 | ARMTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, |
Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2334 | SelectionDAG &DAG) const { |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2335 | SDLoc dl(GA); |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2336 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2337 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2338 | MachineFunction &MF = DAG.getMachineFunction(); |
2339 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); | ||||
Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2340 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2341 | ARMConstantPoolValue *CPV = |
Bill Wendling | 7753d66 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2342 | ARMConstantPoolConstant::Create(GA->getGlobal(), ARMPCLabelIndex, |
2343 | ARMCP::CPValue, PCAdj, ARMCP::TLSGD, true); | ||||
Evan Cheng | 1fb8aed | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2344 | SDValue Argument = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2345 | Argument = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Argument); |
Evan Cheng | cdbb70c | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2346 | Argument = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Argument, |
Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2347 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2348 | false, false, false, 0); |
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2349 | SDValue Chain = Argument.getValue(1); |
Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2350 | |
Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2351 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2352 | Argument = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Argument, PICLabel); |
Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2353 | |
2354 | // call __tls_get_addr. | ||||
2355 | ArgListTy Args; | ||||
2356 | ArgListEntry Entry; | ||||
2357 | Entry.Node = Argument; | ||||
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2358 | Entry.Ty = (Type *) Type::getInt32Ty(*DAG.getContext()); |
Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2359 | Args.push_back(Entry); |
Dale Johannesen | 555a375 | 2009-01-30 23:10:59 +0000 | [diff] [blame] | 2360 | // FIXME: is there useful debug info available here? |
Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 2361 | TargetLowering::CallLoweringInfo CLI(Chain, |
2362 | (Type *) Type::getInt32Ty(*DAG.getContext()), | ||||
Evan Cheng | 09c070f | 2009-08-14 19:11:20 +0000 | [diff] [blame] | 2363 | false, false, false, false, |
Evan Cheng | 65f9d19 | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 2364 | 0, CallingConv::C, /*isTailCall=*/false, |
2365 | /*doesNotRet=*/false, /*isReturnValueUsed=*/true, | ||||
Bill Wendling | 78c5b7a | 2010-03-02 01:55:18 +0000 | [diff] [blame] | 2366 | DAG.getExternalSymbol("__tls_get_addr", PtrVT), Args, DAG, dl); |
Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 2367 | std::pair<SDValue, SDValue> CallResult = LowerCallTo(CLI); |
Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2368 | return CallResult.first; |
2369 | } | ||||
2370 | |||||
2371 | // Lower ISD::GlobalTLSAddress using the "initial exec" or | ||||
2372 | // "local exec" model. | ||||
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2373 | SDValue |
Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2374 | ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA, |
Hans Wennborg | aea4120 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2375 | SelectionDAG &DAG, |
2376 | TLSModel::Model model) const { | ||||
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2377 | const GlobalValue *GV = GA->getGlobal(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2378 | SDLoc dl(GA); |
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2379 | SDValue Offset; |
2380 | SDValue Chain = DAG.getEntryNode(); | ||||
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2381 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2382 | // Get the Thread Pointer |
Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2383 | SDValue ThreadPointer = DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2384 | |
Hans Wennborg | aea4120 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2385 | if (model == TLSModel::InitialExec) { |
Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2386 | MachineFunction &MF = DAG.getMachineFunction(); |
2387 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); | ||||
Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2388 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2389 | // Initial exec model. |
Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2390 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
2391 | ARMConstantPoolValue *CPV = | ||||
Bill Wendling | 7753d66 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2392 | ARMConstantPoolConstant::Create(GA->getGlobal(), ARMPCLabelIndex, |
2393 | ARMCP::CPValue, PCAdj, ARMCP::GOTTPOFF, | ||||
2394 | true); | ||||
Evan Cheng | 1fb8aed | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2395 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2396 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | cdbb70c | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2397 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2398 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2399 | false, false, false, 0); |
Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2400 | Chain = Offset.getValue(1); |
2401 | |||||
Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2402 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2403 | Offset = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Offset, PICLabel); |
Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2404 | |
Evan Cheng | cdbb70c | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2405 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2406 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2407 | false, false, false, 0); |
Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2408 | } else { |
2409 | // local exec model | ||||
Hans Wennborg | aea4120 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2410 | assert(model == TLSModel::LocalExec); |
Bill Wendling | 7753d66 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2411 | ARMConstantPoolValue *CPV = |
2412 | ARMConstantPoolConstant::Create(GV, ARMCP::TPOFF); | ||||
Evan Cheng | 1fb8aed | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2413 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2414 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | cdbb70c | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2415 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2416 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2417 | false, false, false, 0); |
Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2418 | } |
2419 | |||||
2420 | // The address of the thread local variable is the add of the thread | ||||
2421 | // pointer with the offset of the variable. | ||||
Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2422 | return DAG.getNode(ISD::ADD, dl, PtrVT, ThreadPointer, Offset); |
Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2423 | } |
2424 | |||||
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2425 | SDValue |
Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2426 | ARMTargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const { |
Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2427 | // TODO: implement the "local dynamic" model |
2428 | assert(Subtarget->isTargetELF() && | ||||
2429 | "TLS not implemented for non-ELF targets"); | ||||
2430 | GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); | ||||
Hans Wennborg | aea4120 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2431 | |
2432 | TLSModel::Model model = getTargetMachine().getTLSModel(GA->getGlobal()); | ||||
2433 | |||||
2434 | switch (model) { | ||||
2435 | case TLSModel::GeneralDynamic: | ||||
2436 | case TLSModel::LocalDynamic: | ||||
2437 | return LowerToTLSGeneralDynamicModel(GA, DAG); | ||||
2438 | case TLSModel::InitialExec: | ||||
2439 | case TLSModel::LocalExec: | ||||
2440 | return LowerToTLSExecModels(GA, DAG, model); | ||||
2441 | } | ||||
Matt Beaumont-Gay | e82ab6b | 2012-05-04 18:34:27 +0000 | [diff] [blame] | 2442 | llvm_unreachable("bogus TLS model"); |
Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2443 | } |
2444 | |||||
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2445 | SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op, |
Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2446 | SelectionDAG &DAG) const { |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2447 | EVT PtrVT = getPointerTy(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2448 | SDLoc dl(Op); |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2449 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Chad Rosier | 537ff50 | 2013-02-28 19:16:42 +0000 | [diff] [blame] | 2450 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Rafael Espindola | 6de96a1 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 2451 | bool UseGOTOFF = GV->hasLocalLinkage() || GV->hasHiddenVisibility(); |
Lauro Ramos Venancio | ee2d164 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2452 | ARMConstantPoolValue *CPV = |
Bill Wendling | 7753d66 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2453 | ARMConstantPoolConstant::Create(GV, |
2454 | UseGOTOFF ? ARMCP::GOTOFF : ARMCP::GOT); | ||||
Evan Cheng | 1fb8aed | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2455 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2456 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2457 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), |
Anton Korobeynikov | 75b59fb | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2458 | CPAddr, |
Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2459 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2460 | false, false, false, 0); |
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2461 | SDValue Chain = Result.getValue(1); |
Dale Johannesen | 62fd95d | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 2462 | SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(PtrVT); |
Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2463 | Result = DAG.getNode(ISD::ADD, dl, PtrVT, Result, GOT); |
Lauro Ramos Venancio | ee2d164 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2464 | if (!UseGOTOFF) |
Anton Korobeynikov | 75b59fb | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2465 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, |
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2466 | MachinePointerInfo::getGOT(), |
2467 | false, false, false, 0); | ||||
Lauro Ramos Venancio | ee2d164 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2468 | return Result; |
Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2469 | } |
2470 | |||||
2471 | // If we have T2 ops, we can materialize the address directly via movt/movw | ||||
James Molloy | dd9137a | 2011-10-26 08:53:19 +0000 | [diff] [blame] | 2472 | // pair. This is always cheaper. |
2473 | if (Subtarget->useMovt()) { | ||||
Evan Cheng | 68aec14 | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2474 | ++NumMovwMovt; |
Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2475 | // FIXME: Once remat is capable of dealing with instructions with register |
2476 | // operands, expand this into two nodes. | ||||
2477 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, | ||||
2478 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); | ||||
Lauro Ramos Venancio | ee2d164 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2479 | } else { |
Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2480 | SDValue CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
2481 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); | ||||
2482 | return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, | ||||
2483 | MachinePointerInfo::getConstantPool(), | ||||
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2484 | false, false, false, 0); |
Lauro Ramos Venancio | ee2d164 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2485 | } |
2486 | } | ||||
2487 | |||||
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2488 | SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op, |
Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2489 | SelectionDAG &DAG) const { |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2490 | EVT PtrVT = getPointerTy(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2491 | SDLoc dl(Op); |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2492 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2493 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2494 | |
Tim Northover | 72360d2 | 2013-12-02 10:35:41 +0000 | [diff] [blame] | 2495 | if (Subtarget->useMovt()) |
Evan Cheng | 68aec14 | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2496 | ++NumMovwMovt; |
Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2497 | |
Tim Northover | 72360d2 | 2013-12-02 10:35:41 +0000 | [diff] [blame] | 2498 | // FIXME: Once remat is capable of dealing with instructions with register |
2499 | // operands, expand this into multiple nodes | ||||
2500 | unsigned Wrapper = | ||||
2501 | RelocM == Reloc::PIC_ ? ARMISD::WrapperPIC : ARMISD::Wrapper; | ||||
Tim Northover | db962e2c | 2013-11-25 16:24:52 +0000 | [diff] [blame] | 2502 | |
Tim Northover | 72360d2 | 2013-12-02 10:35:41 +0000 | [diff] [blame] | 2503 | SDValue G = DAG.getTargetGlobalAddress(GV, dl, PtrVT, 0, ARMII::MO_NONLAZY); |
2504 | SDValue Result = DAG.getNode(Wrapper, dl, PtrVT, G); | ||||
Evan Cheng | 43b9ca6 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2505 | |
Evan Cheng | 1b38952 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 2506 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
Tim Northover | 72360d2 | 2013-12-02 10:35:41 +0000 | [diff] [blame] | 2507 | Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Result, |
2508 | MachinePointerInfo::getGOT(), false, false, false, 0); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2509 | return Result; |
2510 | } | ||||
2511 | |||||
Saleem Abdulrasool | 40bca0a | 2014-05-09 00:58:32 +0000 | [diff] [blame] | 2512 | SDValue ARMTargetLowering::LowerGlobalAddressWindows(SDValue Op, |
2513 | SelectionDAG &DAG) const { | ||||
2514 | assert(Subtarget->isTargetWindows() && "non-Windows COFF is not supported"); | ||||
2515 | assert(Subtarget->useMovt() && "Windows on ARM expects to use movw/movt"); | ||||
2516 | |||||
2517 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); | ||||
2518 | EVT PtrVT = getPointerTy(); | ||||
2519 | SDLoc DL(Op); | ||||
2520 | |||||
2521 | ++NumMovwMovt; | ||||
2522 | |||||
2523 | // FIXME: Once remat is capable of dealing with instructions with register | ||||
2524 | // operands, expand this into two nodes. | ||||
2525 | return DAG.getNode(ARMISD::Wrapper, DL, PtrVT, | ||||
2526 | DAG.getTargetGlobalAddress(GV, DL, PtrVT)); | ||||
2527 | } | ||||
2528 | |||||
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2529 | SDValue ARMTargetLowering::LowerGLOBAL_OFFSET_TABLE(SDValue Op, |
Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2530 | SelectionDAG &DAG) const { |
Lauro Ramos Venancio | ee2d164 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2531 | assert(Subtarget->isTargetELF() && |
2532 | "GLOBAL OFFSET TABLE not implemented for non-ELF targets"); | ||||
Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2533 | MachineFunction &MF = DAG.getMachineFunction(); |
2534 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); | ||||
Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2535 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2536 | EVT PtrVT = getPointerTy(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2537 | SDLoc dl(Op); |
Lauro Ramos Venancio | ee2d164 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2538 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Bill Wendling | c214cb0 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 2539 | ARMConstantPoolValue *CPV = |
2540 | ARMConstantPoolSymbol::Create(*DAG.getContext(), "_GLOBAL_OFFSET_TABLE_", | ||||
2541 | ARMPCLabelIndex, PCAdj); | ||||
Evan Cheng | 1fb8aed | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2542 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2543 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Anton Korobeynikov | 75b59fb | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2544 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2545 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2546 | false, false, false, 0); |
Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2547 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2548 | return DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Lauro Ramos Venancio | ee2d164 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2549 | } |
2550 | |||||
Jim Grosbach | aeca45d | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2551 | SDValue |
Jim Grosbach | c98892f | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2552 | ARMTargetLowering::LowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const { |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2553 | SDLoc dl(Op); |
Jim Grosbach | faa3abb | 2010-05-27 23:49:24 +0000 | [diff] [blame] | 2554 | SDValue Val = DAG.getConstant(0, MVT::i32); |
Bill Wendling | 7ecfbd9 | 2011-10-07 21:25:38 +0000 | [diff] [blame] | 2555 | return DAG.getNode(ARMISD::EH_SJLJ_SETJMP, dl, |
2556 | DAG.getVTList(MVT::i32, MVT::Other), Op.getOperand(0), | ||||
Jim Grosbach | c98892f | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2557 | Op.getOperand(1), Val); |
2558 | } | ||||
2559 | |||||
2560 | SDValue | ||||
Jim Grosbach | bd9485d | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 2561 | ARMTargetLowering::LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const { |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2562 | SDLoc dl(Op); |
Jim Grosbach | bd9485d | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 2563 | return DAG.getNode(ARMISD::EH_SJLJ_LONGJMP, dl, MVT::Other, Op.getOperand(0), |
2564 | Op.getOperand(1), DAG.getConstant(0, MVT::i32)); | ||||
2565 | } | ||||
2566 | |||||
2567 | SDValue | ||||
Jim Grosbach | a570d05 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 2568 | ARMTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG, |
Jim Grosbach | e3864cc | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2569 | const ARMSubtarget *Subtarget) const { |
Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2570 | unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2571 | SDLoc dl(Op); |
Lauro Ramos Venancio | f6a67bf | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2572 | switch (IntNo) { |
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2573 | default: return SDValue(); // Don't custom lower most intrinsics. |
Bob Wilson | 17f8878 | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2574 | case Intrinsic::arm_thread_pointer: { |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2575 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Bob Wilson | 17f8878 | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2576 | return DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
2577 | } | ||||
Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2578 | case Intrinsic::eh_sjlj_lsda: { |
Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2579 | MachineFunction &MF = DAG.getMachineFunction(); |
Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2580 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2581 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2582 | EVT PtrVT = getPointerTy(); |
Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2583 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
2584 | SDValue CPAddr; | ||||
2585 | unsigned PCAdj = (RelocM != Reloc::PIC_) | ||||
2586 | ? 0 : (Subtarget->isThumb() ? 4 : 8); | ||||
Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2587 | ARMConstantPoolValue *CPV = |
Bill Wendling | 7753d66 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2588 | ARMConstantPoolConstant::Create(MF.getFunction(), ARMPCLabelIndex, |
2589 | ARMCP::CPLSDA, PCAdj); | ||||
Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2590 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2591 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2592 | SDValue Result = |
Evan Cheng | cdbb70c | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2593 | DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2594 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2595 | false, false, false, 0); |
Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2596 | |
2597 | if (RelocM == Reloc::PIC_) { | ||||
Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2598 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2599 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
2600 | } | ||||
2601 | return Result; | ||||
2602 | } | ||||
Evan Cheng | 18381b4 | 2011-03-29 23:06:19 +0000 | [diff] [blame] | 2603 | case Intrinsic::arm_neon_vmulls: |
2604 | case Intrinsic::arm_neon_vmullu: { | ||||
2605 | unsigned NewOpc = (IntNo == Intrinsic::arm_neon_vmulls) | ||||
2606 | ? ARMISD::VMULLs : ARMISD::VMULLu; | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2607 | return DAG.getNode(NewOpc, SDLoc(Op), Op.getValueType(), |
Evan Cheng | 18381b4 | 2011-03-29 23:06:19 +0000 | [diff] [blame] | 2608 | Op.getOperand(1), Op.getOperand(2)); |
2609 | } | ||||
Lauro Ramos Venancio | f6a67bf | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2610 | } |
2611 | } | ||||
2612 | |||||
Eli Friedman | 30a49e9 | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2613 | static SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG &DAG, |
2614 | const ARMSubtarget *Subtarget) { | ||||
2615 | // FIXME: handle "fence singlethread" more efficiently. | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2616 | SDLoc dl(Op); |
Eli Friedman | 26a4848 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2617 | if (!Subtarget->hasDataBarrier()) { |
2618 | // Some ARMv6 cpus can support data barriers with an mcr instruction. | ||||
2619 | // Thumb1 and pre-v6 ARM mode use a libcall instead and should never get | ||||
2620 | // here. | ||||
2621 | assert(Subtarget->hasV6Ops() && !Subtarget->isThumb() && | ||||
Tim Northover | c7ea804 | 2013-10-25 09:30:24 +0000 | [diff] [blame] | 2622 | "Unexpected ISD::ATOMIC_FENCE encountered. Should be libcall!"); |
Eli Friedman | 30a49e9 | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2623 | return DAG.getNode(ARMISD::MEMBARRIER_MCR, dl, MVT::Other, Op.getOperand(0), |
Eli Friedman | 26a4848 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2624 | DAG.getConstant(0, MVT::i32)); |
2625 | } | ||||
2626 | |||||
Tim Northover | 36b2417 | 2013-07-03 09:20:36 +0000 | [diff] [blame] | 2627 | ConstantSDNode *OrdN = cast<ConstantSDNode>(Op.getOperand(1)); |
2628 | AtomicOrdering Ord = static_cast<AtomicOrdering>(OrdN->getZExtValue()); | ||||
2629 | unsigned Domain = ARM_MB::ISH; | ||||
Tim Northover | f576988 | 2013-08-28 14:39:19 +0000 | [diff] [blame] | 2630 | if (Subtarget->isMClass()) { |
2631 | // Only a full system barrier exists in the M-class architectures. | ||||
2632 | Domain = ARM_MB::SY; | ||||
2633 | } else if (Subtarget->isSwift() && Ord == Release) { | ||||
Tim Northover | 36b2417 | 2013-07-03 09:20:36 +0000 | [diff] [blame] | 2634 | // Swift happens to implement ISHST barriers in a way that's compatible with |
2635 | // Release semantics but weaker than ISH so we'd be fools not to use | ||||
2636 | // it. Beware: other processors probably don't! | ||||
2637 | Domain = ARM_MB::ISHST; | ||||
2638 | } | ||||
2639 | |||||
Joey Gouly | 926d3f5 | 2013-09-05 15:35:24 +0000 | [diff] [blame] | 2640 | return DAG.getNode(ISD::INTRINSIC_VOID, dl, MVT::Other, Op.getOperand(0), |
2641 | DAG.getConstant(Intrinsic::arm_dmb, MVT::i32), | ||||
Tim Northover | 36b2417 | 2013-07-03 09:20:36 +0000 | [diff] [blame] | 2642 | DAG.getConstant(Domain, MVT::i32)); |
Eli Friedman | 26a4848 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2643 | } |
2644 | |||||
Evan Cheng | 8740ee3 | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2645 | static SDValue LowerPREFETCH(SDValue Op, SelectionDAG &DAG, |
2646 | const ARMSubtarget *Subtarget) { | ||||
2647 | // ARM pre v5TE and Thumb1 does not have preload instructions. | ||||
2648 | if (!(Subtarget->isThumb2() || | ||||
2649 | (!Subtarget->isThumb1Only() && Subtarget->hasV5TEOps()))) | ||||
2650 | // Just preserve the chain. | ||||
2651 | return Op.getOperand(0); | ||||
2652 | |||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2653 | SDLoc dl(Op); |
Evan Cheng | 21acf9f | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2654 | unsigned isRead = ~cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue() & 1; |
2655 | if (!isRead && | ||||
2656 | (!Subtarget->hasV7Ops() || !Subtarget->hasMPExtension())) | ||||
2657 | // ARMv7 with MP extension has PLDW. | ||||
2658 | return Op.getOperand(0); | ||||
Evan Cheng | 8740ee3 | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2659 | |
Bruno Cardoso Lopes | dc9ff3a | 2011-06-14 04:58:37 +0000 | [diff] [blame] | 2660 | unsigned isData = cast<ConstantSDNode>(Op.getOperand(4))->getZExtValue(); |
2661 | if (Subtarget->isThumb()) { | ||||
Evan Cheng | 8740ee3 | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2662 | // Invert the bits. |
Evan Cheng | 21acf9f | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2663 | isRead = ~isRead & 1; |
Bruno Cardoso Lopes | dc9ff3a | 2011-06-14 04:58:37 +0000 | [diff] [blame] | 2664 | isData = ~isData & 1; |
2665 | } | ||||
Evan Cheng | 8740ee3 | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2666 | |
2667 | return DAG.getNode(ARMISD::PRELOAD, dl, MVT::Other, Op.getOperand(0), | ||||
Evan Cheng | 21acf9f | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2668 | Op.getOperand(1), DAG.getConstant(isRead, MVT::i32), |
2669 | DAG.getConstant(isData, MVT::i32)); | ||||
Evan Cheng | 8740ee3 | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2670 | } |
2671 | |||||
Dan Gohman | 31ae586 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2672 | static SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) { |
2673 | MachineFunction &MF = DAG.getMachineFunction(); | ||||
2674 | ARMFunctionInfo *FuncInfo = MF.getInfo<ARMFunctionInfo>(); | ||||
2675 | |||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2676 | // vastart just stores the address of the VarArgsFrameIndex slot into the |
2677 | // memory location argument. | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2678 | SDLoc dl(Op); |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2679 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Dan Gohman | 31ae586 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2680 | SDValue FR = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), PtrVT); |
Dan Gohman | 2d489b5 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 2681 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
Chris Lattner | 886250c | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 2682 | return DAG.getStore(Op.getOperand(0), dl, FR, Op.getOperand(1), |
2683 | MachinePointerInfo(SV), false, false, 0); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2684 | } |
2685 | |||||
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2686 | SDValue |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2687 | ARMTargetLowering::GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA, |
2688 | SDValue &Root, SelectionDAG &DAG, | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2689 | SDLoc dl) const { |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2690 | MachineFunction &MF = DAG.getMachineFunction(); |
2691 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); | ||||
2692 | |||||
Craig Topper | 760b134 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2693 | const TargetRegisterClass *RC; |
David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 2694 | if (AFI->isThumb1OnlyFunction()) |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2695 | RC = &ARM::tGPRRegClass; |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2696 | else |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2697 | RC = &ARM::GPRRegClass; |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2698 | |
2699 | // Transform the arguments stored in physical registers into virtual ones. | ||||
Devang Patel | f3292b2 | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2700 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2701 | SDValue ArgValue = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2702 | |
2703 | SDValue ArgValue2; | ||||
2704 | if (NextVA.isMemLoc()) { | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2705 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Evan Cheng | 0664a67 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2706 | int FI = MFI->CreateFixedObject(4, NextVA.getLocMemOffset(), true); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2707 | |
2708 | // Create load node to retrieve arguments from the stack. | ||||
2709 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); | ||||
Evan Cheng | cdbb70c | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2710 | ArgValue2 = DAG.getLoad(MVT::i32, dl, Root, FIN, |
Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2711 | MachinePointerInfo::getFixedStack(FI), |
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2712 | false, false, false, 0); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2713 | } else { |
Devang Patel | f3292b2 | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2714 | Reg = MF.addLiveIn(NextVA.getLocReg(), RC); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2715 | ArgValue2 = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2716 | } |
Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 2717 | if (!Subtarget->isLittle()) |
2718 | std::swap (ArgValue, ArgValue2); | ||||
Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2719 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, ArgValue, ArgValue2); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2720 | } |
2721 | |||||
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2722 | void |
2723 | ARMTargetLowering::computeRegArea(CCState &CCInfo, MachineFunction &MF, | ||||
Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 2724 | unsigned InRegsParamRecordIdx, |
Stepan Dyatkovskiy | d0e34a2 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 2725 | unsigned ArgSize, |
Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2726 | unsigned &ArgRegsSize, |
2727 | unsigned &ArgRegsSaveSize) | ||||
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2728 | const { |
2729 | unsigned NumGPRs; | ||||
Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 2730 | if (InRegsParamRecordIdx < CCInfo.getInRegsParamsCount()) { |
2731 | unsigned RBegin, REnd; | ||||
2732 | CCInfo.getInRegsParamInfo(InRegsParamRecordIdx, RBegin, REnd); | ||||
2733 | NumGPRs = REnd - RBegin; | ||||
2734 | } else { | ||||
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2735 | unsigned int firstUnalloced; |
2736 | firstUnalloced = CCInfo.getFirstUnallocated(GPRArgRegs, | ||||
2737 | sizeof(GPRArgRegs) / | ||||
2738 | sizeof(GPRArgRegs[0])); | ||||
2739 | NumGPRs = (firstUnalloced <= 3) ? (4 - firstUnalloced) : 0; | ||||
2740 | } | ||||
2741 | |||||
2742 | unsigned Align = MF.getTarget().getFrameLowering()->getStackAlignment(); | ||||
Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2743 | ArgRegsSize = NumGPRs * 4; |
Stepan Dyatkovskiy | d0e34a2 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 2744 | |
2745 | // If parameter is split between stack and GPRs... | ||||
Mark Seaborn | be266aa | 2014-02-16 18:59:48 +0000 | [diff] [blame] | 2746 | if (NumGPRs && Align > 4 && |
Stepan Dyatkovskiy | d0e34a2 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 2747 | (ArgRegsSize < ArgSize || |
2748 | InRegsParamRecordIdx >= CCInfo.getInRegsParamsCount())) { | ||||
Mark Seaborn | be266aa | 2014-02-16 18:59:48 +0000 | [diff] [blame] | 2749 | // Add padding for part of param recovered from GPRs. For example, |
2750 | // if Align == 8, its last byte must be at address K*8 - 1. | ||||
Stepan Dyatkovskiy | d0e34a2 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 2751 | // We need to do it, since remained (stack) part of parameter has |
2752 | // stack alignment, and we need to "attach" "GPRs head" without gaps | ||||
2753 | // to it: | ||||
2754 | // Stack: | ||||
2755 | // |---- 8 bytes block ----| |---- 8 bytes block ----| |---- 8 bytes... | ||||
2756 | // [ [padding] [GPRs head] ] [ Tail passed via stack .... | ||||
2757 | // | ||||
2758 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); | ||||
2759 | unsigned Padding = | ||||
Mark Seaborn | be266aa | 2014-02-16 18:59:48 +0000 | [diff] [blame] | 2760 | OffsetToAlignment(ArgRegsSize + AFI->getArgRegsSaveSize(), Align); |
Stepan Dyatkovskiy | d0e34a2 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 2761 | ArgRegsSaveSize = ArgRegsSize + Padding; |
2762 | } else | ||||
2763 | // We don't need to extend regs save size for byval parameters if they | ||||
2764 | // are passed via GPRs only. | ||||
2765 | ArgRegsSaveSize = ArgRegsSize; | ||||
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2766 | } |
2767 | |||||
2768 | // The remaining GPRs hold either the beginning of variable-argument | ||||
David Peixotto | 4299cf8 | 2013-02-13 00:36:35 +0000 | [diff] [blame] | 2769 | // data, or the beginning of an aggregate passed by value (usually |
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2770 | // byval). Either way, we allocate stack slots adjacent to the data |
2771 | // provided by our caller, and store the unallocated registers there. | ||||
2772 | // If this is a variadic function, the va_list pointer will begin with | ||||
2773 | // these values; otherwise, this reassembles a (byval) structure that | ||||
2774 | // was split between registers and memory. | ||||
Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2775 | // Return: The frame index registers were stored into. |
2776 | int | ||||
2777 | ARMTargetLowering::StoreByValRegs(CCState &CCInfo, SelectionDAG &DAG, | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2778 | SDLoc dl, SDValue &Chain, |
Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2779 | const Value *OrigArg, |
Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 2780 | unsigned InRegsParamRecordIdx, |
Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2781 | unsigned OffsetFromOrigArg, |
2782 | unsigned ArgOffset, | ||||
Stepan Dyatkovskiy | d0e34a2 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 2783 | unsigned ArgSize, |
Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 2784 | bool ForceMutable, |
2785 | unsigned ByValStoreOffset, | ||||
2786 | unsigned TotalArgRegsSaveSize) const { | ||||
Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2787 | |
2788 | // Currently, two use-cases possible: | ||||
Alp Toker | f907b89 | 2013-12-05 05:44:44 +0000 | [diff] [blame] | 2789 | // Case #1. Non-var-args function, and we meet first byval parameter. |
Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2790 | // Setup first unallocated register as first byval register; |
2791 | // eat all remained registers | ||||
2792 | // (these two actions are performed by HandleByVal method). | ||||
2793 | // Then, here, we initialize stack frame with | ||||
2794 | // "store-reg" instructions. | ||||
2795 | // Case #2. Var-args function, that doesn't contain byval parameters. | ||||
2796 | // The same: eat all remained unallocated registers, | ||||
2797 | // initialize stack frame. | ||||
2798 | |||||
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2799 | MachineFunction &MF = DAG.getMachineFunction(); |
2800 | MachineFrameInfo *MFI = MF.getFrameInfo(); | ||||
2801 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); | ||||
Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 2802 | unsigned firstRegToSaveIndex, lastRegToSaveIndex; |
2803 | unsigned RBegin, REnd; | ||||
2804 | if (InRegsParamRecordIdx < CCInfo.getInRegsParamsCount()) { | ||||
2805 | CCInfo.getInRegsParamInfo(InRegsParamRecordIdx, RBegin, REnd); | ||||
2806 | firstRegToSaveIndex = RBegin - ARM::R0; | ||||
2807 | lastRegToSaveIndex = REnd - ARM::R0; | ||||
2808 | } else { | ||||
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2809 | firstRegToSaveIndex = CCInfo.getFirstUnallocated |
Craig Topper | 5871321 | 2013-07-15 04:27:47 +0000 | [diff] [blame] | 2810 | (GPRArgRegs, array_lengthof(GPRArgRegs)); |
Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 2811 | lastRegToSaveIndex = 4; |
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2812 | } |
2813 | |||||
Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2814 | unsigned ArgRegsSize, ArgRegsSaveSize; |
Stepan Dyatkovskiy | d0e34a2 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 2815 | computeRegArea(CCInfo, MF, InRegsParamRecordIdx, ArgSize, |
2816 | ArgRegsSize, ArgRegsSaveSize); | ||||
Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2817 | |
2818 | // Store any by-val regs to their spots on the stack so that they may be | ||||
2819 | // loaded by deferencing the result of formal parameter pointer or va_next. | ||||
2820 | // Note: once stack area for byval/varargs registers | ||||
2821 | // was initialized, it can't be initialized again. | ||||
Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 2822 | if (ArgRegsSaveSize) { |
Stepan Dyatkovskiy | d0e34a2 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 2823 | unsigned Padding = ArgRegsSaveSize - ArgRegsSize; |
2824 | |||||
2825 | if (Padding) { | ||||
2826 | assert(AFI->getStoredByValParamsPadding() == 0 && | ||||
2827 | "The only parameter may be padded."); | ||||
2828 | AFI->setStoredByValParamsPadding(Padding); | ||||
2829 | } | ||||
2830 | |||||
Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 2831 | int FrameIndex = MFI->CreateFixedObject(ArgRegsSaveSize, |
2832 | Padding + | ||||
2833 | ByValStoreOffset - | ||||
2834 | (int64_t)TotalArgRegsSaveSize, | ||||
2835 | false); | ||||
Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2836 | SDValue FIN = DAG.getFrameIndex(FrameIndex, getPointerTy()); |
Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 2837 | if (Padding) { |
2838 | MFI->CreateFixedObject(Padding, | ||||
2839 | ArgOffset + ByValStoreOffset - | ||||
2840 | (int64_t)ArgRegsSaveSize, | ||||
2841 | false); | ||||
2842 | } | ||||
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2843 | |
2844 | SmallVector<SDValue, 4> MemOps; | ||||
Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 2845 | for (unsigned i = 0; firstRegToSaveIndex < lastRegToSaveIndex; |
2846 | ++firstRegToSaveIndex, ++i) { | ||||
Craig Topper | 760b134 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2847 | const TargetRegisterClass *RC; |
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2848 | if (AFI->isThumb1OnlyFunction()) |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2849 | RC = &ARM::tGPRRegClass; |
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2850 | else |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2851 | RC = &ARM::GPRRegClass; |
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2852 | |
2853 | unsigned VReg = MF.addLiveIn(GPRArgRegs[firstRegToSaveIndex], RC); | ||||
2854 | SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i32); | ||||
2855 | SDValue Store = | ||||
2856 | DAG.getStore(Val.getValue(1), dl, Val, FIN, | ||||
Stepan Dyatkovskiy | f13dbb8 | 2012-10-10 11:37:36 +0000 | [diff] [blame] | 2857 | MachinePointerInfo(OrigArg, OffsetFromOrigArg + 4*i), |
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2858 | false, false, 0); |
2859 | MemOps.push_back(Store); | ||||
2860 | FIN = DAG.getNode(ISD::ADD, dl, getPointerTy(), FIN, | ||||
2861 | DAG.getConstant(4, getPointerTy())); | ||||
2862 | } | ||||
Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 2863 | |
2864 | AFI->setArgRegsSaveSize(ArgRegsSaveSize + AFI->getArgRegsSaveSize()); | ||||
2865 | |||||
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2866 | if (!MemOps.empty()) |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 2867 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOps); |
Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2868 | return FrameIndex; |
Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 2869 | } else { |
2870 | if (ArgSize == 0) { | ||||
2871 | // We cannot allocate a zero-byte object for the first variadic argument, | ||||
2872 | // so just make up a size. | ||||
2873 | ArgSize = 4; | ||||
2874 | } | ||||
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2875 | // This will point to the next argument passed via stack. |
Stepan Dyatkovskiy | d0e34a2 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 2876 | return MFI->CreateFixedObject( |
Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 2877 | ArgSize, ArgOffset, !ForceMutable); |
2878 | } | ||||
Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2879 | } |
2880 | |||||
2881 | // Setup stack frame, the va_list pointer will start from. | ||||
2882 | void | ||||
2883 | ARMTargetLowering::VarArgStyleRegisters(CCState &CCInfo, SelectionDAG &DAG, | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2884 | SDLoc dl, SDValue &Chain, |
Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2885 | unsigned ArgOffset, |
Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 2886 | unsigned TotalArgRegsSaveSize, |
Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2887 | bool ForceMutable) const { |
2888 | MachineFunction &MF = DAG.getMachineFunction(); | ||||
2889 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); | ||||
2890 | |||||
2891 | // Try to store any remaining integer argument regs | ||||
2892 | // to their spots on the stack so that they may be loaded by deferencing | ||||
2893 | // the result of va_next. | ||||
2894 | // If there is no regs to be stored, just point address after last | ||||
2895 | // argument passed via stack. | ||||
2896 | int FrameIndex = | ||||
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 2897 | StoreByValRegs(CCInfo, DAG, dl, Chain, nullptr, |
2898 | CCInfo.getInRegsParamsCount(), 0, ArgOffset, 0, ForceMutable, | ||||
2899 | 0, TotalArgRegsSaveSize); | ||||
Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2900 | |
2901 | AFI->setVarArgsFrameIndex(FrameIndex); | ||||
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2902 | } |
2903 | |||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2904 | SDValue |
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2905 | ARMTargetLowering::LowerFormalArguments(SDValue Chain, |
Sandeep Patel | 68c5f47 | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 2906 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2907 | const SmallVectorImpl<ISD::InputArg> |
2908 | &Ins, | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2909 | SDLoc dl, SelectionDAG &DAG, |
Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2910 | SmallVectorImpl<SDValue> &InVals) |
2911 | const { | ||||
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2912 | MachineFunction &MF = DAG.getMachineFunction(); |
2913 | MachineFrameInfo *MFI = MF.getFrameInfo(); | ||||
2914 | |||||
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2915 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
2916 | |||||
2917 | // Assign locations to all of the incoming arguments. | ||||
2918 | SmallVector<CCValAssign, 16> ArgLocs; | ||||
Cameron Zwarich | 8901978 | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 2919 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
2920 | getTargetMachine(), ArgLocs, *DAG.getContext(), Prologue); | ||||
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2921 | CCInfo.AnalyzeFormalArguments(Ins, |
Anton Korobeynikov | 22ef751 | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2922 | CCAssignFnForNode(CallConv, /* Return*/ false, |
2923 | isVarArg)); | ||||
Jim Grosbach | 54efea0 | 2013-03-02 20:16:15 +0000 | [diff] [blame] | 2924 | |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2925 | SmallVector<SDValue, 16> ArgValues; |
Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2926 | int lastInsIndex = -1; |
Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2927 | SDValue ArgValue; |
Stepan Dyatkovskiy | f13dbb8 | 2012-10-10 11:37:36 +0000 | [diff] [blame] | 2928 | Function::const_arg_iterator CurOrigArg = MF.getFunction()->arg_begin(); |
2929 | unsigned CurArgIdx = 0; | ||||
Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 2930 | |
2931 | // Initially ArgRegsSaveSize is zero. | ||||
2932 | // Then we increase this value each time we meet byval parameter. | ||||
2933 | // We also increase this value in case of varargs function. | ||||
2934 | AFI->setArgRegsSaveSize(0); | ||||
2935 | |||||
Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 2936 | unsigned ByValStoreOffset = 0; |
2937 | unsigned TotalArgRegsSaveSize = 0; | ||||
2938 | unsigned ArgRegsSaveSizeMaxAlign = 4; | ||||
2939 | |||||
2940 | // Calculate the amount of stack space that we need to allocate to store | ||||
2941 | // byval and variadic arguments that are passed in registers. | ||||
2942 | // We need to know this before we allocate the first byval or variadic | ||||
2943 | // argument, as they will be allocated a stack slot below the CFA (Canonical | ||||
2944 | // Frame Address, the stack pointer at entry to the function). | ||||
2945 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { | ||||
2946 | CCValAssign &VA = ArgLocs[i]; | ||||
2947 | if (VA.isMemLoc()) { | ||||
2948 | int index = VA.getValNo(); | ||||
2949 | if (index != lastInsIndex) { | ||||
2950 | ISD::ArgFlagsTy Flags = Ins[index].Flags; | ||||
2951 | if (Flags.isByVal()) { | ||||
2952 | unsigned ExtraArgRegsSize; | ||||
2953 | unsigned ExtraArgRegsSaveSize; | ||||
2954 | computeRegArea(CCInfo, MF, CCInfo.getInRegsParamsProceed(), | ||||
2955 | Flags.getByValSize(), | ||||
2956 | ExtraArgRegsSize, ExtraArgRegsSaveSize); | ||||
2957 | |||||
2958 | TotalArgRegsSaveSize += ExtraArgRegsSaveSize; | ||||
2959 | if (Flags.getByValAlign() > ArgRegsSaveSizeMaxAlign) | ||||
2960 | ArgRegsSaveSizeMaxAlign = Flags.getByValAlign(); | ||||
2961 | CCInfo.nextInRegsParam(); | ||||
2962 | } | ||||
2963 | lastInsIndex = index; | ||||
2964 | } | ||||
2965 | } | ||||
2966 | } | ||||
2967 | CCInfo.rewindByValRegsInfo(); | ||||
2968 | lastInsIndex = -1; | ||||
2969 | if (isVarArg) { | ||||
2970 | unsigned ExtraArgRegsSize; | ||||
2971 | unsigned ExtraArgRegsSaveSize; | ||||
2972 | computeRegArea(CCInfo, MF, CCInfo.getInRegsParamsCount(), 0, | ||||
2973 | ExtraArgRegsSize, ExtraArgRegsSaveSize); | ||||
2974 | TotalArgRegsSaveSize += ExtraArgRegsSaveSize; | ||||
2975 | } | ||||
2976 | // If the arg regs save area contains N-byte aligned values, the | ||||
2977 | // bottom of it must be at least N-byte aligned. | ||||
2978 | TotalArgRegsSaveSize = RoundUpToAlignment(TotalArgRegsSaveSize, ArgRegsSaveSizeMaxAlign); | ||||
2979 | TotalArgRegsSaveSize = std::min(TotalArgRegsSaveSize, 16U); | ||||
2980 | |||||
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2981 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
2982 | CCValAssign &VA = ArgLocs[i]; | ||||
Stepan Dyatkovskiy | f13dbb8 | 2012-10-10 11:37:36 +0000 | [diff] [blame] | 2983 | std::advance(CurOrigArg, Ins[VA.getValNo()].OrigArgIndex - CurArgIdx); |
2984 | CurArgIdx = Ins[VA.getValNo()].OrigArgIndex; | ||||
Bob Wilson | ea09d4a | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2985 | // Arguments stored in registers. |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2986 | if (VA.isRegLoc()) { |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2987 | EVT RegVT = VA.getLocVT(); |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2988 | |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2989 | if (VA.needsCustom()) { |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2990 | // f64 and vector types are split up into multiple registers or |
2991 | // combinations of registers and stack slots. | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2992 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2993 | SDValue ArgValue1 = GetF64FormalArgument(VA, ArgLocs[++i], |
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2994 | Chain, DAG, dl); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2995 | VA = ArgLocs[++i]; // skip ahead to next loc |
Bob Wilson | 699bdf7 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2996 | SDValue ArgValue2; |
2997 | if (VA.isMemLoc()) { | ||||
Evan Cheng | 0664a67 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2998 | int FI = MFI->CreateFixedObject(8, VA.getLocMemOffset(), true); |
Bob Wilson | 699bdf7 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2999 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
3000 | ArgValue2 = DAG.getLoad(MVT::f64, dl, Chain, FIN, | ||||
Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3001 | MachinePointerInfo::getFixedStack(FI), |
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3002 | false, false, false, 0); |
Bob Wilson | 699bdf7 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 3003 | } else { |
3004 | ArgValue2 = GetF64FormalArgument(VA, ArgLocs[++i], | ||||
3005 | Chain, DAG, dl); | ||||
3006 | } | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3007 | ArgValue = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
3008 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3009 | ArgValue, ArgValue1, DAG.getIntPtrConstant(0)); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3010 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3011 | ArgValue, ArgValue2, DAG.getIntPtrConstant(1)); |
3012 | } else | ||||
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3013 | ArgValue = GetF64FormalArgument(VA, ArgLocs[++i], Chain, DAG, dl); |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3014 | |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3015 | } else { |
Craig Topper | 760b134 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 3016 | const TargetRegisterClass *RC; |
Anton Korobeynikov | 22ef751 | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 3017 | |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3018 | if (RegVT == MVT::f32) |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 3019 | RC = &ARM::SPRRegClass; |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3020 | else if (RegVT == MVT::f64) |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 3021 | RC = &ARM::DPRRegClass; |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3022 | else if (RegVT == MVT::v2f64) |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 3023 | RC = &ARM::QPRRegClass; |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3024 | else if (RegVT == MVT::i32) |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 3025 | RC = AFI->isThumb1OnlyFunction() ? |
3026 | (const TargetRegisterClass*)&ARM::tGPRRegClass : | ||||
3027 | (const TargetRegisterClass*)&ARM::GPRRegClass; | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3028 | else |
Anton Korobeynikov | ef98dbe | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 3029 | llvm_unreachable("RegVT not supported by FORMAL_ARGUMENTS Lowering"); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3030 | |
3031 | // Transform the arguments in physical registers into virtual ones. | ||||
Devang Patel | f3292b2 | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 3032 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3033 | ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, RegVT); |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3034 | } |
3035 | |||||
3036 | // If this is an 8 or 16-bit value, it is really passed promoted | ||||
3037 | // to 32 bits. Insert an assert[sz]ext to capture this, then | ||||
3038 | // truncate to the right size. | ||||
3039 | switch (VA.getLocInfo()) { | ||||
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3040 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3041 | case CCValAssign::Full: break; |
3042 | case CCValAssign::BCvt: | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3043 | ArgValue = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), ArgValue); |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3044 | break; |
3045 | case CCValAssign::SExt: | ||||
3046 | ArgValue = DAG.getNode(ISD::AssertSext, dl, RegVT, ArgValue, | ||||
3047 | DAG.getValueType(VA.getValVT())); | ||||
3048 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); | ||||
3049 | break; | ||||
3050 | case CCValAssign::ZExt: | ||||
3051 | ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue, | ||||
3052 | DAG.getValueType(VA.getValVT())); | ||||
3053 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); | ||||
3054 | break; | ||||
3055 | } | ||||
3056 | |||||
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3057 | InVals.push_back(ArgValue); |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3058 | |
3059 | } else { // VA.isRegLoc() | ||||
3060 | |||||
3061 | // sanity check | ||||
3062 | assert(VA.isMemLoc()); | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3063 | assert(VA.getValVT() != MVT::i64 && "i64 should already be lowered"); |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3064 | |
Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 3065 | int index = ArgLocs[i].getValNo(); |
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 3066 | |
Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 3067 | // Some Ins[] entries become multiple ArgLoc[] entries. |
3068 | // Process them only once. | ||||
3069 | if (index != lastInsIndex) | ||||
3070 | { | ||||
3071 | ISD::ArgFlagsTy Flags = Ins[index].Flags; | ||||
Eric Christopher | 0713a9d | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 3072 | // FIXME: For now, all byval parameter objects are marked mutable. |
Eric Christopher | e02e07c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 3073 | // This can be changed with more analysis. |
3074 | // In case of tail call optimization mark all arguments mutable. | ||||
3075 | // Since they could be overwritten by lowering of arguments in case of | ||||
3076 | // a tail call. | ||||
Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 3077 | if (Flags.isByVal()) { |
Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 3078 | unsigned CurByValIndex = CCInfo.getInRegsParamsProceed(); |
Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3079 | |
3080 | ByValStoreOffset = RoundUpToAlignment(ByValStoreOffset, Flags.getByValAlign()); | ||||
Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 3081 | int FrameIndex = StoreByValRegs( |
Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 3082 | CCInfo, DAG, dl, Chain, CurOrigArg, |
3083 | CurByValIndex, | ||||
3084 | Ins[VA.getValNo()].PartOffset, | ||||
3085 | VA.getLocMemOffset(), | ||||
Stepan Dyatkovskiy | d0e34a2 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 3086 | Flags.getByValSize(), |
Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3087 | true /*force mutable frames*/, |
3088 | ByValStoreOffset, | ||||
3089 | TotalArgRegsSaveSize); | ||||
3090 | ByValStoreOffset += Flags.getByValSize(); | ||||
3091 | ByValStoreOffset = std::min(ByValStoreOffset, 16U); | ||||
Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 3092 | InVals.push_back(DAG.getFrameIndex(FrameIndex, getPointerTy())); |
Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 3093 | CCInfo.nextInRegsParam(); |
Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 3094 | } else { |
Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3095 | unsigned FIOffset = VA.getLocMemOffset(); |
Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 3096 | int FI = MFI->CreateFixedObject(VA.getLocVT().getSizeInBits()/8, |
Stepan Dyatkovskiy | d0e34a2 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 3097 | FIOffset, true); |
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3098 | |
Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 3099 | // Create load nodes to retrieve arguments from the stack. |
3100 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); | ||||
3101 | InVals.push_back(DAG.getLoad(VA.getValVT(), dl, Chain, FIN, | ||||
3102 | MachinePointerInfo::getFixedStack(FI), | ||||
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3103 | false, false, false, 0)); |
Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 3104 | } |
3105 | lastInsIndex = index; | ||||
3106 | } | ||||
Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3107 | } |
3108 | } | ||||
3109 | |||||
3110 | // varargs | ||||
Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 3111 | if (isVarArg) |
Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 3112 | VarArgStyleRegisters(CCInfo, DAG, dl, Chain, |
Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3113 | CCInfo.getNextStackOffset(), |
3114 | TotalArgRegsSaveSize); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3115 | |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 3116 | AFI->setArgumentStackSize(CCInfo.getNextStackOffset()); |
3117 | |||||
Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3118 | return Chain; |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3119 | } |
3120 | |||||
3121 | /// isFloatingPointZero - Return true if this is +0.0. | ||||
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3122 | static bool isFloatingPointZero(SDValue Op) { |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3123 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op)) |
Dale Johannesen | 3cf889f | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 3124 | return CFP->getValueAPF().isPosZero(); |
Gabor Greif | f304a7a | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3125 | else if (ISD::isEXTLoad(Op.getNode()) || ISD::isNON_EXTLoad(Op.getNode())) { |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3126 | // Maybe this has already been legalized into the constant pool? |
3127 | if (Op.getOperand(1).getOpcode() == ARMISD::Wrapper) { | ||||
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3128 | SDValue WrapperOp = Op.getOperand(1).getOperand(0); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3129 | if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(WrapperOp)) |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 3130 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal())) |
Dale Johannesen | 3cf889f | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 3131 | return CFP->getValueAPF().isPosZero(); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3132 | } |
3133 | } | ||||
3134 | return false; | ||||
3135 | } | ||||
3136 | |||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3137 | /// Returns appropriate ARM CMP (cmp) and corresponding condition code for |
3138 | /// the given operands. | ||||
Evan Cheng | 15b80e4 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 3139 | SDValue |
3140 | ARMTargetLowering::getARMCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC, | ||||
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3141 | SDValue &ARMcc, SelectionDAG &DAG, |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3142 | SDLoc dl) const { |
Gabor Greif | f304a7a | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3143 | if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS.getNode())) { |
Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 3144 | unsigned C = RHSC->getZExtValue(); |
Evan Cheng | 15b80e4 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 3145 | if (!isLegalICmpImmediate(C)) { |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3146 | // Constant does not fit, try adjusting it by one? |
3147 | switch (CC) { | ||||
3148 | default: break; | ||||
3149 | case ISD::SETLT: | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3150 | case ISD::SETGE: |
Daniel Dunbar | a54a1b0 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 3151 | if (C != 0x80000000 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 48b094d | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 3152 | CC = (CC == ISD::SETLT) ? ISD::SETLE : ISD::SETGT; |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3153 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | 48b094d | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 3154 | } |
3155 | break; | ||||
3156 | case ISD::SETULT: | ||||
3157 | case ISD::SETUGE: | ||||
Daniel Dunbar | a54a1b0 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 3158 | if (C != 0 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 48b094d | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 3159 | CC = (CC == ISD::SETULT) ? ISD::SETULE : ISD::SETUGT; |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3160 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3161 | } |
3162 | break; | ||||
3163 | case ISD::SETLE: | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3164 | case ISD::SETGT: |
Daniel Dunbar | a54a1b0 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 3165 | if (C != 0x7fffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 48b094d | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 3166 | CC = (CC == ISD::SETLE) ? ISD::SETLT : ISD::SETGE; |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3167 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | 48b094d | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 3168 | } |
3169 | break; | ||||
3170 | case ISD::SETULE: | ||||
3171 | case ISD::SETUGT: | ||||
Daniel Dunbar | a54a1b0 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 3172 | if (C != 0xffffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 48b094d | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 3173 | CC = (CC == ISD::SETULE) ? ISD::SETULT : ISD::SETUGE; |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3174 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3175 | } |
3176 | break; | ||||
3177 | } | ||||
3178 | } | ||||
3179 | } | ||||
3180 | |||||
3181 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); | ||||
Lauro Ramos Venancio | 6be8533 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 3182 | ARMISD::NodeType CompareType; |
3183 | switch (CondCode) { | ||||
3184 | default: | ||||
3185 | CompareType = ARMISD::CMP; | ||||
3186 | break; | ||||
3187 | case ARMCC::EQ: | ||||
3188 | case ARMCC::NE: | ||||
David Goodwin | dbf11ba | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 3189 | // Uses only Z Flag |
3190 | CompareType = ARMISD::CMPZ; | ||||
Lauro Ramos Venancio | 6be8533 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 3191 | break; |
3192 | } | ||||
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3193 | ARMcc = DAG.getConstant(CondCode, MVT::i32); |
Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3194 | return DAG.getNode(CompareType, dl, MVT::Glue, LHS, RHS); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3195 | } |
3196 | |||||
3197 | /// Returns a appropriate VFP CMP (fcmp{s|d}+fmstat) for the given operands. | ||||
Evan Cheng | 25f9364 | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 3198 | SDValue |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3199 | ARMTargetLowering::getVFPCmp(SDValue LHS, SDValue RHS, SelectionDAG &DAG, |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3200 | SDLoc dl) const { |
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3201 | SDValue Cmp; |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3202 | if (!isFloatingPointZero(RHS)) |
Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3203 | Cmp = DAG.getNode(ARMISD::CMPFP, dl, MVT::Glue, LHS, RHS); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3204 | else |
Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3205 | Cmp = DAG.getNode(ARMISD::CMPFPw0, dl, MVT::Glue, LHS); |
3206 | return DAG.getNode(ARMISD::FMSTAT, dl, MVT::Glue, Cmp); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3207 | } |
3208 | |||||
Bob Wilson | 45acbd0 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 3209 | /// duplicateCmp - Glue values can have only one use, so this function |
3210 | /// duplicates a comparison node. | ||||
3211 | SDValue | ||||
3212 | ARMTargetLowering::duplicateCmp(SDValue Cmp, SelectionDAG &DAG) const { | ||||
3213 | unsigned Opc = Cmp.getOpcode(); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3214 | SDLoc DL(Cmp); |
Bob Wilson | 45acbd0 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 3215 | if (Opc == ARMISD::CMP || Opc == ARMISD::CMPZ) |
3216 | return DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); | ||||
3217 | |||||
3218 | assert(Opc == ARMISD::FMSTAT && "unexpected comparison operation"); | ||||
3219 | Cmp = Cmp.getOperand(0); | ||||
3220 | Opc = Cmp.getOpcode(); | ||||
3221 | if (Opc == ARMISD::CMPFP) | ||||
3222 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); | ||||
3223 | else { | ||||
3224 | assert(Opc == ARMISD::CMPFPw0 && "unexpected operand of FMSTAT"); | ||||
3225 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0)); | ||||
3226 | } | ||||
3227 | return DAG.getNode(ARMISD::FMSTAT, DL, MVT::Glue, Cmp); | ||||
3228 | } | ||||
3229 | |||||
Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3230 | std::pair<SDValue, SDValue> |
3231 | ARMTargetLowering::getARMXALUOOp(SDValue Op, SelectionDAG &DAG, | ||||
3232 | SDValue &ARMcc) const { | ||||
3233 | assert(Op.getValueType() == MVT::i32 && "Unsupported value type"); | ||||
3234 | |||||
3235 | SDValue Value, OverflowCmp; | ||||
3236 | SDValue LHS = Op.getOperand(0); | ||||
3237 | SDValue RHS = Op.getOperand(1); | ||||
3238 | |||||
3239 | |||||
3240 | // FIXME: We are currently always generating CMPs because we don't support | ||||
3241 | // generating CMN through the backend. This is not as good as the natural | ||||
3242 | // CMP case because it causes a register dependency and cannot be folded | ||||
3243 | // later. | ||||
3244 | |||||
3245 | switch (Op.getOpcode()) { | ||||
3246 | default: | ||||
3247 | llvm_unreachable("Unknown overflow instruction!"); | ||||
3248 | case ISD::SADDO: | ||||
3249 | ARMcc = DAG.getConstant(ARMCC::VC, MVT::i32); | ||||
3250 | Value = DAG.getNode(ISD::ADD, SDLoc(Op), Op.getValueType(), LHS, RHS); | ||||
3251 | OverflowCmp = DAG.getNode(ARMISD::CMP, SDLoc(Op), MVT::Glue, Value, LHS); | ||||
3252 | break; | ||||
3253 | case ISD::UADDO: | ||||
3254 | ARMcc = DAG.getConstant(ARMCC::HS, MVT::i32); | ||||
3255 | Value = DAG.getNode(ISD::ADD, SDLoc(Op), Op.getValueType(), LHS, RHS); | ||||
3256 | OverflowCmp = DAG.getNode(ARMISD::CMP, SDLoc(Op), MVT::Glue, Value, LHS); | ||||
3257 | break; | ||||
3258 | case ISD::SSUBO: | ||||
3259 | ARMcc = DAG.getConstant(ARMCC::VC, MVT::i32); | ||||
3260 | Value = DAG.getNode(ISD::SUB, SDLoc(Op), Op.getValueType(), LHS, RHS); | ||||
3261 | OverflowCmp = DAG.getNode(ARMISD::CMP, SDLoc(Op), MVT::Glue, LHS, RHS); | ||||
3262 | break; | ||||
3263 | case ISD::USUBO: | ||||
3264 | ARMcc = DAG.getConstant(ARMCC::HS, MVT::i32); | ||||
3265 | Value = DAG.getNode(ISD::SUB, SDLoc(Op), Op.getValueType(), LHS, RHS); | ||||
3266 | OverflowCmp = DAG.getNode(ARMISD::CMP, SDLoc(Op), MVT::Glue, LHS, RHS); | ||||
3267 | break; | ||||
3268 | } // switch (...) | ||||
3269 | |||||
3270 | return std::make_pair(Value, OverflowCmp); | ||||
3271 | } | ||||
3272 | |||||
3273 | |||||
3274 | SDValue | ||||
3275 | ARMTargetLowering::LowerXALUO(SDValue Op, SelectionDAG &DAG) const { | ||||
3276 | // Let legalize expand this if it isn't a legal type yet. | ||||
3277 | if (!DAG.getTargetLoweringInfo().isTypeLegal(Op.getValueType())) | ||||
3278 | return SDValue(); | ||||
3279 | |||||
3280 | SDValue Value, OverflowCmp; | ||||
3281 | SDValue ARMcc; | ||||
3282 | std::tie(Value, OverflowCmp) = getARMXALUOOp(Op, DAG, ARMcc); | ||||
3283 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); | ||||
3284 | // We use 0 and 1 as false and true values. | ||||
3285 | SDValue TVal = DAG.getConstant(1, MVT::i32); | ||||
3286 | SDValue FVal = DAG.getConstant(0, MVT::i32); | ||||
3287 | EVT VT = Op.getValueType(); | ||||
3288 | |||||
3289 | SDValue Overflow = DAG.getNode(ARMISD::CMOV, SDLoc(Op), VT, TVal, FVal, | ||||
3290 | ARMcc, CCR, OverflowCmp); | ||||
3291 | |||||
3292 | SDVTList VTs = DAG.getVTList(Op.getValueType(), MVT::i32); | ||||
3293 | return DAG.getNode(ISD::MERGE_VALUES, SDLoc(Op), VTs, Value, Overflow); | ||||
3294 | } | ||||
3295 | |||||
3296 | |||||
Bill Wendling | 6a98131 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 3297 | SDValue ARMTargetLowering::LowerSELECT(SDValue Op, SelectionDAG &DAG) const { |
3298 | SDValue Cond = Op.getOperand(0); | ||||
3299 | SDValue SelectTrue = Op.getOperand(1); | ||||
3300 | SDValue SelectFalse = Op.getOperand(2); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3301 | SDLoc dl(Op); |
Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3302 | unsigned Opc = Cond.getOpcode(); |
3303 | |||||
3304 | if (Cond.getResNo() == 1 && | ||||
3305 | (Opc == ISD::SADDO || Opc == ISD::UADDO || Opc == ISD::SSUBO || | ||||
3306 | Opc == ISD::USUBO)) { | ||||
3307 | if (!DAG.getTargetLoweringInfo().isTypeLegal(Cond->getValueType(0))) | ||||
3308 | return SDValue(); | ||||
3309 | |||||
3310 | SDValue Value, OverflowCmp; | ||||
3311 | SDValue ARMcc; | ||||
3312 | std::tie(Value, OverflowCmp) = getARMXALUOOp(Cond, DAG, ARMcc); | ||||
3313 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); | ||||
3314 | EVT VT = Op.getValueType(); | ||||
3315 | |||||
3316 | return DAG.getNode(ARMISD::CMOV, SDLoc(Op), VT, SelectTrue, SelectFalse, | ||||
3317 | ARMcc, CCR, OverflowCmp); | ||||
3318 | |||||
3319 | } | ||||
Bill Wendling | 6a98131 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 3320 | |
3321 | // Convert: | ||||
3322 | // | ||||
3323 | // (select (cmov 1, 0, cond), t, f) -> (cmov t, f, cond) | ||||
3324 | // (select (cmov 0, 1, cond), t, f) -> (cmov f, t, cond) | ||||
3325 | // | ||||
3326 | if (Cond.getOpcode() == ARMISD::CMOV && Cond.hasOneUse()) { | ||||
3327 | const ConstantSDNode *CMOVTrue = | ||||
3328 | dyn_cast<ConstantSDNode>(Cond.getOperand(0)); | ||||
3329 | const ConstantSDNode *CMOVFalse = | ||||
3330 | dyn_cast<ConstantSDNode>(Cond.getOperand(1)); | ||||
3331 | |||||
3332 | if (CMOVTrue && CMOVFalse) { | ||||
3333 | unsigned CMOVTrueVal = CMOVTrue->getZExtValue(); | ||||
3334 | unsigned CMOVFalseVal = CMOVFalse->getZExtValue(); | ||||
3335 | |||||
3336 | SDValue True; | ||||
3337 | SDValue False; | ||||
3338 | if (CMOVTrueVal == 1 && CMOVFalseVal == 0) { | ||||
3339 | True = SelectTrue; | ||||
3340 | False = SelectFalse; | ||||
3341 | } else if (CMOVTrueVal == 0 && CMOVFalseVal == 1) { | ||||
3342 | True = SelectFalse; | ||||
3343 | False = SelectTrue; | ||||
3344 | } | ||||
3345 | |||||
3346 | if (True.getNode() && False.getNode()) { | ||||
Evan Cheng | 522fbfe | 2011-05-18 18:59:17 +0000 | [diff] [blame] | 3347 | EVT VT = Op.getValueType(); |
Bill Wendling | 6a98131 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 3348 | SDValue ARMcc = Cond.getOperand(2); |
3349 | SDValue CCR = Cond.getOperand(3); | ||||
Bob Wilson | 45acbd0 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 3350 | SDValue Cmp = duplicateCmp(Cond.getOperand(4), DAG); |
Evan Cheng | 522fbfe | 2011-05-18 18:59:17 +0000 | [diff] [blame] | 3351 | assert(True.getValueType() == VT); |
3352 | return DAG.getNode(ARMISD::CMOV, dl, VT, True, False, ARMcc, CCR, Cmp); | ||||
Bill Wendling | 6a98131 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 3353 | } |
3354 | } | ||||
3355 | } | ||||
3356 | |||||
Dan Gohman | d4a77c4 | 2012-02-24 00:09:36 +0000 | [diff] [blame] | 3357 | // ARM's BooleanContents value is UndefinedBooleanContent. Mask out the |
3358 | // undefined bits before doing a full-word comparison with zero. | ||||
3359 | Cond = DAG.getNode(ISD::AND, dl, Cond.getValueType(), Cond, | ||||
3360 | DAG.getConstant(1, Cond.getValueType())); | ||||
3361 | |||||
Bill Wendling | 6a98131 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 3362 | return DAG.getSelectCC(dl, Cond, |
3363 | DAG.getConstant(0, Cond.getValueType()), | ||||
3364 | SelectTrue, SelectFalse, ISD::SETNE); | ||||
3365 | } | ||||
3366 | |||||
Joey Gouly | 881eab5 | 2013-08-22 15:29:11 +0000 | [diff] [blame] | 3367 | static ISD::CondCode getInverseCCForVSEL(ISD::CondCode CC) { |
3368 | if (CC == ISD::SETNE) | ||||
3369 | return ISD::SETEQ; | ||||
Weiming Zhao | 63871d2 | 2013-12-18 22:25:17 +0000 | [diff] [blame] | 3370 | return ISD::getSetCCInverse(CC, true); |
Joey Gouly | 881eab5 | 2013-08-22 15:29:11 +0000 | [diff] [blame] | 3371 | } |
3372 | |||||
3373 | static void checkVSELConstraints(ISD::CondCode CC, ARMCC::CondCodes &CondCode, | ||||
3374 | bool &swpCmpOps, bool &swpVselOps) { | ||||
3375 | // Start by selecting the GE condition code for opcodes that return true for | ||||
3376 | // 'equality' | ||||
3377 | if (CC == ISD::SETUGE || CC == ISD::SETOGE || CC == ISD::SETOLE || | ||||
3378 | CC == ISD::SETULE) | ||||
3379 | CondCode = ARMCC::GE; | ||||
3380 | |||||
3381 | // and GT for opcodes that return false for 'equality'. | ||||
3382 | else if (CC == ISD::SETUGT || CC == ISD::SETOGT || CC == ISD::SETOLT || | ||||
3383 | CC == ISD::SETULT) | ||||
3384 | CondCode = ARMCC::GT; | ||||
3385 | |||||
3386 | // Since we are constrained to GE/GT, if the opcode contains 'less', we need | ||||
3387 | // to swap the compare operands. | ||||
3388 | if (CC == ISD::SETOLE || CC == ISD::SETULE || CC == ISD::SETOLT || | ||||
3389 | CC == ISD::SETULT) | ||||
3390 | swpCmpOps = true; | ||||
3391 | |||||
3392 | // Both GT and GE are ordered comparisons, and return false for 'unordered'. | ||||
3393 | // If we have an unordered opcode, we need to swap the operands to the VSEL | ||||
3394 | // instruction (effectively negating the condition). | ||||
3395 | // | ||||
3396 | // This also has the effect of swapping which one of 'less' or 'greater' | ||||
3397 | // returns true, so we also swap the compare operands. It also switches | ||||
3398 | // whether we return true for 'equality', so we compensate by picking the | ||||
3399 | // opposite condition code to our original choice. | ||||
3400 | if (CC == ISD::SETULE || CC == ISD::SETULT || CC == ISD::SETUGE || | ||||
3401 | CC == ISD::SETUGT) { | ||||
3402 | swpCmpOps = !swpCmpOps; | ||||
3403 | swpVselOps = !swpVselOps; | ||||
3404 | CondCode = CondCode == ARMCC::GT ? ARMCC::GE : ARMCC::GT; | ||||
3405 | } | ||||
3406 | |||||
3407 | // 'ordered' is 'anything but unordered', so use the VS condition code and | ||||
3408 | // swap the VSEL operands. | ||||
3409 | if (CC == ISD::SETO) { | ||||
3410 | CondCode = ARMCC::VS; | ||||
3411 | swpVselOps = true; | ||||
3412 | } | ||||
3413 | |||||
3414 | // 'unordered or not equal' is 'anything but equal', so use the EQ condition | ||||
3415 | // code and swap the VSEL operands. | ||||
3416 | if (CC == ISD::SETUNE) { | ||||
3417 | CondCode = ARMCC::EQ; | ||||
3418 | swpVselOps = true; | ||||
3419 | } | ||||
3420 | } | ||||
3421 | |||||
Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3422 | SDValue ARMTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const { |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3423 | EVT VT = Op.getValueType(); |
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3424 | SDValue LHS = Op.getOperand(0); |
3425 | SDValue RHS = Op.getOperand(1); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3426 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get(); |
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3427 | SDValue TrueVal = Op.getOperand(2); |
3428 | SDValue FalseVal = Op.getOperand(3); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3429 | SDLoc dl(Op); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3430 | |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3431 | if (LHS.getValueType() == MVT::i32) { |
Joey Gouly | 881eab5 | 2013-08-22 15:29:11 +0000 | [diff] [blame] | 3432 | // Try to generate VSEL on ARMv8. |
3433 | // The VSEL instruction can't use all the usual ARM condition | ||||
3434 | // codes: it only has two bits to select the condition code, so it's | ||||
3435 | // constrained to use only GE, GT, VS and EQ. | ||||
3436 | // | ||||
3437 | // To implement all the various ISD::SETXXX opcodes, we sometimes need to | ||||
3438 | // swap the operands of the previous compare instruction (effectively | ||||
3439 | // inverting the compare condition, swapping 'less' and 'greater') and | ||||
3440 | // sometimes need to swap the operands to the VSEL (which inverts the | ||||
3441 | // condition in the sense of firing whenever the previous condition didn't) | ||||
Joey Gouly | ccd0489 | 2013-09-13 13:46:57 +0000 | [diff] [blame] | 3442 | if (getSubtarget()->hasFPARMv8() && (TrueVal.getValueType() == MVT::f32 || |
Joey Gouly | 881eab5 | 2013-08-22 15:29:11 +0000 | [diff] [blame] | 3443 | TrueVal.getValueType() == MVT::f64)) { |
3444 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); | ||||
3445 | if (CondCode == ARMCC::LT || CondCode == ARMCC::LE || | ||||
3446 | CondCode == ARMCC::VC || CondCode == ARMCC::NE) { | ||||
3447 | CC = getInverseCCForVSEL(CC); | ||||
3448 | std::swap(TrueVal, FalseVal); | ||||
3449 | } | ||||
3450 | } | ||||
3451 | |||||
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3452 | SDValue ARMcc; |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3453 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3454 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
Joey Gouly | 881eab5 | 2013-08-22 15:29:11 +0000 | [diff] [blame] | 3455 | return DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, CCR, |
3456 | Cmp); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3457 | } |
3458 | |||||
3459 | ARMCC::CondCodes CondCode, CondCode2; | ||||
Bob Wilson | a2e8333 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 3460 | FPCCToARMCC(CC, CondCode, CondCode2); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3461 | |
Joey Gouly | 881eab5 | 2013-08-22 15:29:11 +0000 | [diff] [blame] | 3462 | // Try to generate VSEL on ARMv8. |
Joey Gouly | ccd0489 | 2013-09-13 13:46:57 +0000 | [diff] [blame] | 3463 | if (getSubtarget()->hasFPARMv8() && (TrueVal.getValueType() == MVT::f32 || |
Joey Gouly | 881eab5 | 2013-08-22 15:29:11 +0000 | [diff] [blame] | 3464 | TrueVal.getValueType() == MVT::f64)) { |
Joey Gouly | e3dd684 | 2013-08-23 12:01:13 +0000 | [diff] [blame] | 3465 | // We can select VMAXNM/VMINNM from a compare followed by a select with the |
3466 | // same operands, as follows: | ||||
3467 | // c = fcmp [ogt, olt, ugt, ult] a, b | ||||
3468 | // select c, a, b | ||||
3469 | // We only do this in unsafe-fp-math, because signed zeros and NaNs are | ||||
3470 | // handled differently than the original code sequence. | ||||
3471 | if (getTargetMachine().Options.UnsafeFPMath && LHS == TrueVal && | ||||
3472 | RHS == FalseVal) { | ||||
3473 | if (CC == ISD::SETOGT || CC == ISD::SETUGT) | ||||
3474 | return DAG.getNode(ARMISD::VMAXNM, dl, VT, TrueVal, FalseVal); | ||||
3475 | if (CC == ISD::SETOLT || CC == ISD::SETULT) | ||||
3476 | return DAG.getNode(ARMISD::VMINNM, dl, VT, TrueVal, FalseVal); | ||||
3477 | } | ||||
3478 | |||||
Joey Gouly | 881eab5 | 2013-08-22 15:29:11 +0000 | [diff] [blame] | 3479 | bool swpCmpOps = false; |
3480 | bool swpVselOps = false; | ||||
3481 | checkVSELConstraints(CC, CondCode, swpCmpOps, swpVselOps); | ||||
3482 | |||||
3483 | if (CondCode == ARMCC::GT || CondCode == ARMCC::GE || | ||||
3484 | CondCode == ARMCC::VS || CondCode == ARMCC::EQ) { | ||||
3485 | if (swpCmpOps) | ||||
3486 | std::swap(LHS, RHS); | ||||
3487 | if (swpVselOps) | ||||
3488 | std::swap(TrueVal, FalseVal); | ||||
3489 | } | ||||
3490 | } | ||||
3491 | |||||
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3492 | SDValue ARMcc = DAG.getConstant(CondCode, MVT::i32); |
3493 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3494 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Dale Johannesen | 400dc2e | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3495 | SDValue Result = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3496 | ARMcc, CCR, Cmp); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3497 | if (CondCode2 != ARMCC::AL) { |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3498 | SDValue ARMcc2 = DAG.getConstant(CondCode2, MVT::i32); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3499 | // FIXME: Needs another CMP because flag can have but one use. |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3500 | SDValue Cmp2 = getVFPCmp(LHS, RHS, DAG, dl); |
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3501 | Result = DAG.getNode(ARMISD::CMOV, dl, VT, |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3502 | Result, TrueVal, ARMcc2, CCR, Cmp2); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3503 | } |
3504 | return Result; | ||||
3505 | } | ||||
3506 | |||||
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3507 | /// canChangeToInt - Given the fp compare operand, return true if it is suitable |
3508 | /// to morph to an integer compare sequence. | ||||
3509 | static bool canChangeToInt(SDValue Op, bool &SeenZero, | ||||
3510 | const ARMSubtarget *Subtarget) { | ||||
3511 | SDNode *N = Op.getNode(); | ||||
3512 | if (!N->hasOneUse()) | ||||
3513 | // Otherwise it requires moving the value from fp to integer registers. | ||||
3514 | return false; | ||||
3515 | if (!N->getNumValues()) | ||||
3516 | return false; | ||||
3517 | EVT VT = Op.getValueType(); | ||||
3518 | if (VT != MVT::f32 && !Subtarget->isFPBrccSlow()) | ||||
3519 | // f32 case is generally profitable. f64 case only makes sense when vcmpe + | ||||
3520 | // vmrs are very slow, e.g. cortex-a8. | ||||
3521 | return false; | ||||
3522 | |||||
3523 | if (isFloatingPointZero(Op)) { | ||||
3524 | SeenZero = true; | ||||
3525 | return true; | ||||
3526 | } | ||||
3527 | return ISD::isNormalLoad(N); | ||||
3528 | } | ||||
3529 | |||||
3530 | static SDValue bitcastf32Toi32(SDValue Op, SelectionDAG &DAG) { | ||||
3531 | if (isFloatingPointZero(Op)) | ||||
3532 | return DAG.getConstant(0, MVT::i32); | ||||
3533 | |||||
3534 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3535 | return DAG.getLoad(MVT::i32, SDLoc(Op), |
Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3536 | Ld->getChain(), Ld->getBasePtr(), Ld->getPointerInfo(), |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3537 | Ld->isVolatile(), Ld->isNonTemporal(), |
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3538 | Ld->isInvariant(), Ld->getAlignment()); |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3539 | |
3540 | llvm_unreachable("Unknown VFP cmp argument!"); | ||||
3541 | } | ||||
3542 | |||||
3543 | static void expandf64Toi32(SDValue Op, SelectionDAG &DAG, | ||||
3544 | SDValue &RetVal1, SDValue &RetVal2) { | ||||
3545 | if (isFloatingPointZero(Op)) { | ||||
3546 | RetVal1 = DAG.getConstant(0, MVT::i32); | ||||
3547 | RetVal2 = DAG.getConstant(0, MVT::i32); | ||||
3548 | return; | ||||
3549 | } | ||||
3550 | |||||
3551 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) { | ||||
3552 | SDValue Ptr = Ld->getBasePtr(); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3553 | RetVal1 = DAG.getLoad(MVT::i32, SDLoc(Op), |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3554 | Ld->getChain(), Ptr, |
Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3555 | Ld->getPointerInfo(), |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3556 | Ld->isVolatile(), Ld->isNonTemporal(), |
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3557 | Ld->isInvariant(), Ld->getAlignment()); |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3558 | |
3559 | EVT PtrType = Ptr.getValueType(); | ||||
3560 | unsigned NewAlign = MinAlign(Ld->getAlignment(), 4); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3561 | SDValue NewPtr = DAG.getNode(ISD::ADD, SDLoc(Op), |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3562 | PtrType, Ptr, DAG.getConstant(4, PtrType)); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3563 | RetVal2 = DAG.getLoad(MVT::i32, SDLoc(Op), |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3564 | Ld->getChain(), NewPtr, |
Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3565 | Ld->getPointerInfo().getWithOffset(4), |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3566 | Ld->isVolatile(), Ld->isNonTemporal(), |
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3567 | Ld->isInvariant(), NewAlign); |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3568 | return; |
3569 | } | ||||
3570 | |||||
3571 | llvm_unreachable("Unknown VFP cmp argument!"); | ||||
3572 | } | ||||
3573 | |||||
3574 | /// OptimizeVFPBrcond - With -enable-unsafe-fp-math, it's legal to optimize some | ||||
3575 | /// f32 and even f64 comparisons to integer ones. | ||||
3576 | SDValue | ||||
3577 | ARMTargetLowering::OptimizeVFPBrcond(SDValue Op, SelectionDAG &DAG) const { | ||||
3578 | SDValue Chain = Op.getOperand(0); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3579 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3580 | SDValue LHS = Op.getOperand(2); |
3581 | SDValue RHS = Op.getOperand(3); | ||||
3582 | SDValue Dest = Op.getOperand(4); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3583 | SDLoc dl(Op); |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3584 | |
Evan Cheng | d12af5d | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3585 | bool LHSSeenZero = false; |
3586 | bool LHSOk = canChangeToInt(LHS, LHSSeenZero, Subtarget); | ||||
3587 | bool RHSSeenZero = false; | ||||
3588 | bool RHSOk = canChangeToInt(RHS, RHSSeenZero, Subtarget); | ||||
3589 | if (LHSOk && RHSOk && (LHSSeenZero || RHSSeenZero)) { | ||||
Bob Wilson | 70bd363 | 2011-03-08 01:17:16 +0000 | [diff] [blame] | 3590 | // If unsafe fp math optimization is enabled and there are no other uses of |
3591 | // the CMP operands, and the condition code is EQ or NE, we can optimize it | ||||
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3592 | // to an integer comparison. |
3593 | if (CC == ISD::SETOEQ) | ||||
3594 | CC = ISD::SETEQ; | ||||
3595 | else if (CC == ISD::SETUNE) | ||||
3596 | CC = ISD::SETNE; | ||||
3597 | |||||
Evan Cheng | d12af5d | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3598 | SDValue Mask = DAG.getConstant(0x7fffffff, MVT::i32); |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3599 | SDValue ARMcc; |
3600 | if (LHS.getValueType() == MVT::f32) { | ||||
Evan Cheng | d12af5d | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3601 | LHS = DAG.getNode(ISD::AND, dl, MVT::i32, |
3602 | bitcastf32Toi32(LHS, DAG), Mask); | ||||
3603 | RHS = DAG.getNode(ISD::AND, dl, MVT::i32, | ||||
3604 | bitcastf32Toi32(RHS, DAG), Mask); | ||||
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3605 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
3606 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); | ||||
3607 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, | ||||
3608 | Chain, Dest, ARMcc, CCR, Cmp); | ||||
3609 | } | ||||
3610 | |||||
3611 | SDValue LHS1, LHS2; | ||||
3612 | SDValue RHS1, RHS2; | ||||
3613 | expandf64Toi32(LHS, DAG, LHS1, LHS2); | ||||
3614 | expandf64Toi32(RHS, DAG, RHS1, RHS2); | ||||
Evan Cheng | d12af5d | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3615 | LHS2 = DAG.getNode(ISD::AND, dl, MVT::i32, LHS2, Mask); |
3616 | RHS2 = DAG.getNode(ISD::AND, dl, MVT::i32, RHS2, Mask); | ||||
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3617 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
3618 | ARMcc = DAG.getConstant(CondCode, MVT::i32); | ||||
Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3619 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3620 | SDValue Ops[] = { Chain, ARMcc, LHS1, LHS2, RHS1, RHS2, Dest }; |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 3621 | return DAG.getNode(ARMISD::BCC_i64, dl, VTList, Ops); |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3622 | } |
3623 | |||||
3624 | return SDValue(); | ||||
3625 | } | ||||
3626 | |||||
3627 | SDValue ARMTargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) const { | ||||
3628 | SDValue Chain = Op.getOperand(0); | ||||
3629 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); | ||||
3630 | SDValue LHS = Op.getOperand(2); | ||||
3631 | SDValue RHS = Op.getOperand(3); | ||||
3632 | SDValue Dest = Op.getOperand(4); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3633 | SDLoc dl(Op); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3634 | |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3635 | if (LHS.getValueType() == MVT::i32) { |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3636 | SDValue ARMcc; |
3637 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3638 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3639 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3640 | Chain, Dest, ARMcc, CCR, Cmp); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3641 | } |
3642 | |||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3643 | assert(LHS.getValueType() == MVT::f32 || LHS.getValueType() == MVT::f64); |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3644 | |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 3645 | if (getTargetMachine().Options.UnsafeFPMath && |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3646 | (CC == ISD::SETEQ || CC == ISD::SETOEQ || |
3647 | CC == ISD::SETNE || CC == ISD::SETUNE)) { | ||||
3648 | SDValue Result = OptimizeVFPBrcond(Op, DAG); | ||||
3649 | if (Result.getNode()) | ||||
3650 | return Result; | ||||
3651 | } | ||||
3652 | |||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3653 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | a2e8333 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 3654 | FPCCToARMCC(CC, CondCode, CondCode2); |
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3655 | |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3656 | SDValue ARMcc = DAG.getConstant(CondCode, MVT::i32); |
3657 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3658 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3659 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3660 | SDValue Ops[] = { Chain, Dest, ARMcc, CCR, Cmp }; |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 3661 | SDValue Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3662 | if (CondCode2 != ARMCC::AL) { |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3663 | ARMcc = DAG.getConstant(CondCode2, MVT::i32); |
3664 | SDValue Ops[] = { Res, Dest, ARMcc, CCR, Res.getValue(1) }; | ||||
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 3665 | Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3666 | } |
3667 | return Res; | ||||
3668 | } | ||||
3669 | |||||
Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3670 | SDValue ARMTargetLowering::LowerBR_JT(SDValue Op, SelectionDAG &DAG) const { |
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3671 | SDValue Chain = Op.getOperand(0); |
3672 | SDValue Table = Op.getOperand(1); | ||||
3673 | SDValue Index = Op.getOperand(2); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3674 | SDLoc dl(Op); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3675 | |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3676 | EVT PTy = getPointerTy(); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3677 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Table); |
3678 | ARMFunctionInfo *AFI = DAG.getMachineFunction().getInfo<ARMFunctionInfo>(); | ||||
Bob Wilson | 3f17aee | 2009-07-14 18:44:34 +0000 | [diff] [blame] | 3679 | SDValue UId = DAG.getConstant(AFI->createJumpTableUId(), PTy); |
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3680 | SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PTy); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3681 | Table = DAG.getNode(ARMISD::WrapperJT, dl, MVT::i32, JTI, UId); |
Evan Cheng | c8bed03 | 2009-07-28 20:53:24 +0000 | [diff] [blame] | 3682 | Index = DAG.getNode(ISD::MUL, dl, PTy, Index, DAG.getConstant(4, PTy)); |
3683 | SDValue Addr = DAG.getNode(ISD::ADD, dl, PTy, Index, Table); | ||||
Evan Cheng | f3a1fce | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3684 | if (Subtarget->isThumb2()) { |
3685 | // Thumb2 uses a two-level jump. That is, it jumps into the jump table | ||||
3686 | // which does another jump to the destination. This also makes it easier | ||||
3687 | // to translate it to TBB / TBH later. | ||||
3688 | // FIXME: This might not work if the function is extremely large. | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3689 | return DAG.getNode(ARMISD::BR2_JT, dl, MVT::Other, Chain, |
Evan Cheng | c6d70ae | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 3690 | Addr, Op.getOperand(2), JTI, UId); |
Evan Cheng | f3a1fce | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3691 | } |
Evan Cheng | f3a1fce | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3692 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Evan Cheng | cdbb70c | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 3693 | Addr = DAG.getLoad((EVT)MVT::i32, dl, Chain, Addr, |
Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3694 | MachinePointerInfo::getJumpTable(), |
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3695 | false, false, false, 0); |
Evan Cheng | f3a1fce | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3696 | Chain = Addr.getValue(1); |
Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 3697 | Addr = DAG.getNode(ISD::ADD, dl, PTy, Addr, Table); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3698 | return DAG.getNode(ARMISD::BR_JT, dl, MVT::Other, Chain, Addr, JTI, UId); |
Evan Cheng | f3a1fce | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3699 | } else { |
Evan Cheng | cdbb70c | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 3700 | Addr = DAG.getLoad(PTy, dl, Chain, Addr, |
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3701 | MachinePointerInfo::getJumpTable(), |
3702 | false, false, false, 0); | ||||
Evan Cheng | f3a1fce | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3703 | Chain = Addr.getValue(1); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3704 | return DAG.getNode(ARMISD::BR_JT, dl, MVT::Other, Chain, Addr, JTI, UId); |
Evan Cheng | f3a1fce | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3705 | } |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3706 | } |
3707 | |||||
Eli Friedman | 2d4055b | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3708 | static SDValue LowerVectorFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
James Molloy | 547d4c0 | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 3709 | EVT VT = Op.getValueType(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3710 | SDLoc dl(Op); |
Eli Friedman | 2d4055b | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3711 | |
James Molloy | 547d4c0 | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 3712 | if (Op.getValueType().getVectorElementType() == MVT::i32) { |
3713 | if (Op.getOperand(0).getValueType().getVectorElementType() == MVT::f32) | ||||
3714 | return Op; | ||||
3715 | return DAG.UnrollVectorOp(Op.getNode()); | ||||
3716 | } | ||||
3717 | |||||
3718 | assert(Op.getOperand(0).getValueType() == MVT::v4f32 && | ||||
3719 | "Invalid type for custom lowering!"); | ||||
3720 | if (VT != MVT::v4i16) | ||||
3721 | return DAG.UnrollVectorOp(Op.getNode()); | ||||
3722 | |||||
3723 | Op = DAG.getNode(Op.getOpcode(), dl, MVT::v4i32, Op.getOperand(0)); | ||||
3724 | return DAG.getNode(ISD::TRUNCATE, dl, VT, Op); | ||||
Eli Friedman | 2d4055b | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3725 | } |
3726 | |||||
Bob Wilson | e4191e7 | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3727 | static SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
Eli Friedman | 2d4055b | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3728 | EVT VT = Op.getValueType(); |
3729 | if (VT.isVector()) | ||||
3730 | return LowerVectorFP_TO_INT(Op, DAG); | ||||
3731 | |||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3732 | SDLoc dl(Op); |
Bob Wilson | e4191e7 | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3733 | unsigned Opc; |
3734 | |||||
3735 | switch (Op.getOpcode()) { | ||||
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3736 | default: llvm_unreachable("Invalid opcode!"); |
Bob Wilson | e4191e7 | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3737 | case ISD::FP_TO_SINT: |
3738 | Opc = ARMISD::FTOSI; | ||||
3739 | break; | ||||
3740 | case ISD::FP_TO_UINT: | ||||
3741 | Opc = ARMISD::FTOUI; | ||||
3742 | break; | ||||
3743 | } | ||||
3744 | Op = DAG.getNode(Opc, dl, MVT::f32, Op.getOperand(0)); | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3745 | return DAG.getNode(ISD::BITCAST, dl, MVT::i32, Op); |
Bob Wilson | e4191e7 | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3746 | } |
3747 | |||||
Cameron Zwarich | 143f9ae | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3748 | static SDValue LowerVectorINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
3749 | EVT VT = Op.getValueType(); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3750 | SDLoc dl(Op); |
Cameron Zwarich | 143f9ae | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3751 | |
Eli Friedman | 2d4055b | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3752 | if (Op.getOperand(0).getValueType().getVectorElementType() == MVT::i32) { |
3753 | if (VT.getVectorElementType() == MVT::f32) | ||||
3754 | return Op; | ||||
3755 | return DAG.UnrollVectorOp(Op.getNode()); | ||||
3756 | } | ||||
3757 | |||||
Duncan Sands | a41634e | 2011-08-12 14:54:45 +0000 | [diff] [blame] | 3758 | assert(Op.getOperand(0).getValueType() == MVT::v4i16 && |
3759 | "Invalid type for custom lowering!"); | ||||
Cameron Zwarich | 143f9ae | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3760 | if (VT != MVT::v4f32) |
3761 | return DAG.UnrollVectorOp(Op.getNode()); | ||||
3762 | |||||
3763 | unsigned CastOpc; | ||||
3764 | unsigned Opc; | ||||
3765 | switch (Op.getOpcode()) { | ||||
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3766 | default: llvm_unreachable("Invalid opcode!"); |
Cameron Zwarich | 143f9ae | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3767 | case ISD::SINT_TO_FP: |
3768 | CastOpc = ISD::SIGN_EXTEND; | ||||
3769 | Opc = ISD::SINT_TO_FP; | ||||
3770 | break; | ||||
3771 | case ISD::UINT_TO_FP: | ||||
3772 | CastOpc = ISD::ZERO_EXTEND; | ||||
3773 | Opc = ISD::UINT_TO_FP; | ||||
3774 | break; | ||||
3775 | } | ||||
3776 | |||||
3777 | Op = DAG.getNode(CastOpc, dl, MVT::v4i32, Op.getOperand(0)); | ||||
3778 | return DAG.getNode(Opc, dl, VT, Op); | ||||
3779 | } | ||||
3780 | |||||
Bob Wilson | e4191e7 | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3781 | static SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
3782 | EVT VT = Op.getValueType(); | ||||
Cameron Zwarich | 143f9ae | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3783 | if (VT.isVector()) |
3784 | return LowerVectorINT_TO_FP(Op, DAG); | ||||
3785 | |||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3786 | SDLoc dl(Op); |
Bob Wilson | e4191e7 | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3787 | unsigned Opc; |
3788 | |||||
3789 | switch (Op.getOpcode()) { | ||||
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3790 | default: llvm_unreachable("Invalid opcode!"); |
Bob Wilson | e4191e7 | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3791 | case ISD::SINT_TO_FP: |
3792 | Opc = ARMISD::SITOF; | ||||
3793 | break; | ||||
3794 | case ISD::UINT_TO_FP: | ||||
3795 | Opc = ARMISD::UITOF; | ||||
3796 | break; | ||||
3797 | } | ||||
3798 | |||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3799 | Op = DAG.getNode(ISD::BITCAST, dl, MVT::f32, Op.getOperand(0)); |
Bob Wilson | e4191e7 | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3800 | return DAG.getNode(Opc, dl, VT, Op); |
3801 | } | ||||
3802 | |||||
Evan Cheng | 25f9364 | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 3803 | SDValue ARMTargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3804 | // Implement fcopysign with a fabs and a conditional fneg. |
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3805 | SDValue Tmp0 = Op.getOperand(0); |
3806 | SDValue Tmp1 = Op.getOperand(1); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3807 | SDLoc dl(Op); |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3808 | EVT VT = Op.getValueType(); |
3809 | EVT SrcVT = Tmp1.getValueType(); | ||||
Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3810 | bool InGPR = Tmp0.getOpcode() == ISD::BITCAST || |
3811 | Tmp0.getOpcode() == ARMISD::VMOVDRR; | ||||
3812 | bool UseNEON = !InGPR && Subtarget->hasNEON(); | ||||
3813 | |||||
3814 | if (UseNEON) { | ||||
3815 | // Use VBSL to copy the sign bit. | ||||
3816 | unsigned EncodedVal = ARM_AM::createNEONModImm(0x6, 0x80); | ||||
3817 | SDValue Mask = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v2i32, | ||||
3818 | DAG.getTargetConstant(EncodedVal, MVT::i32)); | ||||
3819 | EVT OpVT = (VT == MVT::f32) ? MVT::v2i32 : MVT::v1i64; | ||||
3820 | if (VT == MVT::f64) | ||||
3821 | Mask = DAG.getNode(ARMISD::VSHL, dl, OpVT, | ||||
3822 | DAG.getNode(ISD::BITCAST, dl, OpVT, Mask), | ||||
3823 | DAG.getConstant(32, MVT::i32)); | ||||
3824 | else /*if (VT == MVT::f32)*/ | ||||
3825 | Tmp0 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp0); | ||||
3826 | if (SrcVT == MVT::f32) { | ||||
3827 | Tmp1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp1); | ||||
3828 | if (VT == MVT::f64) | ||||
3829 | Tmp1 = DAG.getNode(ARMISD::VSHL, dl, OpVT, | ||||
3830 | DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1), | ||||
3831 | DAG.getConstant(32, MVT::i32)); | ||||
Evan Cheng | 12bb05b | 2011-04-15 01:31:00 +0000 | [diff] [blame] | 3832 | } else if (VT == MVT::f32) |
3833 | Tmp1 = DAG.getNode(ARMISD::VSHRu, dl, MVT::v1i64, | ||||
3834 | DAG.getNode(ISD::BITCAST, dl, MVT::v1i64, Tmp1), | ||||
3835 | DAG.getConstant(32, MVT::i32)); | ||||
Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3836 | Tmp0 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp0); |
3837 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1); | ||||
3838 | |||||
3839 | SDValue AllOnes = DAG.getTargetConstant(ARM_AM::createNEONModImm(0xe, 0xff), | ||||
3840 | MVT::i32); | ||||
3841 | AllOnes = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v8i8, AllOnes); | ||||
3842 | SDValue MaskNot = DAG.getNode(ISD::XOR, dl, OpVT, Mask, | ||||
3843 | DAG.getNode(ISD::BITCAST, dl, OpVT, AllOnes)); | ||||
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 3844 | |
Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3845 | SDValue Res = DAG.getNode(ISD::OR, dl, OpVT, |
3846 | DAG.getNode(ISD::AND, dl, OpVT, Tmp1, Mask), | ||||
3847 | DAG.getNode(ISD::AND, dl, OpVT, Tmp0, MaskNot)); | ||||
Evan Cheng | 6e3d443 | 2011-02-28 18:45:27 +0000 | [diff] [blame] | 3848 | if (VT == MVT::f32) { |
Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3849 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::v2f32, Res); |
3850 | Res = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f32, Res, | ||||
3851 | DAG.getConstant(0, MVT::i32)); | ||||
3852 | } else { | ||||
3853 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::f64, Res); | ||||
3854 | } | ||||
3855 | |||||
3856 | return Res; | ||||
3857 | } | ||||
Evan Cheng | 2da1c95 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 3858 | |
3859 | // Bitcast operand 1 to i32. | ||||
3860 | if (SrcVT == MVT::f64) | ||||
3861 | Tmp1 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), | ||||
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 3862 | Tmp1).getValue(1); |
Evan Cheng | 2da1c95 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 3863 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp1); |
3864 | |||||
Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3865 | // Or in the signbit with integer operations. |
3866 | SDValue Mask1 = DAG.getConstant(0x80000000, MVT::i32); | ||||
3867 | SDValue Mask2 = DAG.getConstant(0x7fffffff, MVT::i32); | ||||
3868 | Tmp1 = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp1, Mask1); | ||||
3869 | if (VT == MVT::f32) { | ||||
3870 | Tmp0 = DAG.getNode(ISD::AND, dl, MVT::i32, | ||||
3871 | DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp0), Mask2); | ||||
3872 | return DAG.getNode(ISD::BITCAST, dl, MVT::f32, | ||||
3873 | DAG.getNode(ISD::OR, dl, MVT::i32, Tmp0, Tmp1)); | ||||
Evan Cheng | 2da1c95 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 3874 | } |
3875 | |||||
Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3876 | // f64: Or the high part with signbit and then combine two parts. |
3877 | Tmp0 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), | ||||
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 3878 | Tmp0); |
Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3879 | SDValue Lo = Tmp0.getValue(0); |
3880 | SDValue Hi = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp0.getValue(1), Mask2); | ||||
3881 | Hi = DAG.getNode(ISD::OR, dl, MVT::i32, Hi, Tmp1); | ||||
3882 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3883 | } |
3884 | |||||
Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3885 | SDValue ARMTargetLowering::LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const{ |
3886 | MachineFunction &MF = DAG.getMachineFunction(); | ||||
3887 | MachineFrameInfo *MFI = MF.getFrameInfo(); | ||||
3888 | MFI->setReturnAddressIsTaken(true); | ||||
3889 | |||||
Bill Wendling | 908bf81 | 2014-01-06 00:43:20 +0000 | [diff] [blame] | 3890 | if (verifyReturnAddressArgumentIsConstant(Op, DAG)) |
Bill Wendling | df7dd28 | 2014-01-05 01:47:20 +0000 | [diff] [blame] | 3891 | return SDValue(); |
Bill Wendling | df7dd28 | 2014-01-05 01:47:20 +0000 | [diff] [blame] | 3892 | |
Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3893 | EVT VT = Op.getValueType(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3894 | SDLoc dl(Op); |
Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3895 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
3896 | if (Depth) { | ||||
3897 | SDValue FrameAddr = LowerFRAMEADDR(Op, DAG); | ||||
3898 | SDValue Offset = DAG.getConstant(4, MVT::i32); | ||||
3899 | return DAG.getLoad(VT, dl, DAG.getEntryNode(), | ||||
3900 | DAG.getNode(ISD::ADD, dl, VT, FrameAddr, Offset), | ||||
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3901 | MachinePointerInfo(), false, false, false, 0); |
Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3902 | } |
3903 | |||||
3904 | // Return LR, which contains the return address. Mark it an implicit live-in. | ||||
Devang Patel | f3292b2 | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 3905 | unsigned Reg = MF.addLiveIn(ARM::LR, getRegClassFor(MVT::i32)); |
Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3906 | return DAG.getCopyFromReg(DAG.getEntryNode(), dl, Reg, VT); |
3907 | } | ||||
3908 | |||||
Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3909 | SDValue ARMTargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const { |
Jim Grosbach | aeca45d | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3910 | MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); |
3911 | MFI->setFrameAddressIsTaken(true); | ||||
Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3912 | |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3913 | EVT VT = Op.getValueType(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3914 | SDLoc dl(Op); // FIXME probably not meaningful |
Jim Grosbach | aeca45d | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3915 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 3916 | unsigned FrameReg = (Subtarget->isThumb() || Subtarget->isTargetMachO()) |
Jim Grosbach | aeca45d | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3917 | ? ARM::R7 : ARM::R11; |
3918 | SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, FrameReg, VT); | ||||
3919 | while (Depth--) | ||||
Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3920 | FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr, |
3921 | MachinePointerInfo(), | ||||
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3922 | false, false, false, 0); |
Jim Grosbach | aeca45d | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3923 | return FrameAddr; |
3924 | } | ||||
3925 | |||||
Renato Golin | c7aea40 | 2014-05-06 16:51:25 +0000 | [diff] [blame] | 3926 | // FIXME? Maybe this could be a TableGen attribute on some registers and |
3927 | // this table could be generated automatically from RegInfo. | ||||
Hal Finkel | f0e086a | 2014-05-11 19:29:07 +0000 | [diff] [blame] | 3928 | unsigned ARMTargetLowering::getRegisterByName(const char* RegName, |
3929 | EVT VT) const { | ||||
Renato Golin | c7aea40 | 2014-05-06 16:51:25 +0000 | [diff] [blame] | 3930 | unsigned Reg = StringSwitch<unsigned>(RegName) |
3931 | .Case("sp", ARM::SP) | ||||
3932 | .Default(0); | ||||
3933 | if (Reg) | ||||
3934 | return Reg; | ||||
3935 | report_fatal_error("Invalid register name global variable"); | ||||
3936 | } | ||||
3937 | |||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3938 | /// ExpandBITCAST - If the target supports VFP, this function is called to |
Bob Wilson | 59b70ea | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3939 | /// expand a bit convert where either the source or destination type is i64 to |
3940 | /// use a VMOVDRR or VMOVRRD node. This should not be done when the non-i64 | ||||
3941 | /// operand type is illegal (e.g., v2f32 for a target that doesn't support | ||||
3942 | /// vectors), since the legalizer won't know what to do with that. | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3943 | static SDValue ExpandBITCAST(SDNode *N, SelectionDAG &DAG) { |
Bob Wilson | 59b70ea | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3944 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3945 | SDLoc dl(N); |
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3946 | SDValue Op = N->getOperand(0); |
Bob Wilson | c05b887 | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3947 | |
Bob Wilson | 59b70ea | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3948 | // This function is only supposed to be called for i64 types, either as the |
3949 | // source or destination of the bit convert. | ||||
3950 | EVT SrcVT = Op.getValueType(); | ||||
3951 | EVT DstVT = N->getValueType(0); | ||||
3952 | assert((SrcVT == MVT::i64 || DstVT == MVT::i64) && | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3953 | "ExpandBITCAST called for non-i64 type"); |
Bob Wilson | c05b887 | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3954 | |
Bob Wilson | 59b70ea | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3955 | // Turn i64->f64 into VMOVDRR. |
3956 | if (SrcVT == MVT::i64 && TLI.isTypeLegal(DstVT)) { | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3957 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
3958 | DAG.getConstant(0, MVT::i32)); | ||||
3959 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, | ||||
3960 | DAG.getConstant(1, MVT::i32)); | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3961 | return DAG.getNode(ISD::BITCAST, dl, DstVT, |
Bob Wilson | f07d33d | 2010-06-11 22:45:25 +0000 | [diff] [blame] | 3962 | DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi)); |
Evan Cheng | 297b32a | 2008-11-04 19:57:48 +0000 | [diff] [blame] | 3963 | } |
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3964 | |
Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 3965 | // Turn f64->i64 into VMOVRRD. |
Bob Wilson | 59b70ea | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3966 | if (DstVT == MVT::i64 && TLI.isTypeLegal(SrcVT)) { |
Christian Pirker | 238c7c1 | 2014-05-12 11:19:20 +0000 | [diff] [blame^] | 3967 | SDValue Cvt; |
3968 | if (TLI.isBigEndian() && SrcVT.isVector()) | ||||
3969 | Cvt = DAG.getNode(ARMISD::VMOVRRD, dl, | ||||
3970 | DAG.getVTList(MVT::i32, MVT::i32), | ||||
3971 | DAG.getNode(ARMISD::VREV64, dl, SrcVT, Op)); | ||||
3972 | else | ||||
3973 | Cvt = DAG.getNode(ARMISD::VMOVRRD, dl, | ||||
3974 | DAG.getVTList(MVT::i32, MVT::i32), Op); | ||||
Bob Wilson | 59b70ea | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3975 | // Merge the pieces into a single i64 value. |
3976 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Cvt, Cvt.getValue(1)); | ||||
3977 | } | ||||
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3978 | |
Bob Wilson | 59b70ea | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3979 | return SDValue(); |
Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3980 | } |
3981 | |||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3982 | /// getZeroVector - Returns a vector of specified type with all zero elements. |
Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3983 | /// Zero vectors are used to represent vector negation and in those cases |
3984 | /// will be implemented with the NEON VNEG instruction. However, VNEG does | ||||
3985 | /// not support i64 elements, so sometimes the zero vectors will need to be | ||||
3986 | /// explicitly constructed. Regardless, use a canonical VMOV to create the | ||||
3987 | /// zero vector. | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3988 | static SDValue getZeroVector(EVT VT, SelectionDAG &DAG, SDLoc dl) { |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3989 | assert(VT.isVector() && "Expected a vector type"); |
Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3990 | // The canonical modified immediate encoding of a zero vector is....0! |
3991 | SDValue EncodedVal = DAG.getTargetConstant(0, MVT::i32); | ||||
3992 | EVT VmovVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; | ||||
3993 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, EncodedVal); | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3994 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3995 | } |
3996 | |||||
Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3997 | /// LowerShiftRightParts - Lower SRA_PARTS, which returns two |
3998 | /// i32 values and take a 2 x i32 value to shift plus a shift amount. | ||||
Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3999 | SDValue ARMTargetLowering::LowerShiftRightParts(SDValue Op, |
4000 | SelectionDAG &DAG) const { | ||||
Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4001 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
4002 | EVT VT = Op.getValueType(); | ||||
4003 | unsigned VTBits = VT.getSizeInBits(); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4004 | SDLoc dl(Op); |
Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4005 | SDValue ShOpLo = Op.getOperand(0); |
4006 | SDValue ShOpHi = Op.getOperand(1); | ||||
4007 | SDValue ShAmt = Op.getOperand(2); | ||||
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 4008 | SDValue ARMcc; |
Jim Grosbach | 8fe6fd7 | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 4009 | unsigned Opc = (Op.getOpcode() == ISD::SRA_PARTS) ? ISD::SRA : ISD::SRL; |
Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4010 | |
Jim Grosbach | 8fe6fd7 | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 4011 | assert(Op.getOpcode() == ISD::SRA_PARTS || Op.getOpcode() == ISD::SRL_PARTS); |
4012 | |||||
Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4013 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
4014 | DAG.getConstant(VTBits, MVT::i32), ShAmt); | ||||
4015 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, ShAmt); | ||||
4016 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, | ||||
4017 | DAG.getConstant(VTBits, MVT::i32)); | ||||
4018 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, RevShAmt); | ||||
4019 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); | ||||
Jim Grosbach | 8fe6fd7 | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 4020 | SDValue TrueVal = DAG.getNode(Opc, dl, VT, ShOpHi, ExtraShAmt); |
Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4021 | |
4022 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); | ||||
4023 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, | ||||
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 4024 | ARMcc, DAG, dl); |
Jim Grosbach | 8fe6fd7 | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 4025 | SDValue Hi = DAG.getNode(Opc, dl, VT, ShOpHi, ShAmt); |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 4026 | SDValue Lo = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, |
Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4027 | CCR, Cmp); |
4028 | |||||
4029 | SDValue Ops[2] = { Lo, Hi }; | ||||
Craig Topper | 64941d9 | 2014-04-27 19:20:57 +0000 | [diff] [blame] | 4030 | return DAG.getMergeValues(Ops, dl); |
Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4031 | } |
4032 | |||||
Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4033 | /// LowerShiftLeftParts - Lower SHL_PARTS, which returns two |
4034 | /// i32 values and take a 2 x i32 value to shift plus a shift amount. | ||||
Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 4035 | SDValue ARMTargetLowering::LowerShiftLeftParts(SDValue Op, |
4036 | SelectionDAG &DAG) const { | ||||
Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4037 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
4038 | EVT VT = Op.getValueType(); | ||||
4039 | unsigned VTBits = VT.getSizeInBits(); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4040 | SDLoc dl(Op); |
Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4041 | SDValue ShOpLo = Op.getOperand(0); |
4042 | SDValue ShOpHi = Op.getOperand(1); | ||||
4043 | SDValue ShAmt = Op.getOperand(2); | ||||
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 4044 | SDValue ARMcc; |
Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4045 | |
4046 | assert(Op.getOpcode() == ISD::SHL_PARTS); | ||||
4047 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, | ||||
4048 | DAG.getConstant(VTBits, MVT::i32), ShAmt); | ||||
4049 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, RevShAmt); | ||||
4050 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, | ||||
4051 | DAG.getConstant(VTBits, MVT::i32)); | ||||
4052 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, ShAmt); | ||||
4053 | SDValue Tmp3 = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ExtraShAmt); | ||||
4054 | |||||
4055 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); | ||||
4056 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); | ||||
4057 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, | ||||
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 4058 | ARMcc, DAG, dl); |
Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4059 | SDValue Lo = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ShAmt); |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 4060 | SDValue Hi = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, Tmp3, ARMcc, |
Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4061 | CCR, Cmp); |
4062 | |||||
4063 | SDValue Ops[2] = { Lo, Hi }; | ||||
Craig Topper | 64941d9 | 2014-04-27 19:20:57 +0000 | [diff] [blame] | 4064 | return DAG.getMergeValues(Ops, dl); |
Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4065 | } |
4066 | |||||
Jim Grosbach | 535d3b4 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 4067 | SDValue ARMTargetLowering::LowerFLT_ROUNDS_(SDValue Op, |
Nate Begeman | b69b182 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 4068 | SelectionDAG &DAG) const { |
4069 | // The rounding mode is in bits 23:22 of the FPSCR. | ||||
4070 | // The ARM rounding mode value to FLT_ROUNDS mapping is 0->1, 1->2, 2->3, 3->0 | ||||
4071 | // The formula we use to implement this is (((FPSCR + 1 << 22) >> 22) & 3) | ||||
4072 | // so that the shift + and get folded into a bitfield extract. | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4073 | SDLoc dl(Op); |
Nate Begeman | b69b182 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 4074 | SDValue FPSCR = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::i32, |
4075 | DAG.getConstant(Intrinsic::arm_get_fpscr, | ||||
4076 | MVT::i32)); | ||||
Jim Grosbach | 535d3b4 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 4077 | SDValue FltRounds = DAG.getNode(ISD::ADD, dl, MVT::i32, FPSCR, |
Nate Begeman | b69b182 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 4078 | DAG.getConstant(1U << 22, MVT::i32)); |
4079 | SDValue RMODE = DAG.getNode(ISD::SRL, dl, MVT::i32, FltRounds, | ||||
4080 | DAG.getConstant(22, MVT::i32)); | ||||
Jim Grosbach | 535d3b4 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 4081 | return DAG.getNode(ISD::AND, dl, MVT::i32, RMODE, |
Nate Begeman | b69b182 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 4082 | DAG.getConstant(3, MVT::i32)); |
4083 | } | ||||
4084 | |||||
Jim Grosbach | 8546ec9 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 4085 | static SDValue LowerCTTZ(SDNode *N, SelectionDAG &DAG, |
4086 | const ARMSubtarget *ST) { | ||||
4087 | EVT VT = N->getValueType(0); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4088 | SDLoc dl(N); |
Jim Grosbach | 8546ec9 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 4089 | |
4090 | if (!ST->hasV6T2Ops()) | ||||
4091 | return SDValue(); | ||||
4092 | |||||
4093 | SDValue rbit = DAG.getNode(ARMISD::RBIT, dl, VT, N->getOperand(0)); | ||||
4094 | return DAG.getNode(ISD::CTLZ, dl, VT, rbit); | ||||
4095 | } | ||||
4096 | |||||
Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4097 | /// getCTPOP16BitCounts - Returns a v8i8/v16i8 vector containing the bit-count |
4098 | /// for each 16-bit element from operand, repeated. The basic idea is to | ||||
4099 | /// leverage vcnt to get the 8-bit counts, gather and add the results. | ||||
4100 | /// | ||||
4101 | /// Trace for v4i16: | ||||
4102 | /// input = [v0 v1 v2 v3 ] (vi 16-bit element) | ||||
4103 | /// cast: N0 = [w0 w1 w2 w3 w4 w5 w6 w7] (v0 = [w0 w1], wi 8-bit element) | ||||
4104 | /// vcnt: N1 = [b0 b1 b2 b3 b4 b5 b6 b7] (bi = bit-count of 8-bit element wi) | ||||
Jim Grosbach | 54efea0 | 2013-03-02 20:16:15 +0000 | [diff] [blame] | 4105 | /// vrev: N2 = [b1 b0 b3 b2 b5 b4 b7 b6] |
Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4106 | /// [b0 b1 b2 b3 b4 b5 b6 b7] |
4107 | /// +[b1 b0 b3 b2 b5 b4 b7 b6] | ||||
4108 | /// N3=N1+N2 = [k0 k0 k1 k1 k2 k2 k3 k3] (k0 = b0+b1 = bit-count of 16-bit v0, | ||||
4109 | /// vuzp: = [k0 k1 k2 k3 k0 k1 k2 k3] each ki is 8-bits) | ||||
4110 | static SDValue getCTPOP16BitCounts(SDNode *N, SelectionDAG &DAG) { | ||||
4111 | EVT VT = N->getValueType(0); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4112 | SDLoc DL(N); |
Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4113 | |
4114 | EVT VT8Bit = VT.is64BitVector() ? MVT::v8i8 : MVT::v16i8; | ||||
4115 | SDValue N0 = DAG.getNode(ISD::BITCAST, DL, VT8Bit, N->getOperand(0)); | ||||
4116 | SDValue N1 = DAG.getNode(ISD::CTPOP, DL, VT8Bit, N0); | ||||
4117 | SDValue N2 = DAG.getNode(ARMISD::VREV16, DL, VT8Bit, N1); | ||||
4118 | SDValue N3 = DAG.getNode(ISD::ADD, DL, VT8Bit, N1, N2); | ||||
4119 | return DAG.getNode(ARMISD::VUZP, DL, VT8Bit, N3, N3); | ||||
4120 | } | ||||
4121 | |||||
4122 | /// lowerCTPOP16BitElements - Returns a v4i16/v8i16 vector containing the | ||||
4123 | /// bit-count for each 16-bit element from the operand. We need slightly | ||||
4124 | /// different sequencing for v4i16 and v8i16 to stay within NEON's available | ||||
4125 | /// 64/128-bit registers. | ||||
Jim Grosbach | 54efea0 | 2013-03-02 20:16:15 +0000 | [diff] [blame] | 4126 | /// |
Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4127 | /// Trace for v4i16: |
4128 | /// input = [v0 v1 v2 v3 ] (vi 16-bit element) | ||||
4129 | /// v8i8: BitCounts = [k0 k1 k2 k3 k0 k1 k2 k3 ] (ki is the bit-count of vi) | ||||
4130 | /// v8i16:Extended = [k0 k1 k2 k3 k0 k1 k2 k3 ] | ||||
4131 | /// v4i16:Extracted = [k0 k1 k2 k3 ] | ||||
4132 | static SDValue lowerCTPOP16BitElements(SDNode *N, SelectionDAG &DAG) { | ||||
4133 | EVT VT = N->getValueType(0); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4134 | SDLoc DL(N); |
Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4135 | |
4136 | SDValue BitCounts = getCTPOP16BitCounts(N, DAG); | ||||
4137 | if (VT.is64BitVector()) { | ||||
4138 | SDValue Extended = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v8i16, BitCounts); | ||||
4139 | return DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MVT::v4i16, Extended, | ||||
4140 | DAG.getIntPtrConstant(0)); | ||||
4141 | } else { | ||||
4142 | SDValue Extracted = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MVT::v8i8, | ||||
4143 | BitCounts, DAG.getIntPtrConstant(0)); | ||||
4144 | return DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v8i16, Extracted); | ||||
4145 | } | ||||
4146 | } | ||||
4147 | |||||
4148 | /// lowerCTPOP32BitElements - Returns a v2i32/v4i32 vector containing the | ||||
4149 | /// bit-count for each 32-bit element from the operand. The idea here is | ||||
4150 | /// to split the vector into 16-bit elements, leverage the 16-bit count | ||||
4151 | /// routine, and then combine the results. | ||||
4152 | /// | ||||
4153 | /// Trace for v2i32 (v4i32 similar with Extracted/Extended exchanged): | ||||
4154 | /// input = [v0 v1 ] (vi: 32-bit elements) | ||||
4155 | /// Bitcast = [w0 w1 w2 w3 ] (wi: 16-bit elements, v0 = [w0 w1]) | ||||
4156 | /// Counts16 = [k0 k1 k2 k3 ] (ki: 16-bit elements, bit-count of wi) | ||||
Jim Grosbach | 54efea0 | 2013-03-02 20:16:15 +0000 | [diff] [blame] | 4157 | /// vrev: N0 = [k1 k0 k3 k2 ] |
Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4158 | /// [k0 k1 k2 k3 ] |
4159 | /// N1 =+[k1 k0 k3 k2 ] | ||||
4160 | /// [k0 k2 k1 k3 ] | ||||
4161 | /// N2 =+[k1 k3 k0 k2 ] | ||||
4162 | /// [k0 k2 k1 k3 ] | ||||
4163 | /// Extended =+[k1 k3 k0 k2 ] | ||||
4164 | /// [k0 k2 ] | ||||
4165 | /// Extracted=+[k1 k3 ] | ||||
4166 | /// | ||||
4167 | static SDValue lowerCTPOP32BitElements(SDNode *N, SelectionDAG &DAG) { | ||||
4168 | EVT VT = N->getValueType(0); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4169 | SDLoc DL(N); |
Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4170 | |
4171 | EVT VT16Bit = VT.is64BitVector() ? MVT::v4i16 : MVT::v8i16; | ||||
4172 | |||||
4173 | SDValue Bitcast = DAG.getNode(ISD::BITCAST, DL, VT16Bit, N->getOperand(0)); | ||||
4174 | SDValue Counts16 = lowerCTPOP16BitElements(Bitcast.getNode(), DAG); | ||||
4175 | SDValue N0 = DAG.getNode(ARMISD::VREV32, DL, VT16Bit, Counts16); | ||||
4176 | SDValue N1 = DAG.getNode(ISD::ADD, DL, VT16Bit, Counts16, N0); | ||||
4177 | SDValue N2 = DAG.getNode(ARMISD::VUZP, DL, VT16Bit, N1, N1); | ||||
4178 | |||||
4179 | if (VT.is64BitVector()) { | ||||
4180 | SDValue Extended = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v4i32, N2); | ||||
4181 | return DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MVT::v2i32, Extended, | ||||
4182 | DAG.getIntPtrConstant(0)); | ||||
4183 | } else { | ||||
4184 | SDValue Extracted = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MVT::v4i16, N2, | ||||
4185 | DAG.getIntPtrConstant(0)); | ||||
4186 | return DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v4i32, Extracted); | ||||
4187 | } | ||||
4188 | } | ||||
4189 | |||||
4190 | static SDValue LowerCTPOP(SDNode *N, SelectionDAG &DAG, | ||||
4191 | const ARMSubtarget *ST) { | ||||
4192 | EVT VT = N->getValueType(0); | ||||
4193 | |||||
4194 | assert(ST->hasNEON() && "Custom ctpop lowering requires NEON."); | ||||
Matt Beaumont-Gay | 50f61b6 | 2012-12-04 23:54:02 +0000 | [diff] [blame] | 4195 | assert((VT == MVT::v2i32 || VT == MVT::v4i32 || |
4196 | VT == MVT::v4i16 || VT == MVT::v8i16) && | ||||
Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4197 | "Unexpected type for custom ctpop lowering"); |
4198 | |||||
4199 | if (VT.getVectorElementType() == MVT::i32) | ||||
4200 | return lowerCTPOP32BitElements(N, DAG); | ||||
4201 | else | ||||
4202 | return lowerCTPOP16BitElements(N, DAG); | ||||
4203 | } | ||||
4204 | |||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4205 | static SDValue LowerShift(SDNode *N, SelectionDAG &DAG, |
4206 | const ARMSubtarget *ST) { | ||||
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4207 | EVT VT = N->getValueType(0); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4208 | SDLoc dl(N); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4209 | |
Bob Wilson | 7d47133 | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 4210 | if (!VT.isVector()) |
4211 | return SDValue(); | ||||
4212 | |||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4213 | // Lower vector shifts on NEON to use VSHL. |
Bob Wilson | 7d47133 | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 4214 | assert(ST->hasNEON() && "unexpected vector shift"); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4215 | |
Bob Wilson | 7d47133 | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 4216 | // Left shifts translate directly to the vshiftu intrinsic. |
4217 | if (N->getOpcode() == ISD::SHL) | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4218 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
Bob Wilson | 7d47133 | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 4219 | DAG.getConstant(Intrinsic::arm_neon_vshiftu, MVT::i32), |
4220 | N->getOperand(0), N->getOperand(1)); | ||||
4221 | |||||
4222 | assert((N->getOpcode() == ISD::SRA || | ||||
4223 | N->getOpcode() == ISD::SRL) && "unexpected vector shift opcode"); | ||||
4224 | |||||
4225 | // NEON uses the same intrinsics for both left and right shifts. For | ||||
4226 | // right shifts, the shift amounts are negative, so negate the vector of | ||||
4227 | // shift amounts. | ||||
4228 | EVT ShiftVT = N->getOperand(1).getValueType(); | ||||
4229 | SDValue NegatedCount = DAG.getNode(ISD::SUB, dl, ShiftVT, | ||||
4230 | getZeroVector(ShiftVT, DAG, dl), | ||||
4231 | N->getOperand(1)); | ||||
4232 | Intrinsic::ID vshiftInt = (N->getOpcode() == ISD::SRA ? | ||||
4233 | Intrinsic::arm_neon_vshifts : | ||||
4234 | Intrinsic::arm_neon_vshiftu); | ||||
4235 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, | ||||
4236 | DAG.getConstant(vshiftInt, MVT::i32), | ||||
4237 | N->getOperand(0), NegatedCount); | ||||
4238 | } | ||||
4239 | |||||
4240 | static SDValue Expand64BitShift(SDNode *N, SelectionDAG &DAG, | ||||
4241 | const ARMSubtarget *ST) { | ||||
4242 | EVT VT = N->getValueType(0); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4243 | SDLoc dl(N); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4244 | |
Eli Friedman | 682d8c1 | 2009-08-22 03:13:10 +0000 | [diff] [blame] | 4245 | // We can get here for a node like i32 = ISD::SHL i32, i64 |
4246 | if (VT != MVT::i64) | ||||
4247 | return SDValue(); | ||||
4248 | |||||
4249 | assert((N->getOpcode() == ISD::SRL || N->getOpcode() == ISD::SRA) && | ||||
Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4250 | "Unknown shift to lower!"); |
Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 4251 | |
Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4252 | // We only lower SRA, SRL of 1 here, all others use generic lowering. |
4253 | if (!isa<ConstantSDNode>(N->getOperand(1)) || | ||||
Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 4254 | cast<ConstantSDNode>(N->getOperand(1))->getZExtValue() != 1) |
Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 4255 | return SDValue(); |
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4256 | |
Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4257 | // If we are in thumb mode, we don't have RRX. |
David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 4258 | if (ST->isThumb1Only()) return SDValue(); |
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4259 | |
Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4260 | // Okay, we have a 64-bit SRA or SRL of 1. Lower this to an RRX expr. |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4261 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, N->getOperand(0), |
Bob Wilson | 26fdebc | 2010-05-25 03:36:52 +0000 | [diff] [blame] | 4262 | DAG.getConstant(0, MVT::i32)); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4263 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, N->getOperand(0), |
Bob Wilson | 26fdebc | 2010-05-25 03:36:52 +0000 | [diff] [blame] | 4264 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4265 | |
Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4266 | // First, build a SRA_FLAG/SRL_FLAG op, which shifts the top part by one and |
4267 | // captures the result into a carry flag. | ||||
4268 | unsigned Opc = N->getOpcode() == ISD::SRL ? ARMISD::SRL_FLAG:ARMISD::SRA_FLAG; | ||||
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 4269 | Hi = DAG.getNode(Opc, dl, DAG.getVTList(MVT::i32, MVT::Glue), Hi); |
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4270 | |
Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4271 | // The low part is an ARMISD::RRX operand, which shifts the carry in. |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4272 | Lo = DAG.getNode(ARMISD::RRX, dl, MVT::i32, Lo, Hi.getValue(1)); |
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4273 | |
Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4274 | // Merge the pieces into a single i64 value. |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4275 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi); |
Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4276 | } |
4277 | |||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4278 | static SDValue LowerVSETCC(SDValue Op, SelectionDAG &DAG) { |
4279 | SDValue TmpOp0, TmpOp1; | ||||
4280 | bool Invert = false; | ||||
4281 | bool Swap = false; | ||||
4282 | unsigned Opc = 0; | ||||
4283 | |||||
4284 | SDValue Op0 = Op.getOperand(0); | ||||
4285 | SDValue Op1 = Op.getOperand(1); | ||||
4286 | SDValue CC = Op.getOperand(2); | ||||
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4287 | EVT VT = Op.getValueType(); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4288 | ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4289 | SDLoc dl(Op); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4290 | |
4291 | if (Op.getOperand(1).getValueType().isFloatingPoint()) { | ||||
4292 | switch (SetCCOpcode) { | ||||
David Blaikie | 46a9f01 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 4293 | default: llvm_unreachable("Illegal FP comparison"); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4294 | case ISD::SETUNE: |
4295 | case ISD::SETNE: Invert = true; // Fallthrough | ||||
4296 | case ISD::SETOEQ: | ||||
4297 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; | ||||
4298 | case ISD::SETOLT: | ||||
4299 | case ISD::SETLT: Swap = true; // Fallthrough | ||||
4300 | case ISD::SETOGT: | ||||
4301 | case ISD::SETGT: Opc = ARMISD::VCGT; break; | ||||
4302 | case ISD::SETOLE: | ||||
4303 | case ISD::SETLE: Swap = true; // Fallthrough | ||||
4304 | case ISD::SETOGE: | ||||
4305 | case ISD::SETGE: Opc = ARMISD::VCGE; break; | ||||
4306 | case ISD::SETUGE: Swap = true; // Fallthrough | ||||
4307 | case ISD::SETULE: Invert = true; Opc = ARMISD::VCGT; break; | ||||
4308 | case ISD::SETUGT: Swap = true; // Fallthrough | ||||
4309 | case ISD::SETULT: Invert = true; Opc = ARMISD::VCGE; break; | ||||
4310 | case ISD::SETUEQ: Invert = true; // Fallthrough | ||||
4311 | case ISD::SETONE: | ||||
4312 | // Expand this to (OLT | OGT). | ||||
4313 | TmpOp0 = Op0; | ||||
4314 | TmpOp1 = Op1; | ||||
4315 | Opc = ISD::OR; | ||||
4316 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); | ||||
4317 | Op1 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp0, TmpOp1); | ||||
4318 | break; | ||||
4319 | case ISD::SETUO: Invert = true; // Fallthrough | ||||
4320 | case ISD::SETO: | ||||
4321 | // Expand this to (OLT | OGE). | ||||
4322 | TmpOp0 = Op0; | ||||
4323 | TmpOp1 = Op1; | ||||
4324 | Opc = ISD::OR; | ||||
4325 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); | ||||
4326 | Op1 = DAG.getNode(ARMISD::VCGE, dl, VT, TmpOp0, TmpOp1); | ||||
4327 | break; | ||||
4328 | } | ||||
4329 | } else { | ||||
4330 | // Integer comparisons. | ||||
4331 | switch (SetCCOpcode) { | ||||
David Blaikie | 46a9f01 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 4332 | default: llvm_unreachable("Illegal integer comparison"); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4333 | case ISD::SETNE: Invert = true; |
4334 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; | ||||
4335 | case ISD::SETLT: Swap = true; | ||||
4336 | case ISD::SETGT: Opc = ARMISD::VCGT; break; | ||||
4337 | case ISD::SETLE: Swap = true; | ||||
4338 | case ISD::SETGE: Opc = ARMISD::VCGE; break; | ||||
4339 | case ISD::SETULT: Swap = true; | ||||
4340 | case ISD::SETUGT: Opc = ARMISD::VCGTU; break; | ||||
4341 | case ISD::SETULE: Swap = true; | ||||
4342 | case ISD::SETUGE: Opc = ARMISD::VCGEU; break; | ||||
4343 | } | ||||
4344 | |||||
Nick Lewycky | a21d3da | 2009-07-08 03:04:38 +0000 | [diff] [blame] | 4345 | // Detect VTST (Vector Test Bits) = icmp ne (and (op0, op1), zero). |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4346 | if (Opc == ARMISD::VCEQ) { |
4347 | |||||
4348 | SDValue AndOp; | ||||
4349 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) | ||||
4350 | AndOp = Op0; | ||||
4351 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) | ||||
4352 | AndOp = Op1; | ||||
4353 | |||||
4354 | // Ignore bitconvert. | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4355 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::BITCAST) |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4356 | AndOp = AndOp.getOperand(0); |
4357 | |||||
4358 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::AND) { | ||||
4359 | Opc = ARMISD::VTST; | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4360 | Op0 = DAG.getNode(ISD::BITCAST, dl, VT, AndOp.getOperand(0)); |
4361 | Op1 = DAG.getNode(ISD::BITCAST, dl, VT, AndOp.getOperand(1)); | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4362 | Invert = !Invert; |
4363 | } | ||||
4364 | } | ||||
4365 | } | ||||
4366 | |||||
4367 | if (Swap) | ||||
4368 | std::swap(Op0, Op1); | ||||
4369 | |||||
Owen Anderson | c7baee3 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 4370 | // If one of the operands is a constant vector zero, attempt to fold the |
4371 | // comparison to a specialized compare-against-zero form. | ||||
4372 | SDValue SingleOp; | ||||
4373 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) | ||||
4374 | SingleOp = Op0; | ||||
4375 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) { | ||||
4376 | if (Opc == ARMISD::VCGE) | ||||
4377 | Opc = ARMISD::VCLEZ; | ||||
4378 | else if (Opc == ARMISD::VCGT) | ||||
4379 | Opc = ARMISD::VCLTZ; | ||||
4380 | SingleOp = Op1; | ||||
4381 | } | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4382 | |
Owen Anderson | c7baee3 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 4383 | SDValue Result; |
4384 | if (SingleOp.getNode()) { | ||||
4385 | switch (Opc) { | ||||
4386 | case ARMISD::VCEQ: | ||||
4387 | Result = DAG.getNode(ARMISD::VCEQZ, dl, VT, SingleOp); break; | ||||
4388 | case ARMISD::VCGE: | ||||
4389 | Result = DAG.getNode(ARMISD::VCGEZ, dl, VT, SingleOp); break; | ||||
4390 | case ARMISD::VCLEZ: | ||||
4391 | Result = DAG.getNode(ARMISD::VCLEZ, dl, VT, SingleOp); break; | ||||
4392 | case ARMISD::VCGT: | ||||
4393 | Result = DAG.getNode(ARMISD::VCGTZ, dl, VT, SingleOp); break; | ||||
4394 | case ARMISD::VCLTZ: | ||||
4395 | Result = DAG.getNode(ARMISD::VCLTZ, dl, VT, SingleOp); break; | ||||
4396 | default: | ||||
4397 | Result = DAG.getNode(Opc, dl, VT, Op0, Op1); | ||||
4398 | } | ||||
4399 | } else { | ||||
4400 | Result = DAG.getNode(Opc, dl, VT, Op0, Op1); | ||||
4401 | } | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4402 | |
4403 | if (Invert) | ||||
4404 | Result = DAG.getNOT(dl, Result, VT); | ||||
4405 | |||||
4406 | return Result; | ||||
4407 | } | ||||
4408 | |||||
Bob Wilson | 5b2b504 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 4409 | /// isNEONModifiedImm - Check if the specified splat value corresponds to a |
4410 | /// valid vector constant for a NEON instruction with a "modified immediate" | ||||
Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4411 | /// operand (e.g., VMOV). If so, return the encoded value. |
Bob Wilson | 5b2b504 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 4412 | static SDValue isNEONModifiedImm(uint64_t SplatBits, uint64_t SplatUndef, |
4413 | unsigned SplatBitSize, SelectionDAG &DAG, | ||||
Owen Anderson | a407692 | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4414 | EVT &VT, bool is128Bits, NEONModImmType type) { |
Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4415 | unsigned OpCmode, Imm; |
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4416 | |
Bob Wilson | f3f7a77 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 4417 | // SplatBitSize is set to the smallest size that splats the vector, so a |
4418 | // zero vector will always have SplatBitSize == 8. However, NEON modified | ||||
4419 | // immediate instructions others than VMOV do not support the 8-bit encoding | ||||
4420 | // of a zero vector, and the default encoding of zero is supposed to be the | ||||
4421 | // 32-bit version. | ||||
4422 | if (SplatBits == 0) | ||||
4423 | SplatBitSize = 32; | ||||
4424 | |||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4425 | switch (SplatBitSize) { |
4426 | case 8: | ||||
Owen Anderson | a407692 | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4427 | if (type != VMOVModImm) |
Bob Wilson | bad47f6 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4428 | return SDValue(); |
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4429 | // Any 1-byte value is OK. Op=0, Cmode=1110. |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4430 | assert((SplatBits & ~0xff) == 0 && "one byte splat value is too big"); |
Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4431 | OpCmode = 0xe; |
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4432 | Imm = SplatBits; |
Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4433 | VT = is128Bits ? MVT::v16i8 : MVT::v8i8; |
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4434 | break; |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4435 | |
4436 | case 16: | ||||
4437 | // NEON's 16-bit VMOV supports splat values where only one byte is nonzero. | ||||
Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4438 | VT = is128Bits ? MVT::v8i16 : MVT::v4i16; |
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4439 | if ((SplatBits & ~0xff) == 0) { |
4440 | // Value = 0x00nn: Op=x, Cmode=100x. | ||||
Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4441 | OpCmode = 0x8; |
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4442 | Imm = SplatBits; |
4443 | break; | ||||
4444 | } | ||||
4445 | if ((SplatBits & ~0xff00) == 0) { | ||||
4446 | // Value = 0xnn00: Op=x, Cmode=101x. | ||||
Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4447 | OpCmode = 0xa; |
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4448 | Imm = SplatBits >> 8; |
4449 | break; | ||||
4450 | } | ||||
4451 | return SDValue(); | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4452 | |
4453 | case 32: | ||||
4454 | // NEON's 32-bit VMOV supports splat values where: | ||||
4455 | // * only one byte is nonzero, or | ||||
4456 | // * the least significant byte is 0xff and the second byte is nonzero, or | ||||
4457 | // * the least significant 2 bytes are 0xff and the third is nonzero. | ||||
Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4458 | VT = is128Bits ? MVT::v4i32 : MVT::v2i32; |
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4459 | if ((SplatBits & ~0xff) == 0) { |
4460 | // Value = 0x000000nn: Op=x, Cmode=000x. | ||||
Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4461 | OpCmode = 0; |
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4462 | Imm = SplatBits; |
4463 | break; | ||||
4464 | } | ||||
4465 | if ((SplatBits & ~0xff00) == 0) { | ||||
4466 | // Value = 0x0000nn00: Op=x, Cmode=001x. | ||||
Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4467 | OpCmode = 0x2; |
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4468 | Imm = SplatBits >> 8; |
4469 | break; | ||||
4470 | } | ||||
4471 | if ((SplatBits & ~0xff0000) == 0) { | ||||
4472 | // Value = 0x00nn0000: Op=x, Cmode=010x. | ||||
Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4473 | OpCmode = 0x4; |
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4474 | Imm = SplatBits >> 16; |
4475 | break; | ||||
4476 | } | ||||
4477 | if ((SplatBits & ~0xff000000) == 0) { | ||||
4478 | // Value = 0xnn000000: Op=x, Cmode=011x. | ||||
Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4479 | OpCmode = 0x6; |
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4480 | Imm = SplatBits >> 24; |
4481 | break; | ||||
4482 | } | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4483 | |
Owen Anderson | a407692 | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4484 | // cmode == 0b1100 and cmode == 0b1101 are not supported for VORR or VBIC |
4485 | if (type == OtherModImm) return SDValue(); | ||||
4486 | |||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4487 | if ((SplatBits & ~0xffff) == 0 && |
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4488 | ((SplatBits | SplatUndef) & 0xff) == 0xff) { |
4489 | // Value = 0x0000nnff: Op=x, Cmode=1100. | ||||
Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4490 | OpCmode = 0xc; |
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4491 | Imm = SplatBits >> 8; |
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4492 | break; |
4493 | } | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4494 | |
4495 | if ((SplatBits & ~0xffffff) == 0 && | ||||
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4496 | ((SplatBits | SplatUndef) & 0xffff) == 0xffff) { |
4497 | // Value = 0x00nnffff: Op=x, Cmode=1101. | ||||
Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4498 | OpCmode = 0xd; |
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4499 | Imm = SplatBits >> 16; |
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4500 | break; |
4501 | } | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4502 | |
4503 | // Note: there are a few 32-bit splat values (specifically: 00ffff00, | ||||
4504 | // ff000000, ff0000ff, and ffff00ff) that are valid for VMOV.I64 but not | ||||
4505 | // VMOV.I32. A (very) minor optimization would be to replicate the value | ||||
4506 | // and fall through here to test for a valid 64-bit splat. But, then the | ||||
4507 | // caller would also need to check and handle the change in size. | ||||
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4508 | return SDValue(); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4509 | |
4510 | case 64: { | ||||
Owen Anderson | a407692 | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4511 | if (type != VMOVModImm) |
Bob Wilson | f3f7a77 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 4512 | return SDValue(); |
Bob Wilson | bad47f6 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4513 | // NEON has a 64-bit VMOV splat where each byte is either 0 or 0xff. |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4514 | uint64_t BitMask = 0xff; |
4515 | uint64_t Val = 0; | ||||
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4516 | unsigned ImmMask = 1; |
4517 | Imm = 0; | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4518 | for (int ByteNum = 0; ByteNum < 8; ++ByteNum) { |
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4519 | if (((SplatBits | SplatUndef) & BitMask) == BitMask) { |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4520 | Val |= BitMask; |
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4521 | Imm |= ImmMask; |
4522 | } else if ((SplatBits & BitMask) != 0) { | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4523 | return SDValue(); |
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4524 | } |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4525 | BitMask <<= 8; |
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4526 | ImmMask <<= 1; |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4527 | } |
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4528 | // Op=1, Cmode=1110. |
Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4529 | OpCmode = 0x1e; |
Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4530 | VT = is128Bits ? MVT::v2i64 : MVT::v1i64; |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4531 | break; |
4532 | } | ||||
4533 | |||||
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4534 | default: |
Bob Wilson | 0ae0893 | 2010-06-19 05:32:09 +0000 | [diff] [blame] | 4535 | llvm_unreachable("unexpected size for isNEONModifiedImm"); |
Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4536 | } |
4537 | |||||
Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4538 | unsigned EncodedVal = ARM_AM::createNEONModImm(OpCmode, Imm); |
4539 | return DAG.getTargetConstant(EncodedVal, MVT::i32); | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4540 | } |
4541 | |||||
Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4542 | SDValue ARMTargetLowering::LowerConstantFP(SDValue Op, SelectionDAG &DAG, |
4543 | const ARMSubtarget *ST) const { | ||||
Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 4544 | if (!ST->hasVFP3()) |
Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4545 | return SDValue(); |
4546 | |||||
Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 4547 | bool IsDouble = Op.getValueType() == MVT::f64; |
Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4548 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Op); |
Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4549 | |
4550 | // Try splatting with a VMOV.f32... | ||||
4551 | APFloat FPVal = CFP->getValueAPF(); | ||||
Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 4552 | int ImmVal = IsDouble ? ARM_AM::getFP64Imm(FPVal) : ARM_AM::getFP32Imm(FPVal); |
4553 | |||||
Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4554 | if (ImmVal != -1) { |
Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 4555 | if (IsDouble || !ST->useNEONForSinglePrecisionFP()) { |
4556 | // We have code in place to select a valid ConstantFP already, no need to | ||||
4557 | // do any mangling. | ||||
4558 | return Op; | ||||
4559 | } | ||||
4560 | |||||
4561 | // It's a float and we are trying to use NEON operations where | ||||
4562 | // possible. Lower it to a splat followed by an extract. | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4563 | SDLoc DL(Op); |
Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4564 | SDValue NewVal = DAG.getTargetConstant(ImmVal, MVT::i32); |
4565 | SDValue VecConstant = DAG.getNode(ARMISD::VMOVFPIMM, DL, MVT::v2f32, | ||||
4566 | NewVal); | ||||
4567 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, VecConstant, | ||||
4568 | DAG.getConstant(0, MVT::i32)); | ||||
4569 | } | ||||
4570 | |||||
Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 4571 | // The rest of our options are NEON only, make sure that's allowed before |
4572 | // proceeding.. | ||||
4573 | if (!ST->hasNEON() || (!IsDouble && !ST->useNEONForSinglePrecisionFP())) | ||||
4574 | return SDValue(); | ||||
4575 | |||||
Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4576 | EVT VMovVT; |
Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 4577 | uint64_t iVal = FPVal.bitcastToAPInt().getZExtValue(); |
4578 | |||||
4579 | // It wouldn't really be worth bothering for doubles except for one very | ||||
4580 | // important value, which does happen to match: 0.0. So make sure we don't do | ||||
4581 | // anything stupid. | ||||
4582 | if (IsDouble && (iVal & 0xffffffff) != (iVal >> 32)) | ||||
4583 | return SDValue(); | ||||
4584 | |||||
4585 | // Try a VMOV.i32 (FIXME: i8, i16, or i64 could work too). | ||||
4586 | SDValue NewVal = isNEONModifiedImm(iVal & 0xffffffffU, 0, 32, DAG, VMovVT, | ||||
4587 | false, VMOVModImm); | ||||
Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4588 | if (NewVal != SDValue()) { |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4589 | SDLoc DL(Op); |
Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4590 | SDValue VecConstant = DAG.getNode(ARMISD::VMOVIMM, DL, VMovVT, |
4591 | NewVal); | ||||
Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 4592 | if (IsDouble) |
4593 | return DAG.getNode(ISD::BITCAST, DL, MVT::f64, VecConstant); | ||||
4594 | |||||
4595 | // It's a float: cast and extract a vector element. | ||||
Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4596 | SDValue VecFConstant = DAG.getNode(ISD::BITCAST, DL, MVT::v2f32, |
4597 | VecConstant); | ||||
4598 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, VecFConstant, | ||||
4599 | DAG.getConstant(0, MVT::i32)); | ||||
4600 | } | ||||
4601 | |||||
4602 | // Finally, try a VMVN.i32 | ||||
Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 4603 | NewVal = isNEONModifiedImm(~iVal & 0xffffffffU, 0, 32, DAG, VMovVT, |
4604 | false, VMVNModImm); | ||||
Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4605 | if (NewVal != SDValue()) { |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4606 | SDLoc DL(Op); |
Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4607 | SDValue VecConstant = DAG.getNode(ARMISD::VMVNIMM, DL, VMovVT, NewVal); |
Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 4608 | |
4609 | if (IsDouble) | ||||
4610 | return DAG.getNode(ISD::BITCAST, DL, MVT::f64, VecConstant); | ||||
4611 | |||||
4612 | // It's a float: cast and extract a vector element. | ||||
Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4613 | SDValue VecFConstant = DAG.getNode(ISD::BITCAST, DL, MVT::v2f32, |
4614 | VecConstant); | ||||
4615 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, VecFConstant, | ||||
4616 | DAG.getConstant(0, MVT::i32)); | ||||
4617 | } | ||||
4618 | |||||
4619 | return SDValue(); | ||||
4620 | } | ||||
4621 | |||||
Quentin Colombet | 8e1fe84 | 2012-11-02 21:32:17 +0000 | [diff] [blame] | 4622 | // check if an VEXT instruction can handle the shuffle mask when the |
4623 | // vector sources of the shuffle are the same. | ||||
4624 | static bool isSingletonVEXTMask(ArrayRef<int> M, EVT VT, unsigned &Imm) { | ||||
4625 | unsigned NumElts = VT.getVectorNumElements(); | ||||
4626 | |||||
4627 | // Assume that the first shuffle index is not UNDEF. Fail if it is. | ||||
4628 | if (M[0] < 0) | ||||
4629 | return false; | ||||
4630 | |||||
4631 | Imm = M[0]; | ||||
4632 | |||||
4633 | // If this is a VEXT shuffle, the immediate value is the index of the first | ||||
4634 | // element. The other shuffle indices must be the successive elements after | ||||
4635 | // the first one. | ||||
4636 | unsigned ExpectedElt = Imm; | ||||
4637 | for (unsigned i = 1; i < NumElts; ++i) { | ||||
4638 | // Increment the expected index. If it wraps around, just follow it | ||||
4639 | // back to index zero and keep going. | ||||
4640 | ++ExpectedElt; | ||||
4641 | if (ExpectedElt == NumElts) | ||||
4642 | ExpectedElt = 0; | ||||
4643 | |||||
4644 | if (M[i] < 0) continue; // ignore UNDEF indices | ||||
4645 | if (ExpectedElt != static_cast<unsigned>(M[i])) | ||||
4646 | return false; | ||||
4647 | } | ||||
4648 | |||||
4649 | return true; | ||||
4650 | } | ||||
4651 | |||||
Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4652 | |
Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4653 | static bool isVEXTMask(ArrayRef<int> M, EVT VT, |
Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4654 | bool &ReverseVEXT, unsigned &Imm) { |
Bob Wilson | 32cd855 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4655 | unsigned NumElts = VT.getVectorNumElements(); |
4656 | ReverseVEXT = false; | ||||
Bob Wilson | 411dfad | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4657 | |
4658 | // Assume that the first shuffle index is not UNDEF. Fail if it is. | ||||
4659 | if (M[0] < 0) | ||||
4660 | return false; | ||||
4661 | |||||
Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4662 | Imm = M[0]; |
Bob Wilson | 32cd855 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4663 | |
4664 | // If this is a VEXT shuffle, the immediate value is the index of the first | ||||
4665 | // element. The other shuffle indices must be the successive elements after | ||||
4666 | // the first one. | ||||
4667 | unsigned ExpectedElt = Imm; | ||||
4668 | for (unsigned i = 1; i < NumElts; ++i) { | ||||
Bob Wilson | 32cd855 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4669 | // Increment the expected index. If it wraps around, it may still be |
4670 | // a VEXT but the source vectors must be swapped. | ||||
4671 | ExpectedElt += 1; | ||||
4672 | if (ExpectedElt == NumElts * 2) { | ||||
4673 | ExpectedElt = 0; | ||||
4674 | ReverseVEXT = true; | ||||
4675 | } | ||||
4676 | |||||
Bob Wilson | 411dfad | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4677 | if (M[i] < 0) continue; // ignore UNDEF indices |
Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4678 | if (ExpectedElt != static_cast<unsigned>(M[i])) |
Bob Wilson | 32cd855 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4679 | return false; |
4680 | } | ||||
4681 | |||||
4682 | // Adjust the index value if the source operands will be swapped. | ||||
4683 | if (ReverseVEXT) | ||||
4684 | Imm -= NumElts; | ||||
4685 | |||||
Bob Wilson | 32cd855 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4686 | return true; |
4687 | } | ||||
4688 | |||||
Bob Wilson | 8a37bbe | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 4689 | /// isVREVMask - Check if a vector shuffle corresponds to a VREV |
4690 | /// instruction with the specified blocksize. (The order of the elements | ||||
4691 | /// within each block of the vector is reversed.) | ||||
Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4692 | static bool isVREVMask(ArrayRef<int> M, EVT VT, unsigned BlockSize) { |
Bob Wilson | 8a37bbe | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 4693 | assert((BlockSize==16 || BlockSize==32 || BlockSize==64) && |
4694 | "Only possible block sizes for VREV are: 16, 32, 64"); | ||||
4695 | |||||
Bob Wilson | 8a37bbe | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 4696 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
Bob Wilson | 854530a | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 4697 | if (EltSz == 64) |
4698 | return false; | ||||
4699 | |||||
4700 | unsigned NumElts = VT.getVectorNumElements(); | ||||
Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4701 | unsigned BlockElts = M[0] + 1; |
Bob Wilson | 411dfad | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4702 | // If the first shuffle index is UNDEF, be optimistic. |
4703 | if (M[0] < 0) | ||||
4704 | BlockElts = BlockSize / EltSz; | ||||
Bob Wilson | 8a37bbe | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 4705 | |
4706 | if (BlockSize <= EltSz || BlockSize != BlockElts * EltSz) | ||||
4707 | return false; | ||||
4708 | |||||
4709 | for (unsigned i = 0; i < NumElts; ++i) { | ||||
Bob Wilson | 411dfad | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4710 | if (M[i] < 0) continue; // ignore UNDEF indices |
4711 | if ((unsigned) M[i] != (i - i%BlockElts) + (BlockElts - 1 - i%BlockElts)) | ||||
Bob Wilson | 8a37bbe | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 4712 | return false; |
4713 | } | ||||
4714 | |||||
4715 | return true; | ||||
4716 | } | ||||
4717 | |||||
Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4718 | static bool isVTBLMask(ArrayRef<int> M, EVT VT) { |
Bill Wendling | 865f8b5 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 4719 | // We can handle <8 x i8> vector shuffles. If the index in the mask is out of |
4720 | // range, then 0 is placed into the resulting vector. So pretty much any mask | ||||
4721 | // of 8 elements can work here. | ||||
4722 | return VT == MVT::v8i8 && M.size() == 8; | ||||
4723 | } | ||||
4724 | |||||
Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4725 | static bool isVTRNMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
Bob Wilson | 854530a | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 4726 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
4727 | if (EltSz == 64) | ||||
4728 | return false; | ||||
4729 | |||||
Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4730 | unsigned NumElts = VT.getVectorNumElements(); |
4731 | WhichResult = (M[0] == 0 ? 0 : 1); | ||||
4732 | for (unsigned i = 0; i < NumElts; i += 2) { | ||||
Bob Wilson | 411dfad | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4733 | if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) || |
4734 | (M[i+1] >= 0 && (unsigned) M[i+1] != i + NumElts + WhichResult)) | ||||
Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4735 | return false; |
4736 | } | ||||
4737 | return true; | ||||
4738 | } | ||||
4739 | |||||
Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4740 | /// isVTRN_v_undef_Mask - Special case of isVTRNMask for canonical form of |
4741 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". | ||||
4742 | /// Mask is e.g., <0, 0, 2, 2> instead of <0, 4, 2, 6>. | ||||
Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4743 | static bool isVTRN_v_undef_Mask(ArrayRef<int> M, EVT VT, unsigned &WhichResult){ |
Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4744 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
4745 | if (EltSz == 64) | ||||
4746 | return false; | ||||
4747 | |||||
4748 | unsigned NumElts = VT.getVectorNumElements(); | ||||
4749 | WhichResult = (M[0] == 0 ? 0 : 1); | ||||
4750 | for (unsigned i = 0; i < NumElts; i += 2) { | ||||
Bob Wilson | 411dfad | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4751 | if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) || |
4752 | (M[i+1] >= 0 && (unsigned) M[i+1] != i + WhichResult)) | ||||
Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4753 | return false; |
4754 | } | ||||
4755 | return true; | ||||
4756 | } | ||||
4757 | |||||
Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4758 | static bool isVUZPMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
Bob Wilson | 854530a | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 4759 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
4760 | if (EltSz == 64) | ||||
4761 | return false; | ||||
4762 | |||||
Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4763 | unsigned NumElts = VT.getVectorNumElements(); |
4764 | WhichResult = (M[0] == 0 ? 0 : 1); | ||||
4765 | for (unsigned i = 0; i != NumElts; ++i) { | ||||
Bob Wilson | 411dfad | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4766 | if (M[i] < 0) continue; // ignore UNDEF indices |
Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4767 | if ((unsigned) M[i] != 2 * i + WhichResult) |
4768 | return false; | ||||
4769 | } | ||||
4770 | |||||
4771 | // VUZP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. | ||||
Bob Wilson | 854530a | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 4772 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4773 | return false; |
4774 | |||||
4775 | return true; | ||||
4776 | } | ||||
4777 | |||||
Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4778 | /// isVUZP_v_undef_Mask - Special case of isVUZPMask for canonical form of |
4779 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". | ||||
4780 | /// Mask is e.g., <0, 2, 0, 2> instead of <0, 2, 4, 6>, | ||||
Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4781 | static bool isVUZP_v_undef_Mask(ArrayRef<int> M, EVT VT, unsigned &WhichResult){ |
Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4782 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
4783 | if (EltSz == 64) | ||||
4784 | return false; | ||||
4785 | |||||
4786 | unsigned Half = VT.getVectorNumElements() / 2; | ||||
4787 | WhichResult = (M[0] == 0 ? 0 : 1); | ||||
4788 | for (unsigned j = 0; j != 2; ++j) { | ||||
4789 | unsigned Idx = WhichResult; | ||||
4790 | for (unsigned i = 0; i != Half; ++i) { | ||||
Bob Wilson | 411dfad | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4791 | int MIdx = M[i + j * Half]; |
4792 | if (MIdx >= 0 && (unsigned) MIdx != Idx) | ||||
Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4793 | return false; |
4794 | Idx += 2; | ||||
4795 | } | ||||
4796 | } | ||||
4797 | |||||
4798 | // VUZP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. | ||||
4799 | if (VT.is64BitVector() && EltSz == 32) | ||||
4800 | return false; | ||||
4801 | |||||
4802 | return true; | ||||
4803 | } | ||||
4804 | |||||
Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4805 | static bool isVZIPMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
Bob Wilson | 854530a | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 4806 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
4807 | if (EltSz == 64) | ||||
4808 | return false; | ||||
4809 | |||||
Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4810 | unsigned NumElts = VT.getVectorNumElements(); |
4811 | WhichResult = (M[0] == 0 ? 0 : 1); | ||||
4812 | unsigned Idx = WhichResult * NumElts / 2; | ||||
4813 | for (unsigned i = 0; i != NumElts; i += 2) { | ||||
Bob Wilson | 411dfad | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4814 | if ((M[i] >= 0 && (unsigned) M[i] != Idx) || |
4815 | (M[i+1] >= 0 && (unsigned) M[i+1] != Idx + NumElts)) | ||||
Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4816 | return false; |
4817 | Idx += 1; | ||||
4818 | } | ||||
4819 | |||||
4820 | // VZIP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. | ||||
Bob Wilson | 854530a | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 4821 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4822 | return false; |
4823 | |||||
4824 | return true; | ||||
4825 | } | ||||
4826 | |||||
Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4827 | /// isVZIP_v_undef_Mask - Special case of isVZIPMask for canonical form of |
4828 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". | ||||
4829 | /// Mask is e.g., <0, 0, 1, 1> instead of <0, 4, 1, 5>. | ||||
Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4830 | static bool isVZIP_v_undef_Mask(ArrayRef<int> M, EVT VT, unsigned &WhichResult){ |
Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4831 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
4832 | if (EltSz == 64) | ||||
4833 | return false; | ||||
4834 | |||||
4835 | unsigned NumElts = VT.getVectorNumElements(); | ||||
4836 | WhichResult = (M[0] == 0 ? 0 : 1); | ||||
4837 | unsigned Idx = WhichResult * NumElts / 2; | ||||
4838 | for (unsigned i = 0; i != NumElts; i += 2) { | ||||
Bob Wilson | 411dfad | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4839 | if ((M[i] >= 0 && (unsigned) M[i] != Idx) || |
4840 | (M[i+1] >= 0 && (unsigned) M[i+1] != Idx)) | ||||
Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4841 | return false; |
4842 | Idx += 1; | ||||
4843 | } | ||||
4844 | |||||
4845 | // VZIP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. | ||||
4846 | if (VT.is64BitVector() && EltSz == 32) | ||||
4847 | return false; | ||||
4848 | |||||
4849 | return true; | ||||
4850 | } | ||||
4851 | |||||
Arnold Schwaighofer | 1f3d3ca | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 4852 | /// \return true if this is a reverse operation on an vector. |
4853 | static bool isReverseMask(ArrayRef<int> M, EVT VT) { | ||||
4854 | unsigned NumElts = VT.getVectorNumElements(); | ||||
4855 | // Make sure the mask has the right size. | ||||
4856 | if (NumElts != M.size()) | ||||
4857 | return false; | ||||
4858 | |||||
4859 | // Look for <15, ..., 3, -1, 1, 0>. | ||||
4860 | for (unsigned i = 0; i != NumElts; ++i) | ||||
4861 | if (M[i] >= 0 && M[i] != (int) (NumElts - 1 - i)) | ||||
4862 | return false; | ||||
4863 | |||||
4864 | return true; | ||||
4865 | } | ||||
4866 | |||||
Dale Johannesen | 2bff505 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4867 | // If N is an integer constant that can be moved into a register in one |
4868 | // instruction, return an SDValue of such a constant (will become a MOV | ||||
4869 | // instruction). Otherwise return null. | ||||
4870 | static SDValue IsSingleInstrConstant(SDValue N, SelectionDAG &DAG, | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4871 | const ARMSubtarget *ST, SDLoc dl) { |
Dale Johannesen | 2bff505 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4872 | uint64_t Val; |
4873 | if (!isa<ConstantSDNode>(N)) | ||||
4874 | return SDValue(); | ||||
4875 | Val = cast<ConstantSDNode>(N)->getZExtValue(); | ||||
4876 | |||||
4877 | if (ST->isThumb1Only()) { | ||||
4878 | if (Val <= 255 || ~Val <= 255) | ||||
4879 | return DAG.getConstant(Val, MVT::i32); | ||||
4880 | } else { | ||||
4881 | if (ARM_AM::getSOImmVal(Val) != -1 || ARM_AM::getSOImmVal(~Val) != -1) | ||||
4882 | return DAG.getConstant(Val, MVT::i32); | ||||
4883 | } | ||||
4884 | return SDValue(); | ||||
4885 | } | ||||
4886 | |||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4887 | // If this is a case we can't handle, return null and let the default |
4888 | // expansion code take care of it. | ||||
Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4889 | SDValue ARMTargetLowering::LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG, |
4890 | const ARMSubtarget *ST) const { | ||||
Bob Wilson | fcd6361 | 2009-08-13 01:57:47 +0000 | [diff] [blame] | 4891 | BuildVectorSDNode *BVN = cast<BuildVectorSDNode>(Op.getNode()); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4892 | SDLoc dl(Op); |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4893 | EVT VT = Op.getValueType(); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4894 | |
4895 | APInt SplatBits, SplatUndef; | ||||
4896 | unsigned SplatBitSize; | ||||
4897 | bool HasAnyUndefs; | ||||
4898 | if (BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { | ||||
Anton Korobeynikov | ece642a | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 4899 | if (SplatBitSize <= 64) { |
Bob Wilson | 5b2b504 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 4900 | // Check if an immediate VMOV works. |
Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4901 | EVT VmovVT; |
Bob Wilson | 5b2b504 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 4902 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4903 | SplatUndef.getZExtValue(), SplatBitSize, |
Owen Anderson | a407692 | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4904 | DAG, VmovVT, VT.is128BitVector(), |
4905 | VMOVModImm); | ||||
Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4906 | if (Val.getNode()) { |
4907 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, Val); | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4908 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4909 | } |
Bob Wilson | bad47f6 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4910 | |
4911 | // Try an immediate VMVN. | ||||
Eli Friedman | aa6ec39 | 2011-10-13 22:40:23 +0000 | [diff] [blame] | 4912 | uint64_t NegatedImm = (~SplatBits).getZExtValue(); |
Bob Wilson | bad47f6 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4913 | Val = isNEONModifiedImm(NegatedImm, |
4914 | SplatUndef.getZExtValue(), SplatBitSize, | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4915 | DAG, VmovVT, VT.is128BitVector(), |
Owen Anderson | a407692 | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4916 | VMVNModImm); |
Bob Wilson | bad47f6 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4917 | if (Val.getNode()) { |
4918 | SDValue Vmov = DAG.getNode(ARMISD::VMVNIMM, dl, VmovVT, Val); | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4919 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | bad47f6 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4920 | } |
Evan Cheng | 7ca4b6e | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 4921 | |
4922 | // Use vmov.f32 to materialize other v2f32 and v4f32 splats. | ||||
Eli Friedman | c9bf1b1 | 2011-12-15 22:56:53 +0000 | [diff] [blame] | 4923 | if ((VT == MVT::v2f32 || VT == MVT::v4f32) && SplatBitSize == 32) { |
Eli Friedman | 4e36a93 | 2011-12-09 23:54:42 +0000 | [diff] [blame] | 4924 | int ImmVal = ARM_AM::getFP32Imm(SplatBits); |
Evan Cheng | 7ca4b6e | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 4925 | if (ImmVal != -1) { |
4926 | SDValue Val = DAG.getTargetConstant(ImmVal, MVT::i32); | ||||
4927 | return DAG.getNode(ARMISD::VMOVFPIMM, dl, VT, Val); | ||||
4928 | } | ||||
4929 | } | ||||
Anton Korobeynikov | ece642a | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 4930 | } |
Bob Wilson | 0dbdec8 | 2009-07-30 00:31:25 +0000 | [diff] [blame] | 4931 | } |
4932 | |||||
Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4933 | // Scan through the operands to see if only one value is used. |
James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4934 | // |
4935 | // As an optimisation, even if more than one value is used it may be more | ||||
4936 | // profitable to splat with one value then change some lanes. | ||||
4937 | // | ||||
4938 | // Heuristically we decide to do this if the vector has a "dominant" value, | ||||
4939 | // defined as splatted to more than half of the lanes. | ||||
Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4940 | unsigned NumElts = VT.getVectorNumElements(); |
4941 | bool isOnlyLowElement = true; | ||||
4942 | bool usesOnlyOneValue = true; | ||||
James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4943 | bool hasDominantValue = false; |
Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4944 | bool isConstant = true; |
James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4945 | |
4946 | // Map of the number of times a particular SDValue appears in the | ||||
4947 | // element list. | ||||
James Molloy | 9d30dc2 | 2012-09-06 10:32:08 +0000 | [diff] [blame] | 4948 | DenseMap<SDValue, unsigned> ValueCounts; |
Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4949 | SDValue Value; |
4950 | for (unsigned i = 0; i < NumElts; ++i) { | ||||
4951 | SDValue V = Op.getOperand(i); | ||||
4952 | if (V.getOpcode() == ISD::UNDEF) | ||||
4953 | continue; | ||||
4954 | if (i > 0) | ||||
4955 | isOnlyLowElement = false; | ||||
4956 | if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V)) | ||||
4957 | isConstant = false; | ||||
4958 | |||||
James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4959 | ValueCounts.insert(std::make_pair(V, 0)); |
James Molloy | 9d30dc2 | 2012-09-06 10:32:08 +0000 | [diff] [blame] | 4960 | unsigned &Count = ValueCounts[V]; |
Jim Grosbach | 54efea0 | 2013-03-02 20:16:15 +0000 | [diff] [blame] | 4961 | |
James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4962 | // Is this value dominant? (takes up more than half of the lanes) |
4963 | if (++Count > (NumElts / 2)) { | ||||
4964 | hasDominantValue = true; | ||||
Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4965 | Value = V; |
James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4966 | } |
Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4967 | } |
James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4968 | if (ValueCounts.size() != 1) |
4969 | usesOnlyOneValue = false; | ||||
4970 | if (!Value.getNode() && ValueCounts.size() > 0) | ||||
4971 | Value = ValueCounts.begin()->first; | ||||
Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4972 | |
James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4973 | if (ValueCounts.size() == 0) |
Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4974 | return DAG.getUNDEF(VT); |
4975 | |||||
Quentin Colombet | 0f2fe74 | 2013-07-23 22:34:47 +0000 | [diff] [blame] | 4976 | // Loads are better lowered with insert_vector_elt/ARMISD::BUILD_VECTOR. |
4977 | // Keep going if we are hitting this case. | ||||
4978 | if (isOnlyLowElement && !ISD::isNormalLoad(Value.getNode())) | ||||
Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4979 | return DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, Value); |
4980 | |||||
Dale Johannesen | 2bff505 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4981 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
4982 | |||||
Dale Johannesen | 710a2d9 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 4983 | // Use VDUP for non-constant splats. For f32 constant splats, reduce to |
4984 | // i32 and try again. | ||||
James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4985 | if (hasDominantValue && EltSize <= 32) { |
4986 | if (!isConstant) { | ||||
4987 | SDValue N; | ||||
4988 | |||||
4989 | // If we are VDUPing a value that comes directly from a vector, that will | ||||
4990 | // cause an unnecessary move to and from a GPR, where instead we could | ||||
Jim Grosbach | a3c5c76 | 2013-03-02 20:16:24 +0000 | [diff] [blame] | 4991 | // just use VDUPLANE. We can only do this if the lane being extracted |
4992 | // is at a constant index, as the VDUP from lane instructions only have | ||||
4993 | // constant-index forms. | ||||
4994 | if (Value->getOpcode() == ISD::EXTRACT_VECTOR_ELT && | ||||
4995 | isa<ConstantSDNode>(Value->getOperand(1))) { | ||||
Silviu Baranga | b140970 | 2012-10-15 09:41:32 +0000 | [diff] [blame] | 4996 | // We need to create a new undef vector to use for the VDUPLANE if the |
4997 | // size of the vector from which we get the value is different than the | ||||
4998 | // size of the vector that we need to create. We will insert the element | ||||
4999 | // such that the register coalescer will remove unnecessary copies. | ||||
5000 | if (VT != Value->getOperand(0).getValueType()) { | ||||
5001 | ConstantSDNode *constIndex; | ||||
5002 | constIndex = dyn_cast<ConstantSDNode>(Value->getOperand(1)); | ||||
5003 | assert(constIndex && "The index is not a constant!"); | ||||
5004 | unsigned index = constIndex->getAPIntValue().getLimitedValue() % | ||||
5005 | VT.getVectorNumElements(); | ||||
5006 | N = DAG.getNode(ARMISD::VDUPLANE, dl, VT, | ||||
5007 | DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VT, DAG.getUNDEF(VT), | ||||
5008 | Value, DAG.getConstant(index, MVT::i32)), | ||||
5009 | DAG.getConstant(index, MVT::i32)); | ||||
Jim Grosbach | c6f1914 | 2013-03-02 20:16:19 +0000 | [diff] [blame] | 5010 | } else |
Silviu Baranga | b140970 | 2012-10-15 09:41:32 +0000 | [diff] [blame] | 5011 | N = DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5012 | Value->getOperand(0), Value->getOperand(1)); |
Jim Grosbach | c6f1914 | 2013-03-02 20:16:19 +0000 | [diff] [blame] | 5013 | } else |
James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5014 | N = DAG.getNode(ARMISD::VDUP, dl, VT, Value); |
5015 | |||||
5016 | if (!usesOnlyOneValue) { | ||||
5017 | // The dominant value was splatted as 'N', but we now have to insert | ||||
5018 | // all differing elements. | ||||
5019 | for (unsigned I = 0; I < NumElts; ++I) { | ||||
5020 | if (Op.getOperand(I) == Value) | ||||
5021 | continue; | ||||
5022 | SmallVector<SDValue, 3> Ops; | ||||
5023 | Ops.push_back(N); | ||||
5024 | Ops.push_back(Op.getOperand(I)); | ||||
5025 | Ops.push_back(DAG.getConstant(I, MVT::i32)); | ||||
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 5026 | N = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VT, Ops); |
James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5027 | } |
5028 | } | ||||
5029 | return N; | ||||
5030 | } | ||||
Dale Johannesen | 710a2d9 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 5031 | if (VT.getVectorElementType().isFloatingPoint()) { |
5032 | SmallVector<SDValue, 8> Ops; | ||||
5033 | for (unsigned i = 0; i < NumElts; ++i) | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5034 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, MVT::i32, |
Dale Johannesen | 710a2d9 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 5035 | Op.getOperand(i))); |
Nate Begeman | ca52411 | 2010-11-10 21:35:41 +0000 | [diff] [blame] | 5036 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), MVT::i32, NumElts); |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 5037 | SDValue Val = DAG.getNode(ISD::BUILD_VECTOR, dl, VecVT, Ops); |
Dale Johannesen | ff37675 | 2010-10-20 22:03:37 +0000 | [diff] [blame] | 5038 | Val = LowerBUILD_VECTOR(Val, DAG, ST); |
5039 | if (Val.getNode()) | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5040 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Dale Johannesen | 2bff505 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 5041 | } |
James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5042 | if (usesOnlyOneValue) { |
5043 | SDValue Val = IsSingleInstrConstant(Value, DAG, ST, dl); | ||||
5044 | if (isConstant && Val.getNode()) | ||||
Jim Grosbach | 54efea0 | 2013-03-02 20:16:15 +0000 | [diff] [blame] | 5045 | return DAG.getNode(ARMISD::VDUP, dl, VT, Val); |
James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5046 | } |
Dale Johannesen | 2bff505 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 5047 | } |
5048 | |||||
5049 | // If all elements are constants and the case above didn't get hit, fall back | ||||
5050 | // to the default expansion, which will generate a load from the constant | ||||
5051 | // pool. | ||||
Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5052 | if (isConstant) |
5053 | return SDValue(); | ||||
5054 | |||||
Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5055 | // Empirical tests suggest this is rarely worth it for vectors of length <= 2. |
5056 | if (NumElts >= 4) { | ||||
5057 | SDValue shuffle = ReconstructShuffle(Op, DAG); | ||||
5058 | if (shuffle != SDValue()) | ||||
5059 | return shuffle; | ||||
5060 | } | ||||
5061 | |||||
Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5062 | // Vectors with 32- or 64-bit elements can be built by directly assigning |
Bob Wilson | d8a9a04 | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 5063 | // the subregisters. Lower it to an ARMISD::BUILD_VECTOR so the operands |
5064 | // will be legalized. | ||||
Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5065 | if (EltSize >= 32) { |
5066 | // Do the expansion with floating-point types, since that is what the VFP | ||||
5067 | // registers are defined to use, and since i64 is not legal. | ||||
5068 | EVT EltVT = EVT::getFloatingPointVT(EltSize); | ||||
5069 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); | ||||
Bob Wilson | d8a9a04 | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 5070 | SmallVector<SDValue, 8> Ops; |
5071 | for (unsigned i = 0; i < NumElts; ++i) | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5072 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, EltVT, Op.getOperand(i))); |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 5073 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, Ops); |
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5074 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5075 | } |
5076 | |||||
Jim Grosbach | 24e102a | 2013-07-08 18:18:52 +0000 | [diff] [blame] | 5077 | // If all else fails, just use a sequence of INSERT_VECTOR_ELT when we |
5078 | // know the default expansion would otherwise fall back on something even | ||||
5079 | // worse. For a vector with one or two non-undef values, that's | ||||
5080 | // scalar_to_vector for the elements followed by a shuffle (provided the | ||||
5081 | // shuffle is valid for the target) and materialization element by element | ||||
5082 | // on the stack followed by a load for everything else. | ||||
5083 | if (!isConstant && !usesOnlyOneValue) { | ||||
5084 | SDValue Vec = DAG.getUNDEF(VT); | ||||
5085 | for (unsigned i = 0 ; i < NumElts; ++i) { | ||||
5086 | SDValue V = Op.getOperand(i); | ||||
5087 | if (V.getOpcode() == ISD::UNDEF) | ||||
5088 | continue; | ||||
5089 | SDValue LaneIdx = DAG.getConstant(i, MVT::i32); | ||||
5090 | Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VT, Vec, V, LaneIdx); | ||||
5091 | } | ||||
5092 | return Vec; | ||||
5093 | } | ||||
5094 | |||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5095 | return SDValue(); |
5096 | } | ||||
5097 | |||||
Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5098 | // Gather data to see if the operation can be modelled as a |
Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5099 | // shuffle in combination with VEXTs. |
Eric Christopher | 2af9551 | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 5100 | SDValue ARMTargetLowering::ReconstructShuffle(SDValue Op, |
5101 | SelectionDAG &DAG) const { | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5102 | SDLoc dl(Op); |
Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5103 | EVT VT = Op.getValueType(); |
5104 | unsigned NumElts = VT.getVectorNumElements(); | ||||
5105 | |||||
5106 | SmallVector<SDValue, 2> SourceVecs; | ||||
5107 | SmallVector<unsigned, 2> MinElts; | ||||
5108 | SmallVector<unsigned, 2> MaxElts; | ||||
Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5109 | |
Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5110 | for (unsigned i = 0; i < NumElts; ++i) { |
5111 | SDValue V = Op.getOperand(i); | ||||
5112 | if (V.getOpcode() == ISD::UNDEF) | ||||
5113 | continue; | ||||
5114 | else if (V.getOpcode() != ISD::EXTRACT_VECTOR_ELT) { | ||||
5115 | // A shuffle can only come from building a vector from various | ||||
5116 | // elements of other vectors. | ||||
5117 | return SDValue(); | ||||
Eli Friedman | 74d1da5 | 2011-10-14 23:58:49 +0000 | [diff] [blame] | 5118 | } else if (V.getOperand(0).getValueType().getVectorElementType() != |
5119 | VT.getVectorElementType()) { | ||||
5120 | // This code doesn't know how to handle shuffles where the vector | ||||
5121 | // element types do not match (this happens because type legalization | ||||
5122 | // promotes the return type of EXTRACT_VECTOR_ELT). | ||||
5123 | // FIXME: It might be appropriate to extend this code to handle | ||||
5124 | // mismatched types. | ||||
5125 | return SDValue(); | ||||
Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5126 | } |
Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5127 | |
Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5128 | // Record this extraction against the appropriate vector if possible... |
5129 | SDValue SourceVec = V.getOperand(0); | ||||
Jim Grosbach | 6df755c | 2012-07-25 17:02:47 +0000 | [diff] [blame] | 5130 | // If the element number isn't a constant, we can't effectively |
5131 | // analyze what's going on. | ||||
5132 | if (!isa<ConstantSDNode>(V.getOperand(1))) | ||||
5133 | return SDValue(); | ||||
Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5134 | unsigned EltNo = cast<ConstantSDNode>(V.getOperand(1))->getZExtValue(); |
5135 | bool FoundSource = false; | ||||
5136 | for (unsigned j = 0; j < SourceVecs.size(); ++j) { | ||||
5137 | if (SourceVecs[j] == SourceVec) { | ||||
5138 | if (MinElts[j] > EltNo) | ||||
5139 | MinElts[j] = EltNo; | ||||
5140 | if (MaxElts[j] < EltNo) | ||||
5141 | MaxElts[j] = EltNo; | ||||
5142 | FoundSource = true; | ||||
5143 | break; | ||||
5144 | } | ||||
5145 | } | ||||
Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5146 | |
Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5147 | // Or record a new source if not... |
5148 | if (!FoundSource) { | ||||
5149 | SourceVecs.push_back(SourceVec); | ||||
5150 | MinElts.push_back(EltNo); | ||||
5151 | MaxElts.push_back(EltNo); | ||||
5152 | } | ||||
5153 | } | ||||
Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5154 | |
Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5155 | // Currently only do something sane when at most two source vectors |
5156 | // involved. | ||||
5157 | if (SourceVecs.size() > 2) | ||||
5158 | return SDValue(); | ||||
5159 | |||||
5160 | SDValue ShuffleSrcs[2] = {DAG.getUNDEF(VT), DAG.getUNDEF(VT) }; | ||||
5161 | int VEXTOffsets[2] = {0, 0}; | ||||
Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5162 | |
Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5163 | // This loop extracts the usage patterns of the source vectors |
5164 | // and prepares appropriate SDValues for a shuffle if possible. | ||||
5165 | for (unsigned i = 0; i < SourceVecs.size(); ++i) { | ||||
5166 | if (SourceVecs[i].getValueType() == VT) { | ||||
5167 | // No VEXT necessary | ||||
5168 | ShuffleSrcs[i] = SourceVecs[i]; | ||||
5169 | VEXTOffsets[i] = 0; | ||||
5170 | continue; | ||||
5171 | } else if (SourceVecs[i].getValueType().getVectorNumElements() < NumElts) { | ||||
5172 | // It probably isn't worth padding out a smaller vector just to | ||||
5173 | // break it down again in a shuffle. | ||||
5174 | return SDValue(); | ||||
5175 | } | ||||
Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5176 | |
Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5177 | // Since only 64-bit and 128-bit vectors are legal on ARM and |
5178 | // we've eliminated the other cases... | ||||
Bob Wilson | 3fa9c06 | 2011-01-07 23:40:46 +0000 | [diff] [blame] | 5179 | assert(SourceVecs[i].getValueType().getVectorNumElements() == 2*NumElts && |
5180 | "unexpected vector sizes in ReconstructShuffle"); | ||||
Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5181 | |
Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5182 | if (MaxElts[i] - MinElts[i] >= NumElts) { |
5183 | // Span too large for a VEXT to cope | ||||
5184 | return SDValue(); | ||||
Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5185 | } |
5186 | |||||
Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5187 | if (MinElts[i] >= NumElts) { |
5188 | // The extraction can just take the second half | ||||
5189 | VEXTOffsets[i] = NumElts; | ||||
Eric Christopher | 2af9551 | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 5190 | ShuffleSrcs[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
5191 | SourceVecs[i], | ||||
Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5192 | DAG.getIntPtrConstant(NumElts)); |
5193 | } else if (MaxElts[i] < NumElts) { | ||||
5194 | // The extraction can just take the first half | ||||
5195 | VEXTOffsets[i] = 0; | ||||
Eric Christopher | 2af9551 | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 5196 | ShuffleSrcs[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
5197 | SourceVecs[i], | ||||
Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5198 | DAG.getIntPtrConstant(0)); |
5199 | } else { | ||||
5200 | // An actual VEXT is needed | ||||
5201 | VEXTOffsets[i] = MinElts[i]; | ||||
Eric Christopher | 2af9551 | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 5202 | SDValue VEXTSrc1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
5203 | SourceVecs[i], | ||||
Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5204 | DAG.getIntPtrConstant(0)); |
Eric Christopher | 2af9551 | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 5205 | SDValue VEXTSrc2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
5206 | SourceVecs[i], | ||||
Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5207 | DAG.getIntPtrConstant(NumElts)); |
5208 | ShuffleSrcs[i] = DAG.getNode(ARMISD::VEXT, dl, VT, VEXTSrc1, VEXTSrc2, | ||||
5209 | DAG.getConstant(VEXTOffsets[i], MVT::i32)); | ||||
5210 | } | ||||
5211 | } | ||||
Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5212 | |
Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5213 | SmallVector<int, 8> Mask; |
Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5214 | |
Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5215 | for (unsigned i = 0; i < NumElts; ++i) { |
5216 | SDValue Entry = Op.getOperand(i); | ||||
5217 | if (Entry.getOpcode() == ISD::UNDEF) { | ||||
5218 | Mask.push_back(-1); | ||||
5219 | continue; | ||||
5220 | } | ||||
Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5221 | |
Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5222 | SDValue ExtractVec = Entry.getOperand(0); |
Eric Christopher | 2af9551 | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 5223 | int ExtractElt = cast<ConstantSDNode>(Op.getOperand(i) |
5224 | .getOperand(1))->getSExtValue(); | ||||
Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5225 | if (ExtractVec == SourceVecs[0]) { |
5226 | Mask.push_back(ExtractElt - VEXTOffsets[0]); | ||||
5227 | } else { | ||||
5228 | Mask.push_back(ExtractElt + NumElts - VEXTOffsets[1]); | ||||
5229 | } | ||||
5230 | } | ||||
Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5231 | |
Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5232 | // Final check before we try to produce nonsense... |
5233 | if (isShuffleMaskLegal(Mask, VT)) | ||||
Eric Christopher | 2af9551 | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 5234 | return DAG.getVectorShuffle(VT, dl, ShuffleSrcs[0], ShuffleSrcs[1], |
5235 | &Mask[0]); | ||||
Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5236 | |
Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5237 | return SDValue(); |
5238 | } | ||||
5239 | |||||
Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 5240 | /// isShuffleMaskLegal - Targets can use this to indicate that they only |
5241 | /// support *some* VECTOR_SHUFFLE operations, those with specific masks. | ||||
5242 | /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values | ||||
5243 | /// are assumed to be legal. | ||||
5244 | bool | ||||
5245 | ARMTargetLowering::isShuffleMaskLegal(const SmallVectorImpl<int> &M, | ||||
5246 | EVT VT) const { | ||||
Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5247 | if (VT.getVectorNumElements() == 4 && |
5248 | (VT.is128BitVector() || VT.is64BitVector())) { | ||||
5249 | unsigned PFIndexes[4]; | ||||
5250 | for (unsigned i = 0; i != 4; ++i) { | ||||
5251 | if (M[i] < 0) | ||||
5252 | PFIndexes[i] = 8; | ||||
5253 | else | ||||
5254 | PFIndexes[i] = M[i]; | ||||
5255 | } | ||||
5256 | |||||
5257 | // Compute the index in the perfect shuffle table. | ||||
5258 | unsigned PFTableIndex = | ||||
5259 | PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3]; | ||||
5260 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; | ||||
5261 | unsigned Cost = (PFEntry >> 30); | ||||
5262 | |||||
5263 | if (Cost <= 4) | ||||
5264 | return true; | ||||
5265 | } | ||||
5266 | |||||
Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 5267 | bool ReverseVEXT; |
Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5268 | unsigned Imm, WhichResult; |
Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 5269 | |
Bob Wilson | 846bd79 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 5270 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
5271 | return (EltSize >= 32 || | ||||
5272 | ShuffleVectorSDNode::isSplatMask(&M[0], VT) || | ||||
Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 5273 | isVREVMask(M, VT, 64) || |
5274 | isVREVMask(M, VT, 32) || | ||||
5275 | isVREVMask(M, VT, 16) || | ||||
Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5276 | isVEXTMask(M, VT, ReverseVEXT, Imm) || |
Bill Wendling | 865f8b5 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 5277 | isVTBLMask(M, VT) || |
Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5278 | isVTRNMask(M, VT, WhichResult) || |
5279 | isVUZPMask(M, VT, WhichResult) || | ||||
Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 5280 | isVZIPMask(M, VT, WhichResult) || |
5281 | isVTRN_v_undef_Mask(M, VT, WhichResult) || | ||||
5282 | isVUZP_v_undef_Mask(M, VT, WhichResult) || | ||||
Arnold Schwaighofer | 1f3d3ca | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 5283 | isVZIP_v_undef_Mask(M, VT, WhichResult) || |
5284 | ((VT == MVT::v8i16 || VT == MVT::v16i8) && isReverseMask(M, VT))); | ||||
Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 5285 | } |
5286 | |||||
Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5287 | /// GeneratePerfectShuffle - Given an entry in the perfect-shuffle table, emit |
5288 | /// the specified operations to build the shuffle. | ||||
5289 | static SDValue GeneratePerfectShuffle(unsigned PFEntry, SDValue LHS, | ||||
5290 | SDValue RHS, SelectionDAG &DAG, | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5291 | SDLoc dl) { |
Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5292 | unsigned OpNum = (PFEntry >> 26) & 0x0F; |
5293 | unsigned LHSID = (PFEntry >> 13) & ((1 << 13)-1); | ||||
5294 | unsigned RHSID = (PFEntry >> 0) & ((1 << 13)-1); | ||||
5295 | |||||
5296 | enum { | ||||
5297 | OP_COPY = 0, // Copy, used for things like <u,u,u,3> to say it is <0,1,2,3> | ||||
5298 | OP_VREV, | ||||
5299 | OP_VDUP0, | ||||
5300 | OP_VDUP1, | ||||
5301 | OP_VDUP2, | ||||
5302 | OP_VDUP3, | ||||
5303 | OP_VEXT1, | ||||
5304 | OP_VEXT2, | ||||
5305 | OP_VEXT3, | ||||
5306 | OP_VUZPL, // VUZP, left result | ||||
5307 | OP_VUZPR, // VUZP, right result | ||||
5308 | OP_VZIPL, // VZIP, left result | ||||
5309 | OP_VZIPR, // VZIP, right result | ||||
5310 | OP_VTRNL, // VTRN, left result | ||||
5311 | OP_VTRNR // VTRN, right result | ||||
5312 | }; | ||||
5313 | |||||
5314 | if (OpNum == OP_COPY) { | ||||
5315 | if (LHSID == (1*9+2)*9+3) return LHS; | ||||
5316 | assert(LHSID == ((4*9+5)*9+6)*9+7 && "Illegal OP_COPY!"); | ||||
5317 | return RHS; | ||||
5318 | } | ||||
5319 | |||||
5320 | SDValue OpLHS, OpRHS; | ||||
5321 | OpLHS = GeneratePerfectShuffle(PerfectShuffleTable[LHSID], LHS, RHS, DAG, dl); | ||||
5322 | OpRHS = GeneratePerfectShuffle(PerfectShuffleTable[RHSID], LHS, RHS, DAG, dl); | ||||
5323 | EVT VT = OpLHS.getValueType(); | ||||
5324 | |||||
5325 | switch (OpNum) { | ||||
5326 | default: llvm_unreachable("Unknown shuffle opcode!"); | ||||
5327 | case OP_VREV: | ||||
Tanya Lattner | 48b182c | 2011-05-18 06:42:21 +0000 | [diff] [blame] | 5328 | // VREV divides the vector in half and swaps within the half. |
Tanya Lattner | 1d11720 | 2011-05-18 21:44:54 +0000 | [diff] [blame] | 5329 | if (VT.getVectorElementType() == MVT::i32 || |
5330 | VT.getVectorElementType() == MVT::f32) | ||||
Tanya Lattner | 48b182c | 2011-05-18 06:42:21 +0000 | [diff] [blame] | 5331 | return DAG.getNode(ARMISD::VREV64, dl, VT, OpLHS); |
5332 | // vrev <4 x i16> -> VREV32 | ||||
5333 | if (VT.getVectorElementType() == MVT::i16) | ||||
5334 | return DAG.getNode(ARMISD::VREV32, dl, VT, OpLHS); | ||||
5335 | // vrev <4 x i8> -> VREV16 | ||||
5336 | assert(VT.getVectorElementType() == MVT::i8); | ||||
5337 | return DAG.getNode(ARMISD::VREV16, dl, VT, OpLHS); | ||||
Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5338 | case OP_VDUP0: |
5339 | case OP_VDUP1: | ||||
5340 | case OP_VDUP2: | ||||
5341 | case OP_VDUP3: | ||||
5342 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, | ||||
Anton Korobeynikov | 232b19c | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 5343 | OpLHS, DAG.getConstant(OpNum-OP_VDUP0, MVT::i32)); |
Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5344 | case OP_VEXT1: |
5345 | case OP_VEXT2: | ||||
5346 | case OP_VEXT3: | ||||
5347 | return DAG.getNode(ARMISD::VEXT, dl, VT, | ||||
5348 | OpLHS, OpRHS, | ||||
5349 | DAG.getConstant(OpNum-OP_VEXT1+1, MVT::i32)); | ||||
5350 | case OP_VUZPL: | ||||
5351 | case OP_VUZPR: | ||||
Anton Korobeynikov | 232b19c | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 5352 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5353 | OpLHS, OpRHS).getValue(OpNum-OP_VUZPL); |
5354 | case OP_VZIPL: | ||||
5355 | case OP_VZIPR: | ||||
Anton Korobeynikov | 232b19c | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 5356 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5357 | OpLHS, OpRHS).getValue(OpNum-OP_VZIPL); |
5358 | case OP_VTRNL: | ||||
5359 | case OP_VTRNR: | ||||
Anton Korobeynikov | 232b19c | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 5360 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
5361 | OpLHS, OpRHS).getValue(OpNum-OP_VTRNL); | ||||
Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5362 | } |
5363 | } | ||||
5364 | |||||
Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 5365 | static SDValue LowerVECTOR_SHUFFLEv8i8(SDValue Op, |
Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 5366 | ArrayRef<int> ShuffleMask, |
Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 5367 | SelectionDAG &DAG) { |
5368 | // Check to see if we can use the VTBL instruction. | ||||
5369 | SDValue V1 = Op.getOperand(0); | ||||
5370 | SDValue V2 = Op.getOperand(1); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5371 | SDLoc DL(Op); |
Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 5372 | |
5373 | SmallVector<SDValue, 8> VTBLMask; | ||||
Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 5374 | for (ArrayRef<int>::iterator |
Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 5375 | I = ShuffleMask.begin(), E = ShuffleMask.end(); I != E; ++I) |
5376 | VTBLMask.push_back(DAG.getConstant(*I, MVT::i32)); | ||||
5377 | |||||
5378 | if (V2.getNode()->getOpcode() == ISD::UNDEF) | ||||
5379 | return DAG.getNode(ARMISD::VTBL1, DL, MVT::v8i8, V1, | ||||
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 5380 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, VTBLMask)); |
Bill Wendling | ebecb33 | 2011-03-15 20:47:26 +0000 | [diff] [blame] | 5381 | |
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5382 | return DAG.getNode(ARMISD::VTBL2, DL, MVT::v8i8, V1, V2, |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 5383 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, VTBLMask)); |
Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 5384 | } |
5385 | |||||
Arnold Schwaighofer | 1f3d3ca | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 5386 | static SDValue LowerReverse_VECTOR_SHUFFLEv16i8_v8i16(SDValue Op, |
5387 | SelectionDAG &DAG) { | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5388 | SDLoc DL(Op); |
Arnold Schwaighofer | 1f3d3ca | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 5389 | SDValue OpLHS = Op.getOperand(0); |
5390 | EVT VT = OpLHS.getValueType(); | ||||
5391 | |||||
5392 | assert((VT == MVT::v8i16 || VT == MVT::v16i8) && | ||||
5393 | "Expect an v8i16/v16i8 type"); | ||||
5394 | OpLHS = DAG.getNode(ARMISD::VREV64, DL, VT, OpLHS); | ||||
5395 | // For a v16i8 type: After the VREV, we have got <8, ...15, 8, ..., 0>. Now, | ||||
5396 | // extract the first 8 bytes into the top double word and the last 8 bytes | ||||
5397 | // into the bottom double word. The v8i16 case is similar. | ||||
5398 | unsigned ExtractNum = (VT == MVT::v16i8) ? 8 : 4; | ||||
5399 | return DAG.getNode(ARMISD::VEXT, DL, VT, OpLHS, OpLHS, | ||||
5400 | DAG.getConstant(ExtractNum, MVT::i32)); | ||||
5401 | } | ||||
5402 | |||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5403 | static SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) { |
Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5404 | SDValue V1 = Op.getOperand(0); |
5405 | SDValue V2 = Op.getOperand(1); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5406 | SDLoc dl(Op); |
Bob Wilson | ea3a402 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 5407 | EVT VT = Op.getValueType(); |
Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5408 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op.getNode()); |
Bob Wilson | ea3a402 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 5409 | |
Bob Wilson | c6800b5 | 2009-08-13 02:13:04 +0000 | [diff] [blame] | 5410 | // Convert shuffles that are directly supported on NEON to target-specific |
5411 | // DAG nodes, instead of keeping them as shuffles and matching them again | ||||
5412 | // during code selection. This is more efficient and avoids the possibility | ||||
5413 | // of inconsistencies between legalization and selection. | ||||
Bob Wilson | 3e4c012 | 2009-08-13 06:01:30 +0000 | [diff] [blame] | 5414 | // FIXME: floating-point vectors should be canonicalized to integer vectors |
5415 | // of the same time so that they get CSEd properly. | ||||
Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 5416 | ArrayRef<int> ShuffleMask = SVN->getMask(); |
Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 5417 | |
Bob Wilson | 846bd79 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 5418 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
5419 | if (EltSize <= 32) { | ||||
5420 | if (ShuffleVectorSDNode::isSplatMask(&ShuffleMask[0], VT)) { | ||||
5421 | int Lane = SVN->getSplatIndex(); | ||||
5422 | // If this is undef splat, generate it via "just" vdup, if possible. | ||||
5423 | if (Lane == -1) Lane = 0; | ||||
Anton Korobeynikov | 4d23754 | 2009-11-02 00:12:06 +0000 | [diff] [blame] | 5424 | |
Dan Gohman | 198b7ff | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 5425 | // Test if V1 is a SCALAR_TO_VECTOR. |
Bob Wilson | 846bd79 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 5426 | if (Lane == 0 && V1.getOpcode() == ISD::SCALAR_TO_VECTOR) { |
5427 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); | ||||
5428 | } | ||||
Dan Gohman | 198b7ff | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 5429 | // Test if V1 is a BUILD_VECTOR which is equivalent to a SCALAR_TO_VECTOR |
5430 | // (and probably will turn into a SCALAR_TO_VECTOR once legalization | ||||
5431 | // reaches it). | ||||
5432 | if (Lane == 0 && V1.getOpcode() == ISD::BUILD_VECTOR && | ||||
5433 | !isa<ConstantSDNode>(V1.getOperand(0))) { | ||||
5434 | bool IsScalarToVector = true; | ||||
5435 | for (unsigned i = 1, e = V1.getNumOperands(); i != e; ++i) | ||||
5436 | if (V1.getOperand(i).getOpcode() != ISD::UNDEF) { | ||||
5437 | IsScalarToVector = false; | ||||
5438 | break; | ||||
5439 | } | ||||
5440 | if (IsScalarToVector) | ||||
5441 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); | ||||
5442 | } | ||||
Bob Wilson | 846bd79 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 5443 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, V1, |
5444 | DAG.getConstant(Lane, MVT::i32)); | ||||
Bob Wilson | eb54d51 | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 5445 | } |
Bob Wilson | 846bd79 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 5446 | |
5447 | bool ReverseVEXT; | ||||
5448 | unsigned Imm; | ||||
5449 | if (isVEXTMask(ShuffleMask, VT, ReverseVEXT, Imm)) { | ||||
5450 | if (ReverseVEXT) | ||||
5451 | std::swap(V1, V2); | ||||
5452 | return DAG.getNode(ARMISD::VEXT, dl, VT, V1, V2, | ||||
5453 | DAG.getConstant(Imm, MVT::i32)); | ||||
5454 | } | ||||
5455 | |||||
5456 | if (isVREVMask(ShuffleMask, VT, 64)) | ||||
5457 | return DAG.getNode(ARMISD::VREV64, dl, VT, V1); | ||||
5458 | if (isVREVMask(ShuffleMask, VT, 32)) | ||||
5459 | return DAG.getNode(ARMISD::VREV32, dl, VT, V1); | ||||
5460 | if (isVREVMask(ShuffleMask, VT, 16)) | ||||
5461 | return DAG.getNode(ARMISD::VREV16, dl, VT, V1); | ||||
5462 | |||||
Quentin Colombet | 8e1fe84 | 2012-11-02 21:32:17 +0000 | [diff] [blame] | 5463 | if (V2->getOpcode() == ISD::UNDEF && |
5464 | isSingletonVEXTMask(ShuffleMask, VT, Imm)) { | ||||
5465 | return DAG.getNode(ARMISD::VEXT, dl, VT, V1, V1, | ||||
5466 | DAG.getConstant(Imm, MVT::i32)); | ||||
5467 | } | ||||
5468 | |||||
Bob Wilson | 846bd79 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 5469 | // Check for Neon shuffles that modify both input vectors in place. |
5470 | // If both results are used, i.e., if there are two shuffles with the same | ||||
5471 | // source operands and with masks corresponding to both results of one of | ||||
5472 | // these operations, DAG memoization will ensure that a single node is | ||||
5473 | // used for both shuffles. | ||||
5474 | unsigned WhichResult; | ||||
5475 | if (isVTRNMask(ShuffleMask, VT, WhichResult)) | ||||
5476 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), | ||||
5477 | V1, V2).getValue(WhichResult); | ||||
5478 | if (isVUZPMask(ShuffleMask, VT, WhichResult)) | ||||
5479 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), | ||||
5480 | V1, V2).getValue(WhichResult); | ||||
5481 | if (isVZIPMask(ShuffleMask, VT, WhichResult)) | ||||
5482 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), | ||||
5483 | V1, V2).getValue(WhichResult); | ||||
5484 | |||||
5485 | if (isVTRN_v_undef_Mask(ShuffleMask, VT, WhichResult)) | ||||
5486 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), | ||||
5487 | V1, V1).getValue(WhichResult); | ||||
5488 | if (isVUZP_v_undef_Mask(ShuffleMask, VT, WhichResult)) | ||||
5489 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), | ||||
5490 | V1, V1).getValue(WhichResult); | ||||
5491 | if (isVZIP_v_undef_Mask(ShuffleMask, VT, WhichResult)) | ||||
5492 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), | ||||
5493 | V1, V1).getValue(WhichResult); | ||||
Bob Wilson | cce31f6 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 5494 | } |
Bob Wilson | 32cd855 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 5495 | |
Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5496 | // If the shuffle is not directly supported and it has 4 elements, use |
5497 | // the PerfectShuffle-generated table to synthesize it from other shuffles. | ||||
Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5498 | unsigned NumElts = VT.getVectorNumElements(); |
5499 | if (NumElts == 4) { | ||||
Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5500 | unsigned PFIndexes[4]; |
5501 | for (unsigned i = 0; i != 4; ++i) { | ||||
5502 | if (ShuffleMask[i] < 0) | ||||
5503 | PFIndexes[i] = 8; | ||||
5504 | else | ||||
5505 | PFIndexes[i] = ShuffleMask[i]; | ||||
5506 | } | ||||
5507 | |||||
5508 | // Compute the index in the perfect shuffle table. | ||||
5509 | unsigned PFTableIndex = | ||||
5510 | PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3]; | ||||
Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5511 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
5512 | unsigned Cost = (PFEntry >> 30); | ||||
5513 | |||||
5514 | if (Cost <= 4) | ||||
5515 | return GeneratePerfectShuffle(PFEntry, V1, V2, DAG, dl); | ||||
5516 | } | ||||
Bob Wilson | ea3a402 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 5517 | |
Bob Wilson | d8a9a04 | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 5518 | // Implement shuffles with 32- or 64-bit elements as ARMISD::BUILD_VECTORs. |
Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5519 | if (EltSize >= 32) { |
5520 | // Do the expansion with floating-point types, since that is what the VFP | ||||
5521 | // registers are defined to use, and since i64 is not legal. | ||||
5522 | EVT EltVT = EVT::getFloatingPointVT(EltSize); | ||||
5523 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5524 | V1 = DAG.getNode(ISD::BITCAST, dl, VecVT, V1); |
5525 | V2 = DAG.getNode(ISD::BITCAST, dl, VecVT, V2); | ||||
Bob Wilson | d8a9a04 | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 5526 | SmallVector<SDValue, 8> Ops; |
Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5527 | for (unsigned i = 0; i < NumElts; ++i) { |
Bob Wilson | 5954994 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 5528 | if (ShuffleMask[i] < 0) |
Bob Wilson | d8a9a04 | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 5529 | Ops.push_back(DAG.getUNDEF(EltVT)); |
5530 | else | ||||
5531 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, | ||||
5532 | ShuffleMask[i] < (int)NumElts ? V1 : V2, | ||||
5533 | DAG.getConstant(ShuffleMask[i] & (NumElts-1), | ||||
5534 | MVT::i32))); | ||||
Bob Wilson | 5954994 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 5535 | } |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 5536 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, Ops); |
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5537 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Bob Wilson | 5954994 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 5538 | } |
5539 | |||||
Arnold Schwaighofer | 1f3d3ca | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 5540 | if ((VT == MVT::v8i16 || VT == MVT::v16i8) && isReverseMask(ShuffleMask, VT)) |
5541 | return LowerReverse_VECTOR_SHUFFLEv16i8_v8i16(Op, DAG); | ||||
5542 | |||||
Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 5543 | if (VT == MVT::v8i8) { |
5544 | SDValue NewOp = LowerVECTOR_SHUFFLEv8i8(Op, ShuffleMask, DAG); | ||||
5545 | if (NewOp.getNode()) | ||||
5546 | return NewOp; | ||||
5547 | } | ||||
5548 | |||||
Bob Wilson | 6f34e27 | 2009-08-14 05:16:33 +0000 | [diff] [blame] | 5549 | return SDValue(); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5550 | } |
5551 | |||||
Eli Friedman | a5e244c | 2011-10-24 23:08:52 +0000 | [diff] [blame] | 5552 | static SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
5553 | // INSERT_VECTOR_ELT is legal only for immediate indexes. | ||||
5554 | SDValue Lane = Op.getOperand(2); | ||||
5555 | if (!isa<ConstantSDNode>(Lane)) | ||||
5556 | return SDValue(); | ||||
5557 | |||||
5558 | return Op; | ||||
5559 | } | ||||
5560 | |||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5561 | static SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
Bob Wilson | ceb4929 | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 5562 | // EXTRACT_VECTOR_ELT is legal only for immediate indexes. |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5563 | SDValue Lane = Op.getOperand(1); |
Bob Wilson | ceb4929 | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 5564 | if (!isa<ConstantSDNode>(Lane)) |
5565 | return SDValue(); | ||||
5566 | |||||
5567 | SDValue Vec = Op.getOperand(0); | ||||
5568 | if (Op.getValueType() == MVT::i32 && | ||||
5569 | Vec.getValueType().getVectorElementType().getSizeInBits() < 32) { | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5570 | SDLoc dl(Op); |
Bob Wilson | ceb4929 | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 5571 | return DAG.getNode(ARMISD::VGETLANEu, dl, MVT::i32, Vec, Lane); |
5572 | } | ||||
5573 | |||||
5574 | return Op; | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5575 | } |
5576 | |||||
Bob Wilson | f307e0b | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 5577 | static SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) { |
5578 | // The only time a CONCAT_VECTORS operation can have legal types is when | ||||
5579 | // two 64-bit vectors are concatenated to a 128-bit vector. | ||||
5580 | assert(Op.getValueType().is128BitVector() && Op.getNumOperands() == 2 && | ||||
5581 | "unexpected CONCAT_VECTORS"); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5582 | SDLoc dl(Op); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5583 | SDValue Val = DAG.getUNDEF(MVT::v2f64); |
Bob Wilson | f307e0b | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 5584 | SDValue Op0 = Op.getOperand(0); |
5585 | SDValue Op1 = Op.getOperand(1); | ||||
5586 | if (Op0.getOpcode() != ISD::UNDEF) | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5587 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5588 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op0), |
Bob Wilson | f307e0b | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 5589 | DAG.getIntPtrConstant(0)); |
5590 | if (Op1.getOpcode() != ISD::UNDEF) | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5591 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5592 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op1), |
Bob Wilson | f307e0b | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 5593 | DAG.getIntPtrConstant(1)); |
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5594 | return DAG.getNode(ISD::BITCAST, dl, Op.getValueType(), Val); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5595 | } |
5596 | |||||
Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 5597 | /// isExtendedBUILD_VECTOR - Check if N is a constant BUILD_VECTOR where each |
5598 | /// element has been zero/sign-extended, depending on the isSigned parameter, | ||||
5599 | /// from an integer type half its size. | ||||
5600 | static bool isExtendedBUILD_VECTOR(SDNode *N, SelectionDAG &DAG, | ||||
5601 | bool isSigned) { | ||||
5602 | // A v2i64 BUILD_VECTOR will have been legalized to a BITCAST from v4i32. | ||||
5603 | EVT VT = N->getValueType(0); | ||||
5604 | if (VT == MVT::v2i64 && N->getOpcode() == ISD::BITCAST) { | ||||
5605 | SDNode *BVN = N->getOperand(0).getNode(); | ||||
5606 | if (BVN->getValueType(0) != MVT::v4i32 || | ||||
5607 | BVN->getOpcode() != ISD::BUILD_VECTOR) | ||||
5608 | return false; | ||||
5609 | unsigned LoElt = DAG.getTargetLoweringInfo().isBigEndian() ? 1 : 0; | ||||
5610 | unsigned HiElt = 1 - LoElt; | ||||
5611 | ConstantSDNode *Lo0 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt)); | ||||
5612 | ConstantSDNode *Hi0 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt)); | ||||
5613 | ConstantSDNode *Lo1 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt+2)); | ||||
5614 | ConstantSDNode *Hi1 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt+2)); | ||||
5615 | if (!Lo0 || !Hi0 || !Lo1 || !Hi1) | ||||
5616 | return false; | ||||
5617 | if (isSigned) { | ||||
5618 | if (Hi0->getSExtValue() == Lo0->getSExtValue() >> 32 && | ||||
5619 | Hi1->getSExtValue() == Lo1->getSExtValue() >> 32) | ||||
5620 | return true; | ||||
5621 | } else { | ||||
5622 | if (Hi0->isNullValue() && Hi1->isNullValue()) | ||||
5623 | return true; | ||||
5624 | } | ||||
5625 | return false; | ||||
5626 | } | ||||
5627 | |||||
5628 | if (N->getOpcode() != ISD::BUILD_VECTOR) | ||||
5629 | return false; | ||||
5630 | |||||
5631 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { | ||||
5632 | SDNode *Elt = N->getOperand(i).getNode(); | ||||
5633 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Elt)) { | ||||
5634 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); | ||||
5635 | unsigned HalfSize = EltSize / 2; | ||||
5636 | if (isSigned) { | ||||
Bob Wilson | 93b0f7b | 2011-10-18 18:46:49 +0000 | [diff] [blame] | 5637 | if (!isIntN(HalfSize, C->getSExtValue())) |
Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 5638 | return false; |
5639 | } else { | ||||
Bob Wilson | 93b0f7b | 2011-10-18 18:46:49 +0000 | [diff] [blame] | 5640 | if (!isUIntN(HalfSize, C->getZExtValue())) |
Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 5641 | return false; |
5642 | } | ||||
5643 | continue; | ||||
5644 | } | ||||
5645 | return false; | ||||
5646 | } | ||||
5647 | |||||
5648 | return true; | ||||
5649 | } | ||||
5650 | |||||
5651 | /// isSignExtended - Check if a node is a vector value that is sign-extended | ||||
5652 | /// or a constant BUILD_VECTOR with sign-extended elements. | ||||
5653 | static bool isSignExtended(SDNode *N, SelectionDAG &DAG) { | ||||
5654 | if (N->getOpcode() == ISD::SIGN_EXTEND || ISD::isSEXTLoad(N)) | ||||
5655 | return true; | ||||
5656 | if (isExtendedBUILD_VECTOR(N, DAG, true)) | ||||
5657 | return true; | ||||
5658 | return false; | ||||
5659 | } | ||||
5660 | |||||
5661 | /// isZeroExtended - Check if a node is a vector value that is zero-extended | ||||
5662 | /// or a constant BUILD_VECTOR with zero-extended elements. | ||||
5663 | static bool isZeroExtended(SDNode *N, SelectionDAG &DAG) { | ||||
5664 | if (N->getOpcode() == ISD::ZERO_EXTEND || ISD::isZEXTLoad(N)) | ||||
5665 | return true; | ||||
5666 | if (isExtendedBUILD_VECTOR(N, DAG, false)) | ||||
5667 | return true; | ||||
5668 | return false; | ||||
5669 | } | ||||
5670 | |||||
Arnold Schwaighofer | af85f60 | 2013-05-14 22:33:24 +0000 | [diff] [blame] | 5671 | static EVT getExtensionTo64Bits(const EVT &OrigVT) { |
5672 | if (OrigVT.getSizeInBits() >= 64) | ||||
5673 | return OrigVT; | ||||
5674 | |||||
5675 | assert(OrigVT.isSimple() && "Expecting a simple value type"); | ||||
5676 | |||||
5677 | MVT::SimpleValueType OrigSimpleTy = OrigVT.getSimpleVT().SimpleTy; | ||||
5678 | switch (OrigSimpleTy) { | ||||
5679 | default: llvm_unreachable("Unexpected Vector Type"); | ||||
5680 | case MVT::v2i8: | ||||
5681 | case MVT::v2i16: | ||||
5682 | return MVT::v2i32; | ||||
5683 | case MVT::v4i8: | ||||
5684 | return MVT::v4i16; | ||||
5685 | } | ||||
5686 | } | ||||
5687 | |||||
Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5688 | /// AddRequiredExtensionForVMULL - Add a sign/zero extension to extend the total |
5689 | /// value size to 64 bits. We need a 64-bit D register as an operand to VMULL. | ||||
5690 | /// We insert the required extension here to get the vector to fill a D register. | ||||
5691 | static SDValue AddRequiredExtensionForVMULL(SDValue N, SelectionDAG &DAG, | ||||
5692 | const EVT &OrigTy, | ||||
5693 | const EVT &ExtTy, | ||||
5694 | unsigned ExtOpcode) { | ||||
5695 | // The vector originally had a size of OrigTy. It was then extended to ExtTy. | ||||
5696 | // We expect the ExtTy to be 128-bits total. If the OrigTy is less than | ||||
5697 | // 64-bits we need to insert a new extension so that it will be 64-bits. | ||||
5698 | assert(ExtTy.is128BitVector() && "Unexpected extension size"); | ||||
5699 | if (OrigTy.getSizeInBits() >= 64) | ||||
5700 | return N; | ||||
5701 | |||||
5702 | // Must extend size to at least 64 bits to be used as an operand for VMULL. | ||||
Arnold Schwaighofer | af85f60 | 2013-05-14 22:33:24 +0000 | [diff] [blame] | 5703 | EVT NewVT = getExtensionTo64Bits(OrigTy); |
5704 | |||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5705 | return DAG.getNode(ExtOpcode, SDLoc(N), NewVT, N); |
Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5706 | } |
5707 | |||||
5708 | /// SkipLoadExtensionForVMULL - return a load of the original vector size that | ||||
5709 | /// does not do any sign/zero extension. If the original vector is less | ||||
5710 | /// than 64 bits, an appropriate extension will be added after the load to | ||||
5711 | /// reach a total size of 64 bits. We have to add the extension separately | ||||
5712 | /// because ARM does not have a sign/zero extending load for vectors. | ||||
5713 | static SDValue SkipLoadExtensionForVMULL(LoadSDNode *LD, SelectionDAG& DAG) { | ||||
Arnold Schwaighofer | af85f60 | 2013-05-14 22:33:24 +0000 | [diff] [blame] | 5714 | EVT ExtendedTy = getExtensionTo64Bits(LD->getMemoryVT()); |
5715 | |||||
5716 | // The load already has the right type. | ||||
5717 | if (ExtendedTy == LD->getMemoryVT()) | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5718 | return DAG.getLoad(LD->getMemoryVT(), SDLoc(LD), LD->getChain(), |
Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5719 | LD->getBasePtr(), LD->getPointerInfo(), LD->isVolatile(), |
5720 | LD->isNonTemporal(), LD->isInvariant(), | ||||
5721 | LD->getAlignment()); | ||||
Arnold Schwaighofer | af85f60 | 2013-05-14 22:33:24 +0000 | [diff] [blame] | 5722 | |
5723 | // We need to create a zextload/sextload. We cannot just create a load | ||||
5724 | // followed by a zext/zext node because LowerMUL is also run during normal | ||||
5725 | // operation legalization where we can't create illegal types. | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5726 | return DAG.getExtLoad(LD->getExtensionType(), SDLoc(LD), ExtendedTy, |
Arnold Schwaighofer | af85f60 | 2013-05-14 22:33:24 +0000 | [diff] [blame] | 5727 | LD->getChain(), LD->getBasePtr(), LD->getPointerInfo(), |
5728 | LD->getMemoryVT(), LD->isVolatile(), | ||||
5729 | LD->isNonTemporal(), LD->getAlignment()); | ||||
Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5730 | } |
5731 | |||||
5732 | /// SkipExtensionForVMULL - For a node that is a SIGN_EXTEND, ZERO_EXTEND, | ||||
5733 | /// extending load, or BUILD_VECTOR with extended elements, return the | ||||
5734 | /// unextended value. The unextended vector should be 64 bits so that it can | ||||
5735 | /// be used as an operand to a VMULL instruction. If the original vector size | ||||
5736 | /// before extension is less than 64 bits we add a an extension to resize | ||||
5737 | /// the vector to 64 bits. | ||||
5738 | static SDValue SkipExtensionForVMULL(SDNode *N, SelectionDAG &DAG) { | ||||
Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5739 | if (N->getOpcode() == ISD::SIGN_EXTEND || N->getOpcode() == ISD::ZERO_EXTEND) |
Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5740 | return AddRequiredExtensionForVMULL(N->getOperand(0), DAG, |
5741 | N->getOperand(0)->getValueType(0), | ||||
5742 | N->getValueType(0), | ||||
5743 | N->getOpcode()); | ||||
5744 | |||||
Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 5745 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) |
Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5746 | return SkipLoadExtensionForVMULL(LD, DAG); |
5747 | |||||
Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 5748 | // Otherwise, the value must be a BUILD_VECTOR. For v2i64, it will |
5749 | // have been legalized as a BITCAST from v4i32. | ||||
5750 | if (N->getOpcode() == ISD::BITCAST) { | ||||
5751 | SDNode *BVN = N->getOperand(0).getNode(); | ||||
5752 | assert(BVN->getOpcode() == ISD::BUILD_VECTOR && | ||||
5753 | BVN->getValueType(0) == MVT::v4i32 && "expected v4i32 BUILD_VECTOR"); | ||||
5754 | unsigned LowElt = DAG.getTargetLoweringInfo().isBigEndian() ? 1 : 0; | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5755 | return DAG.getNode(ISD::BUILD_VECTOR, SDLoc(N), MVT::v2i32, |
Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 5756 | BVN->getOperand(LowElt), BVN->getOperand(LowElt+2)); |
5757 | } | ||||
5758 | // Construct a new BUILD_VECTOR with elements truncated to half the size. | ||||
5759 | assert(N->getOpcode() == ISD::BUILD_VECTOR && "expected BUILD_VECTOR"); | ||||
5760 | EVT VT = N->getValueType(0); | ||||
5761 | unsigned EltSize = VT.getVectorElementType().getSizeInBits() / 2; | ||||
5762 | unsigned NumElts = VT.getVectorNumElements(); | ||||
5763 | MVT TruncVT = MVT::getIntegerVT(EltSize); | ||||
5764 | SmallVector<SDValue, 8> Ops; | ||||
5765 | for (unsigned i = 0; i != NumElts; ++i) { | ||||
5766 | ConstantSDNode *C = cast<ConstantSDNode>(N->getOperand(i)); | ||||
5767 | const APInt &CInt = C->getAPIntValue(); | ||||
Bob Wilson | 9245c93 | 2012-04-30 16:53:34 +0000 | [diff] [blame] | 5768 | // Element types smaller than 32 bits are not legal, so use i32 elements. |
5769 | // The values are implicitly truncated so sext vs. zext doesn't matter. | ||||
5770 | Ops.push_back(DAG.getConstant(CInt.zextOrTrunc(32), MVT::i32)); | ||||
Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 5771 | } |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5772 | return DAG.getNode(ISD::BUILD_VECTOR, SDLoc(N), |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 5773 | MVT::getVectorVT(TruncVT, NumElts), Ops); |
Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5774 | } |
5775 | |||||
Evan Cheng | e2086e7 | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5776 | static bool isAddSubSExt(SDNode *N, SelectionDAG &DAG) { |
5777 | unsigned Opcode = N->getOpcode(); | ||||
5778 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { | ||||
5779 | SDNode *N0 = N->getOperand(0).getNode(); | ||||
5780 | SDNode *N1 = N->getOperand(1).getNode(); | ||||
5781 | return N0->hasOneUse() && N1->hasOneUse() && | ||||
5782 | isSignExtended(N0, DAG) && isSignExtended(N1, DAG); | ||||
5783 | } | ||||
5784 | return false; | ||||
5785 | } | ||||
5786 | |||||
5787 | static bool isAddSubZExt(SDNode *N, SelectionDAG &DAG) { | ||||
5788 | unsigned Opcode = N->getOpcode(); | ||||
5789 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { | ||||
5790 | SDNode *N0 = N->getOperand(0).getNode(); | ||||
5791 | SDNode *N1 = N->getOperand(1).getNode(); | ||||
5792 | return N0->hasOneUse() && N1->hasOneUse() && | ||||
5793 | isZeroExtended(N0, DAG) && isZeroExtended(N1, DAG); | ||||
5794 | } | ||||
5795 | return false; | ||||
5796 | } | ||||
5797 | |||||
Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5798 | static SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) { |
5799 | // Multiplications are only custom-lowered for 128-bit vectors so that | ||||
5800 | // VMULL can be detected. Otherwise v2i64 multiplications are not legal. | ||||
5801 | EVT VT = Op.getValueType(); | ||||
Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5802 | assert(VT.is128BitVector() && VT.isInteger() && |
5803 | "unexpected type for custom-lowering ISD::MUL"); | ||||
Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5804 | SDNode *N0 = Op.getOperand(0).getNode(); |
5805 | SDNode *N1 = Op.getOperand(1).getNode(); | ||||
5806 | unsigned NewOpc = 0; | ||||
Evan Cheng | e2086e7 | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5807 | bool isMLA = false; |
5808 | bool isN0SExt = isSignExtended(N0, DAG); | ||||
5809 | bool isN1SExt = isSignExtended(N1, DAG); | ||||
5810 | if (isN0SExt && isN1SExt) | ||||
Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5811 | NewOpc = ARMISD::VMULLs; |
Evan Cheng | e2086e7 | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5812 | else { |
5813 | bool isN0ZExt = isZeroExtended(N0, DAG); | ||||
5814 | bool isN1ZExt = isZeroExtended(N1, DAG); | ||||
5815 | if (isN0ZExt && isN1ZExt) | ||||
5816 | NewOpc = ARMISD::VMULLu; | ||||
5817 | else if (isN1SExt || isN1ZExt) { | ||||
5818 | // Look for (s/zext A + s/zext B) * (s/zext C). We want to turn these | ||||
5819 | // into (s/zext A * s/zext C) + (s/zext B * s/zext C) | ||||
5820 | if (isN1SExt && isAddSubSExt(N0, DAG)) { | ||||
5821 | NewOpc = ARMISD::VMULLs; | ||||
5822 | isMLA = true; | ||||
5823 | } else if (isN1ZExt && isAddSubZExt(N0, DAG)) { | ||||
5824 | NewOpc = ARMISD::VMULLu; | ||||
5825 | isMLA = true; | ||||
5826 | } else if (isN0ZExt && isAddSubZExt(N1, DAG)) { | ||||
5827 | std::swap(N0, N1); | ||||
5828 | NewOpc = ARMISD::VMULLu; | ||||
5829 | isMLA = true; | ||||
5830 | } | ||||
5831 | } | ||||
5832 | |||||
5833 | if (!NewOpc) { | ||||
5834 | if (VT == MVT::v2i64) | ||||
5835 | // Fall through to expand this. It is not legal. | ||||
5836 | return SDValue(); | ||||
5837 | else | ||||
5838 | // Other vector multiplications are legal. | ||||
5839 | return Op; | ||||
5840 | } | ||||
5841 | } | ||||
Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5842 | |
5843 | // Legalize to a VMULL instruction. | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5844 | SDLoc DL(Op); |
Evan Cheng | e2086e7 | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5845 | SDValue Op0; |
Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5846 | SDValue Op1 = SkipExtensionForVMULL(N1, DAG); |
Evan Cheng | e2086e7 | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5847 | if (!isMLA) { |
Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5848 | Op0 = SkipExtensionForVMULL(N0, DAG); |
Evan Cheng | e2086e7 | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5849 | assert(Op0.getValueType().is64BitVector() && |
5850 | Op1.getValueType().is64BitVector() && | ||||
5851 | "unexpected types for extended operands to VMULL"); | ||||
5852 | return DAG.getNode(NewOpc, DL, VT, Op0, Op1); | ||||
5853 | } | ||||
Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5854 | |
Evan Cheng | e2086e7 | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5855 | // Optimizing (zext A + zext B) * C, to (VMULL A, C) + (VMULL B, C) during |
5856 | // isel lowering to take advantage of no-stall back to back vmul + vmla. | ||||
5857 | // vmull q0, d4, d6 | ||||
5858 | // vmlal q0, d5, d6 | ||||
5859 | // is faster than | ||||
5860 | // vaddl q0, d4, d5 | ||||
5861 | // vmovl q1, d6 | ||||
5862 | // vmul q0, q0, q1 | ||||
Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5863 | SDValue N00 = SkipExtensionForVMULL(N0->getOperand(0).getNode(), DAG); |
5864 | SDValue N01 = SkipExtensionForVMULL(N0->getOperand(1).getNode(), DAG); | ||||
Evan Cheng | e2086e7 | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5865 | EVT Op1VT = Op1.getValueType(); |
5866 | return DAG.getNode(N0->getOpcode(), DL, VT, | ||||
5867 | DAG.getNode(NewOpc, DL, VT, | ||||
5868 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N00), Op1), | ||||
5869 | DAG.getNode(NewOpc, DL, VT, | ||||
5870 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N01), Op1)); | ||||
Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5871 | } |
5872 | |||||
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5873 | static SDValue |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5874 | LowerSDIV_v4i8(SDValue X, SDValue Y, SDLoc dl, SelectionDAG &DAG) { |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5875 | // Convert to float |
5876 | // float4 xf = vcvt_f32_s32(vmovl_s16(a.lo)); | ||||
5877 | // float4 yf = vcvt_f32_s32(vmovl_s16(b.lo)); | ||||
5878 | X = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, X); | ||||
5879 | Y = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, Y); | ||||
5880 | X = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, X); | ||||
5881 | Y = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, Y); | ||||
5882 | // Get reciprocal estimate. | ||||
5883 | // float4 recip = vrecpeq_f32(yf); | ||||
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5884 | Y = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5885 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), Y); |
5886 | // Because char has a smaller range than uchar, we can actually get away | ||||
5887 | // without any newton steps. This requires that we use a weird bias | ||||
5888 | // of 0xb000, however (again, this has been exhaustively tested). | ||||
5889 | // float4 result = as_float4(as_int4(xf*recip) + 0xb000); | ||||
5890 | X = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, X, Y); | ||||
5891 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, X); | ||||
5892 | Y = DAG.getConstant(0xb000, MVT::i32); | ||||
5893 | Y = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, Y, Y, Y, Y); | ||||
5894 | X = DAG.getNode(ISD::ADD, dl, MVT::v4i32, X, Y); | ||||
5895 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, X); | ||||
5896 | // Convert back to short. | ||||
5897 | X = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, X); | ||||
5898 | X = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, X); | ||||
5899 | return X; | ||||
5900 | } | ||||
5901 | |||||
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5902 | static SDValue |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5903 | LowerSDIV_v4i16(SDValue N0, SDValue N1, SDLoc dl, SelectionDAG &DAG) { |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5904 | SDValue N2; |
5905 | // Convert to float. | ||||
5906 | // float4 yf = vcvt_f32_s32(vmovl_s16(y)); | ||||
5907 | // float4 xf = vcvt_f32_s32(vmovl_s16(x)); | ||||
5908 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N0); | ||||
5909 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N1); | ||||
5910 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); | ||||
5911 | N1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); | ||||
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5912 | |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5913 | // Use reciprocal estimate and one refinement step. |
5914 | // float4 recip = vrecpeq_f32(yf); | ||||
5915 | // recip *= vrecpsq_f32(yf, recip); | ||||
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5916 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5917 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), N1); |
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5918 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5919 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
5920 | N1, N2); | ||||
5921 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); | ||||
5922 | // Because short has a smaller range than ushort, we can actually get away | ||||
5923 | // with only a single newton step. This requires that we use a weird bias | ||||
5924 | // of 89, however (again, this has been exhaustively tested). | ||||
Mon P Wang | 6d9e1c7 | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5925 | // float4 result = as_float4(as_int4(xf*recip) + 0x89); |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5926 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
5927 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); | ||||
Mon P Wang | 6d9e1c7 | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5928 | N1 = DAG.getConstant(0x89, MVT::i32); |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5929 | N1 = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, N1, N1, N1, N1); |
5930 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); | ||||
5931 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); | ||||
5932 | // Convert back to integer and return. | ||||
5933 | // return vmovn_s32(vcvt_s32_f32(result)); | ||||
5934 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); | ||||
5935 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); | ||||
5936 | return N0; | ||||
5937 | } | ||||
5938 | |||||
5939 | static SDValue LowerSDIV(SDValue Op, SelectionDAG &DAG) { | ||||
5940 | EVT VT = Op.getValueType(); | ||||
5941 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && | ||||
5942 | "unexpected type for custom-lowering ISD::SDIV"); | ||||
5943 | |||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5944 | SDLoc dl(Op); |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5945 | SDValue N0 = Op.getOperand(0); |
5946 | SDValue N1 = Op.getOperand(1); | ||||
5947 | SDValue N2, N3; | ||||
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5948 | |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5949 | if (VT == MVT::v8i8) { |
5950 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N0); | ||||
5951 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N1); | ||||
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5952 | |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5953 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
5954 | DAG.getIntPtrConstant(4)); | ||||
5955 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, | ||||
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5956 | DAG.getIntPtrConstant(4)); |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5957 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
5958 | DAG.getIntPtrConstant(0)); | ||||
5959 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, | ||||
5960 | DAG.getIntPtrConstant(0)); | ||||
5961 | |||||
5962 | N0 = LowerSDIV_v4i8(N0, N1, dl, DAG); // v4i16 | ||||
5963 | N2 = LowerSDIV_v4i8(N2, N3, dl, DAG); // v4i16 | ||||
5964 | |||||
5965 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); | ||||
5966 | N0 = LowerCONCAT_VECTORS(N0, DAG); | ||||
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5967 | |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5968 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v8i8, N0); |
5969 | return N0; | ||||
5970 | } | ||||
5971 | return LowerSDIV_v4i16(N0, N1, dl, DAG); | ||||
5972 | } | ||||
5973 | |||||
5974 | static SDValue LowerUDIV(SDValue Op, SelectionDAG &DAG) { | ||||
5975 | EVT VT = Op.getValueType(); | ||||
5976 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && | ||||
5977 | "unexpected type for custom-lowering ISD::UDIV"); | ||||
5978 | |||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5979 | SDLoc dl(Op); |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5980 | SDValue N0 = Op.getOperand(0); |
5981 | SDValue N1 = Op.getOperand(1); | ||||
5982 | SDValue N2, N3; | ||||
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5983 | |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5984 | if (VT == MVT::v8i8) { |
5985 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N0); | ||||
5986 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N1); | ||||
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5987 | |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5988 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
5989 | DAG.getIntPtrConstant(4)); | ||||
5990 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, | ||||
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5991 | DAG.getIntPtrConstant(4)); |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5992 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
5993 | DAG.getIntPtrConstant(0)); | ||||
5994 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, | ||||
5995 | DAG.getIntPtrConstant(0)); | ||||
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5996 | |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5997 | N0 = LowerSDIV_v4i16(N0, N1, dl, DAG); // v4i16 |
5998 | N2 = LowerSDIV_v4i16(N2, N3, dl, DAG); // v4i16 | ||||
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5999 | |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6000 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
6001 | N0 = LowerCONCAT_VECTORS(N0, DAG); | ||||
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6002 | |
6003 | N0 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v8i8, | ||||
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6004 | DAG.getConstant(Intrinsic::arm_neon_vqmovnsu, MVT::i32), |
6005 | N0); | ||||
6006 | return N0; | ||||
6007 | } | ||||
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6008 | |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6009 | // v4i16 sdiv ... Convert to float. |
6010 | // float4 yf = vcvt_f32_s32(vmovl_u16(y)); | ||||
6011 | // float4 xf = vcvt_f32_s32(vmovl_u16(x)); | ||||
6012 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N0); | ||||
6013 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N1); | ||||
6014 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); | ||||
Mon P Wang | 6d9e1c7 | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 6015 | SDValue BN1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6016 | |
6017 | // Use reciprocal estimate and two refinement steps. | ||||
6018 | // float4 recip = vrecpeq_f32(yf); | ||||
6019 | // recip *= vrecpsq_f32(yf, recip); | ||||
6020 | // recip *= vrecpsq_f32(yf, recip); | ||||
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6021 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Mon P Wang | 6d9e1c7 | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 6022 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), BN1); |
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6023 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6024 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
Mon P Wang | 6d9e1c7 | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 6025 | BN1, N2); |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6026 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6027 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6028 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
Mon P Wang | 6d9e1c7 | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 6029 | BN1, N2); |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6030 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
6031 | // Simply multiplying by the reciprocal estimate can leave us a few ulps | ||||
6032 | // too low, so we add 2 ulps (exhaustive testing shows that this is enough, | ||||
6033 | // and that it will never cause us to return an answer too large). | ||||
Mon P Wang | 6d9e1c7 | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 6034 | // float4 result = as_float4(as_int4(xf*recip) + 2); |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6035 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
6036 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); | ||||
6037 | N1 = DAG.getConstant(2, MVT::i32); | ||||
6038 | N1 = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, N1, N1, N1, N1); | ||||
6039 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); | ||||
6040 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); | ||||
6041 | // Convert back to integer and return. | ||||
6042 | // return vmovn_u32(vcvt_s32_f32(result)); | ||||
6043 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); | ||||
6044 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); | ||||
6045 | return N0; | ||||
6046 | } | ||||
6047 | |||||
Evan Cheng | e891654 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 6048 | static SDValue LowerADDC_ADDE_SUBC_SUBE(SDValue Op, SelectionDAG &DAG) { |
6049 | EVT VT = Op.getNode()->getValueType(0); | ||||
6050 | SDVTList VTs = DAG.getVTList(VT, MVT::i32); | ||||
6051 | |||||
6052 | unsigned Opc; | ||||
6053 | bool ExtraOp = false; | ||||
6054 | switch (Op.getOpcode()) { | ||||
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 6055 | default: llvm_unreachable("Invalid code"); |
Evan Cheng | e891654 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 6056 | case ISD::ADDC: Opc = ARMISD::ADDC; break; |
6057 | case ISD::ADDE: Opc = ARMISD::ADDE; ExtraOp = true; break; | ||||
6058 | case ISD::SUBC: Opc = ARMISD::SUBC; break; | ||||
6059 | case ISD::SUBE: Opc = ARMISD::SUBE; ExtraOp = true; break; | ||||
6060 | } | ||||
6061 | |||||
6062 | if (!ExtraOp) | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6063 | return DAG.getNode(Opc, SDLoc(Op), VTs, Op.getOperand(0), |
Evan Cheng | e891654 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 6064 | Op.getOperand(1)); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6065 | return DAG.getNode(Opc, SDLoc(Op), VTs, Op.getOperand(0), |
Evan Cheng | e891654 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 6066 | Op.getOperand(1), Op.getOperand(2)); |
6067 | } | ||||
6068 | |||||
Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 6069 | SDValue ARMTargetLowering::LowerFSINCOS(SDValue Op, SelectionDAG &DAG) const { |
6070 | assert(Subtarget->isTargetDarwin()); | ||||
6071 | |||||
6072 | // For iOS, we want to call an alternative entry point: __sincos_stret, | ||||
6073 | // return values are passed via sret. | ||||
6074 | SDLoc dl(Op); | ||||
6075 | SDValue Arg = Op.getOperand(0); | ||||
6076 | EVT ArgVT = Arg.getValueType(); | ||||
6077 | Type *ArgTy = ArgVT.getTypeForEVT(*DAG.getContext()); | ||||
6078 | |||||
6079 | MachineFrameInfo *FrameInfo = DAG.getMachineFunction().getFrameInfo(); | ||||
6080 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); | ||||
6081 | |||||
6082 | // Pair of floats / doubles used to pass the result. | ||||
6083 | StructType *RetTy = StructType::get(ArgTy, ArgTy, NULL); | ||||
6084 | |||||
6085 | // Create stack object for sret. | ||||
6086 | const uint64_t ByteSize = TLI.getDataLayout()->getTypeAllocSize(RetTy); | ||||
6087 | const unsigned StackAlign = TLI.getDataLayout()->getPrefTypeAlignment(RetTy); | ||||
6088 | int FrameIdx = FrameInfo->CreateStackObject(ByteSize, StackAlign, false); | ||||
6089 | SDValue SRet = DAG.getFrameIndex(FrameIdx, TLI.getPointerTy()); | ||||
6090 | |||||
6091 | ArgListTy Args; | ||||
6092 | ArgListEntry Entry; | ||||
6093 | |||||
6094 | Entry.Node = SRet; | ||||
6095 | Entry.Ty = RetTy->getPointerTo(); | ||||
6096 | Entry.isSExt = false; | ||||
6097 | Entry.isZExt = false; | ||||
6098 | Entry.isSRet = true; | ||||
6099 | Args.push_back(Entry); | ||||
6100 | |||||
6101 | Entry.Node = Arg; | ||||
6102 | Entry.Ty = ArgTy; | ||||
6103 | Entry.isSExt = false; | ||||
6104 | Entry.isZExt = false; | ||||
6105 | Args.push_back(Entry); | ||||
6106 | |||||
6107 | const char *LibcallName = (ArgVT == MVT::f64) | ||||
6108 | ? "__sincos_stret" : "__sincosf_stret"; | ||||
6109 | SDValue Callee = DAG.getExternalSymbol(LibcallName, getPointerTy()); | ||||
6110 | |||||
6111 | TargetLowering:: | ||||
6112 | CallLoweringInfo CLI(DAG.getEntryNode(), Type::getVoidTy(*DAG.getContext()), | ||||
6113 | false, false, false, false, 0, | ||||
6114 | CallingConv::C, /*isTaillCall=*/false, | ||||
6115 | /*doesNotRet=*/false, /*isReturnValueUsed*/false, | ||||
6116 | Callee, Args, DAG, dl); | ||||
6117 | std::pair<SDValue, SDValue> CallResult = LowerCallTo(CLI); | ||||
6118 | |||||
6119 | SDValue LoadSin = DAG.getLoad(ArgVT, dl, CallResult.second, SRet, | ||||
6120 | MachinePointerInfo(), false, false, false, 0); | ||||
6121 | |||||
6122 | // Address of cos field. | ||||
6123 | SDValue Add = DAG.getNode(ISD::ADD, dl, getPointerTy(), SRet, | ||||
6124 | DAG.getIntPtrConstant(ArgVT.getStoreSize())); | ||||
6125 | SDValue LoadCos = DAG.getLoad(ArgVT, dl, LoadSin.getValue(1), Add, | ||||
6126 | MachinePointerInfo(), false, false, false, 0); | ||||
6127 | |||||
6128 | SDVTList Tys = DAG.getVTList(ArgVT, ArgVT); | ||||
6129 | return DAG.getNode(ISD::MERGE_VALUES, dl, Tys, | ||||
6130 | LoadSin.getValue(0), LoadCos.getValue(0)); | ||||
6131 | } | ||||
6132 | |||||
Eli Friedman | 10f9ce2 | 2011-09-15 22:26:18 +0000 | [diff] [blame] | 6133 | static SDValue LowerAtomicLoadStore(SDValue Op, SelectionDAG &DAG) { |
Eli Friedman | ba912e0 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 6134 | // Monotonic load/store is legal for all targets |
6135 | if (cast<AtomicSDNode>(Op)->getOrdering() <= Monotonic) | ||||
6136 | return Op; | ||||
6137 | |||||
Alp Toker | cb40291 | 2014-01-24 17:20:08 +0000 | [diff] [blame] | 6138 | // Acquire/Release load/store is not legal for targets without a |
Eli Friedman | ba912e0 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 6139 | // dmb or equivalent available. |
6140 | return SDValue(); | ||||
6141 | } | ||||
6142 | |||||
Tim Northover | bc93308 | 2013-05-23 19:11:20 +0000 | [diff] [blame] | 6143 | static void ReplaceREADCYCLECOUNTER(SDNode *N, |
6144 | SmallVectorImpl<SDValue> &Results, | ||||
6145 | SelectionDAG &DAG, | ||||
6146 | const ARMSubtarget *Subtarget) { | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6147 | SDLoc DL(N); |
Tim Northover | bc93308 | 2013-05-23 19:11:20 +0000 | [diff] [blame] | 6148 | SDValue Cycles32, OutChain; |
6149 | |||||
6150 | if (Subtarget->hasPerfMon()) { | ||||
6151 | // Under Power Management extensions, the cycle-count is: | ||||
6152 | // mrc p15, #0, <Rt>, c9, c13, #0 | ||||
6153 | SDValue Ops[] = { N->getOperand(0), // Chain | ||||
6154 | DAG.getConstant(Intrinsic::arm_mrc, MVT::i32), | ||||
6155 | DAG.getConstant(15, MVT::i32), | ||||
6156 | DAG.getConstant(0, MVT::i32), | ||||
6157 | DAG.getConstant(9, MVT::i32), | ||||
6158 | DAG.getConstant(13, MVT::i32), | ||||
6159 | DAG.getConstant(0, MVT::i32) | ||||
6160 | }; | ||||
6161 | |||||
6162 | Cycles32 = DAG.getNode(ISD::INTRINSIC_W_CHAIN, DL, | ||||
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 6163 | DAG.getVTList(MVT::i32, MVT::Other), Ops); |
Tim Northover | bc93308 | 2013-05-23 19:11:20 +0000 | [diff] [blame] | 6164 | OutChain = Cycles32.getValue(1); |
6165 | } else { | ||||
6166 | // Intrinsic is defined to return 0 on unsupported platforms. Technically | ||||
6167 | // there are older ARM CPUs that have implementation-specific ways of | ||||
6168 | // obtaining this information (FIXME!). | ||||
6169 | Cycles32 = DAG.getConstant(0, MVT::i32); | ||||
6170 | OutChain = DAG.getEntryNode(); | ||||
6171 | } | ||||
6172 | |||||
6173 | |||||
6174 | SDValue Cycles64 = DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64, | ||||
6175 | Cycles32, DAG.getConstant(0, MVT::i32)); | ||||
6176 | Results.push_back(Cycles64); | ||||
6177 | Results.push_back(OutChain); | ||||
6178 | } | ||||
6179 | |||||
Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 6180 | SDValue ARMTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6181 | switch (Op.getOpcode()) { |
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 6182 | default: llvm_unreachable("Don't know how to custom lower this!"); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6183 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
Bob Wilson | 1cf0b03 | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 6184 | case ISD::BlockAddress: return LowerBlockAddress(Op, DAG); |
Lauro Ramos Venancio | ee2d164 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 6185 | case ISD::GlobalAddress: |
Saleem Abdulrasool | 40bca0a | 2014-05-09 00:58:32 +0000 | [diff] [blame] | 6186 | switch (Subtarget->getTargetTriple().getObjectFormat()) { |
6187 | default: llvm_unreachable("unknown object format"); | ||||
6188 | case Triple::COFF: | ||||
6189 | return LowerGlobalAddressWindows(Op, DAG); | ||||
6190 | case Triple::ELF: | ||||
6191 | return LowerGlobalAddressELF(Op, DAG); | ||||
6192 | case Triple::MachO: | ||||
6193 | return LowerGlobalAddressDarwin(Op, DAG); | ||||
6194 | } | ||||
Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 6195 | case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); |
Bill Wendling | 6a98131 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 6196 | case ISD::SELECT: return LowerSELECT(Op, DAG); |
Evan Cheng | 15b80e4 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 6197 | case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG); |
6198 | case ISD::BR_CC: return LowerBR_CC(Op, DAG); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6199 | case ISD::BR_JT: return LowerBR_JT(Op, DAG); |
Dan Gohman | 31ae586 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 6200 | case ISD::VASTART: return LowerVASTART(Op, DAG); |
Eli Friedman | 26a4848 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 6201 | case ISD::ATOMIC_FENCE: return LowerATOMIC_FENCE(Op, DAG, Subtarget); |
Evan Cheng | 8740ee3 | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 6202 | case ISD::PREFETCH: return LowerPREFETCH(Op, DAG, Subtarget); |
Bob Wilson | e4191e7 | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 6203 | case ISD::SINT_TO_FP: |
6204 | case ISD::UINT_TO_FP: return LowerINT_TO_FP(Op, DAG); | ||||
6205 | case ISD::FP_TO_SINT: | ||||
6206 | case ISD::FP_TO_UINT: return LowerFP_TO_INT(Op, DAG); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6207 | case ISD::FCOPYSIGN: return LowerFCOPYSIGN(Op, DAG); |
Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 6208 | case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG); |
Jim Grosbach | aeca45d | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 6209 | case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG); |
Lauro Ramos Venancio | ee2d164 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 6210 | case ISD::GLOBAL_OFFSET_TABLE: return LowerGLOBAL_OFFSET_TABLE(Op, DAG); |
Jim Grosbach | c98892f | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 6211 | case ISD::EH_SJLJ_SETJMP: return LowerEH_SJLJ_SETJMP(Op, DAG); |
Jim Grosbach | bd9485d | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 6212 | case ISD::EH_SJLJ_LONGJMP: return LowerEH_SJLJ_LONGJMP(Op, DAG); |
Jim Grosbach | a570d05 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 6213 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG, |
6214 | Subtarget); | ||||
Evan Cheng | 383ecd8 | 2011-03-14 18:02:30 +0000 | [diff] [blame] | 6215 | case ISD::BITCAST: return ExpandBITCAST(Op.getNode(), DAG); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6216 | case ISD::SHL: |
Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6217 | case ISD::SRL: |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6218 | case ISD::SRA: return LowerShift(Op.getNode(), DAG, Subtarget); |
Evan Cheng | 15b80e4 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 6219 | case ISD::SHL_PARTS: return LowerShiftLeftParts(Op, DAG); |
Jim Grosbach | 8fe6fd7 | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 6220 | case ISD::SRL_PARTS: |
Evan Cheng | 15b80e4 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 6221 | case ISD::SRA_PARTS: return LowerShiftRightParts(Op, DAG); |
Jim Grosbach | 8546ec9 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 6222 | case ISD::CTTZ: return LowerCTTZ(Op.getNode(), DAG, Subtarget); |
Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 6223 | case ISD::CTPOP: return LowerCTPOP(Op.getNode(), DAG, Subtarget); |
Duncan Sands | f2641e1 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 6224 | case ISD::SETCC: return LowerVSETCC(Op, DAG); |
Lang Hames | c35ee8b | 2012-03-15 18:49:02 +0000 | [diff] [blame] | 6225 | case ISD::ConstantFP: return LowerConstantFP(Op, DAG, Subtarget); |
Dale Johannesen | 2bff505 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 6226 | case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG, Subtarget); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6227 | case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG); |
Eli Friedman | a5e244c | 2011-10-24 23:08:52 +0000 | [diff] [blame] | 6228 | case ISD::INSERT_VECTOR_ELT: return LowerINSERT_VECTOR_ELT(Op, DAG); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6229 | case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG); |
Bob Wilson | f307e0b | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 6230 | case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG); |
Bob Wilson | 9a511c0 | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 6231 | case ISD::FLT_ROUNDS_: return LowerFLT_ROUNDS_(Op, DAG); |
Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 6232 | case ISD::MUL: return LowerMUL(Op, DAG); |
Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6233 | case ISD::SDIV: return LowerSDIV(Op, DAG); |
6234 | case ISD::UDIV: return LowerUDIV(Op, DAG); | ||||
Evan Cheng | e891654 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 6235 | case ISD::ADDC: |
6236 | case ISD::ADDE: | ||||
6237 | case ISD::SUBC: | ||||
6238 | case ISD::SUBE: return LowerADDC_ADDE_SUBC_SUBE(Op, DAG); | ||||
Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 6239 | case ISD::SADDO: |
6240 | case ISD::UADDO: | ||||
6241 | case ISD::SSUBO: | ||||
6242 | case ISD::USUBO: | ||||
6243 | return LowerXALUO(Op, DAG); | ||||
Eli Friedman | ba912e0 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 6244 | case ISD::ATOMIC_LOAD: |
Eli Friedman | 10f9ce2 | 2011-09-15 22:26:18 +0000 | [diff] [blame] | 6245 | case ISD::ATOMIC_STORE: return LowerAtomicLoadStore(Op, DAG); |
Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 6246 | case ISD::FSINCOS: return LowerFSINCOS(Op, DAG); |
Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 6247 | case ISD::SDIVREM: |
6248 | case ISD::UDIVREM: return LowerDivRem(Op, DAG); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6249 | } |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6250 | } |
6251 | |||||
Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 6252 | /// ReplaceNodeResults - Replace the results of node with an illegal result |
6253 | /// type with new values built out of custom code. | ||||
Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 6254 | void ARMTargetLowering::ReplaceNodeResults(SDNode *N, |
6255 | SmallVectorImpl<SDValue>&Results, | ||||
Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 6256 | SelectionDAG &DAG) const { |
Bob Wilson | c05b887 | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 6257 | SDValue Res; |
Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6258 | switch (N->getOpcode()) { |
Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 6259 | default: |
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 6260 | llvm_unreachable("Don't know how to custom expand this!"); |
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6261 | case ISD::BITCAST: |
6262 | Res = ExpandBITCAST(N, DAG); | ||||
Bob Wilson | c05b887 | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 6263 | break; |
Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6264 | case ISD::SRL: |
Bob Wilson | c05b887 | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 6265 | case ISD::SRA: |
Bob Wilson | 7d47133 | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 6266 | Res = Expand64BitShift(N, DAG, Subtarget); |
Bob Wilson | c05b887 | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 6267 | break; |
Tim Northover | bc93308 | 2013-05-23 19:11:20 +0000 | [diff] [blame] | 6268 | case ISD::READCYCLECOUNTER: |
6269 | ReplaceREADCYCLECOUNTER(N, Results, DAG, Subtarget); | ||||
6270 | return; | ||||
Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 6271 | } |
Bob Wilson | c05b887 | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 6272 | if (Res.getNode()) |
6273 | Results.push_back(Res); | ||||
Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6274 | } |
Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6275 | |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6276 | //===----------------------------------------------------------------------===// |
6277 | // ARM Scheduler Hooks | ||||
6278 | //===----------------------------------------------------------------------===// | ||||
6279 | |||||
Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6280 | /// SetupEntryBlockForSjLj - Insert code into the entry block that creates and |
6281 | /// registers the function context. | ||||
6282 | void ARMTargetLowering:: | ||||
6283 | SetupEntryBlockForSjLj(MachineInstr *MI, MachineBasicBlock *MBB, | ||||
6284 | MachineBasicBlock *DispatchBB, int FI) const { | ||||
Bill Wendling | 374ee19 | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6285 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
6286 | DebugLoc dl = MI->getDebugLoc(); | ||||
6287 | MachineFunction *MF = MBB->getParent(); | ||||
6288 | MachineRegisterInfo *MRI = &MF->getRegInfo(); | ||||
6289 | MachineConstantPool *MCP = MF->getConstantPool(); | ||||
6290 | ARMFunctionInfo *AFI = MF->getInfo<ARMFunctionInfo>(); | ||||
6291 | const Function *F = MF->getFunction(); | ||||
Bill Wendling | 374ee19 | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6292 | |
Bill Wendling | 374ee19 | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6293 | bool isThumb = Subtarget->isThumb(); |
Bill Wendling | 1eab54f | 2011-10-03 22:44:15 +0000 | [diff] [blame] | 6294 | bool isThumb2 = Subtarget->isThumb2(); |
Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6295 | |
Bill Wendling | 374ee19 | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6296 | unsigned PCLabelId = AFI->createPICLabelUId(); |
Bill Wendling | 1eab54f | 2011-10-03 22:44:15 +0000 | [diff] [blame] | 6297 | unsigned PCAdj = (isThumb || isThumb2) ? 4 : 8; |
Bill Wendling | 374ee19 | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6298 | ARMConstantPoolValue *CPV = |
6299 | ARMConstantPoolMBB::Create(F->getContext(), DispatchBB, PCLabelId, PCAdj); | ||||
6300 | unsigned CPI = MCP->getConstantPoolIndex(CPV, 4); | ||||
6301 | |||||
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6302 | const TargetRegisterClass *TRC = isThumb ? |
6303 | (const TargetRegisterClass*)&ARM::tGPRRegClass : | ||||
6304 | (const TargetRegisterClass*)&ARM::GPRRegClass; | ||||
Bill Wendling | 374ee19 | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6305 | |
Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6306 | // Grab constant pool and fixed stack memory operands. |
6307 | MachineMemOperand *CPMMO = | ||||
6308 | MF->getMachineMemOperand(MachinePointerInfo::getConstantPool(), | ||||
6309 | MachineMemOperand::MOLoad, 4, 4); | ||||
6310 | |||||
6311 | MachineMemOperand *FIMMOSt = | ||||
6312 | MF->getMachineMemOperand(MachinePointerInfo::getFixedStack(FI), | ||||
6313 | MachineMemOperand::MOStore, 4, 4); | ||||
6314 | |||||
6315 | // Load the address of the dispatch MBB into the jump buffer. | ||||
6316 | if (isThumb2) { | ||||
6317 | // Incoming value: jbuf | ||||
6318 | // ldr.n r5, LCPI1_1 | ||||
6319 | // orr r5, r5, #1 | ||||
6320 | // add r5, pc | ||||
6321 | // str r5, [$jbuf, #+4] ; &jbuf[1] | ||||
6322 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); | ||||
6323 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2LDRpci), NewVReg1) | ||||
6324 | .addConstantPoolIndex(CPI) | ||||
6325 | .addMemOperand(CPMMO)); | ||||
6326 | // Set the low bit because of thumb mode. | ||||
6327 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); | ||||
6328 | AddDefaultCC( | ||||
6329 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2ORRri), NewVReg2) | ||||
6330 | .addReg(NewVReg1, RegState::Kill) | ||||
6331 | .addImm(0x01))); | ||||
6332 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); | ||||
6333 | BuildMI(*MBB, MI, dl, TII->get(ARM::tPICADD), NewVReg3) | ||||
6334 | .addReg(NewVReg2, RegState::Kill) | ||||
6335 | .addImm(PCLabelId); | ||||
6336 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2STRi12)) | ||||
6337 | .addReg(NewVReg3, RegState::Kill) | ||||
6338 | .addFrameIndex(FI) | ||||
6339 | .addImm(36) // &jbuf[1] :: pc | ||||
6340 | .addMemOperand(FIMMOSt)); | ||||
6341 | } else if (isThumb) { | ||||
6342 | // Incoming value: jbuf | ||||
6343 | // ldr.n r1, LCPI1_4 | ||||
6344 | // add r1, pc | ||||
6345 | // mov r2, #1 | ||||
6346 | // orrs r1, r2 | ||||
6347 | // add r2, $jbuf, #+4 ; &jbuf[1] | ||||
6348 | // str r1, [r2] | ||||
6349 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); | ||||
6350 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tLDRpci), NewVReg1) | ||||
6351 | .addConstantPoolIndex(CPI) | ||||
6352 | .addMemOperand(CPMMO)); | ||||
6353 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); | ||||
6354 | BuildMI(*MBB, MI, dl, TII->get(ARM::tPICADD), NewVReg2) | ||||
6355 | .addReg(NewVReg1, RegState::Kill) | ||||
6356 | .addImm(PCLabelId); | ||||
6357 | // Set the low bit because of thumb mode. | ||||
6358 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); | ||||
6359 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tMOVi8), NewVReg3) | ||||
6360 | .addReg(ARM::CPSR, RegState::Define) | ||||
6361 | .addImm(1)); | ||||
6362 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); | ||||
6363 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tORR), NewVReg4) | ||||
6364 | .addReg(ARM::CPSR, RegState::Define) | ||||
6365 | .addReg(NewVReg2, RegState::Kill) | ||||
6366 | .addReg(NewVReg3, RegState::Kill)); | ||||
6367 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); | ||||
6368 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tADDrSPi), NewVReg5) | ||||
6369 | .addFrameIndex(FI) | ||||
6370 | .addImm(36)); // &jbuf[1] :: pc | ||||
6371 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tSTRi)) | ||||
6372 | .addReg(NewVReg4, RegState::Kill) | ||||
6373 | .addReg(NewVReg5, RegState::Kill) | ||||
6374 | .addImm(0) | ||||
6375 | .addMemOperand(FIMMOSt)); | ||||
6376 | } else { | ||||
6377 | // Incoming value: jbuf | ||||
6378 | // ldr r1, LCPI1_1 | ||||
6379 | // add r1, pc, r1 | ||||
6380 | // str r1, [$jbuf, #+4] ; &jbuf[1] | ||||
6381 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); | ||||
6382 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::LDRi12), NewVReg1) | ||||
6383 | .addConstantPoolIndex(CPI) | ||||
6384 | .addImm(0) | ||||
6385 | .addMemOperand(CPMMO)); | ||||
6386 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); | ||||
6387 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::PICADD), NewVReg2) | ||||
6388 | .addReg(NewVReg1, RegState::Kill) | ||||
6389 | .addImm(PCLabelId)); | ||||
6390 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::STRi12)) | ||||
6391 | .addReg(NewVReg2, RegState::Kill) | ||||
6392 | .addFrameIndex(FI) | ||||
6393 | .addImm(36) // &jbuf[1] :: pc | ||||
6394 | .addMemOperand(FIMMOSt)); | ||||
6395 | } | ||||
6396 | } | ||||
6397 | |||||
6398 | MachineBasicBlock *ARMTargetLowering:: | ||||
6399 | EmitSjLjDispatchBlock(MachineInstr *MI, MachineBasicBlock *MBB) const { | ||||
6400 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); | ||||
6401 | DebugLoc dl = MI->getDebugLoc(); | ||||
6402 | MachineFunction *MF = MBB->getParent(); | ||||
6403 | MachineRegisterInfo *MRI = &MF->getRegInfo(); | ||||
6404 | ARMFunctionInfo *AFI = MF->getInfo<ARMFunctionInfo>(); | ||||
6405 | MachineFrameInfo *MFI = MF->getFrameInfo(); | ||||
6406 | int FI = MFI->getFunctionContextIndex(); | ||||
6407 | |||||
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6408 | const TargetRegisterClass *TRC = Subtarget->isThumb() ? |
6409 | (const TargetRegisterClass*)&ARM::tGPRRegClass : | ||||
Jakob Stoklund Olesen | 691ae33 | 2012-05-20 06:38:47 +0000 | [diff] [blame] | 6410 | (const TargetRegisterClass*)&ARM::GPRnopcRegClass; |
Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6411 | |
Bill Wendling | 362c1b0 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 6412 | // Get a mapping of the call site numbers to all of the landing pads they're |
6413 | // associated with. | ||||
Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6414 | DenseMap<unsigned, SmallVector<MachineBasicBlock*, 2> > CallSiteNumToLPad; |
6415 | unsigned MaxCSNum = 0; | ||||
6416 | MachineModuleInfo &MMI = MF->getMMI(); | ||||
Jim Grosbach | 0c509fa | 2012-04-06 23:43:50 +0000 | [diff] [blame] | 6417 | for (MachineFunction::iterator BB = MF->begin(), E = MF->end(); BB != E; |
6418 | ++BB) { | ||||
Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6419 | if (!BB->isLandingPad()) continue; |
6420 | |||||
6421 | // FIXME: We should assert that the EH_LABEL is the first MI in the landing | ||||
6422 | // pad. | ||||
6423 | for (MachineBasicBlock::iterator | ||||
6424 | II = BB->begin(), IE = BB->end(); II != IE; ++II) { | ||||
6425 | if (!II->isEHLabel()) continue; | ||||
6426 | |||||
6427 | MCSymbol *Sym = II->getOperand(0).getMCSymbol(); | ||||
Bill Wendling | f793e7e | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 6428 | if (!MMI.hasCallSiteLandingPad(Sym)) continue; |
Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6429 | |
Bill Wendling | f793e7e | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 6430 | SmallVectorImpl<unsigned> &CallSiteIdxs = MMI.getCallSiteLandingPad(Sym); |
6431 | for (SmallVectorImpl<unsigned>::iterator | ||||
6432 | CSI = CallSiteIdxs.begin(), CSE = CallSiteIdxs.end(); | ||||
6433 | CSI != CSE; ++CSI) { | ||||
6434 | CallSiteNumToLPad[*CSI].push_back(BB); | ||||
6435 | MaxCSNum = std::max(MaxCSNum, *CSI); | ||||
6436 | } | ||||
Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6437 | break; |
6438 | } | ||||
6439 | } | ||||
6440 | |||||
6441 | // Get an ordered list of the machine basic blocks for the jump table. | ||||
6442 | std::vector<MachineBasicBlock*> LPadList; | ||||
Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6443 | SmallPtrSet<MachineBasicBlock*, 64> InvokeBBs; |
Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6444 | LPadList.reserve(CallSiteNumToLPad.size()); |
6445 | for (unsigned I = 1; I <= MaxCSNum; ++I) { | ||||
6446 | SmallVectorImpl<MachineBasicBlock*> &MBBList = CallSiteNumToLPad[I]; | ||||
6447 | for (SmallVectorImpl<MachineBasicBlock*>::iterator | ||||
Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6448 | II = MBBList.begin(), IE = MBBList.end(); II != IE; ++II) { |
Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6449 | LPadList.push_back(*II); |
Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6450 | InvokeBBs.insert((*II)->pred_begin(), (*II)->pred_end()); |
6451 | } | ||||
Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6452 | } |
6453 | |||||
Bill Wendling | f793e7e | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 6454 | assert(!LPadList.empty() && |
6455 | "No landing pad destinations for the dispatch jump table!"); | ||||
6456 | |||||
Bill Wendling | 362c1b0 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 6457 | // Create the jump table and associated information. |
Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6458 | MachineJumpTableInfo *JTI = |
6459 | MF->getOrCreateJumpTableInfo(MachineJumpTableInfo::EK_Inline); | ||||
6460 | unsigned MJTI = JTI->createJumpTableIndex(LPadList); | ||||
6461 | unsigned UId = AFI->createJumpTableUId(); | ||||
Chad Rosier | 9660343 | 2013-03-01 18:30:38 +0000 | [diff] [blame] | 6462 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6463 | |
Bill Wendling | 362c1b0 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 6464 | // Create the MBBs for the dispatch code. |
Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6465 | |
6466 | // Shove the dispatch's address into the return slot in the function context. | ||||
6467 | MachineBasicBlock *DispatchBB = MF->CreateMachineBasicBlock(); | ||||
6468 | DispatchBB->setIsLandingPad(); | ||||
Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6469 | |
Bill Wendling | 324be98 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6470 | MachineBasicBlock *TrapBB = MF->CreateMachineBasicBlock(); |
Eli Bendersky | 2e2ce49 | 2013-01-30 16:30:19 +0000 | [diff] [blame] | 6471 | unsigned trap_opcode; |
Chad Rosier | 11a9828 | 2013-02-28 18:54:27 +0000 | [diff] [blame] | 6472 | if (Subtarget->isThumb()) |
Eli Bendersky | 2e2ce49 | 2013-01-30 16:30:19 +0000 | [diff] [blame] | 6473 | trap_opcode = ARM::tTRAP; |
Chad Rosier | 11a9828 | 2013-02-28 18:54:27 +0000 | [diff] [blame] | 6474 | else |
6475 | trap_opcode = Subtarget->useNaClTrap() ? ARM::TRAPNaCl : ARM::TRAP; | ||||
6476 | |||||
Eli Bendersky | 2e2ce49 | 2013-01-30 16:30:19 +0000 | [diff] [blame] | 6477 | BuildMI(TrapBB, dl, TII->get(trap_opcode)); |
Bill Wendling | 324be98 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6478 | DispatchBB->addSuccessor(TrapBB); |
6479 | |||||
6480 | MachineBasicBlock *DispContBB = MF->CreateMachineBasicBlock(); | ||||
6481 | DispatchBB->addSuccessor(DispContBB); | ||||
Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6482 | |
Bill Wendling | 510fbcd | 2011-10-17 21:32:56 +0000 | [diff] [blame] | 6483 | // Insert and MBBs. |
Bill Wendling | 6134655 | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 6484 | MF->insert(MF->end(), DispatchBB); |
6485 | MF->insert(MF->end(), DispContBB); | ||||
6486 | MF->insert(MF->end(), TrapBB); | ||||
Bill Wendling | 6134655 | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 6487 | |
Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6488 | // Insert code into the entry block that creates and registers the function |
6489 | // context. | ||||
6490 | SetupEntryBlockForSjLj(MI, MBB, DispatchBB, FI); | ||||
6491 | |||||
Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6492 | MachineMemOperand *FIMMOLd = |
Bill Wendling | 362c1b0 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 6493 | MF->getMachineMemOperand(MachinePointerInfo::getFixedStack(FI), |
Bill Wendling | b3d4678 | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 6494 | MachineMemOperand::MOLoad | |
6495 | MachineMemOperand::MOVolatile, 4, 4); | ||||
Bill Wendling | 6134655 | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 6496 | |
Chad Rosier | 1ec8e40 | 2012-11-06 23:05:24 +0000 | [diff] [blame] | 6497 | MachineInstrBuilder MIB; |
6498 | MIB = BuildMI(DispatchBB, dl, TII->get(ARM::Int_eh_sjlj_dispatchsetup)); | ||||
6499 | |||||
6500 | const ARMBaseInstrInfo *AII = static_cast<const ARMBaseInstrInfo*>(TII); | ||||
6501 | const ARMBaseRegisterInfo &RI = AII->getRegisterInfo(); | ||||
6502 | |||||
6503 | // Add a register mask with no preserved registers. This results in all | ||||
6504 | // registers being marked as clobbered. | ||||
6505 | MIB.addRegMask(RI.getNoPreservedMask()); | ||||
Bob Wilson | f6d1728 | 2011-11-16 07:11:57 +0000 | [diff] [blame] | 6506 | |
Bill Wendling | 85833f7 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 6507 | unsigned NumLPads = LPadList.size(); |
Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6508 | if (Subtarget->isThumb2()) { |
6509 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); | ||||
6510 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2LDRi12), NewVReg1) | ||||
6511 | .addFrameIndex(FI) | ||||
6512 | .addImm(4) | ||||
6513 | .addMemOperand(FIMMOLd)); | ||||
Bill Wendling | b2a703d | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 6514 | |
Bill Wendling | 85833f7 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 6515 | if (NumLPads < 256) { |
6516 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2CMPri)) | ||||
6517 | .addReg(NewVReg1) | ||||
6518 | .addImm(LPadList.size())); | ||||
6519 | } else { | ||||
6520 | unsigned VReg1 = MRI->createVirtualRegister(TRC); | ||||
6521 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2MOVi16), VReg1) | ||||
Bill Wendling | 94f6001 | 2011-10-18 23:19:55 +0000 | [diff] [blame] | 6522 | .addImm(NumLPads & 0xFFFF)); |
6523 | |||||
6524 | unsigned VReg2 = VReg1; | ||||
6525 | if ((NumLPads & 0xFFFF0000) != 0) { | ||||
6526 | VReg2 = MRI->createVirtualRegister(TRC); | ||||
6527 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2MOVTi16), VReg2) | ||||
6528 | .addReg(VReg1) | ||||
6529 | .addImm(NumLPads >> 16)); | ||||
6530 | } | ||||
6531 | |||||
Bill Wendling | 85833f7 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 6532 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2CMPrr)) |
6533 | .addReg(NewVReg1) | ||||
6534 | .addReg(VReg2)); | ||||
6535 | } | ||||
Bill Wendling | b2a703d | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 6536 | |
Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6537 | BuildMI(DispatchBB, dl, TII->get(ARM::t2Bcc)) |
6538 | .addMBB(TrapBB) | ||||
6539 | .addImm(ARMCC::HI) | ||||
6540 | .addReg(ARM::CPSR); | ||||
Bill Wendling | 324be98 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6541 | |
Bill Wendling | b2a703d | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 6542 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
6543 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::t2LEApcrelJT),NewVReg3) | ||||
Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6544 | .addJumpTableIndex(MJTI) |
6545 | .addImm(UId)); | ||||
Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6546 | |
Bill Wendling | b2a703d | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 6547 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6548 | AddDefaultCC( |
6549 | AddDefaultPred( | ||||
Bill Wendling | b2a703d | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 6550 | BuildMI(DispContBB, dl, TII->get(ARM::t2ADDrs), NewVReg4) |
6551 | .addReg(NewVReg3, RegState::Kill) | ||||
Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6552 | .addReg(NewVReg1) |
6553 | .addImm(ARM_AM::getSORegOpc(ARM_AM::lsl, 2)))); | ||||
6554 | |||||
6555 | BuildMI(DispContBB, dl, TII->get(ARM::t2BR_JT)) | ||||
Bill Wendling | b2a703d | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 6556 | .addReg(NewVReg4, RegState::Kill) |
Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6557 | .addReg(NewVReg1) |
Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6558 | .addJumpTableIndex(MJTI) |
6559 | .addImm(UId); | ||||
6560 | } else if (Subtarget->isThumb()) { | ||||
Bill Wendling | b3d4678 | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 6561 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
6562 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tLDRspi), NewVReg1) | ||||
6563 | .addFrameIndex(FI) | ||||
6564 | .addImm(1) | ||||
6565 | .addMemOperand(FIMMOLd)); | ||||
Bill Wendling | f9f5e45 | 2011-10-07 22:08:37 +0000 | [diff] [blame] | 6566 | |
Bill Wendling | 64e6bfc | 2011-10-18 23:11:05 +0000 | [diff] [blame] | 6567 | if (NumLPads < 256) { |
6568 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tCMPi8)) | ||||
6569 | .addReg(NewVReg1) | ||||
6570 | .addImm(NumLPads)); | ||||
6571 | } else { | ||||
6572 | MachineConstantPool *ConstantPool = MF->getConstantPool(); | ||||
Bill Wendling | 2977a15 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6573 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); |
6574 | const Constant *C = ConstantInt::get(Int32Ty, NumLPads); | ||||
6575 | |||||
6576 | // MachineConstantPool wants an explicit alignment. | ||||
Micah Villmow | cdfe20b | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 6577 | unsigned Align = getDataLayout()->getPrefTypeAlignment(Int32Ty); |
Bill Wendling | 2977a15 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6578 | if (Align == 0) |
Micah Villmow | cdfe20b | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 6579 | Align = getDataLayout()->getTypeAllocSize(C->getType()); |
Bill Wendling | 2977a15 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6580 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
Bill Wendling | 64e6bfc | 2011-10-18 23:11:05 +0000 | [diff] [blame] | 6581 | |
6582 | unsigned VReg1 = MRI->createVirtualRegister(TRC); | ||||
6583 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tLDRpci)) | ||||
6584 | .addReg(VReg1, RegState::Define) | ||||
6585 | .addConstantPoolIndex(Idx)); | ||||
6586 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tCMPr)) | ||||
6587 | .addReg(NewVReg1) | ||||
6588 | .addReg(VReg1)); | ||||
6589 | } | ||||
6590 | |||||
Bill Wendling | b3d4678 | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 6591 | BuildMI(DispatchBB, dl, TII->get(ARM::tBcc)) |
6592 | .addMBB(TrapBB) | ||||
6593 | .addImm(ARMCC::HI) | ||||
6594 | .addReg(ARM::CPSR); | ||||
6595 | |||||
6596 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); | ||||
6597 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLSLri), NewVReg2) | ||||
6598 | .addReg(ARM::CPSR, RegState::Define) | ||||
6599 | .addReg(NewVReg1) | ||||
6600 | .addImm(2)); | ||||
6601 | |||||
6602 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); | ||||
Bill Wendling | 8d50ea0 | 2011-10-06 23:41:14 +0000 | [diff] [blame] | 6603 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLEApcrelJT), NewVReg3) |
Bill Wendling | b3d4678 | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 6604 | .addJumpTableIndex(MJTI) |
6605 | .addImm(UId)); | ||||
6606 | |||||
6607 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); | ||||
6608 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tADDrr), NewVReg4) | ||||
6609 | .addReg(ARM::CPSR, RegState::Define) | ||||
6610 | .addReg(NewVReg2, RegState::Kill) | ||||
6611 | .addReg(NewVReg3)); | ||||
6612 | |||||
6613 | MachineMemOperand *JTMMOLd = | ||||
6614 | MF->getMachineMemOperand(MachinePointerInfo::getJumpTable(), | ||||
6615 | MachineMemOperand::MOLoad, 4, 4); | ||||
6616 | |||||
6617 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); | ||||
6618 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLDRi), NewVReg5) | ||||
6619 | .addReg(NewVReg4, RegState::Kill) | ||||
6620 | .addImm(0) | ||||
6621 | .addMemOperand(JTMMOLd)); | ||||
6622 | |||||
Chad Rosier | 9660343 | 2013-03-01 18:30:38 +0000 | [diff] [blame] | 6623 | unsigned NewVReg6 = NewVReg5; |
6624 | if (RelocM == Reloc::PIC_) { | ||||
6625 | NewVReg6 = MRI->createVirtualRegister(TRC); | ||||
6626 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tADDrr), NewVReg6) | ||||
6627 | .addReg(ARM::CPSR, RegState::Define) | ||||
6628 | .addReg(NewVReg5, RegState::Kill) | ||||
6629 | .addReg(NewVReg3)); | ||||
6630 | } | ||||
Bill Wendling | b3d4678 | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 6631 | |
6632 | BuildMI(DispContBB, dl, TII->get(ARM::tBR_JTr)) | ||||
6633 | .addReg(NewVReg6, RegState::Kill) | ||||
6634 | .addJumpTableIndex(MJTI) | ||||
6635 | .addImm(UId); | ||||
Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6636 | } else { |
6637 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); | ||||
6638 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::LDRi12), NewVReg1) | ||||
6639 | .addFrameIndex(FI) | ||||
6640 | .addImm(4) | ||||
6641 | .addMemOperand(FIMMOLd)); | ||||
Bill Wendling | 973c817 | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6642 | |
Bill Wendling | 4969dcd | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6643 | if (NumLPads < 256) { |
6644 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPri)) | ||||
6645 | .addReg(NewVReg1) | ||||
6646 | .addImm(NumLPads)); | ||||
Bill Wendling | 2977a15 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6647 | } else if (Subtarget->hasV6T2Ops() && isUInt<16>(NumLPads)) { |
Bill Wendling | 4969dcd | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6648 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
6649 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::MOVi16), VReg1) | ||||
Bill Wendling | 94f6001 | 2011-10-18 23:19:55 +0000 | [diff] [blame] | 6650 | .addImm(NumLPads & 0xFFFF)); |
6651 | |||||
6652 | unsigned VReg2 = VReg1; | ||||
6653 | if ((NumLPads & 0xFFFF0000) != 0) { | ||||
6654 | VReg2 = MRI->createVirtualRegister(TRC); | ||||
6655 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::MOVTi16), VReg2) | ||||
6656 | .addReg(VReg1) | ||||
6657 | .addImm(NumLPads >> 16)); | ||||
6658 | } | ||||
6659 | |||||
Bill Wendling | 4969dcd | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6660 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPrr)) |
6661 | .addReg(NewVReg1) | ||||
6662 | .addReg(VReg2)); | ||||
Bill Wendling | 2977a15 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6663 | } else { |
6664 | MachineConstantPool *ConstantPool = MF->getConstantPool(); | ||||
6665 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); | ||||
6666 | const Constant *C = ConstantInt::get(Int32Ty, NumLPads); | ||||
6667 | |||||
6668 | // MachineConstantPool wants an explicit alignment. | ||||
Micah Villmow | cdfe20b | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 6669 | unsigned Align = getDataLayout()->getPrefTypeAlignment(Int32Ty); |
Bill Wendling | 2977a15 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6670 | if (Align == 0) |
Micah Villmow | cdfe20b | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 6671 | Align = getDataLayout()->getTypeAllocSize(C->getType()); |
Bill Wendling | 2977a15 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6672 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
6673 | |||||
6674 | unsigned VReg1 = MRI->createVirtualRegister(TRC); | ||||
6675 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::LDRcp)) | ||||
6676 | .addReg(VReg1, RegState::Define) | ||||
Bill Wendling | cf7bdf4 | 2011-10-20 20:37:11 +0000 | [diff] [blame] | 6677 | .addConstantPoolIndex(Idx) |
6678 | .addImm(0)); | ||||
Bill Wendling | 2977a15 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6679 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPrr)) |
6680 | .addReg(NewVReg1) | ||||
6681 | .addReg(VReg1, RegState::Kill)); | ||||
Bill Wendling | 4969dcd | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6682 | } |
6683 | |||||
Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6684 | BuildMI(DispatchBB, dl, TII->get(ARM::Bcc)) |
6685 | .addMBB(TrapBB) | ||||
6686 | .addImm(ARMCC::HI) | ||||
6687 | .addReg(ARM::CPSR); | ||||
Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6688 | |
Bill Wendling | 973c817 | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6689 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6690 | AddDefaultCC( |
Bill Wendling | 973c817 | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6691 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::MOVsi), NewVReg3) |
Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6692 | .addReg(NewVReg1) |
6693 | .addImm(ARM_AM::getSORegOpc(ARM_AM::lsl, 2)))); | ||||
Bill Wendling | 973c817 | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6694 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
6695 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::LEApcrelJT), NewVReg4) | ||||
Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6696 | .addJumpTableIndex(MJTI) |
6697 | .addImm(UId)); | ||||
6698 | |||||
6699 | MachineMemOperand *JTMMOLd = | ||||
6700 | MF->getMachineMemOperand(MachinePointerInfo::getJumpTable(), | ||||
6701 | MachineMemOperand::MOLoad, 4, 4); | ||||
Bill Wendling | 973c817 | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6702 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6703 | AddDefaultPred( |
Bill Wendling | 973c817 | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6704 | BuildMI(DispContBB, dl, TII->get(ARM::LDRrs), NewVReg5) |
6705 | .addReg(NewVReg3, RegState::Kill) | ||||
6706 | .addReg(NewVReg4) | ||||
Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6707 | .addImm(0) |
6708 | .addMemOperand(JTMMOLd)); | ||||
6709 | |||||
Chad Rosier | 9660343 | 2013-03-01 18:30:38 +0000 | [diff] [blame] | 6710 | if (RelocM == Reloc::PIC_) { |
6711 | BuildMI(DispContBB, dl, TII->get(ARM::BR_JTadd)) | ||||
6712 | .addReg(NewVReg5, RegState::Kill) | ||||
6713 | .addReg(NewVReg4) | ||||
6714 | .addJumpTableIndex(MJTI) | ||||
6715 | .addImm(UId); | ||||
6716 | } else { | ||||
6717 | BuildMI(DispContBB, dl, TII->get(ARM::BR_JTr)) | ||||
6718 | .addReg(NewVReg5, RegState::Kill) | ||||
6719 | .addJumpTableIndex(MJTI) | ||||
6720 | .addImm(UId); | ||||
6721 | } | ||||
Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6722 | } |
Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6723 | |
Bill Wendling | 324be98 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6724 | // Add the jump table entries as successors to the MBB. |
Jakob Stoklund Olesen | 710093e | 2012-08-20 20:52:03 +0000 | [diff] [blame] | 6725 | SmallPtrSet<MachineBasicBlock*, 8> SeenMBBs; |
Bill Wendling | 324be98 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6726 | for (std::vector<MachineBasicBlock*>::iterator |
Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6727 | I = LPadList.begin(), E = LPadList.end(); I != E; ++I) { |
6728 | MachineBasicBlock *CurMBB = *I; | ||||
Jakob Stoklund Olesen | 710093e | 2012-08-20 20:52:03 +0000 | [diff] [blame] | 6729 | if (SeenMBBs.insert(CurMBB)) |
Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6730 | DispContBB->addSuccessor(CurMBB); |
Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6731 | } |
6732 | |||||
Bill Wendling | 26d2780 | 2011-10-17 05:25:09 +0000 | [diff] [blame] | 6733 | // N.B. the order the invoke BBs are processed in doesn't matter here. |
Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 6734 | const MCPhysReg *SavedRegs = RI.getCalleeSavedRegs(MF); |
Bill Wendling | 617075f | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 6735 | SmallVector<MachineBasicBlock*, 64> MBBLPads; |
Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6736 | for (SmallPtrSet<MachineBasicBlock*, 64>::iterator |
6737 | I = InvokeBBs.begin(), E = InvokeBBs.end(); I != E; ++I) { | ||||
6738 | MachineBasicBlock *BB = *I; | ||||
Bill Wendling | 6f3f9a3 | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6739 | |
6740 | // Remove the landing pad successor from the invoke block and replace it | ||||
6741 | // with the new dispatch block. | ||||
Bill Wendling | 1414bc5 | 2011-10-26 07:16:18 +0000 | [diff] [blame] | 6742 | SmallVector<MachineBasicBlock*, 4> Successors(BB->succ_begin(), |
6743 | BB->succ_end()); | ||||
6744 | while (!Successors.empty()) { | ||||
6745 | MachineBasicBlock *SMBB = Successors.pop_back_val(); | ||||
Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6746 | if (SMBB->isLandingPad()) { |
6747 | BB->removeSuccessor(SMBB); | ||||
Bill Wendling | 617075f | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 6748 | MBBLPads.push_back(SMBB); |
Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6749 | } |
6750 | } | ||||
6751 | |||||
6752 | BB->addSuccessor(DispatchBB); | ||||
Bill Wendling | 6f3f9a3 | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6753 | |
6754 | // Find the invoke call and mark all of the callee-saved registers as | ||||
6755 | // 'implicit defined' so that they're spilled. This prevents code from | ||||
6756 | // moving instructions to before the EH block, where they will never be | ||||
6757 | // executed. | ||||
6758 | for (MachineBasicBlock::reverse_iterator | ||||
6759 | II = BB->rbegin(), IE = BB->rend(); II != IE; ++II) { | ||||
Evan Cheng | 7f8e563 | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 6760 | if (!II->isCall()) continue; |
Bill Wendling | 6f3f9a3 | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6761 | |
6762 | DenseMap<unsigned, bool> DefRegs; | ||||
6763 | for (MachineInstr::mop_iterator | ||||
6764 | OI = II->operands_begin(), OE = II->operands_end(); | ||||
6765 | OI != OE; ++OI) { | ||||
6766 | if (!OI->isReg()) continue; | ||||
6767 | DefRegs[OI->getReg()] = true; | ||||
6768 | } | ||||
6769 | |||||
Jakob Stoklund Olesen | b159b5f | 2012-12-19 21:31:56 +0000 | [diff] [blame] | 6770 | MachineInstrBuilder MIB(*MF, &*II); |
Bill Wendling | 6f3f9a3 | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6771 | |
Bill Wendling | 9e0cd1e | 2011-10-14 23:55:44 +0000 | [diff] [blame] | 6772 | for (unsigned i = 0; SavedRegs[i] != 0; ++i) { |
Bill Wendling | 94e6643 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 6773 | unsigned Reg = SavedRegs[i]; |
6774 | if (Subtarget->isThumb2() && | ||||
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6775 | !ARM::tGPRRegClass.contains(Reg) && |
6776 | !ARM::hGPRRegClass.contains(Reg)) | ||||
Bill Wendling | 94e6643 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 6777 | continue; |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6778 | if (Subtarget->isThumb1Only() && !ARM::tGPRRegClass.contains(Reg)) |
Bill Wendling | 94e6643 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 6779 | continue; |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6780 | if (!Subtarget->isThumb() && !ARM::GPRRegClass.contains(Reg)) |
Bill Wendling | 94e6643 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 6781 | continue; |
6782 | if (!DefRegs[Reg]) | ||||
6783 | MIB.addReg(Reg, RegState::ImplicitDefine | RegState::Dead); | ||||
Bill Wendling | 9e0cd1e | 2011-10-14 23:55:44 +0000 | [diff] [blame] | 6784 | } |
Bill Wendling | 6f3f9a3 | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6785 | |
6786 | break; | ||||
6787 | } | ||||
Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6788 | } |
Bill Wendling | 324be98 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6789 | |
Bill Wendling | 617075f | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 6790 | // Mark all former landing pads as non-landing pads. The dispatch is the only |
6791 | // landing pad now. | ||||
6792 | for (SmallVectorImpl<MachineBasicBlock*>::iterator | ||||
6793 | I = MBBLPads.begin(), E = MBBLPads.end(); I != E; ++I) | ||||
6794 | (*I)->setIsLandingPad(false); | ||||
6795 | |||||
Bill Wendling | 324be98 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6796 | // The instruction is gone now. |
6797 | MI->eraseFromParent(); | ||||
6798 | |||||
Bill Wendling | 374ee19 | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6799 | return MBB; |
6800 | } | ||||
6801 | |||||
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 6802 | static |
6803 | MachineBasicBlock *OtherSucc(MachineBasicBlock *MBB, MachineBasicBlock *Succ) { | ||||
6804 | for (MachineBasicBlock::succ_iterator I = MBB->succ_begin(), | ||||
6805 | E = MBB->succ_end(); I != E; ++I) | ||||
6806 | if (*I != Succ) | ||||
6807 | return *I; | ||||
6808 | llvm_unreachable("Expecting a BB with two successors!"); | ||||
6809 | } | ||||
6810 | |||||
Manman Ren | b504f49 | 2013-10-29 22:27:32 +0000 | [diff] [blame] | 6811 | /// Return the load opcode for a given load size. If load size >= 8, |
6812 | /// neon opcode will be returned. | ||||
6813 | static unsigned getLdOpcode(unsigned LdSize, bool IsThumb1, bool IsThumb2) { | ||||
6814 | if (LdSize >= 8) | ||||
6815 | return LdSize == 16 ? ARM::VLD1q32wb_fixed | ||||
6816 | : LdSize == 8 ? ARM::VLD1d32wb_fixed : 0; | ||||
6817 | if (IsThumb1) | ||||
6818 | return LdSize == 4 ? ARM::tLDRi | ||||
6819 | : LdSize == 2 ? ARM::tLDRHi | ||||
6820 | : LdSize == 1 ? ARM::tLDRBi : 0; | ||||
6821 | if (IsThumb2) | ||||
6822 | return LdSize == 4 ? ARM::t2LDR_POST | ||||
6823 | : LdSize == 2 ? ARM::t2LDRH_POST | ||||
6824 | : LdSize == 1 ? ARM::t2LDRB_POST : 0; | ||||
6825 | return LdSize == 4 ? ARM::LDR_POST_IMM | ||||
6826 | : LdSize == 2 ? ARM::LDRH_POST | ||||
6827 | : LdSize == 1 ? ARM::LDRB_POST_IMM : 0; | ||||
6828 | } | ||||
6829 | |||||
6830 | /// Return the store opcode for a given store size. If store size >= 8, | ||||
6831 | /// neon opcode will be returned. | ||||
6832 | static unsigned getStOpcode(unsigned StSize, bool IsThumb1, bool IsThumb2) { | ||||
6833 | if (StSize >= 8) | ||||
6834 | return StSize == 16 ? ARM::VST1q32wb_fixed | ||||
6835 | : StSize == 8 ? ARM::VST1d32wb_fixed : 0; | ||||
6836 | if (IsThumb1) | ||||
6837 | return StSize == 4 ? ARM::tSTRi | ||||
6838 | : StSize == 2 ? ARM::tSTRHi | ||||
6839 | : StSize == 1 ? ARM::tSTRBi : 0; | ||||
6840 | if (IsThumb2) | ||||
6841 | return StSize == 4 ? ARM::t2STR_POST | ||||
6842 | : StSize == 2 ? ARM::t2STRH_POST | ||||
6843 | : StSize == 1 ? ARM::t2STRB_POST : 0; | ||||
6844 | return StSize == 4 ? ARM::STR_POST_IMM | ||||
6845 | : StSize == 2 ? ARM::STRH_POST | ||||
6846 | : StSize == 1 ? ARM::STRB_POST_IMM : 0; | ||||
6847 | } | ||||
6848 | |||||
6849 | /// Emit a post-increment load operation with given size. The instructions | ||||
6850 | /// will be added to BB at Pos. | ||||
6851 | static void emitPostLd(MachineBasicBlock *BB, MachineInstr *Pos, | ||||
6852 | const TargetInstrInfo *TII, DebugLoc dl, | ||||
6853 | unsigned LdSize, unsigned Data, unsigned AddrIn, | ||||
6854 | unsigned AddrOut, bool IsThumb1, bool IsThumb2) { | ||||
6855 | unsigned LdOpc = getLdOpcode(LdSize, IsThumb1, IsThumb2); | ||||
6856 | assert(LdOpc != 0 && "Should have a load opcode"); | ||||
6857 | if (LdSize >= 8) { | ||||
6858 | AddDefaultPred(BuildMI(*BB, Pos, dl, TII->get(LdOpc), Data) | ||||
6859 | .addReg(AddrOut, RegState::Define).addReg(AddrIn) | ||||
6860 | .addImm(0)); | ||||
6861 | } else if (IsThumb1) { | ||||
6862 | // load + update AddrIn | ||||
6863 | AddDefaultPred(BuildMI(*BB, Pos, dl, TII->get(LdOpc), Data) | ||||
6864 | .addReg(AddrIn).addImm(0)); | ||||
6865 | MachineInstrBuilder MIB = | ||||
6866 | BuildMI(*BB, Pos, dl, TII->get(ARM::tADDi8), AddrOut); | ||||
6867 | MIB = AddDefaultT1CC(MIB); | ||||
6868 | MIB.addReg(AddrIn).addImm(LdSize); | ||||
6869 | AddDefaultPred(MIB); | ||||
6870 | } else if (IsThumb2) { | ||||
6871 | AddDefaultPred(BuildMI(*BB, Pos, dl, TII->get(LdOpc), Data) | ||||
6872 | .addReg(AddrOut, RegState::Define).addReg(AddrIn) | ||||
6873 | .addImm(LdSize)); | ||||
6874 | } else { // arm | ||||
6875 | AddDefaultPred(BuildMI(*BB, Pos, dl, TII->get(LdOpc), Data) | ||||
6876 | .addReg(AddrOut, RegState::Define).addReg(AddrIn) | ||||
6877 | .addReg(0).addImm(LdSize)); | ||||
6878 | } | ||||
6879 | } | ||||
6880 | |||||
6881 | /// Emit a post-increment store operation with given size. The instructions | ||||
6882 | /// will be added to BB at Pos. | ||||
6883 | static void emitPostSt(MachineBasicBlock *BB, MachineInstr *Pos, | ||||
6884 | const TargetInstrInfo *TII, DebugLoc dl, | ||||
6885 | unsigned StSize, unsigned Data, unsigned AddrIn, | ||||
6886 | unsigned AddrOut, bool IsThumb1, bool IsThumb2) { | ||||
6887 | unsigned StOpc = getStOpcode(StSize, IsThumb1, IsThumb2); | ||||
6888 | assert(StOpc != 0 && "Should have a store opcode"); | ||||
6889 | if (StSize >= 8) { | ||||
6890 | AddDefaultPred(BuildMI(*BB, Pos, dl, TII->get(StOpc), AddrOut) | ||||
6891 | .addReg(AddrIn).addImm(0).addReg(Data)); | ||||
6892 | } else if (IsThumb1) { | ||||
6893 | // store + update AddrIn | ||||
6894 | AddDefaultPred(BuildMI(*BB, Pos, dl, TII->get(StOpc)).addReg(Data) | ||||
6895 | .addReg(AddrIn).addImm(0)); | ||||
6896 | MachineInstrBuilder MIB = | ||||
6897 | BuildMI(*BB, Pos, dl, TII->get(ARM::tADDi8), AddrOut); | ||||
6898 | MIB = AddDefaultT1CC(MIB); | ||||
6899 | MIB.addReg(AddrIn).addImm(StSize); | ||||
6900 | AddDefaultPred(MIB); | ||||
6901 | } else if (IsThumb2) { | ||||
6902 | AddDefaultPred(BuildMI(*BB, Pos, dl, TII->get(StOpc), AddrOut) | ||||
6903 | .addReg(Data).addReg(AddrIn).addImm(StSize)); | ||||
6904 | } else { // arm | ||||
6905 | AddDefaultPred(BuildMI(*BB, Pos, dl, TII->get(StOpc), AddrOut) | ||||
6906 | .addReg(Data).addReg(AddrIn).addReg(0) | ||||
6907 | .addImm(StSize)); | ||||
6908 | } | ||||
6909 | } | ||||
6910 | |||||
David Peixotto | c32e24a | 2013-10-17 19:49:22 +0000 | [diff] [blame] | 6911 | MachineBasicBlock * |
6912 | ARMTargetLowering::EmitStructByval(MachineInstr *MI, | ||||
6913 | MachineBasicBlock *BB) const { | ||||
Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6914 | // This pseudo instruction has 3 operands: dst, src, size |
6915 | // We expand it to a loop if size > Subtarget->getMaxInlineSizeThreshold(). | ||||
6916 | // Otherwise, we will generate unrolled scalar copies. | ||||
6917 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); | ||||
6918 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); | ||||
6919 | MachineFunction::iterator It = BB; | ||||
6920 | ++It; | ||||
6921 | |||||
6922 | unsigned dest = MI->getOperand(0).getReg(); | ||||
6923 | unsigned src = MI->getOperand(1).getReg(); | ||||
6924 | unsigned SizeVal = MI->getOperand(2).getImm(); | ||||
6925 | unsigned Align = MI->getOperand(3).getImm(); | ||||
6926 | DebugLoc dl = MI->getDebugLoc(); | ||||
6927 | |||||
Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6928 | MachineFunction *MF = BB->getParent(); |
6929 | MachineRegisterInfo &MRI = MF->getRegInfo(); | ||||
David Peixotto | c32e24a | 2013-10-17 19:49:22 +0000 | [diff] [blame] | 6930 | unsigned UnitSize = 0; |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 6931 | const TargetRegisterClass *TRC = nullptr; |
6932 | const TargetRegisterClass *VecTRC = nullptr; | ||||
David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 6933 | |
6934 | bool IsThumb1 = Subtarget->isThumb1Only(); | ||||
6935 | bool IsThumb2 = Subtarget->isThumb2(); | ||||
Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6936 | |
6937 | if (Align & 1) { | ||||
Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6938 | UnitSize = 1; |
6939 | } else if (Align & 2) { | ||||
Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6940 | UnitSize = 2; |
6941 | } else { | ||||
Manman Ren | 6e1fd46 | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6942 | // Check whether we can use NEON instructions. |
Bill Wendling | 698e84f | 2012-12-30 10:32:01 +0000 | [diff] [blame] | 6943 | if (!MF->getFunction()->getAttributes(). |
6944 | hasAttribute(AttributeSet::FunctionIndex, | ||||
6945 | Attribute::NoImplicitFloat) && | ||||
Manman Ren | 6e1fd46 | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6946 | Subtarget->hasNEON()) { |
David Peixotto | c32e24a | 2013-10-17 19:49:22 +0000 | [diff] [blame] | 6947 | if ((Align % 16 == 0) && SizeVal >= 16) |
Manman Ren | 6e1fd46 | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6948 | UnitSize = 16; |
David Peixotto | c32e24a | 2013-10-17 19:49:22 +0000 | [diff] [blame] | 6949 | else if ((Align % 8 == 0) && SizeVal >= 8) |
Manman Ren | 6e1fd46 | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6950 | UnitSize = 8; |
Manman Ren | 6e1fd46 | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6951 | } |
6952 | // Can't use NEON instructions. | ||||
David Peixotto | c32e24a | 2013-10-17 19:49:22 +0000 | [diff] [blame] | 6953 | if (UnitSize == 0) |
Manman Ren | 6e1fd46 | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6954 | UnitSize = 4; |
Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6955 | } |
Manman Ren | 6e1fd46 | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6956 | |
David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 6957 | // Select the correct opcode and register class for unit size load/store |
6958 | bool IsNeon = UnitSize >= 8; | ||||
6959 | TRC = (IsThumb1 || IsThumb2) ? (const TargetRegisterClass *)&ARM::tGPRRegClass | ||||
6960 | : (const TargetRegisterClass *)&ARM::GPRRegClass; | ||||
Manman Ren | b504f49 | 2013-10-29 22:27:32 +0000 | [diff] [blame] | 6961 | if (IsNeon) |
David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 6962 | VecTRC = UnitSize == 16 |
6963 | ? (const TargetRegisterClass *)&ARM::DPairRegClass | ||||
6964 | : UnitSize == 8 | ||||
6965 | ? (const TargetRegisterClass *)&ARM::DPRRegClass | ||||
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 6966 | : nullptr; |
David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 6967 | |
Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6968 | unsigned BytesLeft = SizeVal % UnitSize; |
6969 | unsigned LoopSize = SizeVal - BytesLeft; | ||||
6970 | |||||
6971 | if (SizeVal <= Subtarget->getMaxInlineSizeThreshold()) { | ||||
6972 | // Use LDR and STR to copy. | ||||
6973 | // [scratch, srcOut] = LDR_POST(srcIn, UnitSize) | ||||
6974 | // [destOut] = STR_POST(scratch, destIn, UnitSize) | ||||
6975 | unsigned srcIn = src; | ||||
6976 | unsigned destIn = dest; | ||||
6977 | for (unsigned i = 0; i < LoopSize; i+=UnitSize) { | ||||
David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 6978 | unsigned srcOut = MRI.createVirtualRegister(TRC); |
6979 | unsigned destOut = MRI.createVirtualRegister(TRC); | ||||
6980 | unsigned scratch = MRI.createVirtualRegister(IsNeon ? VecTRC : TRC); | ||||
Manman Ren | b504f49 | 2013-10-29 22:27:32 +0000 | [diff] [blame] | 6981 | emitPostLd(BB, MI, TII, dl, UnitSize, scratch, srcIn, srcOut, |
6982 | IsThumb1, IsThumb2); | ||||
6983 | emitPostSt(BB, MI, TII, dl, UnitSize, scratch, destIn, destOut, | ||||
6984 | IsThumb1, IsThumb2); | ||||
David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 6985 | srcIn = srcOut; |
6986 | destIn = destOut; | ||||
Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6987 | } |
6988 | |||||
6989 | // Handle the leftover bytes with LDRB and STRB. | ||||
6990 | // [scratch, srcOut] = LDRB_POST(srcIn, 1) | ||||
6991 | // [destOut] = STRB_POST(scratch, destIn, 1) | ||||
Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6992 | for (unsigned i = 0; i < BytesLeft; i++) { |
David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 6993 | unsigned srcOut = MRI.createVirtualRegister(TRC); |
6994 | unsigned destOut = MRI.createVirtualRegister(TRC); | ||||
6995 | unsigned scratch = MRI.createVirtualRegister(TRC); | ||||
Manman Ren | b504f49 | 2013-10-29 22:27:32 +0000 | [diff] [blame] | 6996 | emitPostLd(BB, MI, TII, dl, 1, scratch, srcIn, srcOut, |
6997 | IsThumb1, IsThumb2); | ||||
6998 | emitPostSt(BB, MI, TII, dl, 1, scratch, destIn, destOut, | ||||
6999 | IsThumb1, IsThumb2); | ||||
David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7000 | srcIn = srcOut; |
7001 | destIn = destOut; | ||||
Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7002 | } |
7003 | MI->eraseFromParent(); // The instruction is gone now. | ||||
7004 | return BB; | ||||
7005 | } | ||||
7006 | |||||
7007 | // Expand the pseudo op to a loop. | ||||
7008 | // thisMBB: | ||||
7009 | // ... | ||||
7010 | // movw varEnd, # --> with thumb2 | ||||
7011 | // movt varEnd, # | ||||
7012 | // ldrcp varEnd, idx --> without thumb2 | ||||
7013 | // fallthrough --> loopMBB | ||||
7014 | // loopMBB: | ||||
7015 | // PHI varPhi, varEnd, varLoop | ||||
7016 | // PHI srcPhi, src, srcLoop | ||||
7017 | // PHI destPhi, dst, destLoop | ||||
7018 | // [scratch, srcLoop] = LDR_POST(srcPhi, UnitSize) | ||||
7019 | // [destLoop] = STR_POST(scratch, destPhi, UnitSize) | ||||
7020 | // subs varLoop, varPhi, #UnitSize | ||||
7021 | // bne loopMBB | ||||
7022 | // fallthrough --> exitMBB | ||||
7023 | // exitMBB: | ||||
7024 | // epilogue to handle left-over bytes | ||||
7025 | // [scratch, srcOut] = LDRB_POST(srcLoop, 1) | ||||
7026 | // [destOut] = STRB_POST(scratch, destLoop, 1) | ||||
7027 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); | ||||
7028 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); | ||||
7029 | MF->insert(It, loopMBB); | ||||
7030 | MF->insert(It, exitMBB); | ||||
7031 | |||||
7032 | // Transfer the remainder of BB and its successor edges to exitMBB. | ||||
7033 | exitMBB->splice(exitMBB->begin(), BB, | ||||
Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 7034 | std::next(MachineBasicBlock::iterator(MI)), BB->end()); |
Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7035 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
7036 | |||||
7037 | // Load an immediate to varEnd. | ||||
David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7038 | unsigned varEnd = MRI.createVirtualRegister(TRC); |
7039 | if (IsThumb2) { | ||||
7040 | unsigned Vtmp = varEnd; | ||||
7041 | if ((LoopSize & 0xFFFF0000) != 0) | ||||
7042 | Vtmp = MRI.createVirtualRegister(TRC); | ||||
7043 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::t2MOVi16), Vtmp) | ||||
7044 | .addImm(LoopSize & 0xFFFF)); | ||||
7045 | |||||
7046 | if ((LoopSize & 0xFFFF0000) != 0) | ||||
7047 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::t2MOVTi16), varEnd) | ||||
7048 | .addReg(Vtmp).addImm(LoopSize >> 16)); | ||||
7049 | } else { | ||||
7050 | MachineConstantPool *ConstantPool = MF->getConstantPool(); | ||||
7051 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); | ||||
7052 | const Constant *C = ConstantInt::get(Int32Ty, LoopSize); | ||||
7053 | |||||
7054 | // MachineConstantPool wants an explicit alignment. | ||||
7055 | unsigned Align = getDataLayout()->getPrefTypeAlignment(Int32Ty); | ||||
7056 | if (Align == 0) | ||||
7057 | Align = getDataLayout()->getTypeAllocSize(C->getType()); | ||||
7058 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); | ||||
7059 | |||||
7060 | if (IsThumb1) | ||||
7061 | AddDefaultPred(BuildMI(*BB, MI, dl, TII->get(ARM::tLDRpci)).addReg( | ||||
7062 | varEnd, RegState::Define).addConstantPoolIndex(Idx)); | ||||
7063 | else | ||||
7064 | AddDefaultPred(BuildMI(*BB, MI, dl, TII->get(ARM::LDRcp)).addReg( | ||||
7065 | varEnd, RegState::Define).addConstantPoolIndex(Idx).addImm(0)); | ||||
7066 | } | ||||
Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7067 | BB->addSuccessor(loopMBB); |
7068 | |||||
7069 | // Generate the loop body: | ||||
7070 | // varPhi = PHI(varLoop, varEnd) | ||||
7071 | // srcPhi = PHI(srcLoop, src) | ||||
7072 | // destPhi = PHI(destLoop, dst) | ||||
7073 | MachineBasicBlock *entryBB = BB; | ||||
7074 | BB = loopMBB; | ||||
David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7075 | unsigned varLoop = MRI.createVirtualRegister(TRC); |
7076 | unsigned varPhi = MRI.createVirtualRegister(TRC); | ||||
7077 | unsigned srcLoop = MRI.createVirtualRegister(TRC); | ||||
7078 | unsigned srcPhi = MRI.createVirtualRegister(TRC); | ||||
7079 | unsigned destLoop = MRI.createVirtualRegister(TRC); | ||||
7080 | unsigned destPhi = MRI.createVirtualRegister(TRC); | ||||
Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7081 | |
7082 | BuildMI(*BB, BB->begin(), dl, TII->get(ARM::PHI), varPhi) | ||||
7083 | .addReg(varLoop).addMBB(loopMBB) | ||||
7084 | .addReg(varEnd).addMBB(entryBB); | ||||
7085 | BuildMI(BB, dl, TII->get(ARM::PHI), srcPhi) | ||||
7086 | .addReg(srcLoop).addMBB(loopMBB) | ||||
7087 | .addReg(src).addMBB(entryBB); | ||||
7088 | BuildMI(BB, dl, TII->get(ARM::PHI), destPhi) | ||||
7089 | .addReg(destLoop).addMBB(loopMBB) | ||||
7090 | .addReg(dest).addMBB(entryBB); | ||||
7091 | |||||
7092 | // [scratch, srcLoop] = LDR_POST(srcPhi, UnitSize) | ||||
7093 | // [destLoop] = STR_POST(scratch, destPhi, UnitSiz) | ||||
David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7094 | unsigned scratch = MRI.createVirtualRegister(IsNeon ? VecTRC : TRC); |
Manman Ren | b504f49 | 2013-10-29 22:27:32 +0000 | [diff] [blame] | 7095 | emitPostLd(BB, BB->end(), TII, dl, UnitSize, scratch, srcPhi, srcLoop, |
7096 | IsThumb1, IsThumb2); | ||||
7097 | emitPostSt(BB, BB->end(), TII, dl, UnitSize, scratch, destPhi, destLoop, | ||||
7098 | IsThumb1, IsThumb2); | ||||
Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7099 | |
7100 | // Decrement loop variable by UnitSize. | ||||
David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7101 | if (IsThumb1) { |
7102 | MachineInstrBuilder MIB = | ||||
7103 | BuildMI(*BB, BB->end(), dl, TII->get(ARM::tSUBi8), varLoop); | ||||
7104 | MIB = AddDefaultT1CC(MIB); | ||||
7105 | MIB.addReg(varPhi).addImm(UnitSize); | ||||
7106 | AddDefaultPred(MIB); | ||||
7107 | } else { | ||||
7108 | MachineInstrBuilder MIB = | ||||
7109 | BuildMI(*BB, BB->end(), dl, | ||||
7110 | TII->get(IsThumb2 ? ARM::t2SUBri : ARM::SUBri), varLoop); | ||||
7111 | AddDefaultCC(AddDefaultPred(MIB.addReg(varPhi).addImm(UnitSize))); | ||||
7112 | MIB->getOperand(5).setReg(ARM::CPSR); | ||||
7113 | MIB->getOperand(5).setIsDef(true); | ||||
7114 | } | ||||
7115 | BuildMI(*BB, BB->end(), dl, | ||||
7116 | TII->get(IsThumb1 ? ARM::tBcc : IsThumb2 ? ARM::t2Bcc : ARM::Bcc)) | ||||
7117 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); | ||||
Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7118 | |
7119 | // loopMBB can loop back to loopMBB or fall through to exitMBB. | ||||
7120 | BB->addSuccessor(loopMBB); | ||||
7121 | BB->addSuccessor(exitMBB); | ||||
7122 | |||||
7123 | // Add epilogue to handle BytesLeft. | ||||
7124 | BB = exitMBB; | ||||
7125 | MachineInstr *StartOfExit = exitMBB->begin(); | ||||
Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7126 | |
7127 | // [scratch, srcOut] = LDRB_POST(srcLoop, 1) | ||||
7128 | // [destOut] = STRB_POST(scratch, destLoop, 1) | ||||
7129 | unsigned srcIn = srcLoop; | ||||
7130 | unsigned destIn = destLoop; | ||||
7131 | for (unsigned i = 0; i < BytesLeft; i++) { | ||||
David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7132 | unsigned srcOut = MRI.createVirtualRegister(TRC); |
7133 | unsigned destOut = MRI.createVirtualRegister(TRC); | ||||
7134 | unsigned scratch = MRI.createVirtualRegister(TRC); | ||||
Manman Ren | b504f49 | 2013-10-29 22:27:32 +0000 | [diff] [blame] | 7135 | emitPostLd(BB, StartOfExit, TII, dl, 1, scratch, srcIn, srcOut, |
7136 | IsThumb1, IsThumb2); | ||||
7137 | emitPostSt(BB, StartOfExit, TII, dl, 1, scratch, destIn, destOut, | ||||
7138 | IsThumb1, IsThumb2); | ||||
David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7139 | srcIn = srcOut; |
7140 | destIn = destOut; | ||||
Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7141 | } |
7142 | |||||
7143 | MI->eraseFromParent(); // The instruction is gone now. | ||||
7144 | return BB; | ||||
7145 | } | ||||
7146 | |||||
Jim Grosbach | 8f9a3ac | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 7147 | MachineBasicBlock * |
Evan Cheng | 29cfb67 | 2008-01-30 18:18:23 +0000 | [diff] [blame] | 7148 | ARMTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
Dan Gohman | 25c1653 | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 7149 | MachineBasicBlock *BB) const { |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7150 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Dale Johannesen | 7647da6 | 2009-02-13 02:25:56 +0000 | [diff] [blame] | 7151 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | 57ccc19 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 7152 | bool isThumb2 = Subtarget->isThumb2(); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7153 | switch (MI->getOpcode()) { |
Andrew Trick | 0ed5778 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 7154 | default: { |
Jim Grosbach | 5c4e99f | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 7155 | MI->dump(); |
Evan Cheng | b972e56 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 7156 | llvm_unreachable("Unexpected instr type to insert"); |
Andrew Trick | 0ed5778 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 7157 | } |
Jim Grosbach | 9c0b86a | 2011-09-16 21:55:56 +0000 | [diff] [blame] | 7158 | // The Thumb2 pre-indexed stores have the same MI operands, they just |
7159 | // define them differently in the .td files from the isel patterns, so | ||||
7160 | // they need pseudos. | ||||
7161 | case ARM::t2STR_preidx: | ||||
7162 | MI->setDesc(TII->get(ARM::t2STR_PRE)); | ||||
7163 | return BB; | ||||
7164 | case ARM::t2STRB_preidx: | ||||
7165 | MI->setDesc(TII->get(ARM::t2STRB_PRE)); | ||||
7166 | return BB; | ||||
7167 | case ARM::t2STRH_preidx: | ||||
7168 | MI->setDesc(TII->get(ARM::t2STRH_PRE)); | ||||
7169 | return BB; | ||||
7170 | |||||
Jim Grosbach | f0c95ca | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 7171 | case ARM::STRi_preidx: |
7172 | case ARM::STRBi_preidx: { | ||||
Jim Grosbach | 5e80abb | 2011-08-09 21:22:41 +0000 | [diff] [blame] | 7173 | unsigned NewOpc = MI->getOpcode() == ARM::STRi_preidx ? |
Jim Grosbach | f0c95ca | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 7174 | ARM::STR_PRE_IMM : ARM::STRB_PRE_IMM; |
7175 | // Decode the offset. | ||||
7176 | unsigned Offset = MI->getOperand(4).getImm(); | ||||
7177 | bool isSub = ARM_AM::getAM2Op(Offset) == ARM_AM::sub; | ||||
7178 | Offset = ARM_AM::getAM2Offset(Offset); | ||||
7179 | if (isSub) | ||||
7180 | Offset = -Offset; | ||||
7181 | |||||
Jim Grosbach | f402f69 | 2011-08-12 21:02:34 +0000 | [diff] [blame] | 7182 | MachineMemOperand *MMO = *MI->memoperands_begin(); |
Benjamin Kramer | 61a1ff5 | 2011-08-27 17:36:14 +0000 | [diff] [blame] | 7183 | BuildMI(*BB, MI, dl, TII->get(NewOpc)) |
Jim Grosbach | f0c95ca | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 7184 | .addOperand(MI->getOperand(0)) // Rn_wb |
7185 | .addOperand(MI->getOperand(1)) // Rt | ||||
7186 | .addOperand(MI->getOperand(2)) // Rn | ||||
7187 | .addImm(Offset) // offset (skip GPR==zero_reg) | ||||
7188 | .addOperand(MI->getOperand(5)) // pred | ||||
Jim Grosbach | f402f69 | 2011-08-12 21:02:34 +0000 | [diff] [blame] | 7189 | .addOperand(MI->getOperand(6)) |
7190 | .addMemOperand(MMO); | ||||
Jim Grosbach | f0c95ca | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 7191 | MI->eraseFromParent(); |
7192 | return BB; | ||||
7193 | } | ||||
7194 | case ARM::STRr_preidx: | ||||
Jim Grosbach | d886f8c | 2011-08-11 21:17:22 +0000 | [diff] [blame] | 7195 | case ARM::STRBr_preidx: |
7196 | case ARM::STRH_preidx: { | ||||
7197 | unsigned NewOpc; | ||||
7198 | switch (MI->getOpcode()) { | ||||
7199 | default: llvm_unreachable("unexpected opcode!"); | ||||
7200 | case ARM::STRr_preidx: NewOpc = ARM::STR_PRE_REG; break; | ||||
7201 | case ARM::STRBr_preidx: NewOpc = ARM::STRB_PRE_REG; break; | ||||
7202 | case ARM::STRH_preidx: NewOpc = ARM::STRH_PRE; break; | ||||
7203 | } | ||||
Jim Grosbach | f0c95ca | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 7204 | MachineInstrBuilder MIB = BuildMI(*BB, MI, dl, TII->get(NewOpc)); |
7205 | for (unsigned i = 0; i < MI->getNumOperands(); ++i) | ||||
7206 | MIB.addOperand(MI->getOperand(i)); | ||||
7207 | MI->eraseFromParent(); | ||||
7208 | return BB; | ||||
7209 | } | ||||
Eli Friedman | c3f9c4a | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 7210 | |
Evan Cheng | bb2af35 | 2009-08-12 05:17:19 +0000 | [diff] [blame] | 7211 | case ARM::tMOVCCr_pseudo: { |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7212 | // To "insert" a SELECT_CC instruction, we actually have to insert the |
7213 | // diamond control-flow pattern. The incoming instruction knows the | ||||
7214 | // destination vreg to set, the condition code register to branch on, the | ||||
7215 | // true/false values to select between, and a branch opcode to use. | ||||
7216 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); | ||||
Dan Gohman | 3b46030 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 7217 | MachineFunction::iterator It = BB; |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7218 | ++It; |
7219 | |||||
7220 | // thisMBB: | ||||
7221 | // ... | ||||
7222 | // TrueVal = ... | ||||
7223 | // cmpTY ccX, r1, r2 | ||||
7224 | // bCC copy1MBB | ||||
7225 | // fallthrough --> copy0MBB | ||||
7226 | MachineBasicBlock *thisMBB = BB; | ||||
Dan Gohman | 3b46030 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 7227 | MachineFunction *F = BB->getParent(); |
7228 | MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); | ||||
7229 | MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); | ||||
Dan Gohman | f4f0410 | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 7230 | F->insert(It, copy0MBB); |
7231 | F->insert(It, sinkMBB); | ||||
Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 7232 | |
7233 | // Transfer the remainder of BB and its successor edges to sinkMBB. | ||||
7234 | sinkMBB->splice(sinkMBB->begin(), BB, | ||||
Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 7235 | std::next(MachineBasicBlock::iterator(MI)), BB->end()); |
Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 7236 | sinkMBB->transferSuccessorsAndUpdatePHIs(BB); |
7237 | |||||
Dan Gohman | f4f0410 | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 7238 | BB->addSuccessor(copy0MBB); |
7239 | BB->addSuccessor(sinkMBB); | ||||
Dan Gohman | 1220564 | 2010-07-06 15:18:19 +0000 | [diff] [blame] | 7240 | |
Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 7241 | BuildMI(BB, dl, TII->get(ARM::tBcc)).addMBB(sinkMBB) |
7242 | .addImm(MI->getOperand(3).getImm()).addReg(MI->getOperand(4).getReg()); | ||||
7243 | |||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7244 | // copy0MBB: |
7245 | // %FalseValue = ... | ||||
7246 | // # fallthrough to sinkMBB | ||||
7247 | BB = copy0MBB; | ||||
7248 | |||||
7249 | // Update machine-CFG edges | ||||
7250 | BB->addSuccessor(sinkMBB); | ||||
7251 | |||||
7252 | // sinkMBB: | ||||
7253 | // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] | ||||
7254 | // ... | ||||
7255 | BB = sinkMBB; | ||||
Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 7256 | BuildMI(*BB, BB->begin(), dl, |
7257 | TII->get(ARM::PHI), MI->getOperand(0).getReg()) | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7258 | .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB) |
7259 | .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB); | ||||
7260 | |||||
Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 7261 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7262 | return BB; |
7263 | } | ||||
Evan Cheng | b972e56 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 7264 | |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 7265 | case ARM::BCCi64: |
7266 | case ARM::BCCZi64: { | ||||
Bob Wilson | 36be00c | 2010-12-23 22:45:49 +0000 | [diff] [blame] | 7267 | // If there is an unconditional branch to the other successor, remove it. |
Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 7268 | BB->erase(std::next(MachineBasicBlock::iterator(MI)), BB->end()); |
Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 7269 | |
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 7270 | // Compare both parts that make up the double comparison separately for |
7271 | // equality. | ||||
7272 | bool RHSisZero = MI->getOpcode() == ARM::BCCZi64; | ||||
7273 | |||||
7274 | unsigned LHS1 = MI->getOperand(1).getReg(); | ||||
7275 | unsigned LHS2 = MI->getOperand(2).getReg(); | ||||
7276 | if (RHSisZero) { | ||||
7277 | AddDefaultPred(BuildMI(BB, dl, | ||||
7278 | TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) | ||||
7279 | .addReg(LHS1).addImm(0)); | ||||
7280 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) | ||||
7281 | .addReg(LHS2).addImm(0) | ||||
7282 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); | ||||
7283 | } else { | ||||
7284 | unsigned RHS1 = MI->getOperand(3).getReg(); | ||||
7285 | unsigned RHS2 = MI->getOperand(4).getReg(); | ||||
7286 | AddDefaultPred(BuildMI(BB, dl, | ||||
7287 | TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) | ||||
7288 | .addReg(LHS1).addReg(RHS1)); | ||||
7289 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) | ||||
7290 | .addReg(LHS2).addReg(RHS2) | ||||
7291 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); | ||||
7292 | } | ||||
7293 | |||||
7294 | MachineBasicBlock *destMBB = MI->getOperand(RHSisZero ? 3 : 5).getMBB(); | ||||
7295 | MachineBasicBlock *exitMBB = OtherSucc(BB, destMBB); | ||||
7296 | if (MI->getOperand(0).getImm() == ARMCC::NE) | ||||
7297 | std::swap(destMBB, exitMBB); | ||||
7298 | |||||
7299 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) | ||||
7300 | .addMBB(destMBB).addImm(ARMCC::EQ).addReg(ARM::CPSR); | ||||
Owen Anderson | 29cfe6c | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 7301 | if (isThumb2) |
7302 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::t2B)).addMBB(exitMBB)); | ||||
7303 | else | ||||
7304 | BuildMI(BB, dl, TII->get(ARM::B)) .addMBB(exitMBB); | ||||
Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 7305 | |
7306 | MI->eraseFromParent(); // The pseudo instruction is gone now. | ||||
7307 | return BB; | ||||
7308 | } | ||||
Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7309 | |
Bill Wendling | f7f223f | 2011-10-17 20:37:20 +0000 | [diff] [blame] | 7310 | case ARM::Int_eh_sjlj_setjmp: |
7311 | case ARM::Int_eh_sjlj_setjmp_nofp: | ||||
7312 | case ARM::tInt_eh_sjlj_setjmp: | ||||
7313 | case ARM::t2Int_eh_sjlj_setjmp: | ||||
7314 | case ARM::t2Int_eh_sjlj_setjmp_nofp: | ||||
7315 | EmitSjLjDispatchBlock(MI, BB); | ||||
7316 | return BB; | ||||
7317 | |||||
Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7318 | case ARM::ABS: |
7319 | case ARM::t2ABS: { | ||||
7320 | // To insert an ABS instruction, we have to insert the | ||||
7321 | // diamond control-flow pattern. The incoming instruction knows the | ||||
7322 | // source vreg to test against 0, the destination vreg to set, | ||||
7323 | // the condition code register to branch on, the | ||||
Andrew Trick | 3f07c42 | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 7324 | // true/false values to select between, and a branch opcode to use. |
Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7325 | // It transforms |
7326 | // V1 = ABS V0 | ||||
7327 | // into | ||||
7328 | // V2 = MOVS V0 | ||||
7329 | // BCC (branch to SinkBB if V0 >= 0) | ||||
7330 | // RSBBB: V3 = RSBri V2, 0 (compute ABS if V2 < 0) | ||||
Andrew Trick | 3f07c42 | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 7331 | // SinkBB: V1 = PHI(V2, V3) |
Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7332 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
7333 | MachineFunction::iterator BBI = BB; | ||||
7334 | ++BBI; | ||||
7335 | MachineFunction *Fn = BB->getParent(); | ||||
7336 | MachineBasicBlock *RSBBB = Fn->CreateMachineBasicBlock(LLVM_BB); | ||||
7337 | MachineBasicBlock *SinkBB = Fn->CreateMachineBasicBlock(LLVM_BB); | ||||
7338 | Fn->insert(BBI, RSBBB); | ||||
7339 | Fn->insert(BBI, SinkBB); | ||||
7340 | |||||
7341 | unsigned int ABSSrcReg = MI->getOperand(1).getReg(); | ||||
7342 | unsigned int ABSDstReg = MI->getOperand(0).getReg(); | ||||
7343 | bool isThumb2 = Subtarget->isThumb2(); | ||||
7344 | MachineRegisterInfo &MRI = Fn->getRegInfo(); | ||||
7345 | // In Thumb mode S must not be specified if source register is the SP or | ||||
7346 | // PC and if destination register is the SP, so restrict register class | ||||
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 7347 | unsigned NewRsbDstReg = MRI.createVirtualRegister(isThumb2 ? |
7348 | (const TargetRegisterClass*)&ARM::rGPRRegClass : | ||||
7349 | (const TargetRegisterClass*)&ARM::GPRRegClass); | ||||
Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7350 | |
7351 | // Transfer the remainder of BB and its successor edges to sinkMBB. | ||||
7352 | SinkBB->splice(SinkBB->begin(), BB, | ||||
Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 7353 | std::next(MachineBasicBlock::iterator(MI)), BB->end()); |
Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7354 | SinkBB->transferSuccessorsAndUpdatePHIs(BB); |
7355 | |||||
7356 | BB->addSuccessor(RSBBB); | ||||
7357 | BB->addSuccessor(SinkBB); | ||||
7358 | |||||
7359 | // fall through to SinkMBB | ||||
7360 | RSBBB->addSuccessor(SinkBB); | ||||
7361 | |||||
Manman Ren | e0763c7 | 2012-06-15 21:32:12 +0000 | [diff] [blame] | 7362 | // insert a cmp at the end of BB |
Andrew Trick | bc32516 | 2012-07-18 18:34:24 +0000 | [diff] [blame] | 7363 | AddDefaultPred(BuildMI(BB, dl, |
Manman Ren | e0763c7 | 2012-06-15 21:32:12 +0000 | [diff] [blame] | 7364 | TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
7365 | .addReg(ABSSrcReg).addImm(0)); | ||||
Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7366 | |
7367 | // insert a bcc with opposite CC to ARMCC::MI at the end of BB | ||||
Andrew Trick | 3f07c42 | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 7368 | BuildMI(BB, dl, |
Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7369 | TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)).addMBB(SinkBB) |
7370 | .addImm(ARMCC::getOppositeCondition(ARMCC::MI)).addReg(ARM::CPSR); | ||||
7371 | |||||
7372 | // insert rsbri in RSBBB | ||||
7373 | // Note: BCC and rsbri will be converted into predicated rsbmi | ||||
7374 | // by if-conversion pass | ||||
Andrew Trick | 3f07c42 | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 7375 | BuildMI(*RSBBB, RSBBB->begin(), dl, |
Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7376 | TII->get(isThumb2 ? ARM::t2RSBri : ARM::RSBri), NewRsbDstReg) |
Manman Ren | e0763c7 | 2012-06-15 21:32:12 +0000 | [diff] [blame] | 7377 | .addReg(ABSSrcReg, RegState::Kill) |
Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7378 | .addImm(0).addImm((unsigned)ARMCC::AL).addReg(0).addReg(0); |
7379 | |||||
Andrew Trick | 3f07c42 | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 7380 | // insert PHI in SinkBB, |
Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7381 | // reuse ABSDstReg to not change uses of ABS instruction |
7382 | BuildMI(*SinkBB, SinkBB->begin(), dl, | ||||
7383 | TII->get(ARM::PHI), ABSDstReg) | ||||
7384 | .addReg(NewRsbDstReg).addMBB(RSBBB) | ||||
Manman Ren | e0763c7 | 2012-06-15 21:32:12 +0000 | [diff] [blame] | 7385 | .addReg(ABSSrcReg).addMBB(BB); |
Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7386 | |
7387 | // remove ABS instruction | ||||
Andrew Trick | 3f07c42 | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 7388 | MI->eraseFromParent(); |
Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7389 | |
7390 | // return last added BB | ||||
7391 | return SinkBB; | ||||
7392 | } | ||||
Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7393 | case ARM::COPY_STRUCT_BYVAL_I32: |
Manman Ren | 9f91116 | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 7394 | ++NumLoopByVals; |
Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7395 | return EmitStructByval(MI, BB); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7396 | } |
7397 | } | ||||
7398 | |||||
Evan Cheng | e6fba77 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 7399 | void ARMTargetLowering::AdjustInstrPostInstrSelection(MachineInstr *MI, |
7400 | SDNode *Node) const { | ||||
Evan Cheng | 7f8e563 | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 7401 | if (!MI->hasPostISelHook()) { |
Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7402 | assert(!convertAddSubFlagsOpcode(MI->getOpcode()) && |
7403 | "Pseudo flag-setting opcodes must be marked with 'hasPostISelHook'"); | ||||
7404 | return; | ||||
7405 | } | ||||
7406 | |||||
Evan Cheng | 7f8e563 | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 7407 | const MCInstrDesc *MCID = &MI->getDesc(); |
Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7408 | // Adjust potentially 's' setting instructions after isel, i.e. ADC, SBC, RSB, |
7409 | // RSC. Coming out of isel, they have an implicit CPSR def, but the optional | ||||
7410 | // operand is still set to noreg. If needed, set the optional operand's | ||||
7411 | // register to CPSR, and remove the redundant implicit def. | ||||
Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7412 | // |
Andrew Trick | 88b2450 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 7413 | // e.g. ADCS (..., CPSR<imp-def>) -> ADC (... opt:CPSR<def>). |
Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7414 | |
Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7415 | // Rename pseudo opcodes. |
7416 | unsigned NewOpc = convertAddSubFlagsOpcode(MI->getOpcode()); | ||||
7417 | if (NewOpc) { | ||||
7418 | const ARMBaseInstrInfo *TII = | ||||
7419 | static_cast<const ARMBaseInstrInfo*>(getTargetMachine().getInstrInfo()); | ||||
Andrew Trick | 88b2450 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 7420 | MCID = &TII->get(NewOpc); |
7421 | |||||
7422 | assert(MCID->getNumOperands() == MI->getDesc().getNumOperands() + 1 && | ||||
7423 | "converted opcode should be the same except for cc_out"); | ||||
7424 | |||||
7425 | MI->setDesc(*MCID); | ||||
7426 | |||||
7427 | // Add the optional cc_out operand | ||||
7428 | MI->addOperand(MachineOperand::CreateReg(0, /*isDef=*/true)); | ||||
Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7429 | } |
Andrew Trick | 88b2450 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 7430 | unsigned ccOutIdx = MCID->getNumOperands() - 1; |
Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7431 | |
7432 | // Any ARM instruction that sets the 's' bit should specify an optional | ||||
7433 | // "cc_out" operand in the last operand position. | ||||
Evan Cheng | 7f8e563 | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 7434 | if (!MI->hasOptionalDef() || !MCID->OpInfo[ccOutIdx].isOptionalDef()) { |
Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7435 | assert(!NewOpc && "Optional cc_out operand required"); |
Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7436 | return; |
7437 | } | ||||
Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7438 | // Look for an implicit def of CPSR added by MachineInstr ctor. Remove it |
7439 | // since we already have an optional CPSR def. | ||||
Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7440 | bool definesCPSR = false; |
7441 | bool deadCPSR = false; | ||||
Andrew Trick | 88b2450 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 7442 | for (unsigned i = MCID->getNumOperands(), e = MI->getNumOperands(); |
Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7443 | i != e; ++i) { |
7444 | const MachineOperand &MO = MI->getOperand(i); | ||||
7445 | if (MO.isReg() && MO.isDef() && MO.getReg() == ARM::CPSR) { | ||||
7446 | definesCPSR = true; | ||||
7447 | if (MO.isDead()) | ||||
7448 | deadCPSR = true; | ||||
7449 | MI->RemoveOperand(i); | ||||
7450 | break; | ||||
Evan Cheng | e6fba77 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 7451 | } |
7452 | } | ||||
Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7453 | if (!definesCPSR) { |
Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7454 | assert(!NewOpc && "Optional cc_out operand required"); |
Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7455 | return; |
7456 | } | ||||
7457 | assert(deadCPSR == !Node->hasAnyUseOfValue(1) && "inconsistent dead flag"); | ||||
Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7458 | if (deadCPSR) { |
7459 | assert(!MI->getOperand(ccOutIdx).getReg() && | ||||
7460 | "expect uninitialized optional cc_out operand"); | ||||
Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7461 | return; |
Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7462 | } |
Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7463 | |
Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7464 | // If this instruction was defined with an optional CPSR def and its dag node |
7465 | // had a live implicit CPSR def, then activate the optional CPSR def. | ||||
Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7466 | MachineOperand &MO = MI->getOperand(ccOutIdx); |
7467 | MO.setReg(ARM::CPSR); | ||||
7468 | MO.setIsDef(true); | ||||
Evan Cheng | e6fba77 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 7469 | } |
7470 | |||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7471 | //===----------------------------------------------------------------------===// |
7472 | // ARM Optimization Hooks | ||||
7473 | //===----------------------------------------------------------------------===// | ||||
7474 | |||||
Jakob Stoklund Olesen | c1dee48 | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7475 | // Helper function that checks if N is a null or all ones constant. |
7476 | static inline bool isZeroOrAllOnes(SDValue N, bool AllOnes) { | ||||
7477 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(N); | ||||
7478 | if (!C) | ||||
7479 | return false; | ||||
7480 | return AllOnes ? C->isAllOnesValue() : C->isNullValue(); | ||||
7481 | } | ||||
7482 | |||||
Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7483 | // Return true if N is conditionally 0 or all ones. |
7484 | // Detects these expressions where cc is an i1 value: | ||||
7485 | // | ||||
7486 | // (select cc 0, y) [AllOnes=0] | ||||
7487 | // (select cc y, 0) [AllOnes=0] | ||||
7488 | // (zext cc) [AllOnes=0] | ||||
7489 | // (sext cc) [AllOnes=0/1] | ||||
7490 | // (select cc -1, y) [AllOnes=1] | ||||
7491 | // (select cc y, -1) [AllOnes=1] | ||||
7492 | // | ||||
7493 | // Invert is set when N is the null/all ones constant when CC is false. | ||||
7494 | // OtherOp is set to the alternative value of N. | ||||
7495 | static bool isConditionalZeroOrAllOnes(SDNode *N, bool AllOnes, | ||||
7496 | SDValue &CC, bool &Invert, | ||||
7497 | SDValue &OtherOp, | ||||
7498 | SelectionDAG &DAG) { | ||||
7499 | switch (N->getOpcode()) { | ||||
7500 | default: return false; | ||||
7501 | case ISD::SELECT: { | ||||
7502 | CC = N->getOperand(0); | ||||
7503 | SDValue N1 = N->getOperand(1); | ||||
7504 | SDValue N2 = N->getOperand(2); | ||||
7505 | if (isZeroOrAllOnes(N1, AllOnes)) { | ||||
7506 | Invert = false; | ||||
7507 | OtherOp = N2; | ||||
7508 | return true; | ||||
7509 | } | ||||
7510 | if (isZeroOrAllOnes(N2, AllOnes)) { | ||||
7511 | Invert = true; | ||||
7512 | OtherOp = N1; | ||||
7513 | return true; | ||||
7514 | } | ||||
7515 | return false; | ||||
7516 | } | ||||
7517 | case ISD::ZERO_EXTEND: | ||||
7518 | // (zext cc) can never be the all ones value. | ||||
7519 | if (AllOnes) | ||||
7520 | return false; | ||||
7521 | // Fall through. | ||||
7522 | case ISD::SIGN_EXTEND: { | ||||
7523 | EVT VT = N->getValueType(0); | ||||
7524 | CC = N->getOperand(0); | ||||
7525 | if (CC.getValueType() != MVT::i1) | ||||
7526 | return false; | ||||
7527 | Invert = !AllOnes; | ||||
7528 | if (AllOnes) | ||||
7529 | // When looking for an AllOnes constant, N is an sext, and the 'other' | ||||
7530 | // value is 0. | ||||
7531 | OtherOp = DAG.getConstant(0, VT); | ||||
7532 | else if (N->getOpcode() == ISD::ZERO_EXTEND) | ||||
7533 | // When looking for a 0 constant, N can be zext or sext. | ||||
7534 | OtherOp = DAG.getConstant(1, VT); | ||||
7535 | else | ||||
7536 | OtherOp = DAG.getConstant(APInt::getAllOnesValue(VT.getSizeInBits()), VT); | ||||
7537 | return true; | ||||
7538 | } | ||||
7539 | } | ||||
7540 | } | ||||
7541 | |||||
Jakob Stoklund Olesen | c1dee48 | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7542 | // Combine a constant select operand into its use: |
7543 | // | ||||
Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7544 | // (add (select cc, 0, c), x) -> (select cc, x, (add, x, c)) |
7545 | // (sub x, (select cc, 0, c)) -> (select cc, x, (sub, x, c)) | ||||
7546 | // (and (select cc, -1, c), x) -> (select cc, x, (and, x, c)) [AllOnes=1] | ||||
7547 | // (or (select cc, 0, c), x) -> (select cc, x, (or, x, c)) | ||||
7548 | // (xor (select cc, 0, c), x) -> (select cc, x, (xor, x, c)) | ||||
Jakob Stoklund Olesen | c1dee48 | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7549 | // |
7550 | // The transform is rejected if the select doesn't have a constant operand that | ||||
Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7551 | // is null, or all ones when AllOnes is set. |
Jakob Stoklund Olesen | c1dee48 | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7552 | // |
Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7553 | // Also recognize sext/zext from i1: |
7554 | // | ||||
7555 | // (add (zext cc), x) -> (select cc (add x, 1), x) | ||||
7556 | // (add (sext cc), x) -> (select cc (add x, -1), x) | ||||
7557 | // | ||||
7558 | // These transformations eventually create predicated instructions. | ||||
7559 | // | ||||
Jakob Stoklund Olesen | c1dee48 | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7560 | // @param N The node to transform. |
7561 | // @param Slct The N operand that is a select. | ||||
7562 | // @param OtherOp The other N operand (x above). | ||||
7563 | // @param DCI Context. | ||||
Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7564 | // @param AllOnes Require the select constant to be all ones instead of null. |
Jakob Stoklund Olesen | c1dee48 | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7565 | // @returns The new node, or SDValue() on failure. |
Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7566 | static |
7567 | SDValue combineSelectAndUse(SDNode *N, SDValue Slct, SDValue OtherOp, | ||||
Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7568 | TargetLowering::DAGCombinerInfo &DCI, |
7569 | bool AllOnes = false) { | ||||
Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7570 | SelectionDAG &DAG = DCI.DAG; |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7571 | EVT VT = N->getValueType(0); |
Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7572 | SDValue NonConstantVal; |
7573 | SDValue CCOp; | ||||
7574 | bool SwapSelectOps; | ||||
7575 | if (!isConditionalZeroOrAllOnes(Slct.getNode(), AllOnes, CCOp, SwapSelectOps, | ||||
7576 | NonConstantVal, DAG)) | ||||
Jakob Stoklund Olesen | c1dee48 | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7577 | return SDValue(); |
7578 | |||||
Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7579 | // Slct is now know to be the desired identity constant when CC is true. |
7580 | SDValue TrueVal = OtherOp; | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 7581 | SDValue FalseVal = DAG.getNode(N->getOpcode(), SDLoc(N), VT, |
Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7582 | OtherOp, NonConstantVal); |
7583 | // Unless SwapSelectOps says CC should be false. | ||||
7584 | if (SwapSelectOps) | ||||
7585 | std::swap(TrueVal, FalseVal); | ||||
7586 | |||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 7587 | return DAG.getNode(ISD::SELECT, SDLoc(N), VT, |
Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7588 | CCOp, TrueVal, FalseVal); |
Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7589 | } |
7590 | |||||
Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7591 | // Attempt combineSelectAndUse on each operand of a commutative operator N. |
7592 | static | ||||
7593 | SDValue combineSelectAndUseCommutative(SDNode *N, bool AllOnes, | ||||
7594 | TargetLowering::DAGCombinerInfo &DCI) { | ||||
7595 | SDValue N0 = N->getOperand(0); | ||||
7596 | SDValue N1 = N->getOperand(1); | ||||
Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7597 | if (N0.getNode()->hasOneUse()) { |
Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7598 | SDValue Result = combineSelectAndUse(N, N0, N1, DCI, AllOnes); |
7599 | if (Result.getNode()) | ||||
7600 | return Result; | ||||
7601 | } | ||||
Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7602 | if (N1.getNode()->hasOneUse()) { |
Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7603 | SDValue Result = combineSelectAndUse(N, N1, N0, DCI, AllOnes); |
7604 | if (Result.getNode()) | ||||
7605 | return Result; | ||||
7606 | } | ||||
7607 | return SDValue(); | ||||
7608 | } | ||||
7609 | |||||
Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7610 | // AddCombineToVPADDL- For pair-wise add on neon, use the vpaddl instruction |
Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7611 | // (only after legalization). |
7612 | static SDValue AddCombineToVPADDL(SDNode *N, SDValue N0, SDValue N1, | ||||
7613 | TargetLowering::DAGCombinerInfo &DCI, | ||||
7614 | const ARMSubtarget *Subtarget) { | ||||
7615 | |||||
7616 | // Only perform optimization if after legalize, and if NEON is available. We | ||||
7617 | // also expected both operands to be BUILD_VECTORs. | ||||
7618 | if (DCI.isBeforeLegalize() || !Subtarget->hasNEON() | ||||
7619 | || N0.getOpcode() != ISD::BUILD_VECTOR | ||||
7620 | || N1.getOpcode() != ISD::BUILD_VECTOR) | ||||
7621 | return SDValue(); | ||||
7622 | |||||
7623 | // Check output type since VPADDL operand elements can only be 8, 16, or 32. | ||||
7624 | EVT VT = N->getValueType(0); | ||||
7625 | if (!VT.isInteger() || VT.getVectorElementType() == MVT::i64) | ||||
7626 | return SDValue(); | ||||
7627 | |||||
7628 | // Check that the vector operands are of the right form. | ||||
7629 | // N0 and N1 are BUILD_VECTOR nodes with N number of EXTRACT_VECTOR | ||||
7630 | // operands, where N is the size of the formed vector. | ||||
7631 | // Each EXTRACT_VECTOR should have the same input vector and odd or even | ||||
7632 | // index such that we have a pair wise add pattern. | ||||
Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7633 | |
7634 | // Grab the vector that all EXTRACT_VECTOR nodes should be referencing. | ||||
Bob Wilson | 4b12a11 | 2011-06-15 06:04:34 +0000 | [diff] [blame] | 7635 | if (N0->getOperand(0)->getOpcode() != ISD::EXTRACT_VECTOR_ELT) |
Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7636 | return SDValue(); |
Bob Wilson | 4b12a11 | 2011-06-15 06:04:34 +0000 | [diff] [blame] | 7637 | SDValue Vec = N0->getOperand(0)->getOperand(0); |
7638 | SDNode *V = Vec.getNode(); | ||||
7639 | unsigned nextIndex = 0; | ||||
Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7640 | |
Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7641 | // For each operands to the ADD which are BUILD_VECTORs, |
Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7642 | // check to see if each of their operands are an EXTRACT_VECTOR with |
7643 | // the same vector and appropriate index. | ||||
7644 | for (unsigned i = 0, e = N0->getNumOperands(); i != e; ++i) { | ||||
7645 | if (N0->getOperand(i)->getOpcode() == ISD::EXTRACT_VECTOR_ELT | ||||
7646 | && N1->getOperand(i)->getOpcode() == ISD::EXTRACT_VECTOR_ELT) { | ||||
Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7647 | |
Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7648 | SDValue ExtVec0 = N0->getOperand(i); |
7649 | SDValue ExtVec1 = N1->getOperand(i); | ||||
Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7650 | |
Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7651 | // First operand is the vector, verify its the same. |
7652 | if (V != ExtVec0->getOperand(0).getNode() || | ||||
7653 | V != ExtVec1->getOperand(0).getNode()) | ||||
7654 | return SDValue(); | ||||
Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7655 | |
Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7656 | // Second is the constant, verify its correct. |
7657 | ConstantSDNode *C0 = dyn_cast<ConstantSDNode>(ExtVec0->getOperand(1)); | ||||
7658 | ConstantSDNode *C1 = dyn_cast<ConstantSDNode>(ExtVec1->getOperand(1)); | ||||
Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7659 | |
Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7660 | // For the constant, we want to see all the even or all the odd. |
7661 | if (!C0 || !C1 || C0->getZExtValue() != nextIndex | ||||
7662 | || C1->getZExtValue() != nextIndex+1) | ||||
7663 | return SDValue(); | ||||
7664 | |||||
7665 | // Increment index. | ||||
7666 | nextIndex+=2; | ||||
Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7667 | } else |
Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7668 | return SDValue(); |
7669 | } | ||||
7670 | |||||
7671 | // Create VPADDL node. | ||||
7672 | SelectionDAG &DAG = DCI.DAG; | ||||
7673 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); | ||||
Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7674 | |
7675 | // Build operand list. | ||||
7676 | SmallVector<SDValue, 8> Ops; | ||||
7677 | Ops.push_back(DAG.getConstant(Intrinsic::arm_neon_vpaddls, | ||||
7678 | TLI.getPointerTy())); | ||||
7679 | |||||
7680 | // Input is the vector. | ||||
7681 | Ops.push_back(Vec); | ||||
Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7682 | |
Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7683 | // Get widened type and narrowed type. |
7684 | MVT widenType; | ||||
7685 | unsigned numElem = VT.getVectorNumElements(); | ||||
Silviu Baranga | a3106e6 | 2014-04-03 10:44:27 +0000 | [diff] [blame] | 7686 | |
7687 | EVT inputLaneType = Vec.getValueType().getVectorElementType(); | ||||
7688 | switch (inputLaneType.getSimpleVT().SimpleTy) { | ||||
Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7689 | case MVT::i8: widenType = MVT::getVectorVT(MVT::i16, numElem); break; |
7690 | case MVT::i16: widenType = MVT::getVectorVT(MVT::i32, numElem); break; | ||||
7691 | case MVT::i32: widenType = MVT::getVectorVT(MVT::i64, numElem); break; | ||||
7692 | default: | ||||
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 7693 | llvm_unreachable("Invalid vector element type for padd optimization."); |
Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7694 | } |
7695 | |||||
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 7696 | SDValue tmp = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, SDLoc(N), widenType, Ops); |
Silviu Baranga | a3106e6 | 2014-04-03 10:44:27 +0000 | [diff] [blame] | 7697 | unsigned ExtOp = VT.bitsGT(tmp.getValueType()) ? ISD::ANY_EXTEND : ISD::TRUNCATE; |
7698 | return DAG.getNode(ExtOp, SDLoc(N), VT, tmp); | ||||
Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7699 | } |
7700 | |||||
Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 7701 | static SDValue findMUL_LOHI(SDValue V) { |
7702 | if (V->getOpcode() == ISD::UMUL_LOHI || | ||||
7703 | V->getOpcode() == ISD::SMUL_LOHI) | ||||
7704 | return V; | ||||
7705 | return SDValue(); | ||||
7706 | } | ||||
7707 | |||||
7708 | static SDValue AddCombineTo64bitMLAL(SDNode *AddcNode, | ||||
7709 | TargetLowering::DAGCombinerInfo &DCI, | ||||
7710 | const ARMSubtarget *Subtarget) { | ||||
7711 | |||||
7712 | if (Subtarget->isThumb1Only()) return SDValue(); | ||||
7713 | |||||
7714 | // Only perform the checks after legalize when the pattern is available. | ||||
7715 | if (DCI.isBeforeLegalize()) return SDValue(); | ||||
7716 | |||||
7717 | // Look for multiply add opportunities. | ||||
7718 | // The pattern is a ISD::UMUL_LOHI followed by two add nodes, where | ||||
7719 | // each add nodes consumes a value from ISD::UMUL_LOHI and there is | ||||
7720 | // a glue link from the first add to the second add. | ||||
7721 | // If we find this pattern, we can replace the U/SMUL_LOHI, ADDC, and ADDE by | ||||
7722 | // a S/UMLAL instruction. | ||||
7723 | // loAdd UMUL_LOHI | ||||
7724 | // \ / :lo \ :hi | ||||
7725 | // \ / \ [no multiline comment] | ||||
7726 | // ADDC | hiAdd | ||||
7727 | // \ :glue / / | ||||
7728 | // \ / / | ||||
7729 | // ADDE | ||||
7730 | // | ||||
7731 | assert(AddcNode->getOpcode() == ISD::ADDC && "Expect an ADDC"); | ||||
7732 | SDValue AddcOp0 = AddcNode->getOperand(0); | ||||
7733 | SDValue AddcOp1 = AddcNode->getOperand(1); | ||||
7734 | |||||
7735 | // Check if the two operands are from the same mul_lohi node. | ||||
7736 | if (AddcOp0.getNode() == AddcOp1.getNode()) | ||||
7737 | return SDValue(); | ||||
7738 | |||||
7739 | assert(AddcNode->getNumValues() == 2 && | ||||
7740 | AddcNode->getValueType(0) == MVT::i32 && | ||||
Michael Gottesman | b2a7056 | 2013-06-18 20:49:40 +0000 | [diff] [blame] | 7741 | "Expect ADDC with two result values. First: i32"); |
7742 | |||||
7743 | // Check that we have a glued ADDC node. | ||||
7744 | if (AddcNode->getValueType(1) != MVT::Glue) | ||||
7745 | return SDValue(); | ||||
Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 7746 | |
7747 | // Check that the ADDC adds the low result of the S/UMUL_LOHI. | ||||
7748 | if (AddcOp0->getOpcode() != ISD::UMUL_LOHI && | ||||
7749 | AddcOp0->getOpcode() != ISD::SMUL_LOHI && | ||||
7750 | AddcOp1->getOpcode() != ISD::UMUL_LOHI && | ||||
7751 | AddcOp1->getOpcode() != ISD::SMUL_LOHI) | ||||
7752 | return SDValue(); | ||||
7753 | |||||
7754 | // Look for the glued ADDE. | ||||
7755 | SDNode* AddeNode = AddcNode->getGluedUser(); | ||||
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 7756 | if (!AddeNode) |
Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 7757 | return SDValue(); |
7758 | |||||
7759 | // Make sure it is really an ADDE. | ||||
7760 | if (AddeNode->getOpcode() != ISD::ADDE) | ||||
7761 | return SDValue(); | ||||
7762 | |||||
7763 | assert(AddeNode->getNumOperands() == 3 && | ||||
7764 | AddeNode->getOperand(2).getValueType() == MVT::Glue && | ||||
7765 | "ADDE node has the wrong inputs"); | ||||
7766 | |||||
7767 | // Check for the triangle shape. | ||||
7768 | SDValue AddeOp0 = AddeNode->getOperand(0); | ||||
7769 | SDValue AddeOp1 = AddeNode->getOperand(1); | ||||
7770 | |||||
7771 | // Make sure that the ADDE operands are not coming from the same node. | ||||
7772 | if (AddeOp0.getNode() == AddeOp1.getNode()) | ||||
7773 | return SDValue(); | ||||
7774 | |||||
7775 | // Find the MUL_LOHI node walking up ADDE's operands. | ||||
7776 | bool IsLeftOperandMUL = false; | ||||
7777 | SDValue MULOp = findMUL_LOHI(AddeOp0); | ||||
7778 | if (MULOp == SDValue()) | ||||
7779 | MULOp = findMUL_LOHI(AddeOp1); | ||||
7780 | else | ||||
7781 | IsLeftOperandMUL = true; | ||||
7782 | if (MULOp == SDValue()) | ||||
7783 | return SDValue(); | ||||
7784 | |||||
7785 | // Figure out the right opcode. | ||||
7786 | unsigned Opc = MULOp->getOpcode(); | ||||
7787 | unsigned FinalOpc = (Opc == ISD::SMUL_LOHI) ? ARMISD::SMLAL : ARMISD::UMLAL; | ||||
7788 | |||||
7789 | // Figure out the high and low input values to the MLAL node. | ||||
7790 | SDValue* HiMul = &MULOp; | ||||
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 7791 | SDValue* HiAdd = nullptr; |
7792 | SDValue* LoMul = nullptr; | ||||
7793 | SDValue* LowAdd = nullptr; | ||||
Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 7794 | |
7795 | if (IsLeftOperandMUL) | ||||
7796 | HiAdd = &AddeOp1; | ||||
7797 | else | ||||
7798 | HiAdd = &AddeOp0; | ||||
7799 | |||||
7800 | |||||
7801 | if (AddcOp0->getOpcode() == Opc) { | ||||
7802 | LoMul = &AddcOp0; | ||||
7803 | LowAdd = &AddcOp1; | ||||
7804 | } | ||||
7805 | if (AddcOp1->getOpcode() == Opc) { | ||||
7806 | LoMul = &AddcOp1; | ||||
7807 | LowAdd = &AddcOp0; | ||||
7808 | } | ||||
7809 | |||||
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 7810 | if (!LoMul) |
Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 7811 | return SDValue(); |
7812 | |||||
7813 | if (LoMul->getNode() != HiMul->getNode()) | ||||
7814 | return SDValue(); | ||||
7815 | |||||
7816 | // Create the merged node. | ||||
7817 | SelectionDAG &DAG = DCI.DAG; | ||||
7818 | |||||
7819 | // Build operand list. | ||||
7820 | SmallVector<SDValue, 8> Ops; | ||||
7821 | Ops.push_back(LoMul->getOperand(0)); | ||||
7822 | Ops.push_back(LoMul->getOperand(1)); | ||||
7823 | Ops.push_back(*LowAdd); | ||||
7824 | Ops.push_back(*HiAdd); | ||||
7825 | |||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 7826 | SDValue MLALNode = DAG.getNode(FinalOpc, SDLoc(AddcNode), |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 7827 | DAG.getVTList(MVT::i32, MVT::i32), Ops); |
Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 7828 | |
7829 | // Replace the ADDs' nodes uses by the MLA node's values. | ||||
7830 | SDValue HiMLALResult(MLALNode.getNode(), 1); | ||||
7831 | DAG.ReplaceAllUsesOfValueWith(SDValue(AddeNode, 0), HiMLALResult); | ||||
7832 | |||||
7833 | SDValue LoMLALResult(MLALNode.getNode(), 0); | ||||
7834 | DAG.ReplaceAllUsesOfValueWith(SDValue(AddcNode, 0), LoMLALResult); | ||||
7835 | |||||
7836 | // Return original node to notify the driver to stop replacing. | ||||
7837 | SDValue resNode(AddcNode, 0); | ||||
7838 | return resNode; | ||||
7839 | } | ||||
7840 | |||||
7841 | /// PerformADDCCombine - Target-specific dag combine transform from | ||||
7842 | /// ISD::ADDC, ISD::ADDE, and ISD::MUL_LOHI to MLAL. | ||||
7843 | static SDValue PerformADDCCombine(SDNode *N, | ||||
7844 | TargetLowering::DAGCombinerInfo &DCI, | ||||
7845 | const ARMSubtarget *Subtarget) { | ||||
7846 | |||||
7847 | return AddCombineTo64bitMLAL(N, DCI, Subtarget); | ||||
7848 | |||||
7849 | } | ||||
7850 | |||||
Bob Wilson | 728eb29 | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 7851 | /// PerformADDCombineWithOperands - Try DAG combinations for an ADD with |
7852 | /// operands N0 and N1. This is a helper for PerformADDCombine that is | ||||
7853 | /// called with the default operands, and if that fails, with commuted | ||||
7854 | /// operands. | ||||
7855 | static SDValue PerformADDCombineWithOperands(SDNode *N, SDValue N0, SDValue N1, | ||||
Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7856 | TargetLowering::DAGCombinerInfo &DCI, |
7857 | const ARMSubtarget *Subtarget){ | ||||
7858 | |||||
7859 | // Attempt to create vpaddl for this add. | ||||
7860 | SDValue Result = AddCombineToVPADDL(N, N0, N1, DCI, Subtarget); | ||||
7861 | if (Result.getNode()) | ||||
7862 | return Result; | ||||
Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7863 | |
Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7864 | // fold (add (select cc, 0, c), x) -> (select cc, x, (add, x, c)) |
Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7865 | if (N0.getNode()->hasOneUse()) { |
Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7866 | SDValue Result = combineSelectAndUse(N, N0, N1, DCI); |
7867 | if (Result.getNode()) return Result; | ||||
7868 | } | ||||
Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7869 | return SDValue(); |
7870 | } | ||||
7871 | |||||
Bob Wilson | 728eb29 | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 7872 | /// PerformADDCombine - Target-specific dag combine xforms for ISD::ADD. |
7873 | /// | ||||
7874 | static SDValue PerformADDCombine(SDNode *N, | ||||
Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7875 | TargetLowering::DAGCombinerInfo &DCI, |
7876 | const ARMSubtarget *Subtarget) { | ||||
Bob Wilson | 728eb29 | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 7877 | SDValue N0 = N->getOperand(0); |
7878 | SDValue N1 = N->getOperand(1); | ||||
7879 | |||||
7880 | // First try with the default operand order. | ||||
Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7881 | SDValue Result = PerformADDCombineWithOperands(N, N0, N1, DCI, Subtarget); |
Bob Wilson | 728eb29 | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 7882 | if (Result.getNode()) |
7883 | return Result; | ||||
7884 | |||||
7885 | // If that didn't work, try again with the operands commuted. | ||||
Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7886 | return PerformADDCombineWithOperands(N, N1, N0, DCI, Subtarget); |
Bob Wilson | 728eb29 | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 7887 | } |
7888 | |||||
Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7889 | /// PerformSUBCombine - Target-specific dag combine xforms for ISD::SUB. |
Bob Wilson | 728eb29 | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 7890 | /// |
Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7891 | static SDValue PerformSUBCombine(SDNode *N, |
7892 | TargetLowering::DAGCombinerInfo &DCI) { | ||||
Bob Wilson | 728eb29 | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 7893 | SDValue N0 = N->getOperand(0); |
7894 | SDValue N1 = N->getOperand(1); | ||||
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 7895 | |
Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7896 | // fold (sub x, (select cc, 0, c)) -> (select cc, x, (sub, x, c)) |
Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7897 | if (N1.getNode()->hasOneUse()) { |
Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7898 | SDValue Result = combineSelectAndUse(N, N1, N0, DCI); |
7899 | if (Result.getNode()) return Result; | ||||
7900 | } | ||||
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 7901 | |
Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7902 | return SDValue(); |
7903 | } | ||||
7904 | |||||
Evan Cheng | 38bf5ad | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 7905 | /// PerformVMULCombine |
7906 | /// Distribute (A + B) * C to (A * C) + (B * C) to take advantage of the | ||||
7907 | /// special multiplier accumulator forwarding. | ||||
7908 | /// vmul d3, d0, d2 | ||||
7909 | /// vmla d3, d1, d2 | ||||
7910 | /// is faster than | ||||
7911 | /// vadd d3, d0, d1 | ||||
7912 | /// vmul d3, d3, d2 | ||||
Weiming Zhao | 2052f48 | 2013-09-25 23:12:06 +0000 | [diff] [blame] | 7913 | // However, for (A + B) * (A + B), |
7914 | // vadd d2, d0, d1 | ||||
7915 | // vmul d3, d0, d2 | ||||
7916 | // vmla d3, d1, d2 | ||||
7917 | // is slower than | ||||
7918 | // vadd d2, d0, d1 | ||||
7919 | // vmul d3, d2, d2 | ||||
Evan Cheng | 38bf5ad | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 7920 | static SDValue PerformVMULCombine(SDNode *N, |
7921 | TargetLowering::DAGCombinerInfo &DCI, | ||||
7922 | const ARMSubtarget *Subtarget) { | ||||
7923 | if (!Subtarget->hasVMLxForwarding()) | ||||
7924 | return SDValue(); | ||||
7925 | |||||
7926 | SelectionDAG &DAG = DCI.DAG; | ||||
7927 | SDValue N0 = N->getOperand(0); | ||||
7928 | SDValue N1 = N->getOperand(1); | ||||
7929 | unsigned Opcode = N0.getOpcode(); | ||||
7930 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && | ||||
7931 | Opcode != ISD::FADD && Opcode != ISD::FSUB) { | ||||
Chad Rosier | 2730162 | 2011-06-16 01:21:54 +0000 | [diff] [blame] | 7932 | Opcode = N1.getOpcode(); |
Evan Cheng | 38bf5ad | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 7933 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
7934 | Opcode != ISD::FADD && Opcode != ISD::FSUB) | ||||
7935 | return SDValue(); | ||||
7936 | std::swap(N0, N1); | ||||
7937 | } | ||||
7938 | |||||
Weiming Zhao | 2052f48 | 2013-09-25 23:12:06 +0000 | [diff] [blame] | 7939 | if (N0 == N1) |
7940 | return SDValue(); | ||||
7941 | |||||
Evan Cheng | 38bf5ad | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 7942 | EVT VT = N->getValueType(0); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 7943 | SDLoc DL(N); |
Evan Cheng | 38bf5ad | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 7944 | SDValue N00 = N0->getOperand(0); |
7945 | SDValue N01 = N0->getOperand(1); | ||||
7946 | return DAG.getNode(Opcode, DL, VT, | ||||
7947 | DAG.getNode(ISD::MUL, DL, VT, N00, N1), | ||||
7948 | DAG.getNode(ISD::MUL, DL, VT, N01, N1)); | ||||
7949 | } | ||||
7950 | |||||
Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 7951 | static SDValue PerformMULCombine(SDNode *N, |
7952 | TargetLowering::DAGCombinerInfo &DCI, | ||||
7953 | const ARMSubtarget *Subtarget) { | ||||
7954 | SelectionDAG &DAG = DCI.DAG; | ||||
7955 | |||||
7956 | if (Subtarget->isThumb1Only()) | ||||
7957 | return SDValue(); | ||||
7958 | |||||
Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 7959 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
7960 | return SDValue(); | ||||
7961 | |||||
7962 | EVT VT = N->getValueType(0); | ||||
Evan Cheng | 38bf5ad | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 7963 | if (VT.is64BitVector() || VT.is128BitVector()) |
7964 | return PerformVMULCombine(N, DCI, Subtarget); | ||||
Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 7965 | if (VT != MVT::i32) |
7966 | return SDValue(); | ||||
7967 | |||||
7968 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1)); | ||||
7969 | if (!C) | ||||
7970 | return SDValue(); | ||||
7971 | |||||
Anton Korobeynikov | 3edd854d | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 7972 | int64_t MulAmt = C->getSExtValue(); |
Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 7973 | unsigned ShiftAmt = countTrailingZeros<uint64_t>(MulAmt); |
Anton Korobeynikov | 3edd854d | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 7974 | |
Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 7975 | ShiftAmt = ShiftAmt & (32 - 1); |
7976 | SDValue V = N->getOperand(0); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 7977 | SDLoc DL(N); |
Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 7978 | |
Anton Korobeynikov | 4c719c4 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 7979 | SDValue Res; |
7980 | MulAmt >>= ShiftAmt; | ||||
Anton Korobeynikov | 3edd854d | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 7981 | |
7982 | if (MulAmt >= 0) { | ||||
7983 | if (isPowerOf2_32(MulAmt - 1)) { | ||||
7984 | // (mul x, 2^N + 1) => (add (shl x, N), x) | ||||
7985 | Res = DAG.getNode(ISD::ADD, DL, VT, | ||||
7986 | V, | ||||
7987 | DAG.getNode(ISD::SHL, DL, VT, | ||||
7988 | V, | ||||
7989 | DAG.getConstant(Log2_32(MulAmt - 1), | ||||
7990 | MVT::i32))); | ||||
7991 | } else if (isPowerOf2_32(MulAmt + 1)) { | ||||
7992 | // (mul x, 2^N - 1) => (sub (shl x, N), x) | ||||
7993 | Res = DAG.getNode(ISD::SUB, DL, VT, | ||||
7994 | DAG.getNode(ISD::SHL, DL, VT, | ||||
7995 | V, | ||||
7996 | DAG.getConstant(Log2_32(MulAmt + 1), | ||||
7997 | MVT::i32)), | ||||
7998 | V); | ||||
7999 | } else | ||||
8000 | return SDValue(); | ||||
8001 | } else { | ||||
8002 | uint64_t MulAmtAbs = -MulAmt; | ||||
8003 | if (isPowerOf2_32(MulAmtAbs + 1)) { | ||||
8004 | // (mul x, -(2^N - 1)) => (sub x, (shl x, N)) | ||||
8005 | Res = DAG.getNode(ISD::SUB, DL, VT, | ||||
8006 | V, | ||||
8007 | DAG.getNode(ISD::SHL, DL, VT, | ||||
8008 | V, | ||||
8009 | DAG.getConstant(Log2_32(MulAmtAbs + 1), | ||||
8010 | MVT::i32))); | ||||
8011 | } else if (isPowerOf2_32(MulAmtAbs - 1)) { | ||||
8012 | // (mul x, -(2^N + 1)) => - (add (shl x, N), x) | ||||
8013 | Res = DAG.getNode(ISD::ADD, DL, VT, | ||||
8014 | V, | ||||
8015 | DAG.getNode(ISD::SHL, DL, VT, | ||||
8016 | V, | ||||
8017 | DAG.getConstant(Log2_32(MulAmtAbs-1), | ||||
8018 | MVT::i32))); | ||||
8019 | Res = DAG.getNode(ISD::SUB, DL, VT, | ||||
8020 | DAG.getConstant(0, MVT::i32),Res); | ||||
8021 | |||||
8022 | } else | ||||
8023 | return SDValue(); | ||||
8024 | } | ||||
Anton Korobeynikov | 4c719c4 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 8025 | |
8026 | if (ShiftAmt != 0) | ||||
Anton Korobeynikov | 3edd854d | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 8027 | Res = DAG.getNode(ISD::SHL, DL, VT, |
8028 | Res, DAG.getConstant(ShiftAmt, MVT::i32)); | ||||
Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8029 | |
8030 | // Do not add new nodes to DAG combiner worklist. | ||||
Anton Korobeynikov | 4c719c4 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 8031 | DCI.CombineTo(N, Res, false); |
Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8032 | return SDValue(); |
8033 | } | ||||
8034 | |||||
Owen Anderson | 30c4892 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8035 | static SDValue PerformANDCombine(SDNode *N, |
Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8036 | TargetLowering::DAGCombinerInfo &DCI, |
8037 | const ARMSubtarget *Subtarget) { | ||||
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 8038 | |
Owen Anderson | 30c4892 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8039 | // Attempt to use immediate-form VBIC |
8040 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8041 | SDLoc dl(N); |
Owen Anderson | 30c4892 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8042 | EVT VT = N->getValueType(0); |
8043 | SelectionDAG &DAG = DCI.DAG; | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8044 | |
Tanya Lattner | 266792a | 2011-04-07 15:24:20 +0000 | [diff] [blame] | 8045 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
8046 | return SDValue(); | ||||
Andrew Trick | 0ed5778 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 8047 | |
Owen Anderson | 30c4892 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8048 | APInt SplatBits, SplatUndef; |
8049 | unsigned SplatBitSize; | ||||
8050 | bool HasAnyUndefs; | ||||
8051 | if (BVN && | ||||
8052 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { | ||||
8053 | if (SplatBitSize <= 64) { | ||||
8054 | EVT VbicVT; | ||||
8055 | SDValue Val = isNEONModifiedImm((~SplatBits).getZExtValue(), | ||||
8056 | SplatUndef.getZExtValue(), SplatBitSize, | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8057 | DAG, VbicVT, VT.is128BitVector(), |
Owen Anderson | a407692 | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 8058 | OtherModImm); |
Owen Anderson | 30c4892 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8059 | if (Val.getNode()) { |
8060 | SDValue Input = | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8061 | DAG.getNode(ISD::BITCAST, dl, VbicVT, N->getOperand(0)); |
Owen Anderson | 30c4892 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8062 | SDValue Vbic = DAG.getNode(ARMISD::VBICIMM, dl, VbicVT, Input, Val); |
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8063 | return DAG.getNode(ISD::BITCAST, dl, VT, Vbic); |
Owen Anderson | 30c4892 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8064 | } |
8065 | } | ||||
8066 | } | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8067 | |
Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8068 | if (!Subtarget->isThumb1Only()) { |
Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8069 | // fold (and (select cc, -1, c), x) -> (select cc, x, (and, x, c)) |
8070 | SDValue Result = combineSelectAndUseCommutative(N, true, DCI); | ||||
8071 | if (Result.getNode()) | ||||
8072 | return Result; | ||||
Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8073 | } |
8074 | |||||
Owen Anderson | 30c4892 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8075 | return SDValue(); |
8076 | } | ||||
8077 | |||||
Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8078 | /// PerformORCombine - Target-specific dag combine xforms for ISD::OR |
8079 | static SDValue PerformORCombine(SDNode *N, | ||||
8080 | TargetLowering::DAGCombinerInfo &DCI, | ||||
8081 | const ARMSubtarget *Subtarget) { | ||||
Owen Anderson | bc9b31c | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8082 | // Attempt to use immediate-form VORR |
8083 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8084 | SDLoc dl(N); |
Owen Anderson | bc9b31c | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8085 | EVT VT = N->getValueType(0); |
8086 | SelectionDAG &DAG = DCI.DAG; | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8087 | |
Tanya Lattner | 266792a | 2011-04-07 15:24:20 +0000 | [diff] [blame] | 8088 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
8089 | return SDValue(); | ||||
Andrew Trick | 0ed5778 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 8090 | |
Owen Anderson | bc9b31c | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8091 | APInt SplatBits, SplatUndef; |
8092 | unsigned SplatBitSize; | ||||
8093 | bool HasAnyUndefs; | ||||
8094 | if (BVN && Subtarget->hasNEON() && | ||||
8095 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { | ||||
8096 | if (SplatBitSize <= 64) { | ||||
8097 | EVT VorrVT; | ||||
8098 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), | ||||
8099 | SplatUndef.getZExtValue(), SplatBitSize, | ||||
Owen Anderson | a407692 | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 8100 | DAG, VorrVT, VT.is128BitVector(), |
8101 | OtherModImm); | ||||
Owen Anderson | bc9b31c | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8102 | if (Val.getNode()) { |
8103 | SDValue Input = | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8104 | DAG.getNode(ISD::BITCAST, dl, VorrVT, N->getOperand(0)); |
Owen Anderson | bc9b31c | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8105 | SDValue Vorr = DAG.getNode(ARMISD::VORRIMM, dl, VorrVT, Input, Val); |
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8106 | return DAG.getNode(ISD::BITCAST, dl, VT, Vorr); |
Owen Anderson | bc9b31c | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8107 | } |
8108 | } | ||||
8109 | } | ||||
8110 | |||||
Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8111 | if (!Subtarget->isThumb1Only()) { |
Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8112 | // fold (or (select cc, 0, c), x) -> (select cc, x, (or, x, c)) |
8113 | SDValue Result = combineSelectAndUseCommutative(N, false, DCI); | ||||
8114 | if (Result.getNode()) | ||||
8115 | return Result; | ||||
Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8116 | } |
8117 | |||||
Nadav Rotem | 3a94c54 | 2012-08-13 18:52:44 +0000 | [diff] [blame] | 8118 | // The code below optimizes (or (and X, Y), Z). |
8119 | // The AND operand needs to have a single user to make these optimizations | ||||
8120 | // profitable. | ||||
Cameron Zwarich | 53dd03d | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 8121 | SDValue N0 = N->getOperand(0); |
Nadav Rotem | 3a94c54 | 2012-08-13 18:52:44 +0000 | [diff] [blame] | 8122 | if (N0.getOpcode() != ISD::AND || !N0.hasOneUse()) |
Cameron Zwarich | 53dd03d | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 8123 | return SDValue(); |
8124 | SDValue N1 = N->getOperand(1); | ||||
8125 | |||||
8126 | // (or (and B, A), (and C, ~A)) => (VBSL A, B, C) when A is a constant. | ||||
8127 | if (Subtarget->hasNEON() && N1.getOpcode() == ISD::AND && VT.isVector() && | ||||
8128 | DAG.getTargetLoweringInfo().isTypeLegal(VT)) { | ||||
8129 | APInt SplatUndef; | ||||
8130 | unsigned SplatBitSize; | ||||
8131 | bool HasAnyUndefs; | ||||
8132 | |||||
Saleem Abdulrasool | 0c2ee5a | 2013-07-30 04:43:08 +0000 | [diff] [blame] | 8133 | APInt SplatBits0, SplatBits1; |
Cameron Zwarich | 53dd03d | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 8134 | BuildVectorSDNode *BVN0 = dyn_cast<BuildVectorSDNode>(N0->getOperand(1)); |
Saleem Abdulrasool | 0c2ee5a | 2013-07-30 04:43:08 +0000 | [diff] [blame] | 8135 | BuildVectorSDNode *BVN1 = dyn_cast<BuildVectorSDNode>(N1->getOperand(1)); |
8136 | // Ensure that the second operand of both ands are constants | ||||
Cameron Zwarich | 53dd03d | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 8137 | if (BVN0 && BVN0->isConstantSplat(SplatBits0, SplatUndef, SplatBitSize, |
Saleem Abdulrasool | 0c2ee5a | 2013-07-30 04:43:08 +0000 | [diff] [blame] | 8138 | HasAnyUndefs) && !HasAnyUndefs) { |
8139 | if (BVN1 && BVN1->isConstantSplat(SplatBits1, SplatUndef, SplatBitSize, | ||||
8140 | HasAnyUndefs) && !HasAnyUndefs) { | ||||
8141 | // Ensure that the bit width of the constants are the same and that | ||||
8142 | // the splat arguments are logical inverses as per the pattern we | ||||
8143 | // are trying to simplify. | ||||
8144 | if (SplatBits0.getBitWidth() == SplatBits1.getBitWidth() && | ||||
8145 | SplatBits0 == ~SplatBits1) { | ||||
8146 | // Canonicalize the vector type to make instruction selection | ||||
8147 | // simpler. | ||||
8148 | EVT CanonicalVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; | ||||
8149 | SDValue Result = DAG.getNode(ARMISD::VBSL, dl, CanonicalVT, | ||||
8150 | N0->getOperand(1), | ||||
8151 | N0->getOperand(0), | ||||
8152 | N1->getOperand(0)); | ||||
8153 | return DAG.getNode(ISD::BITCAST, dl, VT, Result); | ||||
8154 | } | ||||
8155 | } | ||||
Cameron Zwarich | 53dd03d | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 8156 | } |
8157 | } | ||||
8158 | |||||
Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8159 | // Try to use the ARM/Thumb2 BFI (bitfield insert) instruction when |
8160 | // reasonable. | ||||
8161 | |||||
Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8162 | // BFI is only available on V6T2+ |
8163 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6T2Ops()) | ||||
8164 | return SDValue(); | ||||
8165 | |||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8166 | SDLoc DL(N); |
Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8167 | // 1) or (and A, mask), val => ARMbfi A, val, mask |
Sylvestre Ledru | 91ce36c | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 8168 | // iff (val & mask) == val |
Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8169 | // |
8170 | // 2) or (and A, mask), (and B, mask2) => ARMbfi A, (lsr B, amt), mask | ||||
Sylvestre Ledru | 91ce36c | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 8171 | // 2a) iff isBitFieldInvertedMask(mask) && isBitFieldInvertedMask(~mask2) |
Eric Christopher | d553096 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8172 | // && mask == ~mask2 |
Sylvestre Ledru | 91ce36c | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 8173 | // 2b) iff isBitFieldInvertedMask(~mask) && isBitFieldInvertedMask(mask2) |
Eric Christopher | d553096 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8174 | // && ~mask == mask2 |
Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8175 | // (i.e., copy a bitfield value into another bitfield of the same width) |
Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8176 | |
Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8177 | if (VT != MVT::i32) |
8178 | return SDValue(); | ||||
8179 | |||||
Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8180 | SDValue N00 = N0.getOperand(0); |
Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8181 | |
Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8182 | // The value and the mask need to be constants so we can verify this is |
8183 | // actually a bitfield set. If the mask is 0xffff, we can do better | ||||
8184 | // via a movt instruction, so don't use BFI in that case. | ||||
Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8185 | SDValue MaskOp = N0.getOperand(1); |
8186 | ConstantSDNode *MaskC = dyn_cast<ConstantSDNode>(MaskOp); | ||||
8187 | if (!MaskC) | ||||
Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8188 | return SDValue(); |
Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8189 | unsigned Mask = MaskC->getZExtValue(); |
Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8190 | if (Mask == 0xffff) |
8191 | return SDValue(); | ||||
Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8192 | SDValue Res; |
8193 | // Case (1): or (and A, mask), val => ARMbfi A, val, mask | ||||
Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8194 | ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1); |
8195 | if (N1C) { | ||||
8196 | unsigned Val = N1C->getZExtValue(); | ||||
Evan Cheng | 3434575 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 8197 | if ((Val & ~Mask) != Val) |
Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8198 | return SDValue(); |
Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8199 | |
Evan Cheng | 3434575 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 8200 | if (ARM::isBitFieldInvertedMask(Mask)) { |
Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 8201 | Val >>= countTrailingZeros(~Mask); |
Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8202 | |
Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8203 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, |
Evan Cheng | 3434575 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 8204 | DAG.getConstant(Val, MVT::i32), |
8205 | DAG.getConstant(Mask, MVT::i32)); | ||||
8206 | |||||
8207 | // Do not add new nodes to DAG combiner worklist. | ||||
8208 | DCI.CombineTo(N, Res, false); | ||||
Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8209 | return SDValue(); |
Evan Cheng | 3434575 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 8210 | } |
Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8211 | } else if (N1.getOpcode() == ISD::AND) { |
8212 | // case (2) or (and A, mask), (and B, mask2) => ARMbfi A, (lsr B, amt), mask | ||||
Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8213 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
8214 | if (!N11C) | ||||
Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8215 | return SDValue(); |
Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8216 | unsigned Mask2 = N11C->getZExtValue(); |
Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8217 | |
Eric Christopher | d553096 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8218 | // Mask and ~Mask2 (or reverse) must be equivalent for the BFI pattern |
8219 | // as is to match. | ||||
Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8220 | if (ARM::isBitFieldInvertedMask(Mask) && |
Eric Christopher | d553096 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8221 | (Mask == ~Mask2)) { |
Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8222 | // The pack halfword instruction works better for masks that fit it, |
8223 | // so use that when it's available. | ||||
8224 | if (Subtarget->hasT2ExtractPack() && | ||||
8225 | (Mask == 0xffff || Mask == 0xffff0000)) | ||||
8226 | return SDValue(); | ||||
8227 | // 2a | ||||
Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 8228 | unsigned amt = countTrailingZeros(Mask2); |
Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8229 | Res = DAG.getNode(ISD::SRL, DL, VT, N1.getOperand(0), |
Eric Christopher | d553096 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8230 | DAG.getConstant(amt, MVT::i32)); |
Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8231 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, Res, |
Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8232 | DAG.getConstant(Mask, MVT::i32)); |
8233 | // Do not add new nodes to DAG combiner worklist. | ||||
8234 | DCI.CombineTo(N, Res, false); | ||||
Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8235 | return SDValue(); |
Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8236 | } else if (ARM::isBitFieldInvertedMask(~Mask) && |
Eric Christopher | d553096 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8237 | (~Mask == Mask2)) { |
Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8238 | // The pack halfword instruction works better for masks that fit it, |
8239 | // so use that when it's available. | ||||
8240 | if (Subtarget->hasT2ExtractPack() && | ||||
8241 | (Mask2 == 0xffff || Mask2 == 0xffff0000)) | ||||
8242 | return SDValue(); | ||||
8243 | // 2b | ||||
Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 8244 | unsigned lsb = countTrailingZeros(Mask); |
Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8245 | Res = DAG.getNode(ISD::SRL, DL, VT, N00, |
Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8246 | DAG.getConstant(lsb, MVT::i32)); |
8247 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1.getOperand(0), Res, | ||||
Eric Christopher | d553096 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8248 | DAG.getConstant(Mask2, MVT::i32)); |
Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8249 | // Do not add new nodes to DAG combiner worklist. |
8250 | DCI.CombineTo(N, Res, false); | ||||
Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8251 | return SDValue(); |
Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8252 | } |
8253 | } | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8254 | |
Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8255 | if (DAG.MaskedValueIsZero(N1, MaskC->getAPIntValue()) && |
8256 | N00.getOpcode() == ISD::SHL && isa<ConstantSDNode>(N00.getOperand(1)) && | ||||
8257 | ARM::isBitFieldInvertedMask(~Mask)) { | ||||
8258 | // Case (3): or (and (shl A, #shamt), mask), B => ARMbfi B, A, ~mask | ||||
8259 | // where lsb(mask) == #shamt and masked bits of B are known zero. | ||||
8260 | SDValue ShAmt = N00.getOperand(1); | ||||
8261 | unsigned ShAmtC = cast<ConstantSDNode>(ShAmt)->getZExtValue(); | ||||
Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 8262 | unsigned LSB = countTrailingZeros(Mask); |
Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8263 | if (ShAmtC != LSB) |
8264 | return SDValue(); | ||||
8265 | |||||
8266 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1, N00.getOperand(0), | ||||
8267 | DAG.getConstant(~Mask, MVT::i32)); | ||||
8268 | |||||
8269 | // Do not add new nodes to DAG combiner worklist. | ||||
8270 | DCI.CombineTo(N, Res, false); | ||||
8271 | } | ||||
8272 | |||||
Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8273 | return SDValue(); |
8274 | } | ||||
8275 | |||||
Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8276 | static SDValue PerformXORCombine(SDNode *N, |
8277 | TargetLowering::DAGCombinerInfo &DCI, | ||||
8278 | const ARMSubtarget *Subtarget) { | ||||
8279 | EVT VT = N->getValueType(0); | ||||
8280 | SelectionDAG &DAG = DCI.DAG; | ||||
8281 | |||||
8282 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) | ||||
8283 | return SDValue(); | ||||
8284 | |||||
8285 | if (!Subtarget->isThumb1Only()) { | ||||
Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8286 | // fold (xor (select cc, 0, c), x) -> (select cc, x, (xor, x, c)) |
8287 | SDValue Result = combineSelectAndUseCommutative(N, false, DCI); | ||||
8288 | if (Result.getNode()) | ||||
8289 | return Result; | ||||
Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8290 | } |
8291 | |||||
8292 | return SDValue(); | ||||
8293 | } | ||||
8294 | |||||
Evan Cheng | 6d02d90 | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 8295 | /// PerformBFICombine - (bfi A, (and B, Mask1), Mask2) -> (bfi A, B, Mask2) iff |
8296 | /// the bits being cleared by the AND are not demanded by the BFI. | ||||
Evan Cheng | c177813 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 8297 | static SDValue PerformBFICombine(SDNode *N, |
8298 | TargetLowering::DAGCombinerInfo &DCI) { | ||||
8299 | SDValue N1 = N->getOperand(1); | ||||
8300 | if (N1.getOpcode() == ISD::AND) { | ||||
8301 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); | ||||
8302 | if (!N11C) | ||||
8303 | return SDValue(); | ||||
Evan Cheng | 6d02d90 | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 8304 | unsigned InvMask = cast<ConstantSDNode>(N->getOperand(2))->getZExtValue(); |
Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 8305 | unsigned LSB = countTrailingZeros(~InvMask); |
8306 | unsigned Width = (32 - countLeadingZeros(~InvMask)) - LSB; | ||||
Evan Cheng | 6d02d90 | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 8307 | unsigned Mask = (1 << Width)-1; |
Evan Cheng | c177813 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 8308 | unsigned Mask2 = N11C->getZExtValue(); |
Evan Cheng | 6d02d90 | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 8309 | if ((Mask & (~Mask2)) == 0) |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8310 | return DCI.DAG.getNode(ARMISD::BFI, SDLoc(N), N->getValueType(0), |
Evan Cheng | c177813 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 8311 | N->getOperand(0), N1.getOperand(0), |
8312 | N->getOperand(2)); | ||||
8313 | } | ||||
8314 | return SDValue(); | ||||
8315 | } | ||||
8316 | |||||
Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 8317 | /// PerformVMOVRRDCombine - Target-specific dag combine xforms for |
8318 | /// ARMISD::VMOVRRD. | ||||
8319 | static SDValue PerformVMOVRRDCombine(SDNode *N, | ||||
8320 | TargetLowering::DAGCombinerInfo &DCI) { | ||||
8321 | // vmovrrd(vmovdrr x, y) -> x,y | ||||
8322 | SDValue InDouble = N->getOperand(0); | ||||
8323 | if (InDouble.getOpcode() == ARMISD::VMOVDRR) | ||||
8324 | return DCI.CombineTo(N, InDouble.getOperand(0), InDouble.getOperand(1)); | ||||
Cameron Zwarich | 6fe5c29 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 8325 | |
8326 | // vmovrrd(load f64) -> (load i32), (load i32) | ||||
8327 | SDNode *InNode = InDouble.getNode(); | ||||
8328 | if (ISD::isNormalLoad(InNode) && InNode->hasOneUse() && | ||||
8329 | InNode->getValueType(0) == MVT::f64 && | ||||
8330 | InNode->getOperand(1).getOpcode() == ISD::FrameIndex && | ||||
8331 | !cast<LoadSDNode>(InNode)->isVolatile()) { | ||||
8332 | // TODO: Should this be done for non-FrameIndex operands? | ||||
8333 | LoadSDNode *LD = cast<LoadSDNode>(InNode); | ||||
8334 | |||||
8335 | SelectionDAG &DAG = DCI.DAG; | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8336 | SDLoc DL(LD); |
Cameron Zwarich | 6fe5c29 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 8337 | SDValue BasePtr = LD->getBasePtr(); |
8338 | SDValue NewLD1 = DAG.getLoad(MVT::i32, DL, LD->getChain(), BasePtr, | ||||
8339 | LD->getPointerInfo(), LD->isVolatile(), | ||||
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 8340 | LD->isNonTemporal(), LD->isInvariant(), |
8341 | LD->getAlignment()); | ||||
Cameron Zwarich | 6fe5c29 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 8342 | |
8343 | SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, | ||||
8344 | DAG.getConstant(4, MVT::i32)); | ||||
8345 | SDValue NewLD2 = DAG.getLoad(MVT::i32, DL, NewLD1.getValue(1), OffsetPtr, | ||||
8346 | LD->getPointerInfo(), LD->isVolatile(), | ||||
Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 8347 | LD->isNonTemporal(), LD->isInvariant(), |
Cameron Zwarich | 6fe5c29 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 8348 | std::min(4U, LD->getAlignment() / 2)); |
8349 | |||||
8350 | DAG.ReplaceAllUsesOfValueWith(SDValue(LD, 1), NewLD2.getValue(1)); | ||||
8351 | SDValue Result = DCI.CombineTo(N, NewLD1, NewLD2); | ||||
8352 | DCI.RemoveFromWorklist(LD); | ||||
8353 | DAG.DeleteNode(LD); | ||||
8354 | return Result; | ||||
8355 | } | ||||
8356 | |||||
Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 8357 | return SDValue(); |
8358 | } | ||||
8359 | |||||
8360 | /// PerformVMOVDRRCombine - Target-specific dag combine xforms for | ||||
8361 | /// ARMISD::VMOVDRR. This is also used for BUILD_VECTORs with 2 operands. | ||||
8362 | static SDValue PerformVMOVDRRCombine(SDNode *N, SelectionDAG &DAG) { | ||||
8363 | // N=vmovrrd(X); vmovdrr(N:0, N:1) -> bit_convert(X) | ||||
8364 | SDValue Op0 = N->getOperand(0); | ||||
8365 | SDValue Op1 = N->getOperand(1); | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8366 | if (Op0.getOpcode() == ISD::BITCAST) |
Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 8367 | Op0 = Op0.getOperand(0); |
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8368 | if (Op1.getOpcode() == ISD::BITCAST) |
Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 8369 | Op1 = Op1.getOperand(0); |
8370 | if (Op0.getOpcode() == ARMISD::VMOVRRD && | ||||
8371 | Op0.getNode() == Op1.getNode() && | ||||
8372 | Op0.getResNo() == 0 && Op1.getResNo() == 1) | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8373 | return DAG.getNode(ISD::BITCAST, SDLoc(N), |
Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 8374 | N->getValueType(0), Op0.getOperand(0)); |
8375 | return SDValue(); | ||||
8376 | } | ||||
8377 | |||||
Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8378 | /// PerformSTORECombine - Target-specific dag combine xforms for |
8379 | /// ISD::STORE. | ||||
8380 | static SDValue PerformSTORECombine(SDNode *N, | ||||
8381 | TargetLowering::DAGCombinerInfo &DCI) { | ||||
Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8382 | StoreSDNode *St = cast<StoreSDNode>(N); |
Chad Rosier | e0e38f6 | 2012-04-09 20:32:02 +0000 | [diff] [blame] | 8383 | if (St->isVolatile()) |
8384 | return SDValue(); | ||||
8385 | |||||
Andrew Trick | bc32516 | 2012-07-18 18:34:24 +0000 | [diff] [blame] | 8386 | // Optimize trunc store (of multiple scalars) to shuffle and store. First, |
Chad Rosier | e0e38f6 | 2012-04-09 20:32:02 +0000 | [diff] [blame] | 8387 | // pack all of the elements in one place. Next, store to memory in fewer |
8388 | // chunks. | ||||
Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8389 | SDValue StVal = St->getValue(); |
Chad Rosier | e0e38f6 | 2012-04-09 20:32:02 +0000 | [diff] [blame] | 8390 | EVT VT = StVal.getValueType(); |
8391 | if (St->isTruncatingStore() && VT.isVector()) { | ||||
8392 | SelectionDAG &DAG = DCI.DAG; | ||||
8393 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); | ||||
8394 | EVT StVT = St->getMemoryVT(); | ||||
8395 | unsigned NumElems = VT.getVectorNumElements(); | ||||
8396 | assert(StVT != VT && "Cannot truncate to the same type"); | ||||
8397 | unsigned FromEltSz = VT.getVectorElementType().getSizeInBits(); | ||||
8398 | unsigned ToEltSz = StVT.getVectorElementType().getSizeInBits(); | ||||
8399 | |||||
8400 | // From, To sizes and ElemCount must be pow of two | ||||
8401 | if (!isPowerOf2_32(NumElems * FromEltSz * ToEltSz)) return SDValue(); | ||||
8402 | |||||
8403 | // We are going to use the original vector elt for storing. | ||||
8404 | // Accumulated smaller vector elements must be a multiple of the store size. | ||||
8405 | if (0 != (NumElems * FromEltSz) % ToEltSz) return SDValue(); | ||||
8406 | |||||
8407 | unsigned SizeRatio = FromEltSz / ToEltSz; | ||||
8408 | assert(SizeRatio * NumElems * ToEltSz == VT.getSizeInBits()); | ||||
8409 | |||||
8410 | // Create a type on which we perform the shuffle. | ||||
8411 | EVT WideVecVT = EVT::getVectorVT(*DAG.getContext(), StVT.getScalarType(), | ||||
8412 | NumElems*SizeRatio); | ||||
8413 | assert(WideVecVT.getSizeInBits() == VT.getSizeInBits()); | ||||
8414 | |||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8415 | SDLoc DL(St); |
Chad Rosier | e0e38f6 | 2012-04-09 20:32:02 +0000 | [diff] [blame] | 8416 | SDValue WideVec = DAG.getNode(ISD::BITCAST, DL, WideVecVT, StVal); |
8417 | SmallVector<int, 8> ShuffleVec(NumElems * SizeRatio, -1); | ||||
8418 | for (unsigned i = 0; i < NumElems; ++i) ShuffleVec[i] = i * SizeRatio; | ||||
8419 | |||||
8420 | // Can't shuffle using an illegal type. | ||||
8421 | if (!TLI.isTypeLegal(WideVecVT)) return SDValue(); | ||||
8422 | |||||
8423 | SDValue Shuff = DAG.getVectorShuffle(WideVecVT, DL, WideVec, | ||||
8424 | DAG.getUNDEF(WideVec.getValueType()), | ||||
8425 | ShuffleVec.data()); | ||||
8426 | // At this point all of the data is stored at the bottom of the | ||||
8427 | // register. We now need to save it to mem. | ||||
8428 | |||||
8429 | // Find the largest store unit | ||||
8430 | MVT StoreType = MVT::i8; | ||||
8431 | for (unsigned tp = MVT::FIRST_INTEGER_VALUETYPE; | ||||
8432 | tp < MVT::LAST_INTEGER_VALUETYPE; ++tp) { | ||||
8433 | MVT Tp = (MVT::SimpleValueType)tp; | ||||
8434 | if (TLI.isTypeLegal(Tp) && Tp.getSizeInBits() <= NumElems * ToEltSz) | ||||
8435 | StoreType = Tp; | ||||
8436 | } | ||||
8437 | // Didn't find a legal store type. | ||||
8438 | if (!TLI.isTypeLegal(StoreType)) | ||||
8439 | return SDValue(); | ||||
8440 | |||||
8441 | // Bitcast the original vector into a vector of store-size units | ||||
8442 | EVT StoreVecVT = EVT::getVectorVT(*DAG.getContext(), | ||||
8443 | StoreType, VT.getSizeInBits()/EVT(StoreType).getSizeInBits()); | ||||
8444 | assert(StoreVecVT.getSizeInBits() == VT.getSizeInBits()); | ||||
8445 | SDValue ShuffWide = DAG.getNode(ISD::BITCAST, DL, StoreVecVT, Shuff); | ||||
8446 | SmallVector<SDValue, 8> Chains; | ||||
8447 | SDValue Increment = DAG.getConstant(StoreType.getSizeInBits()/8, | ||||
8448 | TLI.getPointerTy()); | ||||
8449 | SDValue BasePtr = St->getBasePtr(); | ||||
8450 | |||||
8451 | // Perform one or more big stores into memory. | ||||
8452 | unsigned E = (ToEltSz*NumElems)/StoreType.getSizeInBits(); | ||||
8453 | for (unsigned I = 0; I < E; I++) { | ||||
8454 | SDValue SubVec = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, | ||||
8455 | StoreType, ShuffWide, | ||||
8456 | DAG.getIntPtrConstant(I)); | ||||
8457 | SDValue Ch = DAG.getStore(St->getChain(), DL, SubVec, BasePtr, | ||||
8458 | St->getPointerInfo(), St->isVolatile(), | ||||
8459 | St->isNonTemporal(), St->getAlignment()); | ||||
8460 | BasePtr = DAG.getNode(ISD::ADD, DL, BasePtr.getValueType(), BasePtr, | ||||
8461 | Increment); | ||||
8462 | Chains.push_back(Ch); | ||||
8463 | } | ||||
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 8464 | return DAG.getNode(ISD::TokenFactor, DL, MVT::Other, Chains); |
Chad Rosier | e0e38f6 | 2012-04-09 20:32:02 +0000 | [diff] [blame] | 8465 | } |
8466 | |||||
8467 | if (!ISD::isNormalStore(St)) | ||||
Cameron Zwarich | fbcd69b | 2011-04-12 02:24:17 +0000 | [diff] [blame] | 8468 | return SDValue(); |
8469 | |||||
Chad Rosier | 99cbde9 | 2012-04-09 19:38:15 +0000 | [diff] [blame] | 8470 | // Split a store of a VMOVDRR into two integer stores to avoid mixing NEON and |
8471 | // ARM stores of arguments in the same cache line. | ||||
Cameron Zwarich | fbcd69b | 2011-04-12 02:24:17 +0000 | [diff] [blame] | 8472 | if (StVal.getNode()->getOpcode() == ARMISD::VMOVDRR && |
Chad Rosier | 99cbde9 | 2012-04-09 19:38:15 +0000 | [diff] [blame] | 8473 | StVal.getNode()->hasOneUse()) { |
Cameron Zwarich | fbcd69b | 2011-04-12 02:24:17 +0000 | [diff] [blame] | 8474 | SelectionDAG &DAG = DCI.DAG; |
Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 8475 | bool isBigEndian = DAG.getTargetLoweringInfo().isBigEndian(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8476 | SDLoc DL(St); |
Cameron Zwarich | fbcd69b | 2011-04-12 02:24:17 +0000 | [diff] [blame] | 8477 | SDValue BasePtr = St->getBasePtr(); |
8478 | SDValue NewST1 = DAG.getStore(St->getChain(), DL, | ||||
Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 8479 | StVal.getNode()->getOperand(isBigEndian ? 1 : 0 ), |
8480 | BasePtr, St->getPointerInfo(), St->isVolatile(), | ||||
Cameron Zwarich | fbcd69b | 2011-04-12 02:24:17 +0000 | [diff] [blame] | 8481 | St->isNonTemporal(), St->getAlignment()); |
8482 | |||||
8483 | SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, | ||||
8484 | DAG.getConstant(4, MVT::i32)); | ||||
Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 8485 | return DAG.getStore(NewST1.getValue(0), DL, |
8486 | StVal.getNode()->getOperand(isBigEndian ? 0 : 1), | ||||
Cameron Zwarich | fbcd69b | 2011-04-12 02:24:17 +0000 | [diff] [blame] | 8487 | OffsetPtr, St->getPointerInfo(), St->isVolatile(), |
8488 | St->isNonTemporal(), | ||||
8489 | std::min(4U, St->getAlignment() / 2)); | ||||
8490 | } | ||||
8491 | |||||
8492 | if (StVal.getValueType() != MVT::i64 || | ||||
Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8493 | StVal.getNode()->getOpcode() != ISD::EXTRACT_VECTOR_ELT) |
8494 | return SDValue(); | ||||
8495 | |||||
Chad Rosier | 99cbde9 | 2012-04-09 19:38:15 +0000 | [diff] [blame] | 8496 | // Bitcast an i64 store extracted from a vector to f64. |
8497 | // Otherwise, the i64 value will be legalized to a pair of i32 values. | ||||
Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8498 | SelectionDAG &DAG = DCI.DAG; |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8499 | SDLoc dl(StVal); |
Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8500 | SDValue IntVec = StVal.getOperand(0); |
8501 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, | ||||
8502 | IntVec.getValueType().getVectorNumElements()); | ||||
8503 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, IntVec); | ||||
8504 | SDValue ExtElt = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, | ||||
8505 | Vec, StVal.getOperand(1)); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8506 | dl = SDLoc(N); |
Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8507 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::i64, ExtElt); |
8508 | // Make the DAGCombiner fold the bitcasts. | ||||
8509 | DCI.AddToWorklist(Vec.getNode()); | ||||
8510 | DCI.AddToWorklist(ExtElt.getNode()); | ||||
8511 | DCI.AddToWorklist(V.getNode()); | ||||
8512 | return DAG.getStore(St->getChain(), dl, V, St->getBasePtr(), | ||||
8513 | St->getPointerInfo(), St->isVolatile(), | ||||
8514 | St->isNonTemporal(), St->getAlignment(), | ||||
8515 | St->getTBAAInfo()); | ||||
8516 | } | ||||
8517 | |||||
8518 | /// hasNormalLoadOperand - Check if any of the operands of a BUILD_VECTOR node | ||||
8519 | /// are normal, non-volatile loads. If so, it is profitable to bitcast an | ||||
8520 | /// i64 vector to have f64 elements, since the value can then be loaded | ||||
8521 | /// directly into a VFP register. | ||||
8522 | static bool hasNormalLoadOperand(SDNode *N) { | ||||
8523 | unsigned NumElts = N->getValueType(0).getVectorNumElements(); | ||||
8524 | for (unsigned i = 0; i < NumElts; ++i) { | ||||
8525 | SDNode *Elt = N->getOperand(i).getNode(); | ||||
8526 | if (ISD::isNormalLoad(Elt) && !cast<LoadSDNode>(Elt)->isVolatile()) | ||||
8527 | return true; | ||||
8528 | } | ||||
8529 | return false; | ||||
8530 | } | ||||
8531 | |||||
Bob Wilson | cb6db98 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 8532 | /// PerformBUILD_VECTORCombine - Target-specific dag combine xforms for |
8533 | /// ISD::BUILD_VECTOR. | ||||
Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8534 | static SDValue PerformBUILD_VECTORCombine(SDNode *N, |
8535 | TargetLowering::DAGCombinerInfo &DCI){ | ||||
Bob Wilson | cb6db98 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 8536 | // build_vector(N=ARMISD::VMOVRRD(X), N:1) -> bit_convert(X): |
8537 | // VMOVRRD is introduced when legalizing i64 types. It forces the i64 value | ||||
8538 | // into a pair of GPRs, which is fine when the value is used as a scalar, | ||||
8539 | // but if the i64 value is converted to a vector, we need to undo the VMOVRRD. | ||||
Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8540 | SelectionDAG &DAG = DCI.DAG; |
8541 | if (N->getNumOperands() == 2) { | ||||
8542 | SDValue RV = PerformVMOVDRRCombine(N, DAG); | ||||
8543 | if (RV.getNode()) | ||||
8544 | return RV; | ||||
8545 | } | ||||
Bob Wilson | cb6db98 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 8546 | |
Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8547 | // Load i64 elements as f64 values so that type legalization does not split |
8548 | // them up into i32 values. | ||||
8549 | EVT VT = N->getValueType(0); | ||||
8550 | if (VT.getVectorElementType() != MVT::i64 || !hasNormalLoadOperand(N)) | ||||
8551 | return SDValue(); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8552 | SDLoc dl(N); |
Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8553 | SmallVector<SDValue, 8> Ops; |
8554 | unsigned NumElts = VT.getVectorNumElements(); | ||||
8555 | for (unsigned i = 0; i < NumElts; ++i) { | ||||
8556 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(i)); | ||||
8557 | Ops.push_back(V); | ||||
8558 | // Make the DAGCombiner fold the bitcast. | ||||
8559 | DCI.AddToWorklist(V.getNode()); | ||||
8560 | } | ||||
8561 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, NumElts); | ||||
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 8562 | SDValue BV = DAG.getNode(ISD::BUILD_VECTOR, dl, FloatVT, Ops); |
Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8563 | return DAG.getNode(ISD::BITCAST, dl, VT, BV); |
8564 | } | ||||
8565 | |||||
Quentin Colombet | 04b3a0f | 2013-07-03 21:42:57 +0000 | [diff] [blame] | 8566 | /// \brief Target-specific dag combine xforms for ARMISD::BUILD_VECTOR. |
8567 | static SDValue | ||||
8568 | PerformARMBUILD_VECTORCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) { | ||||
8569 | // ARMISD::BUILD_VECTOR is introduced when legalizing ISD::BUILD_VECTOR. | ||||
8570 | // At that time, we may have inserted bitcasts from integer to float. | ||||
8571 | // If these bitcasts have survived DAGCombine, change the lowering of this | ||||
8572 | // BUILD_VECTOR in something more vector friendly, i.e., that does not | ||||
8573 | // force to use floating point types. | ||||
8574 | |||||
8575 | // Make sure we can change the type of the vector. | ||||
8576 | // This is possible iff: | ||||
8577 | // 1. The vector is only used in a bitcast to a integer type. I.e., | ||||
8578 | // 1.1. Vector is used only once. | ||||
8579 | // 1.2. Use is a bit convert to an integer type. | ||||
8580 | // 2. The size of its operands are 32-bits (64-bits are not legal). | ||||
8581 | EVT VT = N->getValueType(0); | ||||
8582 | EVT EltVT = VT.getVectorElementType(); | ||||
8583 | |||||
8584 | // Check 1.1. and 2. | ||||
8585 | if (EltVT.getSizeInBits() != 32 || !N->hasOneUse()) | ||||
8586 | return SDValue(); | ||||
8587 | |||||
8588 | // By construction, the input type must be float. | ||||
8589 | assert(EltVT == MVT::f32 && "Unexpected type!"); | ||||
8590 | |||||
8591 | // Check 1.2. | ||||
8592 | SDNode *Use = *N->use_begin(); | ||||
8593 | if (Use->getOpcode() != ISD::BITCAST || | ||||
8594 | Use->getValueType(0).isFloatingPoint()) | ||||
8595 | return SDValue(); | ||||
8596 | |||||
8597 | // Check profitability. | ||||
8598 | // Model is, if more than half of the relevant operands are bitcast from | ||||
8599 | // i32, turn the build_vector into a sequence of insert_vector_elt. | ||||
8600 | // Relevant operands are everything that is not statically | ||||
8601 | // (i.e., at compile time) bitcasted. | ||||
8602 | unsigned NumOfBitCastedElts = 0; | ||||
8603 | unsigned NumElts = VT.getVectorNumElements(); | ||||
8604 | unsigned NumOfRelevantElts = NumElts; | ||||
8605 | for (unsigned Idx = 0; Idx < NumElts; ++Idx) { | ||||
8606 | SDValue Elt = N->getOperand(Idx); | ||||
8607 | if (Elt->getOpcode() == ISD::BITCAST) { | ||||
8608 | // Assume only bit cast to i32 will go away. | ||||
8609 | if (Elt->getOperand(0).getValueType() == MVT::i32) | ||||
8610 | ++NumOfBitCastedElts; | ||||
8611 | } else if (Elt.getOpcode() == ISD::UNDEF || isa<ConstantSDNode>(Elt)) | ||||
8612 | // Constants are statically casted, thus do not count them as | ||||
8613 | // relevant operands. | ||||
8614 | --NumOfRelevantElts; | ||||
8615 | } | ||||
8616 | |||||
8617 | // Check if more than half of the elements require a non-free bitcast. | ||||
8618 | if (NumOfBitCastedElts <= NumOfRelevantElts / 2) | ||||
8619 | return SDValue(); | ||||
8620 | |||||
8621 | SelectionDAG &DAG = DCI.DAG; | ||||
8622 | // Create the new vector type. | ||||
8623 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), MVT::i32, NumElts); | ||||
8624 | // Check if the type is legal. | ||||
8625 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); | ||||
8626 | if (!TLI.isTypeLegal(VecVT)) | ||||
8627 | return SDValue(); | ||||
8628 | |||||
8629 | // Combine: | ||||
8630 | // ARMISD::BUILD_VECTOR E1, E2, ..., EN. | ||||
8631 | // => BITCAST INSERT_VECTOR_ELT | ||||
8632 | // (INSERT_VECTOR_ELT (...), (BITCAST EN-1), N-1), | ||||
8633 | // (BITCAST EN), N. | ||||
8634 | SDValue Vec = DAG.getUNDEF(VecVT); | ||||
8635 | SDLoc dl(N); | ||||
8636 | for (unsigned Idx = 0 ; Idx < NumElts; ++Idx) { | ||||
8637 | SDValue V = N->getOperand(Idx); | ||||
8638 | if (V.getOpcode() == ISD::UNDEF) | ||||
8639 | continue; | ||||
8640 | if (V.getOpcode() == ISD::BITCAST && | ||||
8641 | V->getOperand(0).getValueType() == MVT::i32) | ||||
8642 | // Fold obvious case. | ||||
8643 | V = V.getOperand(0); | ||||
8644 | else { | ||||
Jim Grosbach | 1a59711 | 2014-04-03 23:43:18 +0000 | [diff] [blame] | 8645 | V = DAG.getNode(ISD::BITCAST, SDLoc(V), MVT::i32, V); |
Quentin Colombet | 04b3a0f | 2013-07-03 21:42:57 +0000 | [diff] [blame] | 8646 | // Make the DAGCombiner fold the bitcasts. |
8647 | DCI.AddToWorklist(V.getNode()); | ||||
8648 | } | ||||
8649 | SDValue LaneIdx = DAG.getConstant(Idx, MVT::i32); | ||||
8650 | Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VecVT, Vec, V, LaneIdx); | ||||
8651 | } | ||||
8652 | Vec = DAG.getNode(ISD::BITCAST, dl, VT, Vec); | ||||
8653 | // Make the DAGCombiner fold the bitcasts. | ||||
8654 | DCI.AddToWorklist(Vec.getNode()); | ||||
8655 | return Vec; | ||||
8656 | } | ||||
8657 | |||||
Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8658 | /// PerformInsertEltCombine - Target-specific dag combine xforms for |
8659 | /// ISD::INSERT_VECTOR_ELT. | ||||
8660 | static SDValue PerformInsertEltCombine(SDNode *N, | ||||
8661 | TargetLowering::DAGCombinerInfo &DCI) { | ||||
8662 | // Bitcast an i64 load inserted into a vector to f64. | ||||
8663 | // Otherwise, the i64 value will be legalized to a pair of i32 values. | ||||
8664 | EVT VT = N->getValueType(0); | ||||
8665 | SDNode *Elt = N->getOperand(1).getNode(); | ||||
8666 | if (VT.getVectorElementType() != MVT::i64 || | ||||
8667 | !ISD::isNormalLoad(Elt) || cast<LoadSDNode>(Elt)->isVolatile()) | ||||
8668 | return SDValue(); | ||||
8669 | |||||
8670 | SelectionDAG &DAG = DCI.DAG; | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8671 | SDLoc dl(N); |
Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8672 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
8673 | VT.getVectorNumElements()); | ||||
8674 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, N->getOperand(0)); | ||||
8675 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(1)); | ||||
8676 | // Make the DAGCombiner fold the bitcasts. | ||||
8677 | DCI.AddToWorklist(Vec.getNode()); | ||||
8678 | DCI.AddToWorklist(V.getNode()); | ||||
8679 | SDValue InsElt = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, FloatVT, | ||||
8680 | Vec, V, N->getOperand(2)); | ||||
8681 | return DAG.getNode(ISD::BITCAST, dl, VT, InsElt); | ||||
Bob Wilson | cb6db98 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 8682 | } |
8683 | |||||
Bob Wilson | c7334a1 | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 8684 | /// PerformVECTOR_SHUFFLECombine - Target-specific dag combine xforms for |
8685 | /// ISD::VECTOR_SHUFFLE. | ||||
8686 | static SDValue PerformVECTOR_SHUFFLECombine(SDNode *N, SelectionDAG &DAG) { | ||||
8687 | // The LLVM shufflevector instruction does not require the shuffle mask | ||||
8688 | // length to match the operand vector length, but ISD::VECTOR_SHUFFLE does | ||||
8689 | // have that requirement. When translating to ISD::VECTOR_SHUFFLE, if the | ||||
8690 | // operands do not match the mask length, they are extended by concatenating | ||||
8691 | // them with undef vectors. That is probably the right thing for other | ||||
8692 | // targets, but for NEON it is better to concatenate two double-register | ||||
8693 | // size vector operands into a single quad-register size vector. Do that | ||||
8694 | // transformation here: | ||||
8695 | // shuffle(concat(v1, undef), concat(v2, undef)) -> | ||||
8696 | // shuffle(concat(v1, v2), undef) | ||||
8697 | SDValue Op0 = N->getOperand(0); | ||||
8698 | SDValue Op1 = N->getOperand(1); | ||||
8699 | if (Op0.getOpcode() != ISD::CONCAT_VECTORS || | ||||
8700 | Op1.getOpcode() != ISD::CONCAT_VECTORS || | ||||
8701 | Op0.getNumOperands() != 2 || | ||||
8702 | Op1.getNumOperands() != 2) | ||||
8703 | return SDValue(); | ||||
8704 | SDValue Concat0Op1 = Op0.getOperand(1); | ||||
8705 | SDValue Concat1Op1 = Op1.getOperand(1); | ||||
8706 | if (Concat0Op1.getOpcode() != ISD::UNDEF || | ||||
8707 | Concat1Op1.getOpcode() != ISD::UNDEF) | ||||
8708 | return SDValue(); | ||||
8709 | // Skip the transformation if any of the types are illegal. | ||||
8710 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); | ||||
8711 | EVT VT = N->getValueType(0); | ||||
8712 | if (!TLI.isTypeLegal(VT) || | ||||
8713 | !TLI.isTypeLegal(Concat0Op1.getValueType()) || | ||||
8714 | !TLI.isTypeLegal(Concat1Op1.getValueType())) | ||||
8715 | return SDValue(); | ||||
8716 | |||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8717 | SDValue NewConcat = DAG.getNode(ISD::CONCAT_VECTORS, SDLoc(N), VT, |
Bob Wilson | c7334a1 | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 8718 | Op0.getOperand(0), Op1.getOperand(0)); |
8719 | // Translate the shuffle mask. | ||||
8720 | SmallVector<int, 16> NewMask; | ||||
8721 | unsigned NumElts = VT.getVectorNumElements(); | ||||
8722 | unsigned HalfElts = NumElts/2; | ||||
8723 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(N); | ||||
8724 | for (unsigned n = 0; n < NumElts; ++n) { | ||||
8725 | int MaskElt = SVN->getMaskElt(n); | ||||
8726 | int NewElt = -1; | ||||
Bob Wilson | 6c55007 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 8727 | if (MaskElt < (int)HalfElts) |
Bob Wilson | c7334a1 | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 8728 | NewElt = MaskElt; |
Bob Wilson | 6c55007 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 8729 | else if (MaskElt >= (int)NumElts && MaskElt < (int)(NumElts + HalfElts)) |
Bob Wilson | c7334a1 | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 8730 | NewElt = HalfElts + MaskElt - NumElts; |
8731 | NewMask.push_back(NewElt); | ||||
8732 | } | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8733 | return DAG.getVectorShuffle(VT, SDLoc(N), NewConcat, |
Bob Wilson | c7334a1 | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 8734 | DAG.getUNDEF(VT), NewMask.data()); |
8735 | } | ||||
8736 | |||||
Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8737 | /// CombineBaseUpdate - Target-specific DAG combine function for VLDDUP and |
8738 | /// NEON load/store intrinsics to merge base address updates. | ||||
8739 | static SDValue CombineBaseUpdate(SDNode *N, | ||||
8740 | TargetLowering::DAGCombinerInfo &DCI) { | ||||
8741 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) | ||||
8742 | return SDValue(); | ||||
8743 | |||||
8744 | SelectionDAG &DAG = DCI.DAG; | ||||
8745 | bool isIntrinsic = (N->getOpcode() == ISD::INTRINSIC_VOID || | ||||
8746 | N->getOpcode() == ISD::INTRINSIC_W_CHAIN); | ||||
8747 | unsigned AddrOpIdx = (isIntrinsic ? 2 : 1); | ||||
8748 | SDValue Addr = N->getOperand(AddrOpIdx); | ||||
8749 | |||||
8750 | // Search for a use of the address operand that is an increment. | ||||
8751 | for (SDNode::use_iterator UI = Addr.getNode()->use_begin(), | ||||
8752 | UE = Addr.getNode()->use_end(); UI != UE; ++UI) { | ||||
8753 | SDNode *User = *UI; | ||||
8754 | if (User->getOpcode() != ISD::ADD || | ||||
8755 | UI.getUse().getResNo() != Addr.getResNo()) | ||||
8756 | continue; | ||||
8757 | |||||
8758 | // Check that the add is independent of the load/store. Otherwise, folding | ||||
8759 | // it would create a cycle. | ||||
8760 | if (User->isPredecessorOf(N) || N->isPredecessorOf(User)) | ||||
8761 | continue; | ||||
8762 | |||||
8763 | // Find the new opcode for the updating load/store. | ||||
8764 | bool isLoad = true; | ||||
8765 | bool isLaneOp = false; | ||||
8766 | unsigned NewOpc = 0; | ||||
8767 | unsigned NumVecs = 0; | ||||
8768 | if (isIntrinsic) { | ||||
8769 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue(); | ||||
8770 | switch (IntNo) { | ||||
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 8771 | default: llvm_unreachable("unexpected intrinsic for Neon base update"); |
Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8772 | case Intrinsic::arm_neon_vld1: NewOpc = ARMISD::VLD1_UPD; |
8773 | NumVecs = 1; break; | ||||
8774 | case Intrinsic::arm_neon_vld2: NewOpc = ARMISD::VLD2_UPD; | ||||
8775 | NumVecs = 2; break; | ||||
8776 | case Intrinsic::arm_neon_vld3: NewOpc = ARMISD::VLD3_UPD; | ||||
8777 | NumVecs = 3; break; | ||||
8778 | case Intrinsic::arm_neon_vld4: NewOpc = ARMISD::VLD4_UPD; | ||||
8779 | NumVecs = 4; break; | ||||
8780 | case Intrinsic::arm_neon_vld2lane: NewOpc = ARMISD::VLD2LN_UPD; | ||||
8781 | NumVecs = 2; isLaneOp = true; break; | ||||
8782 | case Intrinsic::arm_neon_vld3lane: NewOpc = ARMISD::VLD3LN_UPD; | ||||
8783 | NumVecs = 3; isLaneOp = true; break; | ||||
8784 | case Intrinsic::arm_neon_vld4lane: NewOpc = ARMISD::VLD4LN_UPD; | ||||
8785 | NumVecs = 4; isLaneOp = true; break; | ||||
8786 | case Intrinsic::arm_neon_vst1: NewOpc = ARMISD::VST1_UPD; | ||||
8787 | NumVecs = 1; isLoad = false; break; | ||||
8788 | case Intrinsic::arm_neon_vst2: NewOpc = ARMISD::VST2_UPD; | ||||
8789 | NumVecs = 2; isLoad = false; break; | ||||
8790 | case Intrinsic::arm_neon_vst3: NewOpc = ARMISD::VST3_UPD; | ||||
8791 | NumVecs = 3; isLoad = false; break; | ||||
8792 | case Intrinsic::arm_neon_vst4: NewOpc = ARMISD::VST4_UPD; | ||||
8793 | NumVecs = 4; isLoad = false; break; | ||||
8794 | case Intrinsic::arm_neon_vst2lane: NewOpc = ARMISD::VST2LN_UPD; | ||||
8795 | NumVecs = 2; isLoad = false; isLaneOp = true; break; | ||||
8796 | case Intrinsic::arm_neon_vst3lane: NewOpc = ARMISD::VST3LN_UPD; | ||||
8797 | NumVecs = 3; isLoad = false; isLaneOp = true; break; | ||||
8798 | case Intrinsic::arm_neon_vst4lane: NewOpc = ARMISD::VST4LN_UPD; | ||||
8799 | NumVecs = 4; isLoad = false; isLaneOp = true; break; | ||||
8800 | } | ||||
8801 | } else { | ||||
8802 | isLaneOp = true; | ||||
8803 | switch (N->getOpcode()) { | ||||
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 8804 | default: llvm_unreachable("unexpected opcode for Neon base update"); |
Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8805 | case ARMISD::VLD2DUP: NewOpc = ARMISD::VLD2DUP_UPD; NumVecs = 2; break; |
8806 | case ARMISD::VLD3DUP: NewOpc = ARMISD::VLD3DUP_UPD; NumVecs = 3; break; | ||||
8807 | case ARMISD::VLD4DUP: NewOpc = ARMISD::VLD4DUP_UPD; NumVecs = 4; break; | ||||
8808 | } | ||||
8809 | } | ||||
8810 | |||||
8811 | // Find the size of memory referenced by the load/store. | ||||
8812 | EVT VecTy; | ||||
8813 | if (isLoad) | ||||
8814 | VecTy = N->getValueType(0); | ||||
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 8815 | else |
Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8816 | VecTy = N->getOperand(AddrOpIdx+1).getValueType(); |
8817 | unsigned NumBytes = NumVecs * VecTy.getSizeInBits() / 8; | ||||
8818 | if (isLaneOp) | ||||
8819 | NumBytes /= VecTy.getVectorNumElements(); | ||||
8820 | |||||
8821 | // If the increment is a constant, it must match the memory ref size. | ||||
8822 | SDValue Inc = User->getOperand(User->getOperand(0) == Addr ? 1 : 0); | ||||
8823 | if (ConstantSDNode *CInc = dyn_cast<ConstantSDNode>(Inc.getNode())) { | ||||
8824 | uint64_t IncVal = CInc->getZExtValue(); | ||||
8825 | if (IncVal != NumBytes) | ||||
8826 | continue; | ||||
8827 | } else if (NumBytes >= 3 * 16) { | ||||
8828 | // VLD3/4 and VST3/4 for 128-bit vectors are implemented with two | ||||
8829 | // separate instructions that make it harder to use a non-constant update. | ||||
8830 | continue; | ||||
8831 | } | ||||
8832 | |||||
8833 | // Create the new updating load/store node. | ||||
8834 | EVT Tys[6]; | ||||
8835 | unsigned NumResultVecs = (isLoad ? NumVecs : 0); | ||||
8836 | unsigned n; | ||||
8837 | for (n = 0; n < NumResultVecs; ++n) | ||||
8838 | Tys[n] = VecTy; | ||||
8839 | Tys[n++] = MVT::i32; | ||||
8840 | Tys[n] = MVT::Other; | ||||
Craig Topper | abb4ac7 | 2014-04-16 06:10:51 +0000 | [diff] [blame] | 8841 | SDVTList SDTys = DAG.getVTList(ArrayRef<EVT>(Tys, NumResultVecs+2)); |
Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8842 | SmallVector<SDValue, 8> Ops; |
8843 | Ops.push_back(N->getOperand(0)); // incoming chain | ||||
8844 | Ops.push_back(N->getOperand(AddrOpIdx)); | ||||
8845 | Ops.push_back(Inc); | ||||
8846 | for (unsigned i = AddrOpIdx + 1; i < N->getNumOperands(); ++i) { | ||||
8847 | Ops.push_back(N->getOperand(i)); | ||||
8848 | } | ||||
8849 | MemIntrinsicSDNode *MemInt = cast<MemIntrinsicSDNode>(N); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8850 | SDValue UpdN = DAG.getMemIntrinsicNode(NewOpc, SDLoc(N), SDTys, |
Craig Topper | 206fcd4 | 2014-04-26 19:29:41 +0000 | [diff] [blame] | 8851 | Ops, MemInt->getMemoryVT(), |
Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8852 | MemInt->getMemOperand()); |
8853 | |||||
8854 | // Update the uses. | ||||
8855 | std::vector<SDValue> NewResults; | ||||
8856 | for (unsigned i = 0; i < NumResultVecs; ++i) { | ||||
8857 | NewResults.push_back(SDValue(UpdN.getNode(), i)); | ||||
8858 | } | ||||
8859 | NewResults.push_back(SDValue(UpdN.getNode(), NumResultVecs+1)); // chain | ||||
8860 | DCI.CombineTo(N, NewResults); | ||||
8861 | DCI.CombineTo(User, SDValue(UpdN.getNode(), NumResultVecs)); | ||||
8862 | |||||
8863 | break; | ||||
Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 8864 | } |
Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8865 | return SDValue(); |
8866 | } | ||||
8867 | |||||
Bob Wilson | 2d790df | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 8868 | /// CombineVLDDUP - For a VDUPLANE node N, check if its source operand is a |
8869 | /// vldN-lane (N > 1) intrinsic, and if all the other uses of that intrinsic | ||||
8870 | /// are also VDUPLANEs. If so, combine them to a vldN-dup operation and | ||||
8871 | /// return true. | ||||
8872 | static bool CombineVLDDUP(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) { | ||||
8873 | SelectionDAG &DAG = DCI.DAG; | ||||
8874 | EVT VT = N->getValueType(0); | ||||
8875 | // vldN-dup instructions only support 64-bit vectors for N > 1. | ||||
8876 | if (!VT.is64BitVector()) | ||||
8877 | return false; | ||||
8878 | |||||
8879 | // Check if the VDUPLANE operand is a vldN-dup intrinsic. | ||||
8880 | SDNode *VLD = N->getOperand(0).getNode(); | ||||
8881 | if (VLD->getOpcode() != ISD::INTRINSIC_W_CHAIN) | ||||
8882 | return false; | ||||
8883 | unsigned NumVecs = 0; | ||||
8884 | unsigned NewOpc = 0; | ||||
8885 | unsigned IntNo = cast<ConstantSDNode>(VLD->getOperand(1))->getZExtValue(); | ||||
8886 | if (IntNo == Intrinsic::arm_neon_vld2lane) { | ||||
8887 | NumVecs = 2; | ||||
8888 | NewOpc = ARMISD::VLD2DUP; | ||||
8889 | } else if (IntNo == Intrinsic::arm_neon_vld3lane) { | ||||
8890 | NumVecs = 3; | ||||
8891 | NewOpc = ARMISD::VLD3DUP; | ||||
8892 | } else if (IntNo == Intrinsic::arm_neon_vld4lane) { | ||||
8893 | NumVecs = 4; | ||||
8894 | NewOpc = ARMISD::VLD4DUP; | ||||
8895 | } else { | ||||
8896 | return false; | ||||
8897 | } | ||||
8898 | |||||
8899 | // First check that all the vldN-lane uses are VDUPLANEs and that the lane | ||||
8900 | // numbers match the load. | ||||
8901 | unsigned VLDLaneNo = | ||||
8902 | cast<ConstantSDNode>(VLD->getOperand(NumVecs+3))->getZExtValue(); | ||||
8903 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); | ||||
8904 | UI != UE; ++UI) { | ||||
8905 | // Ignore uses of the chain result. | ||||
8906 | if (UI.getUse().getResNo() == NumVecs) | ||||
8907 | continue; | ||||
8908 | SDNode *User = *UI; | ||||
8909 | if (User->getOpcode() != ARMISD::VDUPLANE || | ||||
8910 | VLDLaneNo != cast<ConstantSDNode>(User->getOperand(1))->getZExtValue()) | ||||
8911 | return false; | ||||
8912 | } | ||||
8913 | |||||
8914 | // Create the vldN-dup node. | ||||
8915 | EVT Tys[5]; | ||||
8916 | unsigned n; | ||||
8917 | for (n = 0; n < NumVecs; ++n) | ||||
8918 | Tys[n] = VT; | ||||
8919 | Tys[n] = MVT::Other; | ||||
Craig Topper | abb4ac7 | 2014-04-16 06:10:51 +0000 | [diff] [blame] | 8920 | SDVTList SDTys = DAG.getVTList(ArrayRef<EVT>(Tys, NumVecs+1)); |
Bob Wilson | 2d790df | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 8921 | SDValue Ops[] = { VLD->getOperand(0), VLD->getOperand(2) }; |
8922 | MemIntrinsicSDNode *VLDMemInt = cast<MemIntrinsicSDNode>(VLD); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8923 | SDValue VLDDup = DAG.getMemIntrinsicNode(NewOpc, SDLoc(VLD), SDTys, |
Craig Topper | 206fcd4 | 2014-04-26 19:29:41 +0000 | [diff] [blame] | 8924 | Ops, VLDMemInt->getMemoryVT(), |
Bob Wilson | 2d790df | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 8925 | VLDMemInt->getMemOperand()); |
8926 | |||||
8927 | // Update the uses. | ||||
8928 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); | ||||
8929 | UI != UE; ++UI) { | ||||
8930 | unsigned ResNo = UI.getUse().getResNo(); | ||||
8931 | // Ignore uses of the chain result. | ||||
8932 | if (ResNo == NumVecs) | ||||
8933 | continue; | ||||
8934 | SDNode *User = *UI; | ||||
8935 | DCI.CombineTo(User, SDValue(VLDDup.getNode(), ResNo)); | ||||
8936 | } | ||||
8937 | |||||
8938 | // Now the vldN-lane intrinsic is dead except for its chain result. | ||||
8939 | // Update uses of the chain. | ||||
8940 | std::vector<SDValue> VLDDupResults; | ||||
8941 | for (unsigned n = 0; n < NumVecs; ++n) | ||||
8942 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), n)); | ||||
8943 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), NumVecs)); | ||||
8944 | DCI.CombineTo(VLD, VLDDupResults); | ||||
8945 | |||||
8946 | return true; | ||||
8947 | } | ||||
8948 | |||||
Bob Wilson | 103a0dc | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 8949 | /// PerformVDUPLANECombine - Target-specific dag combine xforms for |
8950 | /// ARMISD::VDUPLANE. | ||||
Bob Wilson | 2d790df | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 8951 | static SDValue PerformVDUPLANECombine(SDNode *N, |
8952 | TargetLowering::DAGCombinerInfo &DCI) { | ||||
Bob Wilson | 103a0dc | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 8953 | SDValue Op = N->getOperand(0); |
Bob Wilson | 103a0dc | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 8954 | |
Bob Wilson | 2d790df | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 8955 | // If the source is a vldN-lane (N > 1) intrinsic, and all the other uses |
8956 | // of that intrinsic are also VDUPLANEs, combine them to a vldN-dup operation. | ||||
8957 | if (CombineVLDDUP(N, DCI)) | ||||
8958 | return SDValue(N, 0); | ||||
8959 | |||||
8960 | // If the source is already a VMOVIMM or VMVNIMM splat, the VDUPLANE is | ||||
8961 | // redundant. Ignore bit_converts for now; element sizes are checked below. | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8962 | while (Op.getOpcode() == ISD::BITCAST) |
Bob Wilson | 103a0dc | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 8963 | Op = Op.getOperand(0); |
Bob Wilson | bad47f6 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 8964 | if (Op.getOpcode() != ARMISD::VMOVIMM && Op.getOpcode() != ARMISD::VMVNIMM) |
Bob Wilson | 103a0dc | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 8965 | return SDValue(); |
8966 | |||||
8967 | // Make sure the VMOV element size is not bigger than the VDUPLANE elements. | ||||
8968 | unsigned EltSize = Op.getValueType().getVectorElementType().getSizeInBits(); | ||||
8969 | // The canonical VMOV for a zero vector uses a 32-bit element size. | ||||
8970 | unsigned Imm = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); | ||||
8971 | unsigned EltBits; | ||||
8972 | if (ARM_AM::decodeNEONModImm(Imm, EltBits) == 0) | ||||
8973 | EltSize = 8; | ||||
Bob Wilson | 2d790df | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 8974 | EVT VT = N->getValueType(0); |
Bob Wilson | 103a0dc | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 8975 | if (EltSize > VT.getVectorElementType().getSizeInBits()) |
8976 | return SDValue(); | ||||
8977 | |||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8978 | return DCI.DAG.getNode(ISD::BITCAST, SDLoc(N), VT, Op); |
Bob Wilson | 103a0dc | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 8979 | } |
8980 | |||||
Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8981 | // isConstVecPow2 - Return true if each vector element is a power of 2, all |
Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 8982 | // elements are the same constant, C, and Log2(C) ranges from 1 to 32. |
8983 | static bool isConstVecPow2(SDValue ConstVec, bool isSigned, uint64_t &C) | ||||
8984 | { | ||||
Chad Rosier | 6b610b3 | 2011-06-28 17:26:57 +0000 | [diff] [blame] | 8985 | integerPart cN; |
8986 | integerPart c0 = 0; | ||||
Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 8987 | for (unsigned I = 0, E = ConstVec.getValueType().getVectorNumElements(); |
8988 | I != E; I++) { | ||||
8989 | ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(ConstVec.getOperand(I)); | ||||
8990 | if (!C) | ||||
8991 | return false; | ||||
8992 | |||||
Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8993 | bool isExact; |
Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 8994 | APFloat APF = C->getValueAPF(); |
8995 | if (APF.convertToInteger(&cN, 64, isSigned, APFloat::rmTowardZero, &isExact) | ||||
8996 | != APFloat::opOK || !isExact) | ||||
8997 | return false; | ||||
8998 | |||||
8999 | c0 = (I == 0) ? cN : c0; | ||||
9000 | if (!isPowerOf2_64(cN) || c0 != cN || Log2_64(c0) < 1 || Log2_64(c0) > 32) | ||||
9001 | return false; | ||||
9002 | } | ||||
9003 | C = c0; | ||||
9004 | return true; | ||||
9005 | } | ||||
9006 | |||||
9007 | /// PerformVCVTCombine - VCVT (floating-point to fixed-point, Advanced SIMD) | ||||
9008 | /// can replace combinations of VMUL and VCVT (floating-point to integer) | ||||
9009 | /// when the VMUL has a constant operand that is a power of 2. | ||||
9010 | /// | ||||
9011 | /// Example (assume d17 = <float 8.000000e+00, float 8.000000e+00>): | ||||
9012 | /// vmul.f32 d16, d17, d16 | ||||
9013 | /// vcvt.s32.f32 d16, d16 | ||||
9014 | /// becomes: | ||||
9015 | /// vcvt.s32.f32 d16, d16, #3 | ||||
9016 | static SDValue PerformVCVTCombine(SDNode *N, | ||||
9017 | TargetLowering::DAGCombinerInfo &DCI, | ||||
9018 | const ARMSubtarget *Subtarget) { | ||||
9019 | SelectionDAG &DAG = DCI.DAG; | ||||
9020 | SDValue Op = N->getOperand(0); | ||||
9021 | |||||
9022 | if (!Subtarget->hasNEON() || !Op.getValueType().isVector() || | ||||
9023 | Op.getOpcode() != ISD::FMUL) | ||||
9024 | return SDValue(); | ||||
9025 | |||||
9026 | uint64_t C; | ||||
9027 | SDValue N0 = Op->getOperand(0); | ||||
9028 | SDValue ConstVec = Op->getOperand(1); | ||||
9029 | bool isSigned = N->getOpcode() == ISD::FP_TO_SINT; | ||||
9030 | |||||
Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 9031 | if (ConstVec.getOpcode() != ISD::BUILD_VECTOR || |
Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9032 | !isConstVecPow2(ConstVec, isSigned, C)) |
9033 | return SDValue(); | ||||
9034 | |||||
Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 9035 | MVT FloatTy = Op.getSimpleValueType().getVectorElementType(); |
9036 | MVT IntTy = N->getSimpleValueType(0).getVectorElementType(); | ||||
9037 | if (FloatTy.getSizeInBits() != 32 || IntTy.getSizeInBits() > 32) { | ||||
9038 | // These instructions only exist converting from f32 to i32. We can handle | ||||
9039 | // smaller integers by generating an extra truncate, but larger ones would | ||||
9040 | // be lossy. | ||||
9041 | return SDValue(); | ||||
9042 | } | ||||
9043 | |||||
Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9044 | unsigned IntrinsicOpcode = isSigned ? Intrinsic::arm_neon_vcvtfp2fxs : |
9045 | Intrinsic::arm_neon_vcvtfp2fxu; | ||||
Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 9046 | unsigned NumLanes = Op.getValueType().getVectorNumElements(); |
9047 | SDValue FixConv = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, SDLoc(N), | ||||
9048 | NumLanes == 2 ? MVT::v2i32 : MVT::v4i32, | ||||
9049 | DAG.getConstant(IntrinsicOpcode, MVT::i32), N0, | ||||
9050 | DAG.getConstant(Log2_64(C), MVT::i32)); | ||||
9051 | |||||
9052 | if (IntTy.getSizeInBits() < FloatTy.getSizeInBits()) | ||||
9053 | FixConv = DAG.getNode(ISD::TRUNCATE, SDLoc(N), N->getValueType(0), FixConv); | ||||
9054 | |||||
9055 | return FixConv; | ||||
Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9056 | } |
9057 | |||||
9058 | /// PerformVDIVCombine - VCVT (fixed-point to floating-point, Advanced SIMD) | ||||
9059 | /// can replace combinations of VCVT (integer to floating-point) and VDIV | ||||
9060 | /// when the VDIV has a constant operand that is a power of 2. | ||||
9061 | /// | ||||
9062 | /// Example (assume d17 = <float 8.000000e+00, float 8.000000e+00>): | ||||
9063 | /// vcvt.f32.s32 d16, d16 | ||||
9064 | /// vdiv.f32 d16, d17, d16 | ||||
9065 | /// becomes: | ||||
9066 | /// vcvt.f32.s32 d16, d16, #3 | ||||
9067 | static SDValue PerformVDIVCombine(SDNode *N, | ||||
9068 | TargetLowering::DAGCombinerInfo &DCI, | ||||
9069 | const ARMSubtarget *Subtarget) { | ||||
9070 | SelectionDAG &DAG = DCI.DAG; | ||||
9071 | SDValue Op = N->getOperand(0); | ||||
9072 | unsigned OpOpcode = Op.getNode()->getOpcode(); | ||||
9073 | |||||
9074 | if (!Subtarget->hasNEON() || !N->getValueType(0).isVector() || | ||||
9075 | (OpOpcode != ISD::SINT_TO_FP && OpOpcode != ISD::UINT_TO_FP)) | ||||
9076 | return SDValue(); | ||||
9077 | |||||
9078 | uint64_t C; | ||||
9079 | SDValue ConstVec = N->getOperand(1); | ||||
9080 | bool isSigned = OpOpcode == ISD::SINT_TO_FP; | ||||
9081 | |||||
9082 | if (ConstVec.getOpcode() != ISD::BUILD_VECTOR || | ||||
9083 | !isConstVecPow2(ConstVec, isSigned, C)) | ||||
9084 | return SDValue(); | ||||
9085 | |||||
Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 9086 | MVT FloatTy = N->getSimpleValueType(0).getVectorElementType(); |
9087 | MVT IntTy = Op.getOperand(0).getSimpleValueType().getVectorElementType(); | ||||
9088 | if (FloatTy.getSizeInBits() != 32 || IntTy.getSizeInBits() > 32) { | ||||
9089 | // These instructions only exist converting from i32 to f32. We can handle | ||||
9090 | // smaller integers by generating an extra extend, but larger ones would | ||||
9091 | // be lossy. | ||||
9092 | return SDValue(); | ||||
9093 | } | ||||
9094 | |||||
9095 | SDValue ConvInput = Op.getOperand(0); | ||||
9096 | unsigned NumLanes = Op.getValueType().getVectorNumElements(); | ||||
9097 | if (IntTy.getSizeInBits() < FloatTy.getSizeInBits()) | ||||
9098 | ConvInput = DAG.getNode(isSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND, | ||||
9099 | SDLoc(N), NumLanes == 2 ? MVT::v2i32 : MVT::v4i32, | ||||
9100 | ConvInput); | ||||
9101 | |||||
Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 9102 | unsigned IntrinsicOpcode = isSigned ? Intrinsic::arm_neon_vcvtfxs2fp : |
Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9103 | Intrinsic::arm_neon_vcvtfxu2fp; |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9104 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, SDLoc(N), |
Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9105 | Op.getValueType(), |
Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 9106 | DAG.getConstant(IntrinsicOpcode, MVT::i32), |
Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 9107 | ConvInput, DAG.getConstant(Log2_64(C), MVT::i32)); |
Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9108 | } |
9109 | |||||
9110 | /// Getvshiftimm - Check if this is a valid build_vector for the immediate | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9111 | /// operand of a vector shift operation, where all the elements of the |
9112 | /// build_vector must have the same constant integer value. | ||||
9113 | static bool getVShiftImm(SDValue Op, unsigned ElementBits, int64_t &Cnt) { | ||||
9114 | // Ignore bit_converts. | ||||
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 9115 | while (Op.getOpcode() == ISD::BITCAST) |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9116 | Op = Op.getOperand(0); |
9117 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(Op.getNode()); | ||||
9118 | APInt SplatBits, SplatUndef; | ||||
9119 | unsigned SplatBitSize; | ||||
9120 | bool HasAnyUndefs; | ||||
9121 | if (! BVN || ! BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, | ||||
9122 | HasAnyUndefs, ElementBits) || | ||||
9123 | SplatBitSize > ElementBits) | ||||
9124 | return false; | ||||
9125 | Cnt = SplatBits.getSExtValue(); | ||||
9126 | return true; | ||||
9127 | } | ||||
9128 | |||||
9129 | /// isVShiftLImm - Check if this is a valid build_vector for the immediate | ||||
9130 | /// operand of a vector shift left operation. That value must be in the range: | ||||
9131 | /// 0 <= Value < ElementBits for a left shift; or | ||||
9132 | /// 0 <= Value <= ElementBits for a long left shift. | ||||
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9133 | static bool isVShiftLImm(SDValue Op, EVT VT, bool isLong, int64_t &Cnt) { |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9134 | assert(VT.isVector() && "vector shift count is not a vector type"); |
9135 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); | ||||
9136 | if (! getVShiftImm(Op, ElementBits, Cnt)) | ||||
9137 | return false; | ||||
9138 | return (Cnt >= 0 && (isLong ? Cnt-1 : Cnt) < ElementBits); | ||||
9139 | } | ||||
9140 | |||||
9141 | /// isVShiftRImm - Check if this is a valid build_vector for the immediate | ||||
9142 | /// operand of a vector shift right operation. For a shift opcode, the value | ||||
9143 | /// is positive, but for an intrinsic the value count must be negative. The | ||||
9144 | /// absolute value must be in the range: | ||||
9145 | /// 1 <= |Value| <= ElementBits for a right shift; or | ||||
9146 | /// 1 <= |Value| <= ElementBits/2 for a narrow right shift. | ||||
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9147 | static bool isVShiftRImm(SDValue Op, EVT VT, bool isNarrow, bool isIntrinsic, |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9148 | int64_t &Cnt) { |
9149 | assert(VT.isVector() && "vector shift count is not a vector type"); | ||||
9150 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); | ||||
9151 | if (! getVShiftImm(Op, ElementBits, Cnt)) | ||||
9152 | return false; | ||||
9153 | if (isIntrinsic) | ||||
9154 | Cnt = -Cnt; | ||||
9155 | return (Cnt >= 1 && Cnt <= (isNarrow ? ElementBits/2 : ElementBits)); | ||||
9156 | } | ||||
9157 | |||||
9158 | /// PerformIntrinsicCombine - ARM-specific DAG combining for intrinsics. | ||||
9159 | static SDValue PerformIntrinsicCombine(SDNode *N, SelectionDAG &DAG) { | ||||
9160 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue(); | ||||
9161 | switch (IntNo) { | ||||
9162 | default: | ||||
9163 | // Don't do anything for most intrinsics. | ||||
9164 | break; | ||||
9165 | |||||
9166 | // Vector shifts: check for immediate versions and lower them. | ||||
9167 | // Note: This is done during DAG combining instead of DAG legalizing because | ||||
9168 | // the build_vectors for 64-bit vector element shift counts are generally | ||||
9169 | // not legal, and it is hard to see their values after they get legalized to | ||||
9170 | // loads from a constant pool. | ||||
9171 | case Intrinsic::arm_neon_vshifts: | ||||
9172 | case Intrinsic::arm_neon_vshiftu: | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9173 | case Intrinsic::arm_neon_vrshifts: |
9174 | case Intrinsic::arm_neon_vrshiftu: | ||||
9175 | case Intrinsic::arm_neon_vrshiftn: | ||||
9176 | case Intrinsic::arm_neon_vqshifts: | ||||
9177 | case Intrinsic::arm_neon_vqshiftu: | ||||
9178 | case Intrinsic::arm_neon_vqshiftsu: | ||||
9179 | case Intrinsic::arm_neon_vqshiftns: | ||||
9180 | case Intrinsic::arm_neon_vqshiftnu: | ||||
9181 | case Intrinsic::arm_neon_vqshiftnsu: | ||||
9182 | case Intrinsic::arm_neon_vqrshiftns: | ||||
9183 | case Intrinsic::arm_neon_vqrshiftnu: | ||||
9184 | case Intrinsic::arm_neon_vqrshiftnsu: { | ||||
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9185 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9186 | int64_t Cnt; |
9187 | unsigned VShiftOpc = 0; | ||||
9188 | |||||
9189 | switch (IntNo) { | ||||
9190 | case Intrinsic::arm_neon_vshifts: | ||||
9191 | case Intrinsic::arm_neon_vshiftu: | ||||
9192 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) { | ||||
9193 | VShiftOpc = ARMISD::VSHL; | ||||
9194 | break; | ||||
9195 | } | ||||
9196 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) { | ||||
9197 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshifts ? | ||||
9198 | ARMISD::VSHRs : ARMISD::VSHRu); | ||||
9199 | break; | ||||
9200 | } | ||||
9201 | return SDValue(); | ||||
9202 | |||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9203 | case Intrinsic::arm_neon_vrshifts: |
9204 | case Intrinsic::arm_neon_vrshiftu: | ||||
9205 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) | ||||
9206 | break; | ||||
9207 | return SDValue(); | ||||
9208 | |||||
9209 | case Intrinsic::arm_neon_vqshifts: | ||||
9210 | case Intrinsic::arm_neon_vqshiftu: | ||||
9211 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) | ||||
9212 | break; | ||||
9213 | return SDValue(); | ||||
9214 | |||||
9215 | case Intrinsic::arm_neon_vqshiftsu: | ||||
9216 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) | ||||
9217 | break; | ||||
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 9218 | llvm_unreachable("invalid shift count for vqshlu intrinsic"); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9219 | |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9220 | case Intrinsic::arm_neon_vrshiftn: |
9221 | case Intrinsic::arm_neon_vqshiftns: | ||||
9222 | case Intrinsic::arm_neon_vqshiftnu: | ||||
9223 | case Intrinsic::arm_neon_vqshiftnsu: | ||||
9224 | case Intrinsic::arm_neon_vqrshiftns: | ||||
9225 | case Intrinsic::arm_neon_vqrshiftnu: | ||||
9226 | case Intrinsic::arm_neon_vqrshiftnsu: | ||||
9227 | // Narrowing shifts require an immediate right shift. | ||||
9228 | if (isVShiftRImm(N->getOperand(2), VT, true, true, Cnt)) | ||||
9229 | break; | ||||
Jim Grosbach | 84511e1 | 2010-06-02 21:53:11 +0000 | [diff] [blame] | 9230 | llvm_unreachable("invalid shift count for narrowing vector shift " |
9231 | "intrinsic"); | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9232 | |
9233 | default: | ||||
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 9234 | llvm_unreachable("unhandled vector shift"); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9235 | } |
9236 | |||||
9237 | switch (IntNo) { | ||||
9238 | case Intrinsic::arm_neon_vshifts: | ||||
9239 | case Intrinsic::arm_neon_vshiftu: | ||||
9240 | // Opcode already set above. | ||||
9241 | break; | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9242 | case Intrinsic::arm_neon_vrshifts: |
9243 | VShiftOpc = ARMISD::VRSHRs; break; | ||||
9244 | case Intrinsic::arm_neon_vrshiftu: | ||||
9245 | VShiftOpc = ARMISD::VRSHRu; break; | ||||
9246 | case Intrinsic::arm_neon_vrshiftn: | ||||
9247 | VShiftOpc = ARMISD::VRSHRN; break; | ||||
9248 | case Intrinsic::arm_neon_vqshifts: | ||||
9249 | VShiftOpc = ARMISD::VQSHLs; break; | ||||
9250 | case Intrinsic::arm_neon_vqshiftu: | ||||
9251 | VShiftOpc = ARMISD::VQSHLu; break; | ||||
9252 | case Intrinsic::arm_neon_vqshiftsu: | ||||
9253 | VShiftOpc = ARMISD::VQSHLsu; break; | ||||
9254 | case Intrinsic::arm_neon_vqshiftns: | ||||
9255 | VShiftOpc = ARMISD::VQSHRNs; break; | ||||
9256 | case Intrinsic::arm_neon_vqshiftnu: | ||||
9257 | VShiftOpc = ARMISD::VQSHRNu; break; | ||||
9258 | case Intrinsic::arm_neon_vqshiftnsu: | ||||
9259 | VShiftOpc = ARMISD::VQSHRNsu; break; | ||||
9260 | case Intrinsic::arm_neon_vqrshiftns: | ||||
9261 | VShiftOpc = ARMISD::VQRSHRNs; break; | ||||
9262 | case Intrinsic::arm_neon_vqrshiftnu: | ||||
9263 | VShiftOpc = ARMISD::VQRSHRNu; break; | ||||
9264 | case Intrinsic::arm_neon_vqrshiftnsu: | ||||
9265 | VShiftOpc = ARMISD::VQRSHRNsu; break; | ||||
9266 | } | ||||
9267 | |||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9268 | return DAG.getNode(VShiftOpc, SDLoc(N), N->getValueType(0), |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9269 | N->getOperand(1), DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9270 | } |
9271 | |||||
9272 | case Intrinsic::arm_neon_vshiftins: { | ||||
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9273 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9274 | int64_t Cnt; |
9275 | unsigned VShiftOpc = 0; | ||||
9276 | |||||
9277 | if (isVShiftLImm(N->getOperand(3), VT, false, Cnt)) | ||||
9278 | VShiftOpc = ARMISD::VSLI; | ||||
9279 | else if (isVShiftRImm(N->getOperand(3), VT, false, true, Cnt)) | ||||
9280 | VShiftOpc = ARMISD::VSRI; | ||||
9281 | else { | ||||
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 9282 | llvm_unreachable("invalid shift count for vsli/vsri intrinsic"); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9283 | } |
9284 | |||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9285 | return DAG.getNode(VShiftOpc, SDLoc(N), N->getValueType(0), |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9286 | N->getOperand(1), N->getOperand(2), |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9287 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9288 | } |
9289 | |||||
9290 | case Intrinsic::arm_neon_vqrshifts: | ||||
9291 | case Intrinsic::arm_neon_vqrshiftu: | ||||
9292 | // No immediate versions of these to check for. | ||||
9293 | break; | ||||
9294 | } | ||||
9295 | |||||
9296 | return SDValue(); | ||||
9297 | } | ||||
9298 | |||||
9299 | /// PerformShiftCombine - Checks for immediate versions of vector shifts and | ||||
9300 | /// lowers them. As with the vector shift intrinsics, this is done during DAG | ||||
9301 | /// combining instead of DAG legalizing because the build_vectors for 64-bit | ||||
9302 | /// vector element shift counts are generally not legal, and it is hard to see | ||||
9303 | /// their values after they get legalized to loads from a constant pool. | ||||
9304 | static SDValue PerformShiftCombine(SDNode *N, SelectionDAG &DAG, | ||||
9305 | const ARMSubtarget *ST) { | ||||
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9306 | EVT VT = N->getValueType(0); |
Evan Cheng | f258a15 | 2012-02-23 02:58:19 +0000 | [diff] [blame] | 9307 | if (N->getOpcode() == ISD::SRL && VT == MVT::i32 && ST->hasV6Ops()) { |
9308 | // Canonicalize (srl (bswap x), 16) to (rotr (bswap x), 16) if the high | ||||
9309 | // 16-bits of x is zero. This optimizes rev + lsr 16 to rev16. | ||||
9310 | SDValue N1 = N->getOperand(1); | ||||
9311 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N1)) { | ||||
9312 | SDValue N0 = N->getOperand(0); | ||||
9313 | if (C->getZExtValue() == 16 && N0.getOpcode() == ISD::BSWAP && | ||||
9314 | DAG.MaskedValueIsZero(N0.getOperand(0), | ||||
9315 | APInt::getHighBitsSet(32, 16))) | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9316 | return DAG.getNode(ISD::ROTR, SDLoc(N), VT, N0, N1); |
Evan Cheng | f258a15 | 2012-02-23 02:58:19 +0000 | [diff] [blame] | 9317 | } |
9318 | } | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9319 | |
9320 | // Nothing to be done for scalar shifts. | ||||
Tanya Lattner | cd68095 | 2010-11-18 22:06:46 +0000 | [diff] [blame] | 9321 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
9322 | if (!VT.isVector() || !TLI.isTypeLegal(VT)) | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9323 | return SDValue(); |
9324 | |||||
9325 | assert(ST->hasNEON() && "unexpected vector shift"); | ||||
9326 | int64_t Cnt; | ||||
9327 | |||||
9328 | switch (N->getOpcode()) { | ||||
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 9329 | default: llvm_unreachable("unexpected shift opcode"); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9330 | |
9331 | case ISD::SHL: | ||||
9332 | if (isVShiftLImm(N->getOperand(1), VT, false, Cnt)) | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9333 | return DAG.getNode(ARMISD::VSHL, SDLoc(N), VT, N->getOperand(0), |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9334 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9335 | break; |
9336 | |||||
9337 | case ISD::SRA: | ||||
9338 | case ISD::SRL: | ||||
9339 | if (isVShiftRImm(N->getOperand(1), VT, false, false, Cnt)) { | ||||
9340 | unsigned VShiftOpc = (N->getOpcode() == ISD::SRA ? | ||||
9341 | ARMISD::VSHRs : ARMISD::VSHRu); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9342 | return DAG.getNode(VShiftOpc, SDLoc(N), VT, N->getOperand(0), |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9343 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9344 | } |
9345 | } | ||||
9346 | return SDValue(); | ||||
9347 | } | ||||
9348 | |||||
9349 | /// PerformExtendCombine - Target-specific DAG combining for ISD::SIGN_EXTEND, | ||||
9350 | /// ISD::ZERO_EXTEND, and ISD::ANY_EXTEND. | ||||
9351 | static SDValue PerformExtendCombine(SDNode *N, SelectionDAG &DAG, | ||||
9352 | const ARMSubtarget *ST) { | ||||
9353 | SDValue N0 = N->getOperand(0); | ||||
9354 | |||||
9355 | // Check for sign- and zero-extensions of vector extract operations of 8- | ||||
9356 | // and 16-bit vector elements. NEON supports these directly. They are | ||||
9357 | // handled during DAG combining because type legalization will promote them | ||||
9358 | // to 32-bit types and it is messy to recognize the operations after that. | ||||
9359 | if (ST->hasNEON() && N0.getOpcode() == ISD::EXTRACT_VECTOR_ELT) { | ||||
9360 | SDValue Vec = N0.getOperand(0); | ||||
9361 | SDValue Lane = N0.getOperand(1); | ||||
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9362 | EVT VT = N->getValueType(0); |
9363 | EVT EltVT = N0.getValueType(); | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9364 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
9365 | |||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9366 | if (VT == MVT::i32 && |
9367 | (EltVT == MVT::i8 || EltVT == MVT::i16) && | ||||
Bob Wilson | ceb4929 | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 9368 | TLI.isTypeLegal(Vec.getValueType()) && |
9369 | isa<ConstantSDNode>(Lane)) { | ||||
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9370 | |
9371 | unsigned Opc = 0; | ||||
9372 | switch (N->getOpcode()) { | ||||
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 9373 | default: llvm_unreachable("unexpected opcode"); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9374 | case ISD::SIGN_EXTEND: |
9375 | Opc = ARMISD::VGETLANEs; | ||||
9376 | break; | ||||
9377 | case ISD::ZERO_EXTEND: | ||||
9378 | case ISD::ANY_EXTEND: | ||||
9379 | Opc = ARMISD::VGETLANEu; | ||||
9380 | break; | ||||
9381 | } | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9382 | return DAG.getNode(Opc, SDLoc(N), VT, Vec, Lane); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9383 | } |
9384 | } | ||||
9385 | |||||
9386 | return SDValue(); | ||||
9387 | } | ||||
9388 | |||||
Bob Wilson | c6c13a3 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9389 | /// PerformSELECT_CCCombine - Target-specific DAG combining for ISD::SELECT_CC |
9390 | /// to match f32 max/min patterns to use NEON vmax/vmin instructions. | ||||
9391 | static SDValue PerformSELECT_CCCombine(SDNode *N, SelectionDAG &DAG, | ||||
9392 | const ARMSubtarget *ST) { | ||||
9393 | // If the target supports NEON, try to use vmax/vmin instructions for f32 | ||||
Evan Cheng | 55f0c6b | 2010-07-15 22:07:12 +0000 | [diff] [blame] | 9394 | // selects like "x < y ? x : y". Unless the NoNaNsFPMath option is set, |
Bob Wilson | c6c13a3 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9395 | // be careful about NaNs: NEON's vmax/vmin return NaN if either operand is |
9396 | // a NaN; only do the transformation when it matches that behavior. | ||||
9397 | |||||
9398 | // For now only do this when using NEON for FP operations; if using VFP, it | ||||
9399 | // is not obvious that the benefit outweighs the cost of switching to the | ||||
9400 | // NEON pipeline. | ||||
9401 | if (!ST->hasNEON() || !ST->useNEONForSinglePrecisionFP() || | ||||
9402 | N->getValueType(0) != MVT::f32) | ||||
9403 | return SDValue(); | ||||
9404 | |||||
9405 | SDValue CondLHS = N->getOperand(0); | ||||
9406 | SDValue CondRHS = N->getOperand(1); | ||||
9407 | SDValue LHS = N->getOperand(2); | ||||
9408 | SDValue RHS = N->getOperand(3); | ||||
9409 | ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(4))->get(); | ||||
9410 | |||||
9411 | unsigned Opcode = 0; | ||||
9412 | bool IsReversed; | ||||
Bob Wilson | ba8ac74 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9413 | if (DAG.isEqualTo(LHS, CondLHS) && DAG.isEqualTo(RHS, CondRHS)) { |
Bob Wilson | c6c13a3 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9414 | IsReversed = false; // x CC y ? x : y |
Bob Wilson | ba8ac74 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9415 | } else if (DAG.isEqualTo(LHS, CondRHS) && DAG.isEqualTo(RHS, CondLHS)) { |
Bob Wilson | c6c13a3 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9416 | IsReversed = true ; // x CC y ? y : x |
9417 | } else { | ||||
9418 | return SDValue(); | ||||
9419 | } | ||||
9420 | |||||
Bob Wilson | ba8ac74 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9421 | bool IsUnordered; |
Bob Wilson | c6c13a3 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9422 | switch (CC) { |
9423 | default: break; | ||||
9424 | case ISD::SETOLT: | ||||
9425 | case ISD::SETOLE: | ||||
9426 | case ISD::SETLT: | ||||
9427 | case ISD::SETLE: | ||||
Bob Wilson | c6c13a3 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9428 | case ISD::SETULT: |
9429 | case ISD::SETULE: | ||||
Bob Wilson | ba8ac74 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9430 | // If LHS is NaN, an ordered comparison will be false and the result will |
9431 | // be the RHS, but vmin(NaN, RHS) = NaN. Avoid this by checking that LHS | ||||
9432 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. | ||||
9433 | IsUnordered = (CC == ISD::SETULT || CC == ISD::SETULE); | ||||
9434 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) | ||||
9435 | break; | ||||
9436 | // For less-than-or-equal comparisons, "+0 <= -0" will be true but vmin | ||||
9437 | // will return -0, so vmin can only be used for unsafe math or if one of | ||||
9438 | // the operands is known to be nonzero. | ||||
9439 | if ((CC == ISD::SETLE || CC == ISD::SETOLE || CC == ISD::SETULE) && | ||||
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 9440 | !DAG.getTarget().Options.UnsafeFPMath && |
Bob Wilson | ba8ac74 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9441 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
9442 | break; | ||||
9443 | Opcode = IsReversed ? ARMISD::FMAX : ARMISD::FMIN; | ||||
Bob Wilson | c6c13a3 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9444 | break; |
9445 | |||||
9446 | case ISD::SETOGT: | ||||
9447 | case ISD::SETOGE: | ||||
9448 | case ISD::SETGT: | ||||
9449 | case ISD::SETGE: | ||||
Bob Wilson | c6c13a3 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9450 | case ISD::SETUGT: |
9451 | case ISD::SETUGE: | ||||
Bob Wilson | ba8ac74 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9452 | // If LHS is NaN, an ordered comparison will be false and the result will |
9453 | // be the RHS, but vmax(NaN, RHS) = NaN. Avoid this by checking that LHS | ||||
9454 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. | ||||
9455 | IsUnordered = (CC == ISD::SETUGT || CC == ISD::SETUGE); | ||||
9456 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) | ||||
9457 | break; | ||||
9458 | // For greater-than-or-equal comparisons, "-0 >= +0" will be true but vmax | ||||
9459 | // will return +0, so vmax can only be used for unsafe math or if one of | ||||
9460 | // the operands is known to be nonzero. | ||||
9461 | if ((CC == ISD::SETGE || CC == ISD::SETOGE || CC == ISD::SETUGE) && | ||||
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 9462 | !DAG.getTarget().Options.UnsafeFPMath && |
Bob Wilson | ba8ac74 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9463 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
9464 | break; | ||||
9465 | Opcode = IsReversed ? ARMISD::FMIN : ARMISD::FMAX; | ||||
Bob Wilson | c6c13a3 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9466 | break; |
9467 | } | ||||
9468 | |||||
9469 | if (!Opcode) | ||||
9470 | return SDValue(); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9471 | return DAG.getNode(Opcode, SDLoc(N), N->getValueType(0), LHS, RHS); |
Bob Wilson | c6c13a3 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9472 | } |
9473 | |||||
Evan Cheng | f863e3f | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 9474 | /// PerformCMOVCombine - Target-specific DAG combining for ARMISD::CMOV. |
9475 | SDValue | ||||
9476 | ARMTargetLowering::PerformCMOVCombine(SDNode *N, SelectionDAG &DAG) const { | ||||
9477 | SDValue Cmp = N->getOperand(4); | ||||
9478 | if (Cmp.getOpcode() != ARMISD::CMPZ) | ||||
9479 | // Only looking at EQ and NE cases. | ||||
9480 | return SDValue(); | ||||
9481 | |||||
9482 | EVT VT = N->getValueType(0); | ||||
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9483 | SDLoc dl(N); |
Evan Cheng | f863e3f | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 9484 | SDValue LHS = Cmp.getOperand(0); |
9485 | SDValue RHS = Cmp.getOperand(1); | ||||
9486 | SDValue FalseVal = N->getOperand(0); | ||||
9487 | SDValue TrueVal = N->getOperand(1); | ||||
9488 | SDValue ARMcc = N->getOperand(2); | ||||
Jim Grosbach | e7e2aca | 2011-09-13 20:30:37 +0000 | [diff] [blame] | 9489 | ARMCC::CondCodes CC = |
9490 | (ARMCC::CondCodes)cast<ConstantSDNode>(ARMcc)->getZExtValue(); | ||||
Evan Cheng | f863e3f | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 9491 | |
9492 | // Simplify | ||||
9493 | // mov r1, r0 | ||||
9494 | // cmp r1, x | ||||
9495 | // mov r0, y | ||||
9496 | // moveq r0, x | ||||
9497 | // to | ||||
9498 | // cmp r0, x | ||||
9499 | // movne r0, y | ||||
9500 | // | ||||
9501 | // mov r1, r0 | ||||
9502 | // cmp r1, x | ||||
9503 | // mov r0, x | ||||
9504 | // movne r0, y | ||||
9505 | // to | ||||
9506 | // cmp r0, x | ||||
9507 | // movne r0, y | ||||
9508 | /// FIXME: Turn this into a target neutral optimization? | ||||
9509 | SDValue Res; | ||||
Evan Cheng | 8156376 | 2011-09-28 23:16:31 +0000 | [diff] [blame] | 9510 | if (CC == ARMCC::NE && FalseVal == RHS && FalseVal != LHS) { |
Evan Cheng | f863e3f | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 9511 | Res = DAG.getNode(ARMISD::CMOV, dl, VT, LHS, TrueVal, ARMcc, |
9512 | N->getOperand(3), Cmp); | ||||
9513 | } else if (CC == ARMCC::EQ && TrueVal == RHS) { | ||||
9514 | SDValue ARMcc; | ||||
9515 | SDValue NewCmp = getARMCmp(LHS, RHS, ISD::SETNE, ARMcc, DAG, dl); | ||||
9516 | Res = DAG.getNode(ARMISD::CMOV, dl, VT, LHS, FalseVal, ARMcc, | ||||
9517 | N->getOperand(3), NewCmp); | ||||
9518 | } | ||||
9519 | |||||
9520 | if (Res.getNode()) { | ||||
9521 | APInt KnownZero, KnownOne; | ||||
Rafael Espindola | ba0a6ca | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 9522 | DAG.ComputeMaskedBits(SDValue(N,0), KnownZero, KnownOne); |
Evan Cheng | f863e3f | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 9523 | // Capture demanded bits information that would be otherwise lost. |
9524 | if (KnownZero == 0xfffffffe) | ||||
9525 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, | ||||
9526 | DAG.getValueType(MVT::i1)); | ||||
9527 | else if (KnownZero == 0xffffff00) | ||||
9528 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, | ||||
9529 | DAG.getValueType(MVT::i8)); | ||||
9530 | else if (KnownZero == 0xffff0000) | ||||
9531 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, | ||||
9532 | DAG.getValueType(MVT::i16)); | ||||
9533 | } | ||||
9534 | |||||
9535 | return Res; | ||||
9536 | } | ||||
9537 | |||||
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 9538 | SDValue ARMTargetLowering::PerformDAGCombine(SDNode *N, |
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9539 | DAGCombinerInfo &DCI) const { |
Chris Lattner | f3f4ad9 | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 9540 | switch (N->getOpcode()) { |
9541 | default: break; | ||||
Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 9542 | case ISD::ADDC: return PerformADDCCombine(N, DCI, Subtarget); |
Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 9543 | case ISD::ADD: return PerformADDCombine(N, DCI, Subtarget); |
Bob Wilson | c6c13a3 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9544 | case ISD::SUB: return PerformSUBCombine(N, DCI); |
Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 9545 | case ISD::MUL: return PerformMULCombine(N, DCI, Subtarget); |
Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 9546 | case ISD::OR: return PerformORCombine(N, DCI, Subtarget); |
Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 9547 | case ISD::XOR: return PerformXORCombine(N, DCI, Subtarget); |
9548 | case ISD::AND: return PerformANDCombine(N, DCI, Subtarget); | ||||
Evan Cheng | c177813 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 9549 | case ARMISD::BFI: return PerformBFICombine(N, DCI); |
Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 9550 | case ARMISD::VMOVRRD: return PerformVMOVRRDCombine(N, DCI); |
Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 9551 | case ARMISD::VMOVDRR: return PerformVMOVDRRCombine(N, DCI.DAG); |
Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 9552 | case ISD::STORE: return PerformSTORECombine(N, DCI); |
9553 | case ISD::BUILD_VECTOR: return PerformBUILD_VECTORCombine(N, DCI); | ||||
9554 | case ISD::INSERT_VECTOR_ELT: return PerformInsertEltCombine(N, DCI); | ||||
Bob Wilson | c7334a1 | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 9555 | case ISD::VECTOR_SHUFFLE: return PerformVECTOR_SHUFFLECombine(N, DCI.DAG); |
Bob Wilson | 2d790df | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 9556 | case ARMISD::VDUPLANE: return PerformVDUPLANECombine(N, DCI); |
Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9557 | case ISD::FP_TO_SINT: |
9558 | case ISD::FP_TO_UINT: return PerformVCVTCombine(N, DCI, Subtarget); | ||||
9559 | case ISD::FDIV: return PerformVDIVCombine(N, DCI, Subtarget); | ||||
Bob Wilson | c6c13a3 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9560 | case ISD::INTRINSIC_WO_CHAIN: return PerformIntrinsicCombine(N, DCI.DAG); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9561 | case ISD::SHL: |
9562 | case ISD::SRA: | ||||
Bob Wilson | c6c13a3 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9563 | case ISD::SRL: return PerformShiftCombine(N, DCI.DAG, Subtarget); |
Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9564 | case ISD::SIGN_EXTEND: |
9565 | case ISD::ZERO_EXTEND: | ||||
Bob Wilson | c6c13a3 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9566 | case ISD::ANY_EXTEND: return PerformExtendCombine(N, DCI.DAG, Subtarget); |
9567 | case ISD::SELECT_CC: return PerformSELECT_CCCombine(N, DCI.DAG, Subtarget); | ||||
Evan Cheng | f863e3f | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 9568 | case ARMISD::CMOV: return PerformCMOVCombine(N, DCI.DAG); |
Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9569 | case ARMISD::VLD2DUP: |
9570 | case ARMISD::VLD3DUP: | ||||
9571 | case ARMISD::VLD4DUP: | ||||
9572 | return CombineBaseUpdate(N, DCI); | ||||
Quentin Colombet | 04b3a0f | 2013-07-03 21:42:57 +0000 | [diff] [blame] | 9573 | case ARMISD::BUILD_VECTOR: |
9574 | return PerformARMBUILD_VECTORCombine(N, DCI); | ||||
Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9575 | case ISD::INTRINSIC_VOID: |
9576 | case ISD::INTRINSIC_W_CHAIN: | ||||
9577 | switch (cast<ConstantSDNode>(N->getOperand(1))->getZExtValue()) { | ||||
9578 | case Intrinsic::arm_neon_vld1: | ||||
9579 | case Intrinsic::arm_neon_vld2: | ||||
9580 | case Intrinsic::arm_neon_vld3: | ||||
9581 | case Intrinsic::arm_neon_vld4: | ||||
9582 | case Intrinsic::arm_neon_vld2lane: | ||||
9583 | case Intrinsic::arm_neon_vld3lane: | ||||
9584 | case Intrinsic::arm_neon_vld4lane: | ||||
9585 | case Intrinsic::arm_neon_vst1: | ||||
9586 | case Intrinsic::arm_neon_vst2: | ||||
9587 | case Intrinsic::arm_neon_vst3: | ||||
9588 | case Intrinsic::arm_neon_vst4: | ||||
9589 | case Intrinsic::arm_neon_vst2lane: | ||||
9590 | case Intrinsic::arm_neon_vst3lane: | ||||
9591 | case Intrinsic::arm_neon_vst4lane: | ||||
9592 | return CombineBaseUpdate(N, DCI); | ||||
9593 | default: break; | ||||
9594 | } | ||||
9595 | break; | ||||
Chris Lattner | f3f4ad9 | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 9596 | } |
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 9597 | return SDValue(); |
Chris Lattner | f3f4ad9 | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 9598 | } |
9599 | |||||
Evan Cheng | d42641c | 2011-02-02 01:06:55 +0000 | [diff] [blame] | 9600 | bool ARMTargetLowering::isDesirableToTransformToIntegerOp(unsigned Opc, |
9601 | EVT VT) const { | ||||
9602 | return (VT == MVT::f32) && (Opc == ISD::LOAD || Opc == ISD::STORE); | ||||
9603 | } | ||||
9604 | |||||
Matt Arsenault | 25793a3 | 2014-02-05 23:15:53 +0000 | [diff] [blame] | 9605 | bool ARMTargetLowering::allowsUnalignedMemoryAccesses(EVT VT, unsigned, |
9606 | bool *Fast) const { | ||||
Evan Cheng | 90ae8f8 | 2012-09-18 01:42:45 +0000 | [diff] [blame] | 9607 | // The AllowsUnaliged flag models the SCTLR.A setting in ARM cpus |
Chad Rosier | 66bb178 | 2012-11-09 18:25:27 +0000 | [diff] [blame] | 9608 | bool AllowsUnaligned = Subtarget->allowsUnalignedMem(); |
Bill Wendling | bae6b2c | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 9609 | |
9610 | switch (VT.getSimpleVT().SimpleTy) { | ||||
9611 | default: | ||||
9612 | return false; | ||||
9613 | case MVT::i8: | ||||
9614 | case MVT::i16: | ||||
Evan Cheng | 79e2ca9 | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9615 | case MVT::i32: { |
Evan Cheng | 90ae8f8 | 2012-09-18 01:42:45 +0000 | [diff] [blame] | 9616 | // Unaligned access can use (for example) LRDB, LRDH, LDR |
Evan Cheng | 79e2ca9 | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9617 | if (AllowsUnaligned) { |
9618 | if (Fast) | ||||
9619 | *Fast = Subtarget->hasV7Ops(); | ||||
9620 | return true; | ||||
9621 | } | ||||
9622 | return false; | ||||
9623 | } | ||||
Evan Cheng | eec6bc6 | 2012-08-15 17:44:53 +0000 | [diff] [blame] | 9624 | case MVT::f64: |
Evan Cheng | 79e2ca9 | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9625 | case MVT::v2f64: { |
Evan Cheng | 90ae8f8 | 2012-09-18 01:42:45 +0000 | [diff] [blame] | 9626 | // For any little-endian targets with neon, we can support unaligned ld/st |
9627 | // of D and Q (e.g. {D0,D1}) registers by using vld1.i8/vst1.i8. | ||||
Alp Toker | cb40291 | 2014-01-24 17:20:08 +0000 | [diff] [blame] | 9628 | // A big-endian target may also explicitly support unaligned accesses |
Evan Cheng | 79e2ca9 | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9629 | if (Subtarget->hasNEON() && (AllowsUnaligned || isLittleEndian())) { |
9630 | if (Fast) | ||||
9631 | *Fast = true; | ||||
9632 | return true; | ||||
9633 | } | ||||
9634 | return false; | ||||
9635 | } | ||||
Bill Wendling | bae6b2c | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 9636 | } |
9637 | } | ||||
9638 | |||||
Lang Hames | 9929c42 | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 9639 | static bool memOpAlign(unsigned DstAlign, unsigned SrcAlign, |
9640 | unsigned AlignCheck) { | ||||
9641 | return ((SrcAlign == 0 || SrcAlign % AlignCheck == 0) && | ||||
9642 | (DstAlign == 0 || DstAlign % AlignCheck == 0)); | ||||
9643 | } | ||||
9644 | |||||
9645 | EVT ARMTargetLowering::getOptimalMemOpType(uint64_t Size, | ||||
9646 | unsigned DstAlign, unsigned SrcAlign, | ||||
Evan Cheng | 962711e | 2012-12-12 02:34:41 +0000 | [diff] [blame] | 9647 | bool IsMemset, bool ZeroMemset, |
Lang Hames | 9929c42 | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 9648 | bool MemcpyStrSrc, |
9649 | MachineFunction &MF) const { | ||||
9650 | const Function *F = MF.getFunction(); | ||||
9651 | |||||
9652 | // See if we can use NEON instructions for this... | ||||
Evan Cheng | 962711e | 2012-12-12 02:34:41 +0000 | [diff] [blame] | 9653 | if ((!IsMemset || ZeroMemset) && |
Evan Cheng | 79e2ca9 | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9654 | Subtarget->hasNEON() && |
Bill Wendling | 698e84f | 2012-12-30 10:32:01 +0000 | [diff] [blame] | 9655 | !F->getAttributes().hasAttribute(AttributeSet::FunctionIndex, |
9656 | Attribute::NoImplicitFloat)) { | ||||
Evan Cheng | 79e2ca9 | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9657 | bool Fast; |
Evan Cheng | c2bd620 | 2012-12-11 02:31:57 +0000 | [diff] [blame] | 9658 | if (Size >= 16 && |
9659 | (memOpAlign(SrcAlign, DstAlign, 16) || | ||||
Matt Arsenault | 25793a3 | 2014-02-05 23:15:53 +0000 | [diff] [blame] | 9660 | (allowsUnalignedMemoryAccesses(MVT::v2f64, 0, &Fast) && Fast))) { |
Evan Cheng | 79e2ca9 | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9661 | return MVT::v2f64; |
Evan Cheng | c2bd620 | 2012-12-11 02:31:57 +0000 | [diff] [blame] | 9662 | } else if (Size >= 8 && |
9663 | (memOpAlign(SrcAlign, DstAlign, 8) || | ||||
Matt Arsenault | 25793a3 | 2014-02-05 23:15:53 +0000 | [diff] [blame] | 9664 | (allowsUnalignedMemoryAccesses(MVT::f64, 0, &Fast) && Fast))) { |
Evan Cheng | 79e2ca9 | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9665 | return MVT::f64; |
Lang Hames | 9929c42 | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 9666 | } |
9667 | } | ||||
9668 | |||||
Lang Hames | b85fcd0 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 9669 | // Lowering to i32/i16 if the size permits. |
Evan Cheng | c2bd620 | 2012-12-11 02:31:57 +0000 | [diff] [blame] | 9670 | if (Size >= 4) |
Lang Hames | b85fcd0 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 9671 | return MVT::i32; |
Evan Cheng | c2bd620 | 2012-12-11 02:31:57 +0000 | [diff] [blame] | 9672 | else if (Size >= 2) |
Lang Hames | b85fcd0 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 9673 | return MVT::i16; |
Lang Hames | b85fcd0 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 9674 | |
Lang Hames | 9929c42 | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 9675 | // Let the target-independent logic figure it out. |
9676 | return MVT::Other; | ||||
9677 | } | ||||
9678 | |||||
Evan Cheng | 9ec512d | 2012-12-06 19:13:27 +0000 | [diff] [blame] | 9679 | bool ARMTargetLowering::isZExtFree(SDValue Val, EVT VT2) const { |
9680 | if (Val.getOpcode() != ISD::LOAD) | ||||
9681 | return false; | ||||
9682 | |||||
9683 | EVT VT1 = Val.getValueType(); | ||||
9684 | if (!VT1.isSimple() || !VT1.isInteger() || | ||||
9685 | !VT2.isSimple() || !VT2.isInteger()) | ||||
9686 | return false; | ||||
9687 | |||||
9688 | switch (VT1.getSimpleVT().SimpleTy) { | ||||
9689 | default: break; | ||||
9690 | case MVT::i1: | ||||
9691 | case MVT::i8: | ||||
9692 | case MVT::i16: | ||||
9693 | // 8-bit and 16-bit loads implicitly zero-extend to 32-bits. | ||||
9694 | return true; | ||||
9695 | } | ||||
9696 | |||||
9697 | return false; | ||||
9698 | } | ||||
9699 | |||||
Tim Northover | cc2e903 | 2013-08-06 13:58:03 +0000 | [diff] [blame] | 9700 | bool ARMTargetLowering::allowTruncateForTailCall(Type *Ty1, Type *Ty2) const { |
9701 | if (!Ty1->isIntegerTy() || !Ty2->isIntegerTy()) | ||||
9702 | return false; | ||||
9703 | |||||
9704 | if (!isTypeLegal(EVT::getEVT(Ty1))) | ||||
9705 | return false; | ||||
9706 | |||||
9707 | assert(Ty1->getPrimitiveSizeInBits() <= 64 && "i128 is probably not a noop"); | ||||
9708 | |||||
9709 | // Assuming the caller doesn't have a zeroext or signext return parameter, | ||||
9710 | // truncation all the way down to i1 is valid. | ||||
9711 | return true; | ||||
9712 | } | ||||
9713 | |||||
9714 | |||||
Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9715 | static bool isLegalT1AddressImmediate(int64_t V, EVT VT) { |
9716 | if (V < 0) | ||||
9717 | return false; | ||||
9718 | |||||
9719 | unsigned Scale = 1; | ||||
9720 | switch (VT.getSimpleVT().SimpleTy) { | ||||
9721 | default: return false; | ||||
9722 | case MVT::i1: | ||||
9723 | case MVT::i8: | ||||
9724 | // Scale == 1; | ||||
9725 | break; | ||||
9726 | case MVT::i16: | ||||
9727 | // Scale == 2; | ||||
9728 | Scale = 2; | ||||
9729 | break; | ||||
9730 | case MVT::i32: | ||||
9731 | // Scale == 4; | ||||
9732 | Scale = 4; | ||||
9733 | break; | ||||
9734 | } | ||||
9735 | |||||
9736 | if ((V & (Scale - 1)) != 0) | ||||
9737 | return false; | ||||
9738 | V /= Scale; | ||||
9739 | return V == (V & ((1LL << 5) - 1)); | ||||
9740 | } | ||||
9741 | |||||
9742 | static bool isLegalT2AddressImmediate(int64_t V, EVT VT, | ||||
9743 | const ARMSubtarget *Subtarget) { | ||||
9744 | bool isNeg = false; | ||||
9745 | if (V < 0) { | ||||
9746 | isNeg = true; | ||||
9747 | V = - V; | ||||
9748 | } | ||||
9749 | |||||
9750 | switch (VT.getSimpleVT().SimpleTy) { | ||||
9751 | default: return false; | ||||
9752 | case MVT::i1: | ||||
9753 | case MVT::i8: | ||||
9754 | case MVT::i16: | ||||
9755 | case MVT::i32: | ||||
9756 | // + imm12 or - imm8 | ||||
9757 | if (isNeg) | ||||
9758 | return V == (V & ((1LL << 8) - 1)); | ||||
9759 | return V == (V & ((1LL << 12) - 1)); | ||||
9760 | case MVT::f32: | ||||
9761 | case MVT::f64: | ||||
9762 | // Same as ARM mode. FIXME: NEON? | ||||
9763 | if (!Subtarget->hasVFP2()) | ||||
9764 | return false; | ||||
9765 | if ((V & 3) != 0) | ||||
9766 | return false; | ||||
9767 | V >>= 2; | ||||
9768 | return V == (V & ((1LL << 8) - 1)); | ||||
9769 | } | ||||
9770 | } | ||||
9771 | |||||
Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9772 | /// isLegalAddressImmediate - Return true if the integer value can be used |
9773 | /// as the offset of the target addressing mode for load / store of the | ||||
9774 | /// given type. | ||||
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9775 | static bool isLegalAddressImmediate(int64_t V, EVT VT, |
Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9776 | const ARMSubtarget *Subtarget) { |
Evan Cheng | 507eefa | 2007-03-13 20:37:59 +0000 | [diff] [blame] | 9777 | if (V == 0) |
9778 | return true; | ||||
9779 | |||||
Evan Cheng | ce5dfb6 | 2009-03-09 19:15:00 +0000 | [diff] [blame] | 9780 | if (!VT.isSimple()) |
9781 | return false; | ||||
9782 | |||||
Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9783 | if (Subtarget->isThumb1Only()) |
9784 | return isLegalT1AddressImmediate(V, VT); | ||||
9785 | else if (Subtarget->isThumb2()) | ||||
9786 | return isLegalT2AddressImmediate(V, VT, Subtarget); | ||||
Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9787 | |
Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9788 | // ARM mode. |
Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9789 | if (V < 0) |
9790 | V = - V; | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9791 | switch (VT.getSimpleVT().SimpleTy) { |
Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9792 | default: return false; |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9793 | case MVT::i1: |
9794 | case MVT::i8: | ||||
9795 | case MVT::i32: | ||||
Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9796 | // +- imm12 |
Anton Korobeynikov | 40d67c5 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 9797 | return V == (V & ((1LL << 12) - 1)); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9798 | case MVT::i16: |
Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9799 | // +- imm8 |
Anton Korobeynikov | 40d67c5 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 9800 | return V == (V & ((1LL << 8) - 1)); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9801 | case MVT::f32: |
9802 | case MVT::f64: | ||||
Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9803 | if (!Subtarget->hasVFP2()) // FIXME: NEON? |
Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9804 | return false; |
Evan Cheng | bef131de | 2007-05-03 02:00:18 +0000 | [diff] [blame] | 9805 | if ((V & 3) != 0) |
Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9806 | return false; |
9807 | V >>= 2; | ||||
Anton Korobeynikov | 40d67c5 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 9808 | return V == (V & ((1LL << 8) - 1)); |
Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9809 | } |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9810 | } |
9811 | |||||
Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9812 | bool ARMTargetLowering::isLegalT2ScaledAddressingMode(const AddrMode &AM, |
9813 | EVT VT) const { | ||||
9814 | int Scale = AM.Scale; | ||||
9815 | if (Scale < 0) | ||||
9816 | return false; | ||||
9817 | |||||
9818 | switch (VT.getSimpleVT().SimpleTy) { | ||||
9819 | default: return false; | ||||
9820 | case MVT::i1: | ||||
9821 | case MVT::i8: | ||||
9822 | case MVT::i16: | ||||
9823 | case MVT::i32: | ||||
9824 | if (Scale == 1) | ||||
9825 | return true; | ||||
9826 | // r + r << imm | ||||
9827 | Scale = Scale & ~1; | ||||
9828 | return Scale == 2 || Scale == 4 || Scale == 8; | ||||
9829 | case MVT::i64: | ||||
9830 | // r + r | ||||
9831 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) | ||||
9832 | return true; | ||||
9833 | return false; | ||||
9834 | case MVT::isVoid: | ||||
9835 | // Note, we allow "void" uses (basically, uses that aren't loads or | ||||
9836 | // stores), because arm allows folding a scale into many arithmetic | ||||
9837 | // operations. This should be made more precise and revisited later. | ||||
9838 | |||||
9839 | // Allow r << imm, but the imm has to be a multiple of two. | ||||
9840 | if (Scale & 1) return false; | ||||
9841 | return isPowerOf2_32(Scale); | ||||
9842 | } | ||||
9843 | } | ||||
9844 | |||||
Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9845 | /// isLegalAddressingMode - Return true if the addressing mode represented |
9846 | /// by AM is legal for this target, for a load/store of the specified type. | ||||
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9847 | bool ARMTargetLowering::isLegalAddressingMode(const AddrMode &AM, |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 9848 | Type *Ty) const { |
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9849 | EVT VT = getValueType(Ty, true); |
Bob Wilson | 866c174 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 9850 | if (!isLegalAddressImmediate(AM.BaseOffs, VT, Subtarget)) |
Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9851 | return false; |
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9852 | |
Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9853 | // Can never fold addr of global into load/store. |
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9854 | if (AM.BaseGV) |
Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9855 | return false; |
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9856 | |
Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9857 | switch (AM.Scale) { |
9858 | case 0: // no scale reg, must be "r+i" or "r", or "i". | ||||
9859 | break; | ||||
9860 | case 1: | ||||
Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9861 | if (Subtarget->isThumb1Only()) |
Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9862 | return false; |
Chris Lattner | 502c3f4 | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 9863 | // FALL THROUGH. |
Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9864 | default: |
Chris Lattner | 502c3f4 | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 9865 | // ARM doesn't support any R+R*scale+imm addr modes. |
9866 | if (AM.BaseOffs) | ||||
9867 | return false; | ||||
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9868 | |
Bob Wilson | 866c174 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 9869 | if (!VT.isSimple()) |
9870 | return false; | ||||
9871 | |||||
Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9872 | if (Subtarget->isThumb2()) |
9873 | return isLegalT2ScaledAddressingMode(AM, VT); | ||||
9874 | |||||
Chris Lattner | 9b6d69e | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 9875 | int Scale = AM.Scale; |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9876 | switch (VT.getSimpleVT().SimpleTy) { |
Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9877 | default: return false; |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9878 | case MVT::i1: |
9879 | case MVT::i8: | ||||
9880 | case MVT::i32: | ||||
Chris Lattner | 9b6d69e | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 9881 | if (Scale < 0) Scale = -Scale; |
9882 | if (Scale == 1) | ||||
Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9883 | return true; |
9884 | // r + r << imm | ||||
Chris Lattner | fe926e2 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 9885 | return isPowerOf2_32(Scale & ~1); |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9886 | case MVT::i16: |
Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9887 | case MVT::i64: |
Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9888 | // r + r |
Chris Lattner | 9b6d69e | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 9889 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9890 | return true; |
Chris Lattner | fe926e2 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 9891 | return false; |
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9892 | |
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9893 | case MVT::isVoid: |
Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9894 | // Note, we allow "void" uses (basically, uses that aren't loads or |
9895 | // stores), because arm allows folding a scale into many arithmetic | ||||
9896 | // operations. This should be made more precise and revisited later. | ||||
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9897 | |
Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9898 | // Allow r << imm, but the imm has to be a multiple of two. |
Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9899 | if (Scale & 1) return false; |
9900 | return isPowerOf2_32(Scale); | ||||
Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9901 | } |
Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9902 | } |
Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9903 | return true; |
Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9904 | } |
9905 | |||||
Evan Cheng | 3d3c24a | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 9906 | /// isLegalICmpImmediate - Return true if the specified immediate is legal |
9907 | /// icmp immediate, that is the target has icmp instructions which can compare | ||||
9908 | /// a register against the immediate without having to materialize the | ||||
9909 | /// immediate into a register. | ||||
Evan Cheng | 15b80e4 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 9910 | bool ARMTargetLowering::isLegalICmpImmediate(int64_t Imm) const { |
Jakob Stoklund Olesen | 967b86a | 2012-04-06 17:45:04 +0000 | [diff] [blame] | 9911 | // Thumb2 and ARM modes can use cmn for negative immediates. |
Evan Cheng | 3d3c24a | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 9912 | if (!Subtarget->isThumb()) |
Chandler Carruth | 8a102c2 | 2012-04-06 20:10:52 +0000 | [diff] [blame] | 9913 | return ARM_AM::getSOImmVal(llvm::abs64(Imm)) != -1; |
Evan Cheng | 3d3c24a | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 9914 | if (Subtarget->isThumb2()) |
Chandler Carruth | 8a102c2 | 2012-04-06 20:10:52 +0000 | [diff] [blame] | 9915 | return ARM_AM::getT2SOImmVal(llvm::abs64(Imm)) != -1; |
Jakob Stoklund Olesen | 967b86a | 2012-04-06 17:45:04 +0000 | [diff] [blame] | 9916 | // Thumb1 doesn't have cmn, and only 8-bit immediates. |
Evan Cheng | 15b80e4 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 9917 | return Imm >= 0 && Imm <= 255; |
Evan Cheng | 3d3c24a | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 9918 | } |
9919 | |||||
Andrew Trick | a22cdb7 | 2012-07-18 18:34:27 +0000 | [diff] [blame] | 9920 | /// isLegalAddImmediate - Return true if the specified immediate is a legal add |
9921 | /// *or sub* immediate, that is the target has add or sub instructions which can | ||||
9922 | /// add a register with the immediate without having to materialize the | ||||
Dan Gohman | 6136e94 | 2011-05-03 00:46:49 +0000 | [diff] [blame] | 9923 | /// immediate into a register. |
9924 | bool ARMTargetLowering::isLegalAddImmediate(int64_t Imm) const { | ||||
Andrew Trick | a22cdb7 | 2012-07-18 18:34:27 +0000 | [diff] [blame] | 9925 | // Same encoding for add/sub, just flip the sign. |
9926 | int64_t AbsImm = llvm::abs64(Imm); | ||||
9927 | if (!Subtarget->isThumb()) | ||||
9928 | return ARM_AM::getSOImmVal(AbsImm) != -1; | ||||
9929 | if (Subtarget->isThumb2()) | ||||
9930 | return ARM_AM::getT2SOImmVal(AbsImm) != -1; | ||||
9931 | // Thumb1 only has 8-bit unsigned immediate. | ||||
9932 | return AbsImm >= 0 && AbsImm <= 255; | ||||
Dan Gohman | 6136e94 | 2011-05-03 00:46:49 +0000 | [diff] [blame] | 9933 | } |
9934 | |||||
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9935 | static bool getARMIndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9936 | bool isSEXTLoad, SDValue &Base, |
9937 | SDValue &Offset, bool &isInc, | ||||
9938 | SelectionDAG &DAG) { | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9939 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
9940 | return false; | ||||
9941 | |||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9942 | if (VT == MVT::i16 || ((VT == MVT::i8 || VT == MVT::i1) && isSEXTLoad)) { |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9943 | // AddressingMode 3 |
9944 | Base = Ptr->getOperand(0); | ||||
9945 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { | ||||
Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 9946 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9947 | if (RHSC < 0 && RHSC > -256) { |
Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9948 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9949 | isInc = false; |
9950 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); | ||||
9951 | return true; | ||||
9952 | } | ||||
9953 | } | ||||
9954 | isInc = (Ptr->getOpcode() == ISD::ADD); | ||||
9955 | Offset = Ptr->getOperand(1); | ||||
9956 | return true; | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9957 | } else if (VT == MVT::i32 || VT == MVT::i8 || VT == MVT::i1) { |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9958 | // AddressingMode 2 |
9959 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { | ||||
Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 9960 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9961 | if (RHSC < 0 && RHSC > -0x1000) { |
Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9962 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9963 | isInc = false; |
9964 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); | ||||
9965 | Base = Ptr->getOperand(0); | ||||
9966 | return true; | ||||
9967 | } | ||||
9968 | } | ||||
9969 | |||||
9970 | if (Ptr->getOpcode() == ISD::ADD) { | ||||
9971 | isInc = true; | ||||
Evan Cheng | a20cde3 | 2011-07-20 23:34:39 +0000 | [diff] [blame] | 9972 | ARM_AM::ShiftOpc ShOpcVal= |
9973 | ARM_AM::getShiftOpcForNode(Ptr->getOperand(0).getOpcode()); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9974 | if (ShOpcVal != ARM_AM::no_shift) { |
9975 | Base = Ptr->getOperand(1); | ||||
9976 | Offset = Ptr->getOperand(0); | ||||
9977 | } else { | ||||
9978 | Base = Ptr->getOperand(0); | ||||
9979 | Offset = Ptr->getOperand(1); | ||||
9980 | } | ||||
9981 | return true; | ||||
9982 | } | ||||
9983 | |||||
9984 | isInc = (Ptr->getOpcode() == ISD::ADD); | ||||
9985 | Base = Ptr->getOperand(0); | ||||
9986 | Offset = Ptr->getOperand(1); | ||||
9987 | return true; | ||||
9988 | } | ||||
9989 | |||||
Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 9990 | // FIXME: Use VLDM / VSTM to emulate indexed FP load / store. |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9991 | return false; |
9992 | } | ||||
9993 | |||||
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9994 | static bool getT2IndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9995 | bool isSEXTLoad, SDValue &Base, |
9996 | SDValue &Offset, bool &isInc, | ||||
9997 | SelectionDAG &DAG) { | ||||
9998 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) | ||||
9999 | return false; | ||||
10000 | |||||
10001 | Base = Ptr->getOperand(0); | ||||
10002 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { | ||||
10003 | int RHSC = (int)RHS->getZExtValue(); | ||||
10004 | if (RHSC < 0 && RHSC > -0x100) { // 8 bits. | ||||
10005 | assert(Ptr->getOpcode() == ISD::ADD); | ||||
10006 | isInc = false; | ||||
10007 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); | ||||
10008 | return true; | ||||
10009 | } else if (RHSC > 0 && RHSC < 0x100) { // 8 bit, no zero. | ||||
10010 | isInc = Ptr->getOpcode() == ISD::ADD; | ||||
10011 | Offset = DAG.getConstant(RHSC, RHS->getValueType(0)); | ||||
10012 | return true; | ||||
10013 | } | ||||
10014 | } | ||||
10015 | |||||
10016 | return false; | ||||
10017 | } | ||||
10018 | |||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10019 | /// getPreIndexedAddressParts - returns true by value, base pointer and |
10020 | /// offset pointer and addressing mode by reference if the node's address | ||||
10021 | /// can be legally represented as pre-indexed load / store address. | ||||
10022 | bool | ||||
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 10023 | ARMTargetLowering::getPreIndexedAddressParts(SDNode *N, SDValue &Base, |
10024 | SDValue &Offset, | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10025 | ISD::MemIndexedMode &AM, |
Dan Gohman | 02b9313 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 10026 | SelectionDAG &DAG) const { |
Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10027 | if (Subtarget->isThumb1Only()) |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10028 | return false; |
10029 | |||||
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 10030 | EVT VT; |
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 10031 | SDValue Ptr; |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10032 | bool isSEXTLoad = false; |
10033 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { | ||||
10034 | Ptr = LD->getBasePtr(); | ||||
Dan Gohman | 47a7d6f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 10035 | VT = LD->getMemoryVT(); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10036 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
10037 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { | ||||
10038 | Ptr = ST->getBasePtr(); | ||||
Dan Gohman | 47a7d6f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 10039 | VT = ST->getMemoryVT(); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10040 | } else |
10041 | return false; | ||||
10042 | |||||
10043 | bool isInc; | ||||
Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10044 | bool isLegal = false; |
Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 10045 | if (Subtarget->isThumb2()) |
Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10046 | isLegal = getT2IndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
10047 | Offset, isInc, DAG); | ||||
Jim Grosbach | f24f9d9 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 10048 | else |
Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10049 | isLegal = getARMIndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
Evan Cheng | 844f0b4 | 2009-07-02 06:44:30 +0000 | [diff] [blame] | 10050 | Offset, isInc, DAG); |
Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10051 | if (!isLegal) |
10052 | return false; | ||||
10053 | |||||
10054 | AM = isInc ? ISD::PRE_INC : ISD::PRE_DEC; | ||||
10055 | return true; | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10056 | } |
10057 | |||||
10058 | /// getPostIndexedAddressParts - returns true by value, base pointer and | ||||
10059 | /// offset pointer and addressing mode by reference if this node can be | ||||
10060 | /// combined with a load / store to form a post-indexed load / store. | ||||
10061 | bool ARMTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op, | ||||
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 10062 | SDValue &Base, |
10063 | SDValue &Offset, | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10064 | ISD::MemIndexedMode &AM, |
Dan Gohman | 02b9313 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 10065 | SelectionDAG &DAG) const { |
Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10066 | if (Subtarget->isThumb1Only()) |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10067 | return false; |
10068 | |||||
Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 10069 | EVT VT; |
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 10070 | SDValue Ptr; |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10071 | bool isSEXTLoad = false; |
10072 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { | ||||
Dan Gohman | 47a7d6f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 10073 | VT = LD->getMemoryVT(); |
Evan Cheng | f19384d | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 10074 | Ptr = LD->getBasePtr(); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10075 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
10076 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { | ||||
Dan Gohman | 47a7d6f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 10077 | VT = ST->getMemoryVT(); |
Evan Cheng | f19384d | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 10078 | Ptr = ST->getBasePtr(); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10079 | } else |
10080 | return false; | ||||
10081 | |||||
10082 | bool isInc; | ||||
Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10083 | bool isLegal = false; |
Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 10084 | if (Subtarget->isThumb2()) |
Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10085 | isLegal = getT2IndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
Evan Cheng | f19384d | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 10086 | isInc, DAG); |
Jim Grosbach | f24f9d9 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 10087 | else |
Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10088 | isLegal = getARMIndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
10089 | isInc, DAG); | ||||
10090 | if (!isLegal) | ||||
10091 | return false; | ||||
10092 | |||||
Evan Cheng | f19384d | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 10093 | if (Ptr != Base) { |
10094 | // Swap base ptr and offset to catch more post-index load / store when | ||||
10095 | // it's legal. In Thumb2 mode, offset must be an immediate. | ||||
10096 | if (Ptr == Offset && Op->getOpcode() == ISD::ADD && | ||||
10097 | !Subtarget->isThumb2()) | ||||
10098 | std::swap(Base, Offset); | ||||
10099 | |||||
10100 | // Post-indexed load / store update the base pointer. | ||||
10101 | if (Ptr != Base) | ||||
10102 | return false; | ||||
10103 | } | ||||
10104 | |||||
Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10105 | AM = isInc ? ISD::POST_INC : ISD::POST_DEC; |
10106 | return true; | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10107 | } |
10108 | |||||
Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 10109 | void ARMTargetLowering::computeMaskedBitsForTargetNode(const SDValue Op, |
Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 10110 | APInt &KnownZero, |
Dan Gohman | f990faf | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 10111 | APInt &KnownOne, |
Dan Gohman | 309d3d5 | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 10112 | const SelectionDAG &DAG, |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10113 | unsigned Depth) const { |
Michael Gottesman | 696e44e | 2013-06-18 20:49:45 +0000 | [diff] [blame] | 10114 | unsigned BitWidth = KnownOne.getBitWidth(); |
10115 | KnownZero = KnownOne = APInt(BitWidth, 0); | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10116 | switch (Op.getOpcode()) { |
10117 | default: break; | ||||
Michael Gottesman | 696e44e | 2013-06-18 20:49:45 +0000 | [diff] [blame] | 10118 | case ARMISD::ADDC: |
10119 | case ARMISD::ADDE: | ||||
10120 | case ARMISD::SUBC: | ||||
10121 | case ARMISD::SUBE: | ||||
10122 | // These nodes' second result is a boolean | ||||
10123 | if (Op.getResNo() == 0) | ||||
10124 | break; | ||||
10125 | KnownZero |= APInt::getHighBitsSet(BitWidth, BitWidth - 1); | ||||
10126 | break; | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10127 | case ARMISD::CMOV: { |
10128 | // Bits are known zero/one if known on the LHS and RHS. | ||||
Rafael Espindola | ba0a6ca | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 10129 | DAG.ComputeMaskedBits(Op.getOperand(0), KnownZero, KnownOne, Depth+1); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10130 | if (KnownZero == 0 && KnownOne == 0) return; |
10131 | |||||
Dan Gohman | f990faf | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 10132 | APInt KnownZeroRHS, KnownOneRHS; |
Rafael Espindola | ba0a6ca | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 10133 | DAG.ComputeMaskedBits(Op.getOperand(1), KnownZeroRHS, KnownOneRHS, Depth+1); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10134 | KnownZero &= KnownZeroRHS; |
10135 | KnownOne &= KnownOneRHS; | ||||
10136 | return; | ||||
10137 | } | ||||
Tim Northover | 01b4aa9 | 2014-04-03 15:10:35 +0000 | [diff] [blame] | 10138 | case ISD::INTRINSIC_W_CHAIN: { |
10139 | ConstantSDNode *CN = cast<ConstantSDNode>(Op->getOperand(1)); | ||||
10140 | Intrinsic::ID IntID = static_cast<Intrinsic::ID>(CN->getZExtValue()); | ||||
10141 | switch (IntID) { | ||||
10142 | default: return; | ||||
10143 | case Intrinsic::arm_ldaex: | ||||
10144 | case Intrinsic::arm_ldrex: { | ||||
10145 | EVT VT = cast<MemIntrinsicSDNode>(Op)->getMemoryVT(); | ||||
10146 | unsigned MemBits = VT.getScalarType().getSizeInBits(); | ||||
10147 | KnownZero |= APInt::getHighBitsSet(BitWidth, BitWidth - MemBits); | ||||
10148 | return; | ||||
10149 | } | ||||
10150 | } | ||||
10151 | } | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10152 | } |
10153 | } | ||||
10154 | |||||
10155 | //===----------------------------------------------------------------------===// | ||||
10156 | // ARM Inline Assembly Support | ||||
10157 | //===----------------------------------------------------------------------===// | ||||
10158 | |||||
Evan Cheng | 078b0b0 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 10159 | bool ARMTargetLowering::ExpandInlineAsm(CallInst *CI) const { |
10160 | // Looking for "rev" which is V6+. | ||||
10161 | if (!Subtarget->hasV6Ops()) | ||||
10162 | return false; | ||||
10163 | |||||
10164 | InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue()); | ||||
10165 | std::string AsmStr = IA->getAsmString(); | ||||
10166 | SmallVector<StringRef, 4> AsmPieces; | ||||
10167 | SplitString(AsmStr, AsmPieces, ";\n"); | ||||
10168 | |||||
10169 | switch (AsmPieces.size()) { | ||||
10170 | default: return false; | ||||
10171 | case 1: | ||||
10172 | AsmStr = AsmPieces[0]; | ||||
10173 | AsmPieces.clear(); | ||||
10174 | SplitString(AsmStr, AsmPieces, " \t,"); | ||||
10175 | |||||
10176 | // rev $0, $1 | ||||
10177 | if (AsmPieces.size() == 3 && | ||||
10178 | AsmPieces[0] == "rev" && AsmPieces[1] == "$0" && AsmPieces[2] == "$1" && | ||||
10179 | IA->getConstraintString().compare(0, 4, "=l,l") == 0) { | ||||
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 10180 | IntegerType *Ty = dyn_cast<IntegerType>(CI->getType()); |
Evan Cheng | 078b0b0 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 10181 | if (Ty && Ty->getBitWidth() == 32) |
10182 | return IntrinsicLowering::LowerToByteSwap(CI); | ||||
10183 | } | ||||
10184 | break; | ||||
10185 | } | ||||
10186 | |||||
10187 | return false; | ||||
10188 | } | ||||
10189 | |||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10190 | /// getConstraintType - Given a constraint letter, return the type of |
10191 | /// constraint it is for this target. | ||||
10192 | ARMTargetLowering::ConstraintType | ||||
Chris Lattner | d685514 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 10193 | ARMTargetLowering::getConstraintType(const std::string &Constraint) const { |
10194 | if (Constraint.size() == 1) { | ||||
10195 | switch (Constraint[0]) { | ||||
10196 | default: break; | ||||
10197 | case 'l': return C_RegisterClass; | ||||
Chris Lattner | 6223e83 | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 10198 | case 'w': return C_RegisterClass; |
Eric Christopher | f45daac | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 10199 | case 'h': return C_RegisterClass; |
Eric Christopher | f1c7459 | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 10200 | case 'x': return C_RegisterClass; |
Eric Christopher | c011d31 | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 10201 | case 't': return C_RegisterClass; |
Eric Christopher | 29f1db8 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 10202 | case 'j': return C_Other; // Constant for movw. |
Eric Christopher | aa50300 | 2011-07-29 21:18:58 +0000 | [diff] [blame] | 10203 | // An address with a single base register. Due to the way we |
10204 | // currently handle addresses it is the same as an 'r' memory constraint. | ||||
10205 | case 'Q': return C_Memory; | ||||
Chris Lattner | d685514 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 10206 | } |
Eric Christopher | e256cd0 | 2011-06-21 22:10:57 +0000 | [diff] [blame] | 10207 | } else if (Constraint.size() == 2) { |
10208 | switch (Constraint[0]) { | ||||
10209 | default: break; | ||||
10210 | // All 'U+' constraints are addresses. | ||||
10211 | case 'U': return C_Memory; | ||||
10212 | } | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10213 | } |
Chris Lattner | d685514 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 10214 | return TargetLowering::getConstraintType(Constraint); |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10215 | } |
10216 | |||||
John Thompson | e8360b7 | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 10217 | /// Examine constraint type and operand type and determine a weight value. |
10218 | /// This object must already have been set up with the operand type | ||||
10219 | /// and the current alternative constraint selected. | ||||
10220 | TargetLowering::ConstraintWeight | ||||
10221 | ARMTargetLowering::getSingleConstraintMatchWeight( | ||||
10222 | AsmOperandInfo &info, const char *constraint) const { | ||||
10223 | ConstraintWeight weight = CW_Invalid; | ||||
10224 | Value *CallOperandVal = info.CallOperandVal; | ||||
10225 | // If we don't have a value, we can't do a match, | ||||
10226 | // but allow it at the lowest weight. | ||||
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 10227 | if (!CallOperandVal) |
John Thompson | e8360b7 | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 10228 | return CW_Default; |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 10229 | Type *type = CallOperandVal->getType(); |
John Thompson | e8360b7 | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 10230 | // Look at the constraint type. |
10231 | switch (*constraint) { | ||||
10232 | default: | ||||
10233 | weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint); | ||||
10234 | break; | ||||
10235 | case 'l': | ||||
10236 | if (type->isIntegerTy()) { | ||||
10237 | if (Subtarget->isThumb()) | ||||
10238 | weight = CW_SpecificReg; | ||||
10239 | else | ||||
10240 | weight = CW_Register; | ||||
10241 | } | ||||
10242 | break; | ||||
10243 | case 'w': | ||||
10244 | if (type->isFloatingPointTy()) | ||||
10245 | weight = CW_Register; | ||||
10246 | break; | ||||
10247 | } | ||||
10248 | return weight; | ||||
10249 | } | ||||
10250 | |||||
Eric Christopher | cf2007c | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 10251 | typedef std::pair<unsigned, const TargetRegisterClass*> RCPair; |
10252 | RCPair | ||||
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10253 | ARMTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint, |
Chad Rosier | 295bd43 | 2013-06-22 18:37:38 +0000 | [diff] [blame] | 10254 | MVT VT) const { |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10255 | if (Constraint.size() == 1) { |
Jakob Stoklund Olesen | 0ca14e4 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 10256 | // GCC ARM Constraint Letters |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10257 | switch (Constraint[0]) { |
Eric Christopher | f45daac | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 10258 | case 'l': // Low regs or general regs. |
Jakob Stoklund Olesen | 0ca14e4 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 10259 | if (Subtarget->isThumb()) |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10260 | return RCPair(0U, &ARM::tGPRRegClass); |
10261 | return RCPair(0U, &ARM::GPRRegClass); | ||||
Eric Christopher | f45daac | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 10262 | case 'h': // High regs or no regs. |
10263 | if (Subtarget->isThumb()) | ||||
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10264 | return RCPair(0U, &ARM::hGPRRegClass); |
Eric Christopher | f09b0f1 | 2011-07-01 00:19:27 +0000 | [diff] [blame] | 10265 | break; |
Chris Lattner | 6223e83 | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 10266 | case 'r': |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10267 | return RCPair(0U, &ARM::GPRRegClass); |
Chris Lattner | 6223e83 | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 10268 | case 'w': |
Tim Northover | 28adfbb | 2013-11-14 17:15:39 +0000 | [diff] [blame] | 10269 | if (VT == MVT::Other) |
10270 | break; | ||||
Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10271 | if (VT == MVT::f32) |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10272 | return RCPair(0U, &ARM::SPRRegClass); |
Bob Wilson | 3152b047 | 2009-12-18 01:03:29 +0000 | [diff] [blame] | 10273 | if (VT.getSizeInBits() == 64) |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10274 | return RCPair(0U, &ARM::DPRRegClass); |
Evan Cheng | 0c2544f | 2009-12-08 23:06:22 +0000 | [diff] [blame] | 10275 | if (VT.getSizeInBits() == 128) |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10276 | return RCPair(0U, &ARM::QPRRegClass); |
Chris Lattner | 6223e83 | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 10277 | break; |
Eric Christopher | f1c7459 | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 10278 | case 'x': |
Tim Northover | 28adfbb | 2013-11-14 17:15:39 +0000 | [diff] [blame] | 10279 | if (VT == MVT::Other) |
10280 | break; | ||||
Eric Christopher | f1c7459 | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 10281 | if (VT == MVT::f32) |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10282 | return RCPair(0U, &ARM::SPR_8RegClass); |
Eric Christopher | f1c7459 | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 10283 | if (VT.getSizeInBits() == 64) |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10284 | return RCPair(0U, &ARM::DPR_8RegClass); |
Eric Christopher | f1c7459 | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 10285 | if (VT.getSizeInBits() == 128) |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10286 | return RCPair(0U, &ARM::QPR_8RegClass); |
Eric Christopher | f1c7459 | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 10287 | break; |
Eric Christopher | c011d31 | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 10288 | case 't': |
10289 | if (VT == MVT::f32) | ||||
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10290 | return RCPair(0U, &ARM::SPRRegClass); |
Eric Christopher | c011d31 | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 10291 | break; |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10292 | } |
10293 | } | ||||
Bob Wilson | 3f2293b | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 10294 | if (StringRef("{cc}").equals_lower(Constraint)) |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10295 | return std::make_pair(unsigned(ARM::CPSR), &ARM::CCRRegClass); |
Bob Wilson | 3f2293b | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 10296 | |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10297 | return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); |
10298 | } | ||||
10299 | |||||
Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10300 | /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops |
10301 | /// vector. If it is invalid, don't add anything to Ops. | ||||
10302 | void ARMTargetLowering::LowerAsmOperandForConstraint(SDValue Op, | ||||
Eric Christopher | de9399b | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 10303 | std::string &Constraint, |
Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10304 | std::vector<SDValue>&Ops, |
10305 | SelectionDAG &DAG) const { | ||||
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 10306 | SDValue Result; |
Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10307 | |
Eric Christopher | de9399b | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 10308 | // Currently only support length 1 constraints. |
10309 | if (Constraint.length() != 1) return; | ||||
Eric Christopher | 0713a9d | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 10310 | |
Eric Christopher | de9399b | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 10311 | char ConstraintLetter = Constraint[0]; |
10312 | switch (ConstraintLetter) { | ||||
Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10313 | default: break; |
Eric Christopher | 29f1db8 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 10314 | case 'j': |
Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10315 | case 'I': case 'J': case 'K': case 'L': |
10316 | case 'M': case 'N': case 'O': | ||||
10317 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op); | ||||
10318 | if (!C) | ||||
10319 | return; | ||||
10320 | |||||
10321 | int64_t CVal64 = C->getSExtValue(); | ||||
10322 | int CVal = (int) CVal64; | ||||
10323 | // None of these constraints allow values larger than 32 bits. Check | ||||
10324 | // that the value fits in an int. | ||||
10325 | if (CVal != CVal64) | ||||
10326 | return; | ||||
10327 | |||||
Eric Christopher | de9399b | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 10328 | switch (ConstraintLetter) { |
Eric Christopher | 29f1db8 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 10329 | case 'j': |
Andrew Trick | 53df4b6 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 10330 | // Constant suitable for movw, must be between 0 and |
10331 | // 65535. | ||||
10332 | if (Subtarget->hasV6T2Ops()) | ||||
10333 | if (CVal >= 0 && CVal <= 65535) | ||||
10334 | break; | ||||
10335 | return; | ||||
Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10336 | case 'I': |
David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10337 | if (Subtarget->isThumb1Only()) { |
10338 | // This must be a constant between 0 and 255, for ADD | ||||
10339 | // immediates. | ||||
Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10340 | if (CVal >= 0 && CVal <= 255) |
10341 | break; | ||||
David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10342 | } else if (Subtarget->isThumb2()) { |
10343 | // A constant that can be used as an immediate value in a | ||||
10344 | // data-processing instruction. | ||||
10345 | if (ARM_AM::getT2SOImmVal(CVal) != -1) | ||||
10346 | break; | ||||
Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10347 | } else { |
10348 | // A constant that can be used as an immediate value in a | ||||
10349 | // data-processing instruction. | ||||
10350 | if (ARM_AM::getSOImmVal(CVal) != -1) | ||||
10351 | break; | ||||
10352 | } | ||||
10353 | return; | ||||
10354 | |||||
10355 | case 'J': | ||||
David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10356 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10357 | // This must be a constant between -255 and -1, for negated ADD |
10358 | // immediates. This can be used in GCC with an "n" modifier that | ||||
10359 | // prints the negated value, for use with SUB instructions. It is | ||||
10360 | // not useful otherwise but is implemented for compatibility. | ||||
10361 | if (CVal >= -255 && CVal <= -1) | ||||
10362 | break; | ||||
10363 | } else { | ||||
10364 | // This must be a constant between -4095 and 4095. It is not clear | ||||
10365 | // what this constraint is intended for. Implemented for | ||||
10366 | // compatibility with GCC. | ||||
10367 | if (CVal >= -4095 && CVal <= 4095) | ||||
10368 | break; | ||||
10369 | } | ||||
10370 | return; | ||||
10371 | |||||
10372 | case 'K': | ||||
David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10373 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10374 | // A 32-bit value where only one byte has a nonzero value. Exclude |
10375 | // zero to match GCC. This constraint is used by GCC internally for | ||||
10376 | // constants that can be loaded with a move/shift combination. | ||||
10377 | // It is not useful otherwise but is implemented for compatibility. | ||||
10378 | if (CVal != 0 && ARM_AM::isThumbImmShiftedVal(CVal)) | ||||
10379 | break; | ||||
David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10380 | } else if (Subtarget->isThumb2()) { |
10381 | // A constant whose bitwise inverse can be used as an immediate | ||||
10382 | // value in a data-processing instruction. This can be used in GCC | ||||
10383 | // with a "B" modifier that prints the inverted value, for use with | ||||
10384 | // BIC and MVN instructions. It is not useful otherwise but is | ||||
10385 | // implemented for compatibility. | ||||
10386 | if (ARM_AM::getT2SOImmVal(~CVal) != -1) | ||||
10387 | break; | ||||
Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10388 | } else { |
10389 | // A constant whose bitwise inverse can be used as an immediate | ||||
10390 | // value in a data-processing instruction. This can be used in GCC | ||||
10391 | // with a "B" modifier that prints the inverted value, for use with | ||||
10392 | // BIC and MVN instructions. It is not useful otherwise but is | ||||
10393 | // implemented for compatibility. | ||||
10394 | if (ARM_AM::getSOImmVal(~CVal) != -1) | ||||
10395 | break; | ||||
10396 | } | ||||
10397 | return; | ||||
10398 | |||||
10399 | case 'L': | ||||
David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10400 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10401 | // This must be a constant between -7 and 7, |
10402 | // for 3-operand ADD/SUB immediate instructions. | ||||
10403 | if (CVal >= -7 && CVal < 7) | ||||
10404 | break; | ||||
David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10405 | } else if (Subtarget->isThumb2()) { |
10406 | // A constant whose negation can be used as an immediate value in a | ||||
10407 | // data-processing instruction. This can be used in GCC with an "n" | ||||
10408 | // modifier that prints the negated value, for use with SUB | ||||
10409 | // instructions. It is not useful otherwise but is implemented for | ||||
10410 | // compatibility. | ||||
10411 | if (ARM_AM::getT2SOImmVal(-CVal) != -1) | ||||
10412 | break; | ||||
Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10413 | } else { |
10414 | // A constant whose negation can be used as an immediate value in a | ||||
10415 | // data-processing instruction. This can be used in GCC with an "n" | ||||
10416 | // modifier that prints the negated value, for use with SUB | ||||
10417 | // instructions. It is not useful otherwise but is implemented for | ||||
10418 | // compatibility. | ||||
10419 | if (ARM_AM::getSOImmVal(-CVal) != -1) | ||||
10420 | break; | ||||
10421 | } | ||||
10422 | return; | ||||
10423 | |||||
10424 | case 'M': | ||||
David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10425 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10426 | // This must be a multiple of 4 between 0 and 1020, for |
10427 | // ADD sp + immediate. | ||||
10428 | if ((CVal >= 0 && CVal <= 1020) && ((CVal & 3) == 0)) | ||||
10429 | break; | ||||
10430 | } else { | ||||
10431 | // A power of two or a constant between 0 and 32. This is used in | ||||
10432 | // GCC for the shift amount on shifted register operands, but it is | ||||
10433 | // useful in general for any shift amounts. | ||||
10434 | if ((CVal >= 0 && CVal <= 32) || ((CVal & (CVal - 1)) == 0)) | ||||
10435 | break; | ||||
10436 | } | ||||
10437 | return; | ||||
10438 | |||||
10439 | case 'N': | ||||
David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10440 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10441 | // This must be a constant between 0 and 31, for shift amounts. |
10442 | if (CVal >= 0 && CVal <= 31) | ||||
10443 | break; | ||||
10444 | } | ||||
10445 | return; | ||||
10446 | |||||
10447 | case 'O': | ||||
David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10448 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10449 | // This must be a multiple of 4 between -508 and 508, for |
10450 | // ADD/SUB sp = sp + immediate. | ||||
10451 | if ((CVal >= -508 && CVal <= 508) && ((CVal & 3) == 0)) | ||||
10452 | break; | ||||
10453 | } | ||||
10454 | return; | ||||
10455 | } | ||||
10456 | Result = DAG.getTargetConstant(CVal, Op.getValueType()); | ||||
10457 | break; | ||||
10458 | } | ||||
10459 | |||||
10460 | if (Result.getNode()) { | ||||
10461 | Ops.push_back(Result); | ||||
10462 | return; | ||||
10463 | } | ||||
Dale Johannesen | ce97d55 | 2010-06-25 21:55:36 +0000 | [diff] [blame] | 10464 | return TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG); |
Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10465 | } |
Anton Korobeynikov | 29a44df | 2009-09-23 19:04:09 +0000 | [diff] [blame] | 10466 | |
Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 10467 | SDValue ARMTargetLowering::LowerDivRem(SDValue Op, SelectionDAG &DAG) const { |
10468 | assert(Subtarget->isTargetAEABI() && "Register-based DivRem lowering only"); | ||||
10469 | unsigned Opcode = Op->getOpcode(); | ||||
10470 | assert((Opcode == ISD::SDIVREM || Opcode == ISD::UDIVREM) && | ||||
10471 | "Invalid opcode for Div/Rem lowering"); | ||||
10472 | bool isSigned = (Opcode == ISD::SDIVREM); | ||||
10473 | EVT VT = Op->getValueType(0); | ||||
10474 | Type *Ty = VT.getTypeForEVT(*DAG.getContext()); | ||||
10475 | |||||
10476 | RTLIB::Libcall LC; | ||||
10477 | switch (VT.getSimpleVT().SimpleTy) { | ||||
10478 | default: llvm_unreachable("Unexpected request for libcall!"); | ||||
10479 | case MVT::i8: LC= isSigned ? RTLIB::SDIVREM_I8 : RTLIB::UDIVREM_I8; break; | ||||
10480 | case MVT::i16: LC= isSigned ? RTLIB::SDIVREM_I16 : RTLIB::UDIVREM_I16; break; | ||||
10481 | case MVT::i32: LC= isSigned ? RTLIB::SDIVREM_I32 : RTLIB::UDIVREM_I32; break; | ||||
10482 | case MVT::i64: LC= isSigned ? RTLIB::SDIVREM_I64 : RTLIB::UDIVREM_I64; break; | ||||
10483 | } | ||||
10484 | |||||
10485 | SDValue InChain = DAG.getEntryNode(); | ||||
10486 | |||||
10487 | TargetLowering::ArgListTy Args; | ||||
10488 | TargetLowering::ArgListEntry Entry; | ||||
10489 | for (unsigned i = 0, e = Op->getNumOperands(); i != e; ++i) { | ||||
10490 | EVT ArgVT = Op->getOperand(i).getValueType(); | ||||
10491 | Type *ArgTy = ArgVT.getTypeForEVT(*DAG.getContext()); | ||||
10492 | Entry.Node = Op->getOperand(i); | ||||
10493 | Entry.Ty = ArgTy; | ||||
10494 | Entry.isSExt = isSigned; | ||||
10495 | Entry.isZExt = !isSigned; | ||||
10496 | Args.push_back(Entry); | ||||
10497 | } | ||||
10498 | |||||
10499 | SDValue Callee = DAG.getExternalSymbol(getLibcallName(LC), | ||||
10500 | getPointerTy()); | ||||
10501 | |||||
10502 | Type *RetTy = (Type*)StructType::get(Ty, Ty, NULL); | ||||
10503 | |||||
10504 | SDLoc dl(Op); | ||||
10505 | TargetLowering:: | ||||
10506 | CallLoweringInfo CLI(InChain, RetTy, isSigned, !isSigned, false, true, | ||||
10507 | 0, getLibcallCallingConv(LC), /*isTailCall=*/false, | ||||
10508 | /*doesNotReturn=*/false, /*isReturnValueUsed=*/true, | ||||
10509 | Callee, Args, DAG, dl); | ||||
10510 | std::pair<SDValue, SDValue> CallInfo = LowerCallTo(CLI); | ||||
10511 | |||||
10512 | return CallInfo.first; | ||||
10513 | } | ||||
10514 | |||||
Anton Korobeynikov | 29a44df | 2009-09-23 19:04:09 +0000 | [diff] [blame] | 10515 | bool |
10516 | ARMTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { | ||||
10517 | // The ARM target isn't yet aware of offsets. | ||||
10518 | return false; | ||||
10519 | } | ||||
Evan Cheng | 4a609f3c | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 10520 | |
Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 10521 | bool ARM::isBitFieldInvertedMask(unsigned v) { |
10522 | if (v == 0xffffffff) | ||||
Benjamin Kramer | 8bad66e | 2013-05-19 22:01:57 +0000 | [diff] [blame] | 10523 | return false; |
10524 | |||||
Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 10525 | // there can be 1's on either or both "outsides", all the "inside" |
10526 | // bits must be 0's | ||||
Benjamin Kramer | 8bad66e | 2013-05-19 22:01:57 +0000 | [diff] [blame] | 10527 | unsigned TO = CountTrailingOnes_32(v); |
10528 | unsigned LO = CountLeadingOnes_32(v); | ||||
10529 | v = (v >> TO) << TO; | ||||
10530 | v = (v << LO) >> LO; | ||||
10531 | return v == 0; | ||||
Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 10532 | } |
10533 | |||||
Evan Cheng | 4a609f3c | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 10534 | /// isFPImmLegal - Returns true if the target can instruction select the |
10535 | /// specified FP immediate natively. If false, the legalizer will | ||||
10536 | /// materialize the FP immediate as a load from a constant pool. | ||||
10537 | bool ARMTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const { | ||||
10538 | if (!Subtarget->hasVFP3()) | ||||
10539 | return false; | ||||
10540 | if (VT == MVT::f32) | ||||
Jim Grosbach | efc761a | 2011-09-30 00:50:06 +0000 | [diff] [blame] | 10541 | return ARM_AM::getFP32Imm(Imm) != -1; |
Evan Cheng | 4a609f3c | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 10542 | if (VT == MVT::f64) |
Jim Grosbach | efc761a | 2011-09-30 00:50:06 +0000 | [diff] [blame] | 10543 | return ARM_AM::getFP64Imm(Imm) != -1; |
Evan Cheng | 4a609f3c | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 10544 | return false; |
10545 | } | ||||
Bob Wilson | 5549d49 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 10546 | |
Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 10547 | /// getTgtMemIntrinsic - Represent NEON load and store intrinsics as |
Bob Wilson | 5549d49 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 10548 | /// MemIntrinsicNodes. The associated MachineMemOperands record the alignment |
10549 | /// specified in the intrinsic calls. | ||||
10550 | bool ARMTargetLowering::getTgtMemIntrinsic(IntrinsicInfo &Info, | ||||
10551 | const CallInst &I, | ||||
10552 | unsigned Intrinsic) const { | ||||
10553 | switch (Intrinsic) { | ||||
10554 | case Intrinsic::arm_neon_vld1: | ||||
10555 | case Intrinsic::arm_neon_vld2: | ||||
10556 | case Intrinsic::arm_neon_vld3: | ||||
10557 | case Intrinsic::arm_neon_vld4: | ||||
10558 | case Intrinsic::arm_neon_vld2lane: | ||||
10559 | case Intrinsic::arm_neon_vld3lane: | ||||
10560 | case Intrinsic::arm_neon_vld4lane: { | ||||
10561 | Info.opc = ISD::INTRINSIC_W_CHAIN; | ||||
10562 | // Conservatively set memVT to the entire set of vectors loaded. | ||||
Micah Villmow | cdfe20b | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 10563 | uint64_t NumElts = getDataLayout()->getTypeAllocSize(I.getType()) / 8; |
Bob Wilson | 5549d49 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 10564 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
10565 | Info.ptrVal = I.getArgOperand(0); | ||||
10566 | Info.offset = 0; | ||||
10567 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); | ||||
10568 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); | ||||
10569 | Info.vol = false; // volatile loads with NEON intrinsics not supported | ||||
10570 | Info.readMem = true; | ||||
10571 | Info.writeMem = false; | ||||
10572 | return true; | ||||
10573 | } | ||||
10574 | case Intrinsic::arm_neon_vst1: | ||||
10575 | case Intrinsic::arm_neon_vst2: | ||||
10576 | case Intrinsic::arm_neon_vst3: | ||||
10577 | case Intrinsic::arm_neon_vst4: | ||||
10578 | case Intrinsic::arm_neon_vst2lane: | ||||
10579 | case Intrinsic::arm_neon_vst3lane: | ||||
10580 | case Intrinsic::arm_neon_vst4lane: { | ||||
10581 | Info.opc = ISD::INTRINSIC_VOID; | ||||
10582 | // Conservatively set memVT to the entire set of vectors stored. | ||||
10583 | unsigned NumElts = 0; | ||||
10584 | for (unsigned ArgI = 1, ArgE = I.getNumArgOperands(); ArgI < ArgE; ++ArgI) { | ||||
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 10585 | Type *ArgTy = I.getArgOperand(ArgI)->getType(); |
Bob Wilson | 5549d49 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 10586 | if (!ArgTy->isVectorTy()) |
10587 | break; | ||||
Micah Villmow | cdfe20b | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 10588 | NumElts += getDataLayout()->getTypeAllocSize(ArgTy) / 8; |
Bob Wilson | 5549d49 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 10589 | } |
10590 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); | ||||
10591 | Info.ptrVal = I.getArgOperand(0); | ||||
10592 | Info.offset = 0; | ||||
10593 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); | ||||
10594 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); | ||||
10595 | Info.vol = false; // volatile stores with NEON intrinsics not supported | ||||
10596 | Info.readMem = false; | ||||
10597 | Info.writeMem = true; | ||||
10598 | return true; | ||||
10599 | } | ||||
Tim Northover | 1ff5f29 | 2014-03-26 14:39:31 +0000 | [diff] [blame] | 10600 | case Intrinsic::arm_ldaex: |
Tim Northover | a7ecd24 | 2013-07-16 09:46:55 +0000 | [diff] [blame] | 10601 | case Intrinsic::arm_ldrex: { |
10602 | PointerType *PtrTy = cast<PointerType>(I.getArgOperand(0)->getType()); | ||||
10603 | Info.opc = ISD::INTRINSIC_W_CHAIN; | ||||
10604 | Info.memVT = MVT::getVT(PtrTy->getElementType()); | ||||
10605 | Info.ptrVal = I.getArgOperand(0); | ||||
10606 | Info.offset = 0; | ||||
10607 | Info.align = getDataLayout()->getABITypeAlignment(PtrTy->getElementType()); | ||||
10608 | Info.vol = true; | ||||
10609 | Info.readMem = true; | ||||
10610 | Info.writeMem = false; | ||||
10611 | return true; | ||||
10612 | } | ||||
Tim Northover | 1ff5f29 | 2014-03-26 14:39:31 +0000 | [diff] [blame] | 10613 | case Intrinsic::arm_stlex: |
Tim Northover | a7ecd24 | 2013-07-16 09:46:55 +0000 | [diff] [blame] | 10614 | case Intrinsic::arm_strex: { |
10615 | PointerType *PtrTy = cast<PointerType>(I.getArgOperand(1)->getType()); | ||||
10616 | Info.opc = ISD::INTRINSIC_W_CHAIN; | ||||
10617 | Info.memVT = MVT::getVT(PtrTy->getElementType()); | ||||
10618 | Info.ptrVal = I.getArgOperand(1); | ||||
10619 | Info.offset = 0; | ||||
10620 | Info.align = getDataLayout()->getABITypeAlignment(PtrTy->getElementType()); | ||||
10621 | Info.vol = true; | ||||
10622 | Info.readMem = false; | ||||
10623 | Info.writeMem = true; | ||||
10624 | return true; | ||||
10625 | } | ||||
Tim Northover | 1ff5f29 | 2014-03-26 14:39:31 +0000 | [diff] [blame] | 10626 | case Intrinsic::arm_stlexd: |
Bruno Cardoso Lopes | 325110f | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 10627 | case Intrinsic::arm_strexd: { |
10628 | Info.opc = ISD::INTRINSIC_W_CHAIN; | ||||
10629 | Info.memVT = MVT::i64; | ||||
10630 | Info.ptrVal = I.getArgOperand(2); | ||||
10631 | Info.offset = 0; | ||||
10632 | Info.align = 8; | ||||
Bruno Cardoso Lopes | d66ab9e | 2011-06-16 18:11:32 +0000 | [diff] [blame] | 10633 | Info.vol = true; |
Bruno Cardoso Lopes | 325110f | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 10634 | Info.readMem = false; |
10635 | Info.writeMem = true; | ||||
10636 | return true; | ||||
10637 | } | ||||
Tim Northover | 1ff5f29 | 2014-03-26 14:39:31 +0000 | [diff] [blame] | 10638 | case Intrinsic::arm_ldaexd: |
Bruno Cardoso Lopes | 325110f | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 10639 | case Intrinsic::arm_ldrexd: { |
10640 | Info.opc = ISD::INTRINSIC_W_CHAIN; | ||||
10641 | Info.memVT = MVT::i64; | ||||
10642 | Info.ptrVal = I.getArgOperand(0); | ||||
10643 | Info.offset = 0; | ||||
10644 | Info.align = 8; | ||||
Bruno Cardoso Lopes | d66ab9e | 2011-06-16 18:11:32 +0000 | [diff] [blame] | 10645 | Info.vol = true; |
Bruno Cardoso Lopes | 325110f | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 10646 | Info.readMem = true; |
10647 | Info.writeMem = false; | ||||
10648 | return true; | ||||
10649 | } | ||||
Bob Wilson | 5549d49 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 10650 | default: |
10651 | break; | ||||
10652 | } | ||||
10653 | |||||
10654 | return false; | ||||
10655 | } | ||||
Juergen Ributzka | 659ce00 | 2014-01-28 01:20:14 +0000 | [diff] [blame] | 10656 | |
10657 | /// \brief Returns true if it is beneficial to convert a load of a constant | ||||
10658 | /// to just the constant itself. | ||||
10659 | bool ARMTargetLowering::shouldConvertConstantLoadToIntImm(const APInt &Imm, | ||||
10660 | Type *Ty) const { | ||||
10661 | assert(Ty->isIntegerTy()); | ||||
10662 | |||||
10663 | unsigned Bits = Ty->getPrimitiveSizeInBits(); | ||||
10664 | if (Bits == 0 || Bits > 32) | ||||
10665 | return false; | ||||
10666 | return true; | ||||
10667 | } | ||||
Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 10668 | |
10669 | bool ARMTargetLowering::shouldExpandAtomicInIR(Instruction *Inst) const { | ||||
10670 | // Loads and stores less than 64-bits are already atomic; ones above that | ||||
10671 | // are doomed anyway, so defer to the default libcall and blame the OS when | ||||
10672 | // things go wrong: | ||||
10673 | if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) | ||||
10674 | return SI->getValueOperand()->getType()->getPrimitiveSizeInBits() == 64; | ||||
10675 | else if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) | ||||
10676 | return LI->getType()->getPrimitiveSizeInBits() == 64; | ||||
10677 | |||||
10678 | // For the real atomic operations, we have ldrex/strex up to 64 bits. | ||||
10679 | return Inst->getType()->getPrimitiveSizeInBits() <= 64; | ||||
10680 | } | ||||
10681 | |||||
10682 | Value *ARMTargetLowering::emitLoadLinked(IRBuilder<> &Builder, Value *Addr, | ||||
10683 | AtomicOrdering Ord) const { | ||||
10684 | Module *M = Builder.GetInsertBlock()->getParent()->getParent(); | ||||
10685 | Type *ValTy = cast<PointerType>(Addr->getType())->getElementType(); | ||||
10686 | bool IsAcquire = | ||||
10687 | Ord == Acquire || Ord == AcquireRelease || Ord == SequentiallyConsistent; | ||||
10688 | |||||
10689 | // Since i64 isn't legal and intrinsics don't get type-lowered, the ldrexd | ||||
10690 | // intrinsic must return {i32, i32} and we have to recombine them into a | ||||
10691 | // single i64 here. | ||||
10692 | if (ValTy->getPrimitiveSizeInBits() == 64) { | ||||
10693 | Intrinsic::ID Int = | ||||
10694 | IsAcquire ? Intrinsic::arm_ldaexd : Intrinsic::arm_ldrexd; | ||||
10695 | Function *Ldrex = llvm::Intrinsic::getDeclaration(M, Int); | ||||
10696 | |||||
10697 | Addr = Builder.CreateBitCast(Addr, Type::getInt8PtrTy(M->getContext())); | ||||
10698 | Value *LoHi = Builder.CreateCall(Ldrex, Addr, "lohi"); | ||||
10699 | |||||
10700 | Value *Lo = Builder.CreateExtractValue(LoHi, 0, "lo"); | ||||
10701 | Value *Hi = Builder.CreateExtractValue(LoHi, 1, "hi"); | ||||
Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 10702 | if (!Subtarget->isLittle()) |
10703 | std::swap (Lo, Hi); | ||||
Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 10704 | Lo = Builder.CreateZExt(Lo, ValTy, "lo64"); |
10705 | Hi = Builder.CreateZExt(Hi, ValTy, "hi64"); | ||||
10706 | return Builder.CreateOr( | ||||
10707 | Lo, Builder.CreateShl(Hi, ConstantInt::get(ValTy, 32)), "val64"); | ||||
10708 | } | ||||
10709 | |||||
10710 | Type *Tys[] = { Addr->getType() }; | ||||
10711 | Intrinsic::ID Int = IsAcquire ? Intrinsic::arm_ldaex : Intrinsic::arm_ldrex; | ||||
10712 | Function *Ldrex = llvm::Intrinsic::getDeclaration(M, Int, Tys); | ||||
10713 | |||||
10714 | return Builder.CreateTruncOrBitCast( | ||||
10715 | Builder.CreateCall(Ldrex, Addr), | ||||
10716 | cast<PointerType>(Addr->getType())->getElementType()); | ||||
10717 | } | ||||
10718 | |||||
10719 | Value *ARMTargetLowering::emitStoreConditional(IRBuilder<> &Builder, Value *Val, | ||||
10720 | Value *Addr, | ||||
10721 | AtomicOrdering Ord) const { | ||||
10722 | Module *M = Builder.GetInsertBlock()->getParent()->getParent(); | ||||
10723 | bool IsRelease = | ||||
10724 | Ord == Release || Ord == AcquireRelease || Ord == SequentiallyConsistent; | ||||
10725 | |||||
10726 | // Since the intrinsics must have legal type, the i64 intrinsics take two | ||||
10727 | // parameters: "i32, i32". We must marshal Val into the appropriate form | ||||
10728 | // before the call. | ||||
10729 | if (Val->getType()->getPrimitiveSizeInBits() == 64) { | ||||
10730 | Intrinsic::ID Int = | ||||
10731 | IsRelease ? Intrinsic::arm_stlexd : Intrinsic::arm_strexd; | ||||
10732 | Function *Strex = Intrinsic::getDeclaration(M, Int); | ||||
10733 | Type *Int32Ty = Type::getInt32Ty(M->getContext()); | ||||
10734 | |||||
10735 | Value *Lo = Builder.CreateTrunc(Val, Int32Ty, "lo"); | ||||
10736 | Value *Hi = Builder.CreateTrunc(Builder.CreateLShr(Val, 32), Int32Ty, "hi"); | ||||
Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 10737 | if (!Subtarget->isLittle()) |
10738 | std::swap (Lo, Hi); | ||||
Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 10739 | Addr = Builder.CreateBitCast(Addr, Type::getInt8PtrTy(M->getContext())); |
10740 | return Builder.CreateCall3(Strex, Lo, Hi, Addr); | ||||
10741 | } | ||||
10742 | |||||
10743 | Intrinsic::ID Int = IsRelease ? Intrinsic::arm_stlex : Intrinsic::arm_strex; | ||||
10744 | Type *Tys[] = { Addr->getType() }; | ||||
10745 | Function *Strex = Intrinsic::getDeclaration(M, Int, Tys); | ||||
10746 | |||||
10747 | return Builder.CreateCall2( | ||||
10748 | Strex, Builder.CreateZExtOrBitCast( | ||||
10749 | Val, Strex->getFunctionType()->getParamType(0)), | ||||
10750 | Addr); | ||||
10751 | } | ||||
Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 10752 | |
10753 | enum HABaseType { | ||||
10754 | HA_UNKNOWN = 0, | ||||
10755 | HA_FLOAT, | ||||
10756 | HA_DOUBLE, | ||||
10757 | HA_VECT64, | ||||
10758 | HA_VECT128 | ||||
10759 | }; | ||||
10760 | |||||
10761 | static bool isHomogeneousAggregate(Type *Ty, HABaseType &Base, | ||||
10762 | uint64_t &Members) { | ||||
10763 | if (const StructType *ST = dyn_cast<StructType>(Ty)) { | ||||
10764 | for (unsigned i = 0; i < ST->getNumElements(); ++i) { | ||||
10765 | uint64_t SubMembers = 0; | ||||
10766 | if (!isHomogeneousAggregate(ST->getElementType(i), Base, SubMembers)) | ||||
10767 | return false; | ||||
10768 | Members += SubMembers; | ||||
10769 | } | ||||
10770 | } else if (const ArrayType *AT = dyn_cast<ArrayType>(Ty)) { | ||||
10771 | uint64_t SubMembers = 0; | ||||
10772 | if (!isHomogeneousAggregate(AT->getElementType(), Base, SubMembers)) | ||||
10773 | return false; | ||||
10774 | Members += SubMembers * AT->getNumElements(); | ||||
10775 | } else if (Ty->isFloatTy()) { | ||||
10776 | if (Base != HA_UNKNOWN && Base != HA_FLOAT) | ||||
10777 | return false; | ||||
10778 | Members = 1; | ||||
10779 | Base = HA_FLOAT; | ||||
10780 | } else if (Ty->isDoubleTy()) { | ||||
10781 | if (Base != HA_UNKNOWN && Base != HA_DOUBLE) | ||||
10782 | return false; | ||||
10783 | Members = 1; | ||||
10784 | Base = HA_DOUBLE; | ||||
10785 | } else if (const VectorType *VT = dyn_cast<VectorType>(Ty)) { | ||||
10786 | Members = 1; | ||||
10787 | switch (Base) { | ||||
10788 | case HA_FLOAT: | ||||
10789 | case HA_DOUBLE: | ||||
10790 | return false; | ||||
10791 | case HA_VECT64: | ||||
10792 | return VT->getBitWidth() == 64; | ||||
10793 | case HA_VECT128: | ||||
10794 | return VT->getBitWidth() == 128; | ||||
10795 | case HA_UNKNOWN: | ||||
10796 | switch (VT->getBitWidth()) { | ||||
10797 | case 64: | ||||
10798 | Base = HA_VECT64; | ||||
10799 | return true; | ||||
10800 | case 128: | ||||
10801 | Base = HA_VECT128; | ||||
10802 | return true; | ||||
10803 | default: | ||||
10804 | return false; | ||||
10805 | } | ||||
10806 | } | ||||
10807 | } | ||||
10808 | |||||
10809 | return (Members > 0 && Members <= 4); | ||||
10810 | } | ||||
10811 | |||||
10812 | /// \brief Return true if a type is an AAPCS-VFP homogeneous aggregate. | ||||
10813 | bool ARMTargetLowering::functionArgumentNeedsConsecutiveRegisters( | ||||
10814 | Type *Ty, CallingConv::ID CallConv, bool isVarArg) const { | ||||
10815 | if (getEffectiveCallingConv(CallConv, isVarArg) == | ||||
10816 | CallingConv::ARM_AAPCS_VFP) { | ||||
10817 | HABaseType Base = HA_UNKNOWN; | ||||
10818 | uint64_t Members = 0; | ||||
10819 | bool result = isHomogeneousAggregate(Ty, Base, Members); | ||||
10820 | DEBUG(dbgs() << "isHA: " << result << " "; Ty->dump(); dbgs() << "\n"); | ||||
10821 | return result; | ||||
10822 | } else { | ||||
10823 | return false; | ||||
10824 | } | ||||
10825 | } |