Evan Cheng | a8e2989 | 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 | 4ee451d | 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 | a8e2989 | 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 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 15 | #define DEBUG_TYPE "arm-isel" |
Craig Topper | c1f6f42 | 2012-03-17 07:33:42 +0000 | [diff] [blame] | 16 | #include "ARMISelLowering.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 17 | #include "ARM.h" |
Eric Christopher | 6f2ccef | 2010-09-10 22:42:06 +0000 | [diff] [blame] | 18 | #include "ARMCallingConv.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 19 | #include "ARMConstantPoolValue.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 20 | #include "ARMMachineFunctionInfo.h" |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 21 | #include "ARMPerfectShuffle.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 22 | #include "ARMSubtarget.h" |
| 23 | #include "ARMTargetMachine.h" |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 24 | #include "ARMTargetObjectFile.h" |
Evan Cheng | ee04a6d | 2011-07-20 23:34:39 +0000 | [diff] [blame] | 25 | #include "MCTargetDesc/ARMAddressingModes.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/Statistic.h" |
| 27 | #include "llvm/ADT/StringExtras.h" |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/CallingConvLower.h" |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/IntrinsicLowering.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 31 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 32 | #include "llvm/CodeGen/MachineFunction.h" |
| 33 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 34 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 35 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 36 | #include "llvm/CodeGen/SelectionDAG.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 37 | #include "llvm/IR/CallingConv.h" |
| 38 | #include "llvm/IR/Constants.h" |
| 39 | #include "llvm/IR/Function.h" |
| 40 | #include "llvm/IR/GlobalValue.h" |
| 41 | #include "llvm/IR/Instruction.h" |
| 42 | #include "llvm/IR/Instructions.h" |
| 43 | #include "llvm/IR/Intrinsics.h" |
| 44 | #include "llvm/IR/Type.h" |
Bill Wendling | 94a1c63 | 2010-03-09 02:46:12 +0000 | [diff] [blame] | 45 | #include "llvm/MC/MCSectionMachO.h" |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 46 | #include "llvm/Support/CommandLine.h" |
Torok Edwin | ab7c09b | 2009-07-08 18:01:40 +0000 | [diff] [blame] | 47 | #include "llvm/Support/ErrorHandling.h" |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 48 | #include "llvm/Support/MathExtras.h" |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 49 | #include "llvm/Support/raw_ostream.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 50 | #include "llvm/Target/TargetOptions.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 51 | using namespace llvm; |
| 52 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 53 | STATISTIC(NumTailCalls, "Number of tail calls"); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 54 | STATISTIC(NumMovwMovt, "Number of GAs materialized with movw + movt"); |
Manman Ren | 763a75d | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 55 | STATISTIC(NumLoopByVals, "Number of loops generated for byval arguments"); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 56 | |
Bob Wilson | 703af3a | 2010-08-13 22:43:33 +0000 | [diff] [blame] | 57 | // This option should go away when tail calls fully work. |
| 58 | static cl::opt<bool> |
| 59 | EnableARMTailCalls("arm-tail-calls", cl::Hidden, |
| 60 | cl::desc("Generate tail calls (TEMPORARY OPTION)."), |
| 61 | cl::init(false)); |
| 62 | |
Eric Christopher | 836c624 | 2010-12-15 23:47:29 +0000 | [diff] [blame] | 63 | cl::opt<bool> |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 64 | EnableARMLongCalls("arm-long-calls", cl::Hidden, |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 65 | cl::desc("Generate calls via indirect call instructions"), |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 66 | cl::init(false)); |
| 67 | |
Evan Cheng | 46df4eb | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 68 | static cl::opt<bool> |
| 69 | ARMInterworking("arm-interworking", cl::Hidden, |
| 70 | cl::desc("Enable / disable ARM interworking (for debugging only)"), |
| 71 | cl::init(true)); |
| 72 | |
Benjamin Kramer | 0861f57 | 2011-11-26 23:01:57 +0000 | [diff] [blame] | 73 | namespace { |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 74 | class ARMCCState : public CCState { |
| 75 | public: |
| 76 | ARMCCState(CallingConv::ID CC, bool isVarArg, MachineFunction &MF, |
| 77 | const TargetMachine &TM, SmallVector<CCValAssign, 16> &locs, |
| 78 | LLVMContext &C, ParmContext PC) |
| 79 | : CCState(CC, isVarArg, MF, TM, locs, C) { |
| 80 | assert(((PC == Call) || (PC == Prologue)) && |
| 81 | "ARMCCState users must specify whether their context is call" |
| 82 | "or prologue generation."); |
| 83 | CallOrPrologue = PC; |
| 84 | } |
| 85 | }; |
| 86 | } |
| 87 | |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 88 | // The APCS parameter registers. |
Craig Topper | c5eaae4 | 2012-03-11 07:57:25 +0000 | [diff] [blame] | 89 | static const uint16_t GPRArgRegs[] = { |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 90 | ARM::R0, ARM::R1, ARM::R2, ARM::R3 |
| 91 | }; |
| 92 | |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 93 | void ARMTargetLowering::addTypeForNEON(MVT VT, MVT PromotedLdStVT, |
| 94 | MVT PromotedBitwiseVT) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 95 | if (VT != PromotedLdStVT) { |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 96 | setOperationAction(ISD::LOAD, VT, Promote); |
| 97 | AddPromotedToType (ISD::LOAD, VT, PromotedLdStVT); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 98 | |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 99 | setOperationAction(ISD::STORE, VT, Promote); |
| 100 | AddPromotedToType (ISD::STORE, VT, PromotedLdStVT); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 103 | MVT ElemTy = VT.getVectorElementType(); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 104 | if (ElemTy != MVT::i64 && ElemTy != MVT::f64) |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 105 | setOperationAction(ISD::SETCC, VT, Custom); |
| 106 | setOperationAction(ISD::INSERT_VECTOR_ELT, VT, Custom); |
| 107 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, VT, Custom); |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 108 | if (ElemTy == MVT::i32) { |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 109 | setOperationAction(ISD::SINT_TO_FP, VT, Custom); |
| 110 | setOperationAction(ISD::UINT_TO_FP, VT, Custom); |
| 111 | setOperationAction(ISD::FP_TO_SINT, VT, Custom); |
| 112 | setOperationAction(ISD::FP_TO_UINT, VT, Custom); |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 113 | } else { |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 114 | setOperationAction(ISD::SINT_TO_FP, VT, Expand); |
| 115 | setOperationAction(ISD::UINT_TO_FP, VT, Expand); |
| 116 | setOperationAction(ISD::FP_TO_SINT, VT, Expand); |
| 117 | setOperationAction(ISD::FP_TO_UINT, VT, Expand); |
Bob Wilson | 0696fdf | 2009-09-16 20:20:44 +0000 | [diff] [blame] | 118 | } |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 119 | setOperationAction(ISD::BUILD_VECTOR, VT, Custom); |
| 120 | setOperationAction(ISD::VECTOR_SHUFFLE, VT, Custom); |
| 121 | setOperationAction(ISD::CONCAT_VECTORS, VT, Legal); |
| 122 | setOperationAction(ISD::EXTRACT_SUBVECTOR, VT, Legal); |
| 123 | setOperationAction(ISD::SELECT, VT, Expand); |
| 124 | setOperationAction(ISD::SELECT_CC, VT, Expand); |
Jim Grosbach | 4346fa9 | 2012-10-12 22:59:21 +0000 | [diff] [blame] | 125 | setOperationAction(ISD::VSELECT, VT, Expand); |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 126 | setOperationAction(ISD::SIGN_EXTEND_INREG, VT, Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 127 | if (VT.isInteger()) { |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 128 | setOperationAction(ISD::SHL, VT, Custom); |
| 129 | setOperationAction(ISD::SRA, VT, Custom); |
| 130 | setOperationAction(ISD::SRL, VT, Custom); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | // Promote all bit-wise operations. |
| 134 | if (VT.isInteger() && VT != PromotedBitwiseVT) { |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 135 | setOperationAction(ISD::AND, VT, Promote); |
| 136 | AddPromotedToType (ISD::AND, VT, PromotedBitwiseVT); |
| 137 | setOperationAction(ISD::OR, VT, Promote); |
| 138 | AddPromotedToType (ISD::OR, VT, PromotedBitwiseVT); |
| 139 | setOperationAction(ISD::XOR, VT, Promote); |
| 140 | AddPromotedToType (ISD::XOR, VT, PromotedBitwiseVT); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 141 | } |
Bob Wilson | 1633076 | 2009-09-16 00:17:28 +0000 | [diff] [blame] | 142 | |
| 143 | // Neon does not support vector divide/remainder operations. |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 144 | setOperationAction(ISD::SDIV, VT, Expand); |
| 145 | setOperationAction(ISD::UDIV, VT, Expand); |
| 146 | setOperationAction(ISD::FDIV, VT, Expand); |
| 147 | setOperationAction(ISD::SREM, VT, Expand); |
| 148 | setOperationAction(ISD::UREM, VT, Expand); |
| 149 | setOperationAction(ISD::FREM, VT, Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 152 | void ARMTargetLowering::addDRTypeForNEON(MVT VT) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 153 | addRegisterClass(VT, &ARM::DPRRegClass); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 154 | addTypeForNEON(VT, MVT::f64, MVT::v2i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Craig Topper | 0faf46c | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 157 | void ARMTargetLowering::addQRTypeForNEON(MVT VT) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 158 | addRegisterClass(VT, &ARM::QPRRegClass); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 159 | addTypeForNEON(VT, MVT::v2f64, MVT::v4i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 162 | static TargetLoweringObjectFile *createTLOF(TargetMachine &TM) { |
| 163 | if (TM.getSubtarget<ARMSubtarget>().isTargetDarwin()) |
Bill Wendling | 505ad8b | 2010-03-15 21:09:38 +0000 | [diff] [blame] | 164 | return new TargetLoweringObjectFileMachO(); |
Bill Wendling | 94a1c63 | 2010-03-09 02:46:12 +0000 | [diff] [blame] | 165 | |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 166 | return new ARMElfTargetObjectFile(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 167 | } |
| 168 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 169 | ARMTargetLowering::ARMTargetLowering(TargetMachine &TM) |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 170 | : TargetLowering(TM, createTLOF(TM)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 171 | Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
Evan Cheng | 3144687 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 172 | RegInfo = TM.getRegisterInfo(); |
Evan Cheng | 3ef1c87 | 2010-09-10 01:29:16 +0000 | [diff] [blame] | 173 | Itins = TM.getInstrItineraryData(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 174 | |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 175 | setBooleanVectorContents(ZeroOrNegativeOneBooleanContent); |
| 176 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 177 | if (Subtarget->isTargetDarwin()) { |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 178 | // Uses VFP for Thumb libfuncs if available. |
| 179 | if (Subtarget->isThumb() && Subtarget->hasVFP2()) { |
| 180 | // Single-precision floating-point arithmetic. |
| 181 | setLibcallName(RTLIB::ADD_F32, "__addsf3vfp"); |
| 182 | setLibcallName(RTLIB::SUB_F32, "__subsf3vfp"); |
| 183 | setLibcallName(RTLIB::MUL_F32, "__mulsf3vfp"); |
| 184 | setLibcallName(RTLIB::DIV_F32, "__divsf3vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 185 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 186 | // Double-precision floating-point arithmetic. |
| 187 | setLibcallName(RTLIB::ADD_F64, "__adddf3vfp"); |
| 188 | setLibcallName(RTLIB::SUB_F64, "__subdf3vfp"); |
| 189 | setLibcallName(RTLIB::MUL_F64, "__muldf3vfp"); |
| 190 | setLibcallName(RTLIB::DIV_F64, "__divdf3vfp"); |
Evan Cheng | 193f850 | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 191 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 192 | // Single-precision comparisons. |
| 193 | setLibcallName(RTLIB::OEQ_F32, "__eqsf2vfp"); |
| 194 | setLibcallName(RTLIB::UNE_F32, "__nesf2vfp"); |
| 195 | setLibcallName(RTLIB::OLT_F32, "__ltsf2vfp"); |
| 196 | setLibcallName(RTLIB::OLE_F32, "__lesf2vfp"); |
| 197 | setLibcallName(RTLIB::OGE_F32, "__gesf2vfp"); |
| 198 | setLibcallName(RTLIB::OGT_F32, "__gtsf2vfp"); |
| 199 | setLibcallName(RTLIB::UO_F32, "__unordsf2vfp"); |
| 200 | setLibcallName(RTLIB::O_F32, "__unordsf2vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 201 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 202 | setCmpLibcallCC(RTLIB::OEQ_F32, ISD::SETNE); |
| 203 | setCmpLibcallCC(RTLIB::UNE_F32, ISD::SETNE); |
| 204 | setCmpLibcallCC(RTLIB::OLT_F32, ISD::SETNE); |
| 205 | setCmpLibcallCC(RTLIB::OLE_F32, ISD::SETNE); |
| 206 | setCmpLibcallCC(RTLIB::OGE_F32, ISD::SETNE); |
| 207 | setCmpLibcallCC(RTLIB::OGT_F32, ISD::SETNE); |
| 208 | setCmpLibcallCC(RTLIB::UO_F32, ISD::SETNE); |
| 209 | setCmpLibcallCC(RTLIB::O_F32, ISD::SETEQ); |
Evan Cheng | 193f850 | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 210 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 211 | // Double-precision comparisons. |
| 212 | setLibcallName(RTLIB::OEQ_F64, "__eqdf2vfp"); |
| 213 | setLibcallName(RTLIB::UNE_F64, "__nedf2vfp"); |
| 214 | setLibcallName(RTLIB::OLT_F64, "__ltdf2vfp"); |
| 215 | setLibcallName(RTLIB::OLE_F64, "__ledf2vfp"); |
| 216 | setLibcallName(RTLIB::OGE_F64, "__gedf2vfp"); |
| 217 | setLibcallName(RTLIB::OGT_F64, "__gtdf2vfp"); |
| 218 | setLibcallName(RTLIB::UO_F64, "__unorddf2vfp"); |
| 219 | setLibcallName(RTLIB::O_F64, "__unorddf2vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 220 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 221 | setCmpLibcallCC(RTLIB::OEQ_F64, ISD::SETNE); |
| 222 | setCmpLibcallCC(RTLIB::UNE_F64, ISD::SETNE); |
| 223 | setCmpLibcallCC(RTLIB::OLT_F64, ISD::SETNE); |
| 224 | setCmpLibcallCC(RTLIB::OLE_F64, ISD::SETNE); |
| 225 | setCmpLibcallCC(RTLIB::OGE_F64, ISD::SETNE); |
| 226 | setCmpLibcallCC(RTLIB::OGT_F64, ISD::SETNE); |
| 227 | setCmpLibcallCC(RTLIB::UO_F64, ISD::SETNE); |
| 228 | setCmpLibcallCC(RTLIB::O_F64, ISD::SETEQ); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 229 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 230 | // Floating-point to integer conversions. |
| 231 | // i64 conversions are done via library routines even when generating VFP |
| 232 | // instructions, so use the same ones. |
| 233 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__fixdfsivfp"); |
| 234 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__fixunsdfsivfp"); |
| 235 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__fixsfsivfp"); |
| 236 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__fixunssfsivfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 237 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 238 | // Conversions between floating types. |
| 239 | setLibcallName(RTLIB::FPROUND_F64_F32, "__truncdfsf2vfp"); |
| 240 | setLibcallName(RTLIB::FPEXT_F32_F64, "__extendsfdf2vfp"); |
| 241 | |
| 242 | // Integer to floating-point conversions. |
| 243 | // i64 conversions are done via library routines even when generating VFP |
| 244 | // instructions, so use the same ones. |
Bob Wilson | 2a14c52 | 2009-03-20 23:16:43 +0000 | [diff] [blame] | 245 | // FIXME: There appears to be some naming inconsistency in ARM libgcc: |
| 246 | // e.g., __floatunsidf vs. __floatunssidfvfp. |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 247 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__floatsidfvfp"); |
| 248 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__floatunssidfvfp"); |
| 249 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__floatsisfvfp"); |
| 250 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__floatunssisfvfp"); |
| 251 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 252 | } |
| 253 | |
Bob Wilson | 2f95461 | 2009-05-22 17:38:41 +0000 | [diff] [blame] | 254 | // These libcalls are not available in 32-bit. |
| 255 | setLibcallName(RTLIB::SHL_I128, 0); |
| 256 | setLibcallName(RTLIB::SRL_I128, 0); |
| 257 | setLibcallName(RTLIB::SRA_I128, 0); |
| 258 | |
Evan Cheng | 0704327 | 2012-02-21 20:46:00 +0000 | [diff] [blame] | 259 | if (Subtarget->isAAPCS_ABI() && !Subtarget->isTargetDarwin()) { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 260 | // Double-precision floating-point arithmetic helper functions |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 261 | // RTABI chapter 4.1.2, Table 2 |
| 262 | setLibcallName(RTLIB::ADD_F64, "__aeabi_dadd"); |
| 263 | setLibcallName(RTLIB::DIV_F64, "__aeabi_ddiv"); |
| 264 | setLibcallName(RTLIB::MUL_F64, "__aeabi_dmul"); |
| 265 | setLibcallName(RTLIB::SUB_F64, "__aeabi_dsub"); |
| 266 | setLibcallCallingConv(RTLIB::ADD_F64, CallingConv::ARM_AAPCS); |
| 267 | setLibcallCallingConv(RTLIB::DIV_F64, CallingConv::ARM_AAPCS); |
| 268 | setLibcallCallingConv(RTLIB::MUL_F64, CallingConv::ARM_AAPCS); |
| 269 | setLibcallCallingConv(RTLIB::SUB_F64, CallingConv::ARM_AAPCS); |
| 270 | |
| 271 | // Double-precision floating-point comparison helper functions |
| 272 | // RTABI chapter 4.1.2, Table 3 |
| 273 | setLibcallName(RTLIB::OEQ_F64, "__aeabi_dcmpeq"); |
| 274 | setCmpLibcallCC(RTLIB::OEQ_F64, ISD::SETNE); |
| 275 | setLibcallName(RTLIB::UNE_F64, "__aeabi_dcmpeq"); |
| 276 | setCmpLibcallCC(RTLIB::UNE_F64, ISD::SETEQ); |
| 277 | setLibcallName(RTLIB::OLT_F64, "__aeabi_dcmplt"); |
| 278 | setCmpLibcallCC(RTLIB::OLT_F64, ISD::SETNE); |
| 279 | setLibcallName(RTLIB::OLE_F64, "__aeabi_dcmple"); |
| 280 | setCmpLibcallCC(RTLIB::OLE_F64, ISD::SETNE); |
| 281 | setLibcallName(RTLIB::OGE_F64, "__aeabi_dcmpge"); |
| 282 | setCmpLibcallCC(RTLIB::OGE_F64, ISD::SETNE); |
| 283 | setLibcallName(RTLIB::OGT_F64, "__aeabi_dcmpgt"); |
| 284 | setCmpLibcallCC(RTLIB::OGT_F64, ISD::SETNE); |
| 285 | setLibcallName(RTLIB::UO_F64, "__aeabi_dcmpun"); |
| 286 | setCmpLibcallCC(RTLIB::UO_F64, ISD::SETNE); |
| 287 | setLibcallName(RTLIB::O_F64, "__aeabi_dcmpun"); |
| 288 | setCmpLibcallCC(RTLIB::O_F64, ISD::SETEQ); |
| 289 | setLibcallCallingConv(RTLIB::OEQ_F64, CallingConv::ARM_AAPCS); |
| 290 | setLibcallCallingConv(RTLIB::UNE_F64, CallingConv::ARM_AAPCS); |
| 291 | setLibcallCallingConv(RTLIB::OLT_F64, CallingConv::ARM_AAPCS); |
| 292 | setLibcallCallingConv(RTLIB::OLE_F64, CallingConv::ARM_AAPCS); |
| 293 | setLibcallCallingConv(RTLIB::OGE_F64, CallingConv::ARM_AAPCS); |
| 294 | setLibcallCallingConv(RTLIB::OGT_F64, CallingConv::ARM_AAPCS); |
| 295 | setLibcallCallingConv(RTLIB::UO_F64, CallingConv::ARM_AAPCS); |
| 296 | setLibcallCallingConv(RTLIB::O_F64, CallingConv::ARM_AAPCS); |
| 297 | |
| 298 | // Single-precision floating-point arithmetic helper functions |
| 299 | // RTABI chapter 4.1.2, Table 4 |
| 300 | setLibcallName(RTLIB::ADD_F32, "__aeabi_fadd"); |
| 301 | setLibcallName(RTLIB::DIV_F32, "__aeabi_fdiv"); |
| 302 | setLibcallName(RTLIB::MUL_F32, "__aeabi_fmul"); |
| 303 | setLibcallName(RTLIB::SUB_F32, "__aeabi_fsub"); |
| 304 | setLibcallCallingConv(RTLIB::ADD_F32, CallingConv::ARM_AAPCS); |
| 305 | setLibcallCallingConv(RTLIB::DIV_F32, CallingConv::ARM_AAPCS); |
| 306 | setLibcallCallingConv(RTLIB::MUL_F32, CallingConv::ARM_AAPCS); |
| 307 | setLibcallCallingConv(RTLIB::SUB_F32, CallingConv::ARM_AAPCS); |
| 308 | |
| 309 | // Single-precision floating-point comparison helper functions |
| 310 | // RTABI chapter 4.1.2, Table 5 |
| 311 | setLibcallName(RTLIB::OEQ_F32, "__aeabi_fcmpeq"); |
| 312 | setCmpLibcallCC(RTLIB::OEQ_F32, ISD::SETNE); |
| 313 | setLibcallName(RTLIB::UNE_F32, "__aeabi_fcmpeq"); |
| 314 | setCmpLibcallCC(RTLIB::UNE_F32, ISD::SETEQ); |
| 315 | setLibcallName(RTLIB::OLT_F32, "__aeabi_fcmplt"); |
| 316 | setCmpLibcallCC(RTLIB::OLT_F32, ISD::SETNE); |
| 317 | setLibcallName(RTLIB::OLE_F32, "__aeabi_fcmple"); |
| 318 | setCmpLibcallCC(RTLIB::OLE_F32, ISD::SETNE); |
| 319 | setLibcallName(RTLIB::OGE_F32, "__aeabi_fcmpge"); |
| 320 | setCmpLibcallCC(RTLIB::OGE_F32, ISD::SETNE); |
| 321 | setLibcallName(RTLIB::OGT_F32, "__aeabi_fcmpgt"); |
| 322 | setCmpLibcallCC(RTLIB::OGT_F32, ISD::SETNE); |
| 323 | setLibcallName(RTLIB::UO_F32, "__aeabi_fcmpun"); |
| 324 | setCmpLibcallCC(RTLIB::UO_F32, ISD::SETNE); |
| 325 | setLibcallName(RTLIB::O_F32, "__aeabi_fcmpun"); |
| 326 | setCmpLibcallCC(RTLIB::O_F32, ISD::SETEQ); |
| 327 | setLibcallCallingConv(RTLIB::OEQ_F32, CallingConv::ARM_AAPCS); |
| 328 | setLibcallCallingConv(RTLIB::UNE_F32, CallingConv::ARM_AAPCS); |
| 329 | setLibcallCallingConv(RTLIB::OLT_F32, CallingConv::ARM_AAPCS); |
| 330 | setLibcallCallingConv(RTLIB::OLE_F32, CallingConv::ARM_AAPCS); |
| 331 | setLibcallCallingConv(RTLIB::OGE_F32, CallingConv::ARM_AAPCS); |
| 332 | setLibcallCallingConv(RTLIB::OGT_F32, CallingConv::ARM_AAPCS); |
| 333 | setLibcallCallingConv(RTLIB::UO_F32, CallingConv::ARM_AAPCS); |
| 334 | setLibcallCallingConv(RTLIB::O_F32, CallingConv::ARM_AAPCS); |
| 335 | |
| 336 | // Floating-point to integer conversions. |
| 337 | // RTABI chapter 4.1.2, Table 6 |
| 338 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__aeabi_d2iz"); |
| 339 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__aeabi_d2uiz"); |
| 340 | setLibcallName(RTLIB::FPTOSINT_F64_I64, "__aeabi_d2lz"); |
| 341 | setLibcallName(RTLIB::FPTOUINT_F64_I64, "__aeabi_d2ulz"); |
| 342 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__aeabi_f2iz"); |
| 343 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__aeabi_f2uiz"); |
| 344 | setLibcallName(RTLIB::FPTOSINT_F32_I64, "__aeabi_f2lz"); |
| 345 | setLibcallName(RTLIB::FPTOUINT_F32_I64, "__aeabi_f2ulz"); |
| 346 | setLibcallCallingConv(RTLIB::FPTOSINT_F64_I32, CallingConv::ARM_AAPCS); |
| 347 | setLibcallCallingConv(RTLIB::FPTOUINT_F64_I32, CallingConv::ARM_AAPCS); |
| 348 | setLibcallCallingConv(RTLIB::FPTOSINT_F64_I64, CallingConv::ARM_AAPCS); |
| 349 | setLibcallCallingConv(RTLIB::FPTOUINT_F64_I64, CallingConv::ARM_AAPCS); |
| 350 | setLibcallCallingConv(RTLIB::FPTOSINT_F32_I32, CallingConv::ARM_AAPCS); |
| 351 | setLibcallCallingConv(RTLIB::FPTOUINT_F32_I32, CallingConv::ARM_AAPCS); |
| 352 | setLibcallCallingConv(RTLIB::FPTOSINT_F32_I64, CallingConv::ARM_AAPCS); |
| 353 | setLibcallCallingConv(RTLIB::FPTOUINT_F32_I64, CallingConv::ARM_AAPCS); |
| 354 | |
| 355 | // Conversions between floating types. |
| 356 | // RTABI chapter 4.1.2, Table 7 |
| 357 | setLibcallName(RTLIB::FPROUND_F64_F32, "__aeabi_d2f"); |
| 358 | setLibcallName(RTLIB::FPEXT_F32_F64, "__aeabi_f2d"); |
| 359 | setLibcallCallingConv(RTLIB::FPROUND_F64_F32, CallingConv::ARM_AAPCS); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 360 | setLibcallCallingConv(RTLIB::FPEXT_F32_F64, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 361 | |
| 362 | // Integer to floating-point conversions. |
| 363 | // RTABI chapter 4.1.2, Table 8 |
| 364 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__aeabi_i2d"); |
| 365 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__aeabi_ui2d"); |
| 366 | setLibcallName(RTLIB::SINTTOFP_I64_F64, "__aeabi_l2d"); |
| 367 | setLibcallName(RTLIB::UINTTOFP_I64_F64, "__aeabi_ul2d"); |
| 368 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__aeabi_i2f"); |
| 369 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__aeabi_ui2f"); |
| 370 | setLibcallName(RTLIB::SINTTOFP_I64_F32, "__aeabi_l2f"); |
| 371 | setLibcallName(RTLIB::UINTTOFP_I64_F32, "__aeabi_ul2f"); |
| 372 | setLibcallCallingConv(RTLIB::SINTTOFP_I32_F64, CallingConv::ARM_AAPCS); |
| 373 | setLibcallCallingConv(RTLIB::UINTTOFP_I32_F64, CallingConv::ARM_AAPCS); |
| 374 | setLibcallCallingConv(RTLIB::SINTTOFP_I64_F64, CallingConv::ARM_AAPCS); |
| 375 | setLibcallCallingConv(RTLIB::UINTTOFP_I64_F64, CallingConv::ARM_AAPCS); |
| 376 | setLibcallCallingConv(RTLIB::SINTTOFP_I32_F32, CallingConv::ARM_AAPCS); |
| 377 | setLibcallCallingConv(RTLIB::UINTTOFP_I32_F32, CallingConv::ARM_AAPCS); |
| 378 | setLibcallCallingConv(RTLIB::SINTTOFP_I64_F32, CallingConv::ARM_AAPCS); |
| 379 | setLibcallCallingConv(RTLIB::UINTTOFP_I64_F32, CallingConv::ARM_AAPCS); |
| 380 | |
| 381 | // Long long helper functions |
| 382 | // RTABI chapter 4.2, Table 9 |
| 383 | setLibcallName(RTLIB::MUL_I64, "__aeabi_lmul"); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 384 | setLibcallName(RTLIB::SHL_I64, "__aeabi_llsl"); |
| 385 | setLibcallName(RTLIB::SRL_I64, "__aeabi_llsr"); |
| 386 | setLibcallName(RTLIB::SRA_I64, "__aeabi_lasr"); |
| 387 | setLibcallCallingConv(RTLIB::MUL_I64, CallingConv::ARM_AAPCS); |
| 388 | setLibcallCallingConv(RTLIB::SDIV_I64, CallingConv::ARM_AAPCS); |
| 389 | setLibcallCallingConv(RTLIB::UDIV_I64, CallingConv::ARM_AAPCS); |
| 390 | setLibcallCallingConv(RTLIB::SHL_I64, CallingConv::ARM_AAPCS); |
| 391 | setLibcallCallingConv(RTLIB::SRL_I64, CallingConv::ARM_AAPCS); |
| 392 | setLibcallCallingConv(RTLIB::SRA_I64, CallingConv::ARM_AAPCS); |
| 393 | |
| 394 | // Integer division functions |
| 395 | // RTABI chapter 4.3.1 |
| 396 | setLibcallName(RTLIB::SDIV_I8, "__aeabi_idiv"); |
| 397 | setLibcallName(RTLIB::SDIV_I16, "__aeabi_idiv"); |
| 398 | setLibcallName(RTLIB::SDIV_I32, "__aeabi_idiv"); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 399 | setLibcallName(RTLIB::SDIV_I64, "__aeabi_ldivmod"); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 400 | setLibcallName(RTLIB::UDIV_I8, "__aeabi_uidiv"); |
| 401 | setLibcallName(RTLIB::UDIV_I16, "__aeabi_uidiv"); |
| 402 | setLibcallName(RTLIB::UDIV_I32, "__aeabi_uidiv"); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 403 | setLibcallName(RTLIB::UDIV_I64, "__aeabi_uldivmod"); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 404 | setLibcallCallingConv(RTLIB::SDIV_I8, CallingConv::ARM_AAPCS); |
| 405 | setLibcallCallingConv(RTLIB::SDIV_I16, CallingConv::ARM_AAPCS); |
| 406 | setLibcallCallingConv(RTLIB::SDIV_I32, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 407 | setLibcallCallingConv(RTLIB::SDIV_I64, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 408 | setLibcallCallingConv(RTLIB::UDIV_I8, CallingConv::ARM_AAPCS); |
| 409 | setLibcallCallingConv(RTLIB::UDIV_I16, CallingConv::ARM_AAPCS); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 410 | setLibcallCallingConv(RTLIB::UDIV_I32, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 411 | setLibcallCallingConv(RTLIB::UDIV_I64, CallingConv::ARM_AAPCS); |
Renato Golin | 1ec11fb | 2011-05-22 21:41:23 +0000 | [diff] [blame] | 412 | |
| 413 | // Memory operations |
| 414 | // RTABI chapter 4.3.4 |
| 415 | setLibcallName(RTLIB::MEMCPY, "__aeabi_memcpy"); |
| 416 | setLibcallName(RTLIB::MEMMOVE, "__aeabi_memmove"); |
| 417 | setLibcallName(RTLIB::MEMSET, "__aeabi_memset"); |
Anton Korobeynikov | 6edd588 | 2012-01-29 09:11:50 +0000 | [diff] [blame] | 418 | setLibcallCallingConv(RTLIB::MEMCPY, CallingConv::ARM_AAPCS); |
| 419 | setLibcallCallingConv(RTLIB::MEMMOVE, CallingConv::ARM_AAPCS); |
| 420 | setLibcallCallingConv(RTLIB::MEMSET, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 72977a4 | 2009-08-14 20:10:52 +0000 | [diff] [blame] | 421 | } |
| 422 | |
Bob Wilson | 2fef457 | 2011-10-07 16:59:21 +0000 | [diff] [blame] | 423 | // Use divmod compiler-rt calls for iOS 5.0 and later. |
| 424 | if (Subtarget->getTargetTriple().getOS() == Triple::IOS && |
| 425 | !Subtarget->getTargetTriple().isOSVersionLT(5, 0)) { |
| 426 | setLibcallName(RTLIB::SDIVREM_I32, "__divmodsi4"); |
| 427 | setLibcallName(RTLIB::UDIVREM_I32, "__udivmodsi4"); |
| 428 | } |
| 429 | |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 430 | if (Subtarget->isThumb1Only()) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 431 | addRegisterClass(MVT::i32, &ARM::tGPRRegClass); |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 432 | else |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 433 | addRegisterClass(MVT::i32, &ARM::GPRRegClass); |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 434 | if (!TM.Options.UseSoftFloat && Subtarget->hasVFP2() && |
| 435 | !Subtarget->isThumb1Only()) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 436 | addRegisterClass(MVT::f32, &ARM::SPRRegClass); |
Jim Grosbach | fcba5e6 | 2010-08-11 15:44:15 +0000 | [diff] [blame] | 437 | if (!Subtarget->isFPOnlySP()) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 438 | addRegisterClass(MVT::f64, &ARM::DPRRegClass); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 439 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 440 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 441 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 442 | |
Eli Friedman | 9f1f26a | 2011-11-08 01:43:53 +0000 | [diff] [blame] | 443 | for (unsigned VT = (unsigned)MVT::FIRST_VECTOR_VALUETYPE; |
| 444 | VT <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++VT) { |
| 445 | for (unsigned InnerVT = (unsigned)MVT::FIRST_VECTOR_VALUETYPE; |
| 446 | InnerVT <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++InnerVT) |
| 447 | setTruncStoreAction((MVT::SimpleValueType)VT, |
| 448 | (MVT::SimpleValueType)InnerVT, Expand); |
| 449 | setLoadExtAction(ISD::SEXTLOAD, (MVT::SimpleValueType)VT, Expand); |
| 450 | setLoadExtAction(ISD::ZEXTLOAD, (MVT::SimpleValueType)VT, Expand); |
| 451 | setLoadExtAction(ISD::EXTLOAD, (MVT::SimpleValueType)VT, Expand); |
| 452 | } |
| 453 | |
Lang Hames | 45b5f88 | 2012-03-15 18:49:02 +0000 | [diff] [blame] | 454 | setOperationAction(ISD::ConstantFP, MVT::f32, Custom); |
| 455 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 456 | if (Subtarget->hasNEON()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 457 | addDRTypeForNEON(MVT::v2f32); |
| 458 | addDRTypeForNEON(MVT::v8i8); |
| 459 | addDRTypeForNEON(MVT::v4i16); |
| 460 | addDRTypeForNEON(MVT::v2i32); |
| 461 | addDRTypeForNEON(MVT::v1i64); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 462 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 463 | addQRTypeForNEON(MVT::v4f32); |
| 464 | addQRTypeForNEON(MVT::v2f64); |
| 465 | addQRTypeForNEON(MVT::v16i8); |
| 466 | addQRTypeForNEON(MVT::v8i16); |
| 467 | addQRTypeForNEON(MVT::v4i32); |
| 468 | addQRTypeForNEON(MVT::v2i64); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 469 | |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 470 | // v2f64 is legal so that QR subregs can be extracted as f64 elements, but |
| 471 | // neither Neon nor VFP support any arithmetic operations on it. |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 472 | // The same with v4f32. But keep in mind that vadd, vsub, vmul are natively |
| 473 | // supported for v4f32. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 474 | setOperationAction(ISD::FADD, MVT::v2f64, Expand); |
| 475 | setOperationAction(ISD::FSUB, MVT::v2f64, Expand); |
| 476 | setOperationAction(ISD::FMUL, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 477 | // FIXME: Code duplication: FDIV and FREM are expanded always, see |
| 478 | // ARMTargetLowering::addTypeForNEON method for details. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 479 | setOperationAction(ISD::FDIV, MVT::v2f64, Expand); |
| 480 | setOperationAction(ISD::FREM, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 481 | // FIXME: Create unittest. |
| 482 | // In another words, find a way when "copysign" appears in DAG with vector |
| 483 | // operands. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 484 | setOperationAction(ISD::FCOPYSIGN, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 485 | // FIXME: Code duplication: SETCC has custom operation action, see |
| 486 | // ARMTargetLowering::addTypeForNEON method for details. |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 487 | setOperationAction(ISD::SETCC, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 488 | // FIXME: Create unittest for FNEG and for FABS. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 489 | setOperationAction(ISD::FNEG, MVT::v2f64, Expand); |
| 490 | setOperationAction(ISD::FABS, MVT::v2f64, Expand); |
| 491 | setOperationAction(ISD::FSQRT, MVT::v2f64, Expand); |
| 492 | setOperationAction(ISD::FSIN, MVT::v2f64, Expand); |
| 493 | setOperationAction(ISD::FCOS, MVT::v2f64, Expand); |
| 494 | setOperationAction(ISD::FPOWI, MVT::v2f64, Expand); |
| 495 | setOperationAction(ISD::FPOW, MVT::v2f64, Expand); |
| 496 | setOperationAction(ISD::FLOG, MVT::v2f64, Expand); |
| 497 | setOperationAction(ISD::FLOG2, MVT::v2f64, Expand); |
| 498 | setOperationAction(ISD::FLOG10, MVT::v2f64, Expand); |
| 499 | setOperationAction(ISD::FEXP, MVT::v2f64, Expand); |
| 500 | setOperationAction(ISD::FEXP2, MVT::v2f64, Expand); |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 501 | // FIXME: Create unittest for FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR. |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 502 | setOperationAction(ISD::FCEIL, MVT::v2f64, Expand); |
| 503 | setOperationAction(ISD::FTRUNC, MVT::v2f64, Expand); |
| 504 | setOperationAction(ISD::FRINT, MVT::v2f64, Expand); |
| 505 | setOperationAction(ISD::FNEARBYINT, MVT::v2f64, Expand); |
| 506 | setOperationAction(ISD::FFLOOR, MVT::v2f64, Expand); |
Arnold Schwaighofer | 21c0aa7 | 2013-03-02 19:38:33 +0000 | [diff] [blame] | 507 | setOperationAction(ISD::FMA, MVT::v2f64, Expand); |
Lang Hames | c0a9f82 | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 508 | |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 509 | setOperationAction(ISD::FSQRT, MVT::v4f32, Expand); |
| 510 | setOperationAction(ISD::FSIN, MVT::v4f32, Expand); |
| 511 | setOperationAction(ISD::FCOS, MVT::v4f32, Expand); |
| 512 | setOperationAction(ISD::FPOWI, MVT::v4f32, Expand); |
| 513 | setOperationAction(ISD::FPOW, MVT::v4f32, Expand); |
| 514 | setOperationAction(ISD::FLOG, MVT::v4f32, Expand); |
| 515 | setOperationAction(ISD::FLOG2, MVT::v4f32, Expand); |
| 516 | setOperationAction(ISD::FLOG10, MVT::v4f32, Expand); |
| 517 | setOperationAction(ISD::FEXP, MVT::v4f32, Expand); |
| 518 | setOperationAction(ISD::FEXP2, MVT::v4f32, Expand); |
Craig Topper | 4901047 | 2012-11-15 06:51:10 +0000 | [diff] [blame] | 519 | setOperationAction(ISD::FCEIL, MVT::v4f32, Expand); |
| 520 | setOperationAction(ISD::FTRUNC, MVT::v4f32, Expand); |
| 521 | setOperationAction(ISD::FRINT, MVT::v4f32, Expand); |
| 522 | setOperationAction(ISD::FNEARBYINT, MVT::v4f32, Expand); |
Craig Topper | a1fb1d2 | 2012-09-08 04:58:43 +0000 | [diff] [blame] | 523 | setOperationAction(ISD::FFLOOR, MVT::v4f32, Expand); |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 524 | |
Arnold Schwaighofer | 21c0aa7 | 2013-03-02 19:38:33 +0000 | [diff] [blame] | 525 | // Mark v2f32 intrinsics. |
| 526 | setOperationAction(ISD::FSQRT, MVT::v2f32, Expand); |
| 527 | setOperationAction(ISD::FSIN, MVT::v2f32, Expand); |
| 528 | setOperationAction(ISD::FCOS, MVT::v2f32, Expand); |
| 529 | setOperationAction(ISD::FPOWI, MVT::v2f32, Expand); |
| 530 | setOperationAction(ISD::FPOW, MVT::v2f32, Expand); |
| 531 | setOperationAction(ISD::FLOG, MVT::v2f32, Expand); |
| 532 | setOperationAction(ISD::FLOG2, MVT::v2f32, Expand); |
| 533 | setOperationAction(ISD::FLOG10, MVT::v2f32, Expand); |
| 534 | setOperationAction(ISD::FEXP, MVT::v2f32, Expand); |
| 535 | setOperationAction(ISD::FEXP2, MVT::v2f32, Expand); |
| 536 | setOperationAction(ISD::FCEIL, MVT::v2f32, Expand); |
| 537 | setOperationAction(ISD::FTRUNC, MVT::v2f32, Expand); |
| 538 | setOperationAction(ISD::FRINT, MVT::v2f32, Expand); |
| 539 | setOperationAction(ISD::FNEARBYINT, MVT::v2f32, Expand); |
| 540 | setOperationAction(ISD::FFLOOR, MVT::v2f32, Expand); |
| 541 | |
Bob Wilson | 642b329 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 542 | // Neon does not support some operations on v1i64 and v2i64 types. |
| 543 | setOperationAction(ISD::MUL, MVT::v1i64, Expand); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 544 | // Custom handling for some quad-vector types to detect VMULL. |
| 545 | setOperationAction(ISD::MUL, MVT::v8i16, Custom); |
| 546 | setOperationAction(ISD::MUL, MVT::v4i32, Custom); |
| 547 | setOperationAction(ISD::MUL, MVT::v2i64, Custom); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 548 | // Custom handling for some vector types to avoid expensive expansions |
| 549 | setOperationAction(ISD::SDIV, MVT::v4i16, Custom); |
| 550 | setOperationAction(ISD::SDIV, MVT::v8i8, Custom); |
| 551 | setOperationAction(ISD::UDIV, MVT::v4i16, Custom); |
| 552 | setOperationAction(ISD::UDIV, MVT::v8i8, Custom); |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 553 | setOperationAction(ISD::SETCC, MVT::v1i64, Expand); |
| 554 | setOperationAction(ISD::SETCC, MVT::v2i64, Expand); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 555 | // Neon does not have single instruction SINT_TO_FP and UINT_TO_FP with |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 556 | // a destination type that is wider than the source, and nor does |
| 557 | // it have a FP_TO_[SU]INT instruction with a narrower destination than |
| 558 | // source. |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 559 | setOperationAction(ISD::SINT_TO_FP, MVT::v4i16, Custom); |
| 560 | setOperationAction(ISD::UINT_TO_FP, MVT::v4i16, Custom); |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 561 | setOperationAction(ISD::FP_TO_UINT, MVT::v4i16, Custom); |
| 562 | setOperationAction(ISD::FP_TO_SINT, MVT::v4i16, Custom); |
Bob Wilson | 642b329 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 563 | |
Eli Friedman | 846ce8e | 2012-11-15 22:44:27 +0000 | [diff] [blame] | 564 | setOperationAction(ISD::FP_ROUND, MVT::v2f32, Expand); |
Eli Friedman | 43147af | 2012-11-17 01:52:46 +0000 | [diff] [blame] | 565 | setOperationAction(ISD::FP_EXTEND, MVT::v2f64, Expand); |
Eli Friedman | 846ce8e | 2012-11-15 22:44:27 +0000 | [diff] [blame] | 566 | |
Renato Golin | 5ad5f59 | 2013-03-19 08:15:38 +0000 | [diff] [blame] | 567 | // Custom expand long extensions to vectors. |
| 568 | setOperationAction(ISD::SIGN_EXTEND, MVT::v8i32, Custom); |
| 569 | setOperationAction(ISD::ZERO_EXTEND, MVT::v8i32, Custom); |
| 570 | setOperationAction(ISD::SIGN_EXTEND, MVT::v4i64, Custom); |
| 571 | setOperationAction(ISD::ZERO_EXTEND, MVT::v4i64, Custom); |
| 572 | setOperationAction(ISD::SIGN_EXTEND, MVT::v16i32, Custom); |
| 573 | setOperationAction(ISD::ZERO_EXTEND, MVT::v16i32, Custom); |
| 574 | setOperationAction(ISD::SIGN_EXTEND, MVT::v8i64, Custom); |
| 575 | setOperationAction(ISD::ZERO_EXTEND, MVT::v8i64, Custom); |
| 576 | |
Evan Cheng | c8e7045 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 577 | // NEON does not have single instruction CTPOP for vectors with element |
| 578 | // types wider than 8-bits. However, custom lowering can leverage the |
| 579 | // v8i8/v16i8 vcnt instruction. |
| 580 | setOperationAction(ISD::CTPOP, MVT::v2i32, Custom); |
| 581 | setOperationAction(ISD::CTPOP, MVT::v4i32, Custom); |
| 582 | setOperationAction(ISD::CTPOP, MVT::v4i16, Custom); |
| 583 | setOperationAction(ISD::CTPOP, MVT::v8i16, Custom); |
| 584 | |
Jim Grosbach | b302a4e | 2013-02-27 21:31:12 +0000 | [diff] [blame] | 585 | // NEON only has FMA instructions as of VFP4. |
| 586 | if (!Subtarget->hasVFP4()) { |
| 587 | setOperationAction(ISD::FMA, MVT::v2f32, Expand); |
| 588 | setOperationAction(ISD::FMA, MVT::v4f32, Expand); |
| 589 | } |
| 590 | |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 591 | setTargetDAGCombine(ISD::INTRINSIC_VOID); |
| 592 | setTargetDAGCombine(ISD::INTRINSIC_W_CHAIN); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 593 | setTargetDAGCombine(ISD::INTRINSIC_WO_CHAIN); |
| 594 | setTargetDAGCombine(ISD::SHL); |
| 595 | setTargetDAGCombine(ISD::SRL); |
| 596 | setTargetDAGCombine(ISD::SRA); |
| 597 | setTargetDAGCombine(ISD::SIGN_EXTEND); |
| 598 | setTargetDAGCombine(ISD::ZERO_EXTEND); |
| 599 | setTargetDAGCombine(ISD::ANY_EXTEND); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 600 | setTargetDAGCombine(ISD::SELECT_CC); |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 601 | setTargetDAGCombine(ISD::BUILD_VECTOR); |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 602 | setTargetDAGCombine(ISD::VECTOR_SHUFFLE); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 603 | setTargetDAGCombine(ISD::INSERT_VECTOR_ELT); |
| 604 | setTargetDAGCombine(ISD::STORE); |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 605 | setTargetDAGCombine(ISD::FP_TO_SINT); |
| 606 | setTargetDAGCombine(ISD::FP_TO_UINT); |
| 607 | setTargetDAGCombine(ISD::FDIV); |
Nadav Rotem | 004a24b | 2011-10-15 20:03:12 +0000 | [diff] [blame] | 608 | |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 609 | // It is legal to extload from v4i8 to v4i16 or v4i32. |
| 610 | MVT Tys[6] = {MVT::v8i8, MVT::v4i8, MVT::v2i8, |
| 611 | MVT::v4i16, MVT::v2i16, |
| 612 | MVT::v2i32}; |
| 613 | for (unsigned i = 0; i < 6; ++i) { |
| 614 | setLoadExtAction(ISD::EXTLOAD, Tys[i], Legal); |
| 615 | setLoadExtAction(ISD::ZEXTLOAD, Tys[i], Legal); |
| 616 | setLoadExtAction(ISD::SEXTLOAD, Tys[i], Legal); |
| 617 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 618 | } |
| 619 | |
Arnold Schwaighofer | 67514e9 | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 620 | // ARM and Thumb2 support UMLAL/SMLAL. |
| 621 | if (!Subtarget->isThumb1Only()) |
| 622 | setTargetDAGCombine(ISD::ADDC); |
| 623 | |
| 624 | |
Evan Cheng | 9f8cbd1 | 2007-05-18 00:19:34 +0000 | [diff] [blame] | 625 | computeRegisterProperties(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 626 | |
| 627 | // ARM does not have f32 extending load. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 628 | setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 629 | |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 630 | // ARM does not have i1 sign extending load. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 631 | setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote); |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 632 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 633 | // ARM supports all 4 flavors of integer indexed load / store. |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 634 | if (!Subtarget->isThumb1Only()) { |
| 635 | for (unsigned im = (unsigned)ISD::PRE_INC; |
| 636 | im != (unsigned)ISD::LAST_INDEXED_MODE; ++im) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 637 | setIndexedLoadAction(im, MVT::i1, Legal); |
| 638 | setIndexedLoadAction(im, MVT::i8, Legal); |
| 639 | setIndexedLoadAction(im, MVT::i16, Legal); |
| 640 | setIndexedLoadAction(im, MVT::i32, Legal); |
| 641 | setIndexedStoreAction(im, MVT::i1, Legal); |
| 642 | setIndexedStoreAction(im, MVT::i8, Legal); |
| 643 | setIndexedStoreAction(im, MVT::i16, Legal); |
| 644 | setIndexedStoreAction(im, MVT::i32, Legal); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 645 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | // i64 operation support. |
Eric Christopher | 2cc4013 | 2011-04-19 18:49:19 +0000 | [diff] [blame] | 649 | setOperationAction(ISD::MUL, MVT::i64, Expand); |
| 650 | setOperationAction(ISD::MULHU, MVT::i32, Expand); |
Evan Cheng | 5b9fcd1 | 2009-07-07 01:17:28 +0000 | [diff] [blame] | 651 | if (Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 652 | setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand); |
| 653 | setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 654 | } |
Jim Grosbach | a760398 | 2011-07-01 21:12:19 +0000 | [diff] [blame] | 655 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6Ops() |
| 656 | || (Subtarget->isThumb2() && !Subtarget->hasThumb2DSP())) |
Eric Christopher | 2cc4013 | 2011-04-19 18:49:19 +0000 | [diff] [blame] | 657 | setOperationAction(ISD::MULHS, MVT::i32, Expand); |
| 658 | |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 659 | setOperationAction(ISD::SHL_PARTS, MVT::i32, Custom); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 660 | setOperationAction(ISD::SRA_PARTS, MVT::i32, Custom); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 661 | setOperationAction(ISD::SRL_PARTS, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 662 | setOperationAction(ISD::SRL, MVT::i64, Custom); |
| 663 | setOperationAction(ISD::SRA, MVT::i64, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 664 | |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 665 | if (!Subtarget->isThumb1Only()) { |
| 666 | // FIXME: We should do this for Thumb1 as well. |
| 667 | setOperationAction(ISD::ADDC, MVT::i32, Custom); |
| 668 | setOperationAction(ISD::ADDE, MVT::i32, Custom); |
| 669 | setOperationAction(ISD::SUBC, MVT::i32, Custom); |
| 670 | setOperationAction(ISD::SUBE, MVT::i32, Custom); |
| 671 | } |
| 672 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 673 | // ARM does not have ROTL. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 674 | setOperationAction(ISD::ROTL, MVT::i32, Expand); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 675 | setOperationAction(ISD::CTTZ, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 676 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
David Goodwin | 24062ac | 2009-06-26 20:47:43 +0000 | [diff] [blame] | 677 | if (!Subtarget->hasV5TOps() || Subtarget->isThumb1Only()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 678 | setOperationAction(ISD::CTLZ, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 679 | |
Chandler Carruth | 63974b2 | 2011-12-13 01:56:10 +0000 | [diff] [blame] | 680 | // These just redirect to CTTZ and CTLZ on ARM. |
| 681 | setOperationAction(ISD::CTTZ_ZERO_UNDEF , MVT::i32 , Expand); |
| 682 | setOperationAction(ISD::CTLZ_ZERO_UNDEF , MVT::i32 , Expand); |
| 683 | |
Tim Northover | 5a02fc4 | 2013-05-23 19:11:20 +0000 | [diff] [blame] | 684 | setOperationAction(ISD::READCYCLECOUNTER, MVT::i64, Custom); |
| 685 | |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 686 | // Only ARMv6 has BSWAP. |
| 687 | if (!Subtarget->hasV6Ops()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 688 | setOperationAction(ISD::BSWAP, MVT::i32, Expand); |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 689 | |
Bob Wilson | eb1641d | 2012-09-29 21:43:49 +0000 | [diff] [blame] | 690 | if (!(Subtarget->hasDivide() && Subtarget->isThumb2()) && |
| 691 | !(Subtarget->hasDivideInARMMode() && !Subtarget->isThumb())) { |
| 692 | // These are expanded into libcalls if the cpu doesn't have HW divider. |
Jim Grosbach | b1dc393 | 2010-05-05 20:44:35 +0000 | [diff] [blame] | 693 | setOperationAction(ISD::SDIV, MVT::i32, Expand); |
| 694 | setOperationAction(ISD::UDIV, MVT::i32, Expand); |
| 695 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 696 | setOperationAction(ISD::SREM, MVT::i32, Expand); |
| 697 | setOperationAction(ISD::UREM, MVT::i32, Expand); |
| 698 | setOperationAction(ISD::SDIVREM, MVT::i32, Expand); |
| 699 | setOperationAction(ISD::UDIVREM, MVT::i32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 700 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 701 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
| 702 | setOperationAction(ISD::ConstantPool, MVT::i32, Custom); |
| 703 | setOperationAction(ISD::GLOBAL_OFFSET_TABLE, MVT::i32, Custom); |
| 704 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 705 | setOperationAction(ISD::BlockAddress, MVT::i32, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 706 | |
Evan Cheng | 4da0c7c | 2011-04-08 21:37:21 +0000 | [diff] [blame] | 707 | setOperationAction(ISD::TRAP, MVT::Other, Legal); |
Evan Cheng | fb3611d | 2010-05-11 07:26:32 +0000 | [diff] [blame] | 708 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 709 | // Use the default implementation. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 710 | setOperationAction(ISD::VASTART, MVT::Other, Custom); |
| 711 | setOperationAction(ISD::VAARG, MVT::Other, Expand); |
| 712 | setOperationAction(ISD::VACOPY, MVT::Other, Expand); |
| 713 | setOperationAction(ISD::VAEND, MVT::Other, Expand); |
| 714 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
| 715 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
Bill Wendling | bdf9db6 | 2012-02-13 23:47:16 +0000 | [diff] [blame] | 716 | |
| 717 | if (!Subtarget->isTargetDarwin()) { |
| 718 | // Non-Darwin platforms may return values in these registers via the |
| 719 | // personality function. |
| 720 | setOperationAction(ISD::EHSELECTION, MVT::i32, Expand); |
| 721 | setOperationAction(ISD::EXCEPTIONADDR, MVT::i32, Expand); |
| 722 | setExceptionPointerRegister(ARM::R0); |
| 723 | setExceptionSelectorRegister(ARM::R1); |
| 724 | } |
Anton Korobeynikov | 5899a60 | 2011-01-24 22:38:45 +0000 | [diff] [blame] | 725 | |
Evan Cheng | 3a1588a | 2010-04-15 22:20:34 +0000 | [diff] [blame] | 726 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Expand); |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 727 | // ARMv6 Thumb1 (except for CPUs that support dmb / dsb) and earlier use |
| 728 | // the default expansion. |
Eli Friedman | 4db5aca | 2011-08-29 18:23:02 +0000 | [diff] [blame] | 729 | // FIXME: This should be checking for v6k, not just v6. |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 730 | if (Subtarget->hasDataBarrier() || |
Bob Wilson | 54f9256 | 2010-11-09 22:50:44 +0000 | [diff] [blame] | 731 | (Subtarget->hasV6Ops() && !Subtarget->isThumb())) { |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 732 | // membarrier needs custom lowering; the rest are legal and handled |
| 733 | // normally. |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 734 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Custom); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 735 | // Custom lowering for 64-bit ops |
| 736 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i64, Custom); |
| 737 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i64, Custom); |
| 738 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i64, Custom); |
| 739 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i64, Custom); |
| 740 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i64, Custom); |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 741 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i64, Custom); |
| 742 | setOperationAction(ISD::ATOMIC_LOAD_MIN, MVT::i64, Custom); |
| 743 | setOperationAction(ISD::ATOMIC_LOAD_MAX, MVT::i64, Custom); |
| 744 | setOperationAction(ISD::ATOMIC_LOAD_UMIN, MVT::i64, Custom); |
| 745 | setOperationAction(ISD::ATOMIC_LOAD_UMAX, MVT::i64, Custom); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 746 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i64, Custom); |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 747 | // Automatically insert fences (dmb ist) around ATOMIC_SWAP etc. |
| 748 | setInsertFencesForAtomic(true); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 749 | } else { |
| 750 | // Set them all for expansion, which will force libcalls. |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 751 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 752 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i32, Expand); |
Jim Grosbach | ef6eb9c | 2010-06-18 23:03:10 +0000 | [diff] [blame] | 753 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 754 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 755 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 756 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 757 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 758 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 759 | setOperationAction(ISD::ATOMIC_LOAD_NAND, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 760 | setOperationAction(ISD::ATOMIC_LOAD_MIN, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 761 | setOperationAction(ISD::ATOMIC_LOAD_MAX, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 762 | setOperationAction(ISD::ATOMIC_LOAD_UMIN, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 763 | setOperationAction(ISD::ATOMIC_LOAD_UMAX, MVT::i32, Expand); |
Eli Friedman | 7cc1566 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 764 | // Mark ATOMIC_LOAD and ATOMIC_STORE custom so we can handle the |
| 765 | // Unordered/Monotonic case. |
| 766 | setOperationAction(ISD::ATOMIC_LOAD, MVT::i32, Custom); |
| 767 | setOperationAction(ISD::ATOMIC_STORE, MVT::i32, Custom); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 768 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 769 | |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 770 | setOperationAction(ISD::PREFETCH, MVT::Other, Custom); |
Evan Cheng | bc7deb0 | 2010-11-03 05:14:24 +0000 | [diff] [blame] | 771 | |
Eli Friedman | a2c6f45 | 2010-06-26 04:36:50 +0000 | [diff] [blame] | 772 | // Requires SXTB/SXTH, available on v6 and up in both ARM and Thumb modes. |
| 773 | if (!Subtarget->hasV6Ops()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 774 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand); |
| 775 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 776 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 777 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 778 | |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 779 | if (!TM.Options.UseSoftFloat && Subtarget->hasVFP2() && |
| 780 | !Subtarget->isThumb1Only()) { |
Bob Wilson | cb9a6aa | 2010-01-19 22:56:26 +0000 | [diff] [blame] | 781 | // Turn f64->i64 into VMOVRRD, i64 -> f64 to VMOVDRR |
Sylvestre Ledru | 94c2271 | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 782 | // iff target supports vfp2. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 783 | setOperationAction(ISD::BITCAST, MVT::i64, Custom); |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 784 | setOperationAction(ISD::FLT_ROUNDS_, MVT::i32, Custom); |
| 785 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 786 | |
| 787 | // We want to custom lower some of our intrinsics. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 788 | setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); |
Jim Grosbach | e97f968 | 2010-07-07 00:07:57 +0000 | [diff] [blame] | 789 | if (Subtarget->isTargetDarwin()) { |
| 790 | setOperationAction(ISD::EH_SJLJ_SETJMP, MVT::i32, Custom); |
| 791 | setOperationAction(ISD::EH_SJLJ_LONGJMP, MVT::Other, Custom); |
John McCall | 5f8fd54 | 2011-05-29 19:50:32 +0000 | [diff] [blame] | 792 | setLibcallName(RTLIB::UNWIND_RESUME, "_Unwind_SjLj_Resume"); |
Jim Grosbach | e97f968 | 2010-07-07 00:07:57 +0000 | [diff] [blame] | 793 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 794 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 795 | setOperationAction(ISD::SETCC, MVT::i32, Expand); |
| 796 | setOperationAction(ISD::SETCC, MVT::f32, Expand); |
| 797 | setOperationAction(ISD::SETCC, MVT::f64, Expand); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 798 | setOperationAction(ISD::SELECT, MVT::i32, Custom); |
| 799 | setOperationAction(ISD::SELECT, MVT::f32, Custom); |
| 800 | setOperationAction(ISD::SELECT, MVT::f64, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 801 | setOperationAction(ISD::SELECT_CC, MVT::i32, Custom); |
| 802 | setOperationAction(ISD::SELECT_CC, MVT::f32, Custom); |
| 803 | setOperationAction(ISD::SELECT_CC, MVT::f64, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 804 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 805 | setOperationAction(ISD::BRCOND, MVT::Other, Expand); |
| 806 | setOperationAction(ISD::BR_CC, MVT::i32, Custom); |
| 807 | setOperationAction(ISD::BR_CC, MVT::f32, Custom); |
| 808 | setOperationAction(ISD::BR_CC, MVT::f64, Custom); |
| 809 | setOperationAction(ISD::BR_JT, MVT::Other, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 810 | |
Dan Gohman | f96e4de | 2007-10-11 23:21:31 +0000 | [diff] [blame] | 811 | // We don't support sin/cos/fmod/copysign/pow |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 812 | setOperationAction(ISD::FSIN, MVT::f64, Expand); |
| 813 | setOperationAction(ISD::FSIN, MVT::f32, Expand); |
| 814 | setOperationAction(ISD::FCOS, MVT::f32, Expand); |
| 815 | setOperationAction(ISD::FCOS, MVT::f64, Expand); |
Evan Cheng | 8688a58 | 2013-01-29 02:32:37 +0000 | [diff] [blame] | 816 | setOperationAction(ISD::FSINCOS, MVT::f64, Expand); |
| 817 | setOperationAction(ISD::FSINCOS, MVT::f32, Expand); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 818 | setOperationAction(ISD::FREM, MVT::f64, Expand); |
| 819 | setOperationAction(ISD::FREM, MVT::f32, Expand); |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 820 | if (!TM.Options.UseSoftFloat && Subtarget->hasVFP2() && |
| 821 | !Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 822 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Custom); |
| 823 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Custom); |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 824 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 825 | setOperationAction(ISD::FPOW, MVT::f64, Expand); |
| 826 | setOperationAction(ISD::FPOW, MVT::f32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 827 | |
Evan Cheng | 3aef2ff | 2012-04-10 21:40:28 +0000 | [diff] [blame] | 828 | if (!Subtarget->hasVFP4()) { |
| 829 | setOperationAction(ISD::FMA, MVT::f64, Expand); |
| 830 | setOperationAction(ISD::FMA, MVT::f32, Expand); |
| 831 | } |
Cameron Zwarich | 3339084 | 2011-07-08 21:39:21 +0000 | [diff] [blame] | 832 | |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 833 | // Various VFP goodness |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 834 | if (!TM.Options.UseSoftFloat && !Subtarget->isThumb1Only()) { |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 835 | // int <-> fp are custom expanded into bit_convert + ARMISD ops. |
| 836 | if (Subtarget->hasVFP2()) { |
| 837 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom); |
| 838 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Custom); |
| 839 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom); |
| 840 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); |
| 841 | } |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 842 | // Special handling for half-precision FP. |
Anton Korobeynikov | f0d5007 | 2010-03-18 22:35:37 +0000 | [diff] [blame] | 843 | if (!Subtarget->hasFP16()) { |
| 844 | setOperationAction(ISD::FP16_TO_FP32, MVT::f32, Expand); |
| 845 | setOperationAction(ISD::FP32_TO_FP16, MVT::i32, Expand); |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 846 | } |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 847 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 848 | |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 849 | // We have target-specific dag combine patterns for the following nodes: |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 850 | // ARMISD::VMOVRRD - No need to call setTargetDAGCombine |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 851 | setTargetDAGCombine(ISD::ADD); |
| 852 | setTargetDAGCombine(ISD::SUB); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 853 | setTargetDAGCombine(ISD::MUL); |
Jakob Stoklund Olesen | a7390fa | 2012-09-07 17:34:15 +0000 | [diff] [blame] | 854 | setTargetDAGCombine(ISD::AND); |
| 855 | setTargetDAGCombine(ISD::OR); |
| 856 | setTargetDAGCombine(ISD::XOR); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 857 | |
Evan Cheng | 5fb468a | 2012-02-23 02:58:19 +0000 | [diff] [blame] | 858 | if (Subtarget->hasV6Ops()) |
| 859 | setTargetDAGCombine(ISD::SRL); |
| 860 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 861 | setStackPointerRegisterToSaveRestore(ARM::SP); |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 862 | |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 863 | if (TM.Options.UseSoftFloat || Subtarget->isThumb1Only() || |
| 864 | !Subtarget->hasVFP2()) |
Evan Cheng | f7d87ee | 2010-05-21 00:43:17 +0000 | [diff] [blame] | 865 | setSchedulingPreference(Sched::RegPressure); |
| 866 | else |
| 867 | setSchedulingPreference(Sched::Hybrid); |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 868 | |
Evan Cheng | 0521928 | 2011-01-06 06:52:41 +0000 | [diff] [blame] | 869 | //// temporary - rewrite interface to use type |
Jim Grosbach | 3450f80 | 2013-02-20 21:13:59 +0000 | [diff] [blame] | 870 | MaxStoresPerMemset = 8; |
| 871 | MaxStoresPerMemsetOptSize = Subtarget->isTargetDarwin() ? 8 : 4; |
| 872 | MaxStoresPerMemcpy = 4; // For @llvm.memcpy -> sequence of stores |
| 873 | MaxStoresPerMemcpyOptSize = Subtarget->isTargetDarwin() ? 4 : 2; |
| 874 | MaxStoresPerMemmove = 4; // For @llvm.memmove -> sequence of stores |
| 875 | MaxStoresPerMemmoveOptSize = Subtarget->isTargetDarwin() ? 4 : 2; |
Evan Cheng | f679939 | 2010-06-26 01:52:05 +0000 | [diff] [blame] | 876 | |
Rafael Espindola | cbeeae2 | 2010-07-11 04:01:49 +0000 | [diff] [blame] | 877 | // On ARM arguments smaller than 4 bytes are extended, so all arguments |
| 878 | // are at least 4 bytes aligned. |
| 879 | setMinStackArgumentAlignment(4); |
| 880 | |
Benjamin Kramer | aaf723d | 2012-05-05 12:49:14 +0000 | [diff] [blame] | 881 | // Prefer likely predicted branches to selects on out-of-order cores. |
Jim Grosbach | 3450f80 | 2013-02-20 21:13:59 +0000 | [diff] [blame] | 882 | PredictableSelectIsExpensive = Subtarget->isLikeA9(); |
Benjamin Kramer | aaf723d | 2012-05-05 12:49:14 +0000 | [diff] [blame] | 883 | |
Eli Friedman | fc5d305 | 2011-05-06 20:34:06 +0000 | [diff] [blame] | 884 | setMinFunctionAlignment(Subtarget->isThumb() ? 1 : 2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 885 | } |
| 886 | |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 887 | // FIXME: It might make sense to define the representative register class as the |
| 888 | // nearest super-register that has a non-null superset. For example, DPR_VFP2 is |
| 889 | // a super-register of SPR, and DPR is a superset if DPR_VFP2. Consequently, |
| 890 | // SPR's representative would be DPR_VFP2. This should work well if register |
| 891 | // pressure tracking were modified such that a register use would increment the |
| 892 | // pressure of the register class's representative and all of it's super |
| 893 | // classes' representatives transitively. We have not implemented this because |
| 894 | // of the difficulty prior to coalescing of modeling operand register classes |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 895 | // due to the common occurrence of cross class copies and subregister insertions |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 896 | // and extractions. |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 897 | std::pair<const TargetRegisterClass*, uint8_t> |
Patrik Hagglund | 0340557 | 2012-12-19 11:30:36 +0000 | [diff] [blame] | 898 | ARMTargetLowering::findRepresentativeClass(MVT VT) const{ |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 899 | const TargetRegisterClass *RRC = 0; |
| 900 | uint8_t Cost = 1; |
Patrik Hagglund | 0340557 | 2012-12-19 11:30:36 +0000 | [diff] [blame] | 901 | switch (VT.SimpleTy) { |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 902 | default: |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 903 | return TargetLowering::findRepresentativeClass(VT); |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 904 | // Use DPR as representative register class for all floating point |
| 905 | // and vector types. Since there are 32 SPR registers and 32 DPR registers so |
| 906 | // the cost is 1 for both f32 and f64. |
| 907 | case MVT::f32: case MVT::f64: case MVT::v8i8: case MVT::v4i16: |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 908 | case MVT::v2i32: case MVT::v1i64: case MVT::v2f32: |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 909 | RRC = &ARM::DPRRegClass; |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 910 | // When NEON is used for SP, only half of the register file is available |
| 911 | // because operations that define both SP and DP results will be constrained |
| 912 | // to the VFP2 class (D0-D15). We currently model this constraint prior to |
| 913 | // coalescing by double-counting the SP regs. See the FIXME above. |
| 914 | if (Subtarget->useNEONForSinglePrecisionFP()) |
| 915 | Cost = 2; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 916 | break; |
| 917 | case MVT::v16i8: case MVT::v8i16: case MVT::v4i32: case MVT::v2i64: |
| 918 | case MVT::v4f32: case MVT::v2f64: |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 919 | RRC = &ARM::DPRRegClass; |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 920 | Cost = 2; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 921 | break; |
| 922 | case MVT::v4i64: |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 923 | RRC = &ARM::DPRRegClass; |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 924 | Cost = 4; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 925 | break; |
| 926 | case MVT::v8i64: |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 927 | RRC = &ARM::DPRRegClass; |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 928 | Cost = 8; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 929 | break; |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 930 | } |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 931 | return std::make_pair(RRC, Cost); |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 932 | } |
| 933 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 934 | const char *ARMTargetLowering::getTargetNodeName(unsigned Opcode) const { |
| 935 | switch (Opcode) { |
| 936 | default: return 0; |
| 937 | case ARMISD::Wrapper: return "ARMISD::Wrapper"; |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 938 | case ARMISD::WrapperDYN: return "ARMISD::WrapperDYN"; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 939 | case ARMISD::WrapperPIC: return "ARMISD::WrapperPIC"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 940 | case ARMISD::WrapperJT: return "ARMISD::WrapperJT"; |
| 941 | case ARMISD::CALL: return "ARMISD::CALL"; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 942 | case ARMISD::CALL_PRED: return "ARMISD::CALL_PRED"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 943 | case ARMISD::CALL_NOLINK: return "ARMISD::CALL_NOLINK"; |
| 944 | case ARMISD::tCALL: return "ARMISD::tCALL"; |
| 945 | case ARMISD::BRCOND: return "ARMISD::BRCOND"; |
| 946 | case ARMISD::BR_JT: return "ARMISD::BR_JT"; |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 947 | case ARMISD::BR2_JT: return "ARMISD::BR2_JT"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 948 | case ARMISD::RET_FLAG: return "ARMISD::RET_FLAG"; |
| 949 | case ARMISD::PIC_ADD: return "ARMISD::PIC_ADD"; |
| 950 | case ARMISD::CMP: return "ARMISD::CMP"; |
Bill Wendling | ad5c880 | 2012-06-11 08:07:26 +0000 | [diff] [blame] | 951 | case ARMISD::CMN: return "ARMISD::CMN"; |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 952 | case ARMISD::CMPZ: return "ARMISD::CMPZ"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 953 | case ARMISD::CMPFP: return "ARMISD::CMPFP"; |
| 954 | case ARMISD::CMPFPw0: return "ARMISD::CMPFPw0"; |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 955 | case ARMISD::BCC_i64: return "ARMISD::BCC_i64"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 956 | case ARMISD::FMSTAT: return "ARMISD::FMSTAT"; |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 957 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 958 | case ARMISD::CMOV: return "ARMISD::CMOV"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 959 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 960 | case ARMISD::RBIT: return "ARMISD::RBIT"; |
| 961 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 962 | case ARMISD::FTOSI: return "ARMISD::FTOSI"; |
| 963 | case ARMISD::FTOUI: return "ARMISD::FTOUI"; |
| 964 | case ARMISD::SITOF: return "ARMISD::SITOF"; |
| 965 | case ARMISD::UITOF: return "ARMISD::UITOF"; |
| 966 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 967 | case ARMISD::SRL_FLAG: return "ARMISD::SRL_FLAG"; |
| 968 | case ARMISD::SRA_FLAG: return "ARMISD::SRA_FLAG"; |
| 969 | case ARMISD::RRX: return "ARMISD::RRX"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 970 | |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 971 | case ARMISD::ADDC: return "ARMISD::ADDC"; |
| 972 | case ARMISD::ADDE: return "ARMISD::ADDE"; |
| 973 | case ARMISD::SUBC: return "ARMISD::SUBC"; |
| 974 | case ARMISD::SUBE: return "ARMISD::SUBE"; |
| 975 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 976 | case ARMISD::VMOVRRD: return "ARMISD::VMOVRRD"; |
| 977 | case ARMISD::VMOVDRR: return "ARMISD::VMOVDRR"; |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 978 | |
Evan Cheng | c594208 | 2009-10-28 06:55:03 +0000 | [diff] [blame] | 979 | case ARMISD::EH_SJLJ_SETJMP: return "ARMISD::EH_SJLJ_SETJMP"; |
| 980 | case ARMISD::EH_SJLJ_LONGJMP:return "ARMISD::EH_SJLJ_LONGJMP"; |
| 981 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 982 | case ARMISD::TC_RETURN: return "ARMISD::TC_RETURN"; |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 983 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 984 | case ARMISD::THREAD_POINTER:return "ARMISD::THREAD_POINTER"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 985 | |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 986 | case ARMISD::DYN_ALLOC: return "ARMISD::DYN_ALLOC"; |
| 987 | |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 988 | case ARMISD::MEMBARRIER: return "ARMISD::MEMBARRIER"; |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 989 | case ARMISD::MEMBARRIER_MCR: return "ARMISD::MEMBARRIER_MCR"; |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 990 | |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 991 | case ARMISD::PRELOAD: return "ARMISD::PRELOAD"; |
| 992 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 993 | case ARMISD::VCEQ: return "ARMISD::VCEQ"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 994 | case ARMISD::VCEQZ: return "ARMISD::VCEQZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 995 | case ARMISD::VCGE: return "ARMISD::VCGE"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 996 | case ARMISD::VCGEZ: return "ARMISD::VCGEZ"; |
| 997 | case ARMISD::VCLEZ: return "ARMISD::VCLEZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 998 | case ARMISD::VCGEU: return "ARMISD::VCGEU"; |
| 999 | case ARMISD::VCGT: return "ARMISD::VCGT"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 1000 | case ARMISD::VCGTZ: return "ARMISD::VCGTZ"; |
| 1001 | case ARMISD::VCLTZ: return "ARMISD::VCLTZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1002 | case ARMISD::VCGTU: return "ARMISD::VCGTU"; |
| 1003 | case ARMISD::VTST: return "ARMISD::VTST"; |
| 1004 | |
| 1005 | case ARMISD::VSHL: return "ARMISD::VSHL"; |
| 1006 | case ARMISD::VSHRs: return "ARMISD::VSHRs"; |
| 1007 | case ARMISD::VSHRu: return "ARMISD::VSHRu"; |
| 1008 | case ARMISD::VSHLLs: return "ARMISD::VSHLLs"; |
| 1009 | case ARMISD::VSHLLu: return "ARMISD::VSHLLu"; |
| 1010 | case ARMISD::VSHLLi: return "ARMISD::VSHLLi"; |
| 1011 | case ARMISD::VSHRN: return "ARMISD::VSHRN"; |
| 1012 | case ARMISD::VRSHRs: return "ARMISD::VRSHRs"; |
| 1013 | case ARMISD::VRSHRu: return "ARMISD::VRSHRu"; |
| 1014 | case ARMISD::VRSHRN: return "ARMISD::VRSHRN"; |
| 1015 | case ARMISD::VQSHLs: return "ARMISD::VQSHLs"; |
| 1016 | case ARMISD::VQSHLu: return "ARMISD::VQSHLu"; |
| 1017 | case ARMISD::VQSHLsu: return "ARMISD::VQSHLsu"; |
| 1018 | case ARMISD::VQSHRNs: return "ARMISD::VQSHRNs"; |
| 1019 | case ARMISD::VQSHRNu: return "ARMISD::VQSHRNu"; |
| 1020 | case ARMISD::VQSHRNsu: return "ARMISD::VQSHRNsu"; |
| 1021 | case ARMISD::VQRSHRNs: return "ARMISD::VQRSHRNs"; |
| 1022 | case ARMISD::VQRSHRNu: return "ARMISD::VQRSHRNu"; |
| 1023 | case ARMISD::VQRSHRNsu: return "ARMISD::VQRSHRNsu"; |
| 1024 | case ARMISD::VGETLANEu: return "ARMISD::VGETLANEu"; |
| 1025 | case ARMISD::VGETLANEs: return "ARMISD::VGETLANEs"; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 1026 | case ARMISD::VMOVIMM: return "ARMISD::VMOVIMM"; |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 1027 | case ARMISD::VMVNIMM: return "ARMISD::VMVNIMM"; |
Evan Cheng | eaa192a | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 1028 | case ARMISD::VMOVFPIMM: return "ARMISD::VMOVFPIMM"; |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 1029 | case ARMISD::VDUP: return "ARMISD::VDUP"; |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 1030 | case ARMISD::VDUPLANE: return "ARMISD::VDUPLANE"; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 1031 | case ARMISD::VEXT: return "ARMISD::VEXT"; |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 1032 | case ARMISD::VREV64: return "ARMISD::VREV64"; |
| 1033 | case ARMISD::VREV32: return "ARMISD::VREV32"; |
| 1034 | case ARMISD::VREV16: return "ARMISD::VREV16"; |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 1035 | case ARMISD::VZIP: return "ARMISD::VZIP"; |
| 1036 | case ARMISD::VUZP: return "ARMISD::VUZP"; |
| 1037 | case ARMISD::VTRN: return "ARMISD::VTRN"; |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 1038 | case ARMISD::VTBL1: return "ARMISD::VTBL1"; |
| 1039 | case ARMISD::VTBL2: return "ARMISD::VTBL2"; |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 1040 | case ARMISD::VMULLs: return "ARMISD::VMULLs"; |
| 1041 | case ARMISD::VMULLu: return "ARMISD::VMULLu"; |
Arnold Schwaighofer | 67514e9 | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 1042 | case ARMISD::UMLAL: return "ARMISD::UMLAL"; |
| 1043 | case ARMISD::SMLAL: return "ARMISD::SMLAL"; |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 1044 | case ARMISD::BUILD_VECTOR: return "ARMISD::BUILD_VECTOR"; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 1045 | case ARMISD::FMAX: return "ARMISD::FMAX"; |
| 1046 | case ARMISD::FMIN: return "ARMISD::FMIN"; |
Jim Grosbach | dd7d28a | 2010-07-17 01:50:57 +0000 | [diff] [blame] | 1047 | case ARMISD::BFI: return "ARMISD::BFI"; |
Bob Wilson | 364a72a | 2010-11-28 06:51:11 +0000 | [diff] [blame] | 1048 | case ARMISD::VORRIMM: return "ARMISD::VORRIMM"; |
| 1049 | case ARMISD::VBICIMM: return "ARMISD::VBICIMM"; |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 1050 | case ARMISD::VBSL: return "ARMISD::VBSL"; |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 1051 | case ARMISD::VLD2DUP: return "ARMISD::VLD2DUP"; |
| 1052 | case ARMISD::VLD3DUP: return "ARMISD::VLD3DUP"; |
| 1053 | case ARMISD::VLD4DUP: return "ARMISD::VLD4DUP"; |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 1054 | case ARMISD::VLD1_UPD: return "ARMISD::VLD1_UPD"; |
| 1055 | case ARMISD::VLD2_UPD: return "ARMISD::VLD2_UPD"; |
| 1056 | case ARMISD::VLD3_UPD: return "ARMISD::VLD3_UPD"; |
| 1057 | case ARMISD::VLD4_UPD: return "ARMISD::VLD4_UPD"; |
| 1058 | case ARMISD::VLD2LN_UPD: return "ARMISD::VLD2LN_UPD"; |
| 1059 | case ARMISD::VLD3LN_UPD: return "ARMISD::VLD3LN_UPD"; |
| 1060 | case ARMISD::VLD4LN_UPD: return "ARMISD::VLD4LN_UPD"; |
| 1061 | case ARMISD::VLD2DUP_UPD: return "ARMISD::VLD2DUP_UPD"; |
| 1062 | case ARMISD::VLD3DUP_UPD: return "ARMISD::VLD3DUP_UPD"; |
| 1063 | case ARMISD::VLD4DUP_UPD: return "ARMISD::VLD4DUP_UPD"; |
| 1064 | case ARMISD::VST1_UPD: return "ARMISD::VST1_UPD"; |
| 1065 | case ARMISD::VST2_UPD: return "ARMISD::VST2_UPD"; |
| 1066 | case ARMISD::VST3_UPD: return "ARMISD::VST3_UPD"; |
| 1067 | case ARMISD::VST4_UPD: return "ARMISD::VST4_UPD"; |
| 1068 | case ARMISD::VST2LN_UPD: return "ARMISD::VST2LN_UPD"; |
| 1069 | case ARMISD::VST3LN_UPD: return "ARMISD::VST3LN_UPD"; |
| 1070 | case ARMISD::VST4LN_UPD: return "ARMISD::VST4LN_UPD"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1071 | } |
| 1072 | } |
| 1073 | |
Matt Arsenault | 225ed70 | 2013-05-18 00:21:46 +0000 | [diff] [blame] | 1074 | EVT ARMTargetLowering::getSetCCResultType(LLVMContext &, EVT VT) const { |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 1075 | if (!VT.isVector()) return getPointerTy(); |
| 1076 | return VT.changeVectorElementTypeToInteger(); |
| 1077 | } |
| 1078 | |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1079 | /// getRegClassFor - Return the register class that should be used for the |
| 1080 | /// specified value type. |
Patrik Hagglund | a61b17c | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 1081 | const TargetRegisterClass *ARMTargetLowering::getRegClassFor(MVT VT) const { |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1082 | // Map v4i64 to QQ registers but do not make the type legal. Similarly map |
| 1083 | // v8i64 to QQQQ registers. v4i64 and v8i64 are only used for REG_SEQUENCE to |
| 1084 | // load / store 4 to 8 consecutive D registers. |
Evan Cheng | 4782b1e | 2010-05-15 02:20:21 +0000 | [diff] [blame] | 1085 | if (Subtarget->hasNEON()) { |
| 1086 | if (VT == MVT::v4i64) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1087 | return &ARM::QQPRRegClass; |
| 1088 | if (VT == MVT::v8i64) |
| 1089 | return &ARM::QQQQPRRegClass; |
Evan Cheng | 4782b1e | 2010-05-15 02:20:21 +0000 | [diff] [blame] | 1090 | } |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1091 | return TargetLowering::getRegClassFor(VT); |
| 1092 | } |
| 1093 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1094 | // Create a fast isel object. |
| 1095 | FastISel * |
Bob Wilson | d49edb7 | 2012-08-03 04:06:28 +0000 | [diff] [blame] | 1096 | ARMTargetLowering::createFastISel(FunctionLoweringInfo &funcInfo, |
| 1097 | const TargetLibraryInfo *libInfo) const { |
| 1098 | return ARM::createFastISel(funcInfo, libInfo); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1099 | } |
| 1100 | |
Anton Korobeynikov | cec36f4 | 2010-07-24 21:52:08 +0000 | [diff] [blame] | 1101 | /// getMaximalGlobalOffset - Returns the maximal possible offset which can |
| 1102 | /// be used for loads / stores from the global. |
| 1103 | unsigned ARMTargetLowering::getMaximalGlobalOffset() const { |
| 1104 | return (Subtarget->isThumb1Only() ? 127 : 4095); |
| 1105 | } |
| 1106 | |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1107 | Sched::Preference ARMTargetLowering::getSchedulingPreference(SDNode *N) const { |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1108 | unsigned NumVals = N->getNumValues(); |
| 1109 | if (!NumVals) |
| 1110 | return Sched::RegPressure; |
| 1111 | |
| 1112 | for (unsigned i = 0; i != NumVals; ++i) { |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1113 | EVT VT = N->getValueType(i); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1114 | if (VT == MVT::Glue || VT == MVT::Other) |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1115 | continue; |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1116 | if (VT.isFloatingPoint() || VT.isVector()) |
Dan Gohman | 692c1d8 | 2011-10-24 17:55:11 +0000 | [diff] [blame] | 1117 | return Sched::ILP; |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1118 | } |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1119 | |
| 1120 | if (!N->isMachineOpcode()) |
| 1121 | return Sched::RegPressure; |
| 1122 | |
| 1123 | // Load are scheduled for latency even if there instruction itinerary |
| 1124 | // is not available. |
| 1125 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1126 | const MCInstrDesc &MCID = TII->get(N->getMachineOpcode()); |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1127 | |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1128 | if (MCID.getNumDefs() == 0) |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1129 | return Sched::RegPressure; |
| 1130 | if (!Itins->isEmpty() && |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1131 | Itins->getOperandCycle(MCID.getSchedClass(), 0) > 2) |
Dan Gohman | 692c1d8 | 2011-10-24 17:55:11 +0000 | [diff] [blame] | 1132 | return Sched::ILP; |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1133 | |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1134 | return Sched::RegPressure; |
| 1135 | } |
| 1136 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1137 | //===----------------------------------------------------------------------===// |
| 1138 | // Lowering Code |
| 1139 | //===----------------------------------------------------------------------===// |
| 1140 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1141 | /// IntCCToARMCC - Convert a DAG integer condition code to an ARM CC |
| 1142 | static ARMCC::CondCodes IntCCToARMCC(ISD::CondCode CC) { |
| 1143 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1144 | default: llvm_unreachable("Unknown condition code!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1145 | case ISD::SETNE: return ARMCC::NE; |
| 1146 | case ISD::SETEQ: return ARMCC::EQ; |
| 1147 | case ISD::SETGT: return ARMCC::GT; |
| 1148 | case ISD::SETGE: return ARMCC::GE; |
| 1149 | case ISD::SETLT: return ARMCC::LT; |
| 1150 | case ISD::SETLE: return ARMCC::LE; |
| 1151 | case ISD::SETUGT: return ARMCC::HI; |
| 1152 | case ISD::SETUGE: return ARMCC::HS; |
| 1153 | case ISD::SETULT: return ARMCC::LO; |
| 1154 | case ISD::SETULE: return ARMCC::LS; |
| 1155 | } |
| 1156 | } |
| 1157 | |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 1158 | /// FPCCToARMCC - Convert a DAG fp condition code to an ARM CC. |
| 1159 | static void FPCCToARMCC(ISD::CondCode CC, ARMCC::CondCodes &CondCode, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1160 | ARMCC::CondCodes &CondCode2) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1161 | CondCode2 = ARMCC::AL; |
| 1162 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1163 | default: llvm_unreachable("Unknown FP condition!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1164 | case ISD::SETEQ: |
| 1165 | case ISD::SETOEQ: CondCode = ARMCC::EQ; break; |
| 1166 | case ISD::SETGT: |
| 1167 | case ISD::SETOGT: CondCode = ARMCC::GT; break; |
| 1168 | case ISD::SETGE: |
| 1169 | case ISD::SETOGE: CondCode = ARMCC::GE; break; |
| 1170 | case ISD::SETOLT: CondCode = ARMCC::MI; break; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 1171 | case ISD::SETOLE: CondCode = ARMCC::LS; break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1172 | case ISD::SETONE: CondCode = ARMCC::MI; CondCode2 = ARMCC::GT; break; |
| 1173 | case ISD::SETO: CondCode = ARMCC::VC; break; |
| 1174 | case ISD::SETUO: CondCode = ARMCC::VS; break; |
| 1175 | case ISD::SETUEQ: CondCode = ARMCC::EQ; CondCode2 = ARMCC::VS; break; |
| 1176 | case ISD::SETUGT: CondCode = ARMCC::HI; break; |
| 1177 | case ISD::SETUGE: CondCode = ARMCC::PL; break; |
| 1178 | case ISD::SETLT: |
| 1179 | case ISD::SETULT: CondCode = ARMCC::LT; break; |
| 1180 | case ISD::SETLE: |
| 1181 | case ISD::SETULE: CondCode = ARMCC::LE; break; |
| 1182 | case ISD::SETNE: |
| 1183 | case ISD::SETUNE: CondCode = ARMCC::NE; break; |
| 1184 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1185 | } |
| 1186 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1187 | //===----------------------------------------------------------------------===// |
| 1188 | // Calling Convention Implementation |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1189 | //===----------------------------------------------------------------------===// |
| 1190 | |
| 1191 | #include "ARMGenCallingConv.inc" |
| 1192 | |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1193 | /// CCAssignFnForNode - Selects the correct CCAssignFn for a the |
| 1194 | /// given CallingConvention value. |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1195 | CCAssignFn *ARMTargetLowering::CCAssignFnForNode(CallingConv::ID CC, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1196 | bool Return, |
| 1197 | bool isVarArg) const { |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1198 | switch (CC) { |
| 1199 | default: |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1200 | llvm_unreachable("Unsupported calling convention"); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1201 | case CallingConv::Fast: |
Evan Cheng | 5c2d428 | 2010-10-23 02:19:37 +0000 | [diff] [blame] | 1202 | if (Subtarget->hasVFP2() && !isVarArg) { |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1203 | if (!Subtarget->isAAPCS_ABI()) |
| 1204 | return (Return ? RetFastCC_ARM_APCS : FastCC_ARM_APCS); |
| 1205 | // For AAPCS ABI targets, just use VFP variant of the calling convention. |
| 1206 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1207 | } |
| 1208 | // Fallthrough |
| 1209 | case CallingConv::C: { |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1210 | // Use target triple & subtarget features to do actual dispatch. |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1211 | if (!Subtarget->isAAPCS_ABI()) |
| 1212 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS); |
| 1213 | else if (Subtarget->hasVFP2() && |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 1214 | getTargetMachine().Options.FloatABIType == FloatABI::Hard && |
| 1215 | !isVarArg) |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1216 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1217 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); |
| 1218 | } |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1219 | case CallingConv::ARM_AAPCS_VFP: |
Anton Korobeynikov | f349cb8 | 2012-01-29 09:06:09 +0000 | [diff] [blame] | 1220 | if (!isVarArg) |
| 1221 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1222 | // Fallthrough |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1223 | case CallingConv::ARM_AAPCS: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1224 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1225 | case CallingConv::ARM_APCS: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1226 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS); |
Eric Christopher | e94ac88 | 2012-08-03 00:05:53 +0000 | [diff] [blame] | 1227 | case CallingConv::GHC: |
| 1228 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS_GHC); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1229 | } |
| 1230 | } |
| 1231 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1232 | /// LowerCallResult - Lower the result values of a call into the |
| 1233 | /// appropriate copies out of appropriate physical registers. |
| 1234 | SDValue |
| 1235 | ARMTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1236 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1237 | const SmallVectorImpl<ISD::InputArg> &Ins, |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 1238 | SDLoc dl, SelectionDAG &DAG, |
Stephen Lin | 456ca04 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1239 | SmallVectorImpl<SDValue> &InVals, |
| 1240 | bool isThisReturn, SDValue ThisVal) const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1241 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1242 | // Assign locations to each value returned by this call. |
| 1243 | SmallVector<CCValAssign, 16> RVLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1244 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 1245 | getTargetMachine(), RVLocs, *DAG.getContext(), Call); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1246 | CCInfo.AnalyzeCallResult(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1247 | CCAssignFnForNode(CallConv, /* Return*/ true, |
| 1248 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1249 | |
| 1250 | // Copy all of the result registers out of their specified physreg. |
| 1251 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 1252 | CCValAssign VA = RVLocs[i]; |
| 1253 | |
Stephen Lin | 456ca04 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1254 | // Pass 'this' value directly from the argument to return value, to avoid |
| 1255 | // reg unit interference |
| 1256 | if (i == 0 && isThisReturn) { |
Stephen Lin | 81fef02 | 2013-04-23 19:42:25 +0000 | [diff] [blame] | 1257 | assert(!VA.needsCustom() && VA.getLocVT() == MVT::i32 && |
| 1258 | "unexpected return calling convention register assignment"); |
Stephen Lin | 456ca04 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1259 | InVals.push_back(ThisVal); |
| 1260 | continue; |
| 1261 | } |
| 1262 | |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1263 | SDValue Val; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1264 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1265 | // Handle f64 or half of a v2f64. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1266 | SDValue Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1267 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1268 | Chain = Lo.getValue(1); |
| 1269 | InFlag = Lo.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1270 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1271 | SDValue Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1272 | InFlag); |
| 1273 | Chain = Hi.getValue(1); |
| 1274 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1275 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1276 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1277 | if (VA.getLocVT() == MVT::v2f64) { |
| 1278 | SDValue Vec = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 1279 | Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 1280 | DAG.getConstant(0, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1281 | |
| 1282 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1283 | Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1284 | Chain = Lo.getValue(1); |
| 1285 | InFlag = Lo.getValue(2); |
| 1286 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1287 | Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1288 | Chain = Hi.getValue(1); |
| 1289 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1290 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1291 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 1292 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1293 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1294 | } else { |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1295 | Val = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), VA.getLocVT(), |
| 1296 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1297 | Chain = Val.getValue(1); |
| 1298 | InFlag = Val.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1299 | } |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1300 | |
| 1301 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1302 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1303 | case CCValAssign::Full: break; |
| 1304 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1305 | Val = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), Val); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1306 | break; |
| 1307 | } |
| 1308 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1309 | InVals.push_back(Val); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1310 | } |
| 1311 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1312 | return Chain; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1313 | } |
| 1314 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1315 | /// LowerMemOpCallTo - Store the argument to the stack. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1316 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1317 | ARMTargetLowering::LowerMemOpCallTo(SDValue Chain, |
| 1318 | SDValue StackPtr, SDValue Arg, |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 1319 | SDLoc dl, SelectionDAG &DAG, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1320 | const CCValAssign &VA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1321 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1322 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| 1323 | SDValue PtrOff = DAG.getIntPtrConstant(LocMemOffset); |
| 1324 | PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, PtrOff); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1325 | return DAG.getStore(Chain, dl, Arg, PtrOff, |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 1326 | MachinePointerInfo::getStack(LocMemOffset), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1327 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1328 | } |
| 1329 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 1330 | void ARMTargetLowering::PassF64ArgInRegs(SDLoc dl, SelectionDAG &DAG, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1331 | SDValue Chain, SDValue &Arg, |
| 1332 | RegsToPassVector &RegsToPass, |
| 1333 | CCValAssign &VA, CCValAssign &NextVA, |
| 1334 | SDValue &StackPtr, |
| 1335 | SmallVector<SDValue, 8> &MemOpChains, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1336 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1337 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1338 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1339 | DAG.getVTList(MVT::i32, MVT::i32), Arg); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1340 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), fmrrd)); |
| 1341 | |
| 1342 | if (NextVA.isRegLoc()) |
| 1343 | RegsToPass.push_back(std::make_pair(NextVA.getLocReg(), fmrrd.getValue(1))); |
| 1344 | else { |
| 1345 | assert(NextVA.isMemLoc()); |
| 1346 | if (StackPtr.getNode() == 0) |
| 1347 | StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
| 1348 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1349 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, fmrrd.getValue(1), |
| 1350 | dl, DAG, NextVA, |
| 1351 | Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1352 | } |
| 1353 | } |
| 1354 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1355 | /// LowerCall - Lowering a call into a callseq_start <- |
Evan Cheng | fc40342 | 2007-02-03 08:53:01 +0000 | [diff] [blame] | 1356 | /// ARMISD:CALL <- callseq_end chain. Also add input and output parameter |
| 1357 | /// nodes. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1358 | SDValue |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 1359 | ARMTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1360 | SmallVectorImpl<SDValue> &InVals) const { |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 1361 | SelectionDAG &DAG = CLI.DAG; |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 1362 | SDLoc &dl = CLI.DL; |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 1363 | SmallVector<ISD::OutputArg, 32> &Outs = CLI.Outs; |
| 1364 | SmallVector<SDValue, 32> &OutVals = CLI.OutVals; |
| 1365 | SmallVector<ISD::InputArg, 32> &Ins = CLI.Ins; |
| 1366 | SDValue Chain = CLI.Chain; |
| 1367 | SDValue Callee = CLI.Callee; |
| 1368 | bool &isTailCall = CLI.IsTailCall; |
| 1369 | CallingConv::ID CallConv = CLI.CallConv; |
| 1370 | bool doesNotRet = CLI.DoesNotReturn; |
| 1371 | bool isVarArg = CLI.IsVarArg; |
| 1372 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1373 | MachineFunction &MF = DAG.getMachineFunction(); |
Stephen Lin | 3a1b4f8 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1374 | bool isStructRet = (Outs.empty()) ? false : Outs[0].Flags.isSRet(); |
| 1375 | bool isThisReturn = false; |
| 1376 | bool isSibCall = false; |
Bob Wilson | 6d2f9ce | 2011-10-07 17:17:49 +0000 | [diff] [blame] | 1377 | // Disable tail calls if they're not supported. |
| 1378 | if (!EnableARMTailCalls && !Subtarget->supportsTailCall()) |
Bob Wilson | 703af3a | 2010-08-13 22:43:33 +0000 | [diff] [blame] | 1379 | isTailCall = false; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1380 | if (isTailCall) { |
| 1381 | // Check if it's really possible to do a tail call. |
| 1382 | isTailCall = IsEligibleForTailCallOptimization(Callee, CallConv, |
Stephen Lin | 3a1b4f8 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1383 | isVarArg, isStructRet, MF.getFunction()->hasStructRetAttr(), |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1384 | Outs, OutVals, Ins, DAG); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1385 | // We don't support GuaranteedTailCallOpt for ARM, only automatically |
| 1386 | // detected sibcalls. |
| 1387 | if (isTailCall) { |
| 1388 | ++NumTailCalls; |
Stephen Lin | 3a1b4f8 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1389 | isSibCall = true; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1390 | } |
| 1391 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1392 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1393 | // Analyze operands of the call, assigning locations to each operand. |
| 1394 | SmallVector<CCValAssign, 16> ArgLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1395 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 1396 | getTargetMachine(), ArgLocs, *DAG.getContext(), Call); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1397 | CCInfo.AnalyzeCallOperands(Outs, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1398 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 1399 | isVarArg)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1400 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1401 | // Get a count of how many bytes are to be pushed on the stack. |
| 1402 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1403 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1404 | // For tail calls, memory operands are available in our caller's stack. |
Stephen Lin | 3a1b4f8 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1405 | if (isSibCall) |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1406 | NumBytes = 0; |
| 1407 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1408 | // Adjust the stack pointer for the new arguments... |
| 1409 | // These operations are automatically eliminated by the prolog/epilog pass |
Stephen Lin | 3a1b4f8 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1410 | if (!isSibCall) |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1411 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumBytes, true)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1412 | |
Jim Grosbach | f9a4b76 | 2010-02-24 01:43:03 +0000 | [diff] [blame] | 1413 | SDValue StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1414 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1415 | RegsToPassVector RegsToPass; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1416 | SmallVector<SDValue, 8> MemOpChains; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1417 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1418 | // Walk the register/memloc assignments, inserting copies/loads. In the case |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1419 | // of tail call optimization, arguments are handled later. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1420 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 1421 | i != e; |
| 1422 | ++i, ++realArgIdx) { |
| 1423 | CCValAssign &VA = ArgLocs[i]; |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1424 | SDValue Arg = OutVals[realArgIdx]; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1425 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1426 | bool isByVal = Flags.isByVal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1427 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1428 | // Promote the value if needed. |
| 1429 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1430 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1431 | case CCValAssign::Full: break; |
| 1432 | case CCValAssign::SExt: |
| 1433 | Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); |
| 1434 | break; |
| 1435 | case CCValAssign::ZExt: |
| 1436 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); |
| 1437 | break; |
| 1438 | case CCValAssign::AExt: |
| 1439 | Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); |
| 1440 | break; |
| 1441 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1442 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1443 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1444 | } |
| 1445 | |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1446 | // f64 and v2f64 might be passed in i32 pairs and must be split into pieces |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1447 | if (VA.needsCustom()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1448 | if (VA.getLocVT() == MVT::v2f64) { |
| 1449 | SDValue Op0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1450 | DAG.getConstant(0, MVT::i32)); |
| 1451 | SDValue Op1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1452 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1453 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1454 | PassF64ArgInRegs(dl, DAG, Chain, Op0, RegsToPass, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1455 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1456 | |
| 1457 | VA = ArgLocs[++i]; // skip ahead to next loc |
| 1458 | if (VA.isRegLoc()) { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1459 | PassF64ArgInRegs(dl, DAG, Chain, Op1, RegsToPass, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1460 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1461 | } else { |
| 1462 | assert(VA.isMemLoc()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1463 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1464 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Op1, |
| 1465 | dl, DAG, VA, Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1466 | } |
| 1467 | } else { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1468 | PassF64ArgInRegs(dl, DAG, Chain, Arg, RegsToPass, VA, ArgLocs[++i], |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1469 | StackPtr, MemOpChains, Flags); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1470 | } |
| 1471 | } else if (VA.isRegLoc()) { |
Stephen Lin | 81fef02 | 2013-04-23 19:42:25 +0000 | [diff] [blame] | 1472 | if (realArgIdx == 0 && Flags.isReturned() && Outs[0].VT == MVT::i32) { |
| 1473 | assert(VA.getLocVT() == MVT::i32 && |
| 1474 | "unexpected calling convention register assignment"); |
| 1475 | assert(!Ins.empty() && Ins[0].VT == MVT::i32 && |
Stephen Lin | 456ca04 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1476 | "unexpected use of 'returned'"); |
Stephen Lin | 3a1b4f8 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1477 | isThisReturn = true; |
Stephen Lin | 456ca04 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1478 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1479 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1480 | } else if (isByVal) { |
| 1481 | assert(VA.isMemLoc()); |
| 1482 | unsigned offset = 0; |
| 1483 | |
| 1484 | // True if this byval aggregate will be split between registers |
| 1485 | // and memory. |
Stepan Dyatkovskiy | 46abfcf | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1486 | unsigned ByValArgsCount = CCInfo.getInRegsParamsCount(); |
| 1487 | unsigned CurByValIdx = CCInfo.getInRegsParamsProceed(); |
| 1488 | |
| 1489 | if (CurByValIdx < ByValArgsCount) { |
| 1490 | |
| 1491 | unsigned RegBegin, RegEnd; |
| 1492 | CCInfo.getInRegsParamInfo(CurByValIdx, RegBegin, RegEnd); |
| 1493 | |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1494 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
| 1495 | unsigned int i, j; |
Stepan Dyatkovskiy | 46abfcf | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1496 | for (i = 0, j = RegBegin; j < RegEnd; i++, j++) { |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1497 | SDValue Const = DAG.getConstant(4*i, MVT::i32); |
| 1498 | SDValue AddArg = DAG.getNode(ISD::ADD, dl, PtrVT, Arg, Const); |
| 1499 | SDValue Load = DAG.getLoad(PtrVT, dl, Chain, AddArg, |
| 1500 | MachinePointerInfo(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1501 | false, false, false, 0); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1502 | MemOpChains.push_back(Load.getValue(1)); |
| 1503 | RegsToPass.push_back(std::make_pair(j, Load)); |
| 1504 | } |
Stepan Dyatkovskiy | 46abfcf | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1505 | |
| 1506 | // If parameter size outsides register area, "offset" value |
| 1507 | // helps us to calculate stack slot for remained part properly. |
| 1508 | offset = RegEnd - RegBegin; |
| 1509 | |
| 1510 | CCInfo.nextInRegsParam(); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1511 | } |
| 1512 | |
Stepan Dyatkovskiy | 46abfcf | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1513 | if (Flags.getByValSize() > 4*offset) { |
Manman Ren | 763a75d | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 1514 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| 1515 | SDValue StkPtrOff = DAG.getIntPtrConstant(LocMemOffset); |
| 1516 | SDValue Dst = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, |
| 1517 | StkPtrOff); |
| 1518 | SDValue SrcOffset = DAG.getIntPtrConstant(4*offset); |
| 1519 | SDValue Src = DAG.getNode(ISD::ADD, dl, getPointerTy(), Arg, SrcOffset); |
| 1520 | SDValue SizeNode = DAG.getConstant(Flags.getByValSize() - 4*offset, |
| 1521 | MVT::i32); |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 1522 | SDValue AlignNode = DAG.getConstant(Flags.getByValAlign(), MVT::i32); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1523 | |
Manman Ren | 763a75d | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 1524 | SDVTList VTs = DAG.getVTList(MVT::Other, MVT::Glue); |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 1525 | SDValue Ops[] = { Chain, Dst, Src, SizeNode, AlignNode}; |
Manman Ren | 763a75d | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 1526 | MemOpChains.push_back(DAG.getNode(ARMISD::COPY_STRUCT_BYVAL, dl, VTs, |
| 1527 | Ops, array_lengthof(Ops))); |
| 1528 | } |
Stephen Lin | 3a1b4f8 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1529 | } else if (!isSibCall) { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1530 | assert(VA.isMemLoc()); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1531 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1532 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Arg, |
| 1533 | dl, DAG, VA, Flags)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1534 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | if (!MemOpChains.empty()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1538 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1539 | &MemOpChains[0], MemOpChains.size()); |
| 1540 | |
| 1541 | // Build a sequence of copy-to-reg nodes chained together with token chain |
| 1542 | // and flag operands which copy the outgoing args into the appropriate regs. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1543 | SDValue InFlag; |
Dale Johannesen | 6470a11 | 2010-06-15 22:08:33 +0000 | [diff] [blame] | 1544 | // Tail call byval lowering might overwrite argument registers so in case of |
| 1545 | // tail call optimization the copies to registers are lowered later. |
| 1546 | if (!isTailCall) |
| 1547 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1548 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1549 | RegsToPass[i].second, InFlag); |
| 1550 | InFlag = Chain.getValue(1); |
| 1551 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1552 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1553 | // For tail calls lower the arguments to the 'real' stack slot. |
| 1554 | if (isTailCall) { |
| 1555 | // Force all the incoming stack arguments to be loaded from the stack |
| 1556 | // before any new outgoing arguments are stored to the stack, because the |
| 1557 | // outgoing stack slots may alias the incoming argument stack slots, and |
| 1558 | // the alias isn't otherwise explicit. This is slightly more conservative |
| 1559 | // than necessary, because it means that each store effectively depends |
| 1560 | // on every argument instead of just those arguments it would clobber. |
| 1561 | |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 1562 | // Do not flag preceding copytoreg stuff together with the following stuff. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1563 | InFlag = SDValue(); |
| 1564 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1565 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1566 | RegsToPass[i].second, InFlag); |
| 1567 | InFlag = Chain.getValue(1); |
| 1568 | } |
Stephen Lin | 69394f2 | 2013-04-20 00:47:48 +0000 | [diff] [blame] | 1569 | InFlag = SDValue(); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1570 | } |
| 1571 | |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1572 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
| 1573 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 1574 | // node so that legalize doesn't hack it. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1575 | bool isDirect = false; |
| 1576 | bool isARMFunc = false; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1577 | bool isLocalARMFunc = false; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1578 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1579 | |
| 1580 | if (EnableARMLongCalls) { |
| 1581 | assert (getTargetMachine().getRelocationModel() == Reloc::Static |
| 1582 | && "long-calls with non-static relocation model!"); |
| 1583 | // Handle a global address or an external symbol. If it's not one of |
| 1584 | // those, the target's already in a register, so we don't need to do |
| 1585 | // anything extra. |
| 1586 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Anders Carlsson | 0dbdca5 | 2010-04-15 03:11:28 +0000 | [diff] [blame] | 1587 | const GlobalValue *GV = G->getGlobal(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1588 | // Create a constant pool entry for the callee address |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1589 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 1590 | ARMConstantPoolValue *CPV = |
| 1591 | ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex, ARMCP::CPValue, 0); |
| 1592 | |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1593 | // Get the address of the callee into a register |
| 1594 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1595 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1596 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1597 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1598 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1599 | false, false, false, 0); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1600 | } else if (ExternalSymbolSDNode *S=dyn_cast<ExternalSymbolSDNode>(Callee)) { |
| 1601 | const char *Sym = S->getSymbol(); |
| 1602 | |
| 1603 | // Create a constant pool entry for the callee address |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1604 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | fe31e67 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 1605 | ARMConstantPoolValue *CPV = |
| 1606 | ARMConstantPoolSymbol::Create(*DAG.getContext(), Sym, |
| 1607 | ARMPCLabelIndex, 0); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1608 | // Get the address of the callee into a register |
| 1609 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1610 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1611 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1612 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1613 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1614 | false, false, false, 0); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1615 | } |
| 1616 | } else if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1617 | const GlobalValue *GV = G->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1618 | isDirect = true; |
Chris Lattner | 4fb63d0 | 2009-07-15 04:12:33 +0000 | [diff] [blame] | 1619 | bool isExt = GV->isDeclaration() || GV->isWeakForLinker(); |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1620 | bool isStub = (isExt && Subtarget->isTargetDarwin()) && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1621 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1622 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1623 | // ARM call to a local ARM function is predicable. |
Evan Cheng | 46df4eb | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 1624 | isLocalARMFunc = !Subtarget->isThumb() && (!isExt || !ARMInterworking); |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1625 | // tBX takes a register source operand. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1626 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1627 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 1628 | ARMConstantPoolValue *CPV = |
| 1629 | ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex, ARMCP::CPValue, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1630 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1631 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1632 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1633 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1634 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1635 | false, false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1636 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1637 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1638 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | 637d89f | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1639 | } else { |
| 1640 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1641 | unsigned OpFlags = 0; |
| 1642 | if (Subtarget->isTargetELF() && |
Chad Rosier | a6ca703 | 2013-02-28 19:16:42 +0000 | [diff] [blame] | 1643 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
Jim Grosbach | 637d89f | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1644 | OpFlags = ARMII::MO_PLT; |
| 1645 | Callee = DAG.getTargetGlobalAddress(GV, dl, getPointerTy(), 0, OpFlags); |
| 1646 | } |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1647 | } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1648 | isDirect = true; |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1649 | bool isStub = Subtarget->isTargetDarwin() && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1650 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1651 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1652 | // tBX takes a register source operand. |
| 1653 | const char *Sym = S->getSymbol(); |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1654 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1655 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | fe31e67 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 1656 | ARMConstantPoolValue *CPV = |
| 1657 | ARMConstantPoolSymbol::Create(*DAG.getContext(), Sym, |
| 1658 | ARMPCLabelIndex, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1659 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1660 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1661 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1662 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1663 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1664 | false, false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1665 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1666 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1667 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | 637d89f | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1668 | } else { |
| 1669 | unsigned OpFlags = 0; |
| 1670 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1671 | if (Subtarget->isTargetELF() && |
| 1672 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1673 | OpFlags = ARMII::MO_PLT; |
| 1674 | Callee = DAG.getTargetExternalSymbol(Sym, getPointerTy(), OpFlags); |
| 1675 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1676 | } |
| 1677 | |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1678 | // FIXME: handle tail calls differently. |
| 1679 | unsigned CallOpc; |
Bill Wendling | 831737d | 2012-12-30 10:32:01 +0000 | [diff] [blame] | 1680 | bool HasMinSizeAttr = MF.getFunction()->getAttributes(). |
| 1681 | hasAttribute(AttributeSet::FunctionIndex, Attribute::MinSize); |
Evan Cheng | b620724 | 2009-08-01 00:16:10 +0000 | [diff] [blame] | 1682 | if (Subtarget->isThumb()) { |
| 1683 | if ((!isDirect || isARMFunc) && !Subtarget->hasV5TOps()) |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1684 | CallOpc = ARMISD::CALL_NOLINK; |
| 1685 | else |
| 1686 | CallOpc = isARMFunc ? ARMISD::CALL : ARMISD::tCALL; |
| 1687 | } else { |
Evan Cheng | b341fac | 2012-11-10 02:09:05 +0000 | [diff] [blame] | 1688 | if (!isDirect && !Subtarget->hasV5TOps()) |
Evan Cheng | 4bfcd4a | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 1689 | CallOpc = ARMISD::CALL_NOLINK; |
Evan Cheng | b341fac | 2012-11-10 02:09:05 +0000 | [diff] [blame] | 1690 | else if (doesNotRet && isDirect && Subtarget->hasRAS() && |
Quentin Colombet | 43934ae | 2012-11-02 21:32:17 +0000 | [diff] [blame] | 1691 | // Emit regular call when code size is the priority |
| 1692 | !HasMinSizeAttr) |
Evan Cheng | 4bfcd4a | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 1693 | // "mov lr, pc; b _foo" to avoid confusing the RSP |
| 1694 | CallOpc = ARMISD::CALL_NOLINK; |
| 1695 | else |
| 1696 | CallOpc = isLocalARMFunc ? ARMISD::CALL_PRED : ARMISD::CALL; |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1697 | } |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1698 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1699 | std::vector<SDValue> Ops; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1700 | Ops.push_back(Chain); |
| 1701 | Ops.push_back(Callee); |
| 1702 | |
| 1703 | // Add argument registers to the end of the list so that they are known live |
| 1704 | // into the call. |
| 1705 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) |
| 1706 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 1707 | RegsToPass[i].second.getValueType())); |
| 1708 | |
Jakob Stoklund Olesen | c54f634 | 2012-02-24 01:19:29 +0000 | [diff] [blame] | 1709 | // Add a register mask operand representing the call-preserved registers. |
Stephen Lin | 456ca04 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1710 | const uint32_t *Mask; |
Jakob Stoklund Olesen | c54f634 | 2012-02-24 01:19:29 +0000 | [diff] [blame] | 1711 | const TargetRegisterInfo *TRI = getTargetMachine().getRegisterInfo(); |
Stephen Lin | 456ca04 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1712 | const ARMBaseRegisterInfo *ARI = static_cast<const ARMBaseRegisterInfo*>(TRI); |
Stephen Lin | 3a1b4f8 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1713 | if (isThisReturn) |
Stephen Lin | 456ca04 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1714 | // For 'this' returns, use the R0-preserving mask |
| 1715 | Mask = ARI->getThisReturnPreservedMask(CallConv); |
| 1716 | else |
| 1717 | Mask = ARI->getCallPreservedMask(CallConv); |
| 1718 | |
Jakob Stoklund Olesen | c54f634 | 2012-02-24 01:19:29 +0000 | [diff] [blame] | 1719 | assert(Mask && "Missing call preserved mask for calling convention"); |
| 1720 | Ops.push_back(DAG.getRegisterMask(Mask)); |
| 1721 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1722 | if (InFlag.getNode()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1723 | Ops.push_back(InFlag); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1724 | |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1725 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1726 | if (isTailCall) |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1727 | return DAG.getNode(ARMISD::TC_RETURN, dl, NodeTys, &Ops[0], Ops.size()); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1728 | |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1729 | // Returns a chain and a flag for retval copy to use. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1730 | Chain = DAG.getNode(CallOpc, dl, NodeTys, &Ops[0], Ops.size()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1731 | InFlag = Chain.getValue(1); |
| 1732 | |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1733 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, true), |
| 1734 | DAG.getIntPtrConstant(0, true), InFlag); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1735 | if (!Ins.empty()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1736 | InFlag = Chain.getValue(1); |
| 1737 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1738 | // Handle result values, copying them out of physregs into vregs that we |
| 1739 | // return. |
Stephen Lin | 456ca04 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1740 | return LowerCallResult(Chain, InFlag, CallConv, isVarArg, Ins, dl, DAG, |
Stephen Lin | 3a1b4f8 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1741 | InVals, isThisReturn, |
| 1742 | isThisReturn ? OutVals[0] : SDValue()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1743 | } |
| 1744 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1745 | /// HandleByVal - Every parameter *after* a byval parameter is passed |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1746 | /// on the stack. Remember the next parameter register to allocate, |
| 1747 | /// and then confiscate the rest of the parameter registers to insure |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1748 | /// this. |
| 1749 | void |
Stepan Dyatkovskiy | b52ba9f | 2012-10-16 07:16:47 +0000 | [diff] [blame] | 1750 | ARMTargetLowering::HandleByVal( |
| 1751 | CCState *State, unsigned &size, unsigned Align) const { |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1752 | unsigned reg = State->AllocateReg(GPRArgRegs, 4); |
| 1753 | assert((State->getCallOrPrologue() == Prologue || |
| 1754 | State->getCallOrPrologue() == Call) && |
| 1755 | "unhandled ParmContext"); |
Stepan Dyatkovskiy | 46abfcf | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1756 | |
| 1757 | // For in-prologue parameters handling, we also introduce stack offset |
| 1758 | // for byval registers: see CallingConvLower.cpp, CCState::HandleByVal. |
| 1759 | // This behaviour outsides AAPCS rules (5.5 Parameters Passing) of how |
| 1760 | // NSAA should be evaluted (NSAA means "next stacked argument address"). |
| 1761 | // So: NextStackOffset = NSAAOffset + SizeOfByValParamsStoredInRegs. |
| 1762 | // Then: NSAAOffset = NextStackOffset - SizeOfByValParamsStoredInRegs. |
| 1763 | unsigned NSAAOffset = State->getNextStackOffset(); |
| 1764 | if (State->getCallOrPrologue() != Call) { |
| 1765 | for (unsigned i = 0, e = State->getInRegsParamsCount(); i != e; ++i) { |
| 1766 | unsigned RB, RE; |
| 1767 | State->getInRegsParamInfo(i, RB, RE); |
| 1768 | assert(NSAAOffset >= (RE-RB)*4 && |
| 1769 | "Stack offset for byval regs doesn't introduced anymore?"); |
| 1770 | NSAAOffset -= (RE-RB)*4; |
| 1771 | } |
| 1772 | } |
| 1773 | if ((ARM::R0 <= reg) && (reg <= ARM::R3)) { |
Stepan Dyatkovskiy | b52ba9f | 2012-10-16 07:16:47 +0000 | [diff] [blame] | 1774 | if (Subtarget->isAAPCS_ABI() && Align > 4) { |
| 1775 | unsigned AlignInRegs = Align / 4; |
| 1776 | unsigned Waste = (ARM::R4 - reg) % AlignInRegs; |
| 1777 | for (unsigned i = 0; i < Waste; ++i) |
| 1778 | reg = State->AllocateReg(GPRArgRegs, 4); |
| 1779 | } |
| 1780 | if (reg != 0) { |
Stepan Dyatkovskiy | 46abfcf | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1781 | unsigned excess = 4 * (ARM::R4 - reg); |
| 1782 | |
| 1783 | // Special case when NSAA != SP and parameter size greater than size of |
| 1784 | // all remained GPR regs. In that case we can't split parameter, we must |
| 1785 | // send it to stack. We also must set NCRN to R4, so waste all |
| 1786 | // remained registers. |
| 1787 | if (Subtarget->isAAPCS_ABI() && NSAAOffset != 0 && size > excess) { |
| 1788 | while (State->AllocateReg(GPRArgRegs, 4)) |
| 1789 | ; |
| 1790 | return; |
| 1791 | } |
| 1792 | |
| 1793 | // First register for byval parameter is the first register that wasn't |
| 1794 | // allocated before this method call, so it would be "reg". |
| 1795 | // If parameter is small enough to be saved in range [reg, r4), then |
| 1796 | // the end (first after last) register would be reg + param-size-in-regs, |
| 1797 | // else parameter would be splitted between registers and stack, |
| 1798 | // end register would be r4 in this case. |
| 1799 | unsigned ByValRegBegin = reg; |
Stepan Dyatkovskiy | 44b6b53 | 2013-05-08 14:51:27 +0000 | [diff] [blame] | 1800 | unsigned ByValRegEnd = (size < excess) ? reg + size/4 : (unsigned)ARM::R4; |
Stepan Dyatkovskiy | 46abfcf | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1801 | State->addInRegsParamInfo(ByValRegBegin, ByValRegEnd); |
| 1802 | // Note, first register is allocated in the beginning of function already, |
| 1803 | // allocate remained amount of registers we need. |
| 1804 | for (unsigned i = reg+1; i != ByValRegEnd; ++i) |
| 1805 | State->AllocateReg(GPRArgRegs, 4); |
Stepan Dyatkovskiy | b52ba9f | 2012-10-16 07:16:47 +0000 | [diff] [blame] | 1806 | // At a call site, a byval parameter that is split between |
| 1807 | // registers and memory needs its size truncated here. In a |
| 1808 | // function prologue, such byval parameters are reassembled in |
| 1809 | // memory, and are not truncated. |
| 1810 | if (State->getCallOrPrologue() == Call) { |
Stepan Dyatkovskiy | 46abfcf | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1811 | // Make remained size equal to 0 in case, when |
| 1812 | // the whole structure may be stored into registers. |
| 1813 | if (size < excess) |
| 1814 | size = 0; |
| 1815 | else |
| 1816 | size -= excess; |
Stepan Dyatkovskiy | b52ba9f | 2012-10-16 07:16:47 +0000 | [diff] [blame] | 1817 | } |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1818 | } |
| 1819 | } |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1820 | } |
| 1821 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1822 | /// MatchingStackOffset - Return true if the given stack call argument is |
| 1823 | /// already available in the same position (relatively) of the caller's |
| 1824 | /// incoming argument stack. |
| 1825 | static |
| 1826 | bool MatchingStackOffset(SDValue Arg, unsigned Offset, ISD::ArgFlagsTy Flags, |
| 1827 | MachineFrameInfo *MFI, const MachineRegisterInfo *MRI, |
Craig Topper | acf2077 | 2012-03-25 23:49:58 +0000 | [diff] [blame] | 1828 | const TargetInstrInfo *TII) { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1829 | unsigned Bytes = Arg.getValueType().getSizeInBits() / 8; |
| 1830 | int FI = INT_MAX; |
| 1831 | if (Arg.getOpcode() == ISD::CopyFromReg) { |
| 1832 | unsigned VR = cast<RegisterSDNode>(Arg.getOperand(1))->getReg(); |
Jakob Stoklund Olesen | c9df025 | 2011-01-10 02:58:51 +0000 | [diff] [blame] | 1833 | if (!TargetRegisterInfo::isVirtualRegister(VR)) |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1834 | return false; |
| 1835 | MachineInstr *Def = MRI->getVRegDef(VR); |
| 1836 | if (!Def) |
| 1837 | return false; |
| 1838 | if (!Flags.isByVal()) { |
| 1839 | if (!TII->isLoadFromStackSlot(Def, FI)) |
| 1840 | return false; |
| 1841 | } else { |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1842 | return false; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1843 | } |
| 1844 | } else if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Arg)) { |
| 1845 | if (Flags.isByVal()) |
| 1846 | // ByVal argument is passed in as a pointer but it's now being |
| 1847 | // dereferenced. e.g. |
| 1848 | // define @foo(%struct.X* %A) { |
| 1849 | // tail call @bar(%struct.X* byval %A) |
| 1850 | // } |
| 1851 | return false; |
| 1852 | SDValue Ptr = Ld->getBasePtr(); |
| 1853 | FrameIndexSDNode *FINode = dyn_cast<FrameIndexSDNode>(Ptr); |
| 1854 | if (!FINode) |
| 1855 | return false; |
| 1856 | FI = FINode->getIndex(); |
| 1857 | } else |
| 1858 | return false; |
| 1859 | |
| 1860 | assert(FI != INT_MAX); |
| 1861 | if (!MFI->isFixedObjectIndex(FI)) |
| 1862 | return false; |
| 1863 | return Offset == MFI->getObjectOffset(FI) && Bytes == MFI->getObjectSize(FI); |
| 1864 | } |
| 1865 | |
| 1866 | /// IsEligibleForTailCallOptimization - Check whether the call is eligible |
| 1867 | /// for tail call optimization. Targets which want to do tail call |
| 1868 | /// optimization should implement this function. |
| 1869 | bool |
| 1870 | ARMTargetLowering::IsEligibleForTailCallOptimization(SDValue Callee, |
| 1871 | CallingConv::ID CalleeCC, |
| 1872 | bool isVarArg, |
| 1873 | bool isCalleeStructRet, |
| 1874 | bool isCallerStructRet, |
| 1875 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1876 | const SmallVectorImpl<SDValue> &OutVals, |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1877 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1878 | SelectionDAG& DAG) const { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1879 | const Function *CallerF = DAG.getMachineFunction().getFunction(); |
| 1880 | CallingConv::ID CallerCC = CallerF->getCallingConv(); |
| 1881 | bool CCMatch = CallerCC == CalleeCC; |
| 1882 | |
| 1883 | // Look for obvious safe cases to perform tail call optimization that do not |
| 1884 | // require ABI changes. This is what gcc calls sibcall. |
| 1885 | |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 1886 | // Do not sibcall optimize vararg calls unless the call site is not passing |
| 1887 | // any arguments. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1888 | if (isVarArg && !Outs.empty()) |
| 1889 | return false; |
| 1890 | |
| 1891 | // Also avoid sibcall optimization if either caller or callee uses struct |
| 1892 | // return semantics. |
| 1893 | if (isCalleeStructRet || isCallerStructRet) |
| 1894 | return false; |
| 1895 | |
Dale Johannesen | e39fdbe | 2010-06-23 18:52:34 +0000 | [diff] [blame] | 1896 | // FIXME: Completely disable sibcall for Thumb1 since Thumb1RegisterInfo:: |
Jim Grosbach | 8dc41f3 | 2011-07-08 20:18:11 +0000 | [diff] [blame] | 1897 | // emitEpilogue is not ready for them. Thumb tail calls also use t2B, as |
| 1898 | // the Thumb1 16-bit unconditional branch doesn't have sufficient relocation |
| 1899 | // support in the assembler and linker to be used. This would need to be |
| 1900 | // fixed to fully support tail calls in Thumb1. |
| 1901 | // |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1902 | // Doing this is tricky, since the LDM/POP instruction on Thumb doesn't take |
| 1903 | // LR. This means if we need to reload LR, it takes an extra instructions, |
| 1904 | // which outweighs the value of the tail call; but here we don't know yet |
| 1905 | // whether LR is going to be used. Probably the right approach is to |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 1906 | // generate the tail call here and turn it back into CALL/RET in |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1907 | // emitEpilogue if LR is used. |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1908 | |
| 1909 | // Thumb1 PIC calls to external symbols use BX, so they can be tail calls, |
| 1910 | // but we need to make sure there are enough registers; the only valid |
| 1911 | // registers are the 4 used for parameters. We don't currently do this |
| 1912 | // case. |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1913 | if (Subtarget->isThumb1Only()) |
| 1914 | return false; |
Dale Johannesen | df50d7e | 2010-06-18 18:13:11 +0000 | [diff] [blame] | 1915 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1916 | // If the calling conventions do not match, then we'd better make sure the |
| 1917 | // results are returned in the same way as what the caller expects. |
| 1918 | if (!CCMatch) { |
| 1919 | SmallVector<CCValAssign, 16> RVLocs1; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1920 | ARMCCState CCInfo1(CalleeCC, false, DAG.getMachineFunction(), |
| 1921 | getTargetMachine(), RVLocs1, *DAG.getContext(), Call); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1922 | CCInfo1.AnalyzeCallResult(Ins, CCAssignFnForNode(CalleeCC, true, isVarArg)); |
| 1923 | |
| 1924 | SmallVector<CCValAssign, 16> RVLocs2; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1925 | ARMCCState CCInfo2(CallerCC, false, DAG.getMachineFunction(), |
| 1926 | getTargetMachine(), RVLocs2, *DAG.getContext(), Call); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1927 | CCInfo2.AnalyzeCallResult(Ins, CCAssignFnForNode(CallerCC, true, isVarArg)); |
| 1928 | |
| 1929 | if (RVLocs1.size() != RVLocs2.size()) |
| 1930 | return false; |
| 1931 | for (unsigned i = 0, e = RVLocs1.size(); i != e; ++i) { |
| 1932 | if (RVLocs1[i].isRegLoc() != RVLocs2[i].isRegLoc()) |
| 1933 | return false; |
| 1934 | if (RVLocs1[i].getLocInfo() != RVLocs2[i].getLocInfo()) |
| 1935 | return false; |
| 1936 | if (RVLocs1[i].isRegLoc()) { |
| 1937 | if (RVLocs1[i].getLocReg() != RVLocs2[i].getLocReg()) |
| 1938 | return false; |
| 1939 | } else { |
| 1940 | if (RVLocs1[i].getLocMemOffset() != RVLocs2[i].getLocMemOffset()) |
| 1941 | return false; |
| 1942 | } |
| 1943 | } |
| 1944 | } |
| 1945 | |
Manman Ren | e6c3cc8 | 2012-10-12 23:39:43 +0000 | [diff] [blame] | 1946 | // If Caller's vararg or byval argument has been split between registers and |
| 1947 | // stack, do not perform tail call, since part of the argument is in caller's |
| 1948 | // local frame. |
| 1949 | const ARMFunctionInfo *AFI_Caller = DAG.getMachineFunction(). |
| 1950 | getInfo<ARMFunctionInfo>(); |
Stepan Dyatkovskiy | f65e493 | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 1951 | if (AFI_Caller->getArgRegsSaveSize()) |
Manman Ren | e6c3cc8 | 2012-10-12 23:39:43 +0000 | [diff] [blame] | 1952 | return false; |
| 1953 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1954 | // If the callee takes no arguments then go on to check the results of the |
| 1955 | // call. |
| 1956 | if (!Outs.empty()) { |
| 1957 | // Check if stack adjustment is needed. For now, do not do this if any |
| 1958 | // argument is passed on the stack. |
| 1959 | SmallVector<CCValAssign, 16> ArgLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1960 | ARMCCState CCInfo(CalleeCC, isVarArg, DAG.getMachineFunction(), |
| 1961 | getTargetMachine(), ArgLocs, *DAG.getContext(), Call); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1962 | CCInfo.AnalyzeCallOperands(Outs, |
| 1963 | CCAssignFnForNode(CalleeCC, false, isVarArg)); |
| 1964 | if (CCInfo.getNextStackOffset()) { |
| 1965 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1966 | |
| 1967 | // Check if the arguments are already laid out in the right way as |
| 1968 | // the caller's fixed stack objects. |
| 1969 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 1970 | const MachineRegisterInfo *MRI = &MF.getRegInfo(); |
Craig Topper | acf2077 | 2012-03-25 23:49:58 +0000 | [diff] [blame] | 1971 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1972 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 1973 | i != e; |
| 1974 | ++i, ++realArgIdx) { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1975 | CCValAssign &VA = ArgLocs[i]; |
| 1976 | EVT RegVT = VA.getLocVT(); |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1977 | SDValue Arg = OutVals[realArgIdx]; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1978 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1979 | if (VA.getLocInfo() == CCValAssign::Indirect) |
| 1980 | return false; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1981 | if (VA.needsCustom()) { |
| 1982 | // f64 and vector types are split into multiple registers or |
| 1983 | // register/stack-slot combinations. The types will not match |
| 1984 | // the registers; give up on memory f64 refs until we figure |
| 1985 | // out what to do about this. |
| 1986 | if (!VA.isRegLoc()) |
| 1987 | return false; |
| 1988 | if (!ArgLocs[++i].isRegLoc()) |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 1989 | return false; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1990 | if (RegVT == MVT::v2f64) { |
| 1991 | if (!ArgLocs[++i].isRegLoc()) |
| 1992 | return false; |
| 1993 | if (!ArgLocs[++i].isRegLoc()) |
| 1994 | return false; |
| 1995 | } |
| 1996 | } else if (!VA.isRegLoc()) { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1997 | if (!MatchingStackOffset(Arg, VA.getLocMemOffset(), Flags, |
| 1998 | MFI, MRI, TII)) |
| 1999 | return false; |
| 2000 | } |
| 2001 | } |
| 2002 | } |
| 2003 | } |
| 2004 | |
| 2005 | return true; |
| 2006 | } |
| 2007 | |
Benjamin Kramer | 350c008 | 2012-11-28 20:55:10 +0000 | [diff] [blame] | 2008 | bool |
| 2009 | ARMTargetLowering::CanLowerReturn(CallingConv::ID CallConv, |
| 2010 | MachineFunction &MF, bool isVarArg, |
| 2011 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 2012 | LLVMContext &Context) const { |
| 2013 | SmallVector<CCValAssign, 16> RVLocs; |
| 2014 | CCState CCInfo(CallConv, isVarArg, MF, getTargetMachine(), RVLocs, Context); |
| 2015 | return CCInfo.CheckReturn(Outs, CCAssignFnForNode(CallConv, /*Return=*/true, |
| 2016 | isVarArg)); |
| 2017 | } |
| 2018 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2019 | SDValue |
| 2020 | ARMTargetLowering::LowerReturn(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 2021 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2022 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 2023 | const SmallVectorImpl<SDValue> &OutVals, |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 2024 | SDLoc dl, SelectionDAG &DAG) const { |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2025 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2026 | // CCValAssign - represent the assignment of the return value to a location. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2027 | SmallVector<CCValAssign, 16> RVLocs; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2028 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2029 | // CCState - Info about the registers and stack slots. |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 2030 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 2031 | getTargetMachine(), RVLocs, *DAG.getContext(), Call); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2032 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2033 | // Analyze outgoing return values. |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2034 | CCInfo.AnalyzeReturn(Outs, CCAssignFnForNode(CallConv, /* Return */ true, |
| 2035 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2036 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2037 | SDValue Flag; |
Jakob Stoklund Olesen | fc74327 | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2038 | SmallVector<SDValue, 4> RetOps; |
| 2039 | RetOps.push_back(Chain); // Operand #0 = Chain (updated below) |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2040 | |
| 2041 | // Copy the result values into the output registers. |
| 2042 | for (unsigned i = 0, realRVLocIdx = 0; |
| 2043 | i != RVLocs.size(); |
| 2044 | ++i, ++realRVLocIdx) { |
| 2045 | CCValAssign &VA = RVLocs[i]; |
| 2046 | assert(VA.isRegLoc() && "Can only return in registers!"); |
| 2047 | |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 2048 | SDValue Arg = OutVals[realRVLocIdx]; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2049 | |
| 2050 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2051 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2052 | case CCValAssign::Full: break; |
| 2053 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2054 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2055 | break; |
| 2056 | } |
| 2057 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2058 | if (VA.needsCustom()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2059 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2060 | // Extract the first half and return it in two registers. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2061 | SDValue Half = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 2062 | DAG.getConstant(0, MVT::i32)); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2063 | SDValue HalfGPRs = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2064 | DAG.getVTList(MVT::i32, MVT::i32), Half); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2065 | |
| 2066 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), HalfGPRs, Flag); |
| 2067 | Flag = Chain.getValue(1); |
Jakob Stoklund Olesen | fc74327 | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2068 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2069 | VA = RVLocs[++i]; // skip ahead to next loc |
| 2070 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
| 2071 | HalfGPRs.getValue(1), Flag); |
| 2072 | Flag = Chain.getValue(1); |
Jakob Stoklund Olesen | fc74327 | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2073 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2074 | VA = RVLocs[++i]; // skip ahead to next loc |
| 2075 | |
| 2076 | // Extract the 2nd half and fall through to handle it as an f64 value. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2077 | Arg = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 2078 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2079 | } |
| 2080 | // Legalize ret f64 -> ret 2 x i32. We always have fmrrd if f64 is |
| 2081 | // available. |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2082 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2083 | DAG.getVTList(MVT::i32, MVT::i32), &Arg, 1); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2084 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd, Flag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 2085 | Flag = Chain.getValue(1); |
Jakob Stoklund Olesen | fc74327 | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2086 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2087 | VA = RVLocs[++i]; // skip ahead to next loc |
| 2088 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd.getValue(1), |
| 2089 | Flag); |
| 2090 | } else |
| 2091 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), Arg, Flag); |
| 2092 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2093 | // Guarantee that all emitted copies are |
| 2094 | // stuck together, avoiding something bad. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2095 | Flag = Chain.getValue(1); |
Jakob Stoklund Olesen | fc74327 | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2096 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2097 | } |
| 2098 | |
Jakob Stoklund Olesen | fc74327 | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2099 | // Update chain and glue. |
| 2100 | RetOps[0] = Chain; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2101 | if (Flag.getNode()) |
Jakob Stoklund Olesen | fc74327 | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2102 | RetOps.push_back(Flag); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2103 | |
Jakob Stoklund Olesen | fc74327 | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2104 | return DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, |
| 2105 | RetOps.data(), RetOps.size()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2106 | } |
| 2107 | |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2108 | bool ARMTargetLowering::isUsedByReturnOnly(SDNode *N, SDValue &Chain) const { |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2109 | if (N->getNumValues() != 1) |
| 2110 | return false; |
| 2111 | if (!N->hasNUsesOfValue(1, 0)) |
| 2112 | return false; |
| 2113 | |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2114 | SDValue TCChain = Chain; |
| 2115 | SDNode *Copy = *N->use_begin(); |
| 2116 | if (Copy->getOpcode() == ISD::CopyToReg) { |
| 2117 | // If the copy has a glue operand, we conservatively assume it isn't safe to |
| 2118 | // perform a tail call. |
| 2119 | if (Copy->getOperand(Copy->getNumOperands()-1).getValueType() == MVT::Glue) |
| 2120 | return false; |
| 2121 | TCChain = Copy->getOperand(0); |
| 2122 | } else if (Copy->getOpcode() == ARMISD::VMOVRRD) { |
| 2123 | SDNode *VMov = Copy; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2124 | // f64 returned in a pair of GPRs. |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2125 | SmallPtrSet<SDNode*, 2> Copies; |
| 2126 | for (SDNode::use_iterator UI = VMov->use_begin(), UE = VMov->use_end(); |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2127 | UI != UE; ++UI) { |
| 2128 | if (UI->getOpcode() != ISD::CopyToReg) |
| 2129 | return false; |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2130 | Copies.insert(*UI); |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2131 | } |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2132 | if (Copies.size() > 2) |
| 2133 | return false; |
| 2134 | |
| 2135 | for (SDNode::use_iterator UI = VMov->use_begin(), UE = VMov->use_end(); |
| 2136 | UI != UE; ++UI) { |
| 2137 | SDValue UseChain = UI->getOperand(0); |
| 2138 | if (Copies.count(UseChain.getNode())) |
| 2139 | // Second CopyToReg |
| 2140 | Copy = *UI; |
| 2141 | else |
| 2142 | // First CopyToReg |
| 2143 | TCChain = UseChain; |
| 2144 | } |
| 2145 | } else if (Copy->getOpcode() == ISD::BITCAST) { |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2146 | // f32 returned in a single GPR. |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2147 | if (!Copy->hasOneUse()) |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2148 | return false; |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2149 | Copy = *Copy->use_begin(); |
| 2150 | if (Copy->getOpcode() != ISD::CopyToReg || !Copy->hasNUsesOfValue(1, 0)) |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2151 | return false; |
Lang Hames | d26c93d | 2013-05-13 10:21:19 +0000 | [diff] [blame] | 2152 | TCChain = Copy->getOperand(0); |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2153 | } else { |
| 2154 | return false; |
| 2155 | } |
| 2156 | |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 2157 | bool HasRet = false; |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2158 | for (SDNode::use_iterator UI = Copy->use_begin(), UE = Copy->use_end(); |
| 2159 | UI != UE; ++UI) { |
| 2160 | if (UI->getOpcode() != ARMISD::RET_FLAG) |
| 2161 | return false; |
| 2162 | HasRet = true; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2163 | } |
| 2164 | |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2165 | if (!HasRet) |
| 2166 | return false; |
| 2167 | |
| 2168 | Chain = TCChain; |
| 2169 | return true; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2170 | } |
| 2171 | |
Evan Cheng | 485fafc | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 2172 | bool ARMTargetLowering::mayBeEmittedAsTailCall(CallInst *CI) const { |
Evan Cheng | 1c80f56 | 2012-03-30 01:24:39 +0000 | [diff] [blame] | 2173 | if (!EnableARMTailCalls && !Subtarget->supportsTailCall()) |
Evan Cheng | 485fafc | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 2174 | return false; |
| 2175 | |
| 2176 | if (!CI->isTailCall()) |
| 2177 | return false; |
| 2178 | |
| 2179 | return !Subtarget->isThumb1Only(); |
| 2180 | } |
| 2181 | |
Bob Wilson | b62d257 | 2009-11-03 00:02:05 +0000 | [diff] [blame] | 2182 | // ConstantPool, JumpTable, GlobalAddress, and ExternalSymbol are lowered as |
| 2183 | // their target counterpart wrapped in the ARMISD::Wrapper node. Suppose N is |
| 2184 | // one of the above mentioned nodes. It has to be wrapped because otherwise |
| 2185 | // Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only |
| 2186 | // be used to form addressing mode. These wrapped nodes will be selected |
| 2187 | // into MOVi. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2188 | static SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2189 | EVT PtrVT = Op.getValueType(); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 2190 | // FIXME there is no actual debug info here |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 2191 | SDLoc dl(Op); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2192 | ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2193 | SDValue Res; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2194 | if (CP->isMachineConstantPoolEntry()) |
| 2195 | Res = DAG.getTargetConstantPool(CP->getMachineCPVal(), PtrVT, |
| 2196 | CP->getAlignment()); |
| 2197 | else |
| 2198 | Res = DAG.getTargetConstantPool(CP->getConstVal(), PtrVT, |
| 2199 | CP->getAlignment()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2200 | return DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Res); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2201 | } |
| 2202 | |
Jim Grosbach | e1102ca | 2010-07-19 17:20:38 +0000 | [diff] [blame] | 2203 | unsigned ARMTargetLowering::getJumpTableEncoding() const { |
| 2204 | return MachineJumpTableInfo::EK_Inline; |
| 2205 | } |
| 2206 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2207 | SDValue ARMTargetLowering::LowerBlockAddress(SDValue Op, |
| 2208 | SelectionDAG &DAG) const { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2209 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2210 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2211 | unsigned ARMPCLabelIndex = 0; |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 2212 | SDLoc DL(Op); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2213 | EVT PtrVT = getPointerTy(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2214 | const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2215 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2216 | SDValue CPAddr; |
| 2217 | if (RelocM == Reloc::Static) { |
| 2218 | CPAddr = DAG.getTargetConstantPool(BA, PtrVT, 4); |
| 2219 | } else { |
| 2220 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2221 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2222 | ARMConstantPoolValue *CPV = |
| 2223 | ARMConstantPoolConstant::Create(BA, ARMPCLabelIndex, |
| 2224 | ARMCP::CPBlockAddress, PCAdj); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2225 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| 2226 | } |
| 2227 | CPAddr = DAG.getNode(ARMISD::Wrapper, DL, PtrVT, CPAddr); |
| 2228 | SDValue Result = DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2229 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2230 | false, false, false, 0); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2231 | if (RelocM == Reloc::Static) |
| 2232 | return Result; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2233 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2234 | return DAG.getNode(ARMISD::PIC_ADD, DL, PtrVT, Result, PICLabel); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 2235 | } |
| 2236 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2237 | // Lower ISD::GlobalTLSAddress using the "general dynamic" model |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2238 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2239 | ARMTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2240 | SelectionDAG &DAG) const { |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 2241 | SDLoc dl(GA); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2242 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2243 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2244 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2245 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2246 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2247 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2248 | ARMConstantPoolConstant::Create(GA->getGlobal(), ARMPCLabelIndex, |
| 2249 | ARMCP::CPValue, PCAdj, ARMCP::TLSGD, true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2250 | SDValue Argument = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2251 | Argument = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Argument); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2252 | Argument = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Argument, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2253 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2254 | false, false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2255 | SDValue Chain = Argument.getValue(1); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2256 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2257 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2258 | Argument = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Argument, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2259 | |
| 2260 | // call __tls_get_addr. |
| 2261 | ArgListTy Args; |
| 2262 | ArgListEntry Entry; |
| 2263 | Entry.Node = Argument; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2264 | Entry.Ty = (Type *) Type::getInt32Ty(*DAG.getContext()); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2265 | Args.push_back(Entry); |
Dale Johannesen | 7d2ad62 | 2009-01-30 23:10:59 +0000 | [diff] [blame] | 2266 | // FIXME: is there useful debug info available here? |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 2267 | TargetLowering::CallLoweringInfo CLI(Chain, |
| 2268 | (Type *) Type::getInt32Ty(*DAG.getContext()), |
Evan Cheng | 59bc060 | 2009-08-14 19:11:20 +0000 | [diff] [blame] | 2269 | false, false, false, false, |
Evan Cheng | 4bfcd4a | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 2270 | 0, CallingConv::C, /*isTailCall=*/false, |
| 2271 | /*doesNotRet=*/false, /*isReturnValueUsed=*/true, |
Bill Wendling | 46ada19 | 2010-03-02 01:55:18 +0000 | [diff] [blame] | 2272 | DAG.getExternalSymbol("__tls_get_addr", PtrVT), Args, DAG, dl); |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 2273 | std::pair<SDValue, SDValue> CallResult = LowerCallTo(CLI); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2274 | return CallResult.first; |
| 2275 | } |
| 2276 | |
| 2277 | // Lower ISD::GlobalTLSAddress using the "initial exec" or |
| 2278 | // "local exec" model. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2279 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2280 | ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA, |
Hans Wennborg | fd5abd5 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2281 | SelectionDAG &DAG, |
| 2282 | TLSModel::Model model) const { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2283 | const GlobalValue *GV = GA->getGlobal(); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 2284 | SDLoc dl(GA); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2285 | SDValue Offset; |
| 2286 | SDValue Chain = DAG.getEntryNode(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2287 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2288 | // Get the Thread Pointer |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2289 | SDValue ThreadPointer = DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2290 | |
Hans Wennborg | fd5abd5 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2291 | if (model == TLSModel::InitialExec) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2292 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2293 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2294 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2295 | // Initial exec model. |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2296 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
| 2297 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2298 | ARMConstantPoolConstant::Create(GA->getGlobal(), ARMPCLabelIndex, |
| 2299 | ARMCP::CPValue, PCAdj, ARMCP::GOTTPOFF, |
| 2300 | true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2301 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2302 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2303 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2304 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2305 | false, false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2306 | Chain = Offset.getValue(1); |
| 2307 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2308 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2309 | Offset = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Offset, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2310 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2311 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2312 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2313 | false, false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2314 | } else { |
| 2315 | // local exec model |
Hans Wennborg | fd5abd5 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2316 | assert(model == TLSModel::LocalExec); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2317 | ARMConstantPoolValue *CPV = |
| 2318 | ARMConstantPoolConstant::Create(GV, ARMCP::TPOFF); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2319 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2320 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2321 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2322 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2323 | false, false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2324 | } |
| 2325 | |
| 2326 | // The address of the thread local variable is the add of the thread |
| 2327 | // pointer with the offset of the variable. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2328 | return DAG.getNode(ISD::ADD, dl, PtrVT, ThreadPointer, Offset); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2329 | } |
| 2330 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2331 | SDValue |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2332 | ARMTargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const { |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2333 | // TODO: implement the "local dynamic" model |
| 2334 | assert(Subtarget->isTargetELF() && |
| 2335 | "TLS not implemented for non-ELF targets"); |
| 2336 | GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); |
Hans Wennborg | fd5abd5 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2337 | |
| 2338 | TLSModel::Model model = getTargetMachine().getTLSModel(GA->getGlobal()); |
| 2339 | |
| 2340 | switch (model) { |
| 2341 | case TLSModel::GeneralDynamic: |
| 2342 | case TLSModel::LocalDynamic: |
| 2343 | return LowerToTLSGeneralDynamicModel(GA, DAG); |
| 2344 | case TLSModel::InitialExec: |
| 2345 | case TLSModel::LocalExec: |
| 2346 | return LowerToTLSExecModels(GA, DAG, model); |
| 2347 | } |
Matt Beaumont-Gay | 39af944 | 2012-05-04 18:34:27 +0000 | [diff] [blame] | 2348 | llvm_unreachable("bogus TLS model"); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2349 | } |
| 2350 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2351 | SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2352 | SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2353 | EVT PtrVT = getPointerTy(); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 2354 | SDLoc dl(Op); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2355 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Chad Rosier | a6ca703 | 2013-02-28 19:16:42 +0000 | [diff] [blame] | 2356 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 2357 | bool UseGOTOFF = GV->hasLocalLinkage() || GV->hasHiddenVisibility(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2358 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2359 | ARMConstantPoolConstant::Create(GV, |
| 2360 | UseGOTOFF ? ARMCP::GOTOFF : ARMCP::GOT); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2361 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2362 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2363 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2364 | CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2365 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2366 | false, false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2367 | SDValue Chain = Result.getValue(1); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 2368 | SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(PtrVT); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2369 | Result = DAG.getNode(ISD::ADD, dl, PtrVT, Result, GOT); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2370 | if (!UseGOTOFF) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2371 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2372 | MachinePointerInfo::getGOT(), |
| 2373 | false, false, false, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2374 | return Result; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2375 | } |
| 2376 | |
| 2377 | // If we have T2 ops, we can materialize the address directly via movt/movw |
James Molloy | 015cca6 | 2011-10-26 08:53:19 +0000 | [diff] [blame] | 2378 | // pair. This is always cheaper. |
| 2379 | if (Subtarget->useMovt()) { |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2380 | ++NumMovwMovt; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2381 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2382 | // operands, expand this into two nodes. |
| 2383 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 2384 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2385 | } else { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2386 | SDValue CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
| 2387 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 2388 | return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
| 2389 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2390 | false, false, false, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2391 | } |
| 2392 | } |
| 2393 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2394 | SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2395 | SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2396 | EVT PtrVT = getPointerTy(); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 2397 | SDLoc dl(Op); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2398 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2399 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2400 | |
Jakob Stoklund Olesen | 8f37a24 | 2012-01-07 20:49:15 +0000 | [diff] [blame] | 2401 | // FIXME: Enable this for static codegen when tool issues are fixed. Also |
| 2402 | // update ARMFastISel::ARMMaterializeGV. |
Evan Cheng | f31151f | 2011-10-26 01:17:44 +0000 | [diff] [blame] | 2403 | if (Subtarget->useMovt() && RelocM != Reloc::Static) { |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2404 | ++NumMovwMovt; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2405 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2406 | // operands, expand this into two nodes. |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 2407 | if (RelocM == Reloc::Static) |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2408 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 2409 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
| 2410 | |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 2411 | unsigned Wrapper = (RelocM == Reloc::PIC_) |
| 2412 | ? ARMISD::WrapperPIC : ARMISD::WrapperDYN; |
| 2413 | SDValue Result = DAG.getNode(Wrapper, dl, PtrVT, |
Evan Cheng | 9fe2009 | 2011-01-20 08:34:58 +0000 | [diff] [blame] | 2414 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2415 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
| 2416 | Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Result, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2417 | MachinePointerInfo::getGOT(), |
| 2418 | false, false, false, 0); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2419 | return Result; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2420 | } |
| 2421 | |
| 2422 | unsigned ARMPCLabelIndex = 0; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2423 | SDValue CPAddr; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2424 | if (RelocM == Reloc::Static) { |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2425 | CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2426 | } else { |
Chad Rosier | a6ca703 | 2013-02-28 19:16:42 +0000 | [diff] [blame] | 2427 | ARMFunctionInfo *AFI = DAG.getMachineFunction().getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2428 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2429 | unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : (Subtarget->isThumb()?4:8); |
| 2430 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2431 | ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex, ARMCP::CPValue, |
| 2432 | PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2433 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2434 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2435 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2436 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2437 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2438 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2439 | false, false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2440 | SDValue Chain = Result.getValue(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2441 | |
| 2442 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2443 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2444 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2445 | } |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2446 | |
Evan Cheng | 63476a8 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 2447 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2448 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, MachinePointerInfo::getGOT(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2449 | false, false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2450 | |
| 2451 | return Result; |
| 2452 | } |
| 2453 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2454 | SDValue ARMTargetLowering::LowerGLOBAL_OFFSET_TABLE(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2455 | SelectionDAG &DAG) const { |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2456 | assert(Subtarget->isTargetELF() && |
| 2457 | "GLOBAL OFFSET TABLE not implemented for non-ELF targets"); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2458 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2459 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2460 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2461 | EVT PtrVT = getPointerTy(); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 2462 | SDLoc dl(Op); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2463 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Bill Wendling | fe31e67 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 2464 | ARMConstantPoolValue *CPV = |
| 2465 | ARMConstantPoolSymbol::Create(*DAG.getContext(), "_GLOBAL_OFFSET_TABLE_", |
| 2466 | ARMPCLabelIndex, PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2467 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2468 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2469 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2470 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2471 | false, false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2472 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2473 | return DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2474 | } |
| 2475 | |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2476 | SDValue |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2477 | ARMTargetLowering::LowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const { |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 2478 | SDLoc dl(Op); |
Jim Grosbach | 0798edd | 2010-05-27 23:49:24 +0000 | [diff] [blame] | 2479 | SDValue Val = DAG.getConstant(0, MVT::i32); |
Bill Wendling | ce370cf | 2011-10-07 21:25:38 +0000 | [diff] [blame] | 2480 | return DAG.getNode(ARMISD::EH_SJLJ_SETJMP, dl, |
| 2481 | DAG.getVTList(MVT::i32, MVT::Other), Op.getOperand(0), |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2482 | Op.getOperand(1), Val); |
| 2483 | } |
| 2484 | |
| 2485 | SDValue |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 2486 | ARMTargetLowering::LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const { |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 2487 | SDLoc dl(Op); |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 2488 | return DAG.getNode(ARMISD::EH_SJLJ_LONGJMP, dl, MVT::Other, Op.getOperand(0), |
| 2489 | Op.getOperand(1), DAG.getConstant(0, MVT::i32)); |
| 2490 | } |
| 2491 | |
| 2492 | SDValue |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 2493 | ARMTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG, |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2494 | const ARMSubtarget *Subtarget) const { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2495 | unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 2496 | SDLoc dl(Op); |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2497 | switch (IntNo) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2498 | default: return SDValue(); // Don't custom lower most intrinsics. |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2499 | case Intrinsic::arm_thread_pointer: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2500 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2501 | return DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
| 2502 | } |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2503 | case Intrinsic::eh_sjlj_lsda: { |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2504 | MachineFunction &MF = DAG.getMachineFunction(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2505 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2506 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2507 | EVT PtrVT = getPointerTy(); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2508 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2509 | SDValue CPAddr; |
| 2510 | unsigned PCAdj = (RelocM != Reloc::PIC_) |
| 2511 | ? 0 : (Subtarget->isThumb() ? 4 : 8); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2512 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2513 | ARMConstantPoolConstant::Create(MF.getFunction(), ARMPCLabelIndex, |
| 2514 | ARMCP::CPLSDA, PCAdj); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2515 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2516 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2517 | SDValue Result = |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2518 | DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2519 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2520 | false, false, false, 0); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2521 | |
| 2522 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2523 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2524 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
| 2525 | } |
| 2526 | return Result; |
| 2527 | } |
Evan Cheng | 92e3916 | 2011-03-29 23:06:19 +0000 | [diff] [blame] | 2528 | case Intrinsic::arm_neon_vmulls: |
| 2529 | case Intrinsic::arm_neon_vmullu: { |
| 2530 | unsigned NewOpc = (IntNo == Intrinsic::arm_neon_vmulls) |
| 2531 | ? ARMISD::VMULLs : ARMISD::VMULLu; |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 2532 | return DAG.getNode(NewOpc, SDLoc(Op), Op.getValueType(), |
Evan Cheng | 92e3916 | 2011-03-29 23:06:19 +0000 | [diff] [blame] | 2533 | Op.getOperand(1), Op.getOperand(2)); |
| 2534 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2535 | } |
| 2536 | } |
| 2537 | |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2538 | static SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG &DAG, |
| 2539 | const ARMSubtarget *Subtarget) { |
| 2540 | // FIXME: handle "fence singlethread" more efficiently. |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 2541 | SDLoc dl(Op); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2542 | if (!Subtarget->hasDataBarrier()) { |
| 2543 | // Some ARMv6 cpus can support data barriers with an mcr instruction. |
| 2544 | // Thumb1 and pre-v6 ARM mode use a libcall instead and should never get |
| 2545 | // here. |
| 2546 | assert(Subtarget->hasV6Ops() && !Subtarget->isThumb() && |
| 2547 | "Unexpected ISD::MEMBARRIER encountered. Should be libcall!"); |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2548 | return DAG.getNode(ARMISD::MEMBARRIER_MCR, dl, MVT::Other, Op.getOperand(0), |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2549 | DAG.getConstant(0, MVT::i32)); |
| 2550 | } |
| 2551 | |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2552 | return DAG.getNode(ARMISD::MEMBARRIER, dl, MVT::Other, Op.getOperand(0), |
Eli Friedman | 989f61e | 2011-08-02 22:44:16 +0000 | [diff] [blame] | 2553 | DAG.getConstant(ARM_MB::ISH, MVT::i32)); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2554 | } |
| 2555 | |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2556 | static SDValue LowerPREFETCH(SDValue Op, SelectionDAG &DAG, |
| 2557 | const ARMSubtarget *Subtarget) { |
| 2558 | // ARM pre v5TE and Thumb1 does not have preload instructions. |
| 2559 | if (!(Subtarget->isThumb2() || |
| 2560 | (!Subtarget->isThumb1Only() && Subtarget->hasV5TEOps()))) |
| 2561 | // Just preserve the chain. |
| 2562 | return Op.getOperand(0); |
| 2563 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 2564 | SDLoc dl(Op); |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2565 | unsigned isRead = ~cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue() & 1; |
| 2566 | if (!isRead && |
| 2567 | (!Subtarget->hasV7Ops() || !Subtarget->hasMPExtension())) |
| 2568 | // ARMv7 with MP extension has PLDW. |
| 2569 | return Op.getOperand(0); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2570 | |
Bruno Cardoso Lopes | 9a76733 | 2011-06-14 04:58:37 +0000 | [diff] [blame] | 2571 | unsigned isData = cast<ConstantSDNode>(Op.getOperand(4))->getZExtValue(); |
| 2572 | if (Subtarget->isThumb()) { |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2573 | // Invert the bits. |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2574 | isRead = ~isRead & 1; |
Bruno Cardoso Lopes | 9a76733 | 2011-06-14 04:58:37 +0000 | [diff] [blame] | 2575 | isData = ~isData & 1; |
| 2576 | } |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2577 | |
| 2578 | return DAG.getNode(ARMISD::PRELOAD, dl, MVT::Other, Op.getOperand(0), |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2579 | Op.getOperand(1), DAG.getConstant(isRead, MVT::i32), |
| 2580 | DAG.getConstant(isData, MVT::i32)); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2581 | } |
| 2582 | |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2583 | static SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) { |
| 2584 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2585 | ARMFunctionInfo *FuncInfo = MF.getInfo<ARMFunctionInfo>(); |
| 2586 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2587 | // vastart just stores the address of the VarArgsFrameIndex slot into the |
| 2588 | // memory location argument. |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 2589 | SDLoc dl(Op); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2590 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2591 | SDValue FR = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), PtrVT); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 2592 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 2593 | return DAG.getStore(Op.getOperand(0), dl, FR, Op.getOperand(1), |
| 2594 | MachinePointerInfo(SV), false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2595 | } |
| 2596 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2597 | SDValue |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2598 | ARMTargetLowering::GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA, |
| 2599 | SDValue &Root, SelectionDAG &DAG, |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 2600 | SDLoc dl) const { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2601 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2602 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2603 | |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2604 | const TargetRegisterClass *RC; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 2605 | if (AFI->isThumb1OnlyFunction()) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2606 | RC = &ARM::tGPRRegClass; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2607 | else |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2608 | RC = &ARM::GPRRegClass; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2609 | |
| 2610 | // Transform the arguments stored in physical registers into virtual ones. |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2611 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2612 | SDValue ArgValue = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2613 | |
| 2614 | SDValue ArgValue2; |
| 2615 | if (NextVA.isMemLoc()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2616 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2617 | int FI = MFI->CreateFixedObject(4, NextVA.getLocMemOffset(), true); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2618 | |
| 2619 | // Create load node to retrieve arguments from the stack. |
| 2620 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2621 | ArgValue2 = DAG.getLoad(MVT::i32, dl, Root, FIN, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2622 | MachinePointerInfo::getFixedStack(FI), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2623 | false, false, false, 0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2624 | } else { |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2625 | Reg = MF.addLiveIn(NextVA.getLocReg(), RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2626 | ArgValue2 = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2627 | } |
| 2628 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2629 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, ArgValue, ArgValue2); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2630 | } |
| 2631 | |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2632 | void |
| 2633 | ARMTargetLowering::computeRegArea(CCState &CCInfo, MachineFunction &MF, |
Stepan Dyatkovskiy | 46abfcf | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 2634 | unsigned InRegsParamRecordIdx, |
Stepan Dyatkovskiy | 083bc97 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 2635 | unsigned ArgSize, |
Stepan Dyatkovskiy | f65e493 | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2636 | unsigned &ArgRegsSize, |
| 2637 | unsigned &ArgRegsSaveSize) |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2638 | const { |
| 2639 | unsigned NumGPRs; |
Stepan Dyatkovskiy | 46abfcf | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 2640 | if (InRegsParamRecordIdx < CCInfo.getInRegsParamsCount()) { |
| 2641 | unsigned RBegin, REnd; |
| 2642 | CCInfo.getInRegsParamInfo(InRegsParamRecordIdx, RBegin, REnd); |
| 2643 | NumGPRs = REnd - RBegin; |
| 2644 | } else { |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2645 | unsigned int firstUnalloced; |
| 2646 | firstUnalloced = CCInfo.getFirstUnallocated(GPRArgRegs, |
| 2647 | sizeof(GPRArgRegs) / |
| 2648 | sizeof(GPRArgRegs[0])); |
| 2649 | NumGPRs = (firstUnalloced <= 3) ? (4 - firstUnalloced) : 0; |
| 2650 | } |
| 2651 | |
| 2652 | unsigned Align = MF.getTarget().getFrameLowering()->getStackAlignment(); |
Stepan Dyatkovskiy | f65e493 | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2653 | ArgRegsSize = NumGPRs * 4; |
Stepan Dyatkovskiy | 083bc97 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 2654 | |
| 2655 | // If parameter is split between stack and GPRs... |
| 2656 | if (NumGPRs && Align == 8 && |
| 2657 | (ArgRegsSize < ArgSize || |
| 2658 | InRegsParamRecordIdx >= CCInfo.getInRegsParamsCount())) { |
| 2659 | // Add padding for part of param recovered from GPRs, so |
| 2660 | // its last byte must be at address K*8 - 1. |
| 2661 | // We need to do it, since remained (stack) part of parameter has |
| 2662 | // stack alignment, and we need to "attach" "GPRs head" without gaps |
| 2663 | // to it: |
| 2664 | // Stack: |
| 2665 | // |---- 8 bytes block ----| |---- 8 bytes block ----| |---- 8 bytes... |
| 2666 | // [ [padding] [GPRs head] ] [ Tail passed via stack .... |
| 2667 | // |
| 2668 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2669 | unsigned Padding = |
| 2670 | ((ArgRegsSize + AFI->getArgRegsSaveSize() + Align - 1) & ~(Align-1)) - |
| 2671 | (ArgRegsSize + AFI->getArgRegsSaveSize()); |
| 2672 | ArgRegsSaveSize = ArgRegsSize + Padding; |
| 2673 | } else |
| 2674 | // We don't need to extend regs save size for byval parameters if they |
| 2675 | // are passed via GPRs only. |
| 2676 | ArgRegsSaveSize = ArgRegsSize; |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2677 | } |
| 2678 | |
| 2679 | // The remaining GPRs hold either the beginning of variable-argument |
David Peixotto | e68542e | 2013-02-13 00:36:35 +0000 | [diff] [blame] | 2680 | // data, or the beginning of an aggregate passed by value (usually |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2681 | // byval). Either way, we allocate stack slots adjacent to the data |
| 2682 | // provided by our caller, and store the unallocated registers there. |
| 2683 | // If this is a variadic function, the va_list pointer will begin with |
| 2684 | // these values; otherwise, this reassembles a (byval) structure that |
| 2685 | // was split between registers and memory. |
Stepan Dyatkovskiy | f65e493 | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2686 | // Return: The frame index registers were stored into. |
| 2687 | int |
| 2688 | ARMTargetLowering::StoreByValRegs(CCState &CCInfo, SelectionDAG &DAG, |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 2689 | SDLoc dl, SDValue &Chain, |
Stepan Dyatkovskiy | f65e493 | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2690 | const Value *OrigArg, |
Stepan Dyatkovskiy | 46abfcf | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 2691 | unsigned InRegsParamRecordIdx, |
Stepan Dyatkovskiy | f65e493 | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2692 | unsigned OffsetFromOrigArg, |
| 2693 | unsigned ArgOffset, |
Stepan Dyatkovskiy | 083bc97 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 2694 | unsigned ArgSize, |
Stepan Dyatkovskiy | f65e493 | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2695 | bool ForceMutable) const { |
| 2696 | |
| 2697 | // Currently, two use-cases possible: |
| 2698 | // Case #1. Non var-args function, and we meet first byval parameter. |
| 2699 | // Setup first unallocated register as first byval register; |
| 2700 | // eat all remained registers |
| 2701 | // (these two actions are performed by HandleByVal method). |
| 2702 | // Then, here, we initialize stack frame with |
| 2703 | // "store-reg" instructions. |
| 2704 | // Case #2. Var-args function, that doesn't contain byval parameters. |
| 2705 | // The same: eat all remained unallocated registers, |
| 2706 | // initialize stack frame. |
| 2707 | |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2708 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2709 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 2710 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Stepan Dyatkovskiy | 46abfcf | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 2711 | unsigned firstRegToSaveIndex, lastRegToSaveIndex; |
| 2712 | unsigned RBegin, REnd; |
| 2713 | if (InRegsParamRecordIdx < CCInfo.getInRegsParamsCount()) { |
| 2714 | CCInfo.getInRegsParamInfo(InRegsParamRecordIdx, RBegin, REnd); |
| 2715 | firstRegToSaveIndex = RBegin - ARM::R0; |
| 2716 | lastRegToSaveIndex = REnd - ARM::R0; |
| 2717 | } else { |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2718 | firstRegToSaveIndex = CCInfo.getFirstUnallocated |
| 2719 | (GPRArgRegs, sizeof(GPRArgRegs) / sizeof(GPRArgRegs[0])); |
Stepan Dyatkovskiy | 46abfcf | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 2720 | lastRegToSaveIndex = 4; |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2721 | } |
| 2722 | |
Stepan Dyatkovskiy | f65e493 | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2723 | unsigned ArgRegsSize, ArgRegsSaveSize; |
Stepan Dyatkovskiy | 083bc97 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 2724 | computeRegArea(CCInfo, MF, InRegsParamRecordIdx, ArgSize, |
| 2725 | ArgRegsSize, ArgRegsSaveSize); |
Stepan Dyatkovskiy | f65e493 | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2726 | |
| 2727 | // Store any by-val regs to their spots on the stack so that they may be |
| 2728 | // loaded by deferencing the result of formal parameter pointer or va_next. |
| 2729 | // Note: once stack area for byval/varargs registers |
| 2730 | // was initialized, it can't be initialized again. |
Stepan Dyatkovskiy | 46abfcf | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 2731 | if (ArgRegsSaveSize) { |
Stepan Dyatkovskiy | f65e493 | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2732 | |
Stepan Dyatkovskiy | 083bc97 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 2733 | unsigned Padding = ArgRegsSaveSize - ArgRegsSize; |
| 2734 | |
| 2735 | if (Padding) { |
| 2736 | assert(AFI->getStoredByValParamsPadding() == 0 && |
| 2737 | "The only parameter may be padded."); |
| 2738 | AFI->setStoredByValParamsPadding(Padding); |
| 2739 | } |
| 2740 | |
Stepan Dyatkovskiy | f65e493 | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2741 | int FrameIndex = MFI->CreateFixedObject( |
| 2742 | ArgRegsSaveSize, |
Stepan Dyatkovskiy | 083bc97 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 2743 | Padding + ArgOffset, |
Stepan Dyatkovskiy | f65e493 | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2744 | false); |
| 2745 | SDValue FIN = DAG.getFrameIndex(FrameIndex, getPointerTy()); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2746 | |
| 2747 | SmallVector<SDValue, 4> MemOps; |
Stepan Dyatkovskiy | 46abfcf | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 2748 | for (unsigned i = 0; firstRegToSaveIndex < lastRegToSaveIndex; |
| 2749 | ++firstRegToSaveIndex, ++i) { |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2750 | const TargetRegisterClass *RC; |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2751 | if (AFI->isThumb1OnlyFunction()) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2752 | RC = &ARM::tGPRRegClass; |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2753 | else |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2754 | RC = &ARM::GPRRegClass; |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2755 | |
| 2756 | unsigned VReg = MF.addLiveIn(GPRArgRegs[firstRegToSaveIndex], RC); |
| 2757 | SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i32); |
| 2758 | SDValue Store = |
| 2759 | DAG.getStore(Val.getValue(1), dl, Val, FIN, |
Stepan Dyatkovskiy | 661afe7 | 2012-10-10 11:37:36 +0000 | [diff] [blame] | 2760 | MachinePointerInfo(OrigArg, OffsetFromOrigArg + 4*i), |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2761 | false, false, 0); |
| 2762 | MemOps.push_back(Store); |
| 2763 | FIN = DAG.getNode(ISD::ADD, dl, getPointerTy(), FIN, |
| 2764 | DAG.getConstant(4, getPointerTy())); |
| 2765 | } |
Stepan Dyatkovskiy | 46abfcf | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 2766 | |
| 2767 | AFI->setArgRegsSaveSize(ArgRegsSaveSize + AFI->getArgRegsSaveSize()); |
| 2768 | |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2769 | if (!MemOps.empty()) |
| 2770 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
| 2771 | &MemOps[0], MemOps.size()); |
Stepan Dyatkovskiy | f65e493 | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2772 | return FrameIndex; |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2773 | } else |
| 2774 | // This will point to the next argument passed via stack. |
Stepan Dyatkovskiy | 083bc97 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 2775 | return MFI->CreateFixedObject( |
| 2776 | 4, AFI->getStoredByValParamsPadding() + ArgOffset, !ForceMutable); |
Stepan Dyatkovskiy | f65e493 | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | // Setup stack frame, the va_list pointer will start from. |
| 2780 | void |
| 2781 | ARMTargetLowering::VarArgStyleRegisters(CCState &CCInfo, SelectionDAG &DAG, |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 2782 | SDLoc dl, SDValue &Chain, |
Stepan Dyatkovskiy | f65e493 | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2783 | unsigned ArgOffset, |
| 2784 | bool ForceMutable) const { |
| 2785 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2786 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2787 | |
| 2788 | // Try to store any remaining integer argument regs |
| 2789 | // to their spots on the stack so that they may be loaded by deferencing |
| 2790 | // the result of va_next. |
| 2791 | // If there is no regs to be stored, just point address after last |
| 2792 | // argument passed via stack. |
| 2793 | int FrameIndex = |
Stepan Dyatkovskiy | 46abfcf | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 2794 | StoreByValRegs(CCInfo, DAG, dl, Chain, 0, CCInfo.getInRegsParamsCount(), |
Stepan Dyatkovskiy | 083bc97 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 2795 | 0, ArgOffset, 0, ForceMutable); |
Stepan Dyatkovskiy | f65e493 | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2796 | |
| 2797 | AFI->setVarArgsFrameIndex(FrameIndex); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2798 | } |
| 2799 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2800 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2801 | ARMTargetLowering::LowerFormalArguments(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 2802 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2803 | const SmallVectorImpl<ISD::InputArg> |
| 2804 | &Ins, |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 2805 | SDLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2806 | SmallVectorImpl<SDValue> &InVals) |
| 2807 | const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2808 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2809 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 2810 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2811 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2812 | |
| 2813 | // Assign locations to all of the incoming arguments. |
| 2814 | SmallVector<CCValAssign, 16> ArgLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 2815 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 2816 | getTargetMachine(), ArgLocs, *DAG.getContext(), Prologue); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2817 | CCInfo.AnalyzeFormalArguments(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2818 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 2819 | isVarArg)); |
Jim Grosbach | 7ccf463 | 2013-03-02 20:16:15 +0000 | [diff] [blame] | 2820 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2821 | SmallVector<SDValue, 16> ArgValues; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2822 | int lastInsIndex = -1; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2823 | SDValue ArgValue; |
Stepan Dyatkovskiy | 661afe7 | 2012-10-10 11:37:36 +0000 | [diff] [blame] | 2824 | Function::const_arg_iterator CurOrigArg = MF.getFunction()->arg_begin(); |
| 2825 | unsigned CurArgIdx = 0; |
Stepan Dyatkovskiy | 46abfcf | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 2826 | |
| 2827 | // Initially ArgRegsSaveSize is zero. |
| 2828 | // Then we increase this value each time we meet byval parameter. |
| 2829 | // We also increase this value in case of varargs function. |
| 2830 | AFI->setArgRegsSaveSize(0); |
| 2831 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2832 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 2833 | CCValAssign &VA = ArgLocs[i]; |
Stepan Dyatkovskiy | 661afe7 | 2012-10-10 11:37:36 +0000 | [diff] [blame] | 2834 | std::advance(CurOrigArg, Ins[VA.getValNo()].OrigArgIndex - CurArgIdx); |
| 2835 | CurArgIdx = Ins[VA.getValNo()].OrigArgIndex; |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2836 | // Arguments stored in registers. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2837 | if (VA.isRegLoc()) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2838 | EVT RegVT = VA.getLocVT(); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2839 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2840 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2841 | // f64 and vector types are split up into multiple registers or |
| 2842 | // combinations of registers and stack slots. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2843 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2844 | SDValue ArgValue1 = GetF64FormalArgument(VA, ArgLocs[++i], |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2845 | Chain, DAG, dl); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2846 | VA = ArgLocs[++i]; // skip ahead to next loc |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2847 | SDValue ArgValue2; |
| 2848 | if (VA.isMemLoc()) { |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2849 | int FI = MFI->CreateFixedObject(8, VA.getLocMemOffset(), true); |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2850 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 2851 | ArgValue2 = DAG.getLoad(MVT::f64, dl, Chain, FIN, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2852 | MachinePointerInfo::getFixedStack(FI), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2853 | false, false, false, 0); |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2854 | } else { |
| 2855 | ArgValue2 = GetF64FormalArgument(VA, ArgLocs[++i], |
| 2856 | Chain, DAG, dl); |
| 2857 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2858 | ArgValue = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 2859 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2860 | ArgValue, ArgValue1, DAG.getIntPtrConstant(0)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2861 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2862 | ArgValue, ArgValue2, DAG.getIntPtrConstant(1)); |
| 2863 | } else |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2864 | ArgValue = GetF64FormalArgument(VA, ArgLocs[++i], Chain, DAG, dl); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2865 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2866 | } else { |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2867 | const TargetRegisterClass *RC; |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2868 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2869 | if (RegVT == MVT::f32) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2870 | RC = &ARM::SPRRegClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2871 | else if (RegVT == MVT::f64) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2872 | RC = &ARM::DPRRegClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2873 | else if (RegVT == MVT::v2f64) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2874 | RC = &ARM::QPRRegClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2875 | else if (RegVT == MVT::i32) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2876 | RC = AFI->isThumb1OnlyFunction() ? |
| 2877 | (const TargetRegisterClass*)&ARM::tGPRRegClass : |
| 2878 | (const TargetRegisterClass*)&ARM::GPRRegClass; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2879 | else |
Anton Korobeynikov | 058c251 | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 2880 | llvm_unreachable("RegVT not supported by FORMAL_ARGUMENTS Lowering"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2881 | |
| 2882 | // Transform the arguments in physical registers into virtual ones. |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2883 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2884 | ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, RegVT); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2885 | } |
| 2886 | |
| 2887 | // If this is an 8 or 16-bit value, it is really passed promoted |
| 2888 | // to 32 bits. Insert an assert[sz]ext to capture this, then |
| 2889 | // truncate to the right size. |
| 2890 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2891 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2892 | case CCValAssign::Full: break; |
| 2893 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2894 | ArgValue = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), ArgValue); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2895 | break; |
| 2896 | case CCValAssign::SExt: |
| 2897 | ArgValue = DAG.getNode(ISD::AssertSext, dl, RegVT, ArgValue, |
| 2898 | DAG.getValueType(VA.getValVT())); |
| 2899 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 2900 | break; |
| 2901 | case CCValAssign::ZExt: |
| 2902 | ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue, |
| 2903 | DAG.getValueType(VA.getValVT())); |
| 2904 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 2905 | break; |
| 2906 | } |
| 2907 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2908 | InVals.push_back(ArgValue); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2909 | |
| 2910 | } else { // VA.isRegLoc() |
| 2911 | |
| 2912 | // sanity check |
| 2913 | assert(VA.isMemLoc()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2914 | assert(VA.getValVT() != MVT::i64 && "i64 should already be lowered"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2915 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2916 | int index = ArgLocs[i].getValNo(); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 2917 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2918 | // Some Ins[] entries become multiple ArgLoc[] entries. |
| 2919 | // Process them only once. |
| 2920 | if (index != lastInsIndex) |
| 2921 | { |
| 2922 | ISD::ArgFlagsTy Flags = Ins[index].Flags; |
Eric Christopher | 471e422 | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 2923 | // FIXME: For now, all byval parameter objects are marked mutable. |
Eric Christopher | 5ac179c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 2924 | // This can be changed with more analysis. |
| 2925 | // In case of tail call optimization mark all arguments mutable. |
| 2926 | // Since they could be overwritten by lowering of arguments in case of |
| 2927 | // a tail call. |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2928 | if (Flags.isByVal()) { |
Stepan Dyatkovskiy | 46abfcf | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 2929 | unsigned CurByValIndex = CCInfo.getInRegsParamsProceed(); |
Stepan Dyatkovskiy | f65e493 | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2930 | int FrameIndex = StoreByValRegs( |
Stepan Dyatkovskiy | 46abfcf | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 2931 | CCInfo, DAG, dl, Chain, CurOrigArg, |
| 2932 | CurByValIndex, |
| 2933 | Ins[VA.getValNo()].PartOffset, |
| 2934 | VA.getLocMemOffset(), |
Stepan Dyatkovskiy | 083bc97 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 2935 | Flags.getByValSize(), |
Stepan Dyatkovskiy | 46abfcf | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 2936 | true /*force mutable frames*/); |
Stepan Dyatkovskiy | f65e493 | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2937 | InVals.push_back(DAG.getFrameIndex(FrameIndex, getPointerTy())); |
Stepan Dyatkovskiy | 46abfcf | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 2938 | CCInfo.nextInRegsParam(); |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2939 | } else { |
Stepan Dyatkovskiy | 083bc97 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 2940 | unsigned FIOffset = VA.getLocMemOffset() + |
| 2941 | AFI->getStoredByValParamsPadding(); |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2942 | int FI = MFI->CreateFixedObject(VA.getLocVT().getSizeInBits()/8, |
Stepan Dyatkovskiy | 083bc97 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 2943 | FIOffset, true); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2944 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2945 | // Create load nodes to retrieve arguments from the stack. |
| 2946 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 2947 | InVals.push_back(DAG.getLoad(VA.getValVT(), dl, Chain, FIN, |
| 2948 | MachinePointerInfo::getFixedStack(FI), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2949 | false, false, false, 0)); |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2950 | } |
| 2951 | lastInsIndex = index; |
| 2952 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2953 | } |
| 2954 | } |
| 2955 | |
| 2956 | // varargs |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2957 | if (isVarArg) |
Stepan Dyatkovskiy | f65e493 | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2958 | VarArgStyleRegisters(CCInfo, DAG, dl, Chain, |
Stepan Dyatkovskiy | 661afe7 | 2012-10-10 11:37:36 +0000 | [diff] [blame] | 2959 | CCInfo.getNextStackOffset()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2960 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2961 | return Chain; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2962 | } |
| 2963 | |
| 2964 | /// isFloatingPointZero - Return true if this is +0.0. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2965 | static bool isFloatingPointZero(SDValue Op) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2966 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op)) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 2967 | return CFP->getValueAPF().isPosZero(); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2968 | else if (ISD::isEXTLoad(Op.getNode()) || ISD::isNON_EXTLoad(Op.getNode())) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2969 | // Maybe this has already been legalized into the constant pool? |
| 2970 | if (Op.getOperand(1).getOpcode() == ARMISD::Wrapper) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2971 | SDValue WrapperOp = Op.getOperand(1).getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2972 | if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(WrapperOp)) |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2973 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal())) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 2974 | return CFP->getValueAPF().isPosZero(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2975 | } |
| 2976 | } |
| 2977 | return false; |
| 2978 | } |
| 2979 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2980 | /// Returns appropriate ARM CMP (cmp) and corresponding condition code for |
| 2981 | /// the given operands. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2982 | SDValue |
| 2983 | ARMTargetLowering::getARMCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2984 | SDValue &ARMcc, SelectionDAG &DAG, |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 2985 | SDLoc dl) const { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2986 | if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS.getNode())) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2987 | unsigned C = RHSC->getZExtValue(); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2988 | if (!isLegalICmpImmediate(C)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2989 | // Constant does not fit, try adjusting it by one? |
| 2990 | switch (CC) { |
| 2991 | default: break; |
| 2992 | case ISD::SETLT: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2993 | case ISD::SETGE: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2994 | if (C != 0x80000000 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2995 | CC = (CC == ISD::SETLT) ? ISD::SETLE : ISD::SETGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2996 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2997 | } |
| 2998 | break; |
| 2999 | case ISD::SETULT: |
| 3000 | case ISD::SETUGE: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 3001 | if (C != 0 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 3002 | CC = (CC == ISD::SETULT) ? ISD::SETULE : ISD::SETUGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3003 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3004 | } |
| 3005 | break; |
| 3006 | case ISD::SETLE: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3007 | case ISD::SETGT: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 3008 | if (C != 0x7fffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 3009 | CC = (CC == ISD::SETLE) ? ISD::SETLT : ISD::SETGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3010 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 3011 | } |
| 3012 | break; |
| 3013 | case ISD::SETULE: |
| 3014 | case ISD::SETUGT: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 3015 | if (C != 0xffffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 3016 | CC = (CC == ISD::SETULE) ? ISD::SETULT : ISD::SETUGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3017 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3018 | } |
| 3019 | break; |
| 3020 | } |
| 3021 | } |
| 3022 | } |
| 3023 | |
| 3024 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 3025 | ARMISD::NodeType CompareType; |
| 3026 | switch (CondCode) { |
| 3027 | default: |
| 3028 | CompareType = ARMISD::CMP; |
| 3029 | break; |
| 3030 | case ARMCC::EQ: |
| 3031 | case ARMCC::NE: |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 3032 | // Uses only Z Flag |
| 3033 | CompareType = ARMISD::CMPZ; |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 3034 | break; |
| 3035 | } |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3036 | ARMcc = DAG.getConstant(CondCode, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3037 | return DAG.getNode(CompareType, dl, MVT::Glue, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3038 | } |
| 3039 | |
| 3040 | /// Returns a appropriate VFP CMP (fcmp{s|d}+fmstat) for the given operands. |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 3041 | SDValue |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3042 | ARMTargetLowering::getVFPCmp(SDValue LHS, SDValue RHS, SelectionDAG &DAG, |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3043 | SDLoc dl) const { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3044 | SDValue Cmp; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3045 | if (!isFloatingPointZero(RHS)) |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3046 | Cmp = DAG.getNode(ARMISD::CMPFP, dl, MVT::Glue, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3047 | else |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3048 | Cmp = DAG.getNode(ARMISD::CMPFPw0, dl, MVT::Glue, LHS); |
| 3049 | return DAG.getNode(ARMISD::FMSTAT, dl, MVT::Glue, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3050 | } |
| 3051 | |
Bob Wilson | 79f56c9 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 3052 | /// duplicateCmp - Glue values can have only one use, so this function |
| 3053 | /// duplicates a comparison node. |
| 3054 | SDValue |
| 3055 | ARMTargetLowering::duplicateCmp(SDValue Cmp, SelectionDAG &DAG) const { |
| 3056 | unsigned Opc = Cmp.getOpcode(); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3057 | SDLoc DL(Cmp); |
Bob Wilson | 79f56c9 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 3058 | if (Opc == ARMISD::CMP || Opc == ARMISD::CMPZ) |
| 3059 | return DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); |
| 3060 | |
| 3061 | assert(Opc == ARMISD::FMSTAT && "unexpected comparison operation"); |
| 3062 | Cmp = Cmp.getOperand(0); |
| 3063 | Opc = Cmp.getOpcode(); |
| 3064 | if (Opc == ARMISD::CMPFP) |
| 3065 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); |
| 3066 | else { |
| 3067 | assert(Opc == ARMISD::CMPFPw0 && "unexpected operand of FMSTAT"); |
| 3068 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0)); |
| 3069 | } |
| 3070 | return DAG.getNode(ARMISD::FMSTAT, DL, MVT::Glue, Cmp); |
| 3071 | } |
| 3072 | |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 3073 | SDValue ARMTargetLowering::LowerSELECT(SDValue Op, SelectionDAG &DAG) const { |
| 3074 | SDValue Cond = Op.getOperand(0); |
| 3075 | SDValue SelectTrue = Op.getOperand(1); |
| 3076 | SDValue SelectFalse = Op.getOperand(2); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3077 | SDLoc dl(Op); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 3078 | |
| 3079 | // Convert: |
| 3080 | // |
| 3081 | // (select (cmov 1, 0, cond), t, f) -> (cmov t, f, cond) |
| 3082 | // (select (cmov 0, 1, cond), t, f) -> (cmov f, t, cond) |
| 3083 | // |
| 3084 | if (Cond.getOpcode() == ARMISD::CMOV && Cond.hasOneUse()) { |
| 3085 | const ConstantSDNode *CMOVTrue = |
| 3086 | dyn_cast<ConstantSDNode>(Cond.getOperand(0)); |
| 3087 | const ConstantSDNode *CMOVFalse = |
| 3088 | dyn_cast<ConstantSDNode>(Cond.getOperand(1)); |
| 3089 | |
| 3090 | if (CMOVTrue && CMOVFalse) { |
| 3091 | unsigned CMOVTrueVal = CMOVTrue->getZExtValue(); |
| 3092 | unsigned CMOVFalseVal = CMOVFalse->getZExtValue(); |
| 3093 | |
| 3094 | SDValue True; |
| 3095 | SDValue False; |
| 3096 | if (CMOVTrueVal == 1 && CMOVFalseVal == 0) { |
| 3097 | True = SelectTrue; |
| 3098 | False = SelectFalse; |
| 3099 | } else if (CMOVTrueVal == 0 && CMOVFalseVal == 1) { |
| 3100 | True = SelectFalse; |
| 3101 | False = SelectTrue; |
| 3102 | } |
| 3103 | |
| 3104 | if (True.getNode() && False.getNode()) { |
Evan Cheng | b936e30 | 2011-05-18 18:59:17 +0000 | [diff] [blame] | 3105 | EVT VT = Op.getValueType(); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 3106 | SDValue ARMcc = Cond.getOperand(2); |
| 3107 | SDValue CCR = Cond.getOperand(3); |
Bob Wilson | 79f56c9 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 3108 | SDValue Cmp = duplicateCmp(Cond.getOperand(4), DAG); |
Evan Cheng | b936e30 | 2011-05-18 18:59:17 +0000 | [diff] [blame] | 3109 | assert(True.getValueType() == VT); |
| 3110 | return DAG.getNode(ARMISD::CMOV, dl, VT, True, False, ARMcc, CCR, Cmp); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 3111 | } |
| 3112 | } |
| 3113 | } |
| 3114 | |
Dan Gohman | db95389 | 2012-02-24 00:09:36 +0000 | [diff] [blame] | 3115 | // ARM's BooleanContents value is UndefinedBooleanContent. Mask out the |
| 3116 | // undefined bits before doing a full-word comparison with zero. |
| 3117 | Cond = DAG.getNode(ISD::AND, dl, Cond.getValueType(), Cond, |
| 3118 | DAG.getConstant(1, Cond.getValueType())); |
| 3119 | |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 3120 | return DAG.getSelectCC(dl, Cond, |
| 3121 | DAG.getConstant(0, Cond.getValueType()), |
| 3122 | SelectTrue, SelectFalse, ISD::SETNE); |
| 3123 | } |
| 3124 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3125 | SDValue ARMTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3126 | EVT VT = Op.getValueType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3127 | SDValue LHS = Op.getOperand(0); |
| 3128 | SDValue RHS = Op.getOperand(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3129 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3130 | SDValue TrueVal = Op.getOperand(2); |
| 3131 | SDValue FalseVal = Op.getOperand(3); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3132 | SDLoc dl(Op); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3133 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3134 | if (LHS.getValueType() == MVT::i32) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3135 | SDValue ARMcc; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3136 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3137 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
Jim Grosbach | b04546f | 2011-09-13 20:30:37 +0000 | [diff] [blame] | 3138 | return DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, CCR,Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3139 | } |
| 3140 | |
| 3141 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 3142 | FPCCToARMCC(CC, CondCode, CondCode2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3143 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3144 | SDValue ARMcc = DAG.getConstant(CondCode, MVT::i32); |
| 3145 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3146 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3147 | SDValue Result = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3148 | ARMcc, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3149 | if (CondCode2 != ARMCC::AL) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3150 | SDValue ARMcc2 = DAG.getConstant(CondCode2, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3151 | // FIXME: Needs another CMP because flag can have but one use. |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3152 | SDValue Cmp2 = getVFPCmp(LHS, RHS, DAG, dl); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3153 | Result = DAG.getNode(ARMISD::CMOV, dl, VT, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3154 | Result, TrueVal, ARMcc2, CCR, Cmp2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3155 | } |
| 3156 | return Result; |
| 3157 | } |
| 3158 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3159 | /// canChangeToInt - Given the fp compare operand, return true if it is suitable |
| 3160 | /// to morph to an integer compare sequence. |
| 3161 | static bool canChangeToInt(SDValue Op, bool &SeenZero, |
| 3162 | const ARMSubtarget *Subtarget) { |
| 3163 | SDNode *N = Op.getNode(); |
| 3164 | if (!N->hasOneUse()) |
| 3165 | // Otherwise it requires moving the value from fp to integer registers. |
| 3166 | return false; |
| 3167 | if (!N->getNumValues()) |
| 3168 | return false; |
| 3169 | EVT VT = Op.getValueType(); |
| 3170 | if (VT != MVT::f32 && !Subtarget->isFPBrccSlow()) |
| 3171 | // f32 case is generally profitable. f64 case only makes sense when vcmpe + |
| 3172 | // vmrs are very slow, e.g. cortex-a8. |
| 3173 | return false; |
| 3174 | |
| 3175 | if (isFloatingPointZero(Op)) { |
| 3176 | SeenZero = true; |
| 3177 | return true; |
| 3178 | } |
| 3179 | return ISD::isNormalLoad(N); |
| 3180 | } |
| 3181 | |
| 3182 | static SDValue bitcastf32Toi32(SDValue Op, SelectionDAG &DAG) { |
| 3183 | if (isFloatingPointZero(Op)) |
| 3184 | return DAG.getConstant(0, MVT::i32); |
| 3185 | |
| 3186 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3187 | return DAG.getLoad(MVT::i32, SDLoc(Op), |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3188 | Ld->getChain(), Ld->getBasePtr(), Ld->getPointerInfo(), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3189 | Ld->isVolatile(), Ld->isNonTemporal(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3190 | Ld->isInvariant(), Ld->getAlignment()); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3191 | |
| 3192 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 3193 | } |
| 3194 | |
| 3195 | static void expandf64Toi32(SDValue Op, SelectionDAG &DAG, |
| 3196 | SDValue &RetVal1, SDValue &RetVal2) { |
| 3197 | if (isFloatingPointZero(Op)) { |
| 3198 | RetVal1 = DAG.getConstant(0, MVT::i32); |
| 3199 | RetVal2 = DAG.getConstant(0, MVT::i32); |
| 3200 | return; |
| 3201 | } |
| 3202 | |
| 3203 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) { |
| 3204 | SDValue Ptr = Ld->getBasePtr(); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3205 | RetVal1 = DAG.getLoad(MVT::i32, SDLoc(Op), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3206 | Ld->getChain(), Ptr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3207 | Ld->getPointerInfo(), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3208 | Ld->isVolatile(), Ld->isNonTemporal(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3209 | Ld->isInvariant(), Ld->getAlignment()); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3210 | |
| 3211 | EVT PtrType = Ptr.getValueType(); |
| 3212 | unsigned NewAlign = MinAlign(Ld->getAlignment(), 4); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3213 | SDValue NewPtr = DAG.getNode(ISD::ADD, SDLoc(Op), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3214 | PtrType, Ptr, DAG.getConstant(4, PtrType)); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3215 | RetVal2 = DAG.getLoad(MVT::i32, SDLoc(Op), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3216 | Ld->getChain(), NewPtr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3217 | Ld->getPointerInfo().getWithOffset(4), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3218 | Ld->isVolatile(), Ld->isNonTemporal(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3219 | Ld->isInvariant(), NewAlign); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3220 | return; |
| 3221 | } |
| 3222 | |
| 3223 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 3224 | } |
| 3225 | |
| 3226 | /// OptimizeVFPBrcond - With -enable-unsafe-fp-math, it's legal to optimize some |
| 3227 | /// f32 and even f64 comparisons to integer ones. |
| 3228 | SDValue |
| 3229 | ARMTargetLowering::OptimizeVFPBrcond(SDValue Op, SelectionDAG &DAG) const { |
| 3230 | SDValue Chain = Op.getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3231 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3232 | SDValue LHS = Op.getOperand(2); |
| 3233 | SDValue RHS = Op.getOperand(3); |
| 3234 | SDValue Dest = Op.getOperand(4); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3235 | SDLoc dl(Op); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3236 | |
Evan Cheng | fc501a3 | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3237 | bool LHSSeenZero = false; |
| 3238 | bool LHSOk = canChangeToInt(LHS, LHSSeenZero, Subtarget); |
| 3239 | bool RHSSeenZero = false; |
| 3240 | bool RHSOk = canChangeToInt(RHS, RHSSeenZero, Subtarget); |
| 3241 | if (LHSOk && RHSOk && (LHSSeenZero || RHSSeenZero)) { |
Bob Wilson | 1b772f9 | 2011-03-08 01:17:16 +0000 | [diff] [blame] | 3242 | // If unsafe fp math optimization is enabled and there are no other uses of |
| 3243 | // the CMP operands, and the condition code is EQ or NE, we can optimize it |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3244 | // to an integer comparison. |
| 3245 | if (CC == ISD::SETOEQ) |
| 3246 | CC = ISD::SETEQ; |
| 3247 | else if (CC == ISD::SETUNE) |
| 3248 | CC = ISD::SETNE; |
| 3249 | |
Evan Cheng | fc501a3 | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3250 | SDValue Mask = DAG.getConstant(0x7fffffff, MVT::i32); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3251 | SDValue ARMcc; |
| 3252 | if (LHS.getValueType() == MVT::f32) { |
Evan Cheng | fc501a3 | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3253 | LHS = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 3254 | bitcastf32Toi32(LHS, DAG), Mask); |
| 3255 | RHS = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 3256 | bitcastf32Toi32(RHS, DAG), Mask); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3257 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
| 3258 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3259 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
| 3260 | Chain, Dest, ARMcc, CCR, Cmp); |
| 3261 | } |
| 3262 | |
| 3263 | SDValue LHS1, LHS2; |
| 3264 | SDValue RHS1, RHS2; |
| 3265 | expandf64Toi32(LHS, DAG, LHS1, LHS2); |
| 3266 | expandf64Toi32(RHS, DAG, RHS1, RHS2); |
Evan Cheng | fc501a3 | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3267 | LHS2 = DAG.getNode(ISD::AND, dl, MVT::i32, LHS2, Mask); |
| 3268 | RHS2 = DAG.getNode(ISD::AND, dl, MVT::i32, RHS2, Mask); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3269 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
| 3270 | ARMcc = DAG.getConstant(CondCode, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3271 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3272 | SDValue Ops[] = { Chain, ARMcc, LHS1, LHS2, RHS1, RHS2, Dest }; |
| 3273 | return DAG.getNode(ARMISD::BCC_i64, dl, VTList, Ops, 7); |
| 3274 | } |
| 3275 | |
| 3276 | return SDValue(); |
| 3277 | } |
| 3278 | |
| 3279 | SDValue ARMTargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) const { |
| 3280 | SDValue Chain = Op.getOperand(0); |
| 3281 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
| 3282 | SDValue LHS = Op.getOperand(2); |
| 3283 | SDValue RHS = Op.getOperand(3); |
| 3284 | SDValue Dest = Op.getOperand(4); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3285 | SDLoc dl(Op); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3286 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3287 | if (LHS.getValueType() == MVT::i32) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3288 | SDValue ARMcc; |
| 3289 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3290 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3291 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3292 | Chain, Dest, ARMcc, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3293 | } |
| 3294 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3295 | assert(LHS.getValueType() == MVT::f32 || LHS.getValueType() == MVT::f64); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3296 | |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 3297 | if (getTargetMachine().Options.UnsafeFPMath && |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3298 | (CC == ISD::SETEQ || CC == ISD::SETOEQ || |
| 3299 | CC == ISD::SETNE || CC == ISD::SETUNE)) { |
| 3300 | SDValue Result = OptimizeVFPBrcond(Op, DAG); |
| 3301 | if (Result.getNode()) |
| 3302 | return Result; |
| 3303 | } |
| 3304 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3305 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 3306 | FPCCToARMCC(CC, CondCode, CondCode2); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3307 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3308 | SDValue ARMcc = DAG.getConstant(CondCode, MVT::i32); |
| 3309 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3310 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3311 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3312 | SDValue Ops[] = { Chain, Dest, ARMcc, CCR, Cmp }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3313 | SDValue Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3314 | if (CondCode2 != ARMCC::AL) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3315 | ARMcc = DAG.getConstant(CondCode2, MVT::i32); |
| 3316 | SDValue Ops[] = { Res, Dest, ARMcc, CCR, Res.getValue(1) }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3317 | Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3318 | } |
| 3319 | return Res; |
| 3320 | } |
| 3321 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3322 | SDValue ARMTargetLowering::LowerBR_JT(SDValue Op, SelectionDAG &DAG) const { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3323 | SDValue Chain = Op.getOperand(0); |
| 3324 | SDValue Table = Op.getOperand(1); |
| 3325 | SDValue Index = Op.getOperand(2); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3326 | SDLoc dl(Op); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3327 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3328 | EVT PTy = getPointerTy(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3329 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Table); |
| 3330 | ARMFunctionInfo *AFI = DAG.getMachineFunction().getInfo<ARMFunctionInfo>(); |
Bob Wilson | 3eadf00 | 2009-07-14 18:44:34 +0000 | [diff] [blame] | 3331 | SDValue UId = DAG.getConstant(AFI->createJumpTableUId(), PTy); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3332 | SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PTy); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3333 | Table = DAG.getNode(ARMISD::WrapperJT, dl, MVT::i32, JTI, UId); |
Evan Cheng | e7c329b | 2009-07-28 20:53:24 +0000 | [diff] [blame] | 3334 | Index = DAG.getNode(ISD::MUL, dl, PTy, Index, DAG.getConstant(4, PTy)); |
| 3335 | SDValue Addr = DAG.getNode(ISD::ADD, dl, PTy, Index, Table); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3336 | if (Subtarget->isThumb2()) { |
| 3337 | // Thumb2 uses a two-level jump. That is, it jumps into the jump table |
| 3338 | // which does another jump to the destination. This also makes it easier |
| 3339 | // to translate it to TBB / TBH later. |
| 3340 | // FIXME: This might not work if the function is extremely large. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3341 | return DAG.getNode(ARMISD::BR2_JT, dl, MVT::Other, Chain, |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 3342 | Addr, Op.getOperand(2), JTI, UId); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3343 | } |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3344 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 3345 | Addr = DAG.getLoad((EVT)MVT::i32, dl, Chain, Addr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3346 | MachinePointerInfo::getJumpTable(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3347 | false, false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3348 | Chain = Addr.getValue(1); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 3349 | Addr = DAG.getNode(ISD::ADD, dl, PTy, Addr, Table); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3350 | return DAG.getNode(ARMISD::BR_JT, dl, MVT::Other, Chain, Addr, JTI, UId); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3351 | } else { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 3352 | Addr = DAG.getLoad(PTy, dl, Chain, Addr, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3353 | MachinePointerInfo::getJumpTable(), |
| 3354 | false, false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3355 | Chain = Addr.getValue(1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3356 | return DAG.getNode(ARMISD::BR_JT, dl, MVT::Other, Chain, Addr, JTI, UId); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3357 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3358 | } |
| 3359 | |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3360 | static SDValue LowerVectorFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 3361 | EVT VT = Op.getValueType(); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3362 | SDLoc dl(Op); |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3363 | |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 3364 | if (Op.getValueType().getVectorElementType() == MVT::i32) { |
| 3365 | if (Op.getOperand(0).getValueType().getVectorElementType() == MVT::f32) |
| 3366 | return Op; |
| 3367 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3368 | } |
| 3369 | |
| 3370 | assert(Op.getOperand(0).getValueType() == MVT::v4f32 && |
| 3371 | "Invalid type for custom lowering!"); |
| 3372 | if (VT != MVT::v4i16) |
| 3373 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3374 | |
| 3375 | Op = DAG.getNode(Op.getOpcode(), dl, MVT::v4i32, Op.getOperand(0)); |
| 3376 | return DAG.getNode(ISD::TRUNCATE, dl, VT, Op); |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3377 | } |
| 3378 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3379 | static SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3380 | EVT VT = Op.getValueType(); |
| 3381 | if (VT.isVector()) |
| 3382 | return LowerVectorFP_TO_INT(Op, DAG); |
| 3383 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3384 | SDLoc dl(Op); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3385 | unsigned Opc; |
| 3386 | |
| 3387 | switch (Op.getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3388 | default: llvm_unreachable("Invalid opcode!"); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3389 | case ISD::FP_TO_SINT: |
| 3390 | Opc = ARMISD::FTOSI; |
| 3391 | break; |
| 3392 | case ISD::FP_TO_UINT: |
| 3393 | Opc = ARMISD::FTOUI; |
| 3394 | break; |
| 3395 | } |
| 3396 | Op = DAG.getNode(Opc, dl, MVT::f32, Op.getOperand(0)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3397 | return DAG.getNode(ISD::BITCAST, dl, MVT::i32, Op); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3398 | } |
| 3399 | |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3400 | static SDValue LowerVectorINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 3401 | EVT VT = Op.getValueType(); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3402 | SDLoc dl(Op); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3403 | |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3404 | if (Op.getOperand(0).getValueType().getVectorElementType() == MVT::i32) { |
| 3405 | if (VT.getVectorElementType() == MVT::f32) |
| 3406 | return Op; |
| 3407 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3408 | } |
| 3409 | |
Duncan Sands | 1f6a329 | 2011-08-12 14:54:45 +0000 | [diff] [blame] | 3410 | assert(Op.getOperand(0).getValueType() == MVT::v4i16 && |
| 3411 | "Invalid type for custom lowering!"); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3412 | if (VT != MVT::v4f32) |
| 3413 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3414 | |
| 3415 | unsigned CastOpc; |
| 3416 | unsigned Opc; |
| 3417 | switch (Op.getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3418 | default: llvm_unreachable("Invalid opcode!"); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3419 | case ISD::SINT_TO_FP: |
| 3420 | CastOpc = ISD::SIGN_EXTEND; |
| 3421 | Opc = ISD::SINT_TO_FP; |
| 3422 | break; |
| 3423 | case ISD::UINT_TO_FP: |
| 3424 | CastOpc = ISD::ZERO_EXTEND; |
| 3425 | Opc = ISD::UINT_TO_FP; |
| 3426 | break; |
| 3427 | } |
| 3428 | |
| 3429 | Op = DAG.getNode(CastOpc, dl, MVT::v4i32, Op.getOperand(0)); |
| 3430 | return DAG.getNode(Opc, dl, VT, Op); |
| 3431 | } |
| 3432 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3433 | static SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 3434 | EVT VT = Op.getValueType(); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3435 | if (VT.isVector()) |
| 3436 | return LowerVectorINT_TO_FP(Op, DAG); |
| 3437 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3438 | SDLoc dl(Op); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3439 | unsigned Opc; |
| 3440 | |
| 3441 | switch (Op.getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3442 | default: llvm_unreachable("Invalid opcode!"); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3443 | case ISD::SINT_TO_FP: |
| 3444 | Opc = ARMISD::SITOF; |
| 3445 | break; |
| 3446 | case ISD::UINT_TO_FP: |
| 3447 | Opc = ARMISD::UITOF; |
| 3448 | break; |
| 3449 | } |
| 3450 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3451 | Op = DAG.getNode(ISD::BITCAST, dl, MVT::f32, Op.getOperand(0)); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3452 | return DAG.getNode(Opc, dl, VT, Op); |
| 3453 | } |
| 3454 | |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 3455 | SDValue ARMTargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3456 | // Implement fcopysign with a fabs and a conditional fneg. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3457 | SDValue Tmp0 = Op.getOperand(0); |
| 3458 | SDValue Tmp1 = Op.getOperand(1); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3459 | SDLoc dl(Op); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3460 | EVT VT = Op.getValueType(); |
| 3461 | EVT SrcVT = Tmp1.getValueType(); |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3462 | bool InGPR = Tmp0.getOpcode() == ISD::BITCAST || |
| 3463 | Tmp0.getOpcode() == ARMISD::VMOVDRR; |
| 3464 | bool UseNEON = !InGPR && Subtarget->hasNEON(); |
| 3465 | |
| 3466 | if (UseNEON) { |
| 3467 | // Use VBSL to copy the sign bit. |
| 3468 | unsigned EncodedVal = ARM_AM::createNEONModImm(0x6, 0x80); |
| 3469 | SDValue Mask = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v2i32, |
| 3470 | DAG.getTargetConstant(EncodedVal, MVT::i32)); |
| 3471 | EVT OpVT = (VT == MVT::f32) ? MVT::v2i32 : MVT::v1i64; |
| 3472 | if (VT == MVT::f64) |
| 3473 | Mask = DAG.getNode(ARMISD::VSHL, dl, OpVT, |
| 3474 | DAG.getNode(ISD::BITCAST, dl, OpVT, Mask), |
| 3475 | DAG.getConstant(32, MVT::i32)); |
| 3476 | else /*if (VT == MVT::f32)*/ |
| 3477 | Tmp0 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp0); |
| 3478 | if (SrcVT == MVT::f32) { |
| 3479 | Tmp1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp1); |
| 3480 | if (VT == MVT::f64) |
| 3481 | Tmp1 = DAG.getNode(ARMISD::VSHL, dl, OpVT, |
| 3482 | DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1), |
| 3483 | DAG.getConstant(32, MVT::i32)); |
Evan Cheng | 9eec66e | 2011-04-15 01:31:00 +0000 | [diff] [blame] | 3484 | } else if (VT == MVT::f32) |
| 3485 | Tmp1 = DAG.getNode(ARMISD::VSHRu, dl, MVT::v1i64, |
| 3486 | DAG.getNode(ISD::BITCAST, dl, MVT::v1i64, Tmp1), |
| 3487 | DAG.getConstant(32, MVT::i32)); |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3488 | Tmp0 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp0); |
| 3489 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1); |
| 3490 | |
| 3491 | SDValue AllOnes = DAG.getTargetConstant(ARM_AM::createNEONModImm(0xe, 0xff), |
| 3492 | MVT::i32); |
| 3493 | AllOnes = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v8i8, AllOnes); |
| 3494 | SDValue MaskNot = DAG.getNode(ISD::XOR, dl, OpVT, Mask, |
| 3495 | DAG.getNode(ISD::BITCAST, dl, OpVT, AllOnes)); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 3496 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3497 | SDValue Res = DAG.getNode(ISD::OR, dl, OpVT, |
| 3498 | DAG.getNode(ISD::AND, dl, OpVT, Tmp1, Mask), |
| 3499 | DAG.getNode(ISD::AND, dl, OpVT, Tmp0, MaskNot)); |
Evan Cheng | c24ab5c | 2011-02-28 18:45:27 +0000 | [diff] [blame] | 3500 | if (VT == MVT::f32) { |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3501 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::v2f32, Res); |
| 3502 | Res = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f32, Res, |
| 3503 | DAG.getConstant(0, MVT::i32)); |
| 3504 | } else { |
| 3505 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::f64, Res); |
| 3506 | } |
| 3507 | |
| 3508 | return Res; |
| 3509 | } |
Evan Cheng | c143dd4 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 3510 | |
| 3511 | // Bitcast operand 1 to i32. |
| 3512 | if (SrcVT == MVT::f64) |
| 3513 | Tmp1 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), |
| 3514 | &Tmp1, 1).getValue(1); |
| 3515 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp1); |
| 3516 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3517 | // Or in the signbit with integer operations. |
| 3518 | SDValue Mask1 = DAG.getConstant(0x80000000, MVT::i32); |
| 3519 | SDValue Mask2 = DAG.getConstant(0x7fffffff, MVT::i32); |
| 3520 | Tmp1 = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp1, Mask1); |
| 3521 | if (VT == MVT::f32) { |
| 3522 | Tmp0 = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 3523 | DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp0), Mask2); |
| 3524 | return DAG.getNode(ISD::BITCAST, dl, MVT::f32, |
| 3525 | DAG.getNode(ISD::OR, dl, MVT::i32, Tmp0, Tmp1)); |
Evan Cheng | c143dd4 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 3526 | } |
| 3527 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3528 | // f64: Or the high part with signbit and then combine two parts. |
| 3529 | Tmp0 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), |
| 3530 | &Tmp0, 1); |
| 3531 | SDValue Lo = Tmp0.getValue(0); |
| 3532 | SDValue Hi = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp0.getValue(1), Mask2); |
| 3533 | Hi = DAG.getNode(ISD::OR, dl, MVT::i32, Hi, Tmp1); |
| 3534 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3535 | } |
| 3536 | |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3537 | SDValue ARMTargetLowering::LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const{ |
| 3538 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3539 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 3540 | MFI->setReturnAddressIsTaken(true); |
| 3541 | |
| 3542 | EVT VT = Op.getValueType(); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3543 | SDLoc dl(Op); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3544 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 3545 | if (Depth) { |
| 3546 | SDValue FrameAddr = LowerFRAMEADDR(Op, DAG); |
| 3547 | SDValue Offset = DAG.getConstant(4, MVT::i32); |
| 3548 | return DAG.getLoad(VT, dl, DAG.getEntryNode(), |
| 3549 | DAG.getNode(ISD::ADD, dl, VT, FrameAddr, Offset), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3550 | MachinePointerInfo(), false, false, false, 0); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3551 | } |
| 3552 | |
| 3553 | // Return LR, which contains the return address. Mark it an implicit live-in. |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 3554 | unsigned Reg = MF.addLiveIn(ARM::LR, getRegClassFor(MVT::i32)); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3555 | return DAG.getCopyFromReg(DAG.getEntryNode(), dl, Reg, VT); |
| 3556 | } |
| 3557 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3558 | SDValue ARMTargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const { |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3559 | MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); |
| 3560 | MFI->setFrameAddressIsTaken(true); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3561 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3562 | EVT VT = Op.getValueType(); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3563 | SDLoc dl(Op); // FIXME probably not meaningful |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3564 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Evan Cheng | cd82861 | 2009-06-18 23:14:30 +0000 | [diff] [blame] | 3565 | unsigned FrameReg = (Subtarget->isThumb() || Subtarget->isTargetDarwin()) |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3566 | ? ARM::R7 : ARM::R11; |
| 3567 | SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, FrameReg, VT); |
| 3568 | while (Depth--) |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3569 | FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr, |
| 3570 | MachinePointerInfo(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3571 | false, false, false, 0); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3572 | return FrameAddr; |
| 3573 | } |
| 3574 | |
Renato Golin | 5ad5f59 | 2013-03-19 08:15:38 +0000 | [diff] [blame] | 3575 | /// Custom Expand long vector extensions, where size(DestVec) > 2*size(SrcVec), |
| 3576 | /// and size(DestVec) > 128-bits. |
| 3577 | /// This is achieved by doing the one extension from the SrcVec, splitting the |
| 3578 | /// result, extending these parts, and then concatenating these into the |
| 3579 | /// destination. |
| 3580 | static SDValue ExpandVectorExtension(SDNode *N, SelectionDAG &DAG) { |
| 3581 | SDValue Op = N->getOperand(0); |
| 3582 | EVT SrcVT = Op.getValueType(); |
| 3583 | EVT DestVT = N->getValueType(0); |
| 3584 | |
| 3585 | assert(DestVT.getSizeInBits() > 128 && |
| 3586 | "Custom sext/zext expansion needs >128-bit vector."); |
| 3587 | // If this is a normal length extension, use the default expansion. |
| 3588 | if (SrcVT.getSizeInBits()*4 != DestVT.getSizeInBits() && |
| 3589 | SrcVT.getSizeInBits()*8 != DestVT.getSizeInBits()) |
| 3590 | return SDValue(); |
| 3591 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3592 | SDLoc dl(N); |
Renato Golin | 5ad5f59 | 2013-03-19 08:15:38 +0000 | [diff] [blame] | 3593 | unsigned SrcEltSize = SrcVT.getVectorElementType().getSizeInBits(); |
| 3594 | unsigned DestEltSize = DestVT.getVectorElementType().getSizeInBits(); |
| 3595 | unsigned NumElts = SrcVT.getVectorNumElements(); |
| 3596 | LLVMContext &Ctx = *DAG.getContext(); |
| 3597 | SDValue Mid, SplitLo, SplitHi, ExtLo, ExtHi; |
| 3598 | |
| 3599 | EVT MidVT = EVT::getVectorVT(Ctx, EVT::getIntegerVT(Ctx, SrcEltSize*2), |
| 3600 | NumElts); |
| 3601 | EVT SplitVT = EVT::getVectorVT(Ctx, EVT::getIntegerVT(Ctx, SrcEltSize*2), |
| 3602 | NumElts/2); |
| 3603 | EVT ExtVT = EVT::getVectorVT(Ctx, EVT::getIntegerVT(Ctx, DestEltSize), |
| 3604 | NumElts/2); |
| 3605 | |
| 3606 | Mid = DAG.getNode(N->getOpcode(), dl, MidVT, Op); |
| 3607 | SplitLo = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, SplitVT, Mid, |
| 3608 | DAG.getIntPtrConstant(0)); |
| 3609 | SplitHi = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, SplitVT, Mid, |
| 3610 | DAG.getIntPtrConstant(NumElts/2)); |
| 3611 | ExtLo = DAG.getNode(N->getOpcode(), dl, ExtVT, SplitLo); |
| 3612 | ExtHi = DAG.getNode(N->getOpcode(), dl, ExtVT, SplitHi); |
| 3613 | return DAG.getNode(ISD::CONCAT_VECTORS, dl, DestVT, ExtLo, ExtHi); |
| 3614 | } |
| 3615 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3616 | /// ExpandBITCAST - If the target supports VFP, this function is called to |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3617 | /// expand a bit convert where either the source or destination type is i64 to |
| 3618 | /// use a VMOVDRR or VMOVRRD node. This should not be done when the non-i64 |
| 3619 | /// operand type is illegal (e.g., v2f32 for a target that doesn't support |
| 3620 | /// vectors), since the legalizer won't know what to do with that. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3621 | static SDValue ExpandBITCAST(SDNode *N, SelectionDAG &DAG) { |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3622 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3623 | SDLoc dl(N); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3624 | SDValue Op = N->getOperand(0); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3625 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3626 | // This function is only supposed to be called for i64 types, either as the |
| 3627 | // source or destination of the bit convert. |
| 3628 | EVT SrcVT = Op.getValueType(); |
| 3629 | EVT DstVT = N->getValueType(0); |
| 3630 | assert((SrcVT == MVT::i64 || DstVT == MVT::i64) && |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3631 | "ExpandBITCAST called for non-i64 type"); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3632 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3633 | // Turn i64->f64 into VMOVDRR. |
| 3634 | if (SrcVT == MVT::i64 && TLI.isTypeLegal(DstVT)) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3635 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 3636 | DAG.getConstant(0, MVT::i32)); |
| 3637 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 3638 | DAG.getConstant(1, MVT::i32)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3639 | return DAG.getNode(ISD::BITCAST, dl, DstVT, |
Bob Wilson | 1114f56 | 2010-06-11 22:45:25 +0000 | [diff] [blame] | 3640 | DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi)); |
Evan Cheng | c7c7729 | 2008-11-04 19:57:48 +0000 | [diff] [blame] | 3641 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3642 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 3643 | // Turn f64->i64 into VMOVRRD. |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3644 | if (DstVT == MVT::i64 && TLI.isTypeLegal(SrcVT)) { |
| 3645 | SDValue Cvt = DAG.getNode(ARMISD::VMOVRRD, dl, |
| 3646 | DAG.getVTList(MVT::i32, MVT::i32), &Op, 1); |
| 3647 | // Merge the pieces into a single i64 value. |
| 3648 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Cvt, Cvt.getValue(1)); |
| 3649 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3650 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3651 | return SDValue(); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3652 | } |
| 3653 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3654 | /// getZeroVector - Returns a vector of specified type with all zero elements. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3655 | /// Zero vectors are used to represent vector negation and in those cases |
| 3656 | /// will be implemented with the NEON VNEG instruction. However, VNEG does |
| 3657 | /// not support i64 elements, so sometimes the zero vectors will need to be |
| 3658 | /// explicitly constructed. Regardless, use a canonical VMOV to create the |
| 3659 | /// zero vector. |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3660 | static SDValue getZeroVector(EVT VT, SelectionDAG &DAG, SDLoc dl) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3661 | assert(VT.isVector() && "Expected a vector type"); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3662 | // The canonical modified immediate encoding of a zero vector is....0! |
| 3663 | SDValue EncodedVal = DAG.getTargetConstant(0, MVT::i32); |
| 3664 | EVT VmovVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 3665 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, EncodedVal); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3666 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3667 | } |
| 3668 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3669 | /// LowerShiftRightParts - Lower SRA_PARTS, which returns two |
| 3670 | /// i32 values and take a 2 x i32 value to shift plus a shift amount. |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3671 | SDValue ARMTargetLowering::LowerShiftRightParts(SDValue Op, |
| 3672 | SelectionDAG &DAG) const { |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3673 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 3674 | EVT VT = Op.getValueType(); |
| 3675 | unsigned VTBits = VT.getSizeInBits(); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3676 | SDLoc dl(Op); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3677 | SDValue ShOpLo = Op.getOperand(0); |
| 3678 | SDValue ShOpHi = Op.getOperand(1); |
| 3679 | SDValue ShAmt = Op.getOperand(2); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3680 | SDValue ARMcc; |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3681 | unsigned Opc = (Op.getOpcode() == ISD::SRA_PARTS) ? ISD::SRA : ISD::SRL; |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3682 | |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3683 | assert(Op.getOpcode() == ISD::SRA_PARTS || Op.getOpcode() == ISD::SRL_PARTS); |
| 3684 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3685 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 3686 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 3687 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, ShAmt); |
| 3688 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 3689 | DAG.getConstant(VTBits, MVT::i32)); |
| 3690 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, RevShAmt); |
| 3691 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3692 | SDValue TrueVal = DAG.getNode(Opc, dl, VT, ShOpHi, ExtraShAmt); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3693 | |
| 3694 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3695 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3696 | ARMcc, DAG, dl); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3697 | SDValue Hi = DAG.getNode(Opc, dl, VT, ShOpHi, ShAmt); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3698 | SDValue Lo = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3699 | CCR, Cmp); |
| 3700 | |
| 3701 | SDValue Ops[2] = { Lo, Hi }; |
| 3702 | return DAG.getMergeValues(Ops, 2, dl); |
| 3703 | } |
| 3704 | |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3705 | /// LowerShiftLeftParts - Lower SHL_PARTS, which returns two |
| 3706 | /// i32 values and take a 2 x i32 value to shift plus a shift amount. |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3707 | SDValue ARMTargetLowering::LowerShiftLeftParts(SDValue Op, |
| 3708 | SelectionDAG &DAG) const { |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3709 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 3710 | EVT VT = Op.getValueType(); |
| 3711 | unsigned VTBits = VT.getSizeInBits(); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3712 | SDLoc dl(Op); |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3713 | SDValue ShOpLo = Op.getOperand(0); |
| 3714 | SDValue ShOpHi = Op.getOperand(1); |
| 3715 | SDValue ShAmt = Op.getOperand(2); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3716 | SDValue ARMcc; |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3717 | |
| 3718 | assert(Op.getOpcode() == ISD::SHL_PARTS); |
| 3719 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 3720 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 3721 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, RevShAmt); |
| 3722 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 3723 | DAG.getConstant(VTBits, MVT::i32)); |
| 3724 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, ShAmt); |
| 3725 | SDValue Tmp3 = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ExtraShAmt); |
| 3726 | |
| 3727 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
| 3728 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3729 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3730 | ARMcc, DAG, dl); |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3731 | SDValue Lo = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ShAmt); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3732 | SDValue Hi = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, Tmp3, ARMcc, |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3733 | CCR, Cmp); |
| 3734 | |
| 3735 | SDValue Ops[2] = { Lo, Hi }; |
| 3736 | return DAG.getMergeValues(Ops, 2, dl); |
| 3737 | } |
| 3738 | |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3739 | SDValue ARMTargetLowering::LowerFLT_ROUNDS_(SDValue Op, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3740 | SelectionDAG &DAG) const { |
| 3741 | // The rounding mode is in bits 23:22 of the FPSCR. |
| 3742 | // The ARM rounding mode value to FLT_ROUNDS mapping is 0->1, 1->2, 2->3, 3->0 |
| 3743 | // The formula we use to implement this is (((FPSCR + 1 << 22) >> 22) & 3) |
| 3744 | // so that the shift + and get folded into a bitfield extract. |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3745 | SDLoc dl(Op); |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3746 | SDValue FPSCR = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::i32, |
| 3747 | DAG.getConstant(Intrinsic::arm_get_fpscr, |
| 3748 | MVT::i32)); |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3749 | SDValue FltRounds = DAG.getNode(ISD::ADD, dl, MVT::i32, FPSCR, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3750 | DAG.getConstant(1U << 22, MVT::i32)); |
| 3751 | SDValue RMODE = DAG.getNode(ISD::SRL, dl, MVT::i32, FltRounds, |
| 3752 | DAG.getConstant(22, MVT::i32)); |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3753 | return DAG.getNode(ISD::AND, dl, MVT::i32, RMODE, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3754 | DAG.getConstant(3, MVT::i32)); |
| 3755 | } |
| 3756 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 3757 | static SDValue LowerCTTZ(SDNode *N, SelectionDAG &DAG, |
| 3758 | const ARMSubtarget *ST) { |
| 3759 | EVT VT = N->getValueType(0); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3760 | SDLoc dl(N); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 3761 | |
| 3762 | if (!ST->hasV6T2Ops()) |
| 3763 | return SDValue(); |
| 3764 | |
| 3765 | SDValue rbit = DAG.getNode(ARMISD::RBIT, dl, VT, N->getOperand(0)); |
| 3766 | return DAG.getNode(ISD::CTLZ, dl, VT, rbit); |
| 3767 | } |
| 3768 | |
Evan Cheng | c8e7045 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 3769 | /// getCTPOP16BitCounts - Returns a v8i8/v16i8 vector containing the bit-count |
| 3770 | /// for each 16-bit element from operand, repeated. The basic idea is to |
| 3771 | /// leverage vcnt to get the 8-bit counts, gather and add the results. |
| 3772 | /// |
| 3773 | /// Trace for v4i16: |
| 3774 | /// input = [v0 v1 v2 v3 ] (vi 16-bit element) |
| 3775 | /// cast: N0 = [w0 w1 w2 w3 w4 w5 w6 w7] (v0 = [w0 w1], wi 8-bit element) |
| 3776 | /// vcnt: N1 = [b0 b1 b2 b3 b4 b5 b6 b7] (bi = bit-count of 8-bit element wi) |
Jim Grosbach | 7ccf463 | 2013-03-02 20:16:15 +0000 | [diff] [blame] | 3777 | /// vrev: N2 = [b1 b0 b3 b2 b5 b4 b7 b6] |
Evan Cheng | c8e7045 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 3778 | /// [b0 b1 b2 b3 b4 b5 b6 b7] |
| 3779 | /// +[b1 b0 b3 b2 b5 b4 b7 b6] |
| 3780 | /// N3=N1+N2 = [k0 k0 k1 k1 k2 k2 k3 k3] (k0 = b0+b1 = bit-count of 16-bit v0, |
| 3781 | /// vuzp: = [k0 k1 k2 k3 k0 k1 k2 k3] each ki is 8-bits) |
| 3782 | static SDValue getCTPOP16BitCounts(SDNode *N, SelectionDAG &DAG) { |
| 3783 | EVT VT = N->getValueType(0); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3784 | SDLoc DL(N); |
Evan Cheng | c8e7045 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 3785 | |
| 3786 | EVT VT8Bit = VT.is64BitVector() ? MVT::v8i8 : MVT::v16i8; |
| 3787 | SDValue N0 = DAG.getNode(ISD::BITCAST, DL, VT8Bit, N->getOperand(0)); |
| 3788 | SDValue N1 = DAG.getNode(ISD::CTPOP, DL, VT8Bit, N0); |
| 3789 | SDValue N2 = DAG.getNode(ARMISD::VREV16, DL, VT8Bit, N1); |
| 3790 | SDValue N3 = DAG.getNode(ISD::ADD, DL, VT8Bit, N1, N2); |
| 3791 | return DAG.getNode(ARMISD::VUZP, DL, VT8Bit, N3, N3); |
| 3792 | } |
| 3793 | |
| 3794 | /// lowerCTPOP16BitElements - Returns a v4i16/v8i16 vector containing the |
| 3795 | /// bit-count for each 16-bit element from the operand. We need slightly |
| 3796 | /// different sequencing for v4i16 and v8i16 to stay within NEON's available |
| 3797 | /// 64/128-bit registers. |
Jim Grosbach | 7ccf463 | 2013-03-02 20:16:15 +0000 | [diff] [blame] | 3798 | /// |
Evan Cheng | c8e7045 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 3799 | /// Trace for v4i16: |
| 3800 | /// input = [v0 v1 v2 v3 ] (vi 16-bit element) |
| 3801 | /// v8i8: BitCounts = [k0 k1 k2 k3 k0 k1 k2 k3 ] (ki is the bit-count of vi) |
| 3802 | /// v8i16:Extended = [k0 k1 k2 k3 k0 k1 k2 k3 ] |
| 3803 | /// v4i16:Extracted = [k0 k1 k2 k3 ] |
| 3804 | static SDValue lowerCTPOP16BitElements(SDNode *N, SelectionDAG &DAG) { |
| 3805 | EVT VT = N->getValueType(0); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3806 | SDLoc DL(N); |
Evan Cheng | c8e7045 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 3807 | |
| 3808 | SDValue BitCounts = getCTPOP16BitCounts(N, DAG); |
| 3809 | if (VT.is64BitVector()) { |
| 3810 | SDValue Extended = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v8i16, BitCounts); |
| 3811 | return DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MVT::v4i16, Extended, |
| 3812 | DAG.getIntPtrConstant(0)); |
| 3813 | } else { |
| 3814 | SDValue Extracted = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MVT::v8i8, |
| 3815 | BitCounts, DAG.getIntPtrConstant(0)); |
| 3816 | return DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v8i16, Extracted); |
| 3817 | } |
| 3818 | } |
| 3819 | |
| 3820 | /// lowerCTPOP32BitElements - Returns a v2i32/v4i32 vector containing the |
| 3821 | /// bit-count for each 32-bit element from the operand. The idea here is |
| 3822 | /// to split the vector into 16-bit elements, leverage the 16-bit count |
| 3823 | /// routine, and then combine the results. |
| 3824 | /// |
| 3825 | /// Trace for v2i32 (v4i32 similar with Extracted/Extended exchanged): |
| 3826 | /// input = [v0 v1 ] (vi: 32-bit elements) |
| 3827 | /// Bitcast = [w0 w1 w2 w3 ] (wi: 16-bit elements, v0 = [w0 w1]) |
| 3828 | /// Counts16 = [k0 k1 k2 k3 ] (ki: 16-bit elements, bit-count of wi) |
Jim Grosbach | 7ccf463 | 2013-03-02 20:16:15 +0000 | [diff] [blame] | 3829 | /// vrev: N0 = [k1 k0 k3 k2 ] |
Evan Cheng | c8e7045 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 3830 | /// [k0 k1 k2 k3 ] |
| 3831 | /// N1 =+[k1 k0 k3 k2 ] |
| 3832 | /// [k0 k2 k1 k3 ] |
| 3833 | /// N2 =+[k1 k3 k0 k2 ] |
| 3834 | /// [k0 k2 k1 k3 ] |
| 3835 | /// Extended =+[k1 k3 k0 k2 ] |
| 3836 | /// [k0 k2 ] |
| 3837 | /// Extracted=+[k1 k3 ] |
| 3838 | /// |
| 3839 | static SDValue lowerCTPOP32BitElements(SDNode *N, SelectionDAG &DAG) { |
| 3840 | EVT VT = N->getValueType(0); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3841 | SDLoc DL(N); |
Evan Cheng | c8e7045 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 3842 | |
| 3843 | EVT VT16Bit = VT.is64BitVector() ? MVT::v4i16 : MVT::v8i16; |
| 3844 | |
| 3845 | SDValue Bitcast = DAG.getNode(ISD::BITCAST, DL, VT16Bit, N->getOperand(0)); |
| 3846 | SDValue Counts16 = lowerCTPOP16BitElements(Bitcast.getNode(), DAG); |
| 3847 | SDValue N0 = DAG.getNode(ARMISD::VREV32, DL, VT16Bit, Counts16); |
| 3848 | SDValue N1 = DAG.getNode(ISD::ADD, DL, VT16Bit, Counts16, N0); |
| 3849 | SDValue N2 = DAG.getNode(ARMISD::VUZP, DL, VT16Bit, N1, N1); |
| 3850 | |
| 3851 | if (VT.is64BitVector()) { |
| 3852 | SDValue Extended = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v4i32, N2); |
| 3853 | return DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MVT::v2i32, Extended, |
| 3854 | DAG.getIntPtrConstant(0)); |
| 3855 | } else { |
| 3856 | SDValue Extracted = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MVT::v4i16, N2, |
| 3857 | DAG.getIntPtrConstant(0)); |
| 3858 | return DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v4i32, Extracted); |
| 3859 | } |
| 3860 | } |
| 3861 | |
| 3862 | static SDValue LowerCTPOP(SDNode *N, SelectionDAG &DAG, |
| 3863 | const ARMSubtarget *ST) { |
| 3864 | EVT VT = N->getValueType(0); |
| 3865 | |
| 3866 | assert(ST->hasNEON() && "Custom ctpop lowering requires NEON."); |
Matt Beaumont-Gay | 105ab4f | 2012-12-04 23:54:02 +0000 | [diff] [blame] | 3867 | assert((VT == MVT::v2i32 || VT == MVT::v4i32 || |
| 3868 | VT == MVT::v4i16 || VT == MVT::v8i16) && |
Evan Cheng | c8e7045 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 3869 | "Unexpected type for custom ctpop lowering"); |
| 3870 | |
| 3871 | if (VT.getVectorElementType() == MVT::i32) |
| 3872 | return lowerCTPOP32BitElements(N, DAG); |
| 3873 | else |
| 3874 | return lowerCTPOP16BitElements(N, DAG); |
| 3875 | } |
| 3876 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3877 | static SDValue LowerShift(SDNode *N, SelectionDAG &DAG, |
| 3878 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3879 | EVT VT = N->getValueType(0); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3880 | SDLoc dl(N); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3881 | |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3882 | if (!VT.isVector()) |
| 3883 | return SDValue(); |
| 3884 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3885 | // Lower vector shifts on NEON to use VSHL. |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3886 | assert(ST->hasNEON() && "unexpected vector shift"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3887 | |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3888 | // Left shifts translate directly to the vshiftu intrinsic. |
| 3889 | if (N->getOpcode() == ISD::SHL) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3890 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3891 | DAG.getConstant(Intrinsic::arm_neon_vshiftu, MVT::i32), |
| 3892 | N->getOperand(0), N->getOperand(1)); |
| 3893 | |
| 3894 | assert((N->getOpcode() == ISD::SRA || |
| 3895 | N->getOpcode() == ISD::SRL) && "unexpected vector shift opcode"); |
| 3896 | |
| 3897 | // NEON uses the same intrinsics for both left and right shifts. For |
| 3898 | // right shifts, the shift amounts are negative, so negate the vector of |
| 3899 | // shift amounts. |
| 3900 | EVT ShiftVT = N->getOperand(1).getValueType(); |
| 3901 | SDValue NegatedCount = DAG.getNode(ISD::SUB, dl, ShiftVT, |
| 3902 | getZeroVector(ShiftVT, DAG, dl), |
| 3903 | N->getOperand(1)); |
| 3904 | Intrinsic::ID vshiftInt = (N->getOpcode() == ISD::SRA ? |
| 3905 | Intrinsic::arm_neon_vshifts : |
| 3906 | Intrinsic::arm_neon_vshiftu); |
| 3907 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
| 3908 | DAG.getConstant(vshiftInt, MVT::i32), |
| 3909 | N->getOperand(0), NegatedCount); |
| 3910 | } |
| 3911 | |
| 3912 | static SDValue Expand64BitShift(SDNode *N, SelectionDAG &DAG, |
| 3913 | const ARMSubtarget *ST) { |
| 3914 | EVT VT = N->getValueType(0); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3915 | SDLoc dl(N); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3916 | |
Eli Friedman | ce392eb | 2009-08-22 03:13:10 +0000 | [diff] [blame] | 3917 | // We can get here for a node like i32 = ISD::SHL i32, i64 |
| 3918 | if (VT != MVT::i64) |
| 3919 | return SDValue(); |
| 3920 | |
| 3921 | assert((N->getOpcode() == ISD::SRL || N->getOpcode() == ISD::SRA) && |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3922 | "Unknown shift to lower!"); |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3923 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3924 | // We only lower SRA, SRL of 1 here, all others use generic lowering. |
| 3925 | if (!isa<ConstantSDNode>(N->getOperand(1)) || |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 3926 | cast<ConstantSDNode>(N->getOperand(1))->getZExtValue() != 1) |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3927 | return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3928 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3929 | // If we are in thumb mode, we don't have RRX. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 3930 | if (ST->isThumb1Only()) return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3931 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3932 | // Okay, we have a 64-bit SRA or SRL of 1. Lower this to an RRX expr. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3933 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, N->getOperand(0), |
Bob Wilson | ab3912e | 2010-05-25 03:36:52 +0000 | [diff] [blame] | 3934 | DAG.getConstant(0, MVT::i32)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3935 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, N->getOperand(0), |
Bob Wilson | ab3912e | 2010-05-25 03:36:52 +0000 | [diff] [blame] | 3936 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3937 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3938 | // First, build a SRA_FLAG/SRL_FLAG op, which shifts the top part by one and |
| 3939 | // captures the result into a carry flag. |
| 3940 | unsigned Opc = N->getOpcode() == ISD::SRL ? ARMISD::SRL_FLAG:ARMISD::SRA_FLAG; |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3941 | Hi = DAG.getNode(Opc, dl, DAG.getVTList(MVT::i32, MVT::Glue), &Hi, 1); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3942 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3943 | // The low part is an ARMISD::RRX operand, which shifts the carry in. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3944 | Lo = DAG.getNode(ARMISD::RRX, dl, MVT::i32, Lo, Hi.getValue(1)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3945 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3946 | // Merge the pieces into a single i64 value. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3947 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3948 | } |
| 3949 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3950 | static SDValue LowerVSETCC(SDValue Op, SelectionDAG &DAG) { |
| 3951 | SDValue TmpOp0, TmpOp1; |
| 3952 | bool Invert = false; |
| 3953 | bool Swap = false; |
| 3954 | unsigned Opc = 0; |
| 3955 | |
| 3956 | SDValue Op0 = Op.getOperand(0); |
| 3957 | SDValue Op1 = Op.getOperand(1); |
| 3958 | SDValue CC = Op.getOperand(2); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3959 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3960 | ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get(); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 3961 | SDLoc dl(Op); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3962 | |
| 3963 | if (Op.getOperand(1).getValueType().isFloatingPoint()) { |
| 3964 | switch (SetCCOpcode) { |
David Blaikie | 4d6ccb5 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 3965 | default: llvm_unreachable("Illegal FP comparison"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3966 | case ISD::SETUNE: |
| 3967 | case ISD::SETNE: Invert = true; // Fallthrough |
| 3968 | case ISD::SETOEQ: |
| 3969 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 3970 | case ISD::SETOLT: |
| 3971 | case ISD::SETLT: Swap = true; // Fallthrough |
| 3972 | case ISD::SETOGT: |
| 3973 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 3974 | case ISD::SETOLE: |
| 3975 | case ISD::SETLE: Swap = true; // Fallthrough |
| 3976 | case ISD::SETOGE: |
| 3977 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 3978 | case ISD::SETUGE: Swap = true; // Fallthrough |
| 3979 | case ISD::SETULE: Invert = true; Opc = ARMISD::VCGT; break; |
| 3980 | case ISD::SETUGT: Swap = true; // Fallthrough |
| 3981 | case ISD::SETULT: Invert = true; Opc = ARMISD::VCGE; break; |
| 3982 | case ISD::SETUEQ: Invert = true; // Fallthrough |
| 3983 | case ISD::SETONE: |
| 3984 | // Expand this to (OLT | OGT). |
| 3985 | TmpOp0 = Op0; |
| 3986 | TmpOp1 = Op1; |
| 3987 | Opc = ISD::OR; |
| 3988 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 3989 | Op1 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp0, TmpOp1); |
| 3990 | break; |
| 3991 | case ISD::SETUO: Invert = true; // Fallthrough |
| 3992 | case ISD::SETO: |
| 3993 | // Expand this to (OLT | OGE). |
| 3994 | TmpOp0 = Op0; |
| 3995 | TmpOp1 = Op1; |
| 3996 | Opc = ISD::OR; |
| 3997 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 3998 | Op1 = DAG.getNode(ARMISD::VCGE, dl, VT, TmpOp0, TmpOp1); |
| 3999 | break; |
| 4000 | } |
| 4001 | } else { |
| 4002 | // Integer comparisons. |
| 4003 | switch (SetCCOpcode) { |
David Blaikie | 4d6ccb5 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 4004 | default: llvm_unreachable("Illegal integer comparison"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4005 | case ISD::SETNE: Invert = true; |
| 4006 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 4007 | case ISD::SETLT: Swap = true; |
| 4008 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 4009 | case ISD::SETLE: Swap = true; |
| 4010 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 4011 | case ISD::SETULT: Swap = true; |
| 4012 | case ISD::SETUGT: Opc = ARMISD::VCGTU; break; |
| 4013 | case ISD::SETULE: Swap = true; |
| 4014 | case ISD::SETUGE: Opc = ARMISD::VCGEU; break; |
| 4015 | } |
| 4016 | |
Nick Lewycky | 7f6aa2b | 2009-07-08 03:04:38 +0000 | [diff] [blame] | 4017 | // Detect VTST (Vector Test Bits) = icmp ne (and (op0, op1), zero). |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4018 | if (Opc == ARMISD::VCEQ) { |
| 4019 | |
| 4020 | SDValue AndOp; |
| 4021 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 4022 | AndOp = Op0; |
| 4023 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) |
| 4024 | AndOp = Op1; |
| 4025 | |
| 4026 | // Ignore bitconvert. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4027 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::BITCAST) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4028 | AndOp = AndOp.getOperand(0); |
| 4029 | |
| 4030 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::AND) { |
| 4031 | Opc = ARMISD::VTST; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4032 | Op0 = DAG.getNode(ISD::BITCAST, dl, VT, AndOp.getOperand(0)); |
| 4033 | Op1 = DAG.getNode(ISD::BITCAST, dl, VT, AndOp.getOperand(1)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4034 | Invert = !Invert; |
| 4035 | } |
| 4036 | } |
| 4037 | } |
| 4038 | |
| 4039 | if (Swap) |
| 4040 | std::swap(Op0, Op1); |
| 4041 | |
Owen Anderson | c24cb35 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 4042 | // If one of the operands is a constant vector zero, attempt to fold the |
| 4043 | // comparison to a specialized compare-against-zero form. |
| 4044 | SDValue SingleOp; |
| 4045 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 4046 | SingleOp = Op0; |
| 4047 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) { |
| 4048 | if (Opc == ARMISD::VCGE) |
| 4049 | Opc = ARMISD::VCLEZ; |
| 4050 | else if (Opc == ARMISD::VCGT) |
| 4051 | Opc = ARMISD::VCLTZ; |
| 4052 | SingleOp = Op1; |
| 4053 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4054 | |
Owen Anderson | c24cb35 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 4055 | SDValue Result; |
| 4056 | if (SingleOp.getNode()) { |
| 4057 | switch (Opc) { |
| 4058 | case ARMISD::VCEQ: |
| 4059 | Result = DAG.getNode(ARMISD::VCEQZ, dl, VT, SingleOp); break; |
| 4060 | case ARMISD::VCGE: |
| 4061 | Result = DAG.getNode(ARMISD::VCGEZ, dl, VT, SingleOp); break; |
| 4062 | case ARMISD::VCLEZ: |
| 4063 | Result = DAG.getNode(ARMISD::VCLEZ, dl, VT, SingleOp); break; |
| 4064 | case ARMISD::VCGT: |
| 4065 | Result = DAG.getNode(ARMISD::VCGTZ, dl, VT, SingleOp); break; |
| 4066 | case ARMISD::VCLTZ: |
| 4067 | Result = DAG.getNode(ARMISD::VCLTZ, dl, VT, SingleOp); break; |
| 4068 | default: |
| 4069 | Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 4070 | } |
| 4071 | } else { |
| 4072 | Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 4073 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4074 | |
| 4075 | if (Invert) |
| 4076 | Result = DAG.getNOT(dl, Result, VT); |
| 4077 | |
| 4078 | return Result; |
| 4079 | } |
| 4080 | |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 4081 | /// isNEONModifiedImm - Check if the specified splat value corresponds to a |
| 4082 | /// valid vector constant for a NEON instruction with a "modified immediate" |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4083 | /// operand (e.g., VMOV). If so, return the encoded value. |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 4084 | static SDValue isNEONModifiedImm(uint64_t SplatBits, uint64_t SplatUndef, |
| 4085 | unsigned SplatBitSize, SelectionDAG &DAG, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4086 | EVT &VT, bool is128Bits, NEONModImmType type) { |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4087 | unsigned OpCmode, Imm; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4088 | |
Bob Wilson | 827b210 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 4089 | // SplatBitSize is set to the smallest size that splats the vector, so a |
| 4090 | // zero vector will always have SplatBitSize == 8. However, NEON modified |
| 4091 | // immediate instructions others than VMOV do not support the 8-bit encoding |
| 4092 | // of a zero vector, and the default encoding of zero is supposed to be the |
| 4093 | // 32-bit version. |
| 4094 | if (SplatBits == 0) |
| 4095 | SplatBitSize = 32; |
| 4096 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4097 | switch (SplatBitSize) { |
| 4098 | case 8: |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4099 | if (type != VMOVModImm) |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4100 | return SDValue(); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4101 | // Any 1-byte value is OK. Op=0, Cmode=1110. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4102 | assert((SplatBits & ~0xff) == 0 && "one byte splat value is too big"); |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4103 | OpCmode = 0xe; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4104 | Imm = SplatBits; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4105 | VT = is128Bits ? MVT::v16i8 : MVT::v8i8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4106 | break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4107 | |
| 4108 | case 16: |
| 4109 | // NEON's 16-bit VMOV supports splat values where only one byte is nonzero. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4110 | VT = is128Bits ? MVT::v8i16 : MVT::v4i16; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4111 | if ((SplatBits & ~0xff) == 0) { |
| 4112 | // Value = 0x00nn: Op=x, Cmode=100x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4113 | OpCmode = 0x8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4114 | Imm = SplatBits; |
| 4115 | break; |
| 4116 | } |
| 4117 | if ((SplatBits & ~0xff00) == 0) { |
| 4118 | // Value = 0xnn00: Op=x, Cmode=101x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4119 | OpCmode = 0xa; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4120 | Imm = SplatBits >> 8; |
| 4121 | break; |
| 4122 | } |
| 4123 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4124 | |
| 4125 | case 32: |
| 4126 | // NEON's 32-bit VMOV supports splat values where: |
| 4127 | // * only one byte is nonzero, or |
| 4128 | // * the least significant byte is 0xff and the second byte is nonzero, or |
| 4129 | // * the least significant 2 bytes are 0xff and the third is nonzero. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4130 | VT = is128Bits ? MVT::v4i32 : MVT::v2i32; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4131 | if ((SplatBits & ~0xff) == 0) { |
| 4132 | // Value = 0x000000nn: Op=x, Cmode=000x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4133 | OpCmode = 0; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4134 | Imm = SplatBits; |
| 4135 | break; |
| 4136 | } |
| 4137 | if ((SplatBits & ~0xff00) == 0) { |
| 4138 | // Value = 0x0000nn00: Op=x, Cmode=001x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4139 | OpCmode = 0x2; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4140 | Imm = SplatBits >> 8; |
| 4141 | break; |
| 4142 | } |
| 4143 | if ((SplatBits & ~0xff0000) == 0) { |
| 4144 | // Value = 0x00nn0000: Op=x, Cmode=010x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4145 | OpCmode = 0x4; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4146 | Imm = SplatBits >> 16; |
| 4147 | break; |
| 4148 | } |
| 4149 | if ((SplatBits & ~0xff000000) == 0) { |
| 4150 | // Value = 0xnn000000: Op=x, Cmode=011x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4151 | OpCmode = 0x6; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4152 | Imm = SplatBits >> 24; |
| 4153 | break; |
| 4154 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4155 | |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4156 | // cmode == 0b1100 and cmode == 0b1101 are not supported for VORR or VBIC |
| 4157 | if (type == OtherModImm) return SDValue(); |
| 4158 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4159 | if ((SplatBits & ~0xffff) == 0 && |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4160 | ((SplatBits | SplatUndef) & 0xff) == 0xff) { |
| 4161 | // Value = 0x0000nnff: Op=x, Cmode=1100. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4162 | OpCmode = 0xc; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4163 | Imm = SplatBits >> 8; |
| 4164 | SplatBits |= 0xff; |
| 4165 | break; |
| 4166 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4167 | |
| 4168 | if ((SplatBits & ~0xffffff) == 0 && |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4169 | ((SplatBits | SplatUndef) & 0xffff) == 0xffff) { |
| 4170 | // Value = 0x00nnffff: Op=x, Cmode=1101. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4171 | OpCmode = 0xd; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4172 | Imm = SplatBits >> 16; |
| 4173 | SplatBits |= 0xffff; |
| 4174 | break; |
| 4175 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4176 | |
| 4177 | // Note: there are a few 32-bit splat values (specifically: 00ffff00, |
| 4178 | // ff000000, ff0000ff, and ffff00ff) that are valid for VMOV.I64 but not |
| 4179 | // VMOV.I32. A (very) minor optimization would be to replicate the value |
| 4180 | // and fall through here to test for a valid 64-bit splat. But, then the |
| 4181 | // caller would also need to check and handle the change in size. |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4182 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4183 | |
| 4184 | case 64: { |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4185 | if (type != VMOVModImm) |
Bob Wilson | 827b210 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 4186 | return SDValue(); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4187 | // NEON has a 64-bit VMOV splat where each byte is either 0 or 0xff. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4188 | uint64_t BitMask = 0xff; |
| 4189 | uint64_t Val = 0; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4190 | unsigned ImmMask = 1; |
| 4191 | Imm = 0; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4192 | for (int ByteNum = 0; ByteNum < 8; ++ByteNum) { |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4193 | if (((SplatBits | SplatUndef) & BitMask) == BitMask) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4194 | Val |= BitMask; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4195 | Imm |= ImmMask; |
| 4196 | } else if ((SplatBits & BitMask) != 0) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4197 | return SDValue(); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4198 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4199 | BitMask <<= 8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4200 | ImmMask <<= 1; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4201 | } |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4202 | // Op=1, Cmode=1110. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4203 | OpCmode = 0x1e; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4204 | SplatBits = Val; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4205 | VT = is128Bits ? MVT::v2i64 : MVT::v1i64; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4206 | break; |
| 4207 | } |
| 4208 | |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4209 | default: |
Bob Wilson | dc076da | 2010-06-19 05:32:09 +0000 | [diff] [blame] | 4210 | llvm_unreachable("unexpected size for isNEONModifiedImm"); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4211 | } |
| 4212 | |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4213 | unsigned EncodedVal = ARM_AM::createNEONModImm(OpCmode, Imm); |
| 4214 | return DAG.getTargetConstant(EncodedVal, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4215 | } |
| 4216 | |
Lang Hames | c0a9f82 | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4217 | SDValue ARMTargetLowering::LowerConstantFP(SDValue Op, SelectionDAG &DAG, |
| 4218 | const ARMSubtarget *ST) const { |
| 4219 | if (!ST->useNEONForSinglePrecisionFP() || !ST->hasVFP3() || ST->hasD16()) |
| 4220 | return SDValue(); |
| 4221 | |
| 4222 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Op); |
| 4223 | assert(Op.getValueType() == MVT::f32 && |
| 4224 | "ConstantFP custom lowering should only occur for f32."); |
| 4225 | |
| 4226 | // Try splatting with a VMOV.f32... |
| 4227 | APFloat FPVal = CFP->getValueAPF(); |
| 4228 | int ImmVal = ARM_AM::getFP32Imm(FPVal); |
| 4229 | if (ImmVal != -1) { |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 4230 | SDLoc DL(Op); |
Lang Hames | c0a9f82 | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4231 | SDValue NewVal = DAG.getTargetConstant(ImmVal, MVT::i32); |
| 4232 | SDValue VecConstant = DAG.getNode(ARMISD::VMOVFPIMM, DL, MVT::v2f32, |
| 4233 | NewVal); |
| 4234 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, VecConstant, |
| 4235 | DAG.getConstant(0, MVT::i32)); |
| 4236 | } |
| 4237 | |
| 4238 | // If that fails, try a VMOV.i32 |
| 4239 | EVT VMovVT; |
| 4240 | unsigned iVal = FPVal.bitcastToAPInt().getZExtValue(); |
| 4241 | SDValue NewVal = isNEONModifiedImm(iVal, 0, 32, DAG, VMovVT, false, |
| 4242 | VMOVModImm); |
| 4243 | if (NewVal != SDValue()) { |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 4244 | SDLoc DL(Op); |
Lang Hames | c0a9f82 | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4245 | SDValue VecConstant = DAG.getNode(ARMISD::VMOVIMM, DL, VMovVT, |
| 4246 | NewVal); |
| 4247 | SDValue VecFConstant = DAG.getNode(ISD::BITCAST, DL, MVT::v2f32, |
| 4248 | VecConstant); |
| 4249 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, VecFConstant, |
| 4250 | DAG.getConstant(0, MVT::i32)); |
| 4251 | } |
| 4252 | |
| 4253 | // Finally, try a VMVN.i32 |
| 4254 | NewVal = isNEONModifiedImm(~iVal & 0xffffffff, 0, 32, DAG, VMovVT, false, |
| 4255 | VMVNModImm); |
| 4256 | if (NewVal != SDValue()) { |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 4257 | SDLoc DL(Op); |
Lang Hames | c0a9f82 | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4258 | SDValue VecConstant = DAG.getNode(ARMISD::VMVNIMM, DL, VMovVT, NewVal); |
| 4259 | SDValue VecFConstant = DAG.getNode(ISD::BITCAST, DL, MVT::v2f32, |
| 4260 | VecConstant); |
| 4261 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, VecFConstant, |
| 4262 | DAG.getConstant(0, MVT::i32)); |
| 4263 | } |
| 4264 | |
| 4265 | return SDValue(); |
| 4266 | } |
| 4267 | |
Quentin Colombet | 43934ae | 2012-11-02 21:32:17 +0000 | [diff] [blame] | 4268 | // check if an VEXT instruction can handle the shuffle mask when the |
| 4269 | // vector sources of the shuffle are the same. |
| 4270 | static bool isSingletonVEXTMask(ArrayRef<int> M, EVT VT, unsigned &Imm) { |
| 4271 | unsigned NumElts = VT.getVectorNumElements(); |
| 4272 | |
| 4273 | // Assume that the first shuffle index is not UNDEF. Fail if it is. |
| 4274 | if (M[0] < 0) |
| 4275 | return false; |
| 4276 | |
| 4277 | Imm = M[0]; |
| 4278 | |
| 4279 | // If this is a VEXT shuffle, the immediate value is the index of the first |
| 4280 | // element. The other shuffle indices must be the successive elements after |
| 4281 | // the first one. |
| 4282 | unsigned ExpectedElt = Imm; |
| 4283 | for (unsigned i = 1; i < NumElts; ++i) { |
| 4284 | // Increment the expected index. If it wraps around, just follow it |
| 4285 | // back to index zero and keep going. |
| 4286 | ++ExpectedElt; |
| 4287 | if (ExpectedElt == NumElts) |
| 4288 | ExpectedElt = 0; |
| 4289 | |
| 4290 | if (M[i] < 0) continue; // ignore UNDEF indices |
| 4291 | if (ExpectedElt != static_cast<unsigned>(M[i])) |
| 4292 | return false; |
| 4293 | } |
| 4294 | |
| 4295 | return true; |
| 4296 | } |
| 4297 | |
Lang Hames | c0a9f82 | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4298 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4299 | static bool isVEXTMask(ArrayRef<int> M, EVT VT, |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4300 | bool &ReverseVEXT, unsigned &Imm) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4301 | unsigned NumElts = VT.getVectorNumElements(); |
| 4302 | ReverseVEXT = false; |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4303 | |
| 4304 | // Assume that the first shuffle index is not UNDEF. Fail if it is. |
| 4305 | if (M[0] < 0) |
| 4306 | return false; |
| 4307 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4308 | Imm = M[0]; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4309 | |
| 4310 | // If this is a VEXT shuffle, the immediate value is the index of the first |
| 4311 | // element. The other shuffle indices must be the successive elements after |
| 4312 | // the first one. |
| 4313 | unsigned ExpectedElt = Imm; |
| 4314 | for (unsigned i = 1; i < NumElts; ++i) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4315 | // Increment the expected index. If it wraps around, it may still be |
| 4316 | // a VEXT but the source vectors must be swapped. |
| 4317 | ExpectedElt += 1; |
| 4318 | if (ExpectedElt == NumElts * 2) { |
| 4319 | ExpectedElt = 0; |
| 4320 | ReverseVEXT = true; |
| 4321 | } |
| 4322 | |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4323 | if (M[i] < 0) continue; // ignore UNDEF indices |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4324 | if (ExpectedElt != static_cast<unsigned>(M[i])) |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4325 | return false; |
| 4326 | } |
| 4327 | |
| 4328 | // Adjust the index value if the source operands will be swapped. |
| 4329 | if (ReverseVEXT) |
| 4330 | Imm -= NumElts; |
| 4331 | |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4332 | return true; |
| 4333 | } |
| 4334 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 4335 | /// isVREVMask - Check if a vector shuffle corresponds to a VREV |
| 4336 | /// instruction with the specified blocksize. (The order of the elements |
| 4337 | /// within each block of the vector is reversed.) |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4338 | static bool isVREVMask(ArrayRef<int> M, EVT VT, unsigned BlockSize) { |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 4339 | assert((BlockSize==16 || BlockSize==32 || BlockSize==64) && |
| 4340 | "Only possible block sizes for VREV are: 16, 32, 64"); |
| 4341 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 4342 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 4343 | if (EltSz == 64) |
| 4344 | return false; |
| 4345 | |
| 4346 | unsigned NumElts = VT.getVectorNumElements(); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4347 | unsigned BlockElts = M[0] + 1; |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4348 | // If the first shuffle index is UNDEF, be optimistic. |
| 4349 | if (M[0] < 0) |
| 4350 | BlockElts = BlockSize / EltSz; |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 4351 | |
| 4352 | if (BlockSize <= EltSz || BlockSize != BlockElts * EltSz) |
| 4353 | return false; |
| 4354 | |
| 4355 | for (unsigned i = 0; i < NumElts; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4356 | if (M[i] < 0) continue; // ignore UNDEF indices |
| 4357 | if ((unsigned) M[i] != (i - i%BlockElts) + (BlockElts - 1 - i%BlockElts)) |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 4358 | return false; |
| 4359 | } |
| 4360 | |
| 4361 | return true; |
| 4362 | } |
| 4363 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4364 | static bool isVTBLMask(ArrayRef<int> M, EVT VT) { |
Bill Wendling | 0d4c9d9 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 4365 | // We can handle <8 x i8> vector shuffles. If the index in the mask is out of |
| 4366 | // range, then 0 is placed into the resulting vector. So pretty much any mask |
| 4367 | // of 8 elements can work here. |
| 4368 | return VT == MVT::v8i8 && M.size() == 8; |
| 4369 | } |
| 4370 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4371 | static bool isVTRNMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 4372 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 4373 | if (EltSz == 64) |
| 4374 | return false; |
| 4375 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4376 | unsigned NumElts = VT.getVectorNumElements(); |
| 4377 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 4378 | for (unsigned i = 0; i < NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4379 | if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) || |
| 4380 | (M[i+1] >= 0 && (unsigned) M[i+1] != i + NumElts + WhichResult)) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4381 | return false; |
| 4382 | } |
| 4383 | return true; |
| 4384 | } |
| 4385 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4386 | /// isVTRN_v_undef_Mask - Special case of isVTRNMask for canonical form of |
| 4387 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 4388 | /// Mask is e.g., <0, 0, 2, 2> instead of <0, 4, 2, 6>. |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4389 | static bool isVTRN_v_undef_Mask(ArrayRef<int> M, EVT VT, unsigned &WhichResult){ |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4390 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 4391 | if (EltSz == 64) |
| 4392 | return false; |
| 4393 | |
| 4394 | unsigned NumElts = VT.getVectorNumElements(); |
| 4395 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 4396 | for (unsigned i = 0; i < NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4397 | if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) || |
| 4398 | (M[i+1] >= 0 && (unsigned) M[i+1] != i + WhichResult)) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4399 | return false; |
| 4400 | } |
| 4401 | return true; |
| 4402 | } |
| 4403 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4404 | static bool isVUZPMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 4405 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 4406 | if (EltSz == 64) |
| 4407 | return false; |
| 4408 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4409 | unsigned NumElts = VT.getVectorNumElements(); |
| 4410 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 4411 | for (unsigned i = 0; i != NumElts; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4412 | if (M[i] < 0) continue; // ignore UNDEF indices |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4413 | if ((unsigned) M[i] != 2 * i + WhichResult) |
| 4414 | return false; |
| 4415 | } |
| 4416 | |
| 4417 | // VUZP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 4418 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4419 | return false; |
| 4420 | |
| 4421 | return true; |
| 4422 | } |
| 4423 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4424 | /// isVUZP_v_undef_Mask - Special case of isVUZPMask for canonical form of |
| 4425 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 4426 | /// Mask is e.g., <0, 2, 0, 2> instead of <0, 2, 4, 6>, |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4427 | static bool isVUZP_v_undef_Mask(ArrayRef<int> M, EVT VT, unsigned &WhichResult){ |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4428 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 4429 | if (EltSz == 64) |
| 4430 | return false; |
| 4431 | |
| 4432 | unsigned Half = VT.getVectorNumElements() / 2; |
| 4433 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 4434 | for (unsigned j = 0; j != 2; ++j) { |
| 4435 | unsigned Idx = WhichResult; |
| 4436 | for (unsigned i = 0; i != Half; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4437 | int MIdx = M[i + j * Half]; |
| 4438 | if (MIdx >= 0 && (unsigned) MIdx != Idx) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4439 | return false; |
| 4440 | Idx += 2; |
| 4441 | } |
| 4442 | } |
| 4443 | |
| 4444 | // VUZP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 4445 | if (VT.is64BitVector() && EltSz == 32) |
| 4446 | return false; |
| 4447 | |
| 4448 | return true; |
| 4449 | } |
| 4450 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4451 | static bool isVZIPMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 4452 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 4453 | if (EltSz == 64) |
| 4454 | return false; |
| 4455 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4456 | unsigned NumElts = VT.getVectorNumElements(); |
| 4457 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 4458 | unsigned Idx = WhichResult * NumElts / 2; |
| 4459 | for (unsigned i = 0; i != NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4460 | if ((M[i] >= 0 && (unsigned) M[i] != Idx) || |
| 4461 | (M[i+1] >= 0 && (unsigned) M[i+1] != Idx + NumElts)) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4462 | return false; |
| 4463 | Idx += 1; |
| 4464 | } |
| 4465 | |
| 4466 | // VZIP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 4467 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4468 | return false; |
| 4469 | |
| 4470 | return true; |
| 4471 | } |
| 4472 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4473 | /// isVZIP_v_undef_Mask - Special case of isVZIPMask for canonical form of |
| 4474 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 4475 | /// Mask is e.g., <0, 0, 1, 1> instead of <0, 4, 1, 5>. |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4476 | static bool isVZIP_v_undef_Mask(ArrayRef<int> M, EVT VT, unsigned &WhichResult){ |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4477 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 4478 | if (EltSz == 64) |
| 4479 | return false; |
| 4480 | |
| 4481 | unsigned NumElts = VT.getVectorNumElements(); |
| 4482 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 4483 | unsigned Idx = WhichResult * NumElts / 2; |
| 4484 | for (unsigned i = 0; i != NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4485 | if ((M[i] >= 0 && (unsigned) M[i] != Idx) || |
| 4486 | (M[i+1] >= 0 && (unsigned) M[i+1] != Idx)) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4487 | return false; |
| 4488 | Idx += 1; |
| 4489 | } |
| 4490 | |
| 4491 | // VZIP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 4492 | if (VT.is64BitVector() && EltSz == 32) |
| 4493 | return false; |
| 4494 | |
| 4495 | return true; |
| 4496 | } |
| 4497 | |
Arnold Schwaighofer | d9316da | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 4498 | /// \return true if this is a reverse operation on an vector. |
| 4499 | static bool isReverseMask(ArrayRef<int> M, EVT VT) { |
| 4500 | unsigned NumElts = VT.getVectorNumElements(); |
| 4501 | // Make sure the mask has the right size. |
| 4502 | if (NumElts != M.size()) |
| 4503 | return false; |
| 4504 | |
| 4505 | // Look for <15, ..., 3, -1, 1, 0>. |
| 4506 | for (unsigned i = 0; i != NumElts; ++i) |
| 4507 | if (M[i] >= 0 && M[i] != (int) (NumElts - 1 - i)) |
| 4508 | return false; |
| 4509 | |
| 4510 | return true; |
| 4511 | } |
| 4512 | |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4513 | // If N is an integer constant that can be moved into a register in one |
| 4514 | // instruction, return an SDValue of such a constant (will become a MOV |
| 4515 | // instruction). Otherwise return null. |
| 4516 | static SDValue IsSingleInstrConstant(SDValue N, SelectionDAG &DAG, |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 4517 | const ARMSubtarget *ST, SDLoc dl) { |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4518 | uint64_t Val; |
| 4519 | if (!isa<ConstantSDNode>(N)) |
| 4520 | return SDValue(); |
| 4521 | Val = cast<ConstantSDNode>(N)->getZExtValue(); |
| 4522 | |
| 4523 | if (ST->isThumb1Only()) { |
| 4524 | if (Val <= 255 || ~Val <= 255) |
| 4525 | return DAG.getConstant(Val, MVT::i32); |
| 4526 | } else { |
| 4527 | if (ARM_AM::getSOImmVal(Val) != -1 || ARM_AM::getSOImmVal(~Val) != -1) |
| 4528 | return DAG.getConstant(Val, MVT::i32); |
| 4529 | } |
| 4530 | return SDValue(); |
| 4531 | } |
| 4532 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4533 | // If this is a case we can't handle, return null and let the default |
| 4534 | // expansion code take care of it. |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4535 | SDValue ARMTargetLowering::LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG, |
| 4536 | const ARMSubtarget *ST) const { |
Bob Wilson | d06791f | 2009-08-13 01:57:47 +0000 | [diff] [blame] | 4537 | BuildVectorSDNode *BVN = cast<BuildVectorSDNode>(Op.getNode()); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 4538 | SDLoc dl(Op); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4539 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4540 | |
| 4541 | APInt SplatBits, SplatUndef; |
| 4542 | unsigned SplatBitSize; |
| 4543 | bool HasAnyUndefs; |
| 4544 | if (BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
Anton Korobeynikov | 71624cc | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 4545 | if (SplatBitSize <= 64) { |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 4546 | // Check if an immediate VMOV works. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4547 | EVT VmovVT; |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 4548 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4549 | SplatUndef.getZExtValue(), SplatBitSize, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4550 | DAG, VmovVT, VT.is128BitVector(), |
| 4551 | VMOVModImm); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4552 | if (Val.getNode()) { |
| 4553 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4554 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4555 | } |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4556 | |
| 4557 | // Try an immediate VMVN. |
Eli Friedman | 8e4d042 | 2011-10-13 22:40:23 +0000 | [diff] [blame] | 4558 | uint64_t NegatedImm = (~SplatBits).getZExtValue(); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4559 | Val = isNEONModifiedImm(NegatedImm, |
| 4560 | SplatUndef.getZExtValue(), SplatBitSize, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4561 | DAG, VmovVT, VT.is128BitVector(), |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4562 | VMVNModImm); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4563 | if (Val.getNode()) { |
| 4564 | SDValue Vmov = DAG.getNode(ARMISD::VMVNIMM, dl, VmovVT, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4565 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4566 | } |
Evan Cheng | eaa192a | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 4567 | |
| 4568 | // Use vmov.f32 to materialize other v2f32 and v4f32 splats. |
Eli Friedman | 2f21e8c | 2011-12-15 22:56:53 +0000 | [diff] [blame] | 4569 | if ((VT == MVT::v2f32 || VT == MVT::v4f32) && SplatBitSize == 32) { |
Eli Friedman | effab8f | 2011-12-09 23:54:42 +0000 | [diff] [blame] | 4570 | int ImmVal = ARM_AM::getFP32Imm(SplatBits); |
Evan Cheng | eaa192a | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 4571 | if (ImmVal != -1) { |
| 4572 | SDValue Val = DAG.getTargetConstant(ImmVal, MVT::i32); |
| 4573 | return DAG.getNode(ARMISD::VMOVFPIMM, dl, VT, Val); |
| 4574 | } |
| 4575 | } |
Anton Korobeynikov | 71624cc | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 4576 | } |
Bob Wilson | cf661e2 | 2009-07-30 00:31:25 +0000 | [diff] [blame] | 4577 | } |
| 4578 | |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4579 | // Scan through the operands to see if only one value is used. |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4580 | // |
| 4581 | // As an optimisation, even if more than one value is used it may be more |
| 4582 | // profitable to splat with one value then change some lanes. |
| 4583 | // |
| 4584 | // Heuristically we decide to do this if the vector has a "dominant" value, |
| 4585 | // defined as splatted to more than half of the lanes. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4586 | unsigned NumElts = VT.getVectorNumElements(); |
| 4587 | bool isOnlyLowElement = true; |
| 4588 | bool usesOnlyOneValue = true; |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4589 | bool hasDominantValue = false; |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4590 | bool isConstant = true; |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4591 | |
| 4592 | // Map of the number of times a particular SDValue appears in the |
| 4593 | // element list. |
James Molloy | 9515434 | 2012-09-06 10:32:08 +0000 | [diff] [blame] | 4594 | DenseMap<SDValue, unsigned> ValueCounts; |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4595 | SDValue Value; |
| 4596 | for (unsigned i = 0; i < NumElts; ++i) { |
| 4597 | SDValue V = Op.getOperand(i); |
| 4598 | if (V.getOpcode() == ISD::UNDEF) |
| 4599 | continue; |
| 4600 | if (i > 0) |
| 4601 | isOnlyLowElement = false; |
| 4602 | if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V)) |
| 4603 | isConstant = false; |
| 4604 | |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4605 | ValueCounts.insert(std::make_pair(V, 0)); |
James Molloy | 9515434 | 2012-09-06 10:32:08 +0000 | [diff] [blame] | 4606 | unsigned &Count = ValueCounts[V]; |
Jim Grosbach | 7ccf463 | 2013-03-02 20:16:15 +0000 | [diff] [blame] | 4607 | |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4608 | // Is this value dominant? (takes up more than half of the lanes) |
| 4609 | if (++Count > (NumElts / 2)) { |
| 4610 | hasDominantValue = true; |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4611 | Value = V; |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4612 | } |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4613 | } |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4614 | if (ValueCounts.size() != 1) |
| 4615 | usesOnlyOneValue = false; |
| 4616 | if (!Value.getNode() && ValueCounts.size() > 0) |
| 4617 | Value = ValueCounts.begin()->first; |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4618 | |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4619 | if (ValueCounts.size() == 0) |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4620 | return DAG.getUNDEF(VT); |
| 4621 | |
| 4622 | if (isOnlyLowElement) |
| 4623 | return DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, Value); |
| 4624 | |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4625 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4626 | |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 4627 | // Use VDUP for non-constant splats. For f32 constant splats, reduce to |
| 4628 | // i32 and try again. |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4629 | if (hasDominantValue && EltSize <= 32) { |
| 4630 | if (!isConstant) { |
| 4631 | SDValue N; |
| 4632 | |
| 4633 | // If we are VDUPing a value that comes directly from a vector, that will |
| 4634 | // cause an unnecessary move to and from a GPR, where instead we could |
Jim Grosbach | 7bf504c | 2013-03-02 20:16:24 +0000 | [diff] [blame] | 4635 | // just use VDUPLANE. We can only do this if the lane being extracted |
| 4636 | // is at a constant index, as the VDUP from lane instructions only have |
| 4637 | // constant-index forms. |
| 4638 | if (Value->getOpcode() == ISD::EXTRACT_VECTOR_ELT && |
| 4639 | isa<ConstantSDNode>(Value->getOperand(1))) { |
Silviu Baranga | bb1078e | 2012-10-15 09:41:32 +0000 | [diff] [blame] | 4640 | // We need to create a new undef vector to use for the VDUPLANE if the |
| 4641 | // size of the vector from which we get the value is different than the |
| 4642 | // size of the vector that we need to create. We will insert the element |
| 4643 | // such that the register coalescer will remove unnecessary copies. |
| 4644 | if (VT != Value->getOperand(0).getValueType()) { |
| 4645 | ConstantSDNode *constIndex; |
| 4646 | constIndex = dyn_cast<ConstantSDNode>(Value->getOperand(1)); |
| 4647 | assert(constIndex && "The index is not a constant!"); |
| 4648 | unsigned index = constIndex->getAPIntValue().getLimitedValue() % |
| 4649 | VT.getVectorNumElements(); |
| 4650 | N = DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
| 4651 | DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VT, DAG.getUNDEF(VT), |
| 4652 | Value, DAG.getConstant(index, MVT::i32)), |
| 4653 | DAG.getConstant(index, MVT::i32)); |
Jim Grosbach | 65da9f1 | 2013-03-02 20:16:19 +0000 | [diff] [blame] | 4654 | } else |
Silviu Baranga | bb1078e | 2012-10-15 09:41:32 +0000 | [diff] [blame] | 4655 | N = DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4656 | Value->getOperand(0), Value->getOperand(1)); |
Jim Grosbach | 65da9f1 | 2013-03-02 20:16:19 +0000 | [diff] [blame] | 4657 | } else |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4658 | N = DAG.getNode(ARMISD::VDUP, dl, VT, Value); |
| 4659 | |
| 4660 | if (!usesOnlyOneValue) { |
| 4661 | // The dominant value was splatted as 'N', but we now have to insert |
| 4662 | // all differing elements. |
| 4663 | for (unsigned I = 0; I < NumElts; ++I) { |
| 4664 | if (Op.getOperand(I) == Value) |
| 4665 | continue; |
| 4666 | SmallVector<SDValue, 3> Ops; |
| 4667 | Ops.push_back(N); |
| 4668 | Ops.push_back(Op.getOperand(I)); |
| 4669 | Ops.push_back(DAG.getConstant(I, MVT::i32)); |
| 4670 | N = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VT, &Ops[0], 3); |
| 4671 | } |
| 4672 | } |
| 4673 | return N; |
| 4674 | } |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 4675 | if (VT.getVectorElementType().isFloatingPoint()) { |
| 4676 | SmallVector<SDValue, 8> Ops; |
| 4677 | for (unsigned i = 0; i < NumElts; ++i) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4678 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, MVT::i32, |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 4679 | Op.getOperand(i))); |
Nate Begeman | bf5be26 | 2010-11-10 21:35:41 +0000 | [diff] [blame] | 4680 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), MVT::i32, NumElts); |
| 4681 | SDValue Val = DAG.getNode(ISD::BUILD_VECTOR, dl, VecVT, &Ops[0], NumElts); |
Dale Johannesen | e4d3159 | 2010-10-20 22:03:37 +0000 | [diff] [blame] | 4682 | Val = LowerBUILD_VECTOR(Val, DAG, ST); |
| 4683 | if (Val.getNode()) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4684 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4685 | } |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4686 | if (usesOnlyOneValue) { |
| 4687 | SDValue Val = IsSingleInstrConstant(Value, DAG, ST, dl); |
| 4688 | if (isConstant && Val.getNode()) |
Jim Grosbach | 7ccf463 | 2013-03-02 20:16:15 +0000 | [diff] [blame] | 4689 | return DAG.getNode(ARMISD::VDUP, dl, VT, Val); |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4690 | } |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4691 | } |
| 4692 | |
| 4693 | // If all elements are constants and the case above didn't get hit, fall back |
| 4694 | // to the default expansion, which will generate a load from the constant |
| 4695 | // pool. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4696 | if (isConstant) |
| 4697 | return SDValue(); |
| 4698 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4699 | // Empirical tests suggest this is rarely worth it for vectors of length <= 2. |
| 4700 | if (NumElts >= 4) { |
| 4701 | SDValue shuffle = ReconstructShuffle(Op, DAG); |
| 4702 | if (shuffle != SDValue()) |
| 4703 | return shuffle; |
| 4704 | } |
| 4705 | |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4706 | // Vectors with 32- or 64-bit elements can be built by directly assigning |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4707 | // the subregisters. Lower it to an ARMISD::BUILD_VECTOR so the operands |
| 4708 | // will be legalized. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4709 | if (EltSize >= 32) { |
| 4710 | // Do the expansion with floating-point types, since that is what the VFP |
| 4711 | // registers are defined to use, and since i64 is not legal. |
| 4712 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 4713 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4714 | SmallVector<SDValue, 8> Ops; |
| 4715 | for (unsigned i = 0; i < NumElts; ++i) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4716 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, EltVT, Op.getOperand(i))); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4717 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, &Ops[0],NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4718 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4719 | } |
| 4720 | |
| 4721 | return SDValue(); |
| 4722 | } |
| 4723 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4724 | // Gather data to see if the operation can be modelled as a |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4725 | // shuffle in combination with VEXTs. |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4726 | SDValue ARMTargetLowering::ReconstructShuffle(SDValue Op, |
| 4727 | SelectionDAG &DAG) const { |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 4728 | SDLoc dl(Op); |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4729 | EVT VT = Op.getValueType(); |
| 4730 | unsigned NumElts = VT.getVectorNumElements(); |
| 4731 | |
| 4732 | SmallVector<SDValue, 2> SourceVecs; |
| 4733 | SmallVector<unsigned, 2> MinElts; |
| 4734 | SmallVector<unsigned, 2> MaxElts; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4735 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4736 | for (unsigned i = 0; i < NumElts; ++i) { |
| 4737 | SDValue V = Op.getOperand(i); |
| 4738 | if (V.getOpcode() == ISD::UNDEF) |
| 4739 | continue; |
| 4740 | else if (V.getOpcode() != ISD::EXTRACT_VECTOR_ELT) { |
| 4741 | // A shuffle can only come from building a vector from various |
| 4742 | // elements of other vectors. |
| 4743 | return SDValue(); |
Eli Friedman | 46995fa | 2011-10-14 23:58:49 +0000 | [diff] [blame] | 4744 | } else if (V.getOperand(0).getValueType().getVectorElementType() != |
| 4745 | VT.getVectorElementType()) { |
| 4746 | // This code doesn't know how to handle shuffles where the vector |
| 4747 | // element types do not match (this happens because type legalization |
| 4748 | // promotes the return type of EXTRACT_VECTOR_ELT). |
| 4749 | // FIXME: It might be appropriate to extend this code to handle |
| 4750 | // mismatched types. |
| 4751 | return SDValue(); |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4752 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4753 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4754 | // Record this extraction against the appropriate vector if possible... |
| 4755 | SDValue SourceVec = V.getOperand(0); |
Jim Grosbach | 2422047 | 2012-07-25 17:02:47 +0000 | [diff] [blame] | 4756 | // If the element number isn't a constant, we can't effectively |
| 4757 | // analyze what's going on. |
| 4758 | if (!isa<ConstantSDNode>(V.getOperand(1))) |
| 4759 | return SDValue(); |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4760 | unsigned EltNo = cast<ConstantSDNode>(V.getOperand(1))->getZExtValue(); |
| 4761 | bool FoundSource = false; |
| 4762 | for (unsigned j = 0; j < SourceVecs.size(); ++j) { |
| 4763 | if (SourceVecs[j] == SourceVec) { |
| 4764 | if (MinElts[j] > EltNo) |
| 4765 | MinElts[j] = EltNo; |
| 4766 | if (MaxElts[j] < EltNo) |
| 4767 | MaxElts[j] = EltNo; |
| 4768 | FoundSource = true; |
| 4769 | break; |
| 4770 | } |
| 4771 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4772 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4773 | // Or record a new source if not... |
| 4774 | if (!FoundSource) { |
| 4775 | SourceVecs.push_back(SourceVec); |
| 4776 | MinElts.push_back(EltNo); |
| 4777 | MaxElts.push_back(EltNo); |
| 4778 | } |
| 4779 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4780 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4781 | // Currently only do something sane when at most two source vectors |
| 4782 | // involved. |
| 4783 | if (SourceVecs.size() > 2) |
| 4784 | return SDValue(); |
| 4785 | |
| 4786 | SDValue ShuffleSrcs[2] = {DAG.getUNDEF(VT), DAG.getUNDEF(VT) }; |
| 4787 | int VEXTOffsets[2] = {0, 0}; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4788 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4789 | // This loop extracts the usage patterns of the source vectors |
| 4790 | // and prepares appropriate SDValues for a shuffle if possible. |
| 4791 | for (unsigned i = 0; i < SourceVecs.size(); ++i) { |
| 4792 | if (SourceVecs[i].getValueType() == VT) { |
| 4793 | // No VEXT necessary |
| 4794 | ShuffleSrcs[i] = SourceVecs[i]; |
| 4795 | VEXTOffsets[i] = 0; |
| 4796 | continue; |
| 4797 | } else if (SourceVecs[i].getValueType().getVectorNumElements() < NumElts) { |
| 4798 | // It probably isn't worth padding out a smaller vector just to |
| 4799 | // break it down again in a shuffle. |
| 4800 | return SDValue(); |
| 4801 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4802 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4803 | // Since only 64-bit and 128-bit vectors are legal on ARM and |
| 4804 | // we've eliminated the other cases... |
Bob Wilson | 70f8573 | 2011-01-07 23:40:46 +0000 | [diff] [blame] | 4805 | assert(SourceVecs[i].getValueType().getVectorNumElements() == 2*NumElts && |
| 4806 | "unexpected vector sizes in ReconstructShuffle"); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4807 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4808 | if (MaxElts[i] - MinElts[i] >= NumElts) { |
| 4809 | // Span too large for a VEXT to cope |
| 4810 | return SDValue(); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4811 | } |
| 4812 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4813 | if (MinElts[i] >= NumElts) { |
| 4814 | // The extraction can just take the second half |
| 4815 | VEXTOffsets[i] = NumElts; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4816 | ShuffleSrcs[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4817 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4818 | DAG.getIntPtrConstant(NumElts)); |
| 4819 | } else if (MaxElts[i] < NumElts) { |
| 4820 | // The extraction can just take the first half |
| 4821 | VEXTOffsets[i] = 0; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4822 | ShuffleSrcs[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4823 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4824 | DAG.getIntPtrConstant(0)); |
| 4825 | } else { |
| 4826 | // An actual VEXT is needed |
| 4827 | VEXTOffsets[i] = MinElts[i]; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4828 | SDValue VEXTSrc1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4829 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4830 | DAG.getIntPtrConstant(0)); |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4831 | SDValue VEXTSrc2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4832 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4833 | DAG.getIntPtrConstant(NumElts)); |
| 4834 | ShuffleSrcs[i] = DAG.getNode(ARMISD::VEXT, dl, VT, VEXTSrc1, VEXTSrc2, |
| 4835 | DAG.getConstant(VEXTOffsets[i], MVT::i32)); |
| 4836 | } |
| 4837 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4838 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4839 | SmallVector<int, 8> Mask; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4840 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4841 | for (unsigned i = 0; i < NumElts; ++i) { |
| 4842 | SDValue Entry = Op.getOperand(i); |
| 4843 | if (Entry.getOpcode() == ISD::UNDEF) { |
| 4844 | Mask.push_back(-1); |
| 4845 | continue; |
| 4846 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4847 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4848 | SDValue ExtractVec = Entry.getOperand(0); |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4849 | int ExtractElt = cast<ConstantSDNode>(Op.getOperand(i) |
| 4850 | .getOperand(1))->getSExtValue(); |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4851 | if (ExtractVec == SourceVecs[0]) { |
| 4852 | Mask.push_back(ExtractElt - VEXTOffsets[0]); |
| 4853 | } else { |
| 4854 | Mask.push_back(ExtractElt + NumElts - VEXTOffsets[1]); |
| 4855 | } |
| 4856 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4857 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4858 | // Final check before we try to produce nonsense... |
| 4859 | if (isShuffleMaskLegal(Mask, VT)) |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4860 | return DAG.getVectorShuffle(VT, dl, ShuffleSrcs[0], ShuffleSrcs[1], |
| 4861 | &Mask[0]); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4862 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4863 | return SDValue(); |
| 4864 | } |
| 4865 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4866 | /// isShuffleMaskLegal - Targets can use this to indicate that they only |
| 4867 | /// support *some* VECTOR_SHUFFLE operations, those with specific masks. |
| 4868 | /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values |
| 4869 | /// are assumed to be legal. |
| 4870 | bool |
| 4871 | ARMTargetLowering::isShuffleMaskLegal(const SmallVectorImpl<int> &M, |
| 4872 | EVT VT) const { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4873 | if (VT.getVectorNumElements() == 4 && |
| 4874 | (VT.is128BitVector() || VT.is64BitVector())) { |
| 4875 | unsigned PFIndexes[4]; |
| 4876 | for (unsigned i = 0; i != 4; ++i) { |
| 4877 | if (M[i] < 0) |
| 4878 | PFIndexes[i] = 8; |
| 4879 | else |
| 4880 | PFIndexes[i] = M[i]; |
| 4881 | } |
| 4882 | |
| 4883 | // Compute the index in the perfect shuffle table. |
| 4884 | unsigned PFTableIndex = |
| 4885 | PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3]; |
| 4886 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 4887 | unsigned Cost = (PFEntry >> 30); |
| 4888 | |
| 4889 | if (Cost <= 4) |
| 4890 | return true; |
| 4891 | } |
| 4892 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4893 | bool ReverseVEXT; |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4894 | unsigned Imm, WhichResult; |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4895 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4896 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4897 | return (EltSize >= 32 || |
| 4898 | ShuffleVectorSDNode::isSplatMask(&M[0], VT) || |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4899 | isVREVMask(M, VT, 64) || |
| 4900 | isVREVMask(M, VT, 32) || |
| 4901 | isVREVMask(M, VT, 16) || |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4902 | isVEXTMask(M, VT, ReverseVEXT, Imm) || |
Bill Wendling | 0d4c9d9 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 4903 | isVTBLMask(M, VT) || |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4904 | isVTRNMask(M, VT, WhichResult) || |
| 4905 | isVUZPMask(M, VT, WhichResult) || |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4906 | isVZIPMask(M, VT, WhichResult) || |
| 4907 | isVTRN_v_undef_Mask(M, VT, WhichResult) || |
| 4908 | isVUZP_v_undef_Mask(M, VT, WhichResult) || |
Arnold Schwaighofer | d9316da | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 4909 | isVZIP_v_undef_Mask(M, VT, WhichResult) || |
| 4910 | ((VT == MVT::v8i16 || VT == MVT::v16i8) && isReverseMask(M, VT))); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4911 | } |
| 4912 | |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4913 | /// GeneratePerfectShuffle - Given an entry in the perfect-shuffle table, emit |
| 4914 | /// the specified operations to build the shuffle. |
| 4915 | static SDValue GeneratePerfectShuffle(unsigned PFEntry, SDValue LHS, |
| 4916 | SDValue RHS, SelectionDAG &DAG, |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 4917 | SDLoc dl) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4918 | unsigned OpNum = (PFEntry >> 26) & 0x0F; |
| 4919 | unsigned LHSID = (PFEntry >> 13) & ((1 << 13)-1); |
| 4920 | unsigned RHSID = (PFEntry >> 0) & ((1 << 13)-1); |
| 4921 | |
| 4922 | enum { |
| 4923 | OP_COPY = 0, // Copy, used for things like <u,u,u,3> to say it is <0,1,2,3> |
| 4924 | OP_VREV, |
| 4925 | OP_VDUP0, |
| 4926 | OP_VDUP1, |
| 4927 | OP_VDUP2, |
| 4928 | OP_VDUP3, |
| 4929 | OP_VEXT1, |
| 4930 | OP_VEXT2, |
| 4931 | OP_VEXT3, |
| 4932 | OP_VUZPL, // VUZP, left result |
| 4933 | OP_VUZPR, // VUZP, right result |
| 4934 | OP_VZIPL, // VZIP, left result |
| 4935 | OP_VZIPR, // VZIP, right result |
| 4936 | OP_VTRNL, // VTRN, left result |
| 4937 | OP_VTRNR // VTRN, right result |
| 4938 | }; |
| 4939 | |
| 4940 | if (OpNum == OP_COPY) { |
| 4941 | if (LHSID == (1*9+2)*9+3) return LHS; |
| 4942 | assert(LHSID == ((4*9+5)*9+6)*9+7 && "Illegal OP_COPY!"); |
| 4943 | return RHS; |
| 4944 | } |
| 4945 | |
| 4946 | SDValue OpLHS, OpRHS; |
| 4947 | OpLHS = GeneratePerfectShuffle(PerfectShuffleTable[LHSID], LHS, RHS, DAG, dl); |
| 4948 | OpRHS = GeneratePerfectShuffle(PerfectShuffleTable[RHSID], LHS, RHS, DAG, dl); |
| 4949 | EVT VT = OpLHS.getValueType(); |
| 4950 | |
| 4951 | switch (OpNum) { |
| 4952 | default: llvm_unreachable("Unknown shuffle opcode!"); |
| 4953 | case OP_VREV: |
Tanya Lattner | 2a8eb72 | 2011-05-18 06:42:21 +0000 | [diff] [blame] | 4954 | // VREV divides the vector in half and swaps within the half. |
Tanya Lattner | db28247 | 2011-05-18 21:44:54 +0000 | [diff] [blame] | 4955 | if (VT.getVectorElementType() == MVT::i32 || |
| 4956 | VT.getVectorElementType() == MVT::f32) |
Tanya Lattner | 2a8eb72 | 2011-05-18 06:42:21 +0000 | [diff] [blame] | 4957 | return DAG.getNode(ARMISD::VREV64, dl, VT, OpLHS); |
| 4958 | // vrev <4 x i16> -> VREV32 |
| 4959 | if (VT.getVectorElementType() == MVT::i16) |
| 4960 | return DAG.getNode(ARMISD::VREV32, dl, VT, OpLHS); |
| 4961 | // vrev <4 x i8> -> VREV16 |
| 4962 | assert(VT.getVectorElementType() == MVT::i8); |
| 4963 | return DAG.getNode(ARMISD::VREV16, dl, VT, OpLHS); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4964 | case OP_VDUP0: |
| 4965 | case OP_VDUP1: |
| 4966 | case OP_VDUP2: |
| 4967 | case OP_VDUP3: |
| 4968 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4969 | OpLHS, DAG.getConstant(OpNum-OP_VDUP0, MVT::i32)); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4970 | case OP_VEXT1: |
| 4971 | case OP_VEXT2: |
| 4972 | case OP_VEXT3: |
| 4973 | return DAG.getNode(ARMISD::VEXT, dl, VT, |
| 4974 | OpLHS, OpRHS, |
| 4975 | DAG.getConstant(OpNum-OP_VEXT1+1, MVT::i32)); |
| 4976 | case OP_VUZPL: |
| 4977 | case OP_VUZPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4978 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4979 | OpLHS, OpRHS).getValue(OpNum-OP_VUZPL); |
| 4980 | case OP_VZIPL: |
| 4981 | case OP_VZIPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4982 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4983 | OpLHS, OpRHS).getValue(OpNum-OP_VZIPL); |
| 4984 | case OP_VTRNL: |
| 4985 | case OP_VTRNR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4986 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4987 | OpLHS, OpRHS).getValue(OpNum-OP_VTRNL); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4988 | } |
| 4989 | } |
| 4990 | |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4991 | static SDValue LowerVECTOR_SHUFFLEv8i8(SDValue Op, |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4992 | ArrayRef<int> ShuffleMask, |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4993 | SelectionDAG &DAG) { |
| 4994 | // Check to see if we can use the VTBL instruction. |
| 4995 | SDValue V1 = Op.getOperand(0); |
| 4996 | SDValue V2 = Op.getOperand(1); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 4997 | SDLoc DL(Op); |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4998 | |
| 4999 | SmallVector<SDValue, 8> VTBLMask; |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 5000 | for (ArrayRef<int>::iterator |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 5001 | I = ShuffleMask.begin(), E = ShuffleMask.end(); I != E; ++I) |
| 5002 | VTBLMask.push_back(DAG.getConstant(*I, MVT::i32)); |
| 5003 | |
| 5004 | if (V2.getNode()->getOpcode() == ISD::UNDEF) |
| 5005 | return DAG.getNode(ARMISD::VTBL1, DL, MVT::v8i8, V1, |
| 5006 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, |
| 5007 | &VTBLMask[0], 8)); |
Bill Wendling | a24cb40 | 2011-03-15 20:47:26 +0000 | [diff] [blame] | 5008 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5009 | return DAG.getNode(ARMISD::VTBL2, DL, MVT::v8i8, V1, V2, |
Bill Wendling | a24cb40 | 2011-03-15 20:47:26 +0000 | [diff] [blame] | 5010 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, |
| 5011 | &VTBLMask[0], 8)); |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 5012 | } |
| 5013 | |
Arnold Schwaighofer | d9316da | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 5014 | static SDValue LowerReverse_VECTOR_SHUFFLEv16i8_v8i16(SDValue Op, |
| 5015 | SelectionDAG &DAG) { |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 5016 | SDLoc DL(Op); |
Arnold Schwaighofer | d9316da | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 5017 | SDValue OpLHS = Op.getOperand(0); |
| 5018 | EVT VT = OpLHS.getValueType(); |
| 5019 | |
| 5020 | assert((VT == MVT::v8i16 || VT == MVT::v16i8) && |
| 5021 | "Expect an v8i16/v16i8 type"); |
| 5022 | OpLHS = DAG.getNode(ARMISD::VREV64, DL, VT, OpLHS); |
| 5023 | // For a v16i8 type: After the VREV, we have got <8, ...15, 8, ..., 0>. Now, |
| 5024 | // extract the first 8 bytes into the top double word and the last 8 bytes |
| 5025 | // into the bottom double word. The v8i16 case is similar. |
| 5026 | unsigned ExtractNum = (VT == MVT::v16i8) ? 8 : 4; |
| 5027 | return DAG.getNode(ARMISD::VEXT, DL, VT, OpLHS, OpLHS, |
| 5028 | DAG.getConstant(ExtractNum, MVT::i32)); |
| 5029 | } |
| 5030 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5031 | static SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5032 | SDValue V1 = Op.getOperand(0); |
| 5033 | SDValue V2 = Op.getOperand(1); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 5034 | SDLoc dl(Op); |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 5035 | EVT VT = Op.getValueType(); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5036 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op.getNode()); |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 5037 | |
Bob Wilson | 2886506 | 2009-08-13 02:13:04 +0000 | [diff] [blame] | 5038 | // Convert shuffles that are directly supported on NEON to target-specific |
| 5039 | // DAG nodes, instead of keeping them as shuffles and matching them again |
| 5040 | // during code selection. This is more efficient and avoids the possibility |
| 5041 | // of inconsistencies between legalization and selection. |
Bob Wilson | bfcbb50 | 2009-08-13 06:01:30 +0000 | [diff] [blame] | 5042 | // FIXME: floating-point vectors should be canonicalized to integer vectors |
| 5043 | // of the same time so that they get CSEd properly. |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 5044 | ArrayRef<int> ShuffleMask = SVN->getMask(); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 5045 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 5046 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 5047 | if (EltSize <= 32) { |
| 5048 | if (ShuffleVectorSDNode::isSplatMask(&ShuffleMask[0], VT)) { |
| 5049 | int Lane = SVN->getSplatIndex(); |
| 5050 | // If this is undef splat, generate it via "just" vdup, if possible. |
| 5051 | if (Lane == -1) Lane = 0; |
Anton Korobeynikov | 2ae0eec | 2009-11-02 00:12:06 +0000 | [diff] [blame] | 5052 | |
Dan Gohman | 65fd656 | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 5053 | // Test if V1 is a SCALAR_TO_VECTOR. |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 5054 | if (Lane == 0 && V1.getOpcode() == ISD::SCALAR_TO_VECTOR) { |
| 5055 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); |
| 5056 | } |
Dan Gohman | 65fd656 | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 5057 | // Test if V1 is a BUILD_VECTOR which is equivalent to a SCALAR_TO_VECTOR |
| 5058 | // (and probably will turn into a SCALAR_TO_VECTOR once legalization |
| 5059 | // reaches it). |
| 5060 | if (Lane == 0 && V1.getOpcode() == ISD::BUILD_VECTOR && |
| 5061 | !isa<ConstantSDNode>(V1.getOperand(0))) { |
| 5062 | bool IsScalarToVector = true; |
| 5063 | for (unsigned i = 1, e = V1.getNumOperands(); i != e; ++i) |
| 5064 | if (V1.getOperand(i).getOpcode() != ISD::UNDEF) { |
| 5065 | IsScalarToVector = false; |
| 5066 | break; |
| 5067 | } |
| 5068 | if (IsScalarToVector) |
| 5069 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); |
| 5070 | } |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 5071 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, V1, |
| 5072 | DAG.getConstant(Lane, MVT::i32)); |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 5073 | } |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 5074 | |
| 5075 | bool ReverseVEXT; |
| 5076 | unsigned Imm; |
| 5077 | if (isVEXTMask(ShuffleMask, VT, ReverseVEXT, Imm)) { |
| 5078 | if (ReverseVEXT) |
| 5079 | std::swap(V1, V2); |
| 5080 | return DAG.getNode(ARMISD::VEXT, dl, VT, V1, V2, |
| 5081 | DAG.getConstant(Imm, MVT::i32)); |
| 5082 | } |
| 5083 | |
| 5084 | if (isVREVMask(ShuffleMask, VT, 64)) |
| 5085 | return DAG.getNode(ARMISD::VREV64, dl, VT, V1); |
| 5086 | if (isVREVMask(ShuffleMask, VT, 32)) |
| 5087 | return DAG.getNode(ARMISD::VREV32, dl, VT, V1); |
| 5088 | if (isVREVMask(ShuffleMask, VT, 16)) |
| 5089 | return DAG.getNode(ARMISD::VREV16, dl, VT, V1); |
| 5090 | |
Quentin Colombet | 43934ae | 2012-11-02 21:32:17 +0000 | [diff] [blame] | 5091 | if (V2->getOpcode() == ISD::UNDEF && |
| 5092 | isSingletonVEXTMask(ShuffleMask, VT, Imm)) { |
| 5093 | return DAG.getNode(ARMISD::VEXT, dl, VT, V1, V1, |
| 5094 | DAG.getConstant(Imm, MVT::i32)); |
| 5095 | } |
| 5096 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 5097 | // Check for Neon shuffles that modify both input vectors in place. |
| 5098 | // If both results are used, i.e., if there are two shuffles with the same |
| 5099 | // source operands and with masks corresponding to both results of one of |
| 5100 | // these operations, DAG memoization will ensure that a single node is |
| 5101 | // used for both shuffles. |
| 5102 | unsigned WhichResult; |
| 5103 | if (isVTRNMask(ShuffleMask, VT, WhichResult)) |
| 5104 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 5105 | V1, V2).getValue(WhichResult); |
| 5106 | if (isVUZPMask(ShuffleMask, VT, WhichResult)) |
| 5107 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 5108 | V1, V2).getValue(WhichResult); |
| 5109 | if (isVZIPMask(ShuffleMask, VT, WhichResult)) |
| 5110 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 5111 | V1, V2).getValue(WhichResult); |
| 5112 | |
| 5113 | if (isVTRN_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 5114 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 5115 | V1, V1).getValue(WhichResult); |
| 5116 | if (isVUZP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 5117 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 5118 | V1, V1).getValue(WhichResult); |
| 5119 | if (isVZIP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 5120 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 5121 | V1, V1).getValue(WhichResult); |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 5122 | } |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 5123 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5124 | // If the shuffle is not directly supported and it has 4 elements, use |
| 5125 | // the PerfectShuffle-generated table to synthesize it from other shuffles. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5126 | unsigned NumElts = VT.getVectorNumElements(); |
| 5127 | if (NumElts == 4) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5128 | unsigned PFIndexes[4]; |
| 5129 | for (unsigned i = 0; i != 4; ++i) { |
| 5130 | if (ShuffleMask[i] < 0) |
| 5131 | PFIndexes[i] = 8; |
| 5132 | else |
| 5133 | PFIndexes[i] = ShuffleMask[i]; |
| 5134 | } |
| 5135 | |
| 5136 | // Compute the index in the perfect shuffle table. |
| 5137 | unsigned PFTableIndex = |
| 5138 | PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3]; |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5139 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 5140 | unsigned Cost = (PFEntry >> 30); |
| 5141 | |
| 5142 | if (Cost <= 4) |
| 5143 | return GeneratePerfectShuffle(PFEntry, V1, V2, DAG, dl); |
| 5144 | } |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 5145 | |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 5146 | // Implement shuffles with 32- or 64-bit elements as ARMISD::BUILD_VECTORs. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5147 | if (EltSize >= 32) { |
| 5148 | // Do the expansion with floating-point types, since that is what the VFP |
| 5149 | // registers are defined to use, and since i64 is not legal. |
| 5150 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 5151 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5152 | V1 = DAG.getNode(ISD::BITCAST, dl, VecVT, V1); |
| 5153 | V2 = DAG.getNode(ISD::BITCAST, dl, VecVT, V2); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 5154 | SmallVector<SDValue, 8> Ops; |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5155 | for (unsigned i = 0; i < NumElts; ++i) { |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 5156 | if (ShuffleMask[i] < 0) |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 5157 | Ops.push_back(DAG.getUNDEF(EltVT)); |
| 5158 | else |
| 5159 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, |
| 5160 | ShuffleMask[i] < (int)NumElts ? V1 : V2, |
| 5161 | DAG.getConstant(ShuffleMask[i] & (NumElts-1), |
| 5162 | MVT::i32))); |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 5163 | } |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 5164 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, &Ops[0],NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5165 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 5166 | } |
| 5167 | |
Arnold Schwaighofer | d9316da | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 5168 | if ((VT == MVT::v8i16 || VT == MVT::v16i8) && isReverseMask(ShuffleMask, VT)) |
| 5169 | return LowerReverse_VECTOR_SHUFFLEv16i8_v8i16(Op, DAG); |
| 5170 | |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 5171 | if (VT == MVT::v8i8) { |
| 5172 | SDValue NewOp = LowerVECTOR_SHUFFLEv8i8(Op, ShuffleMask, DAG); |
| 5173 | if (NewOp.getNode()) |
| 5174 | return NewOp; |
| 5175 | } |
| 5176 | |
Bob Wilson | 22cac0d | 2009-08-14 05:16:33 +0000 | [diff] [blame] | 5177 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5178 | } |
| 5179 | |
Eli Friedman | 5c89cb8 | 2011-10-24 23:08:52 +0000 | [diff] [blame] | 5180 | static SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
| 5181 | // INSERT_VECTOR_ELT is legal only for immediate indexes. |
| 5182 | SDValue Lane = Op.getOperand(2); |
| 5183 | if (!isa<ConstantSDNode>(Lane)) |
| 5184 | return SDValue(); |
| 5185 | |
| 5186 | return Op; |
| 5187 | } |
| 5188 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5189 | static SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 5190 | // EXTRACT_VECTOR_ELT is legal only for immediate indexes. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5191 | SDValue Lane = Op.getOperand(1); |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 5192 | if (!isa<ConstantSDNode>(Lane)) |
| 5193 | return SDValue(); |
| 5194 | |
| 5195 | SDValue Vec = Op.getOperand(0); |
| 5196 | if (Op.getValueType() == MVT::i32 && |
| 5197 | Vec.getValueType().getVectorElementType().getSizeInBits() < 32) { |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 5198 | SDLoc dl(Op); |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 5199 | return DAG.getNode(ARMISD::VGETLANEu, dl, MVT::i32, Vec, Lane); |
| 5200 | } |
| 5201 | |
| 5202 | return Op; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5203 | } |
| 5204 | |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 5205 | static SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) { |
| 5206 | // The only time a CONCAT_VECTORS operation can have legal types is when |
| 5207 | // two 64-bit vectors are concatenated to a 128-bit vector. |
| 5208 | assert(Op.getValueType().is128BitVector() && Op.getNumOperands() == 2 && |
| 5209 | "unexpected CONCAT_VECTORS"); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 5210 | SDLoc dl(Op); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5211 | SDValue Val = DAG.getUNDEF(MVT::v2f64); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 5212 | SDValue Op0 = Op.getOperand(0); |
| 5213 | SDValue Op1 = Op.getOperand(1); |
| 5214 | if (Op0.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5215 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5216 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op0), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 5217 | DAG.getIntPtrConstant(0)); |
| 5218 | if (Op1.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5219 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5220 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op1), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 5221 | DAG.getIntPtrConstant(1)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5222 | return DAG.getNode(ISD::BITCAST, dl, Op.getValueType(), Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5223 | } |
| 5224 | |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 5225 | /// isExtendedBUILD_VECTOR - Check if N is a constant BUILD_VECTOR where each |
| 5226 | /// element has been zero/sign-extended, depending on the isSigned parameter, |
| 5227 | /// from an integer type half its size. |
| 5228 | static bool isExtendedBUILD_VECTOR(SDNode *N, SelectionDAG &DAG, |
| 5229 | bool isSigned) { |
| 5230 | // A v2i64 BUILD_VECTOR will have been legalized to a BITCAST from v4i32. |
| 5231 | EVT VT = N->getValueType(0); |
| 5232 | if (VT == MVT::v2i64 && N->getOpcode() == ISD::BITCAST) { |
| 5233 | SDNode *BVN = N->getOperand(0).getNode(); |
| 5234 | if (BVN->getValueType(0) != MVT::v4i32 || |
| 5235 | BVN->getOpcode() != ISD::BUILD_VECTOR) |
| 5236 | return false; |
| 5237 | unsigned LoElt = DAG.getTargetLoweringInfo().isBigEndian() ? 1 : 0; |
| 5238 | unsigned HiElt = 1 - LoElt; |
| 5239 | ConstantSDNode *Lo0 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt)); |
| 5240 | ConstantSDNode *Hi0 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt)); |
| 5241 | ConstantSDNode *Lo1 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt+2)); |
| 5242 | ConstantSDNode *Hi1 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt+2)); |
| 5243 | if (!Lo0 || !Hi0 || !Lo1 || !Hi1) |
| 5244 | return false; |
| 5245 | if (isSigned) { |
| 5246 | if (Hi0->getSExtValue() == Lo0->getSExtValue() >> 32 && |
| 5247 | Hi1->getSExtValue() == Lo1->getSExtValue() >> 32) |
| 5248 | return true; |
| 5249 | } else { |
| 5250 | if (Hi0->isNullValue() && Hi1->isNullValue()) |
| 5251 | return true; |
| 5252 | } |
| 5253 | return false; |
| 5254 | } |
| 5255 | |
| 5256 | if (N->getOpcode() != ISD::BUILD_VECTOR) |
| 5257 | return false; |
| 5258 | |
| 5259 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
| 5260 | SDNode *Elt = N->getOperand(i).getNode(); |
| 5261 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Elt)) { |
| 5262 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 5263 | unsigned HalfSize = EltSize / 2; |
| 5264 | if (isSigned) { |
Bob Wilson | 9d45de2 | 2011-10-18 18:46:49 +0000 | [diff] [blame] | 5265 | if (!isIntN(HalfSize, C->getSExtValue())) |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 5266 | return false; |
| 5267 | } else { |
Bob Wilson | 9d45de2 | 2011-10-18 18:46:49 +0000 | [diff] [blame] | 5268 | if (!isUIntN(HalfSize, C->getZExtValue())) |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 5269 | return false; |
| 5270 | } |
| 5271 | continue; |
| 5272 | } |
| 5273 | return false; |
| 5274 | } |
| 5275 | |
| 5276 | return true; |
| 5277 | } |
| 5278 | |
| 5279 | /// isSignExtended - Check if a node is a vector value that is sign-extended |
| 5280 | /// or a constant BUILD_VECTOR with sign-extended elements. |
| 5281 | static bool isSignExtended(SDNode *N, SelectionDAG &DAG) { |
| 5282 | if (N->getOpcode() == ISD::SIGN_EXTEND || ISD::isSEXTLoad(N)) |
| 5283 | return true; |
| 5284 | if (isExtendedBUILD_VECTOR(N, DAG, true)) |
| 5285 | return true; |
| 5286 | return false; |
| 5287 | } |
| 5288 | |
| 5289 | /// isZeroExtended - Check if a node is a vector value that is zero-extended |
| 5290 | /// or a constant BUILD_VECTOR with zero-extended elements. |
| 5291 | static bool isZeroExtended(SDNode *N, SelectionDAG &DAG) { |
| 5292 | if (N->getOpcode() == ISD::ZERO_EXTEND || ISD::isZEXTLoad(N)) |
| 5293 | return true; |
| 5294 | if (isExtendedBUILD_VECTOR(N, DAG, false)) |
| 5295 | return true; |
| 5296 | return false; |
| 5297 | } |
| 5298 | |
Arnold Schwaighofer | 101a361 | 2013-05-14 22:33:24 +0000 | [diff] [blame] | 5299 | static EVT getExtensionTo64Bits(const EVT &OrigVT) { |
| 5300 | if (OrigVT.getSizeInBits() >= 64) |
| 5301 | return OrigVT; |
| 5302 | |
| 5303 | assert(OrigVT.isSimple() && "Expecting a simple value type"); |
| 5304 | |
| 5305 | MVT::SimpleValueType OrigSimpleTy = OrigVT.getSimpleVT().SimpleTy; |
| 5306 | switch (OrigSimpleTy) { |
| 5307 | default: llvm_unreachable("Unexpected Vector Type"); |
| 5308 | case MVT::v2i8: |
| 5309 | case MVT::v2i16: |
| 5310 | return MVT::v2i32; |
| 5311 | case MVT::v4i8: |
| 5312 | return MVT::v4i16; |
| 5313 | } |
| 5314 | } |
| 5315 | |
Sebastian Pop | cb49530 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5316 | /// AddRequiredExtensionForVMULL - Add a sign/zero extension to extend the total |
| 5317 | /// value size to 64 bits. We need a 64-bit D register as an operand to VMULL. |
| 5318 | /// We insert the required extension here to get the vector to fill a D register. |
| 5319 | static SDValue AddRequiredExtensionForVMULL(SDValue N, SelectionDAG &DAG, |
| 5320 | const EVT &OrigTy, |
| 5321 | const EVT &ExtTy, |
| 5322 | unsigned ExtOpcode) { |
| 5323 | // The vector originally had a size of OrigTy. It was then extended to ExtTy. |
| 5324 | // We expect the ExtTy to be 128-bits total. If the OrigTy is less than |
| 5325 | // 64-bits we need to insert a new extension so that it will be 64-bits. |
| 5326 | assert(ExtTy.is128BitVector() && "Unexpected extension size"); |
| 5327 | if (OrigTy.getSizeInBits() >= 64) |
| 5328 | return N; |
| 5329 | |
| 5330 | // Must extend size to at least 64 bits to be used as an operand for VMULL. |
Arnold Schwaighofer | 101a361 | 2013-05-14 22:33:24 +0000 | [diff] [blame] | 5331 | EVT NewVT = getExtensionTo64Bits(OrigTy); |
| 5332 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 5333 | return DAG.getNode(ExtOpcode, SDLoc(N), NewVT, N); |
Sebastian Pop | cb49530 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5334 | } |
| 5335 | |
| 5336 | /// SkipLoadExtensionForVMULL - return a load of the original vector size that |
| 5337 | /// does not do any sign/zero extension. If the original vector is less |
| 5338 | /// than 64 bits, an appropriate extension will be added after the load to |
| 5339 | /// reach a total size of 64 bits. We have to add the extension separately |
| 5340 | /// because ARM does not have a sign/zero extending load for vectors. |
| 5341 | static SDValue SkipLoadExtensionForVMULL(LoadSDNode *LD, SelectionDAG& DAG) { |
Arnold Schwaighofer | 101a361 | 2013-05-14 22:33:24 +0000 | [diff] [blame] | 5342 | EVT ExtendedTy = getExtensionTo64Bits(LD->getMemoryVT()); |
| 5343 | |
| 5344 | // The load already has the right type. |
| 5345 | if (ExtendedTy == LD->getMemoryVT()) |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 5346 | return DAG.getLoad(LD->getMemoryVT(), SDLoc(LD), LD->getChain(), |
Sebastian Pop | cb49530 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5347 | LD->getBasePtr(), LD->getPointerInfo(), LD->isVolatile(), |
| 5348 | LD->isNonTemporal(), LD->isInvariant(), |
| 5349 | LD->getAlignment()); |
Arnold Schwaighofer | 101a361 | 2013-05-14 22:33:24 +0000 | [diff] [blame] | 5350 | |
| 5351 | // We need to create a zextload/sextload. We cannot just create a load |
| 5352 | // followed by a zext/zext node because LowerMUL is also run during normal |
| 5353 | // operation legalization where we can't create illegal types. |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 5354 | return DAG.getExtLoad(LD->getExtensionType(), SDLoc(LD), ExtendedTy, |
Arnold Schwaighofer | 101a361 | 2013-05-14 22:33:24 +0000 | [diff] [blame] | 5355 | LD->getChain(), LD->getBasePtr(), LD->getPointerInfo(), |
| 5356 | LD->getMemoryVT(), LD->isVolatile(), |
| 5357 | LD->isNonTemporal(), LD->getAlignment()); |
Sebastian Pop | cb49530 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5358 | } |
| 5359 | |
| 5360 | /// SkipExtensionForVMULL - For a node that is a SIGN_EXTEND, ZERO_EXTEND, |
| 5361 | /// extending load, or BUILD_VECTOR with extended elements, return the |
| 5362 | /// unextended value. The unextended vector should be 64 bits so that it can |
| 5363 | /// be used as an operand to a VMULL instruction. If the original vector size |
| 5364 | /// before extension is less than 64 bits we add a an extension to resize |
| 5365 | /// the vector to 64 bits. |
| 5366 | static SDValue SkipExtensionForVMULL(SDNode *N, SelectionDAG &DAG) { |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5367 | if (N->getOpcode() == ISD::SIGN_EXTEND || N->getOpcode() == ISD::ZERO_EXTEND) |
Sebastian Pop | cb49530 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5368 | return AddRequiredExtensionForVMULL(N->getOperand(0), DAG, |
| 5369 | N->getOperand(0)->getValueType(0), |
| 5370 | N->getValueType(0), |
| 5371 | N->getOpcode()); |
| 5372 | |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 5373 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) |
Sebastian Pop | cb49530 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5374 | return SkipLoadExtensionForVMULL(LD, DAG); |
| 5375 | |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 5376 | // Otherwise, the value must be a BUILD_VECTOR. For v2i64, it will |
| 5377 | // have been legalized as a BITCAST from v4i32. |
| 5378 | if (N->getOpcode() == ISD::BITCAST) { |
| 5379 | SDNode *BVN = N->getOperand(0).getNode(); |
| 5380 | assert(BVN->getOpcode() == ISD::BUILD_VECTOR && |
| 5381 | BVN->getValueType(0) == MVT::v4i32 && "expected v4i32 BUILD_VECTOR"); |
| 5382 | unsigned LowElt = DAG.getTargetLoweringInfo().isBigEndian() ? 1 : 0; |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 5383 | return DAG.getNode(ISD::BUILD_VECTOR, SDLoc(N), MVT::v2i32, |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 5384 | BVN->getOperand(LowElt), BVN->getOperand(LowElt+2)); |
| 5385 | } |
| 5386 | // Construct a new BUILD_VECTOR with elements truncated to half the size. |
| 5387 | assert(N->getOpcode() == ISD::BUILD_VECTOR && "expected BUILD_VECTOR"); |
| 5388 | EVT VT = N->getValueType(0); |
| 5389 | unsigned EltSize = VT.getVectorElementType().getSizeInBits() / 2; |
| 5390 | unsigned NumElts = VT.getVectorNumElements(); |
| 5391 | MVT TruncVT = MVT::getIntegerVT(EltSize); |
| 5392 | SmallVector<SDValue, 8> Ops; |
| 5393 | for (unsigned i = 0; i != NumElts; ++i) { |
| 5394 | ConstantSDNode *C = cast<ConstantSDNode>(N->getOperand(i)); |
| 5395 | const APInt &CInt = C->getAPIntValue(); |
Bob Wilson | ff73d8f | 2012-04-30 16:53:34 +0000 | [diff] [blame] | 5396 | // Element types smaller than 32 bits are not legal, so use i32 elements. |
| 5397 | // The values are implicitly truncated so sext vs. zext doesn't matter. |
| 5398 | Ops.push_back(DAG.getConstant(CInt.zextOrTrunc(32), MVT::i32)); |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 5399 | } |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 5400 | return DAG.getNode(ISD::BUILD_VECTOR, SDLoc(N), |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 5401 | MVT::getVectorVT(TruncVT, NumElts), Ops.data(), NumElts); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5402 | } |
| 5403 | |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5404 | static bool isAddSubSExt(SDNode *N, SelectionDAG &DAG) { |
| 5405 | unsigned Opcode = N->getOpcode(); |
| 5406 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { |
| 5407 | SDNode *N0 = N->getOperand(0).getNode(); |
| 5408 | SDNode *N1 = N->getOperand(1).getNode(); |
| 5409 | return N0->hasOneUse() && N1->hasOneUse() && |
| 5410 | isSignExtended(N0, DAG) && isSignExtended(N1, DAG); |
| 5411 | } |
| 5412 | return false; |
| 5413 | } |
| 5414 | |
| 5415 | static bool isAddSubZExt(SDNode *N, SelectionDAG &DAG) { |
| 5416 | unsigned Opcode = N->getOpcode(); |
| 5417 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { |
| 5418 | SDNode *N0 = N->getOperand(0).getNode(); |
| 5419 | SDNode *N1 = N->getOperand(1).getNode(); |
| 5420 | return N0->hasOneUse() && N1->hasOneUse() && |
| 5421 | isZeroExtended(N0, DAG) && isZeroExtended(N1, DAG); |
| 5422 | } |
| 5423 | return false; |
| 5424 | } |
| 5425 | |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5426 | static SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) { |
| 5427 | // Multiplications are only custom-lowered for 128-bit vectors so that |
| 5428 | // VMULL can be detected. Otherwise v2i64 multiplications are not legal. |
| 5429 | EVT VT = Op.getValueType(); |
Sebastian Pop | cb49530 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5430 | assert(VT.is128BitVector() && VT.isInteger() && |
| 5431 | "unexpected type for custom-lowering ISD::MUL"); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5432 | SDNode *N0 = Op.getOperand(0).getNode(); |
| 5433 | SDNode *N1 = Op.getOperand(1).getNode(); |
| 5434 | unsigned NewOpc = 0; |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5435 | bool isMLA = false; |
| 5436 | bool isN0SExt = isSignExtended(N0, DAG); |
| 5437 | bool isN1SExt = isSignExtended(N1, DAG); |
| 5438 | if (isN0SExt && isN1SExt) |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5439 | NewOpc = ARMISD::VMULLs; |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5440 | else { |
| 5441 | bool isN0ZExt = isZeroExtended(N0, DAG); |
| 5442 | bool isN1ZExt = isZeroExtended(N1, DAG); |
| 5443 | if (isN0ZExt && isN1ZExt) |
| 5444 | NewOpc = ARMISD::VMULLu; |
| 5445 | else if (isN1SExt || isN1ZExt) { |
| 5446 | // Look for (s/zext A + s/zext B) * (s/zext C). We want to turn these |
| 5447 | // into (s/zext A * s/zext C) + (s/zext B * s/zext C) |
| 5448 | if (isN1SExt && isAddSubSExt(N0, DAG)) { |
| 5449 | NewOpc = ARMISD::VMULLs; |
| 5450 | isMLA = true; |
| 5451 | } else if (isN1ZExt && isAddSubZExt(N0, DAG)) { |
| 5452 | NewOpc = ARMISD::VMULLu; |
| 5453 | isMLA = true; |
| 5454 | } else if (isN0ZExt && isAddSubZExt(N1, DAG)) { |
| 5455 | std::swap(N0, N1); |
| 5456 | NewOpc = ARMISD::VMULLu; |
| 5457 | isMLA = true; |
| 5458 | } |
| 5459 | } |
| 5460 | |
| 5461 | if (!NewOpc) { |
| 5462 | if (VT == MVT::v2i64) |
| 5463 | // Fall through to expand this. It is not legal. |
| 5464 | return SDValue(); |
| 5465 | else |
| 5466 | // Other vector multiplications are legal. |
| 5467 | return Op; |
| 5468 | } |
| 5469 | } |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5470 | |
| 5471 | // Legalize to a VMULL instruction. |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 5472 | SDLoc DL(Op); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5473 | SDValue Op0; |
Sebastian Pop | cb49530 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5474 | SDValue Op1 = SkipExtensionForVMULL(N1, DAG); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5475 | if (!isMLA) { |
Sebastian Pop | cb49530 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5476 | Op0 = SkipExtensionForVMULL(N0, DAG); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5477 | assert(Op0.getValueType().is64BitVector() && |
| 5478 | Op1.getValueType().is64BitVector() && |
| 5479 | "unexpected types for extended operands to VMULL"); |
| 5480 | return DAG.getNode(NewOpc, DL, VT, Op0, Op1); |
| 5481 | } |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5482 | |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5483 | // Optimizing (zext A + zext B) * C, to (VMULL A, C) + (VMULL B, C) during |
| 5484 | // isel lowering to take advantage of no-stall back to back vmul + vmla. |
| 5485 | // vmull q0, d4, d6 |
| 5486 | // vmlal q0, d5, d6 |
| 5487 | // is faster than |
| 5488 | // vaddl q0, d4, d5 |
| 5489 | // vmovl q1, d6 |
| 5490 | // vmul q0, q0, q1 |
Sebastian Pop | cb49530 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5491 | SDValue N00 = SkipExtensionForVMULL(N0->getOperand(0).getNode(), DAG); |
| 5492 | SDValue N01 = SkipExtensionForVMULL(N0->getOperand(1).getNode(), DAG); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5493 | EVT Op1VT = Op1.getValueType(); |
| 5494 | return DAG.getNode(N0->getOpcode(), DL, VT, |
| 5495 | DAG.getNode(NewOpc, DL, VT, |
| 5496 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N00), Op1), |
| 5497 | DAG.getNode(NewOpc, DL, VT, |
| 5498 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N01), Op1)); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5499 | } |
| 5500 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5501 | static SDValue |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 5502 | LowerSDIV_v4i8(SDValue X, SDValue Y, SDLoc dl, SelectionDAG &DAG) { |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5503 | // Convert to float |
| 5504 | // float4 xf = vcvt_f32_s32(vmovl_s16(a.lo)); |
| 5505 | // float4 yf = vcvt_f32_s32(vmovl_s16(b.lo)); |
| 5506 | X = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, X); |
| 5507 | Y = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, Y); |
| 5508 | X = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, X); |
| 5509 | Y = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, Y); |
| 5510 | // Get reciprocal estimate. |
| 5511 | // float4 recip = vrecpeq_f32(yf); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5512 | Y = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5513 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), Y); |
| 5514 | // Because char has a smaller range than uchar, we can actually get away |
| 5515 | // without any newton steps. This requires that we use a weird bias |
| 5516 | // of 0xb000, however (again, this has been exhaustively tested). |
| 5517 | // float4 result = as_float4(as_int4(xf*recip) + 0xb000); |
| 5518 | X = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, X, Y); |
| 5519 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, X); |
| 5520 | Y = DAG.getConstant(0xb000, MVT::i32); |
| 5521 | Y = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, Y, Y, Y, Y); |
| 5522 | X = DAG.getNode(ISD::ADD, dl, MVT::v4i32, X, Y); |
| 5523 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, X); |
| 5524 | // Convert back to short. |
| 5525 | X = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, X); |
| 5526 | X = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, X); |
| 5527 | return X; |
| 5528 | } |
| 5529 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5530 | static SDValue |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 5531 | LowerSDIV_v4i16(SDValue N0, SDValue N1, SDLoc dl, SelectionDAG &DAG) { |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5532 | SDValue N2; |
| 5533 | // Convert to float. |
| 5534 | // float4 yf = vcvt_f32_s32(vmovl_s16(y)); |
| 5535 | // float4 xf = vcvt_f32_s32(vmovl_s16(x)); |
| 5536 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N0); |
| 5537 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N1); |
| 5538 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); |
| 5539 | N1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5540 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5541 | // Use reciprocal estimate and one refinement step. |
| 5542 | // float4 recip = vrecpeq_f32(yf); |
| 5543 | // recip *= vrecpsq_f32(yf, recip); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5544 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5545 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5546 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5547 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
| 5548 | N1, N2); |
| 5549 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 5550 | // Because short has a smaller range than ushort, we can actually get away |
| 5551 | // with only a single newton step. This requires that we use a weird bias |
| 5552 | // of 89, however (again, this has been exhaustively tested). |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5553 | // float4 result = as_float4(as_int4(xf*recip) + 0x89); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5554 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
| 5555 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5556 | N1 = DAG.getConstant(0x89, MVT::i32); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5557 | N1 = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, N1, N1, N1, N1); |
| 5558 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); |
| 5559 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); |
| 5560 | // Convert back to integer and return. |
| 5561 | // return vmovn_s32(vcvt_s32_f32(result)); |
| 5562 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); |
| 5563 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); |
| 5564 | return N0; |
| 5565 | } |
| 5566 | |
| 5567 | static SDValue LowerSDIV(SDValue Op, SelectionDAG &DAG) { |
| 5568 | EVT VT = Op.getValueType(); |
| 5569 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && |
| 5570 | "unexpected type for custom-lowering ISD::SDIV"); |
| 5571 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 5572 | SDLoc dl(Op); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5573 | SDValue N0 = Op.getOperand(0); |
| 5574 | SDValue N1 = Op.getOperand(1); |
| 5575 | SDValue N2, N3; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5576 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5577 | if (VT == MVT::v8i8) { |
| 5578 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N0); |
| 5579 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5580 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5581 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 5582 | DAG.getIntPtrConstant(4)); |
| 5583 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5584 | DAG.getIntPtrConstant(4)); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5585 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 5586 | DAG.getIntPtrConstant(0)); |
| 5587 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| 5588 | DAG.getIntPtrConstant(0)); |
| 5589 | |
| 5590 | N0 = LowerSDIV_v4i8(N0, N1, dl, DAG); // v4i16 |
| 5591 | N2 = LowerSDIV_v4i8(N2, N3, dl, DAG); // v4i16 |
| 5592 | |
| 5593 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
| 5594 | N0 = LowerCONCAT_VECTORS(N0, DAG); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5595 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5596 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v8i8, N0); |
| 5597 | return N0; |
| 5598 | } |
| 5599 | return LowerSDIV_v4i16(N0, N1, dl, DAG); |
| 5600 | } |
| 5601 | |
| 5602 | static SDValue LowerUDIV(SDValue Op, SelectionDAG &DAG) { |
| 5603 | EVT VT = Op.getValueType(); |
| 5604 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && |
| 5605 | "unexpected type for custom-lowering ISD::UDIV"); |
| 5606 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 5607 | SDLoc dl(Op); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5608 | SDValue N0 = Op.getOperand(0); |
| 5609 | SDValue N1 = Op.getOperand(1); |
| 5610 | SDValue N2, N3; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5611 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5612 | if (VT == MVT::v8i8) { |
| 5613 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N0); |
| 5614 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5615 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5616 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 5617 | DAG.getIntPtrConstant(4)); |
| 5618 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5619 | DAG.getIntPtrConstant(4)); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5620 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 5621 | DAG.getIntPtrConstant(0)); |
| 5622 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| 5623 | DAG.getIntPtrConstant(0)); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5624 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5625 | N0 = LowerSDIV_v4i16(N0, N1, dl, DAG); // v4i16 |
| 5626 | N2 = LowerSDIV_v4i16(N2, N3, dl, DAG); // v4i16 |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5627 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5628 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
| 5629 | N0 = LowerCONCAT_VECTORS(N0, DAG); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5630 | |
| 5631 | N0 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v8i8, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5632 | DAG.getConstant(Intrinsic::arm_neon_vqmovnsu, MVT::i32), |
| 5633 | N0); |
| 5634 | return N0; |
| 5635 | } |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5636 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5637 | // v4i16 sdiv ... Convert to float. |
| 5638 | // float4 yf = vcvt_f32_s32(vmovl_u16(y)); |
| 5639 | // float4 xf = vcvt_f32_s32(vmovl_u16(x)); |
| 5640 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N0); |
| 5641 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N1); |
| 5642 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5643 | SDValue BN1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5644 | |
| 5645 | // Use reciprocal estimate and two refinement steps. |
| 5646 | // float4 recip = vrecpeq_f32(yf); |
| 5647 | // recip *= vrecpsq_f32(yf, recip); |
| 5648 | // recip *= vrecpsq_f32(yf, recip); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5649 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5650 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), BN1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5651 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5652 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5653 | BN1, N2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5654 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5655 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5656 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5657 | BN1, N2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5658 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 5659 | // Simply multiplying by the reciprocal estimate can leave us a few ulps |
| 5660 | // too low, so we add 2 ulps (exhaustive testing shows that this is enough, |
| 5661 | // and that it will never cause us to return an answer too large). |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5662 | // float4 result = as_float4(as_int4(xf*recip) + 2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5663 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
| 5664 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); |
| 5665 | N1 = DAG.getConstant(2, MVT::i32); |
| 5666 | N1 = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, N1, N1, N1, N1); |
| 5667 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); |
| 5668 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); |
| 5669 | // Convert back to integer and return. |
| 5670 | // return vmovn_u32(vcvt_s32_f32(result)); |
| 5671 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); |
| 5672 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); |
| 5673 | return N0; |
| 5674 | } |
| 5675 | |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 5676 | static SDValue LowerADDC_ADDE_SUBC_SUBE(SDValue Op, SelectionDAG &DAG) { |
| 5677 | EVT VT = Op.getNode()->getValueType(0); |
| 5678 | SDVTList VTs = DAG.getVTList(VT, MVT::i32); |
| 5679 | |
| 5680 | unsigned Opc; |
| 5681 | bool ExtraOp = false; |
| 5682 | switch (Op.getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 5683 | default: llvm_unreachable("Invalid code"); |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 5684 | case ISD::ADDC: Opc = ARMISD::ADDC; break; |
| 5685 | case ISD::ADDE: Opc = ARMISD::ADDE; ExtraOp = true; break; |
| 5686 | case ISD::SUBC: Opc = ARMISD::SUBC; break; |
| 5687 | case ISD::SUBE: Opc = ARMISD::SUBE; ExtraOp = true; break; |
| 5688 | } |
| 5689 | |
| 5690 | if (!ExtraOp) |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 5691 | return DAG.getNode(Opc, SDLoc(Op), VTs, Op.getOperand(0), |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 5692 | Op.getOperand(1)); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 5693 | return DAG.getNode(Opc, SDLoc(Op), VTs, Op.getOperand(0), |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 5694 | Op.getOperand(1), Op.getOperand(2)); |
| 5695 | } |
| 5696 | |
Eli Friedman | 74bf18c | 2011-09-15 22:26:18 +0000 | [diff] [blame] | 5697 | static SDValue LowerAtomicLoadStore(SDValue Op, SelectionDAG &DAG) { |
Eli Friedman | 7cc1566 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 5698 | // Monotonic load/store is legal for all targets |
| 5699 | if (cast<AtomicSDNode>(Op)->getOrdering() <= Monotonic) |
| 5700 | return Op; |
| 5701 | |
| 5702 | // Aquire/Release load/store is not legal for targets without a |
| 5703 | // dmb or equivalent available. |
| 5704 | return SDValue(); |
| 5705 | } |
| 5706 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5707 | static void |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5708 | ReplaceATOMIC_OP_64(SDNode *Node, SmallVectorImpl<SDValue>& Results, |
| 5709 | SelectionDAG &DAG, unsigned NewOp) { |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 5710 | SDLoc dl(Node); |
Duncan Sands | 17001ce | 2011-10-18 12:44:00 +0000 | [diff] [blame] | 5711 | assert (Node->getValueType(0) == MVT::i64 && |
| 5712 | "Only know how to expand i64 atomics"); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5713 | |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5714 | SmallVector<SDValue, 6> Ops; |
| 5715 | Ops.push_back(Node->getOperand(0)); // Chain |
| 5716 | Ops.push_back(Node->getOperand(1)); // Ptr |
| 5717 | // Low part of Val1 |
| 5718 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5719 | Node->getOperand(2), DAG.getIntPtrConstant(0))); |
| 5720 | // High part of Val1 |
| 5721 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5722 | Node->getOperand(2), DAG.getIntPtrConstant(1))); |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 5723 | if (NewOp == ARMISD::ATOMCMPXCHG64_DAG) { |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5724 | // High part of Val1 |
| 5725 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5726 | Node->getOperand(3), DAG.getIntPtrConstant(0))); |
| 5727 | // High part of Val2 |
| 5728 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5729 | Node->getOperand(3), DAG.getIntPtrConstant(1))); |
| 5730 | } |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5731 | SDVTList Tys = DAG.getVTList(MVT::i32, MVT::i32, MVT::Other); |
| 5732 | SDValue Result = |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5733 | DAG.getMemIntrinsicNode(NewOp, dl, Tys, Ops.data(), Ops.size(), MVT::i64, |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5734 | cast<MemSDNode>(Node)->getMemOperand()); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5735 | SDValue OpsF[] = { Result.getValue(0), Result.getValue(1) }; |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5736 | Results.push_back(DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, OpsF, 2)); |
| 5737 | Results.push_back(Result.getValue(2)); |
| 5738 | } |
| 5739 | |
Tim Northover | 5a02fc4 | 2013-05-23 19:11:20 +0000 | [diff] [blame] | 5740 | static void ReplaceREADCYCLECOUNTER(SDNode *N, |
| 5741 | SmallVectorImpl<SDValue> &Results, |
| 5742 | SelectionDAG &DAG, |
| 5743 | const ARMSubtarget *Subtarget) { |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 5744 | SDLoc DL(N); |
Tim Northover | 5a02fc4 | 2013-05-23 19:11:20 +0000 | [diff] [blame] | 5745 | SDValue Cycles32, OutChain; |
| 5746 | |
| 5747 | if (Subtarget->hasPerfMon()) { |
| 5748 | // Under Power Management extensions, the cycle-count is: |
| 5749 | // mrc p15, #0, <Rt>, c9, c13, #0 |
| 5750 | SDValue Ops[] = { N->getOperand(0), // Chain |
| 5751 | DAG.getConstant(Intrinsic::arm_mrc, MVT::i32), |
| 5752 | DAG.getConstant(15, MVT::i32), |
| 5753 | DAG.getConstant(0, MVT::i32), |
| 5754 | DAG.getConstant(9, MVT::i32), |
| 5755 | DAG.getConstant(13, MVT::i32), |
| 5756 | DAG.getConstant(0, MVT::i32) |
| 5757 | }; |
| 5758 | |
| 5759 | Cycles32 = DAG.getNode(ISD::INTRINSIC_W_CHAIN, DL, |
| 5760 | DAG.getVTList(MVT::i32, MVT::Other), &Ops[0], |
| 5761 | array_lengthof(Ops)); |
| 5762 | OutChain = Cycles32.getValue(1); |
| 5763 | } else { |
| 5764 | // Intrinsic is defined to return 0 on unsupported platforms. Technically |
| 5765 | // there are older ARM CPUs that have implementation-specific ways of |
| 5766 | // obtaining this information (FIXME!). |
| 5767 | Cycles32 = DAG.getConstant(0, MVT::i32); |
| 5768 | OutChain = DAG.getEntryNode(); |
| 5769 | } |
| 5770 | |
| 5771 | |
| 5772 | SDValue Cycles64 = DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64, |
| 5773 | Cycles32, DAG.getConstant(0, MVT::i32)); |
| 5774 | Results.push_back(Cycles64); |
| 5775 | Results.push_back(OutChain); |
| 5776 | } |
| 5777 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 5778 | SDValue ARMTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5779 | switch (Op.getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 5780 | default: llvm_unreachable("Don't know how to custom lower this!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5781 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 5782 | case ISD::BlockAddress: return LowerBlockAddress(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 5783 | case ISD::GlobalAddress: |
| 5784 | return Subtarget->isTargetDarwin() ? LowerGlobalAddressDarwin(Op, DAG) : |
| 5785 | LowerGlobalAddressELF(Op, DAG); |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 5786 | case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 5787 | case ISD::SELECT: return LowerSELECT(Op, DAG); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 5788 | case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG); |
| 5789 | case ISD::BR_CC: return LowerBR_CC(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5790 | case ISD::BR_JT: return LowerBR_JT(Op, DAG); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 5791 | case ISD::VASTART: return LowerVASTART(Op, DAG); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 5792 | case ISD::ATOMIC_FENCE: return LowerATOMIC_FENCE(Op, DAG, Subtarget); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 5793 | case ISD::PREFETCH: return LowerPREFETCH(Op, DAG, Subtarget); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 5794 | case ISD::SINT_TO_FP: |
| 5795 | case ISD::UINT_TO_FP: return LowerINT_TO_FP(Op, DAG); |
| 5796 | case ISD::FP_TO_SINT: |
| 5797 | case ISD::FP_TO_UINT: return LowerFP_TO_INT(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5798 | case ISD::FCOPYSIGN: return LowerFCOPYSIGN(Op, DAG); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 5799 | case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 5800 | case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 5801 | case ISD::GLOBAL_OFFSET_TABLE: return LowerGLOBAL_OFFSET_TABLE(Op, DAG); |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 5802 | case ISD::EH_SJLJ_SETJMP: return LowerEH_SJLJ_SETJMP(Op, DAG); |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 5803 | case ISD::EH_SJLJ_LONGJMP: return LowerEH_SJLJ_LONGJMP(Op, DAG); |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 5804 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG, |
| 5805 | Subtarget); |
Evan Cheng | 21a6179 | 2011-03-14 18:02:30 +0000 | [diff] [blame] | 5806 | case ISD::BITCAST: return ExpandBITCAST(Op.getNode(), DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5807 | case ISD::SHL: |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5808 | case ISD::SRL: |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5809 | case ISD::SRA: return LowerShift(Op.getNode(), DAG, Subtarget); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 5810 | case ISD::SHL_PARTS: return LowerShiftLeftParts(Op, DAG); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 5811 | case ISD::SRL_PARTS: |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 5812 | case ISD::SRA_PARTS: return LowerShiftRightParts(Op, DAG); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 5813 | case ISD::CTTZ: return LowerCTTZ(Op.getNode(), DAG, Subtarget); |
Evan Cheng | c8e7045 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 5814 | case ISD::CTPOP: return LowerCTPOP(Op.getNode(), DAG, Subtarget); |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 5815 | case ISD::SETCC: return LowerVSETCC(Op, DAG); |
Lang Hames | 45b5f88 | 2012-03-15 18:49:02 +0000 | [diff] [blame] | 5816 | case ISD::ConstantFP: return LowerConstantFP(Op, DAG, Subtarget); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 5817 | case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5818 | case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG); |
Eli Friedman | 5c89cb8 | 2011-10-24 23:08:52 +0000 | [diff] [blame] | 5819 | case ISD::INSERT_VECTOR_ELT: return LowerINSERT_VECTOR_ELT(Op, DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5820 | case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 5821 | case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG); |
Bob Wilson | b31a11b | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 5822 | case ISD::FLT_ROUNDS_: return LowerFLT_ROUNDS_(Op, DAG); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5823 | case ISD::MUL: return LowerMUL(Op, DAG); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5824 | case ISD::SDIV: return LowerSDIV(Op, DAG); |
| 5825 | case ISD::UDIV: return LowerUDIV(Op, DAG); |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 5826 | case ISD::ADDC: |
| 5827 | case ISD::ADDE: |
| 5828 | case ISD::SUBC: |
| 5829 | case ISD::SUBE: return LowerADDC_ADDE_SUBC_SUBE(Op, DAG); |
Eli Friedman | 7cc1566 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 5830 | case ISD::ATOMIC_LOAD: |
Eli Friedman | 74bf18c | 2011-09-15 22:26:18 +0000 | [diff] [blame] | 5831 | case ISD::ATOMIC_STORE: return LowerAtomicLoadStore(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5832 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5833 | } |
| 5834 | |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5835 | /// ReplaceNodeResults - Replace the results of node with an illegal result |
| 5836 | /// type with new values built out of custom code. |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5837 | void ARMTargetLowering::ReplaceNodeResults(SDNode *N, |
| 5838 | SmallVectorImpl<SDValue>&Results, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 5839 | SelectionDAG &DAG) const { |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5840 | SDValue Res; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5841 | switch (N->getOpcode()) { |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5842 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 5843 | llvm_unreachable("Don't know how to custom expand this!"); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5844 | case ISD::BITCAST: |
| 5845 | Res = ExpandBITCAST(N, DAG); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5846 | break; |
Renato Golin | 5ad5f59 | 2013-03-19 08:15:38 +0000 | [diff] [blame] | 5847 | case ISD::SIGN_EXTEND: |
| 5848 | case ISD::ZERO_EXTEND: |
| 5849 | Res = ExpandVectorExtension(N, DAG); |
| 5850 | break; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5851 | case ISD::SRL: |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5852 | case ISD::SRA: |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 5853 | Res = Expand64BitShift(N, DAG, Subtarget); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5854 | break; |
Tim Northover | 5a02fc4 | 2013-05-23 19:11:20 +0000 | [diff] [blame] | 5855 | case ISD::READCYCLECOUNTER: |
| 5856 | ReplaceREADCYCLECOUNTER(N, Results, DAG, Subtarget); |
| 5857 | return; |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5858 | case ISD::ATOMIC_LOAD_ADD: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5859 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMADD64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5860 | return; |
| 5861 | case ISD::ATOMIC_LOAD_AND: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5862 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMAND64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5863 | return; |
| 5864 | case ISD::ATOMIC_LOAD_NAND: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5865 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMNAND64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5866 | return; |
| 5867 | case ISD::ATOMIC_LOAD_OR: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5868 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMOR64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5869 | return; |
| 5870 | case ISD::ATOMIC_LOAD_SUB: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5871 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMSUB64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5872 | return; |
| 5873 | case ISD::ATOMIC_LOAD_XOR: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5874 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMXOR64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5875 | return; |
| 5876 | case ISD::ATOMIC_SWAP: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5877 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMSWAP64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5878 | return; |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5879 | case ISD::ATOMIC_CMP_SWAP: |
| 5880 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMCMPXCHG64_DAG); |
| 5881 | return; |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 5882 | case ISD::ATOMIC_LOAD_MIN: |
| 5883 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMMIN64_DAG); |
| 5884 | return; |
| 5885 | case ISD::ATOMIC_LOAD_UMIN: |
| 5886 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMUMIN64_DAG); |
| 5887 | return; |
| 5888 | case ISD::ATOMIC_LOAD_MAX: |
| 5889 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMMAX64_DAG); |
| 5890 | return; |
| 5891 | case ISD::ATOMIC_LOAD_UMAX: |
| 5892 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMUMAX64_DAG); |
| 5893 | return; |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5894 | } |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5895 | if (Res.getNode()) |
| 5896 | Results.push_back(Res); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5897 | } |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5898 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5899 | //===----------------------------------------------------------------------===// |
| 5900 | // ARM Scheduler Hooks |
| 5901 | //===----------------------------------------------------------------------===// |
| 5902 | |
| 5903 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5904 | ARMTargetLowering::EmitAtomicCmpSwap(MachineInstr *MI, |
| 5905 | MachineBasicBlock *BB, |
| 5906 | unsigned Size) const { |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5907 | unsigned dest = MI->getOperand(0).getReg(); |
| 5908 | unsigned ptr = MI->getOperand(1).getReg(); |
| 5909 | unsigned oldval = MI->getOperand(2).getReg(); |
| 5910 | unsigned newval = MI->getOperand(3).getReg(); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5911 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5912 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5913 | bool isThumb2 = Subtarget->isThumb2(); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5914 | |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 5915 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5916 | unsigned scratch = MRI.createVirtualRegister(isThumb2 ? |
| 5917 | (const TargetRegisterClass*)&ARM::rGPRRegClass : |
| 5918 | (const TargetRegisterClass*)&ARM::GPRRegClass); |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 5919 | |
| 5920 | if (isThumb2) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5921 | MRI.constrainRegClass(dest, &ARM::rGPRRegClass); |
| 5922 | MRI.constrainRegClass(oldval, &ARM::rGPRRegClass); |
| 5923 | MRI.constrainRegClass(newval, &ARM::rGPRRegClass); |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 5924 | } |
| 5925 | |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5926 | unsigned ldrOpc, strOpc; |
| 5927 | switch (Size) { |
| 5928 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5929 | case 1: |
| 5930 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
Evan Cheng | aa26102 | 2011-02-07 18:50:47 +0000 | [diff] [blame] | 5931 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5932 | break; |
| 5933 | case 2: |
| 5934 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 5935 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 5936 | break; |
| 5937 | case 4: |
| 5938 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 5939 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 5940 | break; |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5941 | } |
| 5942 | |
| 5943 | MachineFunction *MF = BB->getParent(); |
| 5944 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 5945 | MachineFunction::iterator It = BB; |
| 5946 | ++It; // insert the new blocks after the current block |
| 5947 | |
| 5948 | MachineBasicBlock *loop1MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5949 | MachineBasicBlock *loop2MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5950 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5951 | MF->insert(It, loop1MBB); |
| 5952 | MF->insert(It, loop2MBB); |
| 5953 | MF->insert(It, exitMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5954 | |
| 5955 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5956 | exitMBB->splice(exitMBB->begin(), BB, |
| 5957 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5958 | BB->end()); |
| 5959 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5960 | |
| 5961 | // thisMBB: |
| 5962 | // ... |
| 5963 | // fallthrough --> loop1MBB |
| 5964 | BB->addSuccessor(loop1MBB); |
| 5965 | |
| 5966 | // loop1MBB: |
| 5967 | // ldrex dest, [ptr] |
| 5968 | // cmp dest, oldval |
| 5969 | // bne exitMBB |
| 5970 | BB = loop1MBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5971 | MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr); |
| 5972 | if (ldrOpc == ARM::t2LDREX) |
| 5973 | MIB.addImm(0); |
| 5974 | AddDefaultPred(MIB); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5975 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5976 | .addReg(dest).addReg(oldval)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5977 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5978 | .addMBB(exitMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5979 | BB->addSuccessor(loop2MBB); |
| 5980 | BB->addSuccessor(exitMBB); |
| 5981 | |
| 5982 | // loop2MBB: |
| 5983 | // strex scratch, newval, [ptr] |
| 5984 | // cmp scratch, #0 |
| 5985 | // bne loop1MBB |
| 5986 | BB = loop2MBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5987 | MIB = BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(newval).addReg(ptr); |
| 5988 | if (strOpc == ARM::t2STREX) |
| 5989 | MIB.addImm(0); |
| 5990 | AddDefaultPred(MIB); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5991 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5992 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5993 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5994 | .addMBB(loop1MBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5995 | BB->addSuccessor(loop1MBB); |
| 5996 | BB->addSuccessor(exitMBB); |
| 5997 | |
| 5998 | // exitMBB: |
| 5999 | // ... |
| 6000 | BB = exitMBB; |
Jim Grosbach | 5efaed3 | 2010-01-15 00:18:34 +0000 | [diff] [blame] | 6001 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 6002 | MI->eraseFromParent(); // The instruction is gone now. |
Jim Grosbach | 5efaed3 | 2010-01-15 00:18:34 +0000 | [diff] [blame] | 6003 | |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6004 | return BB; |
| 6005 | } |
| 6006 | |
| 6007 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6008 | ARMTargetLowering::EmitAtomicBinary(MachineInstr *MI, MachineBasicBlock *BB, |
| 6009 | unsigned Size, unsigned BinOpcode) const { |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 6010 | // This also handles ATOMIC_SWAP, indicated by BinOpcode==0. |
| 6011 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 6012 | |
| 6013 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 6014 | MachineFunction *MF = BB->getParent(); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 6015 | MachineFunction::iterator It = BB; |
| 6016 | ++It; |
| 6017 | |
| 6018 | unsigned dest = MI->getOperand(0).getReg(); |
| 6019 | unsigned ptr = MI->getOperand(1).getReg(); |
| 6020 | unsigned incr = MI->getOperand(2).getReg(); |
| 6021 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6022 | bool isThumb2 = Subtarget->isThumb2(); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 6023 | |
| 6024 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 6025 | if (isThumb2) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6026 | MRI.constrainRegClass(dest, &ARM::rGPRRegClass); |
| 6027 | MRI.constrainRegClass(ptr, &ARM::rGPRRegClass); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 6028 | } |
| 6029 | |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 6030 | unsigned ldrOpc, strOpc; |
| 6031 | switch (Size) { |
| 6032 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6033 | case 1: |
| 6034 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
Jakob Stoklund Olesen | 15913c9 | 2010-01-13 19:54:39 +0000 | [diff] [blame] | 6035 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6036 | break; |
| 6037 | case 2: |
| 6038 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 6039 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 6040 | break; |
| 6041 | case 4: |
| 6042 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 6043 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 6044 | break; |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 6045 | } |
| 6046 | |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 6047 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 6048 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 6049 | MF->insert(It, loopMBB); |
| 6050 | MF->insert(It, exitMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 6051 | |
| 6052 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 6053 | exitMBB->splice(exitMBB->begin(), BB, |
| 6054 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 6055 | BB->end()); |
| 6056 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 6057 | |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6058 | const TargetRegisterClass *TRC = isThumb2 ? |
Jakob Stoklund Olesen | 05e80f2 | 2012-08-31 02:08:34 +0000 | [diff] [blame] | 6059 | (const TargetRegisterClass*)&ARM::rGPRRegClass : |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6060 | (const TargetRegisterClass*)&ARM::GPRRegClass; |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 6061 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| 6062 | unsigned scratch2 = (!BinOpcode) ? incr : MRI.createVirtualRegister(TRC); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 6063 | |
| 6064 | // thisMBB: |
| 6065 | // ... |
| 6066 | // fallthrough --> loopMBB |
| 6067 | BB->addSuccessor(loopMBB); |
| 6068 | |
| 6069 | // loopMBB: |
| 6070 | // ldrex dest, ptr |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6071 | // <binop> scratch2, dest, incr |
| 6072 | // strex scratch, scratch2, ptr |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 6073 | // cmp scratch, #0 |
| 6074 | // bne- loopMBB |
| 6075 | // fallthrough --> exitMBB |
| 6076 | BB = loopMBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 6077 | MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr); |
| 6078 | if (ldrOpc == ARM::t2LDREX) |
| 6079 | MIB.addImm(0); |
| 6080 | AddDefaultPred(MIB); |
Jim Grosbach | c67b556 | 2009-12-15 00:12:35 +0000 | [diff] [blame] | 6081 | if (BinOpcode) { |
| 6082 | // operand order needs to go the other way for NAND |
| 6083 | if (BinOpcode == ARM::BICrr || BinOpcode == ARM::t2BICrr) |
| 6084 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 6085 | addReg(incr).addReg(dest)).addReg(0); |
| 6086 | else |
| 6087 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 6088 | addReg(dest).addReg(incr)).addReg(0); |
| 6089 | } |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 6090 | |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 6091 | MIB = BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(scratch2).addReg(ptr); |
| 6092 | if (strOpc == ARM::t2STREX) |
| 6093 | MIB.addImm(0); |
| 6094 | AddDefaultPred(MIB); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6095 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 6096 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6097 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 6098 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 6099 | |
| 6100 | BB->addSuccessor(loopMBB); |
| 6101 | BB->addSuccessor(exitMBB); |
| 6102 | |
| 6103 | // exitMBB: |
| 6104 | // ... |
| 6105 | BB = exitMBB; |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 6106 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 6107 | MI->eraseFromParent(); // The instruction is gone now. |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 6108 | |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 6109 | return BB; |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6110 | } |
| 6111 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 6112 | MachineBasicBlock * |
| 6113 | ARMTargetLowering::EmitAtomicBinaryMinMax(MachineInstr *MI, |
| 6114 | MachineBasicBlock *BB, |
| 6115 | unsigned Size, |
| 6116 | bool signExtend, |
| 6117 | ARMCC::CondCodes Cond) const { |
| 6118 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 6119 | |
| 6120 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 6121 | MachineFunction *MF = BB->getParent(); |
| 6122 | MachineFunction::iterator It = BB; |
| 6123 | ++It; |
| 6124 | |
| 6125 | unsigned dest = MI->getOperand(0).getReg(); |
| 6126 | unsigned ptr = MI->getOperand(1).getReg(); |
| 6127 | unsigned incr = MI->getOperand(2).getReg(); |
| 6128 | unsigned oldval = dest; |
| 6129 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 6130 | bool isThumb2 = Subtarget->isThumb2(); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 6131 | |
| 6132 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 6133 | if (isThumb2) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6134 | MRI.constrainRegClass(dest, &ARM::rGPRRegClass); |
| 6135 | MRI.constrainRegClass(ptr, &ARM::rGPRRegClass); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 6136 | } |
| 6137 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 6138 | unsigned ldrOpc, strOpc, extendOpc; |
| 6139 | switch (Size) { |
| 6140 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
| 6141 | case 1: |
| 6142 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
| 6143 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 6144 | extendOpc = isThumb2 ? ARM::t2SXTB : ARM::SXTB; |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 6145 | break; |
| 6146 | case 2: |
| 6147 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 6148 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 6149 | extendOpc = isThumb2 ? ARM::t2SXTH : ARM::SXTH; |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 6150 | break; |
| 6151 | case 4: |
| 6152 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 6153 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 6154 | extendOpc = 0; |
| 6155 | break; |
| 6156 | } |
| 6157 | |
| 6158 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 6159 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 6160 | MF->insert(It, loopMBB); |
| 6161 | MF->insert(It, exitMBB); |
| 6162 | |
| 6163 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 6164 | exitMBB->splice(exitMBB->begin(), BB, |
| 6165 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 6166 | BB->end()); |
| 6167 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 6168 | |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6169 | const TargetRegisterClass *TRC = isThumb2 ? |
Jakob Stoklund Olesen | 05e80f2 | 2012-08-31 02:08:34 +0000 | [diff] [blame] | 6170 | (const TargetRegisterClass*)&ARM::rGPRRegClass : |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6171 | (const TargetRegisterClass*)&ARM::GPRRegClass; |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 6172 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| 6173 | unsigned scratch2 = MRI.createVirtualRegister(TRC); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 6174 | |
| 6175 | // thisMBB: |
| 6176 | // ... |
| 6177 | // fallthrough --> loopMBB |
| 6178 | BB->addSuccessor(loopMBB); |
| 6179 | |
| 6180 | // loopMBB: |
| 6181 | // ldrex dest, ptr |
| 6182 | // (sign extend dest, if required) |
| 6183 | // cmp dest, incr |
James Molloy | d6d10ae | 2012-09-26 09:48:32 +0000 | [diff] [blame] | 6184 | // cmov.cond scratch2, incr, dest |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 6185 | // strex scratch, scratch2, ptr |
| 6186 | // cmp scratch, #0 |
| 6187 | // bne- loopMBB |
| 6188 | // fallthrough --> exitMBB |
| 6189 | BB = loopMBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 6190 | MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr); |
| 6191 | if (ldrOpc == ARM::t2LDREX) |
| 6192 | MIB.addImm(0); |
| 6193 | AddDefaultPred(MIB); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 6194 | |
| 6195 | // Sign extend the value, if necessary. |
| 6196 | if (signExtend && extendOpc) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6197 | oldval = MRI.createVirtualRegister(&ARM::GPRRegClass); |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 6198 | AddDefaultPred(BuildMI(BB, dl, TII->get(extendOpc), oldval) |
| 6199 | .addReg(dest) |
| 6200 | .addImm(0)); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 6201 | } |
| 6202 | |
| 6203 | // Build compare and cmov instructions. |
| 6204 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 6205 | .addReg(oldval).addReg(incr)); |
| 6206 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2MOVCCr : ARM::MOVCCr), scratch2) |
James Molloy | d6d10ae | 2012-09-26 09:48:32 +0000 | [diff] [blame] | 6207 | .addReg(incr).addReg(oldval).addImm(Cond).addReg(ARM::CPSR); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 6208 | |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 6209 | MIB = BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(scratch2).addReg(ptr); |
| 6210 | if (strOpc == ARM::t2STREX) |
| 6211 | MIB.addImm(0); |
| 6212 | AddDefaultPred(MIB); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 6213 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 6214 | .addReg(scratch).addImm(0)); |
| 6215 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 6216 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 6217 | |
| 6218 | BB->addSuccessor(loopMBB); |
| 6219 | BB->addSuccessor(exitMBB); |
| 6220 | |
| 6221 | // exitMBB: |
| 6222 | // ... |
| 6223 | BB = exitMBB; |
| 6224 | |
| 6225 | MI->eraseFromParent(); // The instruction is gone now. |
| 6226 | |
| 6227 | return BB; |
| 6228 | } |
| 6229 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6230 | MachineBasicBlock * |
| 6231 | ARMTargetLowering::EmitAtomicBinary64(MachineInstr *MI, MachineBasicBlock *BB, |
| 6232 | unsigned Op1, unsigned Op2, |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 6233 | bool NeedsCarry, bool IsCmpxchg, |
| 6234 | bool IsMinMax, ARMCC::CondCodes CC) const { |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6235 | // This also handles ATOMIC_SWAP, indicated by Op1==0. |
| 6236 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 6237 | |
| 6238 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 6239 | MachineFunction *MF = BB->getParent(); |
| 6240 | MachineFunction::iterator It = BB; |
| 6241 | ++It; |
| 6242 | |
| 6243 | unsigned destlo = MI->getOperand(0).getReg(); |
| 6244 | unsigned desthi = MI->getOperand(1).getReg(); |
| 6245 | unsigned ptr = MI->getOperand(2).getReg(); |
| 6246 | unsigned vallo = MI->getOperand(3).getReg(); |
| 6247 | unsigned valhi = MI->getOperand(4).getReg(); |
| 6248 | DebugLoc dl = MI->getDebugLoc(); |
| 6249 | bool isThumb2 = Subtarget->isThumb2(); |
| 6250 | |
| 6251 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 6252 | if (isThumb2) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6253 | MRI.constrainRegClass(destlo, &ARM::rGPRRegClass); |
| 6254 | MRI.constrainRegClass(desthi, &ARM::rGPRRegClass); |
| 6255 | MRI.constrainRegClass(ptr, &ARM::rGPRRegClass); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6256 | } |
| 6257 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6258 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
Eli Friedman | 7df496d | 2011-09-01 22:27:41 +0000 | [diff] [blame] | 6259 | MachineBasicBlock *contBB = 0, *cont2BB = 0; |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 6260 | if (IsCmpxchg || IsMinMax) |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6261 | contBB = MF->CreateMachineBasicBlock(LLVM_BB); |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 6262 | if (IsCmpxchg) |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6263 | cont2BB = MF->CreateMachineBasicBlock(LLVM_BB); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6264 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 6265 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6266 | MF->insert(It, loopMBB); |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 6267 | if (IsCmpxchg || IsMinMax) MF->insert(It, contBB); |
| 6268 | if (IsCmpxchg) MF->insert(It, cont2BB); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6269 | MF->insert(It, exitMBB); |
| 6270 | |
| 6271 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 6272 | exitMBB->splice(exitMBB->begin(), BB, |
| 6273 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 6274 | BB->end()); |
| 6275 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 6276 | |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6277 | const TargetRegisterClass *TRC = isThumb2 ? |
| 6278 | (const TargetRegisterClass*)&ARM::tGPRRegClass : |
| 6279 | (const TargetRegisterClass*)&ARM::GPRRegClass; |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6280 | unsigned storesuccess = MRI.createVirtualRegister(TRC); |
| 6281 | |
| 6282 | // thisMBB: |
| 6283 | // ... |
| 6284 | // fallthrough --> loopMBB |
| 6285 | BB->addSuccessor(loopMBB); |
| 6286 | |
| 6287 | // loopMBB: |
| 6288 | // ldrexd r2, r3, ptr |
| 6289 | // <binopa> r0, r2, incr |
| 6290 | // <binopb> r1, r3, incr |
| 6291 | // strexd storesuccess, r0, r1, ptr |
| 6292 | // cmp storesuccess, #0 |
| 6293 | // bne- loopMBB |
| 6294 | // fallthrough --> exitMBB |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6295 | BB = loopMBB; |
Tim Northover | 0adfded | 2013-01-29 09:06:13 +0000 | [diff] [blame] | 6296 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6297 | // Load |
Tim Northover | 0adfded | 2013-01-29 09:06:13 +0000 | [diff] [blame] | 6298 | if (isThumb2) { |
| 6299 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::t2LDREXD)) |
| 6300 | .addReg(destlo, RegState::Define) |
| 6301 | .addReg(desthi, RegState::Define) |
| 6302 | .addReg(ptr)); |
| 6303 | } else { |
| 6304 | unsigned GPRPair0 = MRI.createVirtualRegister(&ARM::GPRPairRegClass); |
| 6305 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::LDREXD)) |
| 6306 | .addReg(GPRPair0, RegState::Define).addReg(ptr)); |
| 6307 | // Copy r2/r3 into dest. (This copy will normally be coalesced.) |
| 6308 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), destlo) |
| 6309 | .addReg(GPRPair0, 0, ARM::gsub_0); |
| 6310 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), desthi) |
| 6311 | .addReg(GPRPair0, 0, ARM::gsub_1); |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 6312 | } |
Weiming Zhao | e56764b | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 6313 | |
Tim Northover | 0adfded | 2013-01-29 09:06:13 +0000 | [diff] [blame] | 6314 | unsigned StoreLo, StoreHi; |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6315 | if (IsCmpxchg) { |
| 6316 | // Add early exit |
| 6317 | for (unsigned i = 0; i < 2; i++) { |
| 6318 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : |
| 6319 | ARM::CMPrr)) |
| 6320 | .addReg(i == 0 ? destlo : desthi) |
| 6321 | .addReg(i == 0 ? vallo : valhi)); |
| 6322 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 6323 | .addMBB(exitMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 6324 | BB->addSuccessor(exitMBB); |
| 6325 | BB->addSuccessor(i == 0 ? contBB : cont2BB); |
| 6326 | BB = (i == 0 ? contBB : cont2BB); |
| 6327 | } |
| 6328 | |
| 6329 | // Copy to physregs for strexd |
Tim Northover | 0adfded | 2013-01-29 09:06:13 +0000 | [diff] [blame] | 6330 | StoreLo = MI->getOperand(5).getReg(); |
| 6331 | StoreHi = MI->getOperand(6).getReg(); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6332 | } else if (Op1) { |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6333 | // Perform binary operation |
Weiming Zhao | e56764b | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 6334 | unsigned tmpRegLo = MRI.createVirtualRegister(TRC); |
| 6335 | AddDefaultPred(BuildMI(BB, dl, TII->get(Op1), tmpRegLo) |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6336 | .addReg(destlo).addReg(vallo)) |
| 6337 | .addReg(NeedsCarry ? ARM::CPSR : 0, getDefRegState(NeedsCarry)); |
Weiming Zhao | e56764b | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 6338 | unsigned tmpRegHi = MRI.createVirtualRegister(TRC); |
| 6339 | AddDefaultPred(BuildMI(BB, dl, TII->get(Op2), tmpRegHi) |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 6340 | .addReg(desthi).addReg(valhi)) |
| 6341 | .addReg(IsMinMax ? ARM::CPSR : 0, getDefRegState(IsMinMax)); |
Weiming Zhao | e56764b | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 6342 | |
Tim Northover | 0adfded | 2013-01-29 09:06:13 +0000 | [diff] [blame] | 6343 | StoreLo = tmpRegLo; |
| 6344 | StoreHi = tmpRegHi; |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6345 | } else { |
| 6346 | // Copy to physregs for strexd |
Tim Northover | 0adfded | 2013-01-29 09:06:13 +0000 | [diff] [blame] | 6347 | StoreLo = vallo; |
| 6348 | StoreHi = valhi; |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6349 | } |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 6350 | if (IsMinMax) { |
| 6351 | // Compare and branch to exit block. |
| 6352 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 6353 | .addMBB(exitMBB).addImm(CC).addReg(ARM::CPSR); |
| 6354 | BB->addSuccessor(exitMBB); |
| 6355 | BB->addSuccessor(contBB); |
| 6356 | BB = contBB; |
Tim Northover | 0adfded | 2013-01-29 09:06:13 +0000 | [diff] [blame] | 6357 | StoreLo = vallo; |
| 6358 | StoreHi = valhi; |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 6359 | } |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6360 | |
| 6361 | // Store |
Tim Northover | 0adfded | 2013-01-29 09:06:13 +0000 | [diff] [blame] | 6362 | if (isThumb2) { |
| 6363 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::t2STREXD), storesuccess) |
| 6364 | .addReg(StoreLo).addReg(StoreHi).addReg(ptr)); |
| 6365 | } else { |
| 6366 | // Marshal a pair... |
| 6367 | unsigned StorePair = MRI.createVirtualRegister(&ARM::GPRPairRegClass); |
| 6368 | unsigned UndefPair = MRI.createVirtualRegister(&ARM::GPRPairRegClass); |
| 6369 | unsigned r1 = MRI.createVirtualRegister(&ARM::GPRPairRegClass); |
| 6370 | BuildMI(BB, dl, TII->get(TargetOpcode::IMPLICIT_DEF), UndefPair); |
| 6371 | BuildMI(BB, dl, TII->get(TargetOpcode::INSERT_SUBREG), r1) |
| 6372 | .addReg(UndefPair) |
| 6373 | .addReg(StoreLo) |
| 6374 | .addImm(ARM::gsub_0); |
| 6375 | BuildMI(BB, dl, TII->get(TargetOpcode::INSERT_SUBREG), StorePair) |
| 6376 | .addReg(r1) |
| 6377 | .addReg(StoreHi) |
| 6378 | .addImm(ARM::gsub_1); |
| 6379 | |
| 6380 | // ...and store it |
| 6381 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::STREXD), storesuccess) |
| 6382 | .addReg(StorePair).addReg(ptr)); |
| 6383 | } |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6384 | // Cmp+jump |
| 6385 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 6386 | .addReg(storesuccess).addImm(0)); |
| 6387 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 6388 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 6389 | |
| 6390 | BB->addSuccessor(loopMBB); |
| 6391 | BB->addSuccessor(exitMBB); |
| 6392 | |
| 6393 | // exitMBB: |
| 6394 | // ... |
| 6395 | BB = exitMBB; |
| 6396 | |
| 6397 | MI->eraseFromParent(); // The instruction is gone now. |
| 6398 | |
| 6399 | return BB; |
| 6400 | } |
| 6401 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6402 | /// SetupEntryBlockForSjLj - Insert code into the entry block that creates and |
| 6403 | /// registers the function context. |
| 6404 | void ARMTargetLowering:: |
| 6405 | SetupEntryBlockForSjLj(MachineInstr *MI, MachineBasicBlock *MBB, |
| 6406 | MachineBasicBlock *DispatchBB, int FI) const { |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6407 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 6408 | DebugLoc dl = MI->getDebugLoc(); |
| 6409 | MachineFunction *MF = MBB->getParent(); |
| 6410 | MachineRegisterInfo *MRI = &MF->getRegInfo(); |
| 6411 | MachineConstantPool *MCP = MF->getConstantPool(); |
| 6412 | ARMFunctionInfo *AFI = MF->getInfo<ARMFunctionInfo>(); |
| 6413 | const Function *F = MF->getFunction(); |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6414 | |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6415 | bool isThumb = Subtarget->isThumb(); |
Bill Wendling | ff4216a | 2011-10-03 22:44:15 +0000 | [diff] [blame] | 6416 | bool isThumb2 = Subtarget->isThumb2(); |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6417 | |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6418 | unsigned PCLabelId = AFI->createPICLabelUId(); |
Bill Wendling | ff4216a | 2011-10-03 22:44:15 +0000 | [diff] [blame] | 6419 | unsigned PCAdj = (isThumb || isThumb2) ? 4 : 8; |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6420 | ARMConstantPoolValue *CPV = |
| 6421 | ARMConstantPoolMBB::Create(F->getContext(), DispatchBB, PCLabelId, PCAdj); |
| 6422 | unsigned CPI = MCP->getConstantPoolIndex(CPV, 4); |
| 6423 | |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6424 | const TargetRegisterClass *TRC = isThumb ? |
| 6425 | (const TargetRegisterClass*)&ARM::tGPRRegClass : |
| 6426 | (const TargetRegisterClass*)&ARM::GPRRegClass; |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6427 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6428 | // Grab constant pool and fixed stack memory operands. |
| 6429 | MachineMemOperand *CPMMO = |
| 6430 | MF->getMachineMemOperand(MachinePointerInfo::getConstantPool(), |
| 6431 | MachineMemOperand::MOLoad, 4, 4); |
| 6432 | |
| 6433 | MachineMemOperand *FIMMOSt = |
| 6434 | MF->getMachineMemOperand(MachinePointerInfo::getFixedStack(FI), |
| 6435 | MachineMemOperand::MOStore, 4, 4); |
| 6436 | |
| 6437 | // Load the address of the dispatch MBB into the jump buffer. |
| 6438 | if (isThumb2) { |
| 6439 | // Incoming value: jbuf |
| 6440 | // ldr.n r5, LCPI1_1 |
| 6441 | // orr r5, r5, #1 |
| 6442 | // add r5, pc |
| 6443 | // str r5, [$jbuf, #+4] ; &jbuf[1] |
| 6444 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 6445 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2LDRpci), NewVReg1) |
| 6446 | .addConstantPoolIndex(CPI) |
| 6447 | .addMemOperand(CPMMO)); |
| 6448 | // Set the low bit because of thumb mode. |
| 6449 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 6450 | AddDefaultCC( |
| 6451 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2ORRri), NewVReg2) |
| 6452 | .addReg(NewVReg1, RegState::Kill) |
| 6453 | .addImm(0x01))); |
| 6454 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 6455 | BuildMI(*MBB, MI, dl, TII->get(ARM::tPICADD), NewVReg3) |
| 6456 | .addReg(NewVReg2, RegState::Kill) |
| 6457 | .addImm(PCLabelId); |
| 6458 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2STRi12)) |
| 6459 | .addReg(NewVReg3, RegState::Kill) |
| 6460 | .addFrameIndex(FI) |
| 6461 | .addImm(36) // &jbuf[1] :: pc |
| 6462 | .addMemOperand(FIMMOSt)); |
| 6463 | } else if (isThumb) { |
| 6464 | // Incoming value: jbuf |
| 6465 | // ldr.n r1, LCPI1_4 |
| 6466 | // add r1, pc |
| 6467 | // mov r2, #1 |
| 6468 | // orrs r1, r2 |
| 6469 | // add r2, $jbuf, #+4 ; &jbuf[1] |
| 6470 | // str r1, [r2] |
| 6471 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 6472 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tLDRpci), NewVReg1) |
| 6473 | .addConstantPoolIndex(CPI) |
| 6474 | .addMemOperand(CPMMO)); |
| 6475 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 6476 | BuildMI(*MBB, MI, dl, TII->get(ARM::tPICADD), NewVReg2) |
| 6477 | .addReg(NewVReg1, RegState::Kill) |
| 6478 | .addImm(PCLabelId); |
| 6479 | // Set the low bit because of thumb mode. |
| 6480 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 6481 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tMOVi8), NewVReg3) |
| 6482 | .addReg(ARM::CPSR, RegState::Define) |
| 6483 | .addImm(1)); |
| 6484 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 6485 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tORR), NewVReg4) |
| 6486 | .addReg(ARM::CPSR, RegState::Define) |
| 6487 | .addReg(NewVReg2, RegState::Kill) |
| 6488 | .addReg(NewVReg3, RegState::Kill)); |
| 6489 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
| 6490 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tADDrSPi), NewVReg5) |
| 6491 | .addFrameIndex(FI) |
| 6492 | .addImm(36)); // &jbuf[1] :: pc |
| 6493 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tSTRi)) |
| 6494 | .addReg(NewVReg4, RegState::Kill) |
| 6495 | .addReg(NewVReg5, RegState::Kill) |
| 6496 | .addImm(0) |
| 6497 | .addMemOperand(FIMMOSt)); |
| 6498 | } else { |
| 6499 | // Incoming value: jbuf |
| 6500 | // ldr r1, LCPI1_1 |
| 6501 | // add r1, pc, r1 |
| 6502 | // str r1, [$jbuf, #+4] ; &jbuf[1] |
| 6503 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 6504 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::LDRi12), NewVReg1) |
| 6505 | .addConstantPoolIndex(CPI) |
| 6506 | .addImm(0) |
| 6507 | .addMemOperand(CPMMO)); |
| 6508 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 6509 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::PICADD), NewVReg2) |
| 6510 | .addReg(NewVReg1, RegState::Kill) |
| 6511 | .addImm(PCLabelId)); |
| 6512 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::STRi12)) |
| 6513 | .addReg(NewVReg2, RegState::Kill) |
| 6514 | .addFrameIndex(FI) |
| 6515 | .addImm(36) // &jbuf[1] :: pc |
| 6516 | .addMemOperand(FIMMOSt)); |
| 6517 | } |
| 6518 | } |
| 6519 | |
| 6520 | MachineBasicBlock *ARMTargetLowering:: |
| 6521 | EmitSjLjDispatchBlock(MachineInstr *MI, MachineBasicBlock *MBB) const { |
| 6522 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 6523 | DebugLoc dl = MI->getDebugLoc(); |
| 6524 | MachineFunction *MF = MBB->getParent(); |
| 6525 | MachineRegisterInfo *MRI = &MF->getRegInfo(); |
| 6526 | ARMFunctionInfo *AFI = MF->getInfo<ARMFunctionInfo>(); |
| 6527 | MachineFrameInfo *MFI = MF->getFrameInfo(); |
| 6528 | int FI = MFI->getFunctionContextIndex(); |
| 6529 | |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6530 | const TargetRegisterClass *TRC = Subtarget->isThumb() ? |
| 6531 | (const TargetRegisterClass*)&ARM::tGPRRegClass : |
Jakob Stoklund Olesen | 027c32a | 2012-05-20 06:38:47 +0000 | [diff] [blame] | 6532 | (const TargetRegisterClass*)&ARM::GPRnopcRegClass; |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6533 | |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 6534 | // Get a mapping of the call site numbers to all of the landing pads they're |
| 6535 | // associated with. |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6536 | DenseMap<unsigned, SmallVector<MachineBasicBlock*, 2> > CallSiteNumToLPad; |
| 6537 | unsigned MaxCSNum = 0; |
| 6538 | MachineModuleInfo &MMI = MF->getMMI(); |
Jim Grosbach | d4f020a | 2012-04-06 23:43:50 +0000 | [diff] [blame] | 6539 | for (MachineFunction::iterator BB = MF->begin(), E = MF->end(); BB != E; |
| 6540 | ++BB) { |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6541 | if (!BB->isLandingPad()) continue; |
| 6542 | |
| 6543 | // FIXME: We should assert that the EH_LABEL is the first MI in the landing |
| 6544 | // pad. |
| 6545 | for (MachineBasicBlock::iterator |
| 6546 | II = BB->begin(), IE = BB->end(); II != IE; ++II) { |
| 6547 | if (!II->isEHLabel()) continue; |
| 6548 | |
| 6549 | MCSymbol *Sym = II->getOperand(0).getMCSymbol(); |
Bill Wendling | 5cbef19 | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 6550 | if (!MMI.hasCallSiteLandingPad(Sym)) continue; |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6551 | |
Bill Wendling | 5cbef19 | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 6552 | SmallVectorImpl<unsigned> &CallSiteIdxs = MMI.getCallSiteLandingPad(Sym); |
| 6553 | for (SmallVectorImpl<unsigned>::iterator |
| 6554 | CSI = CallSiteIdxs.begin(), CSE = CallSiteIdxs.end(); |
| 6555 | CSI != CSE; ++CSI) { |
| 6556 | CallSiteNumToLPad[*CSI].push_back(BB); |
| 6557 | MaxCSNum = std::max(MaxCSNum, *CSI); |
| 6558 | } |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6559 | break; |
| 6560 | } |
| 6561 | } |
| 6562 | |
| 6563 | // Get an ordered list of the machine basic blocks for the jump table. |
| 6564 | std::vector<MachineBasicBlock*> LPadList; |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6565 | SmallPtrSet<MachineBasicBlock*, 64> InvokeBBs; |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6566 | LPadList.reserve(CallSiteNumToLPad.size()); |
| 6567 | for (unsigned I = 1; I <= MaxCSNum; ++I) { |
| 6568 | SmallVectorImpl<MachineBasicBlock*> &MBBList = CallSiteNumToLPad[I]; |
| 6569 | for (SmallVectorImpl<MachineBasicBlock*>::iterator |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6570 | II = MBBList.begin(), IE = MBBList.end(); II != IE; ++II) { |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6571 | LPadList.push_back(*II); |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6572 | InvokeBBs.insert((*II)->pred_begin(), (*II)->pred_end()); |
| 6573 | } |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6574 | } |
| 6575 | |
Bill Wendling | 5cbef19 | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 6576 | assert(!LPadList.empty() && |
| 6577 | "No landing pad destinations for the dispatch jump table!"); |
| 6578 | |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 6579 | // Create the jump table and associated information. |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6580 | MachineJumpTableInfo *JTI = |
| 6581 | MF->getOrCreateJumpTableInfo(MachineJumpTableInfo::EK_Inline); |
| 6582 | unsigned MJTI = JTI->createJumpTableIndex(LPadList); |
| 6583 | unsigned UId = AFI->createJumpTableUId(); |
Chad Rosier | b8f307b | 2013-03-01 18:30:38 +0000 | [diff] [blame] | 6584 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6585 | |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 6586 | // Create the MBBs for the dispatch code. |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6587 | |
| 6588 | // Shove the dispatch's address into the return slot in the function context. |
| 6589 | MachineBasicBlock *DispatchBB = MF->CreateMachineBasicBlock(); |
| 6590 | DispatchBB->setIsLandingPad(); |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6591 | |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6592 | MachineBasicBlock *TrapBB = MF->CreateMachineBasicBlock(); |
Eli Bendersky | 0f156af | 2013-01-30 16:30:19 +0000 | [diff] [blame] | 6593 | unsigned trap_opcode; |
Chad Rosier | 279706e | 2013-02-28 18:54:27 +0000 | [diff] [blame] | 6594 | if (Subtarget->isThumb()) |
Eli Bendersky | 0f156af | 2013-01-30 16:30:19 +0000 | [diff] [blame] | 6595 | trap_opcode = ARM::tTRAP; |
Chad Rosier | 279706e | 2013-02-28 18:54:27 +0000 | [diff] [blame] | 6596 | else |
| 6597 | trap_opcode = Subtarget->useNaClTrap() ? ARM::TRAPNaCl : ARM::TRAP; |
| 6598 | |
Eli Bendersky | 0f156af | 2013-01-30 16:30:19 +0000 | [diff] [blame] | 6599 | BuildMI(TrapBB, dl, TII->get(trap_opcode)); |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6600 | DispatchBB->addSuccessor(TrapBB); |
| 6601 | |
| 6602 | MachineBasicBlock *DispContBB = MF->CreateMachineBasicBlock(); |
| 6603 | DispatchBB->addSuccessor(DispContBB); |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6604 | |
Bill Wendling | a48ed4f | 2011-10-17 21:32:56 +0000 | [diff] [blame] | 6605 | // Insert and MBBs. |
Bill Wendling | 930193c | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 6606 | MF->insert(MF->end(), DispatchBB); |
| 6607 | MF->insert(MF->end(), DispContBB); |
| 6608 | MF->insert(MF->end(), TrapBB); |
Bill Wendling | 930193c | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 6609 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6610 | // Insert code into the entry block that creates and registers the function |
| 6611 | // context. |
| 6612 | SetupEntryBlockForSjLj(MI, MBB, DispatchBB, FI); |
| 6613 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6614 | MachineMemOperand *FIMMOLd = |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 6615 | MF->getMachineMemOperand(MachinePointerInfo::getFixedStack(FI), |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 6616 | MachineMemOperand::MOLoad | |
| 6617 | MachineMemOperand::MOVolatile, 4, 4); |
Bill Wendling | 930193c | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 6618 | |
Chad Rosier | e7bd519 | 2012-11-06 23:05:24 +0000 | [diff] [blame] | 6619 | MachineInstrBuilder MIB; |
| 6620 | MIB = BuildMI(DispatchBB, dl, TII->get(ARM::Int_eh_sjlj_dispatchsetup)); |
| 6621 | |
| 6622 | const ARMBaseInstrInfo *AII = static_cast<const ARMBaseInstrInfo*>(TII); |
| 6623 | const ARMBaseRegisterInfo &RI = AII->getRegisterInfo(); |
| 6624 | |
| 6625 | // Add a register mask with no preserved registers. This results in all |
| 6626 | // registers being marked as clobbered. |
| 6627 | MIB.addRegMask(RI.getNoPreservedMask()); |
Bob Wilson | eaab6ef | 2011-11-16 07:11:57 +0000 | [diff] [blame] | 6628 | |
Bill Wendling | 952cb50 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 6629 | unsigned NumLPads = LPadList.size(); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6630 | if (Subtarget->isThumb2()) { |
| 6631 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 6632 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2LDRi12), NewVReg1) |
| 6633 | .addFrameIndex(FI) |
| 6634 | .addImm(4) |
| 6635 | .addMemOperand(FIMMOLd)); |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 6636 | |
Bill Wendling | 952cb50 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 6637 | if (NumLPads < 256) { |
| 6638 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2CMPri)) |
| 6639 | .addReg(NewVReg1) |
| 6640 | .addImm(LPadList.size())); |
| 6641 | } else { |
| 6642 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 6643 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2MOVi16), VReg1) |
Bill Wendling | 15a1a22 | 2011-10-18 23:19:55 +0000 | [diff] [blame] | 6644 | .addImm(NumLPads & 0xFFFF)); |
| 6645 | |
| 6646 | unsigned VReg2 = VReg1; |
| 6647 | if ((NumLPads & 0xFFFF0000) != 0) { |
| 6648 | VReg2 = MRI->createVirtualRegister(TRC); |
| 6649 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2MOVTi16), VReg2) |
| 6650 | .addReg(VReg1) |
| 6651 | .addImm(NumLPads >> 16)); |
| 6652 | } |
| 6653 | |
Bill Wendling | 952cb50 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 6654 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2CMPrr)) |
| 6655 | .addReg(NewVReg1) |
| 6656 | .addReg(VReg2)); |
| 6657 | } |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 6658 | |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6659 | BuildMI(DispatchBB, dl, TII->get(ARM::t2Bcc)) |
| 6660 | .addMBB(TrapBB) |
| 6661 | .addImm(ARMCC::HI) |
| 6662 | .addReg(ARM::CPSR); |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6663 | |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 6664 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 6665 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::t2LEApcrelJT),NewVReg3) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6666 | .addJumpTableIndex(MJTI) |
| 6667 | .addImm(UId)); |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6668 | |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 6669 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6670 | AddDefaultCC( |
| 6671 | AddDefaultPred( |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 6672 | BuildMI(DispContBB, dl, TII->get(ARM::t2ADDrs), NewVReg4) |
| 6673 | .addReg(NewVReg3, RegState::Kill) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6674 | .addReg(NewVReg1) |
| 6675 | .addImm(ARM_AM::getSORegOpc(ARM_AM::lsl, 2)))); |
| 6676 | |
| 6677 | BuildMI(DispContBB, dl, TII->get(ARM::t2BR_JT)) |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 6678 | .addReg(NewVReg4, RegState::Kill) |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6679 | .addReg(NewVReg1) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6680 | .addJumpTableIndex(MJTI) |
| 6681 | .addImm(UId); |
| 6682 | } else if (Subtarget->isThumb()) { |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 6683 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 6684 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tLDRspi), NewVReg1) |
| 6685 | .addFrameIndex(FI) |
| 6686 | .addImm(1) |
| 6687 | .addMemOperand(FIMMOLd)); |
Bill Wendling | f1083d4 | 2011-10-07 22:08:37 +0000 | [diff] [blame] | 6688 | |
Bill Wendling | a5871dc | 2011-10-18 23:11:05 +0000 | [diff] [blame] | 6689 | if (NumLPads < 256) { |
| 6690 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tCMPi8)) |
| 6691 | .addReg(NewVReg1) |
| 6692 | .addImm(NumLPads)); |
| 6693 | } else { |
| 6694 | MachineConstantPool *ConstantPool = MF->getConstantPool(); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6695 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); |
| 6696 | const Constant *C = ConstantInt::get(Int32Ty, NumLPads); |
| 6697 | |
| 6698 | // MachineConstantPool wants an explicit alignment. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 6699 | unsigned Align = getDataLayout()->getPrefTypeAlignment(Int32Ty); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6700 | if (Align == 0) |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 6701 | Align = getDataLayout()->getTypeAllocSize(C->getType()); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6702 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
Bill Wendling | a5871dc | 2011-10-18 23:11:05 +0000 | [diff] [blame] | 6703 | |
| 6704 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 6705 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tLDRpci)) |
| 6706 | .addReg(VReg1, RegState::Define) |
| 6707 | .addConstantPoolIndex(Idx)); |
| 6708 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tCMPr)) |
| 6709 | .addReg(NewVReg1) |
| 6710 | .addReg(VReg1)); |
| 6711 | } |
| 6712 | |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 6713 | BuildMI(DispatchBB, dl, TII->get(ARM::tBcc)) |
| 6714 | .addMBB(TrapBB) |
| 6715 | .addImm(ARMCC::HI) |
| 6716 | .addReg(ARM::CPSR); |
| 6717 | |
| 6718 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 6719 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLSLri), NewVReg2) |
| 6720 | .addReg(ARM::CPSR, RegState::Define) |
| 6721 | .addReg(NewVReg1) |
| 6722 | .addImm(2)); |
| 6723 | |
| 6724 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 217f0e9 | 2011-10-06 23:41:14 +0000 | [diff] [blame] | 6725 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLEApcrelJT), NewVReg3) |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 6726 | .addJumpTableIndex(MJTI) |
| 6727 | .addImm(UId)); |
| 6728 | |
| 6729 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 6730 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tADDrr), NewVReg4) |
| 6731 | .addReg(ARM::CPSR, RegState::Define) |
| 6732 | .addReg(NewVReg2, RegState::Kill) |
| 6733 | .addReg(NewVReg3)); |
| 6734 | |
| 6735 | MachineMemOperand *JTMMOLd = |
| 6736 | MF->getMachineMemOperand(MachinePointerInfo::getJumpTable(), |
| 6737 | MachineMemOperand::MOLoad, 4, 4); |
| 6738 | |
| 6739 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
| 6740 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLDRi), NewVReg5) |
| 6741 | .addReg(NewVReg4, RegState::Kill) |
| 6742 | .addImm(0) |
| 6743 | .addMemOperand(JTMMOLd)); |
| 6744 | |
Chad Rosier | b8f307b | 2013-03-01 18:30:38 +0000 | [diff] [blame] | 6745 | unsigned NewVReg6 = NewVReg5; |
| 6746 | if (RelocM == Reloc::PIC_) { |
| 6747 | NewVReg6 = MRI->createVirtualRegister(TRC); |
| 6748 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tADDrr), NewVReg6) |
| 6749 | .addReg(ARM::CPSR, RegState::Define) |
| 6750 | .addReg(NewVReg5, RegState::Kill) |
| 6751 | .addReg(NewVReg3)); |
| 6752 | } |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 6753 | |
| 6754 | BuildMI(DispContBB, dl, TII->get(ARM::tBR_JTr)) |
| 6755 | .addReg(NewVReg6, RegState::Kill) |
| 6756 | .addJumpTableIndex(MJTI) |
| 6757 | .addImm(UId); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6758 | } else { |
| 6759 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 6760 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::LDRi12), NewVReg1) |
| 6761 | .addFrameIndex(FI) |
| 6762 | .addImm(4) |
| 6763 | .addMemOperand(FIMMOLd)); |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6764 | |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6765 | if (NumLPads < 256) { |
| 6766 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPri)) |
| 6767 | .addReg(NewVReg1) |
| 6768 | .addImm(NumLPads)); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6769 | } else if (Subtarget->hasV6T2Ops() && isUInt<16>(NumLPads)) { |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6770 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 6771 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::MOVi16), VReg1) |
Bill Wendling | 15a1a22 | 2011-10-18 23:19:55 +0000 | [diff] [blame] | 6772 | .addImm(NumLPads & 0xFFFF)); |
| 6773 | |
| 6774 | unsigned VReg2 = VReg1; |
| 6775 | if ((NumLPads & 0xFFFF0000) != 0) { |
| 6776 | VReg2 = MRI->createVirtualRegister(TRC); |
| 6777 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::MOVTi16), VReg2) |
| 6778 | .addReg(VReg1) |
| 6779 | .addImm(NumLPads >> 16)); |
| 6780 | } |
| 6781 | |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6782 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPrr)) |
| 6783 | .addReg(NewVReg1) |
| 6784 | .addReg(VReg2)); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6785 | } else { |
| 6786 | MachineConstantPool *ConstantPool = MF->getConstantPool(); |
| 6787 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); |
| 6788 | const Constant *C = ConstantInt::get(Int32Ty, NumLPads); |
| 6789 | |
| 6790 | // MachineConstantPool wants an explicit alignment. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 6791 | unsigned Align = getDataLayout()->getPrefTypeAlignment(Int32Ty); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6792 | if (Align == 0) |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 6793 | Align = getDataLayout()->getTypeAllocSize(C->getType()); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6794 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
| 6795 | |
| 6796 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 6797 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::LDRcp)) |
| 6798 | .addReg(VReg1, RegState::Define) |
Bill Wendling | 767f8be | 2011-10-20 20:37:11 +0000 | [diff] [blame] | 6799 | .addConstantPoolIndex(Idx) |
| 6800 | .addImm(0)); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6801 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPrr)) |
| 6802 | .addReg(NewVReg1) |
| 6803 | .addReg(VReg1, RegState::Kill)); |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6804 | } |
| 6805 | |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6806 | BuildMI(DispatchBB, dl, TII->get(ARM::Bcc)) |
| 6807 | .addMBB(TrapBB) |
| 6808 | .addImm(ARMCC::HI) |
| 6809 | .addReg(ARM::CPSR); |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6810 | |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6811 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6812 | AddDefaultCC( |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6813 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::MOVsi), NewVReg3) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6814 | .addReg(NewVReg1) |
| 6815 | .addImm(ARM_AM::getSORegOpc(ARM_AM::lsl, 2)))); |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6816 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 6817 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::LEApcrelJT), NewVReg4) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6818 | .addJumpTableIndex(MJTI) |
| 6819 | .addImm(UId)); |
| 6820 | |
| 6821 | MachineMemOperand *JTMMOLd = |
| 6822 | MF->getMachineMemOperand(MachinePointerInfo::getJumpTable(), |
| 6823 | MachineMemOperand::MOLoad, 4, 4); |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6824 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6825 | AddDefaultPred( |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6826 | BuildMI(DispContBB, dl, TII->get(ARM::LDRrs), NewVReg5) |
| 6827 | .addReg(NewVReg3, RegState::Kill) |
| 6828 | .addReg(NewVReg4) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6829 | .addImm(0) |
| 6830 | .addMemOperand(JTMMOLd)); |
| 6831 | |
Chad Rosier | b8f307b | 2013-03-01 18:30:38 +0000 | [diff] [blame] | 6832 | if (RelocM == Reloc::PIC_) { |
| 6833 | BuildMI(DispContBB, dl, TII->get(ARM::BR_JTadd)) |
| 6834 | .addReg(NewVReg5, RegState::Kill) |
| 6835 | .addReg(NewVReg4) |
| 6836 | .addJumpTableIndex(MJTI) |
| 6837 | .addImm(UId); |
| 6838 | } else { |
| 6839 | BuildMI(DispContBB, dl, TII->get(ARM::BR_JTr)) |
| 6840 | .addReg(NewVReg5, RegState::Kill) |
| 6841 | .addJumpTableIndex(MJTI) |
| 6842 | .addImm(UId); |
| 6843 | } |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6844 | } |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6845 | |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6846 | // Add the jump table entries as successors to the MBB. |
Jakob Stoklund Olesen | a0708d1 | 2012-08-20 20:52:03 +0000 | [diff] [blame] | 6847 | SmallPtrSet<MachineBasicBlock*, 8> SeenMBBs; |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6848 | for (std::vector<MachineBasicBlock*>::iterator |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6849 | I = LPadList.begin(), E = LPadList.end(); I != E; ++I) { |
| 6850 | MachineBasicBlock *CurMBB = *I; |
Jakob Stoklund Olesen | a0708d1 | 2012-08-20 20:52:03 +0000 | [diff] [blame] | 6851 | if (SeenMBBs.insert(CurMBB)) |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6852 | DispContBB->addSuccessor(CurMBB); |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6853 | } |
| 6854 | |
Bill Wendling | 24bb925 | 2011-10-17 05:25:09 +0000 | [diff] [blame] | 6855 | // N.B. the order the invoke BBs are processed in doesn't matter here. |
Craig Topper | 015f228 | 2012-03-04 03:33:22 +0000 | [diff] [blame] | 6856 | const uint16_t *SavedRegs = RI.getCalleeSavedRegs(MF); |
Bill Wendling | f7b0207 | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 6857 | SmallVector<MachineBasicBlock*, 64> MBBLPads; |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6858 | for (SmallPtrSet<MachineBasicBlock*, 64>::iterator |
| 6859 | I = InvokeBBs.begin(), E = InvokeBBs.end(); I != E; ++I) { |
| 6860 | MachineBasicBlock *BB = *I; |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6861 | |
| 6862 | // Remove the landing pad successor from the invoke block and replace it |
| 6863 | // with the new dispatch block. |
Bill Wendling | de39d86 | 2011-10-26 07:16:18 +0000 | [diff] [blame] | 6864 | SmallVector<MachineBasicBlock*, 4> Successors(BB->succ_begin(), |
| 6865 | BB->succ_end()); |
| 6866 | while (!Successors.empty()) { |
| 6867 | MachineBasicBlock *SMBB = Successors.pop_back_val(); |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6868 | if (SMBB->isLandingPad()) { |
| 6869 | BB->removeSuccessor(SMBB); |
Bill Wendling | f7b0207 | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 6870 | MBBLPads.push_back(SMBB); |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6871 | } |
| 6872 | } |
| 6873 | |
| 6874 | BB->addSuccessor(DispatchBB); |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6875 | |
| 6876 | // Find the invoke call and mark all of the callee-saved registers as |
| 6877 | // 'implicit defined' so that they're spilled. This prevents code from |
| 6878 | // moving instructions to before the EH block, where they will never be |
| 6879 | // executed. |
| 6880 | for (MachineBasicBlock::reverse_iterator |
| 6881 | II = BB->rbegin(), IE = BB->rend(); II != IE; ++II) { |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 6882 | if (!II->isCall()) continue; |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6883 | |
| 6884 | DenseMap<unsigned, bool> DefRegs; |
| 6885 | for (MachineInstr::mop_iterator |
| 6886 | OI = II->operands_begin(), OE = II->operands_end(); |
| 6887 | OI != OE; ++OI) { |
| 6888 | if (!OI->isReg()) continue; |
| 6889 | DefRegs[OI->getReg()] = true; |
| 6890 | } |
| 6891 | |
Jakob Stoklund Olesen | 37a942c | 2012-12-19 21:31:56 +0000 | [diff] [blame] | 6892 | MachineInstrBuilder MIB(*MF, &*II); |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6893 | |
Bill Wendling | 5d79859 | 2011-10-14 23:55:44 +0000 | [diff] [blame] | 6894 | for (unsigned i = 0; SavedRegs[i] != 0; ++i) { |
Bill Wendling | b8dcb31 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 6895 | unsigned Reg = SavedRegs[i]; |
| 6896 | if (Subtarget->isThumb2() && |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6897 | !ARM::tGPRRegClass.contains(Reg) && |
| 6898 | !ARM::hGPRRegClass.contains(Reg)) |
Bill Wendling | b8dcb31 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 6899 | continue; |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6900 | if (Subtarget->isThumb1Only() && !ARM::tGPRRegClass.contains(Reg)) |
Bill Wendling | b8dcb31 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 6901 | continue; |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6902 | if (!Subtarget->isThumb() && !ARM::GPRRegClass.contains(Reg)) |
Bill Wendling | b8dcb31 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 6903 | continue; |
| 6904 | if (!DefRegs[Reg]) |
| 6905 | MIB.addReg(Reg, RegState::ImplicitDefine | RegState::Dead); |
Bill Wendling | 5d79859 | 2011-10-14 23:55:44 +0000 | [diff] [blame] | 6906 | } |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6907 | |
| 6908 | break; |
| 6909 | } |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6910 | } |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6911 | |
Bill Wendling | f7b0207 | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 6912 | // Mark all former landing pads as non-landing pads. The dispatch is the only |
| 6913 | // landing pad now. |
| 6914 | for (SmallVectorImpl<MachineBasicBlock*>::iterator |
| 6915 | I = MBBLPads.begin(), E = MBBLPads.end(); I != E; ++I) |
| 6916 | (*I)->setIsLandingPad(false); |
| 6917 | |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6918 | // The instruction is gone now. |
| 6919 | MI->eraseFromParent(); |
| 6920 | |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6921 | return MBB; |
| 6922 | } |
| 6923 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 6924 | static |
| 6925 | MachineBasicBlock *OtherSucc(MachineBasicBlock *MBB, MachineBasicBlock *Succ) { |
| 6926 | for (MachineBasicBlock::succ_iterator I = MBB->succ_begin(), |
| 6927 | E = MBB->succ_end(); I != E; ++I) |
| 6928 | if (*I != Succ) |
| 6929 | return *I; |
| 6930 | llvm_unreachable("Expecting a BB with two successors!"); |
| 6931 | } |
| 6932 | |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6933 | MachineBasicBlock *ARMTargetLowering:: |
| 6934 | EmitStructByval(MachineInstr *MI, MachineBasicBlock *BB) const { |
| 6935 | // This pseudo instruction has 3 operands: dst, src, size |
| 6936 | // We expand it to a loop if size > Subtarget->getMaxInlineSizeThreshold(). |
| 6937 | // Otherwise, we will generate unrolled scalar copies. |
| 6938 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 6939 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 6940 | MachineFunction::iterator It = BB; |
| 6941 | ++It; |
| 6942 | |
| 6943 | unsigned dest = MI->getOperand(0).getReg(); |
| 6944 | unsigned src = MI->getOperand(1).getReg(); |
| 6945 | unsigned SizeVal = MI->getOperand(2).getImm(); |
| 6946 | unsigned Align = MI->getOperand(3).getImm(); |
| 6947 | DebugLoc dl = MI->getDebugLoc(); |
| 6948 | |
| 6949 | bool isThumb2 = Subtarget->isThumb2(); |
| 6950 | MachineFunction *MF = BB->getParent(); |
| 6951 | MachineRegisterInfo &MRI = MF->getRegInfo(); |
Manman Ren | eda9fdf | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6952 | unsigned ldrOpc, strOpc, UnitSize = 0; |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6953 | |
| 6954 | const TargetRegisterClass *TRC = isThumb2 ? |
| 6955 | (const TargetRegisterClass*)&ARM::tGPRRegClass : |
| 6956 | (const TargetRegisterClass*)&ARM::GPRRegClass; |
Manman Ren | eda9fdf | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6957 | const TargetRegisterClass *TRC_Vec = 0; |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6958 | |
| 6959 | if (Align & 1) { |
| 6960 | ldrOpc = isThumb2 ? ARM::t2LDRB_POST : ARM::LDRB_POST_IMM; |
| 6961 | strOpc = isThumb2 ? ARM::t2STRB_POST : ARM::STRB_POST_IMM; |
| 6962 | UnitSize = 1; |
| 6963 | } else if (Align & 2) { |
| 6964 | ldrOpc = isThumb2 ? ARM::t2LDRH_POST : ARM::LDRH_POST; |
| 6965 | strOpc = isThumb2 ? ARM::t2STRH_POST : ARM::STRH_POST; |
| 6966 | UnitSize = 2; |
| 6967 | } else { |
Manman Ren | eda9fdf | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6968 | // Check whether we can use NEON instructions. |
Bill Wendling | 831737d | 2012-12-30 10:32:01 +0000 | [diff] [blame] | 6969 | if (!MF->getFunction()->getAttributes(). |
| 6970 | hasAttribute(AttributeSet::FunctionIndex, |
| 6971 | Attribute::NoImplicitFloat) && |
Manman Ren | eda9fdf | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6972 | Subtarget->hasNEON()) { |
| 6973 | if ((Align % 16 == 0) && SizeVal >= 16) { |
| 6974 | ldrOpc = ARM::VLD1q32wb_fixed; |
| 6975 | strOpc = ARM::VST1q32wb_fixed; |
| 6976 | UnitSize = 16; |
| 6977 | TRC_Vec = (const TargetRegisterClass*)&ARM::DPairRegClass; |
| 6978 | } |
| 6979 | else if ((Align % 8 == 0) && SizeVal >= 8) { |
| 6980 | ldrOpc = ARM::VLD1d32wb_fixed; |
| 6981 | strOpc = ARM::VST1d32wb_fixed; |
| 6982 | UnitSize = 8; |
| 6983 | TRC_Vec = (const TargetRegisterClass*)&ARM::DPRRegClass; |
| 6984 | } |
| 6985 | } |
| 6986 | // Can't use NEON instructions. |
| 6987 | if (UnitSize == 0) { |
| 6988 | ldrOpc = isThumb2 ? ARM::t2LDR_POST : ARM::LDR_POST_IMM; |
| 6989 | strOpc = isThumb2 ? ARM::t2STR_POST : ARM::STR_POST_IMM; |
| 6990 | UnitSize = 4; |
| 6991 | } |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6992 | } |
Manman Ren | eda9fdf | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6993 | |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6994 | unsigned BytesLeft = SizeVal % UnitSize; |
| 6995 | unsigned LoopSize = SizeVal - BytesLeft; |
| 6996 | |
| 6997 | if (SizeVal <= Subtarget->getMaxInlineSizeThreshold()) { |
| 6998 | // Use LDR and STR to copy. |
| 6999 | // [scratch, srcOut] = LDR_POST(srcIn, UnitSize) |
| 7000 | // [destOut] = STR_POST(scratch, destIn, UnitSize) |
| 7001 | unsigned srcIn = src; |
| 7002 | unsigned destIn = dest; |
| 7003 | for (unsigned i = 0; i < LoopSize; i+=UnitSize) { |
Manman Ren | eda9fdf | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 7004 | unsigned scratch = MRI.createVirtualRegister(UnitSize >= 8 ? TRC_Vec:TRC); |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7005 | unsigned srcOut = MRI.createVirtualRegister(TRC); |
| 7006 | unsigned destOut = MRI.createVirtualRegister(TRC); |
Manman Ren | eda9fdf | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 7007 | if (UnitSize >= 8) { |
| 7008 | AddDefaultPred(BuildMI(*BB, MI, dl, |
| 7009 | TII->get(ldrOpc), scratch) |
| 7010 | .addReg(srcOut, RegState::Define).addReg(srcIn).addImm(0)); |
| 7011 | |
| 7012 | AddDefaultPred(BuildMI(*BB, MI, dl, TII->get(strOpc), destOut) |
| 7013 | .addReg(destIn).addImm(0).addReg(scratch)); |
| 7014 | } else if (isThumb2) { |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7015 | AddDefaultPred(BuildMI(*BB, MI, dl, |
| 7016 | TII->get(ldrOpc), scratch) |
| 7017 | .addReg(srcOut, RegState::Define).addReg(srcIn).addImm(UnitSize)); |
| 7018 | |
| 7019 | AddDefaultPred(BuildMI(*BB, MI, dl, TII->get(strOpc), destOut) |
| 7020 | .addReg(scratch).addReg(destIn) |
| 7021 | .addImm(UnitSize)); |
| 7022 | } else { |
| 7023 | AddDefaultPred(BuildMI(*BB, MI, dl, |
| 7024 | TII->get(ldrOpc), scratch) |
| 7025 | .addReg(srcOut, RegState::Define).addReg(srcIn).addReg(0) |
| 7026 | .addImm(UnitSize)); |
| 7027 | |
| 7028 | AddDefaultPred(BuildMI(*BB, MI, dl, TII->get(strOpc), destOut) |
| 7029 | .addReg(scratch).addReg(destIn) |
| 7030 | .addReg(0).addImm(UnitSize)); |
| 7031 | } |
| 7032 | srcIn = srcOut; |
| 7033 | destIn = destOut; |
| 7034 | } |
| 7035 | |
| 7036 | // Handle the leftover bytes with LDRB and STRB. |
| 7037 | // [scratch, srcOut] = LDRB_POST(srcIn, 1) |
| 7038 | // [destOut] = STRB_POST(scratch, destIn, 1) |
| 7039 | ldrOpc = isThumb2 ? ARM::t2LDRB_POST : ARM::LDRB_POST_IMM; |
| 7040 | strOpc = isThumb2 ? ARM::t2STRB_POST : ARM::STRB_POST_IMM; |
| 7041 | for (unsigned i = 0; i < BytesLeft; i++) { |
| 7042 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| 7043 | unsigned srcOut = MRI.createVirtualRegister(TRC); |
| 7044 | unsigned destOut = MRI.createVirtualRegister(TRC); |
| 7045 | if (isThumb2) { |
| 7046 | AddDefaultPred(BuildMI(*BB, MI, dl, |
| 7047 | TII->get(ldrOpc),scratch) |
| 7048 | .addReg(srcOut, RegState::Define).addReg(srcIn).addImm(1)); |
| 7049 | |
| 7050 | AddDefaultPred(BuildMI(*BB, MI, dl, TII->get(strOpc), destOut) |
| 7051 | .addReg(scratch).addReg(destIn) |
| 7052 | .addReg(0).addImm(1)); |
| 7053 | } else { |
| 7054 | AddDefaultPred(BuildMI(*BB, MI, dl, |
| 7055 | TII->get(ldrOpc),scratch) |
Stepan Dyatkovskiy | 2c2cb3c | 2012-10-10 11:43:40 +0000 | [diff] [blame] | 7056 | .addReg(srcOut, RegState::Define).addReg(srcIn) |
| 7057 | .addReg(0).addImm(1)); |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7058 | |
| 7059 | AddDefaultPred(BuildMI(*BB, MI, dl, TII->get(strOpc), destOut) |
| 7060 | .addReg(scratch).addReg(destIn) |
| 7061 | .addReg(0).addImm(1)); |
| 7062 | } |
| 7063 | srcIn = srcOut; |
| 7064 | destIn = destOut; |
| 7065 | } |
| 7066 | MI->eraseFromParent(); // The instruction is gone now. |
| 7067 | return BB; |
| 7068 | } |
| 7069 | |
| 7070 | // Expand the pseudo op to a loop. |
| 7071 | // thisMBB: |
| 7072 | // ... |
| 7073 | // movw varEnd, # --> with thumb2 |
| 7074 | // movt varEnd, # |
| 7075 | // ldrcp varEnd, idx --> without thumb2 |
| 7076 | // fallthrough --> loopMBB |
| 7077 | // loopMBB: |
| 7078 | // PHI varPhi, varEnd, varLoop |
| 7079 | // PHI srcPhi, src, srcLoop |
| 7080 | // PHI destPhi, dst, destLoop |
| 7081 | // [scratch, srcLoop] = LDR_POST(srcPhi, UnitSize) |
| 7082 | // [destLoop] = STR_POST(scratch, destPhi, UnitSize) |
| 7083 | // subs varLoop, varPhi, #UnitSize |
| 7084 | // bne loopMBB |
| 7085 | // fallthrough --> exitMBB |
| 7086 | // exitMBB: |
| 7087 | // epilogue to handle left-over bytes |
| 7088 | // [scratch, srcOut] = LDRB_POST(srcLoop, 1) |
| 7089 | // [destOut] = STRB_POST(scratch, destLoop, 1) |
| 7090 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 7091 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 7092 | MF->insert(It, loopMBB); |
| 7093 | MF->insert(It, exitMBB); |
| 7094 | |
| 7095 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 7096 | exitMBB->splice(exitMBB->begin(), BB, |
| 7097 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 7098 | BB->end()); |
| 7099 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 7100 | |
| 7101 | // Load an immediate to varEnd. |
| 7102 | unsigned varEnd = MRI.createVirtualRegister(TRC); |
| 7103 | if (isThumb2) { |
| 7104 | unsigned VReg1 = varEnd; |
| 7105 | if ((LoopSize & 0xFFFF0000) != 0) |
| 7106 | VReg1 = MRI.createVirtualRegister(TRC); |
| 7107 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::t2MOVi16), VReg1) |
| 7108 | .addImm(LoopSize & 0xFFFF)); |
| 7109 | |
| 7110 | if ((LoopSize & 0xFFFF0000) != 0) |
| 7111 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::t2MOVTi16), varEnd) |
| 7112 | .addReg(VReg1) |
| 7113 | .addImm(LoopSize >> 16)); |
| 7114 | } else { |
| 7115 | MachineConstantPool *ConstantPool = MF->getConstantPool(); |
| 7116 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); |
| 7117 | const Constant *C = ConstantInt::get(Int32Ty, LoopSize); |
| 7118 | |
| 7119 | // MachineConstantPool wants an explicit alignment. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 7120 | unsigned Align = getDataLayout()->getPrefTypeAlignment(Int32Ty); |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7121 | if (Align == 0) |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 7122 | Align = getDataLayout()->getTypeAllocSize(C->getType()); |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7123 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
| 7124 | |
| 7125 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::LDRcp)) |
| 7126 | .addReg(varEnd, RegState::Define) |
| 7127 | .addConstantPoolIndex(Idx) |
| 7128 | .addImm(0)); |
| 7129 | } |
| 7130 | BB->addSuccessor(loopMBB); |
| 7131 | |
| 7132 | // Generate the loop body: |
| 7133 | // varPhi = PHI(varLoop, varEnd) |
| 7134 | // srcPhi = PHI(srcLoop, src) |
| 7135 | // destPhi = PHI(destLoop, dst) |
| 7136 | MachineBasicBlock *entryBB = BB; |
| 7137 | BB = loopMBB; |
| 7138 | unsigned varLoop = MRI.createVirtualRegister(TRC); |
| 7139 | unsigned varPhi = MRI.createVirtualRegister(TRC); |
| 7140 | unsigned srcLoop = MRI.createVirtualRegister(TRC); |
| 7141 | unsigned srcPhi = MRI.createVirtualRegister(TRC); |
| 7142 | unsigned destLoop = MRI.createVirtualRegister(TRC); |
| 7143 | unsigned destPhi = MRI.createVirtualRegister(TRC); |
| 7144 | |
| 7145 | BuildMI(*BB, BB->begin(), dl, TII->get(ARM::PHI), varPhi) |
| 7146 | .addReg(varLoop).addMBB(loopMBB) |
| 7147 | .addReg(varEnd).addMBB(entryBB); |
| 7148 | BuildMI(BB, dl, TII->get(ARM::PHI), srcPhi) |
| 7149 | .addReg(srcLoop).addMBB(loopMBB) |
| 7150 | .addReg(src).addMBB(entryBB); |
| 7151 | BuildMI(BB, dl, TII->get(ARM::PHI), destPhi) |
| 7152 | .addReg(destLoop).addMBB(loopMBB) |
| 7153 | .addReg(dest).addMBB(entryBB); |
| 7154 | |
| 7155 | // [scratch, srcLoop] = LDR_POST(srcPhi, UnitSize) |
| 7156 | // [destLoop] = STR_POST(scratch, destPhi, UnitSiz) |
Manman Ren | eda9fdf | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 7157 | unsigned scratch = MRI.createVirtualRegister(UnitSize >= 8 ? TRC_Vec:TRC); |
| 7158 | if (UnitSize >= 8) { |
| 7159 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc), scratch) |
| 7160 | .addReg(srcLoop, RegState::Define).addReg(srcPhi).addImm(0)); |
| 7161 | |
| 7162 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), destLoop) |
| 7163 | .addReg(destPhi).addImm(0).addReg(scratch)); |
| 7164 | } else if (isThumb2) { |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7165 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc), scratch) |
| 7166 | .addReg(srcLoop, RegState::Define).addReg(srcPhi).addImm(UnitSize)); |
| 7167 | |
| 7168 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), destLoop) |
| 7169 | .addReg(scratch).addReg(destPhi) |
| 7170 | .addImm(UnitSize)); |
| 7171 | } else { |
| 7172 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc), scratch) |
| 7173 | .addReg(srcLoop, RegState::Define).addReg(srcPhi).addReg(0) |
| 7174 | .addImm(UnitSize)); |
| 7175 | |
| 7176 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), destLoop) |
| 7177 | .addReg(scratch).addReg(destPhi) |
| 7178 | .addReg(0).addImm(UnitSize)); |
| 7179 | } |
| 7180 | |
| 7181 | // Decrement loop variable by UnitSize. |
| 7182 | MachineInstrBuilder MIB = BuildMI(BB, dl, |
| 7183 | TII->get(isThumb2 ? ARM::t2SUBri : ARM::SUBri), varLoop); |
| 7184 | AddDefaultCC(AddDefaultPred(MIB.addReg(varPhi).addImm(UnitSize))); |
| 7185 | MIB->getOperand(5).setReg(ARM::CPSR); |
| 7186 | MIB->getOperand(5).setIsDef(true); |
| 7187 | |
| 7188 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 7189 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 7190 | |
| 7191 | // loopMBB can loop back to loopMBB or fall through to exitMBB. |
| 7192 | BB->addSuccessor(loopMBB); |
| 7193 | BB->addSuccessor(exitMBB); |
| 7194 | |
| 7195 | // Add epilogue to handle BytesLeft. |
| 7196 | BB = exitMBB; |
| 7197 | MachineInstr *StartOfExit = exitMBB->begin(); |
| 7198 | ldrOpc = isThumb2 ? ARM::t2LDRB_POST : ARM::LDRB_POST_IMM; |
| 7199 | strOpc = isThumb2 ? ARM::t2STRB_POST : ARM::STRB_POST_IMM; |
| 7200 | |
| 7201 | // [scratch, srcOut] = LDRB_POST(srcLoop, 1) |
| 7202 | // [destOut] = STRB_POST(scratch, destLoop, 1) |
| 7203 | unsigned srcIn = srcLoop; |
| 7204 | unsigned destIn = destLoop; |
| 7205 | for (unsigned i = 0; i < BytesLeft; i++) { |
| 7206 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| 7207 | unsigned srcOut = MRI.createVirtualRegister(TRC); |
| 7208 | unsigned destOut = MRI.createVirtualRegister(TRC); |
| 7209 | if (isThumb2) { |
| 7210 | AddDefaultPred(BuildMI(*BB, StartOfExit, dl, |
| 7211 | TII->get(ldrOpc),scratch) |
| 7212 | .addReg(srcOut, RegState::Define).addReg(srcIn).addImm(1)); |
| 7213 | |
| 7214 | AddDefaultPred(BuildMI(*BB, StartOfExit, dl, TII->get(strOpc), destOut) |
| 7215 | .addReg(scratch).addReg(destIn) |
| 7216 | .addImm(1)); |
| 7217 | } else { |
| 7218 | AddDefaultPred(BuildMI(*BB, StartOfExit, dl, |
| 7219 | TII->get(ldrOpc),scratch) |
| 7220 | .addReg(srcOut, RegState::Define).addReg(srcIn).addReg(0).addImm(1)); |
| 7221 | |
| 7222 | AddDefaultPred(BuildMI(*BB, StartOfExit, dl, TII->get(strOpc), destOut) |
| 7223 | .addReg(scratch).addReg(destIn) |
| 7224 | .addReg(0).addImm(1)); |
| 7225 | } |
| 7226 | srcIn = srcOut; |
| 7227 | destIn = destOut; |
| 7228 | } |
| 7229 | |
| 7230 | MI->eraseFromParent(); // The instruction is gone now. |
| 7231 | return BB; |
| 7232 | } |
| 7233 | |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 7234 | MachineBasicBlock * |
Evan Cheng | ff9b373 | 2008-01-30 18:18:23 +0000 | [diff] [blame] | 7235 | ARMTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
Dan Gohman | af1d8ca | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 7236 | MachineBasicBlock *BB) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7237 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Dale Johannesen | b672840 | 2009-02-13 02:25:56 +0000 | [diff] [blame] | 7238 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 7239 | bool isThumb2 = Subtarget->isThumb2(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7240 | switch (MI->getOpcode()) { |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 7241 | default: { |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 7242 | MI->dump(); |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 7243 | llvm_unreachable("Unexpected instr type to insert"); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 7244 | } |
Jim Grosbach | ee2c2a4 | 2011-09-16 21:55:56 +0000 | [diff] [blame] | 7245 | // The Thumb2 pre-indexed stores have the same MI operands, they just |
| 7246 | // define them differently in the .td files from the isel patterns, so |
| 7247 | // they need pseudos. |
| 7248 | case ARM::t2STR_preidx: |
| 7249 | MI->setDesc(TII->get(ARM::t2STR_PRE)); |
| 7250 | return BB; |
| 7251 | case ARM::t2STRB_preidx: |
| 7252 | MI->setDesc(TII->get(ARM::t2STRB_PRE)); |
| 7253 | return BB; |
| 7254 | case ARM::t2STRH_preidx: |
| 7255 | MI->setDesc(TII->get(ARM::t2STRH_PRE)); |
| 7256 | return BB; |
| 7257 | |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 7258 | case ARM::STRi_preidx: |
| 7259 | case ARM::STRBi_preidx: { |
Jim Grosbach | 6cd5716 | 2011-08-09 21:22:41 +0000 | [diff] [blame] | 7260 | unsigned NewOpc = MI->getOpcode() == ARM::STRi_preidx ? |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 7261 | ARM::STR_PRE_IMM : ARM::STRB_PRE_IMM; |
| 7262 | // Decode the offset. |
| 7263 | unsigned Offset = MI->getOperand(4).getImm(); |
| 7264 | bool isSub = ARM_AM::getAM2Op(Offset) == ARM_AM::sub; |
| 7265 | Offset = ARM_AM::getAM2Offset(Offset); |
| 7266 | if (isSub) |
| 7267 | Offset = -Offset; |
| 7268 | |
Jim Grosbach | 4dfe220 | 2011-08-12 21:02:34 +0000 | [diff] [blame] | 7269 | MachineMemOperand *MMO = *MI->memoperands_begin(); |
Benjamin Kramer | 2753ae3 | 2011-08-27 17:36:14 +0000 | [diff] [blame] | 7270 | BuildMI(*BB, MI, dl, TII->get(NewOpc)) |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 7271 | .addOperand(MI->getOperand(0)) // Rn_wb |
| 7272 | .addOperand(MI->getOperand(1)) // Rt |
| 7273 | .addOperand(MI->getOperand(2)) // Rn |
| 7274 | .addImm(Offset) // offset (skip GPR==zero_reg) |
| 7275 | .addOperand(MI->getOperand(5)) // pred |
Jim Grosbach | 4dfe220 | 2011-08-12 21:02:34 +0000 | [diff] [blame] | 7276 | .addOperand(MI->getOperand(6)) |
| 7277 | .addMemOperand(MMO); |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 7278 | MI->eraseFromParent(); |
| 7279 | return BB; |
| 7280 | } |
| 7281 | case ARM::STRr_preidx: |
Jim Grosbach | 7b8f46c | 2011-08-11 21:17:22 +0000 | [diff] [blame] | 7282 | case ARM::STRBr_preidx: |
| 7283 | case ARM::STRH_preidx: { |
| 7284 | unsigned NewOpc; |
| 7285 | switch (MI->getOpcode()) { |
| 7286 | default: llvm_unreachable("unexpected opcode!"); |
| 7287 | case ARM::STRr_preidx: NewOpc = ARM::STR_PRE_REG; break; |
| 7288 | case ARM::STRBr_preidx: NewOpc = ARM::STRB_PRE_REG; break; |
| 7289 | case ARM::STRH_preidx: NewOpc = ARM::STRH_PRE; break; |
| 7290 | } |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 7291 | MachineInstrBuilder MIB = BuildMI(*BB, MI, dl, TII->get(NewOpc)); |
| 7292 | for (unsigned i = 0; i < MI->getNumOperands(); ++i) |
| 7293 | MIB.addOperand(MI->getOperand(i)); |
| 7294 | MI->eraseFromParent(); |
| 7295 | return BB; |
| 7296 | } |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 7297 | case ARM::ATOMIC_LOAD_ADD_I8: |
| 7298 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 7299 | case ARM::ATOMIC_LOAD_ADD_I16: |
| 7300 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 7301 | case ARM::ATOMIC_LOAD_ADD_I32: |
| 7302 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 7303 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 7304 | case ARM::ATOMIC_LOAD_AND_I8: |
| 7305 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 7306 | case ARM::ATOMIC_LOAD_AND_I16: |
| 7307 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 7308 | case ARM::ATOMIC_LOAD_AND_I32: |
| 7309 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 7310 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 7311 | case ARM::ATOMIC_LOAD_OR_I8: |
| 7312 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 7313 | case ARM::ATOMIC_LOAD_OR_I16: |
| 7314 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 7315 | case ARM::ATOMIC_LOAD_OR_I32: |
| 7316 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 7317 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 7318 | case ARM::ATOMIC_LOAD_XOR_I8: |
| 7319 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 7320 | case ARM::ATOMIC_LOAD_XOR_I16: |
| 7321 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 7322 | case ARM::ATOMIC_LOAD_XOR_I32: |
| 7323 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 7324 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 7325 | case ARM::ATOMIC_LOAD_NAND_I8: |
| 7326 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 7327 | case ARM::ATOMIC_LOAD_NAND_I16: |
| 7328 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 7329 | case ARM::ATOMIC_LOAD_NAND_I32: |
| 7330 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 7331 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 7332 | case ARM::ATOMIC_LOAD_SUB_I8: |
| 7333 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 7334 | case ARM::ATOMIC_LOAD_SUB_I16: |
| 7335 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 7336 | case ARM::ATOMIC_LOAD_SUB_I32: |
| 7337 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 7338 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 7339 | case ARM::ATOMIC_LOAD_MIN_I8: |
| 7340 | return EmitAtomicBinaryMinMax(MI, BB, 1, true, ARMCC::LT); |
| 7341 | case ARM::ATOMIC_LOAD_MIN_I16: |
| 7342 | return EmitAtomicBinaryMinMax(MI, BB, 2, true, ARMCC::LT); |
| 7343 | case ARM::ATOMIC_LOAD_MIN_I32: |
| 7344 | return EmitAtomicBinaryMinMax(MI, BB, 4, true, ARMCC::LT); |
| 7345 | |
| 7346 | case ARM::ATOMIC_LOAD_MAX_I8: |
| 7347 | return EmitAtomicBinaryMinMax(MI, BB, 1, true, ARMCC::GT); |
| 7348 | case ARM::ATOMIC_LOAD_MAX_I16: |
| 7349 | return EmitAtomicBinaryMinMax(MI, BB, 2, true, ARMCC::GT); |
| 7350 | case ARM::ATOMIC_LOAD_MAX_I32: |
| 7351 | return EmitAtomicBinaryMinMax(MI, BB, 4, true, ARMCC::GT); |
| 7352 | |
| 7353 | case ARM::ATOMIC_LOAD_UMIN_I8: |
| 7354 | return EmitAtomicBinaryMinMax(MI, BB, 1, false, ARMCC::LO); |
| 7355 | case ARM::ATOMIC_LOAD_UMIN_I16: |
| 7356 | return EmitAtomicBinaryMinMax(MI, BB, 2, false, ARMCC::LO); |
| 7357 | case ARM::ATOMIC_LOAD_UMIN_I32: |
| 7358 | return EmitAtomicBinaryMinMax(MI, BB, 4, false, ARMCC::LO); |
| 7359 | |
| 7360 | case ARM::ATOMIC_LOAD_UMAX_I8: |
| 7361 | return EmitAtomicBinaryMinMax(MI, BB, 1, false, ARMCC::HI); |
| 7362 | case ARM::ATOMIC_LOAD_UMAX_I16: |
| 7363 | return EmitAtomicBinaryMinMax(MI, BB, 2, false, ARMCC::HI); |
| 7364 | case ARM::ATOMIC_LOAD_UMAX_I32: |
| 7365 | return EmitAtomicBinaryMinMax(MI, BB, 4, false, ARMCC::HI); |
| 7366 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 7367 | case ARM::ATOMIC_SWAP_I8: return EmitAtomicBinary(MI, BB, 1, 0); |
| 7368 | case ARM::ATOMIC_SWAP_I16: return EmitAtomicBinary(MI, BB, 2, 0); |
| 7369 | case ARM::ATOMIC_SWAP_I32: return EmitAtomicBinary(MI, BB, 4, 0); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 7370 | |
| 7371 | case ARM::ATOMIC_CMP_SWAP_I8: return EmitAtomicCmpSwap(MI, BB, 1); |
| 7372 | case ARM::ATOMIC_CMP_SWAP_I16: return EmitAtomicCmpSwap(MI, BB, 2); |
| 7373 | case ARM::ATOMIC_CMP_SWAP_I32: return EmitAtomicCmpSwap(MI, BB, 4); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 7374 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 7375 | |
| 7376 | case ARM::ATOMADD6432: |
| 7377 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 7378 | isThumb2 ? ARM::t2ADCrr : ARM::ADCrr, |
| 7379 | /*NeedsCarry*/ true); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 7380 | case ARM::ATOMSUB6432: |
| 7381 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 7382 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 7383 | /*NeedsCarry*/ true); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 7384 | case ARM::ATOMOR6432: |
| 7385 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 7386 | isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 7387 | case ARM::ATOMXOR6432: |
| 7388 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2EORrr : ARM::EORrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 7389 | isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 7390 | case ARM::ATOMAND6432: |
| 7391 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 7392 | isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 7393 | case ARM::ATOMSWAP6432: |
| 7394 | return EmitAtomicBinary64(MI, BB, 0, 0, false); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 7395 | case ARM::ATOMCMPXCHG6432: |
| 7396 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
| 7397 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 7398 | /*NeedsCarry*/ false, /*IsCmpxchg*/true); |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 7399 | case ARM::ATOMMIN6432: |
| 7400 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
| 7401 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 7402 | /*NeedsCarry*/ true, /*IsCmpxchg*/false, |
Silviu Baranga | 4a9256f | 2013-01-25 10:39:49 +0000 | [diff] [blame] | 7403 | /*IsMinMax*/ true, ARMCC::LT); |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 7404 | case ARM::ATOMMAX6432: |
| 7405 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
| 7406 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 7407 | /*NeedsCarry*/ true, /*IsCmpxchg*/false, |
| 7408 | /*IsMinMax*/ true, ARMCC::GE); |
| 7409 | case ARM::ATOMUMIN6432: |
| 7410 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
| 7411 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 7412 | /*NeedsCarry*/ true, /*IsCmpxchg*/false, |
Silviu Baranga | 4a9256f | 2013-01-25 10:39:49 +0000 | [diff] [blame] | 7413 | /*IsMinMax*/ true, ARMCC::LO); |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 7414 | case ARM::ATOMUMAX6432: |
| 7415 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
| 7416 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 7417 | /*NeedsCarry*/ true, /*IsCmpxchg*/false, |
| 7418 | /*IsMinMax*/ true, ARMCC::HS); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 7419 | |
Evan Cheng | 007ea27 | 2009-08-12 05:17:19 +0000 | [diff] [blame] | 7420 | case ARM::tMOVCCr_pseudo: { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7421 | // To "insert" a SELECT_CC instruction, we actually have to insert the |
| 7422 | // diamond control-flow pattern. The incoming instruction knows the |
| 7423 | // destination vreg to set, the condition code register to branch on, the |
| 7424 | // true/false values to select between, and a branch opcode to use. |
| 7425 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 7426 | MachineFunction::iterator It = BB; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7427 | ++It; |
| 7428 | |
| 7429 | // thisMBB: |
| 7430 | // ... |
| 7431 | // TrueVal = ... |
| 7432 | // cmpTY ccX, r1, r2 |
| 7433 | // bCC copy1MBB |
| 7434 | // fallthrough --> copy0MBB |
| 7435 | MachineBasicBlock *thisMBB = BB; |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 7436 | MachineFunction *F = BB->getParent(); |
| 7437 | MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 7438 | MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); |
Dan Gohman | 258c58c | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 7439 | F->insert(It, copy0MBB); |
| 7440 | F->insert(It, sinkMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 7441 | |
| 7442 | // Transfer the remainder of BB and its successor edges to sinkMBB. |
| 7443 | sinkMBB->splice(sinkMBB->begin(), BB, |
| 7444 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 7445 | BB->end()); |
| 7446 | sinkMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 7447 | |
Dan Gohman | 258c58c | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 7448 | BB->addSuccessor(copy0MBB); |
| 7449 | BB->addSuccessor(sinkMBB); |
Dan Gohman | b81c771 | 2010-07-06 15:18:19 +0000 | [diff] [blame] | 7450 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 7451 | BuildMI(BB, dl, TII->get(ARM::tBcc)).addMBB(sinkMBB) |
| 7452 | .addImm(MI->getOperand(3).getImm()).addReg(MI->getOperand(4).getReg()); |
| 7453 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7454 | // copy0MBB: |
| 7455 | // %FalseValue = ... |
| 7456 | // # fallthrough to sinkMBB |
| 7457 | BB = copy0MBB; |
| 7458 | |
| 7459 | // Update machine-CFG edges |
| 7460 | BB->addSuccessor(sinkMBB); |
| 7461 | |
| 7462 | // sinkMBB: |
| 7463 | // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] |
| 7464 | // ... |
| 7465 | BB = sinkMBB; |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 7466 | BuildMI(*BB, BB->begin(), dl, |
| 7467 | TII->get(ARM::PHI), MI->getOperand(0).getReg()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7468 | .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB) |
| 7469 | .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB); |
| 7470 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 7471 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7472 | return BB; |
| 7473 | } |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 7474 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 7475 | case ARM::BCCi64: |
| 7476 | case ARM::BCCZi64: { |
Bob Wilson | 3c90469 | 2010-12-23 22:45:49 +0000 | [diff] [blame] | 7477 | // If there is an unconditional branch to the other successor, remove it. |
| 7478 | BB->erase(llvm::next(MachineBasicBlock::iterator(MI)), BB->end()); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 7479 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 7480 | // Compare both parts that make up the double comparison separately for |
| 7481 | // equality. |
| 7482 | bool RHSisZero = MI->getOpcode() == ARM::BCCZi64; |
| 7483 | |
| 7484 | unsigned LHS1 = MI->getOperand(1).getReg(); |
| 7485 | unsigned LHS2 = MI->getOperand(2).getReg(); |
| 7486 | if (RHSisZero) { |
| 7487 | AddDefaultPred(BuildMI(BB, dl, |
| 7488 | TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 7489 | .addReg(LHS1).addImm(0)); |
| 7490 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 7491 | .addReg(LHS2).addImm(0) |
| 7492 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 7493 | } else { |
| 7494 | unsigned RHS1 = MI->getOperand(3).getReg(); |
| 7495 | unsigned RHS2 = MI->getOperand(4).getReg(); |
| 7496 | AddDefaultPred(BuildMI(BB, dl, |
| 7497 | TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 7498 | .addReg(LHS1).addReg(RHS1)); |
| 7499 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 7500 | .addReg(LHS2).addReg(RHS2) |
| 7501 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 7502 | } |
| 7503 | |
| 7504 | MachineBasicBlock *destMBB = MI->getOperand(RHSisZero ? 3 : 5).getMBB(); |
| 7505 | MachineBasicBlock *exitMBB = OtherSucc(BB, destMBB); |
| 7506 | if (MI->getOperand(0).getImm() == ARMCC::NE) |
| 7507 | std::swap(destMBB, exitMBB); |
| 7508 | |
| 7509 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 7510 | .addMBB(destMBB).addImm(ARMCC::EQ).addReg(ARM::CPSR); |
Owen Anderson | 51f6a7a | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 7511 | if (isThumb2) |
| 7512 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::t2B)).addMBB(exitMBB)); |
| 7513 | else |
| 7514 | BuildMI(BB, dl, TII->get(ARM::B)) .addMBB(exitMBB); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 7515 | |
| 7516 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
| 7517 | return BB; |
| 7518 | } |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7519 | |
Bill Wendling | 5bc8528 | 2011-10-17 20:37:20 +0000 | [diff] [blame] | 7520 | case ARM::Int_eh_sjlj_setjmp: |
| 7521 | case ARM::Int_eh_sjlj_setjmp_nofp: |
| 7522 | case ARM::tInt_eh_sjlj_setjmp: |
| 7523 | case ARM::t2Int_eh_sjlj_setjmp: |
| 7524 | case ARM::t2Int_eh_sjlj_setjmp_nofp: |
| 7525 | EmitSjLjDispatchBlock(MI, BB); |
| 7526 | return BB; |
| 7527 | |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7528 | case ARM::ABS: |
| 7529 | case ARM::t2ABS: { |
| 7530 | // To insert an ABS instruction, we have to insert the |
| 7531 | // diamond control-flow pattern. The incoming instruction knows the |
| 7532 | // source vreg to test against 0, the destination vreg to set, |
| 7533 | // the condition code register to branch on, the |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 7534 | // true/false values to select between, and a branch opcode to use. |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7535 | // It transforms |
| 7536 | // V1 = ABS V0 |
| 7537 | // into |
| 7538 | // V2 = MOVS V0 |
| 7539 | // BCC (branch to SinkBB if V0 >= 0) |
| 7540 | // RSBBB: V3 = RSBri V2, 0 (compute ABS if V2 < 0) |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 7541 | // SinkBB: V1 = PHI(V2, V3) |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7542 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 7543 | MachineFunction::iterator BBI = BB; |
| 7544 | ++BBI; |
| 7545 | MachineFunction *Fn = BB->getParent(); |
| 7546 | MachineBasicBlock *RSBBB = Fn->CreateMachineBasicBlock(LLVM_BB); |
| 7547 | MachineBasicBlock *SinkBB = Fn->CreateMachineBasicBlock(LLVM_BB); |
| 7548 | Fn->insert(BBI, RSBBB); |
| 7549 | Fn->insert(BBI, SinkBB); |
| 7550 | |
| 7551 | unsigned int ABSSrcReg = MI->getOperand(1).getReg(); |
| 7552 | unsigned int ABSDstReg = MI->getOperand(0).getReg(); |
| 7553 | bool isThumb2 = Subtarget->isThumb2(); |
| 7554 | MachineRegisterInfo &MRI = Fn->getRegInfo(); |
| 7555 | // In Thumb mode S must not be specified if source register is the SP or |
| 7556 | // PC and if destination register is the SP, so restrict register class |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 7557 | unsigned NewRsbDstReg = MRI.createVirtualRegister(isThumb2 ? |
| 7558 | (const TargetRegisterClass*)&ARM::rGPRRegClass : |
| 7559 | (const TargetRegisterClass*)&ARM::GPRRegClass); |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7560 | |
| 7561 | // Transfer the remainder of BB and its successor edges to sinkMBB. |
| 7562 | SinkBB->splice(SinkBB->begin(), BB, |
| 7563 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 7564 | BB->end()); |
| 7565 | SinkBB->transferSuccessorsAndUpdatePHIs(BB); |
| 7566 | |
| 7567 | BB->addSuccessor(RSBBB); |
| 7568 | BB->addSuccessor(SinkBB); |
| 7569 | |
| 7570 | // fall through to SinkMBB |
| 7571 | RSBBB->addSuccessor(SinkBB); |
| 7572 | |
Manman Ren | 307473d | 2012-06-15 21:32:12 +0000 | [diff] [blame] | 7573 | // insert a cmp at the end of BB |
Andrew Trick | 49b446f | 2012-07-18 18:34:24 +0000 | [diff] [blame] | 7574 | AddDefaultPred(BuildMI(BB, dl, |
Manman Ren | 307473d | 2012-06-15 21:32:12 +0000 | [diff] [blame] | 7575 | TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 7576 | .addReg(ABSSrcReg).addImm(0)); |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7577 | |
| 7578 | // insert a bcc with opposite CC to ARMCC::MI at the end of BB |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 7579 | BuildMI(BB, dl, |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7580 | TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)).addMBB(SinkBB) |
| 7581 | .addImm(ARMCC::getOppositeCondition(ARMCC::MI)).addReg(ARM::CPSR); |
| 7582 | |
| 7583 | // insert rsbri in RSBBB |
| 7584 | // Note: BCC and rsbri will be converted into predicated rsbmi |
| 7585 | // by if-conversion pass |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 7586 | BuildMI(*RSBBB, RSBBB->begin(), dl, |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7587 | TII->get(isThumb2 ? ARM::t2RSBri : ARM::RSBri), NewRsbDstReg) |
Manman Ren | 307473d | 2012-06-15 21:32:12 +0000 | [diff] [blame] | 7588 | .addReg(ABSSrcReg, RegState::Kill) |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7589 | .addImm(0).addImm((unsigned)ARMCC::AL).addReg(0).addReg(0); |
| 7590 | |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 7591 | // insert PHI in SinkBB, |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7592 | // reuse ABSDstReg to not change uses of ABS instruction |
| 7593 | BuildMI(*SinkBB, SinkBB->begin(), dl, |
| 7594 | TII->get(ARM::PHI), ABSDstReg) |
| 7595 | .addReg(NewRsbDstReg).addMBB(RSBBB) |
Manman Ren | 307473d | 2012-06-15 21:32:12 +0000 | [diff] [blame] | 7596 | .addReg(ABSSrcReg).addMBB(BB); |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7597 | |
| 7598 | // remove ABS instruction |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 7599 | MI->eraseFromParent(); |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7600 | |
| 7601 | // return last added BB |
| 7602 | return SinkBB; |
| 7603 | } |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7604 | case ARM::COPY_STRUCT_BYVAL_I32: |
Manman Ren | 763a75d | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 7605 | ++NumLoopByVals; |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7606 | return EmitStructByval(MI, BB); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7607 | } |
| 7608 | } |
| 7609 | |
Evan Cheng | 37fefc2 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 7610 | void ARMTargetLowering::AdjustInstrPostInstrSelection(MachineInstr *MI, |
| 7611 | SDNode *Node) const { |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 7612 | if (!MI->hasPostISelHook()) { |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7613 | assert(!convertAddSubFlagsOpcode(MI->getOpcode()) && |
| 7614 | "Pseudo flag-setting opcodes must be marked with 'hasPostISelHook'"); |
| 7615 | return; |
| 7616 | } |
| 7617 | |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 7618 | const MCInstrDesc *MCID = &MI->getDesc(); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7619 | // Adjust potentially 's' setting instructions after isel, i.e. ADC, SBC, RSB, |
| 7620 | // RSC. Coming out of isel, they have an implicit CPSR def, but the optional |
| 7621 | // operand is still set to noreg. If needed, set the optional operand's |
| 7622 | // register to CPSR, and remove the redundant implicit def. |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7623 | // |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 7624 | // e.g. ADCS (..., CPSR<imp-def>) -> ADC (... opt:CPSR<def>). |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7625 | |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7626 | // Rename pseudo opcodes. |
| 7627 | unsigned NewOpc = convertAddSubFlagsOpcode(MI->getOpcode()); |
| 7628 | if (NewOpc) { |
| 7629 | const ARMBaseInstrInfo *TII = |
| 7630 | static_cast<const ARMBaseInstrInfo*>(getTargetMachine().getInstrInfo()); |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 7631 | MCID = &TII->get(NewOpc); |
| 7632 | |
| 7633 | assert(MCID->getNumOperands() == MI->getDesc().getNumOperands() + 1 && |
| 7634 | "converted opcode should be the same except for cc_out"); |
| 7635 | |
| 7636 | MI->setDesc(*MCID); |
| 7637 | |
| 7638 | // Add the optional cc_out operand |
| 7639 | MI->addOperand(MachineOperand::CreateReg(0, /*isDef=*/true)); |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7640 | } |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 7641 | unsigned ccOutIdx = MCID->getNumOperands() - 1; |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7642 | |
| 7643 | // Any ARM instruction that sets the 's' bit should specify an optional |
| 7644 | // "cc_out" operand in the last operand position. |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 7645 | if (!MI->hasOptionalDef() || !MCID->OpInfo[ccOutIdx].isOptionalDef()) { |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7646 | assert(!NewOpc && "Optional cc_out operand required"); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7647 | return; |
| 7648 | } |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7649 | // Look for an implicit def of CPSR added by MachineInstr ctor. Remove it |
| 7650 | // since we already have an optional CPSR def. |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7651 | bool definesCPSR = false; |
| 7652 | bool deadCPSR = false; |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 7653 | for (unsigned i = MCID->getNumOperands(), e = MI->getNumOperands(); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7654 | i != e; ++i) { |
| 7655 | const MachineOperand &MO = MI->getOperand(i); |
| 7656 | if (MO.isReg() && MO.isDef() && MO.getReg() == ARM::CPSR) { |
| 7657 | definesCPSR = true; |
| 7658 | if (MO.isDead()) |
| 7659 | deadCPSR = true; |
| 7660 | MI->RemoveOperand(i); |
| 7661 | break; |
Evan Cheng | 37fefc2 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 7662 | } |
| 7663 | } |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7664 | if (!definesCPSR) { |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7665 | assert(!NewOpc && "Optional cc_out operand required"); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7666 | return; |
| 7667 | } |
| 7668 | assert(deadCPSR == !Node->hasAnyUseOfValue(1) && "inconsistent dead flag"); |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7669 | if (deadCPSR) { |
| 7670 | assert(!MI->getOperand(ccOutIdx).getReg() && |
| 7671 | "expect uninitialized optional cc_out operand"); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7672 | return; |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7673 | } |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7674 | |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7675 | // If this instruction was defined with an optional CPSR def and its dag node |
| 7676 | // had a live implicit CPSR def, then activate the optional CPSR def. |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7677 | MachineOperand &MO = MI->getOperand(ccOutIdx); |
| 7678 | MO.setReg(ARM::CPSR); |
| 7679 | MO.setIsDef(true); |
Evan Cheng | 37fefc2 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 7680 | } |
| 7681 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7682 | //===----------------------------------------------------------------------===// |
| 7683 | // ARM Optimization Hooks |
| 7684 | //===----------------------------------------------------------------------===// |
| 7685 | |
Jakob Stoklund Olesen | 1f1ab3e | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7686 | // Helper function that checks if N is a null or all ones constant. |
| 7687 | static inline bool isZeroOrAllOnes(SDValue N, bool AllOnes) { |
| 7688 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(N); |
| 7689 | if (!C) |
| 7690 | return false; |
| 7691 | return AllOnes ? C->isAllOnesValue() : C->isNullValue(); |
| 7692 | } |
| 7693 | |
Jakob Stoklund Olesen | 864c870 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7694 | // Return true if N is conditionally 0 or all ones. |
| 7695 | // Detects these expressions where cc is an i1 value: |
| 7696 | // |
| 7697 | // (select cc 0, y) [AllOnes=0] |
| 7698 | // (select cc y, 0) [AllOnes=0] |
| 7699 | // (zext cc) [AllOnes=0] |
| 7700 | // (sext cc) [AllOnes=0/1] |
| 7701 | // (select cc -1, y) [AllOnes=1] |
| 7702 | // (select cc y, -1) [AllOnes=1] |
| 7703 | // |
| 7704 | // Invert is set when N is the null/all ones constant when CC is false. |
| 7705 | // OtherOp is set to the alternative value of N. |
| 7706 | static bool isConditionalZeroOrAllOnes(SDNode *N, bool AllOnes, |
| 7707 | SDValue &CC, bool &Invert, |
| 7708 | SDValue &OtherOp, |
| 7709 | SelectionDAG &DAG) { |
| 7710 | switch (N->getOpcode()) { |
| 7711 | default: return false; |
| 7712 | case ISD::SELECT: { |
| 7713 | CC = N->getOperand(0); |
| 7714 | SDValue N1 = N->getOperand(1); |
| 7715 | SDValue N2 = N->getOperand(2); |
| 7716 | if (isZeroOrAllOnes(N1, AllOnes)) { |
| 7717 | Invert = false; |
| 7718 | OtherOp = N2; |
| 7719 | return true; |
| 7720 | } |
| 7721 | if (isZeroOrAllOnes(N2, AllOnes)) { |
| 7722 | Invert = true; |
| 7723 | OtherOp = N1; |
| 7724 | return true; |
| 7725 | } |
| 7726 | return false; |
| 7727 | } |
| 7728 | case ISD::ZERO_EXTEND: |
| 7729 | // (zext cc) can never be the all ones value. |
| 7730 | if (AllOnes) |
| 7731 | return false; |
| 7732 | // Fall through. |
| 7733 | case ISD::SIGN_EXTEND: { |
| 7734 | EVT VT = N->getValueType(0); |
| 7735 | CC = N->getOperand(0); |
| 7736 | if (CC.getValueType() != MVT::i1) |
| 7737 | return false; |
| 7738 | Invert = !AllOnes; |
| 7739 | if (AllOnes) |
| 7740 | // When looking for an AllOnes constant, N is an sext, and the 'other' |
| 7741 | // value is 0. |
| 7742 | OtherOp = DAG.getConstant(0, VT); |
| 7743 | else if (N->getOpcode() == ISD::ZERO_EXTEND) |
| 7744 | // When looking for a 0 constant, N can be zext or sext. |
| 7745 | OtherOp = DAG.getConstant(1, VT); |
| 7746 | else |
| 7747 | OtherOp = DAG.getConstant(APInt::getAllOnesValue(VT.getSizeInBits()), VT); |
| 7748 | return true; |
| 7749 | } |
| 7750 | } |
| 7751 | } |
| 7752 | |
Jakob Stoklund Olesen | 1f1ab3e | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7753 | // Combine a constant select operand into its use: |
| 7754 | // |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7755 | // (add (select cc, 0, c), x) -> (select cc, x, (add, x, c)) |
| 7756 | // (sub x, (select cc, 0, c)) -> (select cc, x, (sub, x, c)) |
| 7757 | // (and (select cc, -1, c), x) -> (select cc, x, (and, x, c)) [AllOnes=1] |
| 7758 | // (or (select cc, 0, c), x) -> (select cc, x, (or, x, c)) |
| 7759 | // (xor (select cc, 0, c), x) -> (select cc, x, (xor, x, c)) |
Jakob Stoklund Olesen | 1f1ab3e | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7760 | // |
| 7761 | // The transform is rejected if the select doesn't have a constant operand that |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7762 | // is null, or all ones when AllOnes is set. |
Jakob Stoklund Olesen | 1f1ab3e | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7763 | // |
Jakob Stoklund Olesen | 864c870 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7764 | // Also recognize sext/zext from i1: |
| 7765 | // |
| 7766 | // (add (zext cc), x) -> (select cc (add x, 1), x) |
| 7767 | // (add (sext cc), x) -> (select cc (add x, -1), x) |
| 7768 | // |
| 7769 | // These transformations eventually create predicated instructions. |
| 7770 | // |
Jakob Stoklund Olesen | 1f1ab3e | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7771 | // @param N The node to transform. |
| 7772 | // @param Slct The N operand that is a select. |
| 7773 | // @param OtherOp The other N operand (x above). |
| 7774 | // @param DCI Context. |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7775 | // @param AllOnes Require the select constant to be all ones instead of null. |
Jakob Stoklund Olesen | 1f1ab3e | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7776 | // @returns The new node, or SDValue() on failure. |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7777 | static |
| 7778 | SDValue combineSelectAndUse(SDNode *N, SDValue Slct, SDValue OtherOp, |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7779 | TargetLowering::DAGCombinerInfo &DCI, |
| 7780 | bool AllOnes = false) { |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7781 | SelectionDAG &DAG = DCI.DAG; |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7782 | EVT VT = N->getValueType(0); |
Jakob Stoklund Olesen | 864c870 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7783 | SDValue NonConstantVal; |
| 7784 | SDValue CCOp; |
| 7785 | bool SwapSelectOps; |
| 7786 | if (!isConditionalZeroOrAllOnes(Slct.getNode(), AllOnes, CCOp, SwapSelectOps, |
| 7787 | NonConstantVal, DAG)) |
Jakob Stoklund Olesen | 1f1ab3e | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7788 | return SDValue(); |
| 7789 | |
Jakob Stoklund Olesen | 864c870 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7790 | // Slct is now know to be the desired identity constant when CC is true. |
| 7791 | SDValue TrueVal = OtherOp; |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 7792 | SDValue FalseVal = DAG.getNode(N->getOpcode(), SDLoc(N), VT, |
Jakob Stoklund Olesen | 864c870 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7793 | OtherOp, NonConstantVal); |
| 7794 | // Unless SwapSelectOps says CC should be false. |
| 7795 | if (SwapSelectOps) |
| 7796 | std::swap(TrueVal, FalseVal); |
| 7797 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 7798 | return DAG.getNode(ISD::SELECT, SDLoc(N), VT, |
Jakob Stoklund Olesen | 864c870 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7799 | CCOp, TrueVal, FalseVal); |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7800 | } |
| 7801 | |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7802 | // Attempt combineSelectAndUse on each operand of a commutative operator N. |
| 7803 | static |
| 7804 | SDValue combineSelectAndUseCommutative(SDNode *N, bool AllOnes, |
| 7805 | TargetLowering::DAGCombinerInfo &DCI) { |
| 7806 | SDValue N0 = N->getOperand(0); |
| 7807 | SDValue N1 = N->getOperand(1); |
Jakob Stoklund Olesen | 864c870 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7808 | if (N0.getNode()->hasOneUse()) { |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7809 | SDValue Result = combineSelectAndUse(N, N0, N1, DCI, AllOnes); |
| 7810 | if (Result.getNode()) |
| 7811 | return Result; |
| 7812 | } |
Jakob Stoklund Olesen | 864c870 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7813 | if (N1.getNode()->hasOneUse()) { |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7814 | SDValue Result = combineSelectAndUse(N, N1, N0, DCI, AllOnes); |
| 7815 | if (Result.getNode()) |
| 7816 | return Result; |
| 7817 | } |
| 7818 | return SDValue(); |
| 7819 | } |
| 7820 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7821 | // AddCombineToVPADDL- For pair-wise add on neon, use the vpaddl instruction |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7822 | // (only after legalization). |
| 7823 | static SDValue AddCombineToVPADDL(SDNode *N, SDValue N0, SDValue N1, |
| 7824 | TargetLowering::DAGCombinerInfo &DCI, |
| 7825 | const ARMSubtarget *Subtarget) { |
| 7826 | |
| 7827 | // Only perform optimization if after legalize, and if NEON is available. We |
| 7828 | // also expected both operands to be BUILD_VECTORs. |
| 7829 | if (DCI.isBeforeLegalize() || !Subtarget->hasNEON() |
| 7830 | || N0.getOpcode() != ISD::BUILD_VECTOR |
| 7831 | || N1.getOpcode() != ISD::BUILD_VECTOR) |
| 7832 | return SDValue(); |
| 7833 | |
| 7834 | // Check output type since VPADDL operand elements can only be 8, 16, or 32. |
| 7835 | EVT VT = N->getValueType(0); |
| 7836 | if (!VT.isInteger() || VT.getVectorElementType() == MVT::i64) |
| 7837 | return SDValue(); |
| 7838 | |
| 7839 | // Check that the vector operands are of the right form. |
| 7840 | // N0 and N1 are BUILD_VECTOR nodes with N number of EXTRACT_VECTOR |
| 7841 | // operands, where N is the size of the formed vector. |
| 7842 | // Each EXTRACT_VECTOR should have the same input vector and odd or even |
| 7843 | // index such that we have a pair wise add pattern. |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7844 | |
| 7845 | // Grab the vector that all EXTRACT_VECTOR nodes should be referencing. |
Bob Wilson | 7a10ab7 | 2011-06-15 06:04:34 +0000 | [diff] [blame] | 7846 | if (N0->getOperand(0)->getOpcode() != ISD::EXTRACT_VECTOR_ELT) |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7847 | return SDValue(); |
Bob Wilson | 7a10ab7 | 2011-06-15 06:04:34 +0000 | [diff] [blame] | 7848 | SDValue Vec = N0->getOperand(0)->getOperand(0); |
| 7849 | SDNode *V = Vec.getNode(); |
| 7850 | unsigned nextIndex = 0; |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7851 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7852 | // For each operands to the ADD which are BUILD_VECTORs, |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7853 | // check to see if each of their operands are an EXTRACT_VECTOR with |
| 7854 | // the same vector and appropriate index. |
| 7855 | for (unsigned i = 0, e = N0->getNumOperands(); i != e; ++i) { |
| 7856 | if (N0->getOperand(i)->getOpcode() == ISD::EXTRACT_VECTOR_ELT |
| 7857 | && N1->getOperand(i)->getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7858 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7859 | SDValue ExtVec0 = N0->getOperand(i); |
| 7860 | SDValue ExtVec1 = N1->getOperand(i); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7861 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7862 | // First operand is the vector, verify its the same. |
| 7863 | if (V != ExtVec0->getOperand(0).getNode() || |
| 7864 | V != ExtVec1->getOperand(0).getNode()) |
| 7865 | return SDValue(); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7866 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7867 | // Second is the constant, verify its correct. |
| 7868 | ConstantSDNode *C0 = dyn_cast<ConstantSDNode>(ExtVec0->getOperand(1)); |
| 7869 | ConstantSDNode *C1 = dyn_cast<ConstantSDNode>(ExtVec1->getOperand(1)); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7870 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7871 | // For the constant, we want to see all the even or all the odd. |
| 7872 | if (!C0 || !C1 || C0->getZExtValue() != nextIndex |
| 7873 | || C1->getZExtValue() != nextIndex+1) |
| 7874 | return SDValue(); |
| 7875 | |
| 7876 | // Increment index. |
| 7877 | nextIndex+=2; |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7878 | } else |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7879 | return SDValue(); |
| 7880 | } |
| 7881 | |
| 7882 | // Create VPADDL node. |
| 7883 | SelectionDAG &DAG = DCI.DAG; |
| 7884 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7885 | |
| 7886 | // Build operand list. |
| 7887 | SmallVector<SDValue, 8> Ops; |
| 7888 | Ops.push_back(DAG.getConstant(Intrinsic::arm_neon_vpaddls, |
| 7889 | TLI.getPointerTy())); |
| 7890 | |
| 7891 | // Input is the vector. |
| 7892 | Ops.push_back(Vec); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7893 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7894 | // Get widened type and narrowed type. |
| 7895 | MVT widenType; |
| 7896 | unsigned numElem = VT.getVectorNumElements(); |
| 7897 | switch (VT.getVectorElementType().getSimpleVT().SimpleTy) { |
| 7898 | case MVT::i8: widenType = MVT::getVectorVT(MVT::i16, numElem); break; |
| 7899 | case MVT::i16: widenType = MVT::getVectorVT(MVT::i32, numElem); break; |
| 7900 | case MVT::i32: widenType = MVT::getVectorVT(MVT::i64, numElem); break; |
| 7901 | default: |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 7902 | llvm_unreachable("Invalid vector element type for padd optimization."); |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7903 | } |
| 7904 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 7905 | SDValue tmp = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, SDLoc(N), |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7906 | widenType, &Ops[0], Ops.size()); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 7907 | return DAG.getNode(ISD::TRUNCATE, SDLoc(N), VT, tmp); |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7908 | } |
| 7909 | |
Arnold Schwaighofer | 67514e9 | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 7910 | static SDValue findMUL_LOHI(SDValue V) { |
| 7911 | if (V->getOpcode() == ISD::UMUL_LOHI || |
| 7912 | V->getOpcode() == ISD::SMUL_LOHI) |
| 7913 | return V; |
| 7914 | return SDValue(); |
| 7915 | } |
| 7916 | |
| 7917 | static SDValue AddCombineTo64bitMLAL(SDNode *AddcNode, |
| 7918 | TargetLowering::DAGCombinerInfo &DCI, |
| 7919 | const ARMSubtarget *Subtarget) { |
| 7920 | |
| 7921 | if (Subtarget->isThumb1Only()) return SDValue(); |
| 7922 | |
| 7923 | // Only perform the checks after legalize when the pattern is available. |
| 7924 | if (DCI.isBeforeLegalize()) return SDValue(); |
| 7925 | |
| 7926 | // Look for multiply add opportunities. |
| 7927 | // The pattern is a ISD::UMUL_LOHI followed by two add nodes, where |
| 7928 | // each add nodes consumes a value from ISD::UMUL_LOHI and there is |
| 7929 | // a glue link from the first add to the second add. |
| 7930 | // If we find this pattern, we can replace the U/SMUL_LOHI, ADDC, and ADDE by |
| 7931 | // a S/UMLAL instruction. |
| 7932 | // loAdd UMUL_LOHI |
| 7933 | // \ / :lo \ :hi |
| 7934 | // \ / \ [no multiline comment] |
| 7935 | // ADDC | hiAdd |
| 7936 | // \ :glue / / |
| 7937 | // \ / / |
| 7938 | // ADDE |
| 7939 | // |
| 7940 | assert(AddcNode->getOpcode() == ISD::ADDC && "Expect an ADDC"); |
| 7941 | SDValue AddcOp0 = AddcNode->getOperand(0); |
| 7942 | SDValue AddcOp1 = AddcNode->getOperand(1); |
| 7943 | |
| 7944 | // Check if the two operands are from the same mul_lohi node. |
| 7945 | if (AddcOp0.getNode() == AddcOp1.getNode()) |
| 7946 | return SDValue(); |
| 7947 | |
| 7948 | assert(AddcNode->getNumValues() == 2 && |
| 7949 | AddcNode->getValueType(0) == MVT::i32 && |
| 7950 | AddcNode->getValueType(1) == MVT::Glue && |
| 7951 | "Expect ADDC with two result values: i32, glue"); |
| 7952 | |
| 7953 | // Check that the ADDC adds the low result of the S/UMUL_LOHI. |
| 7954 | if (AddcOp0->getOpcode() != ISD::UMUL_LOHI && |
| 7955 | AddcOp0->getOpcode() != ISD::SMUL_LOHI && |
| 7956 | AddcOp1->getOpcode() != ISD::UMUL_LOHI && |
| 7957 | AddcOp1->getOpcode() != ISD::SMUL_LOHI) |
| 7958 | return SDValue(); |
| 7959 | |
| 7960 | // Look for the glued ADDE. |
| 7961 | SDNode* AddeNode = AddcNode->getGluedUser(); |
| 7962 | if (AddeNode == NULL) |
| 7963 | return SDValue(); |
| 7964 | |
| 7965 | // Make sure it is really an ADDE. |
| 7966 | if (AddeNode->getOpcode() != ISD::ADDE) |
| 7967 | return SDValue(); |
| 7968 | |
| 7969 | assert(AddeNode->getNumOperands() == 3 && |
| 7970 | AddeNode->getOperand(2).getValueType() == MVT::Glue && |
| 7971 | "ADDE node has the wrong inputs"); |
| 7972 | |
| 7973 | // Check for the triangle shape. |
| 7974 | SDValue AddeOp0 = AddeNode->getOperand(0); |
| 7975 | SDValue AddeOp1 = AddeNode->getOperand(1); |
| 7976 | |
| 7977 | // Make sure that the ADDE operands are not coming from the same node. |
| 7978 | if (AddeOp0.getNode() == AddeOp1.getNode()) |
| 7979 | return SDValue(); |
| 7980 | |
| 7981 | // Find the MUL_LOHI node walking up ADDE's operands. |
| 7982 | bool IsLeftOperandMUL = false; |
| 7983 | SDValue MULOp = findMUL_LOHI(AddeOp0); |
| 7984 | if (MULOp == SDValue()) |
| 7985 | MULOp = findMUL_LOHI(AddeOp1); |
| 7986 | else |
| 7987 | IsLeftOperandMUL = true; |
| 7988 | if (MULOp == SDValue()) |
| 7989 | return SDValue(); |
| 7990 | |
| 7991 | // Figure out the right opcode. |
| 7992 | unsigned Opc = MULOp->getOpcode(); |
| 7993 | unsigned FinalOpc = (Opc == ISD::SMUL_LOHI) ? ARMISD::SMLAL : ARMISD::UMLAL; |
| 7994 | |
| 7995 | // Figure out the high and low input values to the MLAL node. |
| 7996 | SDValue* HiMul = &MULOp; |
| 7997 | SDValue* HiAdd = NULL; |
| 7998 | SDValue* LoMul = NULL; |
| 7999 | SDValue* LowAdd = NULL; |
| 8000 | |
| 8001 | if (IsLeftOperandMUL) |
| 8002 | HiAdd = &AddeOp1; |
| 8003 | else |
| 8004 | HiAdd = &AddeOp0; |
| 8005 | |
| 8006 | |
| 8007 | if (AddcOp0->getOpcode() == Opc) { |
| 8008 | LoMul = &AddcOp0; |
| 8009 | LowAdd = &AddcOp1; |
| 8010 | } |
| 8011 | if (AddcOp1->getOpcode() == Opc) { |
| 8012 | LoMul = &AddcOp1; |
| 8013 | LowAdd = &AddcOp0; |
| 8014 | } |
| 8015 | |
| 8016 | if (LoMul == NULL) |
| 8017 | return SDValue(); |
| 8018 | |
| 8019 | if (LoMul->getNode() != HiMul->getNode()) |
| 8020 | return SDValue(); |
| 8021 | |
| 8022 | // Create the merged node. |
| 8023 | SelectionDAG &DAG = DCI.DAG; |
| 8024 | |
| 8025 | // Build operand list. |
| 8026 | SmallVector<SDValue, 8> Ops; |
| 8027 | Ops.push_back(LoMul->getOperand(0)); |
| 8028 | Ops.push_back(LoMul->getOperand(1)); |
| 8029 | Ops.push_back(*LowAdd); |
| 8030 | Ops.push_back(*HiAdd); |
| 8031 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 8032 | SDValue MLALNode = DAG.getNode(FinalOpc, SDLoc(AddcNode), |
Arnold Schwaighofer | 67514e9 | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8033 | DAG.getVTList(MVT::i32, MVT::i32), |
| 8034 | &Ops[0], Ops.size()); |
| 8035 | |
| 8036 | // Replace the ADDs' nodes uses by the MLA node's values. |
| 8037 | SDValue HiMLALResult(MLALNode.getNode(), 1); |
| 8038 | DAG.ReplaceAllUsesOfValueWith(SDValue(AddeNode, 0), HiMLALResult); |
| 8039 | |
| 8040 | SDValue LoMLALResult(MLALNode.getNode(), 0); |
| 8041 | DAG.ReplaceAllUsesOfValueWith(SDValue(AddcNode, 0), LoMLALResult); |
| 8042 | |
| 8043 | // Return original node to notify the driver to stop replacing. |
| 8044 | SDValue resNode(AddcNode, 0); |
| 8045 | return resNode; |
| 8046 | } |
| 8047 | |
| 8048 | /// PerformADDCCombine - Target-specific dag combine transform from |
| 8049 | /// ISD::ADDC, ISD::ADDE, and ISD::MUL_LOHI to MLAL. |
| 8050 | static SDValue PerformADDCCombine(SDNode *N, |
| 8051 | TargetLowering::DAGCombinerInfo &DCI, |
| 8052 | const ARMSubtarget *Subtarget) { |
| 8053 | |
| 8054 | return AddCombineTo64bitMLAL(N, DCI, Subtarget); |
| 8055 | |
| 8056 | } |
| 8057 | |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 8058 | /// PerformADDCombineWithOperands - Try DAG combinations for an ADD with |
| 8059 | /// operands N0 and N1. This is a helper for PerformADDCombine that is |
| 8060 | /// called with the default operands, and if that fails, with commuted |
| 8061 | /// operands. |
| 8062 | static SDValue PerformADDCombineWithOperands(SDNode *N, SDValue N0, SDValue N1, |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8063 | TargetLowering::DAGCombinerInfo &DCI, |
| 8064 | const ARMSubtarget *Subtarget){ |
| 8065 | |
| 8066 | // Attempt to create vpaddl for this add. |
| 8067 | SDValue Result = AddCombineToVPADDL(N, N0, N1, DCI, Subtarget); |
| 8068 | if (Result.getNode()) |
| 8069 | return Result; |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8070 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8071 | // fold (add (select cc, 0, c), x) -> (select cc, x, (add, x, c)) |
Jakob Stoklund Olesen | 864c870 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8072 | if (N0.getNode()->hasOneUse()) { |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8073 | SDValue Result = combineSelectAndUse(N, N0, N1, DCI); |
| 8074 | if (Result.getNode()) return Result; |
| 8075 | } |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8076 | return SDValue(); |
| 8077 | } |
| 8078 | |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 8079 | /// PerformADDCombine - Target-specific dag combine xforms for ISD::ADD. |
| 8080 | /// |
| 8081 | static SDValue PerformADDCombine(SDNode *N, |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8082 | TargetLowering::DAGCombinerInfo &DCI, |
| 8083 | const ARMSubtarget *Subtarget) { |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 8084 | SDValue N0 = N->getOperand(0); |
| 8085 | SDValue N1 = N->getOperand(1); |
| 8086 | |
| 8087 | // First try with the default operand order. |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8088 | SDValue Result = PerformADDCombineWithOperands(N, N0, N1, DCI, Subtarget); |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 8089 | if (Result.getNode()) |
| 8090 | return Result; |
| 8091 | |
| 8092 | // If that didn't work, try again with the operands commuted. |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8093 | return PerformADDCombineWithOperands(N, N1, N0, DCI, Subtarget); |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 8094 | } |
| 8095 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8096 | /// PerformSUBCombine - Target-specific dag combine xforms for ISD::SUB. |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 8097 | /// |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8098 | static SDValue PerformSUBCombine(SDNode *N, |
| 8099 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 8100 | SDValue N0 = N->getOperand(0); |
| 8101 | SDValue N1 = N->getOperand(1); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8102 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8103 | // fold (sub x, (select cc, 0, c)) -> (select cc, x, (sub, x, c)) |
Jakob Stoklund Olesen | 864c870 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8104 | if (N1.getNode()->hasOneUse()) { |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8105 | SDValue Result = combineSelectAndUse(N, N1, N0, DCI); |
| 8106 | if (Result.getNode()) return Result; |
| 8107 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8108 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8109 | return SDValue(); |
| 8110 | } |
| 8111 | |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 8112 | /// PerformVMULCombine |
| 8113 | /// Distribute (A + B) * C to (A * C) + (B * C) to take advantage of the |
| 8114 | /// special multiplier accumulator forwarding. |
| 8115 | /// vmul d3, d0, d2 |
| 8116 | /// vmla d3, d1, d2 |
| 8117 | /// is faster than |
| 8118 | /// vadd d3, d0, d1 |
| 8119 | /// vmul d3, d3, d2 |
| 8120 | static SDValue PerformVMULCombine(SDNode *N, |
| 8121 | TargetLowering::DAGCombinerInfo &DCI, |
| 8122 | const ARMSubtarget *Subtarget) { |
| 8123 | if (!Subtarget->hasVMLxForwarding()) |
| 8124 | return SDValue(); |
| 8125 | |
| 8126 | SelectionDAG &DAG = DCI.DAG; |
| 8127 | SDValue N0 = N->getOperand(0); |
| 8128 | SDValue N1 = N->getOperand(1); |
| 8129 | unsigned Opcode = N0.getOpcode(); |
| 8130 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
| 8131 | Opcode != ISD::FADD && Opcode != ISD::FSUB) { |
Chad Rosier | 689edc8 | 2011-06-16 01:21:54 +0000 | [diff] [blame] | 8132 | Opcode = N1.getOpcode(); |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 8133 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
| 8134 | Opcode != ISD::FADD && Opcode != ISD::FSUB) |
| 8135 | return SDValue(); |
| 8136 | std::swap(N0, N1); |
| 8137 | } |
| 8138 | |
| 8139 | EVT VT = N->getValueType(0); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 8140 | SDLoc DL(N); |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 8141 | SDValue N00 = N0->getOperand(0); |
| 8142 | SDValue N01 = N0->getOperand(1); |
| 8143 | return DAG.getNode(Opcode, DL, VT, |
| 8144 | DAG.getNode(ISD::MUL, DL, VT, N00, N1), |
| 8145 | DAG.getNode(ISD::MUL, DL, VT, N01, N1)); |
| 8146 | } |
| 8147 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8148 | static SDValue PerformMULCombine(SDNode *N, |
| 8149 | TargetLowering::DAGCombinerInfo &DCI, |
| 8150 | const ARMSubtarget *Subtarget) { |
| 8151 | SelectionDAG &DAG = DCI.DAG; |
| 8152 | |
| 8153 | if (Subtarget->isThumb1Only()) |
| 8154 | return SDValue(); |
| 8155 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8156 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 8157 | return SDValue(); |
| 8158 | |
| 8159 | EVT VT = N->getValueType(0); |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 8160 | if (VT.is64BitVector() || VT.is128BitVector()) |
| 8161 | return PerformVMULCombine(N, DCI, Subtarget); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8162 | if (VT != MVT::i32) |
| 8163 | return SDValue(); |
| 8164 | |
| 8165 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1)); |
| 8166 | if (!C) |
| 8167 | return SDValue(); |
| 8168 | |
Anton Korobeynikov | 2d7ea04 | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 8169 | int64_t MulAmt = C->getSExtValue(); |
Michael J. Spencer | c6af243 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 8170 | unsigned ShiftAmt = countTrailingZeros<uint64_t>(MulAmt); |
Anton Korobeynikov | 2d7ea04 | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 8171 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8172 | ShiftAmt = ShiftAmt & (32 - 1); |
| 8173 | SDValue V = N->getOperand(0); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 8174 | SDLoc DL(N); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8175 | |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 8176 | SDValue Res; |
| 8177 | MulAmt >>= ShiftAmt; |
Anton Korobeynikov | 2d7ea04 | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 8178 | |
| 8179 | if (MulAmt >= 0) { |
| 8180 | if (isPowerOf2_32(MulAmt - 1)) { |
| 8181 | // (mul x, 2^N + 1) => (add (shl x, N), x) |
| 8182 | Res = DAG.getNode(ISD::ADD, DL, VT, |
| 8183 | V, |
| 8184 | DAG.getNode(ISD::SHL, DL, VT, |
| 8185 | V, |
| 8186 | DAG.getConstant(Log2_32(MulAmt - 1), |
| 8187 | MVT::i32))); |
| 8188 | } else if (isPowerOf2_32(MulAmt + 1)) { |
| 8189 | // (mul x, 2^N - 1) => (sub (shl x, N), x) |
| 8190 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 8191 | DAG.getNode(ISD::SHL, DL, VT, |
| 8192 | V, |
| 8193 | DAG.getConstant(Log2_32(MulAmt + 1), |
| 8194 | MVT::i32)), |
| 8195 | V); |
| 8196 | } else |
| 8197 | return SDValue(); |
| 8198 | } else { |
| 8199 | uint64_t MulAmtAbs = -MulAmt; |
| 8200 | if (isPowerOf2_32(MulAmtAbs + 1)) { |
| 8201 | // (mul x, -(2^N - 1)) => (sub x, (shl x, N)) |
| 8202 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 8203 | V, |
| 8204 | DAG.getNode(ISD::SHL, DL, VT, |
| 8205 | V, |
| 8206 | DAG.getConstant(Log2_32(MulAmtAbs + 1), |
| 8207 | MVT::i32))); |
| 8208 | } else if (isPowerOf2_32(MulAmtAbs - 1)) { |
| 8209 | // (mul x, -(2^N + 1)) => - (add (shl x, N), x) |
| 8210 | Res = DAG.getNode(ISD::ADD, DL, VT, |
| 8211 | V, |
| 8212 | DAG.getNode(ISD::SHL, DL, VT, |
| 8213 | V, |
| 8214 | DAG.getConstant(Log2_32(MulAmtAbs-1), |
| 8215 | MVT::i32))); |
| 8216 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 8217 | DAG.getConstant(0, MVT::i32),Res); |
| 8218 | |
| 8219 | } else |
| 8220 | return SDValue(); |
| 8221 | } |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 8222 | |
| 8223 | if (ShiftAmt != 0) |
Anton Korobeynikov | 2d7ea04 | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 8224 | Res = DAG.getNode(ISD::SHL, DL, VT, |
| 8225 | Res, DAG.getConstant(ShiftAmt, MVT::i32)); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8226 | |
| 8227 | // Do not add new nodes to DAG combiner worklist. |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 8228 | DCI.CombineTo(N, Res, false); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8229 | return SDValue(); |
| 8230 | } |
| 8231 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8232 | static SDValue PerformANDCombine(SDNode *N, |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8233 | TargetLowering::DAGCombinerInfo &DCI, |
| 8234 | const ARMSubtarget *Subtarget) { |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 8235 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8236 | // Attempt to use immediate-form VBIC |
| 8237 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 8238 | SDLoc dl(N); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8239 | EVT VT = N->getValueType(0); |
| 8240 | SelectionDAG &DAG = DCI.DAG; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8241 | |
Tanya Lattner | 0433b21 | 2011-04-07 15:24:20 +0000 | [diff] [blame] | 8242 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 8243 | return SDValue(); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 8244 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8245 | APInt SplatBits, SplatUndef; |
| 8246 | unsigned SplatBitSize; |
| 8247 | bool HasAnyUndefs; |
| 8248 | if (BVN && |
| 8249 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 8250 | if (SplatBitSize <= 64) { |
| 8251 | EVT VbicVT; |
| 8252 | SDValue Val = isNEONModifiedImm((~SplatBits).getZExtValue(), |
| 8253 | SplatUndef.getZExtValue(), SplatBitSize, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8254 | DAG, VbicVT, VT.is128BitVector(), |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 8255 | OtherModImm); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8256 | if (Val.getNode()) { |
| 8257 | SDValue Input = |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8258 | DAG.getNode(ISD::BITCAST, dl, VbicVT, N->getOperand(0)); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8259 | SDValue Vbic = DAG.getNode(ARMISD::VBICIMM, dl, VbicVT, Input, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8260 | return DAG.getNode(ISD::BITCAST, dl, VT, Vbic); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8261 | } |
| 8262 | } |
| 8263 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8264 | |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8265 | if (!Subtarget->isThumb1Only()) { |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8266 | // fold (and (select cc, -1, c), x) -> (select cc, x, (and, x, c)) |
| 8267 | SDValue Result = combineSelectAndUseCommutative(N, true, DCI); |
| 8268 | if (Result.getNode()) |
| 8269 | return Result; |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8270 | } |
| 8271 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8272 | return SDValue(); |
| 8273 | } |
| 8274 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8275 | /// PerformORCombine - Target-specific dag combine xforms for ISD::OR |
| 8276 | static SDValue PerformORCombine(SDNode *N, |
| 8277 | TargetLowering::DAGCombinerInfo &DCI, |
| 8278 | const ARMSubtarget *Subtarget) { |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8279 | // Attempt to use immediate-form VORR |
| 8280 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 8281 | SDLoc dl(N); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8282 | EVT VT = N->getValueType(0); |
| 8283 | SelectionDAG &DAG = DCI.DAG; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8284 | |
Tanya Lattner | 0433b21 | 2011-04-07 15:24:20 +0000 | [diff] [blame] | 8285 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 8286 | return SDValue(); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 8287 | |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8288 | APInt SplatBits, SplatUndef; |
| 8289 | unsigned SplatBitSize; |
| 8290 | bool HasAnyUndefs; |
| 8291 | if (BVN && Subtarget->hasNEON() && |
| 8292 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 8293 | if (SplatBitSize <= 64) { |
| 8294 | EVT VorrVT; |
| 8295 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
| 8296 | SplatUndef.getZExtValue(), SplatBitSize, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 8297 | DAG, VorrVT, VT.is128BitVector(), |
| 8298 | OtherModImm); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8299 | if (Val.getNode()) { |
| 8300 | SDValue Input = |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8301 | DAG.getNode(ISD::BITCAST, dl, VorrVT, N->getOperand(0)); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8302 | SDValue Vorr = DAG.getNode(ARMISD::VORRIMM, dl, VorrVT, Input, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8303 | return DAG.getNode(ISD::BITCAST, dl, VT, Vorr); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8304 | } |
| 8305 | } |
| 8306 | } |
| 8307 | |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8308 | if (!Subtarget->isThumb1Only()) { |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8309 | // fold (or (select cc, 0, c), x) -> (select cc, x, (or, x, c)) |
| 8310 | SDValue Result = combineSelectAndUseCommutative(N, false, DCI); |
| 8311 | if (Result.getNode()) |
| 8312 | return Result; |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8313 | } |
| 8314 | |
Nadav Rotem | df83203 | 2012-08-13 18:52:44 +0000 | [diff] [blame] | 8315 | // The code below optimizes (or (and X, Y), Z). |
| 8316 | // The AND operand needs to have a single user to make these optimizations |
| 8317 | // profitable. |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 8318 | SDValue N0 = N->getOperand(0); |
Nadav Rotem | df83203 | 2012-08-13 18:52:44 +0000 | [diff] [blame] | 8319 | if (N0.getOpcode() != ISD::AND || !N0.hasOneUse()) |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 8320 | return SDValue(); |
| 8321 | SDValue N1 = N->getOperand(1); |
| 8322 | |
| 8323 | // (or (and B, A), (and C, ~A)) => (VBSL A, B, C) when A is a constant. |
| 8324 | if (Subtarget->hasNEON() && N1.getOpcode() == ISD::AND && VT.isVector() && |
| 8325 | DAG.getTargetLoweringInfo().isTypeLegal(VT)) { |
| 8326 | APInt SplatUndef; |
| 8327 | unsigned SplatBitSize; |
| 8328 | bool HasAnyUndefs; |
| 8329 | |
| 8330 | BuildVectorSDNode *BVN0 = dyn_cast<BuildVectorSDNode>(N0->getOperand(1)); |
| 8331 | APInt SplatBits0; |
| 8332 | if (BVN0 && BVN0->isConstantSplat(SplatBits0, SplatUndef, SplatBitSize, |
| 8333 | HasAnyUndefs) && !HasAnyUndefs) { |
| 8334 | BuildVectorSDNode *BVN1 = dyn_cast<BuildVectorSDNode>(N1->getOperand(1)); |
| 8335 | APInt SplatBits1; |
| 8336 | if (BVN1 && BVN1->isConstantSplat(SplatBits1, SplatUndef, SplatBitSize, |
| 8337 | HasAnyUndefs) && !HasAnyUndefs && |
| 8338 | SplatBits0 == ~SplatBits1) { |
| 8339 | // Canonicalize the vector type to make instruction selection simpler. |
| 8340 | EVT CanonicalVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 8341 | SDValue Result = DAG.getNode(ARMISD::VBSL, dl, CanonicalVT, |
| 8342 | N0->getOperand(1), N0->getOperand(0), |
Cameron Zwarich | 5af60ce | 2011-04-13 21:01:19 +0000 | [diff] [blame] | 8343 | N1->getOperand(0)); |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 8344 | return DAG.getNode(ISD::BITCAST, dl, VT, Result); |
| 8345 | } |
| 8346 | } |
| 8347 | } |
| 8348 | |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8349 | // Try to use the ARM/Thumb2 BFI (bitfield insert) instruction when |
| 8350 | // reasonable. |
| 8351 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8352 | // BFI is only available on V6T2+ |
| 8353 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6T2Ops()) |
| 8354 | return SDValue(); |
| 8355 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 8356 | SDLoc DL(N); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8357 | // 1) or (and A, mask), val => ARMbfi A, val, mask |
Sylvestre Ledru | 94c2271 | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 8358 | // iff (val & mask) == val |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8359 | // |
| 8360 | // 2) or (and A, mask), (and B, mask2) => ARMbfi A, (lsr B, amt), mask |
Sylvestre Ledru | 94c2271 | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 8361 | // 2a) iff isBitFieldInvertedMask(mask) && isBitFieldInvertedMask(~mask2) |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8362 | // && mask == ~mask2 |
Sylvestre Ledru | 94c2271 | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 8363 | // 2b) iff isBitFieldInvertedMask(~mask) && isBitFieldInvertedMask(mask2) |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8364 | // && ~mask == mask2 |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8365 | // (i.e., copy a bitfield value into another bitfield of the same width) |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8366 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8367 | if (VT != MVT::i32) |
| 8368 | return SDValue(); |
| 8369 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8370 | SDValue N00 = N0.getOperand(0); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8371 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8372 | // The value and the mask need to be constants so we can verify this is |
| 8373 | // actually a bitfield set. If the mask is 0xffff, we can do better |
| 8374 | // via a movt instruction, so don't use BFI in that case. |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8375 | SDValue MaskOp = N0.getOperand(1); |
| 8376 | ConstantSDNode *MaskC = dyn_cast<ConstantSDNode>(MaskOp); |
| 8377 | if (!MaskC) |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8378 | return SDValue(); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8379 | unsigned Mask = MaskC->getZExtValue(); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8380 | if (Mask == 0xffff) |
| 8381 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8382 | SDValue Res; |
| 8383 | // Case (1): or (and A, mask), val => ARMbfi A, val, mask |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8384 | ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1); |
| 8385 | if (N1C) { |
| 8386 | unsigned Val = N1C->getZExtValue(); |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 8387 | if ((Val & ~Mask) != Val) |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8388 | return SDValue(); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8389 | |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 8390 | if (ARM::isBitFieldInvertedMask(Mask)) { |
Michael J. Spencer | c6af243 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 8391 | Val >>= countTrailingZeros(~Mask); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8392 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8393 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 8394 | DAG.getConstant(Val, MVT::i32), |
| 8395 | DAG.getConstant(Mask, MVT::i32)); |
| 8396 | |
| 8397 | // Do not add new nodes to DAG combiner worklist. |
| 8398 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8399 | return SDValue(); |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 8400 | } |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8401 | } else if (N1.getOpcode() == ISD::AND) { |
| 8402 | // case (2) or (and A, mask), (and B, mask2) => ARMbfi A, (lsr B, amt), mask |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8403 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 8404 | if (!N11C) |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8405 | return SDValue(); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8406 | unsigned Mask2 = N11C->getZExtValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8407 | |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8408 | // Mask and ~Mask2 (or reverse) must be equivalent for the BFI pattern |
| 8409 | // as is to match. |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8410 | if (ARM::isBitFieldInvertedMask(Mask) && |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8411 | (Mask == ~Mask2)) { |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8412 | // The pack halfword instruction works better for masks that fit it, |
| 8413 | // so use that when it's available. |
| 8414 | if (Subtarget->hasT2ExtractPack() && |
| 8415 | (Mask == 0xffff || Mask == 0xffff0000)) |
| 8416 | return SDValue(); |
| 8417 | // 2a |
Michael J. Spencer | c6af243 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 8418 | unsigned amt = countTrailingZeros(Mask2); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8419 | Res = DAG.getNode(ISD::SRL, DL, VT, N1.getOperand(0), |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8420 | DAG.getConstant(amt, MVT::i32)); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8421 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, Res, |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8422 | DAG.getConstant(Mask, MVT::i32)); |
| 8423 | // Do not add new nodes to DAG combiner worklist. |
| 8424 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8425 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8426 | } else if (ARM::isBitFieldInvertedMask(~Mask) && |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8427 | (~Mask == Mask2)) { |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8428 | // The pack halfword instruction works better for masks that fit it, |
| 8429 | // so use that when it's available. |
| 8430 | if (Subtarget->hasT2ExtractPack() && |
| 8431 | (Mask2 == 0xffff || Mask2 == 0xffff0000)) |
| 8432 | return SDValue(); |
| 8433 | // 2b |
Michael J. Spencer | c6af243 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 8434 | unsigned lsb = countTrailingZeros(Mask); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8435 | Res = DAG.getNode(ISD::SRL, DL, VT, N00, |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8436 | DAG.getConstant(lsb, MVT::i32)); |
| 8437 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1.getOperand(0), Res, |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8438 | DAG.getConstant(Mask2, MVT::i32)); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8439 | // Do not add new nodes to DAG combiner worklist. |
| 8440 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8441 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8442 | } |
| 8443 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8444 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8445 | if (DAG.MaskedValueIsZero(N1, MaskC->getAPIntValue()) && |
| 8446 | N00.getOpcode() == ISD::SHL && isa<ConstantSDNode>(N00.getOperand(1)) && |
| 8447 | ARM::isBitFieldInvertedMask(~Mask)) { |
| 8448 | // Case (3): or (and (shl A, #shamt), mask), B => ARMbfi B, A, ~mask |
| 8449 | // where lsb(mask) == #shamt and masked bits of B are known zero. |
| 8450 | SDValue ShAmt = N00.getOperand(1); |
| 8451 | unsigned ShAmtC = cast<ConstantSDNode>(ShAmt)->getZExtValue(); |
Michael J. Spencer | c6af243 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 8452 | unsigned LSB = countTrailingZeros(Mask); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8453 | if (ShAmtC != LSB) |
| 8454 | return SDValue(); |
| 8455 | |
| 8456 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1, N00.getOperand(0), |
| 8457 | DAG.getConstant(~Mask, MVT::i32)); |
| 8458 | |
| 8459 | // Do not add new nodes to DAG combiner worklist. |
| 8460 | DCI.CombineTo(N, Res, false); |
| 8461 | } |
| 8462 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8463 | return SDValue(); |
| 8464 | } |
| 8465 | |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8466 | static SDValue PerformXORCombine(SDNode *N, |
| 8467 | TargetLowering::DAGCombinerInfo &DCI, |
| 8468 | const ARMSubtarget *Subtarget) { |
| 8469 | EVT VT = N->getValueType(0); |
| 8470 | SelectionDAG &DAG = DCI.DAG; |
| 8471 | |
| 8472 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 8473 | return SDValue(); |
| 8474 | |
| 8475 | if (!Subtarget->isThumb1Only()) { |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8476 | // fold (xor (select cc, 0, c), x) -> (select cc, x, (xor, x, c)) |
| 8477 | SDValue Result = combineSelectAndUseCommutative(N, false, DCI); |
| 8478 | if (Result.getNode()) |
| 8479 | return Result; |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8480 | } |
| 8481 | |
| 8482 | return SDValue(); |
| 8483 | } |
| 8484 | |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 8485 | /// PerformBFICombine - (bfi A, (and B, Mask1), Mask2) -> (bfi A, B, Mask2) iff |
| 8486 | /// the bits being cleared by the AND are not demanded by the BFI. |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 8487 | static SDValue PerformBFICombine(SDNode *N, |
| 8488 | TargetLowering::DAGCombinerInfo &DCI) { |
| 8489 | SDValue N1 = N->getOperand(1); |
| 8490 | if (N1.getOpcode() == ISD::AND) { |
| 8491 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 8492 | if (!N11C) |
| 8493 | return SDValue(); |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 8494 | unsigned InvMask = cast<ConstantSDNode>(N->getOperand(2))->getZExtValue(); |
Michael J. Spencer | c6af243 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 8495 | unsigned LSB = countTrailingZeros(~InvMask); |
| 8496 | unsigned Width = (32 - countLeadingZeros(~InvMask)) - LSB; |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 8497 | unsigned Mask = (1 << Width)-1; |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 8498 | unsigned Mask2 = N11C->getZExtValue(); |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 8499 | if ((Mask & (~Mask2)) == 0) |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 8500 | return DCI.DAG.getNode(ARMISD::BFI, SDLoc(N), N->getValueType(0), |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 8501 | N->getOperand(0), N1.getOperand(0), |
| 8502 | N->getOperand(2)); |
| 8503 | } |
| 8504 | return SDValue(); |
| 8505 | } |
| 8506 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 8507 | /// PerformVMOVRRDCombine - Target-specific dag combine xforms for |
| 8508 | /// ARMISD::VMOVRRD. |
| 8509 | static SDValue PerformVMOVRRDCombine(SDNode *N, |
| 8510 | TargetLowering::DAGCombinerInfo &DCI) { |
| 8511 | // vmovrrd(vmovdrr x, y) -> x,y |
| 8512 | SDValue InDouble = N->getOperand(0); |
| 8513 | if (InDouble.getOpcode() == ARMISD::VMOVDRR) |
| 8514 | return DCI.CombineTo(N, InDouble.getOperand(0), InDouble.getOperand(1)); |
Cameron Zwarich | 4071a71 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 8515 | |
| 8516 | // vmovrrd(load f64) -> (load i32), (load i32) |
| 8517 | SDNode *InNode = InDouble.getNode(); |
| 8518 | if (ISD::isNormalLoad(InNode) && InNode->hasOneUse() && |
| 8519 | InNode->getValueType(0) == MVT::f64 && |
| 8520 | InNode->getOperand(1).getOpcode() == ISD::FrameIndex && |
| 8521 | !cast<LoadSDNode>(InNode)->isVolatile()) { |
| 8522 | // TODO: Should this be done for non-FrameIndex operands? |
| 8523 | LoadSDNode *LD = cast<LoadSDNode>(InNode); |
| 8524 | |
| 8525 | SelectionDAG &DAG = DCI.DAG; |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 8526 | SDLoc DL(LD); |
Cameron Zwarich | 4071a71 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 8527 | SDValue BasePtr = LD->getBasePtr(); |
| 8528 | SDValue NewLD1 = DAG.getLoad(MVT::i32, DL, LD->getChain(), BasePtr, |
| 8529 | LD->getPointerInfo(), LD->isVolatile(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 8530 | LD->isNonTemporal(), LD->isInvariant(), |
| 8531 | LD->getAlignment()); |
Cameron Zwarich | 4071a71 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 8532 | |
| 8533 | SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, |
| 8534 | DAG.getConstant(4, MVT::i32)); |
| 8535 | SDValue NewLD2 = DAG.getLoad(MVT::i32, DL, NewLD1.getValue(1), OffsetPtr, |
| 8536 | LD->getPointerInfo(), LD->isVolatile(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 8537 | LD->isNonTemporal(), LD->isInvariant(), |
Cameron Zwarich | 4071a71 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 8538 | std::min(4U, LD->getAlignment() / 2)); |
| 8539 | |
| 8540 | DAG.ReplaceAllUsesOfValueWith(SDValue(LD, 1), NewLD2.getValue(1)); |
| 8541 | SDValue Result = DCI.CombineTo(N, NewLD1, NewLD2); |
| 8542 | DCI.RemoveFromWorklist(LD); |
| 8543 | DAG.DeleteNode(LD); |
| 8544 | return Result; |
| 8545 | } |
| 8546 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 8547 | return SDValue(); |
| 8548 | } |
| 8549 | |
| 8550 | /// PerformVMOVDRRCombine - Target-specific dag combine xforms for |
| 8551 | /// ARMISD::VMOVDRR. This is also used for BUILD_VECTORs with 2 operands. |
| 8552 | static SDValue PerformVMOVDRRCombine(SDNode *N, SelectionDAG &DAG) { |
| 8553 | // N=vmovrrd(X); vmovdrr(N:0, N:1) -> bit_convert(X) |
| 8554 | SDValue Op0 = N->getOperand(0); |
| 8555 | SDValue Op1 = N->getOperand(1); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8556 | if (Op0.getOpcode() == ISD::BITCAST) |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 8557 | Op0 = Op0.getOperand(0); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8558 | if (Op1.getOpcode() == ISD::BITCAST) |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 8559 | Op1 = Op1.getOperand(0); |
| 8560 | if (Op0.getOpcode() == ARMISD::VMOVRRD && |
| 8561 | Op0.getNode() == Op1.getNode() && |
| 8562 | Op0.getResNo() == 0 && Op1.getResNo() == 1) |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 8563 | return DAG.getNode(ISD::BITCAST, SDLoc(N), |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 8564 | N->getValueType(0), Op0.getOperand(0)); |
| 8565 | return SDValue(); |
| 8566 | } |
| 8567 | |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8568 | /// PerformSTORECombine - Target-specific dag combine xforms for |
| 8569 | /// ISD::STORE. |
| 8570 | static SDValue PerformSTORECombine(SDNode *N, |
| 8571 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8572 | StoreSDNode *St = cast<StoreSDNode>(N); |
Chad Rosier | 7f35455 | 2012-04-09 20:32:02 +0000 | [diff] [blame] | 8573 | if (St->isVolatile()) |
| 8574 | return SDValue(); |
| 8575 | |
Andrew Trick | 49b446f | 2012-07-18 18:34:24 +0000 | [diff] [blame] | 8576 | // Optimize trunc store (of multiple scalars) to shuffle and store. First, |
Chad Rosier | 7f35455 | 2012-04-09 20:32:02 +0000 | [diff] [blame] | 8577 | // pack all of the elements in one place. Next, store to memory in fewer |
| 8578 | // chunks. |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8579 | SDValue StVal = St->getValue(); |
Chad Rosier | 7f35455 | 2012-04-09 20:32:02 +0000 | [diff] [blame] | 8580 | EVT VT = StVal.getValueType(); |
| 8581 | if (St->isTruncatingStore() && VT.isVector()) { |
| 8582 | SelectionDAG &DAG = DCI.DAG; |
| 8583 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 8584 | EVT StVT = St->getMemoryVT(); |
| 8585 | unsigned NumElems = VT.getVectorNumElements(); |
| 8586 | assert(StVT != VT && "Cannot truncate to the same type"); |
| 8587 | unsigned FromEltSz = VT.getVectorElementType().getSizeInBits(); |
| 8588 | unsigned ToEltSz = StVT.getVectorElementType().getSizeInBits(); |
| 8589 | |
| 8590 | // From, To sizes and ElemCount must be pow of two |
| 8591 | if (!isPowerOf2_32(NumElems * FromEltSz * ToEltSz)) return SDValue(); |
| 8592 | |
| 8593 | // We are going to use the original vector elt for storing. |
| 8594 | // Accumulated smaller vector elements must be a multiple of the store size. |
| 8595 | if (0 != (NumElems * FromEltSz) % ToEltSz) return SDValue(); |
| 8596 | |
| 8597 | unsigned SizeRatio = FromEltSz / ToEltSz; |
| 8598 | assert(SizeRatio * NumElems * ToEltSz == VT.getSizeInBits()); |
| 8599 | |
| 8600 | // Create a type on which we perform the shuffle. |
| 8601 | EVT WideVecVT = EVT::getVectorVT(*DAG.getContext(), StVT.getScalarType(), |
| 8602 | NumElems*SizeRatio); |
| 8603 | assert(WideVecVT.getSizeInBits() == VT.getSizeInBits()); |
| 8604 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 8605 | SDLoc DL(St); |
Chad Rosier | 7f35455 | 2012-04-09 20:32:02 +0000 | [diff] [blame] | 8606 | SDValue WideVec = DAG.getNode(ISD::BITCAST, DL, WideVecVT, StVal); |
| 8607 | SmallVector<int, 8> ShuffleVec(NumElems * SizeRatio, -1); |
| 8608 | for (unsigned i = 0; i < NumElems; ++i) ShuffleVec[i] = i * SizeRatio; |
| 8609 | |
| 8610 | // Can't shuffle using an illegal type. |
| 8611 | if (!TLI.isTypeLegal(WideVecVT)) return SDValue(); |
| 8612 | |
| 8613 | SDValue Shuff = DAG.getVectorShuffle(WideVecVT, DL, WideVec, |
| 8614 | DAG.getUNDEF(WideVec.getValueType()), |
| 8615 | ShuffleVec.data()); |
| 8616 | // At this point all of the data is stored at the bottom of the |
| 8617 | // register. We now need to save it to mem. |
| 8618 | |
| 8619 | // Find the largest store unit |
| 8620 | MVT StoreType = MVT::i8; |
| 8621 | for (unsigned tp = MVT::FIRST_INTEGER_VALUETYPE; |
| 8622 | tp < MVT::LAST_INTEGER_VALUETYPE; ++tp) { |
| 8623 | MVT Tp = (MVT::SimpleValueType)tp; |
| 8624 | if (TLI.isTypeLegal(Tp) && Tp.getSizeInBits() <= NumElems * ToEltSz) |
| 8625 | StoreType = Tp; |
| 8626 | } |
| 8627 | // Didn't find a legal store type. |
| 8628 | if (!TLI.isTypeLegal(StoreType)) |
| 8629 | return SDValue(); |
| 8630 | |
| 8631 | // Bitcast the original vector into a vector of store-size units |
| 8632 | EVT StoreVecVT = EVT::getVectorVT(*DAG.getContext(), |
| 8633 | StoreType, VT.getSizeInBits()/EVT(StoreType).getSizeInBits()); |
| 8634 | assert(StoreVecVT.getSizeInBits() == VT.getSizeInBits()); |
| 8635 | SDValue ShuffWide = DAG.getNode(ISD::BITCAST, DL, StoreVecVT, Shuff); |
| 8636 | SmallVector<SDValue, 8> Chains; |
| 8637 | SDValue Increment = DAG.getConstant(StoreType.getSizeInBits()/8, |
| 8638 | TLI.getPointerTy()); |
| 8639 | SDValue BasePtr = St->getBasePtr(); |
| 8640 | |
| 8641 | // Perform one or more big stores into memory. |
| 8642 | unsigned E = (ToEltSz*NumElems)/StoreType.getSizeInBits(); |
| 8643 | for (unsigned I = 0; I < E; I++) { |
| 8644 | SDValue SubVec = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, |
| 8645 | StoreType, ShuffWide, |
| 8646 | DAG.getIntPtrConstant(I)); |
| 8647 | SDValue Ch = DAG.getStore(St->getChain(), DL, SubVec, BasePtr, |
| 8648 | St->getPointerInfo(), St->isVolatile(), |
| 8649 | St->isNonTemporal(), St->getAlignment()); |
| 8650 | BasePtr = DAG.getNode(ISD::ADD, DL, BasePtr.getValueType(), BasePtr, |
| 8651 | Increment); |
| 8652 | Chains.push_back(Ch); |
| 8653 | } |
| 8654 | return DAG.getNode(ISD::TokenFactor, DL, MVT::Other, &Chains[0], |
| 8655 | Chains.size()); |
| 8656 | } |
| 8657 | |
| 8658 | if (!ISD::isNormalStore(St)) |
Cameron Zwarich | d0aacbc | 2011-04-12 02:24:17 +0000 | [diff] [blame] | 8659 | return SDValue(); |
| 8660 | |
Chad Rosier | 96b66d6 | 2012-04-09 19:38:15 +0000 | [diff] [blame] | 8661 | // Split a store of a VMOVDRR into two integer stores to avoid mixing NEON and |
| 8662 | // ARM stores of arguments in the same cache line. |
Cameron Zwarich | d0aacbc | 2011-04-12 02:24:17 +0000 | [diff] [blame] | 8663 | if (StVal.getNode()->getOpcode() == ARMISD::VMOVDRR && |
Chad Rosier | 96b66d6 | 2012-04-09 19:38:15 +0000 | [diff] [blame] | 8664 | StVal.getNode()->hasOneUse()) { |
Cameron Zwarich | d0aacbc | 2011-04-12 02:24:17 +0000 | [diff] [blame] | 8665 | SelectionDAG &DAG = DCI.DAG; |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 8666 | SDLoc DL(St); |
Cameron Zwarich | d0aacbc | 2011-04-12 02:24:17 +0000 | [diff] [blame] | 8667 | SDValue BasePtr = St->getBasePtr(); |
| 8668 | SDValue NewST1 = DAG.getStore(St->getChain(), DL, |
| 8669 | StVal.getNode()->getOperand(0), BasePtr, |
| 8670 | St->getPointerInfo(), St->isVolatile(), |
| 8671 | St->isNonTemporal(), St->getAlignment()); |
| 8672 | |
| 8673 | SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, |
| 8674 | DAG.getConstant(4, MVT::i32)); |
| 8675 | return DAG.getStore(NewST1.getValue(0), DL, StVal.getNode()->getOperand(1), |
| 8676 | OffsetPtr, St->getPointerInfo(), St->isVolatile(), |
| 8677 | St->isNonTemporal(), |
| 8678 | std::min(4U, St->getAlignment() / 2)); |
| 8679 | } |
| 8680 | |
| 8681 | if (StVal.getValueType() != MVT::i64 || |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8682 | StVal.getNode()->getOpcode() != ISD::EXTRACT_VECTOR_ELT) |
| 8683 | return SDValue(); |
| 8684 | |
Chad Rosier | 96b66d6 | 2012-04-09 19:38:15 +0000 | [diff] [blame] | 8685 | // Bitcast an i64 store extracted from a vector to f64. |
| 8686 | // Otherwise, the i64 value will be legalized to a pair of i32 values. |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8687 | SelectionDAG &DAG = DCI.DAG; |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 8688 | SDLoc dl(StVal); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8689 | SDValue IntVec = StVal.getOperand(0); |
| 8690 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 8691 | IntVec.getValueType().getVectorNumElements()); |
| 8692 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, IntVec); |
| 8693 | SDValue ExtElt = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, |
| 8694 | Vec, StVal.getOperand(1)); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 8695 | dl = SDLoc(N); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8696 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::i64, ExtElt); |
| 8697 | // Make the DAGCombiner fold the bitcasts. |
| 8698 | DCI.AddToWorklist(Vec.getNode()); |
| 8699 | DCI.AddToWorklist(ExtElt.getNode()); |
| 8700 | DCI.AddToWorklist(V.getNode()); |
| 8701 | return DAG.getStore(St->getChain(), dl, V, St->getBasePtr(), |
| 8702 | St->getPointerInfo(), St->isVolatile(), |
| 8703 | St->isNonTemporal(), St->getAlignment(), |
| 8704 | St->getTBAAInfo()); |
| 8705 | } |
| 8706 | |
| 8707 | /// hasNormalLoadOperand - Check if any of the operands of a BUILD_VECTOR node |
| 8708 | /// are normal, non-volatile loads. If so, it is profitable to bitcast an |
| 8709 | /// i64 vector to have f64 elements, since the value can then be loaded |
| 8710 | /// directly into a VFP register. |
| 8711 | static bool hasNormalLoadOperand(SDNode *N) { |
| 8712 | unsigned NumElts = N->getValueType(0).getVectorNumElements(); |
| 8713 | for (unsigned i = 0; i < NumElts; ++i) { |
| 8714 | SDNode *Elt = N->getOperand(i).getNode(); |
| 8715 | if (ISD::isNormalLoad(Elt) && !cast<LoadSDNode>(Elt)->isVolatile()) |
| 8716 | return true; |
| 8717 | } |
| 8718 | return false; |
| 8719 | } |
| 8720 | |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 8721 | /// PerformBUILD_VECTORCombine - Target-specific dag combine xforms for |
| 8722 | /// ISD::BUILD_VECTOR. |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8723 | static SDValue PerformBUILD_VECTORCombine(SDNode *N, |
| 8724 | TargetLowering::DAGCombinerInfo &DCI){ |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 8725 | // build_vector(N=ARMISD::VMOVRRD(X), N:1) -> bit_convert(X): |
| 8726 | // VMOVRRD is introduced when legalizing i64 types. It forces the i64 value |
| 8727 | // into a pair of GPRs, which is fine when the value is used as a scalar, |
| 8728 | // but if the i64 value is converted to a vector, we need to undo the VMOVRRD. |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8729 | SelectionDAG &DAG = DCI.DAG; |
| 8730 | if (N->getNumOperands() == 2) { |
| 8731 | SDValue RV = PerformVMOVDRRCombine(N, DAG); |
| 8732 | if (RV.getNode()) |
| 8733 | return RV; |
| 8734 | } |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 8735 | |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8736 | // Load i64 elements as f64 values so that type legalization does not split |
| 8737 | // them up into i32 values. |
| 8738 | EVT VT = N->getValueType(0); |
| 8739 | if (VT.getVectorElementType() != MVT::i64 || !hasNormalLoadOperand(N)) |
| 8740 | return SDValue(); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 8741 | SDLoc dl(N); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8742 | SmallVector<SDValue, 8> Ops; |
| 8743 | unsigned NumElts = VT.getVectorNumElements(); |
| 8744 | for (unsigned i = 0; i < NumElts; ++i) { |
| 8745 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(i)); |
| 8746 | Ops.push_back(V); |
| 8747 | // Make the DAGCombiner fold the bitcast. |
| 8748 | DCI.AddToWorklist(V.getNode()); |
| 8749 | } |
| 8750 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, NumElts); |
| 8751 | SDValue BV = DAG.getNode(ISD::BUILD_VECTOR, dl, FloatVT, Ops.data(), NumElts); |
| 8752 | return DAG.getNode(ISD::BITCAST, dl, VT, BV); |
| 8753 | } |
| 8754 | |
| 8755 | /// PerformInsertEltCombine - Target-specific dag combine xforms for |
| 8756 | /// ISD::INSERT_VECTOR_ELT. |
| 8757 | static SDValue PerformInsertEltCombine(SDNode *N, |
| 8758 | TargetLowering::DAGCombinerInfo &DCI) { |
| 8759 | // Bitcast an i64 load inserted into a vector to f64. |
| 8760 | // Otherwise, the i64 value will be legalized to a pair of i32 values. |
| 8761 | EVT VT = N->getValueType(0); |
| 8762 | SDNode *Elt = N->getOperand(1).getNode(); |
| 8763 | if (VT.getVectorElementType() != MVT::i64 || |
| 8764 | !ISD::isNormalLoad(Elt) || cast<LoadSDNode>(Elt)->isVolatile()) |
| 8765 | return SDValue(); |
| 8766 | |
| 8767 | SelectionDAG &DAG = DCI.DAG; |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 8768 | SDLoc dl(N); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8769 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 8770 | VT.getVectorNumElements()); |
| 8771 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, N->getOperand(0)); |
| 8772 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(1)); |
| 8773 | // Make the DAGCombiner fold the bitcasts. |
| 8774 | DCI.AddToWorklist(Vec.getNode()); |
| 8775 | DCI.AddToWorklist(V.getNode()); |
| 8776 | SDValue InsElt = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, FloatVT, |
| 8777 | Vec, V, N->getOperand(2)); |
| 8778 | return DAG.getNode(ISD::BITCAST, dl, VT, InsElt); |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 8779 | } |
| 8780 | |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 8781 | /// PerformVECTOR_SHUFFLECombine - Target-specific dag combine xforms for |
| 8782 | /// ISD::VECTOR_SHUFFLE. |
| 8783 | static SDValue PerformVECTOR_SHUFFLECombine(SDNode *N, SelectionDAG &DAG) { |
| 8784 | // The LLVM shufflevector instruction does not require the shuffle mask |
| 8785 | // length to match the operand vector length, but ISD::VECTOR_SHUFFLE does |
| 8786 | // have that requirement. When translating to ISD::VECTOR_SHUFFLE, if the |
| 8787 | // operands do not match the mask length, they are extended by concatenating |
| 8788 | // them with undef vectors. That is probably the right thing for other |
| 8789 | // targets, but for NEON it is better to concatenate two double-register |
| 8790 | // size vector operands into a single quad-register size vector. Do that |
| 8791 | // transformation here: |
| 8792 | // shuffle(concat(v1, undef), concat(v2, undef)) -> |
| 8793 | // shuffle(concat(v1, v2), undef) |
| 8794 | SDValue Op0 = N->getOperand(0); |
| 8795 | SDValue Op1 = N->getOperand(1); |
| 8796 | if (Op0.getOpcode() != ISD::CONCAT_VECTORS || |
| 8797 | Op1.getOpcode() != ISD::CONCAT_VECTORS || |
| 8798 | Op0.getNumOperands() != 2 || |
| 8799 | Op1.getNumOperands() != 2) |
| 8800 | return SDValue(); |
| 8801 | SDValue Concat0Op1 = Op0.getOperand(1); |
| 8802 | SDValue Concat1Op1 = Op1.getOperand(1); |
| 8803 | if (Concat0Op1.getOpcode() != ISD::UNDEF || |
| 8804 | Concat1Op1.getOpcode() != ISD::UNDEF) |
| 8805 | return SDValue(); |
| 8806 | // Skip the transformation if any of the types are illegal. |
| 8807 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 8808 | EVT VT = N->getValueType(0); |
| 8809 | if (!TLI.isTypeLegal(VT) || |
| 8810 | !TLI.isTypeLegal(Concat0Op1.getValueType()) || |
| 8811 | !TLI.isTypeLegal(Concat1Op1.getValueType())) |
| 8812 | return SDValue(); |
| 8813 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 8814 | SDValue NewConcat = DAG.getNode(ISD::CONCAT_VECTORS, SDLoc(N), VT, |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 8815 | Op0.getOperand(0), Op1.getOperand(0)); |
| 8816 | // Translate the shuffle mask. |
| 8817 | SmallVector<int, 16> NewMask; |
| 8818 | unsigned NumElts = VT.getVectorNumElements(); |
| 8819 | unsigned HalfElts = NumElts/2; |
| 8820 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(N); |
| 8821 | for (unsigned n = 0; n < NumElts; ++n) { |
| 8822 | int MaskElt = SVN->getMaskElt(n); |
| 8823 | int NewElt = -1; |
Bob Wilson | 1fa9d30 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 8824 | if (MaskElt < (int)HalfElts) |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 8825 | NewElt = MaskElt; |
Bob Wilson | 1fa9d30 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 8826 | else if (MaskElt >= (int)NumElts && MaskElt < (int)(NumElts + HalfElts)) |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 8827 | NewElt = HalfElts + MaskElt - NumElts; |
| 8828 | NewMask.push_back(NewElt); |
| 8829 | } |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 8830 | return DAG.getVectorShuffle(VT, SDLoc(N), NewConcat, |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 8831 | DAG.getUNDEF(VT), NewMask.data()); |
| 8832 | } |
| 8833 | |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8834 | /// CombineBaseUpdate - Target-specific DAG combine function for VLDDUP and |
| 8835 | /// NEON load/store intrinsics to merge base address updates. |
| 8836 | static SDValue CombineBaseUpdate(SDNode *N, |
| 8837 | TargetLowering::DAGCombinerInfo &DCI) { |
| 8838 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 8839 | return SDValue(); |
| 8840 | |
| 8841 | SelectionDAG &DAG = DCI.DAG; |
| 8842 | bool isIntrinsic = (N->getOpcode() == ISD::INTRINSIC_VOID || |
| 8843 | N->getOpcode() == ISD::INTRINSIC_W_CHAIN); |
| 8844 | unsigned AddrOpIdx = (isIntrinsic ? 2 : 1); |
| 8845 | SDValue Addr = N->getOperand(AddrOpIdx); |
| 8846 | |
| 8847 | // Search for a use of the address operand that is an increment. |
| 8848 | for (SDNode::use_iterator UI = Addr.getNode()->use_begin(), |
| 8849 | UE = Addr.getNode()->use_end(); UI != UE; ++UI) { |
| 8850 | SDNode *User = *UI; |
| 8851 | if (User->getOpcode() != ISD::ADD || |
| 8852 | UI.getUse().getResNo() != Addr.getResNo()) |
| 8853 | continue; |
| 8854 | |
| 8855 | // Check that the add is independent of the load/store. Otherwise, folding |
| 8856 | // it would create a cycle. |
| 8857 | if (User->isPredecessorOf(N) || N->isPredecessorOf(User)) |
| 8858 | continue; |
| 8859 | |
| 8860 | // Find the new opcode for the updating load/store. |
| 8861 | bool isLoad = true; |
| 8862 | bool isLaneOp = false; |
| 8863 | unsigned NewOpc = 0; |
| 8864 | unsigned NumVecs = 0; |
| 8865 | if (isIntrinsic) { |
| 8866 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue(); |
| 8867 | switch (IntNo) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 8868 | default: llvm_unreachable("unexpected intrinsic for Neon base update"); |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8869 | case Intrinsic::arm_neon_vld1: NewOpc = ARMISD::VLD1_UPD; |
| 8870 | NumVecs = 1; break; |
| 8871 | case Intrinsic::arm_neon_vld2: NewOpc = ARMISD::VLD2_UPD; |
| 8872 | NumVecs = 2; break; |
| 8873 | case Intrinsic::arm_neon_vld3: NewOpc = ARMISD::VLD3_UPD; |
| 8874 | NumVecs = 3; break; |
| 8875 | case Intrinsic::arm_neon_vld4: NewOpc = ARMISD::VLD4_UPD; |
| 8876 | NumVecs = 4; break; |
| 8877 | case Intrinsic::arm_neon_vld2lane: NewOpc = ARMISD::VLD2LN_UPD; |
| 8878 | NumVecs = 2; isLaneOp = true; break; |
| 8879 | case Intrinsic::arm_neon_vld3lane: NewOpc = ARMISD::VLD3LN_UPD; |
| 8880 | NumVecs = 3; isLaneOp = true; break; |
| 8881 | case Intrinsic::arm_neon_vld4lane: NewOpc = ARMISD::VLD4LN_UPD; |
| 8882 | NumVecs = 4; isLaneOp = true; break; |
| 8883 | case Intrinsic::arm_neon_vst1: NewOpc = ARMISD::VST1_UPD; |
| 8884 | NumVecs = 1; isLoad = false; break; |
| 8885 | case Intrinsic::arm_neon_vst2: NewOpc = ARMISD::VST2_UPD; |
| 8886 | NumVecs = 2; isLoad = false; break; |
| 8887 | case Intrinsic::arm_neon_vst3: NewOpc = ARMISD::VST3_UPD; |
| 8888 | NumVecs = 3; isLoad = false; break; |
| 8889 | case Intrinsic::arm_neon_vst4: NewOpc = ARMISD::VST4_UPD; |
| 8890 | NumVecs = 4; isLoad = false; break; |
| 8891 | case Intrinsic::arm_neon_vst2lane: NewOpc = ARMISD::VST2LN_UPD; |
| 8892 | NumVecs = 2; isLoad = false; isLaneOp = true; break; |
| 8893 | case Intrinsic::arm_neon_vst3lane: NewOpc = ARMISD::VST3LN_UPD; |
| 8894 | NumVecs = 3; isLoad = false; isLaneOp = true; break; |
| 8895 | case Intrinsic::arm_neon_vst4lane: NewOpc = ARMISD::VST4LN_UPD; |
| 8896 | NumVecs = 4; isLoad = false; isLaneOp = true; break; |
| 8897 | } |
| 8898 | } else { |
| 8899 | isLaneOp = true; |
| 8900 | switch (N->getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 8901 | default: llvm_unreachable("unexpected opcode for Neon base update"); |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8902 | case ARMISD::VLD2DUP: NewOpc = ARMISD::VLD2DUP_UPD; NumVecs = 2; break; |
| 8903 | case ARMISD::VLD3DUP: NewOpc = ARMISD::VLD3DUP_UPD; NumVecs = 3; break; |
| 8904 | case ARMISD::VLD4DUP: NewOpc = ARMISD::VLD4DUP_UPD; NumVecs = 4; break; |
| 8905 | } |
| 8906 | } |
| 8907 | |
| 8908 | // Find the size of memory referenced by the load/store. |
| 8909 | EVT VecTy; |
| 8910 | if (isLoad) |
| 8911 | VecTy = N->getValueType(0); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 8912 | else |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8913 | VecTy = N->getOperand(AddrOpIdx+1).getValueType(); |
| 8914 | unsigned NumBytes = NumVecs * VecTy.getSizeInBits() / 8; |
| 8915 | if (isLaneOp) |
| 8916 | NumBytes /= VecTy.getVectorNumElements(); |
| 8917 | |
| 8918 | // If the increment is a constant, it must match the memory ref size. |
| 8919 | SDValue Inc = User->getOperand(User->getOperand(0) == Addr ? 1 : 0); |
| 8920 | if (ConstantSDNode *CInc = dyn_cast<ConstantSDNode>(Inc.getNode())) { |
| 8921 | uint64_t IncVal = CInc->getZExtValue(); |
| 8922 | if (IncVal != NumBytes) |
| 8923 | continue; |
| 8924 | } else if (NumBytes >= 3 * 16) { |
| 8925 | // VLD3/4 and VST3/4 for 128-bit vectors are implemented with two |
| 8926 | // separate instructions that make it harder to use a non-constant update. |
| 8927 | continue; |
| 8928 | } |
| 8929 | |
| 8930 | // Create the new updating load/store node. |
| 8931 | EVT Tys[6]; |
| 8932 | unsigned NumResultVecs = (isLoad ? NumVecs : 0); |
| 8933 | unsigned n; |
| 8934 | for (n = 0; n < NumResultVecs; ++n) |
| 8935 | Tys[n] = VecTy; |
| 8936 | Tys[n++] = MVT::i32; |
| 8937 | Tys[n] = MVT::Other; |
| 8938 | SDVTList SDTys = DAG.getVTList(Tys, NumResultVecs+2); |
| 8939 | SmallVector<SDValue, 8> Ops; |
| 8940 | Ops.push_back(N->getOperand(0)); // incoming chain |
| 8941 | Ops.push_back(N->getOperand(AddrOpIdx)); |
| 8942 | Ops.push_back(Inc); |
| 8943 | for (unsigned i = AddrOpIdx + 1; i < N->getNumOperands(); ++i) { |
| 8944 | Ops.push_back(N->getOperand(i)); |
| 8945 | } |
| 8946 | MemIntrinsicSDNode *MemInt = cast<MemIntrinsicSDNode>(N); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 8947 | SDValue UpdN = DAG.getMemIntrinsicNode(NewOpc, SDLoc(N), SDTys, |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8948 | Ops.data(), Ops.size(), |
| 8949 | MemInt->getMemoryVT(), |
| 8950 | MemInt->getMemOperand()); |
| 8951 | |
| 8952 | // Update the uses. |
| 8953 | std::vector<SDValue> NewResults; |
| 8954 | for (unsigned i = 0; i < NumResultVecs; ++i) { |
| 8955 | NewResults.push_back(SDValue(UpdN.getNode(), i)); |
| 8956 | } |
| 8957 | NewResults.push_back(SDValue(UpdN.getNode(), NumResultVecs+1)); // chain |
| 8958 | DCI.CombineTo(N, NewResults); |
| 8959 | DCI.CombineTo(User, SDValue(UpdN.getNode(), NumResultVecs)); |
| 8960 | |
| 8961 | break; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 8962 | } |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8963 | return SDValue(); |
| 8964 | } |
| 8965 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 8966 | /// CombineVLDDUP - For a VDUPLANE node N, check if its source operand is a |
| 8967 | /// vldN-lane (N > 1) intrinsic, and if all the other uses of that intrinsic |
| 8968 | /// are also VDUPLANEs. If so, combine them to a vldN-dup operation and |
| 8969 | /// return true. |
| 8970 | static bool CombineVLDDUP(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) { |
| 8971 | SelectionDAG &DAG = DCI.DAG; |
| 8972 | EVT VT = N->getValueType(0); |
| 8973 | // vldN-dup instructions only support 64-bit vectors for N > 1. |
| 8974 | if (!VT.is64BitVector()) |
| 8975 | return false; |
| 8976 | |
| 8977 | // Check if the VDUPLANE operand is a vldN-dup intrinsic. |
| 8978 | SDNode *VLD = N->getOperand(0).getNode(); |
| 8979 | if (VLD->getOpcode() != ISD::INTRINSIC_W_CHAIN) |
| 8980 | return false; |
| 8981 | unsigned NumVecs = 0; |
| 8982 | unsigned NewOpc = 0; |
| 8983 | unsigned IntNo = cast<ConstantSDNode>(VLD->getOperand(1))->getZExtValue(); |
| 8984 | if (IntNo == Intrinsic::arm_neon_vld2lane) { |
| 8985 | NumVecs = 2; |
| 8986 | NewOpc = ARMISD::VLD2DUP; |
| 8987 | } else if (IntNo == Intrinsic::arm_neon_vld3lane) { |
| 8988 | NumVecs = 3; |
| 8989 | NewOpc = ARMISD::VLD3DUP; |
| 8990 | } else if (IntNo == Intrinsic::arm_neon_vld4lane) { |
| 8991 | NumVecs = 4; |
| 8992 | NewOpc = ARMISD::VLD4DUP; |
| 8993 | } else { |
| 8994 | return false; |
| 8995 | } |
| 8996 | |
| 8997 | // First check that all the vldN-lane uses are VDUPLANEs and that the lane |
| 8998 | // numbers match the load. |
| 8999 | unsigned VLDLaneNo = |
| 9000 | cast<ConstantSDNode>(VLD->getOperand(NumVecs+3))->getZExtValue(); |
| 9001 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 9002 | UI != UE; ++UI) { |
| 9003 | // Ignore uses of the chain result. |
| 9004 | if (UI.getUse().getResNo() == NumVecs) |
| 9005 | continue; |
| 9006 | SDNode *User = *UI; |
| 9007 | if (User->getOpcode() != ARMISD::VDUPLANE || |
| 9008 | VLDLaneNo != cast<ConstantSDNode>(User->getOperand(1))->getZExtValue()) |
| 9009 | return false; |
| 9010 | } |
| 9011 | |
| 9012 | // Create the vldN-dup node. |
| 9013 | EVT Tys[5]; |
| 9014 | unsigned n; |
| 9015 | for (n = 0; n < NumVecs; ++n) |
| 9016 | Tys[n] = VT; |
| 9017 | Tys[n] = MVT::Other; |
| 9018 | SDVTList SDTys = DAG.getVTList(Tys, NumVecs+1); |
| 9019 | SDValue Ops[] = { VLD->getOperand(0), VLD->getOperand(2) }; |
| 9020 | MemIntrinsicSDNode *VLDMemInt = cast<MemIntrinsicSDNode>(VLD); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 9021 | SDValue VLDDup = DAG.getMemIntrinsicNode(NewOpc, SDLoc(VLD), SDTys, |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 9022 | Ops, 2, VLDMemInt->getMemoryVT(), |
| 9023 | VLDMemInt->getMemOperand()); |
| 9024 | |
| 9025 | // Update the uses. |
| 9026 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 9027 | UI != UE; ++UI) { |
| 9028 | unsigned ResNo = UI.getUse().getResNo(); |
| 9029 | // Ignore uses of the chain result. |
| 9030 | if (ResNo == NumVecs) |
| 9031 | continue; |
| 9032 | SDNode *User = *UI; |
| 9033 | DCI.CombineTo(User, SDValue(VLDDup.getNode(), ResNo)); |
| 9034 | } |
| 9035 | |
| 9036 | // Now the vldN-lane intrinsic is dead except for its chain result. |
| 9037 | // Update uses of the chain. |
| 9038 | std::vector<SDValue> VLDDupResults; |
| 9039 | for (unsigned n = 0; n < NumVecs; ++n) |
| 9040 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), n)); |
| 9041 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), NumVecs)); |
| 9042 | DCI.CombineTo(VLD, VLDDupResults); |
| 9043 | |
| 9044 | return true; |
| 9045 | } |
| 9046 | |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 9047 | /// PerformVDUPLANECombine - Target-specific dag combine xforms for |
| 9048 | /// ARMISD::VDUPLANE. |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 9049 | static SDValue PerformVDUPLANECombine(SDNode *N, |
| 9050 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 9051 | SDValue Op = N->getOperand(0); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 9052 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 9053 | // If the source is a vldN-lane (N > 1) intrinsic, and all the other uses |
| 9054 | // of that intrinsic are also VDUPLANEs, combine them to a vldN-dup operation. |
| 9055 | if (CombineVLDDUP(N, DCI)) |
| 9056 | return SDValue(N, 0); |
| 9057 | |
| 9058 | // If the source is already a VMOVIMM or VMVNIMM splat, the VDUPLANE is |
| 9059 | // redundant. Ignore bit_converts for now; element sizes are checked below. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 9060 | while (Op.getOpcode() == ISD::BITCAST) |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 9061 | Op = Op.getOperand(0); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 9062 | if (Op.getOpcode() != ARMISD::VMOVIMM && Op.getOpcode() != ARMISD::VMVNIMM) |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 9063 | return SDValue(); |
| 9064 | |
| 9065 | // Make sure the VMOV element size is not bigger than the VDUPLANE elements. |
| 9066 | unsigned EltSize = Op.getValueType().getVectorElementType().getSizeInBits(); |
| 9067 | // The canonical VMOV for a zero vector uses a 32-bit element size. |
| 9068 | unsigned Imm = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 9069 | unsigned EltBits; |
| 9070 | if (ARM_AM::decodeNEONModImm(Imm, EltBits) == 0) |
| 9071 | EltSize = 8; |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 9072 | EVT VT = N->getValueType(0); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 9073 | if (EltSize > VT.getVectorElementType().getSizeInBits()) |
| 9074 | return SDValue(); |
| 9075 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 9076 | return DCI.DAG.getNode(ISD::BITCAST, SDLoc(N), VT, Op); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 9077 | } |
| 9078 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 9079 | // isConstVecPow2 - Return true if each vector element is a power of 2, all |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9080 | // elements are the same constant, C, and Log2(C) ranges from 1 to 32. |
| 9081 | static bool isConstVecPow2(SDValue ConstVec, bool isSigned, uint64_t &C) |
| 9082 | { |
Chad Rosier | 118c9a0 | 2011-06-28 17:26:57 +0000 | [diff] [blame] | 9083 | integerPart cN; |
| 9084 | integerPart c0 = 0; |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9085 | for (unsigned I = 0, E = ConstVec.getValueType().getVectorNumElements(); |
| 9086 | I != E; I++) { |
| 9087 | ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(ConstVec.getOperand(I)); |
| 9088 | if (!C) |
| 9089 | return false; |
| 9090 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 9091 | bool isExact; |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9092 | APFloat APF = C->getValueAPF(); |
| 9093 | if (APF.convertToInteger(&cN, 64, isSigned, APFloat::rmTowardZero, &isExact) |
| 9094 | != APFloat::opOK || !isExact) |
| 9095 | return false; |
| 9096 | |
| 9097 | c0 = (I == 0) ? cN : c0; |
| 9098 | if (!isPowerOf2_64(cN) || c0 != cN || Log2_64(c0) < 1 || Log2_64(c0) > 32) |
| 9099 | return false; |
| 9100 | } |
| 9101 | C = c0; |
| 9102 | return true; |
| 9103 | } |
| 9104 | |
| 9105 | /// PerformVCVTCombine - VCVT (floating-point to fixed-point, Advanced SIMD) |
| 9106 | /// can replace combinations of VMUL and VCVT (floating-point to integer) |
| 9107 | /// when the VMUL has a constant operand that is a power of 2. |
| 9108 | /// |
| 9109 | /// Example (assume d17 = <float 8.000000e+00, float 8.000000e+00>): |
| 9110 | /// vmul.f32 d16, d17, d16 |
| 9111 | /// vcvt.s32.f32 d16, d16 |
| 9112 | /// becomes: |
| 9113 | /// vcvt.s32.f32 d16, d16, #3 |
| 9114 | static SDValue PerformVCVTCombine(SDNode *N, |
| 9115 | TargetLowering::DAGCombinerInfo &DCI, |
| 9116 | const ARMSubtarget *Subtarget) { |
| 9117 | SelectionDAG &DAG = DCI.DAG; |
| 9118 | SDValue Op = N->getOperand(0); |
| 9119 | |
| 9120 | if (!Subtarget->hasNEON() || !Op.getValueType().isVector() || |
| 9121 | Op.getOpcode() != ISD::FMUL) |
| 9122 | return SDValue(); |
| 9123 | |
| 9124 | uint64_t C; |
| 9125 | SDValue N0 = Op->getOperand(0); |
| 9126 | SDValue ConstVec = Op->getOperand(1); |
| 9127 | bool isSigned = N->getOpcode() == ISD::FP_TO_SINT; |
| 9128 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 9129 | if (ConstVec.getOpcode() != ISD::BUILD_VECTOR || |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9130 | !isConstVecPow2(ConstVec, isSigned, C)) |
| 9131 | return SDValue(); |
| 9132 | |
| 9133 | unsigned IntrinsicOpcode = isSigned ? Intrinsic::arm_neon_vcvtfp2fxs : |
| 9134 | Intrinsic::arm_neon_vcvtfp2fxu; |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 9135 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, SDLoc(N), |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9136 | N->getValueType(0), |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 9137 | DAG.getConstant(IntrinsicOpcode, MVT::i32), N0, |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9138 | DAG.getConstant(Log2_64(C), MVT::i32)); |
| 9139 | } |
| 9140 | |
| 9141 | /// PerformVDIVCombine - VCVT (fixed-point to floating-point, Advanced SIMD) |
| 9142 | /// can replace combinations of VCVT (integer to floating-point) and VDIV |
| 9143 | /// when the VDIV has a constant operand that is a power of 2. |
| 9144 | /// |
| 9145 | /// Example (assume d17 = <float 8.000000e+00, float 8.000000e+00>): |
| 9146 | /// vcvt.f32.s32 d16, d16 |
| 9147 | /// vdiv.f32 d16, d17, d16 |
| 9148 | /// becomes: |
| 9149 | /// vcvt.f32.s32 d16, d16, #3 |
| 9150 | static SDValue PerformVDIVCombine(SDNode *N, |
| 9151 | TargetLowering::DAGCombinerInfo &DCI, |
| 9152 | const ARMSubtarget *Subtarget) { |
| 9153 | SelectionDAG &DAG = DCI.DAG; |
| 9154 | SDValue Op = N->getOperand(0); |
| 9155 | unsigned OpOpcode = Op.getNode()->getOpcode(); |
| 9156 | |
| 9157 | if (!Subtarget->hasNEON() || !N->getValueType(0).isVector() || |
| 9158 | (OpOpcode != ISD::SINT_TO_FP && OpOpcode != ISD::UINT_TO_FP)) |
| 9159 | return SDValue(); |
| 9160 | |
| 9161 | uint64_t C; |
| 9162 | SDValue ConstVec = N->getOperand(1); |
| 9163 | bool isSigned = OpOpcode == ISD::SINT_TO_FP; |
| 9164 | |
| 9165 | if (ConstVec.getOpcode() != ISD::BUILD_VECTOR || |
| 9166 | !isConstVecPow2(ConstVec, isSigned, C)) |
| 9167 | return SDValue(); |
| 9168 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 9169 | unsigned IntrinsicOpcode = isSigned ? Intrinsic::arm_neon_vcvtfxs2fp : |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9170 | Intrinsic::arm_neon_vcvtfxu2fp; |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 9171 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, SDLoc(N), |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9172 | Op.getValueType(), |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 9173 | DAG.getConstant(IntrinsicOpcode, MVT::i32), |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9174 | Op.getOperand(0), DAG.getConstant(Log2_64(C), MVT::i32)); |
| 9175 | } |
| 9176 | |
| 9177 | /// Getvshiftimm - Check if this is a valid build_vector for the immediate |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9178 | /// operand of a vector shift operation, where all the elements of the |
| 9179 | /// build_vector must have the same constant integer value. |
| 9180 | static bool getVShiftImm(SDValue Op, unsigned ElementBits, int64_t &Cnt) { |
| 9181 | // Ignore bit_converts. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 9182 | while (Op.getOpcode() == ISD::BITCAST) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9183 | Op = Op.getOperand(0); |
| 9184 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(Op.getNode()); |
| 9185 | APInt SplatBits, SplatUndef; |
| 9186 | unsigned SplatBitSize; |
| 9187 | bool HasAnyUndefs; |
| 9188 | if (! BVN || ! BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, |
| 9189 | HasAnyUndefs, ElementBits) || |
| 9190 | SplatBitSize > ElementBits) |
| 9191 | return false; |
| 9192 | Cnt = SplatBits.getSExtValue(); |
| 9193 | return true; |
| 9194 | } |
| 9195 | |
| 9196 | /// isVShiftLImm - Check if this is a valid build_vector for the immediate |
| 9197 | /// operand of a vector shift left operation. That value must be in the range: |
| 9198 | /// 0 <= Value < ElementBits for a left shift; or |
| 9199 | /// 0 <= Value <= ElementBits for a long left shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9200 | static bool isVShiftLImm(SDValue Op, EVT VT, bool isLong, int64_t &Cnt) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9201 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 9202 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 9203 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 9204 | return false; |
| 9205 | return (Cnt >= 0 && (isLong ? Cnt-1 : Cnt) < ElementBits); |
| 9206 | } |
| 9207 | |
| 9208 | /// isVShiftRImm - Check if this is a valid build_vector for the immediate |
| 9209 | /// operand of a vector shift right operation. For a shift opcode, the value |
| 9210 | /// is positive, but for an intrinsic the value count must be negative. The |
| 9211 | /// absolute value must be in the range: |
| 9212 | /// 1 <= |Value| <= ElementBits for a right shift; or |
| 9213 | /// 1 <= |Value| <= ElementBits/2 for a narrow right shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9214 | static bool isVShiftRImm(SDValue Op, EVT VT, bool isNarrow, bool isIntrinsic, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9215 | int64_t &Cnt) { |
| 9216 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 9217 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 9218 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 9219 | return false; |
| 9220 | if (isIntrinsic) |
| 9221 | Cnt = -Cnt; |
| 9222 | return (Cnt >= 1 && Cnt <= (isNarrow ? ElementBits/2 : ElementBits)); |
| 9223 | } |
| 9224 | |
| 9225 | /// PerformIntrinsicCombine - ARM-specific DAG combining for intrinsics. |
| 9226 | static SDValue PerformIntrinsicCombine(SDNode *N, SelectionDAG &DAG) { |
| 9227 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue(); |
| 9228 | switch (IntNo) { |
| 9229 | default: |
| 9230 | // Don't do anything for most intrinsics. |
| 9231 | break; |
| 9232 | |
| 9233 | // Vector shifts: check for immediate versions and lower them. |
| 9234 | // Note: This is done during DAG combining instead of DAG legalizing because |
| 9235 | // the build_vectors for 64-bit vector element shift counts are generally |
| 9236 | // not legal, and it is hard to see their values after they get legalized to |
| 9237 | // loads from a constant pool. |
| 9238 | case Intrinsic::arm_neon_vshifts: |
| 9239 | case Intrinsic::arm_neon_vshiftu: |
| 9240 | case Intrinsic::arm_neon_vshiftls: |
| 9241 | case Intrinsic::arm_neon_vshiftlu: |
| 9242 | case Intrinsic::arm_neon_vshiftn: |
| 9243 | case Intrinsic::arm_neon_vrshifts: |
| 9244 | case Intrinsic::arm_neon_vrshiftu: |
| 9245 | case Intrinsic::arm_neon_vrshiftn: |
| 9246 | case Intrinsic::arm_neon_vqshifts: |
| 9247 | case Intrinsic::arm_neon_vqshiftu: |
| 9248 | case Intrinsic::arm_neon_vqshiftsu: |
| 9249 | case Intrinsic::arm_neon_vqshiftns: |
| 9250 | case Intrinsic::arm_neon_vqshiftnu: |
| 9251 | case Intrinsic::arm_neon_vqshiftnsu: |
| 9252 | case Intrinsic::arm_neon_vqrshiftns: |
| 9253 | case Intrinsic::arm_neon_vqrshiftnu: |
| 9254 | case Intrinsic::arm_neon_vqrshiftnsu: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9255 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9256 | int64_t Cnt; |
| 9257 | unsigned VShiftOpc = 0; |
| 9258 | |
| 9259 | switch (IntNo) { |
| 9260 | case Intrinsic::arm_neon_vshifts: |
| 9261 | case Intrinsic::arm_neon_vshiftu: |
| 9262 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) { |
| 9263 | VShiftOpc = ARMISD::VSHL; |
| 9264 | break; |
| 9265 | } |
| 9266 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) { |
| 9267 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshifts ? |
| 9268 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 9269 | break; |
| 9270 | } |
| 9271 | return SDValue(); |
| 9272 | |
| 9273 | case Intrinsic::arm_neon_vshiftls: |
| 9274 | case Intrinsic::arm_neon_vshiftlu: |
| 9275 | if (isVShiftLImm(N->getOperand(2), VT, true, Cnt)) |
| 9276 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 9277 | llvm_unreachable("invalid shift count for vshll intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9278 | |
| 9279 | case Intrinsic::arm_neon_vrshifts: |
| 9280 | case Intrinsic::arm_neon_vrshiftu: |
| 9281 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) |
| 9282 | break; |
| 9283 | return SDValue(); |
| 9284 | |
| 9285 | case Intrinsic::arm_neon_vqshifts: |
| 9286 | case Intrinsic::arm_neon_vqshiftu: |
| 9287 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 9288 | break; |
| 9289 | return SDValue(); |
| 9290 | |
| 9291 | case Intrinsic::arm_neon_vqshiftsu: |
| 9292 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 9293 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 9294 | llvm_unreachable("invalid shift count for vqshlu intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9295 | |
| 9296 | case Intrinsic::arm_neon_vshiftn: |
| 9297 | case Intrinsic::arm_neon_vrshiftn: |
| 9298 | case Intrinsic::arm_neon_vqshiftns: |
| 9299 | case Intrinsic::arm_neon_vqshiftnu: |
| 9300 | case Intrinsic::arm_neon_vqshiftnsu: |
| 9301 | case Intrinsic::arm_neon_vqrshiftns: |
| 9302 | case Intrinsic::arm_neon_vqrshiftnu: |
| 9303 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 9304 | // Narrowing shifts require an immediate right shift. |
| 9305 | if (isVShiftRImm(N->getOperand(2), VT, true, true, Cnt)) |
| 9306 | break; |
Jim Grosbach | 18f30e6 | 2010-06-02 21:53:11 +0000 | [diff] [blame] | 9307 | llvm_unreachable("invalid shift count for narrowing vector shift " |
| 9308 | "intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9309 | |
| 9310 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 9311 | llvm_unreachable("unhandled vector shift"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9312 | } |
| 9313 | |
| 9314 | switch (IntNo) { |
| 9315 | case Intrinsic::arm_neon_vshifts: |
| 9316 | case Intrinsic::arm_neon_vshiftu: |
| 9317 | // Opcode already set above. |
| 9318 | break; |
| 9319 | case Intrinsic::arm_neon_vshiftls: |
| 9320 | case Intrinsic::arm_neon_vshiftlu: |
| 9321 | if (Cnt == VT.getVectorElementType().getSizeInBits()) |
| 9322 | VShiftOpc = ARMISD::VSHLLi; |
| 9323 | else |
| 9324 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshiftls ? |
| 9325 | ARMISD::VSHLLs : ARMISD::VSHLLu); |
| 9326 | break; |
| 9327 | case Intrinsic::arm_neon_vshiftn: |
| 9328 | VShiftOpc = ARMISD::VSHRN; break; |
| 9329 | case Intrinsic::arm_neon_vrshifts: |
| 9330 | VShiftOpc = ARMISD::VRSHRs; break; |
| 9331 | case Intrinsic::arm_neon_vrshiftu: |
| 9332 | VShiftOpc = ARMISD::VRSHRu; break; |
| 9333 | case Intrinsic::arm_neon_vrshiftn: |
| 9334 | VShiftOpc = ARMISD::VRSHRN; break; |
| 9335 | case Intrinsic::arm_neon_vqshifts: |
| 9336 | VShiftOpc = ARMISD::VQSHLs; break; |
| 9337 | case Intrinsic::arm_neon_vqshiftu: |
| 9338 | VShiftOpc = ARMISD::VQSHLu; break; |
| 9339 | case Intrinsic::arm_neon_vqshiftsu: |
| 9340 | VShiftOpc = ARMISD::VQSHLsu; break; |
| 9341 | case Intrinsic::arm_neon_vqshiftns: |
| 9342 | VShiftOpc = ARMISD::VQSHRNs; break; |
| 9343 | case Intrinsic::arm_neon_vqshiftnu: |
| 9344 | VShiftOpc = ARMISD::VQSHRNu; break; |
| 9345 | case Intrinsic::arm_neon_vqshiftnsu: |
| 9346 | VShiftOpc = ARMISD::VQSHRNsu; break; |
| 9347 | case Intrinsic::arm_neon_vqrshiftns: |
| 9348 | VShiftOpc = ARMISD::VQRSHRNs; break; |
| 9349 | case Intrinsic::arm_neon_vqrshiftnu: |
| 9350 | VShiftOpc = ARMISD::VQRSHRNu; break; |
| 9351 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 9352 | VShiftOpc = ARMISD::VQRSHRNsu; break; |
| 9353 | } |
| 9354 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 9355 | return DAG.getNode(VShiftOpc, SDLoc(N), N->getValueType(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9356 | N->getOperand(1), DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9357 | } |
| 9358 | |
| 9359 | case Intrinsic::arm_neon_vshiftins: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9360 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9361 | int64_t Cnt; |
| 9362 | unsigned VShiftOpc = 0; |
| 9363 | |
| 9364 | if (isVShiftLImm(N->getOperand(3), VT, false, Cnt)) |
| 9365 | VShiftOpc = ARMISD::VSLI; |
| 9366 | else if (isVShiftRImm(N->getOperand(3), VT, false, true, Cnt)) |
| 9367 | VShiftOpc = ARMISD::VSRI; |
| 9368 | else { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 9369 | llvm_unreachable("invalid shift count for vsli/vsri intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9370 | } |
| 9371 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 9372 | return DAG.getNode(VShiftOpc, SDLoc(N), N->getValueType(0), |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9373 | N->getOperand(1), N->getOperand(2), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9374 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9375 | } |
| 9376 | |
| 9377 | case Intrinsic::arm_neon_vqrshifts: |
| 9378 | case Intrinsic::arm_neon_vqrshiftu: |
| 9379 | // No immediate versions of these to check for. |
| 9380 | break; |
| 9381 | } |
| 9382 | |
| 9383 | return SDValue(); |
| 9384 | } |
| 9385 | |
| 9386 | /// PerformShiftCombine - Checks for immediate versions of vector shifts and |
| 9387 | /// lowers them. As with the vector shift intrinsics, this is done during DAG |
| 9388 | /// combining instead of DAG legalizing because the build_vectors for 64-bit |
| 9389 | /// vector element shift counts are generally not legal, and it is hard to see |
| 9390 | /// their values after they get legalized to loads from a constant pool. |
| 9391 | static SDValue PerformShiftCombine(SDNode *N, SelectionDAG &DAG, |
| 9392 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9393 | EVT VT = N->getValueType(0); |
Evan Cheng | 5fb468a | 2012-02-23 02:58:19 +0000 | [diff] [blame] | 9394 | if (N->getOpcode() == ISD::SRL && VT == MVT::i32 && ST->hasV6Ops()) { |
| 9395 | // Canonicalize (srl (bswap x), 16) to (rotr (bswap x), 16) if the high |
| 9396 | // 16-bits of x is zero. This optimizes rev + lsr 16 to rev16. |
| 9397 | SDValue N1 = N->getOperand(1); |
| 9398 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N1)) { |
| 9399 | SDValue N0 = N->getOperand(0); |
| 9400 | if (C->getZExtValue() == 16 && N0.getOpcode() == ISD::BSWAP && |
| 9401 | DAG.MaskedValueIsZero(N0.getOperand(0), |
| 9402 | APInt::getHighBitsSet(32, 16))) |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 9403 | return DAG.getNode(ISD::ROTR, SDLoc(N), VT, N0, N1); |
Evan Cheng | 5fb468a | 2012-02-23 02:58:19 +0000 | [diff] [blame] | 9404 | } |
| 9405 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9406 | |
| 9407 | // Nothing to be done for scalar shifts. |
Tanya Lattner | 9684a7c | 2010-11-18 22:06:46 +0000 | [diff] [blame] | 9408 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 9409 | if (!VT.isVector() || !TLI.isTypeLegal(VT)) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9410 | return SDValue(); |
| 9411 | |
| 9412 | assert(ST->hasNEON() && "unexpected vector shift"); |
| 9413 | int64_t Cnt; |
| 9414 | |
| 9415 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 9416 | default: llvm_unreachable("unexpected shift opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9417 | |
| 9418 | case ISD::SHL: |
| 9419 | if (isVShiftLImm(N->getOperand(1), VT, false, Cnt)) |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 9420 | return DAG.getNode(ARMISD::VSHL, SDLoc(N), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9421 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9422 | break; |
| 9423 | |
| 9424 | case ISD::SRA: |
| 9425 | case ISD::SRL: |
| 9426 | if (isVShiftRImm(N->getOperand(1), VT, false, false, Cnt)) { |
| 9427 | unsigned VShiftOpc = (N->getOpcode() == ISD::SRA ? |
| 9428 | ARMISD::VSHRs : ARMISD::VSHRu); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 9429 | return DAG.getNode(VShiftOpc, SDLoc(N), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9430 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9431 | } |
| 9432 | } |
| 9433 | return SDValue(); |
| 9434 | } |
| 9435 | |
| 9436 | /// PerformExtendCombine - Target-specific DAG combining for ISD::SIGN_EXTEND, |
| 9437 | /// ISD::ZERO_EXTEND, and ISD::ANY_EXTEND. |
| 9438 | static SDValue PerformExtendCombine(SDNode *N, SelectionDAG &DAG, |
| 9439 | const ARMSubtarget *ST) { |
| 9440 | SDValue N0 = N->getOperand(0); |
| 9441 | |
| 9442 | // Check for sign- and zero-extensions of vector extract operations of 8- |
| 9443 | // and 16-bit vector elements. NEON supports these directly. They are |
| 9444 | // handled during DAG combining because type legalization will promote them |
| 9445 | // to 32-bit types and it is messy to recognize the operations after that. |
| 9446 | if (ST->hasNEON() && N0.getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
| 9447 | SDValue Vec = N0.getOperand(0); |
| 9448 | SDValue Lane = N0.getOperand(1); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9449 | EVT VT = N->getValueType(0); |
| 9450 | EVT EltVT = N0.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9451 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 9452 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9453 | if (VT == MVT::i32 && |
| 9454 | (EltVT == MVT::i8 || EltVT == MVT::i16) && |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 9455 | TLI.isTypeLegal(Vec.getValueType()) && |
| 9456 | isa<ConstantSDNode>(Lane)) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9457 | |
| 9458 | unsigned Opc = 0; |
| 9459 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 9460 | default: llvm_unreachable("unexpected opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9461 | case ISD::SIGN_EXTEND: |
| 9462 | Opc = ARMISD::VGETLANEs; |
| 9463 | break; |
| 9464 | case ISD::ZERO_EXTEND: |
| 9465 | case ISD::ANY_EXTEND: |
| 9466 | Opc = ARMISD::VGETLANEu; |
| 9467 | break; |
| 9468 | } |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 9469 | return DAG.getNode(Opc, SDLoc(N), VT, Vec, Lane); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9470 | } |
| 9471 | } |
| 9472 | |
| 9473 | return SDValue(); |
| 9474 | } |
| 9475 | |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9476 | /// PerformSELECT_CCCombine - Target-specific DAG combining for ISD::SELECT_CC |
| 9477 | /// to match f32 max/min patterns to use NEON vmax/vmin instructions. |
| 9478 | static SDValue PerformSELECT_CCCombine(SDNode *N, SelectionDAG &DAG, |
| 9479 | const ARMSubtarget *ST) { |
| 9480 | // If the target supports NEON, try to use vmax/vmin instructions for f32 |
Evan Cheng | 60108e9 | 2010-07-15 22:07:12 +0000 | [diff] [blame] | 9481 | // selects like "x < y ? x : y". Unless the NoNaNsFPMath option is set, |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9482 | // be careful about NaNs: NEON's vmax/vmin return NaN if either operand is |
| 9483 | // a NaN; only do the transformation when it matches that behavior. |
| 9484 | |
| 9485 | // For now only do this when using NEON for FP operations; if using VFP, it |
| 9486 | // is not obvious that the benefit outweighs the cost of switching to the |
| 9487 | // NEON pipeline. |
| 9488 | if (!ST->hasNEON() || !ST->useNEONForSinglePrecisionFP() || |
| 9489 | N->getValueType(0) != MVT::f32) |
| 9490 | return SDValue(); |
| 9491 | |
| 9492 | SDValue CondLHS = N->getOperand(0); |
| 9493 | SDValue CondRHS = N->getOperand(1); |
| 9494 | SDValue LHS = N->getOperand(2); |
| 9495 | SDValue RHS = N->getOperand(3); |
| 9496 | ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(4))->get(); |
| 9497 | |
| 9498 | unsigned Opcode = 0; |
| 9499 | bool IsReversed; |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9500 | if (DAG.isEqualTo(LHS, CondLHS) && DAG.isEqualTo(RHS, CondRHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9501 | IsReversed = false; // x CC y ? x : y |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9502 | } else if (DAG.isEqualTo(LHS, CondRHS) && DAG.isEqualTo(RHS, CondLHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9503 | IsReversed = true ; // x CC y ? y : x |
| 9504 | } else { |
| 9505 | return SDValue(); |
| 9506 | } |
| 9507 | |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9508 | bool IsUnordered; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9509 | switch (CC) { |
| 9510 | default: break; |
| 9511 | case ISD::SETOLT: |
| 9512 | case ISD::SETOLE: |
| 9513 | case ISD::SETLT: |
| 9514 | case ISD::SETLE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9515 | case ISD::SETULT: |
| 9516 | case ISD::SETULE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9517 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 9518 | // be the RHS, but vmin(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 9519 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 9520 | IsUnordered = (CC == ISD::SETULT || CC == ISD::SETULE); |
| 9521 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 9522 | break; |
| 9523 | // For less-than-or-equal comparisons, "+0 <= -0" will be true but vmin |
| 9524 | // will return -0, so vmin can only be used for unsafe math or if one of |
| 9525 | // the operands is known to be nonzero. |
| 9526 | if ((CC == ISD::SETLE || CC == ISD::SETOLE || CC == ISD::SETULE) && |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 9527 | !DAG.getTarget().Options.UnsafeFPMath && |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9528 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 9529 | break; |
| 9530 | Opcode = IsReversed ? ARMISD::FMAX : ARMISD::FMIN; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9531 | break; |
| 9532 | |
| 9533 | case ISD::SETOGT: |
| 9534 | case ISD::SETOGE: |
| 9535 | case ISD::SETGT: |
| 9536 | case ISD::SETGE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9537 | case ISD::SETUGT: |
| 9538 | case ISD::SETUGE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9539 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 9540 | // be the RHS, but vmax(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 9541 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 9542 | IsUnordered = (CC == ISD::SETUGT || CC == ISD::SETUGE); |
| 9543 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 9544 | break; |
| 9545 | // For greater-than-or-equal comparisons, "-0 >= +0" will be true but vmax |
| 9546 | // will return +0, so vmax can only be used for unsafe math or if one of |
| 9547 | // the operands is known to be nonzero. |
| 9548 | if ((CC == ISD::SETGE || CC == ISD::SETOGE || CC == ISD::SETUGE) && |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 9549 | !DAG.getTarget().Options.UnsafeFPMath && |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9550 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 9551 | break; |
| 9552 | Opcode = IsReversed ? ARMISD::FMIN : ARMISD::FMAX; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9553 | break; |
| 9554 | } |
| 9555 | |
| 9556 | if (!Opcode) |
| 9557 | return SDValue(); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 9558 | return DAG.getNode(Opcode, SDLoc(N), N->getValueType(0), LHS, RHS); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9559 | } |
| 9560 | |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 9561 | /// PerformCMOVCombine - Target-specific DAG combining for ARMISD::CMOV. |
| 9562 | SDValue |
| 9563 | ARMTargetLowering::PerformCMOVCombine(SDNode *N, SelectionDAG &DAG) const { |
| 9564 | SDValue Cmp = N->getOperand(4); |
| 9565 | if (Cmp.getOpcode() != ARMISD::CMPZ) |
| 9566 | // Only looking at EQ and NE cases. |
| 9567 | return SDValue(); |
| 9568 | |
| 9569 | EVT VT = N->getValueType(0); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame^] | 9570 | SDLoc dl(N); |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 9571 | SDValue LHS = Cmp.getOperand(0); |
| 9572 | SDValue RHS = Cmp.getOperand(1); |
| 9573 | SDValue FalseVal = N->getOperand(0); |
| 9574 | SDValue TrueVal = N->getOperand(1); |
| 9575 | SDValue ARMcc = N->getOperand(2); |
Jim Grosbach | b04546f | 2011-09-13 20:30:37 +0000 | [diff] [blame] | 9576 | ARMCC::CondCodes CC = |
| 9577 | (ARMCC::CondCodes)cast<ConstantSDNode>(ARMcc)->getZExtValue(); |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 9578 | |
| 9579 | // Simplify |
| 9580 | // mov r1, r0 |
| 9581 | // cmp r1, x |
| 9582 | // mov r0, y |
| 9583 | // moveq r0, x |
| 9584 | // to |
| 9585 | // cmp r0, x |
| 9586 | // movne r0, y |
| 9587 | // |
| 9588 | // mov r1, r0 |
| 9589 | // cmp r1, x |
| 9590 | // mov r0, x |
| 9591 | // movne r0, y |
| 9592 | // to |
| 9593 | // cmp r0, x |
| 9594 | // movne r0, y |
| 9595 | /// FIXME: Turn this into a target neutral optimization? |
| 9596 | SDValue Res; |
Evan Cheng | 9b88d2d | 2011-09-28 23:16:31 +0000 | [diff] [blame] | 9597 | if (CC == ARMCC::NE && FalseVal == RHS && FalseVal != LHS) { |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 9598 | Res = DAG.getNode(ARMISD::CMOV, dl, VT, LHS, TrueVal, ARMcc, |
| 9599 | N->getOperand(3), Cmp); |
| 9600 | } else if (CC == ARMCC::EQ && TrueVal == RHS) { |
| 9601 | SDValue ARMcc; |
| 9602 | SDValue NewCmp = getARMCmp(LHS, RHS, ISD::SETNE, ARMcc, DAG, dl); |
| 9603 | Res = DAG.getNode(ARMISD::CMOV, dl, VT, LHS, FalseVal, ARMcc, |
| 9604 | N->getOperand(3), NewCmp); |
| 9605 | } |
| 9606 | |
| 9607 | if (Res.getNode()) { |
| 9608 | APInt KnownZero, KnownOne; |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 9609 | DAG.ComputeMaskedBits(SDValue(N,0), KnownZero, KnownOne); |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 9610 | // Capture demanded bits information that would be otherwise lost. |
| 9611 | if (KnownZero == 0xfffffffe) |
| 9612 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 9613 | DAG.getValueType(MVT::i1)); |
| 9614 | else if (KnownZero == 0xffffff00) |
| 9615 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 9616 | DAG.getValueType(MVT::i8)); |
| 9617 | else if (KnownZero == 0xffff0000) |
| 9618 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 9619 | DAG.getValueType(MVT::i16)); |
| 9620 | } |
| 9621 | |
| 9622 | return Res; |
| 9623 | } |
| 9624 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 9625 | SDValue ARMTargetLowering::PerformDAGCombine(SDNode *N, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9626 | DAGCombinerInfo &DCI) const { |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 9627 | switch (N->getOpcode()) { |
| 9628 | default: break; |
Arnold Schwaighofer | 67514e9 | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 9629 | case ISD::ADDC: return PerformADDCCombine(N, DCI, Subtarget); |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 9630 | case ISD::ADD: return PerformADDCombine(N, DCI, Subtarget); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9631 | case ISD::SUB: return PerformSUBCombine(N, DCI); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 9632 | case ISD::MUL: return PerformMULCombine(N, DCI, Subtarget); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 9633 | case ISD::OR: return PerformORCombine(N, DCI, Subtarget); |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 9634 | case ISD::XOR: return PerformXORCombine(N, DCI, Subtarget); |
| 9635 | case ISD::AND: return PerformANDCombine(N, DCI, Subtarget); |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 9636 | case ARMISD::BFI: return PerformBFICombine(N, DCI); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 9637 | case ARMISD::VMOVRRD: return PerformVMOVRRDCombine(N, DCI); |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 9638 | case ARMISD::VMOVDRR: return PerformVMOVDRRCombine(N, DCI.DAG); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 9639 | case ISD::STORE: return PerformSTORECombine(N, DCI); |
| 9640 | case ISD::BUILD_VECTOR: return PerformBUILD_VECTORCombine(N, DCI); |
| 9641 | case ISD::INSERT_VECTOR_ELT: return PerformInsertEltCombine(N, DCI); |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 9642 | case ISD::VECTOR_SHUFFLE: return PerformVECTOR_SHUFFLECombine(N, DCI.DAG); |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 9643 | case ARMISD::VDUPLANE: return PerformVDUPLANECombine(N, DCI); |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9644 | case ISD::FP_TO_SINT: |
| 9645 | case ISD::FP_TO_UINT: return PerformVCVTCombine(N, DCI, Subtarget); |
| 9646 | case ISD::FDIV: return PerformVDIVCombine(N, DCI, Subtarget); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9647 | case ISD::INTRINSIC_WO_CHAIN: return PerformIntrinsicCombine(N, DCI.DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9648 | case ISD::SHL: |
| 9649 | case ISD::SRA: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9650 | case ISD::SRL: return PerformShiftCombine(N, DCI.DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9651 | case ISD::SIGN_EXTEND: |
| 9652 | case ISD::ZERO_EXTEND: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9653 | case ISD::ANY_EXTEND: return PerformExtendCombine(N, DCI.DAG, Subtarget); |
| 9654 | case ISD::SELECT_CC: return PerformSELECT_CCCombine(N, DCI.DAG, Subtarget); |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 9655 | case ARMISD::CMOV: return PerformCMOVCombine(N, DCI.DAG); |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9656 | case ARMISD::VLD2DUP: |
| 9657 | case ARMISD::VLD3DUP: |
| 9658 | case ARMISD::VLD4DUP: |
| 9659 | return CombineBaseUpdate(N, DCI); |
| 9660 | case ISD::INTRINSIC_VOID: |
| 9661 | case ISD::INTRINSIC_W_CHAIN: |
| 9662 | switch (cast<ConstantSDNode>(N->getOperand(1))->getZExtValue()) { |
| 9663 | case Intrinsic::arm_neon_vld1: |
| 9664 | case Intrinsic::arm_neon_vld2: |
| 9665 | case Intrinsic::arm_neon_vld3: |
| 9666 | case Intrinsic::arm_neon_vld4: |
| 9667 | case Intrinsic::arm_neon_vld2lane: |
| 9668 | case Intrinsic::arm_neon_vld3lane: |
| 9669 | case Intrinsic::arm_neon_vld4lane: |
| 9670 | case Intrinsic::arm_neon_vst1: |
| 9671 | case Intrinsic::arm_neon_vst2: |
| 9672 | case Intrinsic::arm_neon_vst3: |
| 9673 | case Intrinsic::arm_neon_vst4: |
| 9674 | case Intrinsic::arm_neon_vst2lane: |
| 9675 | case Intrinsic::arm_neon_vst3lane: |
| 9676 | case Intrinsic::arm_neon_vst4lane: |
| 9677 | return CombineBaseUpdate(N, DCI); |
| 9678 | default: break; |
| 9679 | } |
| 9680 | break; |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 9681 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 9682 | return SDValue(); |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 9683 | } |
| 9684 | |
Evan Cheng | 31959b1 | 2011-02-02 01:06:55 +0000 | [diff] [blame] | 9685 | bool ARMTargetLowering::isDesirableToTransformToIntegerOp(unsigned Opc, |
| 9686 | EVT VT) const { |
| 9687 | return (VT == MVT::f32) && (Opc == ISD::LOAD || Opc == ISD::STORE); |
| 9688 | } |
| 9689 | |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9690 | bool ARMTargetLowering::allowsUnalignedMemoryAccesses(EVT VT, bool *Fast) const { |
Evan Cheng | d10eab0 | 2012-09-18 01:42:45 +0000 | [diff] [blame] | 9691 | // The AllowsUnaliged flag models the SCTLR.A setting in ARM cpus |
Chad Rosier | b3235b1 | 2012-11-09 18:25:27 +0000 | [diff] [blame] | 9692 | bool AllowsUnaligned = Subtarget->allowsUnalignedMem(); |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 9693 | |
| 9694 | switch (VT.getSimpleVT().SimpleTy) { |
| 9695 | default: |
| 9696 | return false; |
| 9697 | case MVT::i8: |
| 9698 | case MVT::i16: |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9699 | case MVT::i32: { |
Evan Cheng | d10eab0 | 2012-09-18 01:42:45 +0000 | [diff] [blame] | 9700 | // Unaligned access can use (for example) LRDB, LRDH, LDR |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9701 | if (AllowsUnaligned) { |
| 9702 | if (Fast) |
| 9703 | *Fast = Subtarget->hasV7Ops(); |
| 9704 | return true; |
| 9705 | } |
| 9706 | return false; |
| 9707 | } |
Evan Cheng | a99c508 | 2012-08-15 17:44:53 +0000 | [diff] [blame] | 9708 | case MVT::f64: |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9709 | case MVT::v2f64: { |
Evan Cheng | d10eab0 | 2012-09-18 01:42:45 +0000 | [diff] [blame] | 9710 | // For any little-endian targets with neon, we can support unaligned ld/st |
| 9711 | // of D and Q (e.g. {D0,D1}) registers by using vld1.i8/vst1.i8. |
| 9712 | // A big-endian target may also explictly support unaligned accesses |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9713 | if (Subtarget->hasNEON() && (AllowsUnaligned || isLittleEndian())) { |
| 9714 | if (Fast) |
| 9715 | *Fast = true; |
| 9716 | return true; |
| 9717 | } |
| 9718 | return false; |
| 9719 | } |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 9720 | } |
| 9721 | } |
| 9722 | |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 9723 | static bool memOpAlign(unsigned DstAlign, unsigned SrcAlign, |
| 9724 | unsigned AlignCheck) { |
| 9725 | return ((SrcAlign == 0 || SrcAlign % AlignCheck == 0) && |
| 9726 | (DstAlign == 0 || DstAlign % AlignCheck == 0)); |
| 9727 | } |
| 9728 | |
| 9729 | EVT ARMTargetLowering::getOptimalMemOpType(uint64_t Size, |
| 9730 | unsigned DstAlign, unsigned SrcAlign, |
Evan Cheng | 946a3a9 | 2012-12-12 02:34:41 +0000 | [diff] [blame] | 9731 | bool IsMemset, bool ZeroMemset, |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 9732 | bool MemcpyStrSrc, |
| 9733 | MachineFunction &MF) const { |
| 9734 | const Function *F = MF.getFunction(); |
| 9735 | |
| 9736 | // See if we can use NEON instructions for this... |
Evan Cheng | 946a3a9 | 2012-12-12 02:34:41 +0000 | [diff] [blame] | 9737 | if ((!IsMemset || ZeroMemset) && |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9738 | Subtarget->hasNEON() && |
Bill Wendling | 831737d | 2012-12-30 10:32:01 +0000 | [diff] [blame] | 9739 | !F->getAttributes().hasAttribute(AttributeSet::FunctionIndex, |
| 9740 | Attribute::NoImplicitFloat)) { |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9741 | bool Fast; |
Evan Cheng | 6a1b5cc | 2012-12-11 02:31:57 +0000 | [diff] [blame] | 9742 | if (Size >= 16 && |
| 9743 | (memOpAlign(SrcAlign, DstAlign, 16) || |
| 9744 | (allowsUnalignedMemoryAccesses(MVT::v2f64, &Fast) && Fast))) { |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9745 | return MVT::v2f64; |
Evan Cheng | 6a1b5cc | 2012-12-11 02:31:57 +0000 | [diff] [blame] | 9746 | } else if (Size >= 8 && |
| 9747 | (memOpAlign(SrcAlign, DstAlign, 8) || |
| 9748 | (allowsUnalignedMemoryAccesses(MVT::f64, &Fast) && Fast))) { |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 9749 | return MVT::f64; |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 9750 | } |
| 9751 | } |
| 9752 | |
Lang Hames | 5207bf2 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 9753 | // Lowering to i32/i16 if the size permits. |
Evan Cheng | 6a1b5cc | 2012-12-11 02:31:57 +0000 | [diff] [blame] | 9754 | if (Size >= 4) |
Lang Hames | 5207bf2 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 9755 | return MVT::i32; |
Evan Cheng | 6a1b5cc | 2012-12-11 02:31:57 +0000 | [diff] [blame] | 9756 | else if (Size >= 2) |
Lang Hames | 5207bf2 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 9757 | return MVT::i16; |
Lang Hames | 5207bf2 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 9758 | |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 9759 | // Let the target-independent logic figure it out. |
| 9760 | return MVT::Other; |
| 9761 | } |
| 9762 | |
Evan Cheng | 2766a47 | 2012-12-06 19:13:27 +0000 | [diff] [blame] | 9763 | bool ARMTargetLowering::isZExtFree(SDValue Val, EVT VT2) const { |
| 9764 | if (Val.getOpcode() != ISD::LOAD) |
| 9765 | return false; |
| 9766 | |
| 9767 | EVT VT1 = Val.getValueType(); |
| 9768 | if (!VT1.isSimple() || !VT1.isInteger() || |
| 9769 | !VT2.isSimple() || !VT2.isInteger()) |
| 9770 | return false; |
| 9771 | |
| 9772 | switch (VT1.getSimpleVT().SimpleTy) { |
| 9773 | default: break; |
| 9774 | case MVT::i1: |
| 9775 | case MVT::i8: |
| 9776 | case MVT::i16: |
| 9777 | // 8-bit and 16-bit loads implicitly zero-extend to 32-bits. |
| 9778 | return true; |
| 9779 | } |
| 9780 | |
| 9781 | return false; |
| 9782 | } |
| 9783 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9784 | static bool isLegalT1AddressImmediate(int64_t V, EVT VT) { |
| 9785 | if (V < 0) |
| 9786 | return false; |
| 9787 | |
| 9788 | unsigned Scale = 1; |
| 9789 | switch (VT.getSimpleVT().SimpleTy) { |
| 9790 | default: return false; |
| 9791 | case MVT::i1: |
| 9792 | case MVT::i8: |
| 9793 | // Scale == 1; |
| 9794 | break; |
| 9795 | case MVT::i16: |
| 9796 | // Scale == 2; |
| 9797 | Scale = 2; |
| 9798 | break; |
| 9799 | case MVT::i32: |
| 9800 | // Scale == 4; |
| 9801 | Scale = 4; |
| 9802 | break; |
| 9803 | } |
| 9804 | |
| 9805 | if ((V & (Scale - 1)) != 0) |
| 9806 | return false; |
| 9807 | V /= Scale; |
| 9808 | return V == (V & ((1LL << 5) - 1)); |
| 9809 | } |
| 9810 | |
| 9811 | static bool isLegalT2AddressImmediate(int64_t V, EVT VT, |
| 9812 | const ARMSubtarget *Subtarget) { |
| 9813 | bool isNeg = false; |
| 9814 | if (V < 0) { |
| 9815 | isNeg = true; |
| 9816 | V = - V; |
| 9817 | } |
| 9818 | |
| 9819 | switch (VT.getSimpleVT().SimpleTy) { |
| 9820 | default: return false; |
| 9821 | case MVT::i1: |
| 9822 | case MVT::i8: |
| 9823 | case MVT::i16: |
| 9824 | case MVT::i32: |
| 9825 | // + imm12 or - imm8 |
| 9826 | if (isNeg) |
| 9827 | return V == (V & ((1LL << 8) - 1)); |
| 9828 | return V == (V & ((1LL << 12) - 1)); |
| 9829 | case MVT::f32: |
| 9830 | case MVT::f64: |
| 9831 | // Same as ARM mode. FIXME: NEON? |
| 9832 | if (!Subtarget->hasVFP2()) |
| 9833 | return false; |
| 9834 | if ((V & 3) != 0) |
| 9835 | return false; |
| 9836 | V >>= 2; |
| 9837 | return V == (V & ((1LL << 8) - 1)); |
| 9838 | } |
| 9839 | } |
| 9840 | |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9841 | /// isLegalAddressImmediate - Return true if the integer value can be used |
| 9842 | /// as the offset of the target addressing mode for load / store of the |
| 9843 | /// given type. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9844 | static bool isLegalAddressImmediate(int64_t V, EVT VT, |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9845 | const ARMSubtarget *Subtarget) { |
Evan Cheng | 961f879 | 2007-03-13 20:37:59 +0000 | [diff] [blame] | 9846 | if (V == 0) |
| 9847 | return true; |
| 9848 | |
Evan Cheng | 6501153 | 2009-03-09 19:15:00 +0000 | [diff] [blame] | 9849 | if (!VT.isSimple()) |
| 9850 | return false; |
| 9851 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9852 | if (Subtarget->isThumb1Only()) |
| 9853 | return isLegalT1AddressImmediate(V, VT); |
| 9854 | else if (Subtarget->isThumb2()) |
| 9855 | return isLegalT2AddressImmediate(V, VT, Subtarget); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9856 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9857 | // ARM mode. |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9858 | if (V < 0) |
| 9859 | V = - V; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9860 | switch (VT.getSimpleVT().SimpleTy) { |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9861 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9862 | case MVT::i1: |
| 9863 | case MVT::i8: |
| 9864 | case MVT::i32: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9865 | // +- imm12 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 9866 | return V == (V & ((1LL << 12) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9867 | case MVT::i16: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9868 | // +- imm8 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 9869 | return V == (V & ((1LL << 8) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9870 | case MVT::f32: |
| 9871 | case MVT::f64: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9872 | if (!Subtarget->hasVFP2()) // FIXME: NEON? |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9873 | return false; |
Evan Cheng | 0b0a9a9 | 2007-05-03 02:00:18 +0000 | [diff] [blame] | 9874 | if ((V & 3) != 0) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9875 | return false; |
| 9876 | V >>= 2; |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 9877 | return V == (V & ((1LL << 8) - 1)); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9878 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9879 | } |
| 9880 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9881 | bool ARMTargetLowering::isLegalT2ScaledAddressingMode(const AddrMode &AM, |
| 9882 | EVT VT) const { |
| 9883 | int Scale = AM.Scale; |
| 9884 | if (Scale < 0) |
| 9885 | return false; |
| 9886 | |
| 9887 | switch (VT.getSimpleVT().SimpleTy) { |
| 9888 | default: return false; |
| 9889 | case MVT::i1: |
| 9890 | case MVT::i8: |
| 9891 | case MVT::i16: |
| 9892 | case MVT::i32: |
| 9893 | if (Scale == 1) |
| 9894 | return true; |
| 9895 | // r + r << imm |
| 9896 | Scale = Scale & ~1; |
| 9897 | return Scale == 2 || Scale == 4 || Scale == 8; |
| 9898 | case MVT::i64: |
| 9899 | // r + r |
| 9900 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
| 9901 | return true; |
| 9902 | return false; |
| 9903 | case MVT::isVoid: |
| 9904 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 9905 | // stores), because arm allows folding a scale into many arithmetic |
| 9906 | // operations. This should be made more precise and revisited later. |
| 9907 | |
| 9908 | // Allow r << imm, but the imm has to be a multiple of two. |
| 9909 | if (Scale & 1) return false; |
| 9910 | return isPowerOf2_32(Scale); |
| 9911 | } |
| 9912 | } |
| 9913 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9914 | /// isLegalAddressingMode - Return true if the addressing mode represented |
| 9915 | /// by AM is legal for this target, for a load/store of the specified type. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9916 | bool ARMTargetLowering::isLegalAddressingMode(const AddrMode &AM, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 9917 | Type *Ty) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9918 | EVT VT = getValueType(Ty, true); |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 9919 | if (!isLegalAddressImmediate(AM.BaseOffs, VT, Subtarget)) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9920 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9921 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9922 | // Can never fold addr of global into load/store. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9923 | if (AM.BaseGV) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9924 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9925 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9926 | switch (AM.Scale) { |
| 9927 | case 0: // no scale reg, must be "r+i" or "r", or "i". |
| 9928 | break; |
| 9929 | case 1: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9930 | if (Subtarget->isThumb1Only()) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9931 | return false; |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 9932 | // FALL THROUGH. |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9933 | default: |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 9934 | // ARM doesn't support any R+R*scale+imm addr modes. |
| 9935 | if (AM.BaseOffs) |
| 9936 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9937 | |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 9938 | if (!VT.isSimple()) |
| 9939 | return false; |
| 9940 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9941 | if (Subtarget->isThumb2()) |
| 9942 | return isLegalT2ScaledAddressingMode(AM, VT); |
| 9943 | |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 9944 | int Scale = AM.Scale; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9945 | switch (VT.getSimpleVT().SimpleTy) { |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9946 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9947 | case MVT::i1: |
| 9948 | case MVT::i8: |
| 9949 | case MVT::i32: |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 9950 | if (Scale < 0) Scale = -Scale; |
| 9951 | if (Scale == 1) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9952 | return true; |
| 9953 | // r + r << imm |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 9954 | return isPowerOf2_32(Scale & ~1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9955 | case MVT::i16: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9956 | case MVT::i64: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9957 | // r + r |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 9958 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9959 | return true; |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 9960 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9961 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9962 | case MVT::isVoid: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9963 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 9964 | // stores), because arm allows folding a scale into many arithmetic |
| 9965 | // operations. This should be made more precise and revisited later. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9966 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9967 | // Allow r << imm, but the imm has to be a multiple of two. |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9968 | if (Scale & 1) return false; |
| 9969 | return isPowerOf2_32(Scale); |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9970 | } |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9971 | } |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9972 | return true; |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9973 | } |
| 9974 | |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 9975 | /// isLegalICmpImmediate - Return true if the specified immediate is legal |
| 9976 | /// icmp immediate, that is the target has icmp instructions which can compare |
| 9977 | /// a register against the immediate without having to materialize the |
| 9978 | /// immediate into a register. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 9979 | bool ARMTargetLowering::isLegalICmpImmediate(int64_t Imm) const { |
Jakob Stoklund Olesen | 70fbea7 | 2012-04-06 17:45:04 +0000 | [diff] [blame] | 9980 | // Thumb2 and ARM modes can use cmn for negative immediates. |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 9981 | if (!Subtarget->isThumb()) |
Chandler Carruth | ba4d457 | 2012-04-06 20:10:52 +0000 | [diff] [blame] | 9982 | return ARM_AM::getSOImmVal(llvm::abs64(Imm)) != -1; |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 9983 | if (Subtarget->isThumb2()) |
Chandler Carruth | ba4d457 | 2012-04-06 20:10:52 +0000 | [diff] [blame] | 9984 | return ARM_AM::getT2SOImmVal(llvm::abs64(Imm)) != -1; |
Jakob Stoklund Olesen | 70fbea7 | 2012-04-06 17:45:04 +0000 | [diff] [blame] | 9985 | // Thumb1 doesn't have cmn, and only 8-bit immediates. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 9986 | return Imm >= 0 && Imm <= 255; |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 9987 | } |
| 9988 | |
Andrew Trick | 8d8d961 | 2012-07-18 18:34:27 +0000 | [diff] [blame] | 9989 | /// isLegalAddImmediate - Return true if the specified immediate is a legal add |
| 9990 | /// *or sub* immediate, that is the target has add or sub instructions which can |
| 9991 | /// add a register with the immediate without having to materialize the |
Dan Gohman | cca8214 | 2011-05-03 00:46:49 +0000 | [diff] [blame] | 9992 | /// immediate into a register. |
| 9993 | bool ARMTargetLowering::isLegalAddImmediate(int64_t Imm) const { |
Andrew Trick | 8d8d961 | 2012-07-18 18:34:27 +0000 | [diff] [blame] | 9994 | // Same encoding for add/sub, just flip the sign. |
| 9995 | int64_t AbsImm = llvm::abs64(Imm); |
| 9996 | if (!Subtarget->isThumb()) |
| 9997 | return ARM_AM::getSOImmVal(AbsImm) != -1; |
| 9998 | if (Subtarget->isThumb2()) |
| 9999 | return ARM_AM::getT2SOImmVal(AbsImm) != -1; |
| 10000 | // Thumb1 only has 8-bit unsigned immediate. |
| 10001 | return AbsImm >= 0 && AbsImm <= 255; |
Dan Gohman | cca8214 | 2011-05-03 00:46:49 +0000 | [diff] [blame] | 10002 | } |
| 10003 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 10004 | static bool getARMIndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10005 | bool isSEXTLoad, SDValue &Base, |
| 10006 | SDValue &Offset, bool &isInc, |
| 10007 | SelectionDAG &DAG) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10008 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 10009 | return false; |
| 10010 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10011 | if (VT == MVT::i16 || ((VT == MVT::i8 || VT == MVT::i1) && isSEXTLoad)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10012 | // AddressingMode 3 |
| 10013 | Base = Ptr->getOperand(0); |
| 10014 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 10015 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10016 | if (RHSC < 0 && RHSC > -256) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10017 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10018 | isInc = false; |
| 10019 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 10020 | return true; |
| 10021 | } |
| 10022 | } |
| 10023 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 10024 | Offset = Ptr->getOperand(1); |
| 10025 | return true; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10026 | } else if (VT == MVT::i32 || VT == MVT::i8 || VT == MVT::i1) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10027 | // AddressingMode 2 |
| 10028 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 10029 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10030 | if (RHSC < 0 && RHSC > -0x1000) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10031 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10032 | isInc = false; |
| 10033 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 10034 | Base = Ptr->getOperand(0); |
| 10035 | return true; |
| 10036 | } |
| 10037 | } |
| 10038 | |
| 10039 | if (Ptr->getOpcode() == ISD::ADD) { |
| 10040 | isInc = true; |
Evan Cheng | ee04a6d | 2011-07-20 23:34:39 +0000 | [diff] [blame] | 10041 | ARM_AM::ShiftOpc ShOpcVal= |
| 10042 | ARM_AM::getShiftOpcForNode(Ptr->getOperand(0).getOpcode()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10043 | if (ShOpcVal != ARM_AM::no_shift) { |
| 10044 | Base = Ptr->getOperand(1); |
| 10045 | Offset = Ptr->getOperand(0); |
| 10046 | } else { |
| 10047 | Base = Ptr->getOperand(0); |
| 10048 | Offset = Ptr->getOperand(1); |
| 10049 | } |
| 10050 | return true; |
| 10051 | } |
| 10052 | |
| 10053 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 10054 | Base = Ptr->getOperand(0); |
| 10055 | Offset = Ptr->getOperand(1); |
| 10056 | return true; |
| 10057 | } |
| 10058 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 10059 | // FIXME: Use VLDM / VSTM to emulate indexed FP load / store. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10060 | return false; |
| 10061 | } |
| 10062 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 10063 | static bool getT2IndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10064 | bool isSEXTLoad, SDValue &Base, |
| 10065 | SDValue &Offset, bool &isInc, |
| 10066 | SelectionDAG &DAG) { |
| 10067 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 10068 | return false; |
| 10069 | |
| 10070 | Base = Ptr->getOperand(0); |
| 10071 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
| 10072 | int RHSC = (int)RHS->getZExtValue(); |
| 10073 | if (RHSC < 0 && RHSC > -0x100) { // 8 bits. |
| 10074 | assert(Ptr->getOpcode() == ISD::ADD); |
| 10075 | isInc = false; |
| 10076 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 10077 | return true; |
| 10078 | } else if (RHSC > 0 && RHSC < 0x100) { // 8 bit, no zero. |
| 10079 | isInc = Ptr->getOpcode() == ISD::ADD; |
| 10080 | Offset = DAG.getConstant(RHSC, RHS->getValueType(0)); |
| 10081 | return true; |
| 10082 | } |
| 10083 | } |
| 10084 | |
| 10085 | return false; |
| 10086 | } |
| 10087 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10088 | /// getPreIndexedAddressParts - returns true by value, base pointer and |
| 10089 | /// offset pointer and addressing mode by reference if the node's address |
| 10090 | /// can be legally represented as pre-indexed load / store address. |
| 10091 | bool |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 10092 | ARMTargetLowering::getPreIndexedAddressParts(SDNode *N, SDValue &Base, |
| 10093 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10094 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 10095 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10096 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10097 | return false; |
| 10098 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 10099 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 10100 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10101 | bool isSEXTLoad = false; |
| 10102 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
| 10103 | Ptr = LD->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 10104 | VT = LD->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10105 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 10106 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
| 10107 | Ptr = ST->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 10108 | VT = ST->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10109 | } else |
| 10110 | return false; |
| 10111 | |
| 10112 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10113 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 10114 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10115 | isLegal = getT2IndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
| 10116 | Offset, isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 10117 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10118 | isLegal = getARMIndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
Evan Cheng | 0412957 | 2009-07-02 06:44:30 +0000 | [diff] [blame] | 10119 | Offset, isInc, DAG); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10120 | if (!isLegal) |
| 10121 | return false; |
| 10122 | |
| 10123 | AM = isInc ? ISD::PRE_INC : ISD::PRE_DEC; |
| 10124 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10125 | } |
| 10126 | |
| 10127 | /// getPostIndexedAddressParts - returns true by value, base pointer and |
| 10128 | /// offset pointer and addressing mode by reference if this node can be |
| 10129 | /// combined with a load / store to form a post-indexed load / store. |
| 10130 | bool ARMTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 10131 | SDValue &Base, |
| 10132 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10133 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 10134 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10135 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10136 | return false; |
| 10137 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 10138 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 10139 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10140 | bool isSEXTLoad = false; |
| 10141 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 10142 | VT = LD->getMemoryVT(); |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 10143 | Ptr = LD->getBasePtr(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10144 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 10145 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 10146 | VT = ST->getMemoryVT(); |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 10147 | Ptr = ST->getBasePtr(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10148 | } else |
| 10149 | return false; |
| 10150 | |
| 10151 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10152 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 10153 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10154 | isLegal = getT2IndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 10155 | isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 10156 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10157 | isLegal = getARMIndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
| 10158 | isInc, DAG); |
| 10159 | if (!isLegal) |
| 10160 | return false; |
| 10161 | |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 10162 | if (Ptr != Base) { |
| 10163 | // Swap base ptr and offset to catch more post-index load / store when |
| 10164 | // it's legal. In Thumb2 mode, offset must be an immediate. |
| 10165 | if (Ptr == Offset && Op->getOpcode() == ISD::ADD && |
| 10166 | !Subtarget->isThumb2()) |
| 10167 | std::swap(Base, Offset); |
| 10168 | |
| 10169 | // Post-indexed load / store update the base pointer. |
| 10170 | if (Ptr != Base) |
| 10171 | return false; |
| 10172 | } |
| 10173 | |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10174 | AM = isInc ? ISD::POST_INC : ISD::POST_DEC; |
| 10175 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10176 | } |
| 10177 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 10178 | void ARMTargetLowering::computeMaskedBitsForTargetNode(const SDValue Op, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 10179 | APInt &KnownZero, |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 10180 | APInt &KnownOne, |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 10181 | const SelectionDAG &DAG, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10182 | unsigned Depth) const { |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 10183 | KnownZero = KnownOne = APInt(KnownOne.getBitWidth(), 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10184 | switch (Op.getOpcode()) { |
| 10185 | default: break; |
| 10186 | case ARMISD::CMOV: { |
| 10187 | // Bits are known zero/one if known on the LHS and RHS. |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 10188 | DAG.ComputeMaskedBits(Op.getOperand(0), KnownZero, KnownOne, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10189 | if (KnownZero == 0 && KnownOne == 0) return; |
| 10190 | |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 10191 | APInt KnownZeroRHS, KnownOneRHS; |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 10192 | DAG.ComputeMaskedBits(Op.getOperand(1), KnownZeroRHS, KnownOneRHS, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10193 | KnownZero &= KnownZeroRHS; |
| 10194 | KnownOne &= KnownOneRHS; |
| 10195 | return; |
| 10196 | } |
| 10197 | } |
| 10198 | } |
| 10199 | |
| 10200 | //===----------------------------------------------------------------------===// |
| 10201 | // ARM Inline Assembly Support |
| 10202 | //===----------------------------------------------------------------------===// |
| 10203 | |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 10204 | bool ARMTargetLowering::ExpandInlineAsm(CallInst *CI) const { |
| 10205 | // Looking for "rev" which is V6+. |
| 10206 | if (!Subtarget->hasV6Ops()) |
| 10207 | return false; |
| 10208 | |
| 10209 | InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue()); |
| 10210 | std::string AsmStr = IA->getAsmString(); |
| 10211 | SmallVector<StringRef, 4> AsmPieces; |
| 10212 | SplitString(AsmStr, AsmPieces, ";\n"); |
| 10213 | |
| 10214 | switch (AsmPieces.size()) { |
| 10215 | default: return false; |
| 10216 | case 1: |
| 10217 | AsmStr = AsmPieces[0]; |
| 10218 | AsmPieces.clear(); |
| 10219 | SplitString(AsmStr, AsmPieces, " \t,"); |
| 10220 | |
| 10221 | // rev $0, $1 |
| 10222 | if (AsmPieces.size() == 3 && |
| 10223 | AsmPieces[0] == "rev" && AsmPieces[1] == "$0" && AsmPieces[2] == "$1" && |
| 10224 | IA->getConstraintString().compare(0, 4, "=l,l") == 0) { |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 10225 | IntegerType *Ty = dyn_cast<IntegerType>(CI->getType()); |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 10226 | if (Ty && Ty->getBitWidth() == 32) |
| 10227 | return IntrinsicLowering::LowerToByteSwap(CI); |
| 10228 | } |
| 10229 | break; |
| 10230 | } |
| 10231 | |
| 10232 | return false; |
| 10233 | } |
| 10234 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10235 | /// getConstraintType - Given a constraint letter, return the type of |
| 10236 | /// constraint it is for this target. |
| 10237 | ARMTargetLowering::ConstraintType |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 10238 | ARMTargetLowering::getConstraintType(const std::string &Constraint) const { |
| 10239 | if (Constraint.size() == 1) { |
| 10240 | switch (Constraint[0]) { |
| 10241 | default: break; |
| 10242 | case 'l': return C_RegisterClass; |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 10243 | case 'w': return C_RegisterClass; |
Eric Christopher | 73744df | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 10244 | case 'h': return C_RegisterClass; |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 10245 | case 'x': return C_RegisterClass; |
Eric Christopher | d5dc9ec | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 10246 | case 't': return C_RegisterClass; |
Eric Christopher | 5e653c9 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 10247 | case 'j': return C_Other; // Constant for movw. |
Eric Christopher | ef7f1e7 | 2011-07-29 21:18:58 +0000 | [diff] [blame] | 10248 | // An address with a single base register. Due to the way we |
| 10249 | // currently handle addresses it is the same as an 'r' memory constraint. |
| 10250 | case 'Q': return C_Memory; |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 10251 | } |
Eric Christopher | 1312ca8 | 2011-06-21 22:10:57 +0000 | [diff] [blame] | 10252 | } else if (Constraint.size() == 2) { |
| 10253 | switch (Constraint[0]) { |
| 10254 | default: break; |
| 10255 | // All 'U+' constraints are addresses. |
| 10256 | case 'U': return C_Memory; |
| 10257 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10258 | } |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 10259 | return TargetLowering::getConstraintType(Constraint); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10260 | } |
| 10261 | |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 10262 | /// Examine constraint type and operand type and determine a weight value. |
| 10263 | /// This object must already have been set up with the operand type |
| 10264 | /// and the current alternative constraint selected. |
| 10265 | TargetLowering::ConstraintWeight |
| 10266 | ARMTargetLowering::getSingleConstraintMatchWeight( |
| 10267 | AsmOperandInfo &info, const char *constraint) const { |
| 10268 | ConstraintWeight weight = CW_Invalid; |
| 10269 | Value *CallOperandVal = info.CallOperandVal; |
| 10270 | // If we don't have a value, we can't do a match, |
| 10271 | // but allow it at the lowest weight. |
| 10272 | if (CallOperandVal == NULL) |
| 10273 | return CW_Default; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 10274 | Type *type = CallOperandVal->getType(); |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 10275 | // Look at the constraint type. |
| 10276 | switch (*constraint) { |
| 10277 | default: |
| 10278 | weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint); |
| 10279 | break; |
| 10280 | case 'l': |
| 10281 | if (type->isIntegerTy()) { |
| 10282 | if (Subtarget->isThumb()) |
| 10283 | weight = CW_SpecificReg; |
| 10284 | else |
| 10285 | weight = CW_Register; |
| 10286 | } |
| 10287 | break; |
| 10288 | case 'w': |
| 10289 | if (type->isFloatingPointTy()) |
| 10290 | weight = CW_Register; |
| 10291 | break; |
| 10292 | } |
| 10293 | return weight; |
| 10294 | } |
| 10295 | |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 10296 | typedef std::pair<unsigned, const TargetRegisterClass*> RCPair; |
| 10297 | RCPair |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10298 | ARMTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 10299 | EVT VT) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10300 | if (Constraint.size() == 1) { |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 10301 | // GCC ARM Constraint Letters |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10302 | switch (Constraint[0]) { |
Eric Christopher | 73744df | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 10303 | case 'l': // Low regs or general regs. |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 10304 | if (Subtarget->isThumb()) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10305 | return RCPair(0U, &ARM::tGPRRegClass); |
| 10306 | return RCPair(0U, &ARM::GPRRegClass); |
Eric Christopher | 73744df | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 10307 | case 'h': // High regs or no regs. |
| 10308 | if (Subtarget->isThumb()) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10309 | return RCPair(0U, &ARM::hGPRRegClass); |
Eric Christopher | 1070f82 | 2011-07-01 00:19:27 +0000 | [diff] [blame] | 10310 | break; |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 10311 | case 'r': |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10312 | return RCPair(0U, &ARM::GPRRegClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 10313 | case 'w': |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10314 | if (VT == MVT::f32) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10315 | return RCPair(0U, &ARM::SPRRegClass); |
Bob Wilson | 5afffae | 2009-12-18 01:03:29 +0000 | [diff] [blame] | 10316 | if (VT.getSizeInBits() == 64) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10317 | return RCPair(0U, &ARM::DPRRegClass); |
Evan Cheng | d831cda | 2009-12-08 23:06:22 +0000 | [diff] [blame] | 10318 | if (VT.getSizeInBits() == 128) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10319 | return RCPair(0U, &ARM::QPRRegClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 10320 | break; |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 10321 | case 'x': |
| 10322 | if (VT == MVT::f32) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10323 | return RCPair(0U, &ARM::SPR_8RegClass); |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 10324 | if (VT.getSizeInBits() == 64) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10325 | return RCPair(0U, &ARM::DPR_8RegClass); |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 10326 | if (VT.getSizeInBits() == 128) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10327 | return RCPair(0U, &ARM::QPR_8RegClass); |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 10328 | break; |
Eric Christopher | d5dc9ec | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 10329 | case 't': |
| 10330 | if (VT == MVT::f32) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10331 | return RCPair(0U, &ARM::SPRRegClass); |
Eric Christopher | d5dc9ec | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 10332 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10333 | } |
| 10334 | } |
Bob Wilson | 33cc5cb | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 10335 | if (StringRef("{cc}").equals_lower(Constraint)) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 10336 | return std::make_pair(unsigned(ARM::CPSR), &ARM::CCRRegClass); |
Bob Wilson | 33cc5cb | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 10337 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10338 | return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); |
| 10339 | } |
| 10340 | |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10341 | /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops |
| 10342 | /// vector. If it is invalid, don't add anything to Ops. |
| 10343 | void ARMTargetLowering::LowerAsmOperandForConstraint(SDValue Op, |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 10344 | std::string &Constraint, |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10345 | std::vector<SDValue>&Ops, |
| 10346 | SelectionDAG &DAG) const { |
| 10347 | SDValue Result(0, 0); |
| 10348 | |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 10349 | // Currently only support length 1 constraints. |
| 10350 | if (Constraint.length() != 1) return; |
Eric Christopher | 471e422 | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 10351 | |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 10352 | char ConstraintLetter = Constraint[0]; |
| 10353 | switch (ConstraintLetter) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10354 | default: break; |
Eric Christopher | 5e653c9 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 10355 | case 'j': |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10356 | case 'I': case 'J': case 'K': case 'L': |
| 10357 | case 'M': case 'N': case 'O': |
| 10358 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op); |
| 10359 | if (!C) |
| 10360 | return; |
| 10361 | |
| 10362 | int64_t CVal64 = C->getSExtValue(); |
| 10363 | int CVal = (int) CVal64; |
| 10364 | // None of these constraints allow values larger than 32 bits. Check |
| 10365 | // that the value fits in an int. |
| 10366 | if (CVal != CVal64) |
| 10367 | return; |
| 10368 | |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 10369 | switch (ConstraintLetter) { |
Eric Christopher | 5e653c9 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 10370 | case 'j': |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 10371 | // Constant suitable for movw, must be between 0 and |
| 10372 | // 65535. |
| 10373 | if (Subtarget->hasV6T2Ops()) |
| 10374 | if (CVal >= 0 && CVal <= 65535) |
| 10375 | break; |
| 10376 | return; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10377 | case 'I': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10378 | if (Subtarget->isThumb1Only()) { |
| 10379 | // This must be a constant between 0 and 255, for ADD |
| 10380 | // immediates. |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10381 | if (CVal >= 0 && CVal <= 255) |
| 10382 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10383 | } else if (Subtarget->isThumb2()) { |
| 10384 | // A constant that can be used as an immediate value in a |
| 10385 | // data-processing instruction. |
| 10386 | if (ARM_AM::getT2SOImmVal(CVal) != -1) |
| 10387 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10388 | } else { |
| 10389 | // A constant that can be used as an immediate value in a |
| 10390 | // data-processing instruction. |
| 10391 | if (ARM_AM::getSOImmVal(CVal) != -1) |
| 10392 | break; |
| 10393 | } |
| 10394 | return; |
| 10395 | |
| 10396 | case 'J': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10397 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10398 | // This must be a constant between -255 and -1, for negated ADD |
| 10399 | // immediates. This can be used in GCC with an "n" modifier that |
| 10400 | // prints the negated value, for use with SUB instructions. It is |
| 10401 | // not useful otherwise but is implemented for compatibility. |
| 10402 | if (CVal >= -255 && CVal <= -1) |
| 10403 | break; |
| 10404 | } else { |
| 10405 | // This must be a constant between -4095 and 4095. It is not clear |
| 10406 | // what this constraint is intended for. Implemented for |
| 10407 | // compatibility with GCC. |
| 10408 | if (CVal >= -4095 && CVal <= 4095) |
| 10409 | break; |
| 10410 | } |
| 10411 | return; |
| 10412 | |
| 10413 | case 'K': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10414 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10415 | // A 32-bit value where only one byte has a nonzero value. Exclude |
| 10416 | // zero to match GCC. This constraint is used by GCC internally for |
| 10417 | // constants that can be loaded with a move/shift combination. |
| 10418 | // It is not useful otherwise but is implemented for compatibility. |
| 10419 | if (CVal != 0 && ARM_AM::isThumbImmShiftedVal(CVal)) |
| 10420 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10421 | } else if (Subtarget->isThumb2()) { |
| 10422 | // A constant whose bitwise inverse can be used as an immediate |
| 10423 | // value in a data-processing instruction. This can be used in GCC |
| 10424 | // with a "B" modifier that prints the inverted value, for use with |
| 10425 | // BIC and MVN instructions. It is not useful otherwise but is |
| 10426 | // implemented for compatibility. |
| 10427 | if (ARM_AM::getT2SOImmVal(~CVal) != -1) |
| 10428 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10429 | } else { |
| 10430 | // A constant whose bitwise inverse can be used as an immediate |
| 10431 | // value in a data-processing instruction. This can be used in GCC |
| 10432 | // with a "B" modifier that prints the inverted value, for use with |
| 10433 | // BIC and MVN instructions. It is not useful otherwise but is |
| 10434 | // implemented for compatibility. |
| 10435 | if (ARM_AM::getSOImmVal(~CVal) != -1) |
| 10436 | break; |
| 10437 | } |
| 10438 | return; |
| 10439 | |
| 10440 | case 'L': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10441 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10442 | // This must be a constant between -7 and 7, |
| 10443 | // for 3-operand ADD/SUB immediate instructions. |
| 10444 | if (CVal >= -7 && CVal < 7) |
| 10445 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10446 | } else if (Subtarget->isThumb2()) { |
| 10447 | // A constant whose negation can be used as an immediate value in a |
| 10448 | // data-processing instruction. This can be used in GCC with an "n" |
| 10449 | // modifier that prints the negated value, for use with SUB |
| 10450 | // instructions. It is not useful otherwise but is implemented for |
| 10451 | // compatibility. |
| 10452 | if (ARM_AM::getT2SOImmVal(-CVal) != -1) |
| 10453 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10454 | } else { |
| 10455 | // A constant whose negation can be used as an immediate value in a |
| 10456 | // data-processing instruction. This can be used in GCC with an "n" |
| 10457 | // modifier that prints the negated value, for use with SUB |
| 10458 | // instructions. It is not useful otherwise but is implemented for |
| 10459 | // compatibility. |
| 10460 | if (ARM_AM::getSOImmVal(-CVal) != -1) |
| 10461 | break; |
| 10462 | } |
| 10463 | return; |
| 10464 | |
| 10465 | case 'M': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10466 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10467 | // This must be a multiple of 4 between 0 and 1020, for |
| 10468 | // ADD sp + immediate. |
| 10469 | if ((CVal >= 0 && CVal <= 1020) && ((CVal & 3) == 0)) |
| 10470 | break; |
| 10471 | } else { |
| 10472 | // A power of two or a constant between 0 and 32. This is used in |
| 10473 | // GCC for the shift amount on shifted register operands, but it is |
| 10474 | // useful in general for any shift amounts. |
| 10475 | if ((CVal >= 0 && CVal <= 32) || ((CVal & (CVal - 1)) == 0)) |
| 10476 | break; |
| 10477 | } |
| 10478 | return; |
| 10479 | |
| 10480 | case 'N': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10481 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10482 | // This must be a constant between 0 and 31, for shift amounts. |
| 10483 | if (CVal >= 0 && CVal <= 31) |
| 10484 | break; |
| 10485 | } |
| 10486 | return; |
| 10487 | |
| 10488 | case 'O': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10489 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10490 | // This must be a multiple of 4 between -508 and 508, for |
| 10491 | // ADD/SUB sp = sp + immediate. |
| 10492 | if ((CVal >= -508 && CVal <= 508) && ((CVal & 3) == 0)) |
| 10493 | break; |
| 10494 | } |
| 10495 | return; |
| 10496 | } |
| 10497 | Result = DAG.getTargetConstant(CVal, Op.getValueType()); |
| 10498 | break; |
| 10499 | } |
| 10500 | |
| 10501 | if (Result.getNode()) { |
| 10502 | Ops.push_back(Result); |
| 10503 | return; |
| 10504 | } |
Dale Johannesen | 1784d16 | 2010-06-25 21:55:36 +0000 | [diff] [blame] | 10505 | return TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG); |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10506 | } |
Anton Korobeynikov | 48e1935 | 2009-09-23 19:04:09 +0000 | [diff] [blame] | 10507 | |
| 10508 | bool |
| 10509 | ARMTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { |
| 10510 | // The ARM target isn't yet aware of offsets. |
| 10511 | return false; |
| 10512 | } |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 10513 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 10514 | bool ARM::isBitFieldInvertedMask(unsigned v) { |
| 10515 | if (v == 0xffffffff) |
Benjamin Kramer | 4dc8bdf | 2013-05-19 22:01:57 +0000 | [diff] [blame] | 10516 | return false; |
| 10517 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 10518 | // there can be 1's on either or both "outsides", all the "inside" |
| 10519 | // bits must be 0's |
Benjamin Kramer | 4dc8bdf | 2013-05-19 22:01:57 +0000 | [diff] [blame] | 10520 | unsigned TO = CountTrailingOnes_32(v); |
| 10521 | unsigned LO = CountLeadingOnes_32(v); |
| 10522 | v = (v >> TO) << TO; |
| 10523 | v = (v << LO) >> LO; |
| 10524 | return v == 0; |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 10525 | } |
| 10526 | |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 10527 | /// isFPImmLegal - Returns true if the target can instruction select the |
| 10528 | /// specified FP immediate natively. If false, the legalizer will |
| 10529 | /// materialize the FP immediate as a load from a constant pool. |
| 10530 | bool ARMTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const { |
| 10531 | if (!Subtarget->hasVFP3()) |
| 10532 | return false; |
| 10533 | if (VT == MVT::f32) |
Jim Grosbach | 4ebbf7b | 2011-09-30 00:50:06 +0000 | [diff] [blame] | 10534 | return ARM_AM::getFP32Imm(Imm) != -1; |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 10535 | if (VT == MVT::f64) |
Jim Grosbach | 4ebbf7b | 2011-09-30 00:50:06 +0000 | [diff] [blame] | 10536 | return ARM_AM::getFP64Imm(Imm) != -1; |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 10537 | return false; |
| 10538 | } |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 10539 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 10540 | /// getTgtMemIntrinsic - Represent NEON load and store intrinsics as |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 10541 | /// MemIntrinsicNodes. The associated MachineMemOperands record the alignment |
| 10542 | /// specified in the intrinsic calls. |
| 10543 | bool ARMTargetLowering::getTgtMemIntrinsic(IntrinsicInfo &Info, |
| 10544 | const CallInst &I, |
| 10545 | unsigned Intrinsic) const { |
| 10546 | switch (Intrinsic) { |
| 10547 | case Intrinsic::arm_neon_vld1: |
| 10548 | case Intrinsic::arm_neon_vld2: |
| 10549 | case Intrinsic::arm_neon_vld3: |
| 10550 | case Intrinsic::arm_neon_vld4: |
| 10551 | case Intrinsic::arm_neon_vld2lane: |
| 10552 | case Intrinsic::arm_neon_vld3lane: |
| 10553 | case Intrinsic::arm_neon_vld4lane: { |
| 10554 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 10555 | // Conservatively set memVT to the entire set of vectors loaded. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 10556 | uint64_t NumElts = getDataLayout()->getTypeAllocSize(I.getType()) / 8; |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 10557 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 10558 | Info.ptrVal = I.getArgOperand(0); |
| 10559 | Info.offset = 0; |
| 10560 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 10561 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 10562 | Info.vol = false; // volatile loads with NEON intrinsics not supported |
| 10563 | Info.readMem = true; |
| 10564 | Info.writeMem = false; |
| 10565 | return true; |
| 10566 | } |
| 10567 | case Intrinsic::arm_neon_vst1: |
| 10568 | case Intrinsic::arm_neon_vst2: |
| 10569 | case Intrinsic::arm_neon_vst3: |
| 10570 | case Intrinsic::arm_neon_vst4: |
| 10571 | case Intrinsic::arm_neon_vst2lane: |
| 10572 | case Intrinsic::arm_neon_vst3lane: |
| 10573 | case Intrinsic::arm_neon_vst4lane: { |
| 10574 | Info.opc = ISD::INTRINSIC_VOID; |
| 10575 | // Conservatively set memVT to the entire set of vectors stored. |
| 10576 | unsigned NumElts = 0; |
| 10577 | for (unsigned ArgI = 1, ArgE = I.getNumArgOperands(); ArgI < ArgE; ++ArgI) { |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 10578 | Type *ArgTy = I.getArgOperand(ArgI)->getType(); |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 10579 | if (!ArgTy->isVectorTy()) |
| 10580 | break; |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 10581 | NumElts += getDataLayout()->getTypeAllocSize(ArgTy) / 8; |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 10582 | } |
| 10583 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 10584 | Info.ptrVal = I.getArgOperand(0); |
| 10585 | Info.offset = 0; |
| 10586 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 10587 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 10588 | Info.vol = false; // volatile stores with NEON intrinsics not supported |
| 10589 | Info.readMem = false; |
| 10590 | Info.writeMem = true; |
| 10591 | return true; |
| 10592 | } |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 10593 | case Intrinsic::arm_strexd: { |
| 10594 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 10595 | Info.memVT = MVT::i64; |
| 10596 | Info.ptrVal = I.getArgOperand(2); |
| 10597 | Info.offset = 0; |
| 10598 | Info.align = 8; |
Bruno Cardoso Lopes | c75448c | 2011-06-16 18:11:32 +0000 | [diff] [blame] | 10599 | Info.vol = true; |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 10600 | Info.readMem = false; |
| 10601 | Info.writeMem = true; |
| 10602 | return true; |
| 10603 | } |
| 10604 | case Intrinsic::arm_ldrexd: { |
| 10605 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 10606 | Info.memVT = MVT::i64; |
| 10607 | Info.ptrVal = I.getArgOperand(0); |
| 10608 | Info.offset = 0; |
| 10609 | Info.align = 8; |
Bruno Cardoso Lopes | c75448c | 2011-06-16 18:11:32 +0000 | [diff] [blame] | 10610 | Info.vol = true; |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 10611 | Info.readMem = true; |
| 10612 | Info.writeMem = false; |
| 10613 | return true; |
| 10614 | } |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 10615 | default: |
| 10616 | break; |
| 10617 | } |
| 10618 | |
| 10619 | return false; |
| 10620 | } |