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" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 28 | #include "llvm/CallingConv.h" |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/CallingConvLower.h" |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/IntrinsicLowering.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 32 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 33 | #include "llvm/CodeGen/MachineFunction.h" |
| 34 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 35 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 36 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 37 | #include "llvm/CodeGen/SelectionDAG.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 38 | #include "llvm/Constants.h" |
| 39 | #include "llvm/Function.h" |
| 40 | #include "llvm/GlobalValue.h" |
| 41 | #include "llvm/Instruction.h" |
| 42 | #include "llvm/Instructions.h" |
| 43 | #include "llvm/Intrinsics.h" |
Bill Wendling | 94a1c63 | 2010-03-09 02:46:12 +0000 | [diff] [blame] | 44 | #include "llvm/MC/MCSectionMachO.h" |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 45 | #include "llvm/Support/CommandLine.h" |
Torok Edwin | ab7c09b | 2009-07-08 18:01:40 +0000 | [diff] [blame] | 46 | #include "llvm/Support/ErrorHandling.h" |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 47 | #include "llvm/Support/MathExtras.h" |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 48 | #include "llvm/Support/raw_ostream.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 49 | #include "llvm/Target/TargetOptions.h" |
| 50 | #include "llvm/Type.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); |
Lang Hames | c0a9f82 | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 507 | |
Stepan Dyatkovskiy | 3e0dc06 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 508 | setOperationAction(ISD::FSQRT, MVT::v4f32, Expand); |
| 509 | setOperationAction(ISD::FSIN, MVT::v4f32, Expand); |
| 510 | setOperationAction(ISD::FCOS, MVT::v4f32, Expand); |
| 511 | setOperationAction(ISD::FPOWI, MVT::v4f32, Expand); |
| 512 | setOperationAction(ISD::FPOW, MVT::v4f32, Expand); |
| 513 | setOperationAction(ISD::FLOG, MVT::v4f32, Expand); |
| 514 | setOperationAction(ISD::FLOG2, MVT::v4f32, Expand); |
| 515 | setOperationAction(ISD::FLOG10, MVT::v4f32, Expand); |
| 516 | setOperationAction(ISD::FEXP, MVT::v4f32, Expand); |
| 517 | setOperationAction(ISD::FEXP2, MVT::v4f32, Expand); |
Craig Topper | 4901047 | 2012-11-15 06:51:10 +0000 | [diff] [blame] | 518 | setOperationAction(ISD::FCEIL, MVT::v4f32, Expand); |
| 519 | setOperationAction(ISD::FTRUNC, MVT::v4f32, Expand); |
| 520 | setOperationAction(ISD::FRINT, MVT::v4f32, Expand); |
| 521 | setOperationAction(ISD::FNEARBYINT, MVT::v4f32, Expand); |
Craig Topper | a1fb1d2 | 2012-09-08 04:58:43 +0000 | [diff] [blame] | 522 | setOperationAction(ISD::FFLOOR, MVT::v4f32, Expand); |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 523 | |
Bob Wilson | 642b329 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 524 | // Neon does not support some operations on v1i64 and v2i64 types. |
| 525 | setOperationAction(ISD::MUL, MVT::v1i64, Expand); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 526 | // Custom handling for some quad-vector types to detect VMULL. |
| 527 | setOperationAction(ISD::MUL, MVT::v8i16, Custom); |
| 528 | setOperationAction(ISD::MUL, MVT::v4i32, Custom); |
| 529 | setOperationAction(ISD::MUL, MVT::v2i64, Custom); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 530 | // Custom handling for some vector types to avoid expensive expansions |
| 531 | setOperationAction(ISD::SDIV, MVT::v4i16, Custom); |
| 532 | setOperationAction(ISD::SDIV, MVT::v8i8, Custom); |
| 533 | setOperationAction(ISD::UDIV, MVT::v4i16, Custom); |
| 534 | setOperationAction(ISD::UDIV, MVT::v8i8, Custom); |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 535 | setOperationAction(ISD::SETCC, MVT::v1i64, Expand); |
| 536 | setOperationAction(ISD::SETCC, MVT::v2i64, Expand); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 537 | // 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] | 538 | // a destination type that is wider than the source, and nor does |
| 539 | // it have a FP_TO_[SU]INT instruction with a narrower destination than |
| 540 | // source. |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 541 | setOperationAction(ISD::SINT_TO_FP, MVT::v4i16, Custom); |
| 542 | setOperationAction(ISD::UINT_TO_FP, MVT::v4i16, Custom); |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 543 | setOperationAction(ISD::FP_TO_UINT, MVT::v4i16, Custom); |
| 544 | setOperationAction(ISD::FP_TO_SINT, MVT::v4i16, Custom); |
Bob Wilson | 642b329 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 545 | |
Eli Friedman | 846ce8e | 2012-11-15 22:44:27 +0000 | [diff] [blame] | 546 | setOperationAction(ISD::FP_ROUND, MVT::v2f32, Expand); |
Eli Friedman | 43147af | 2012-11-17 01:52:46 +0000 | [diff] [blame] | 547 | setOperationAction(ISD::FP_EXTEND, MVT::v2f64, Expand); |
Eli Friedman | 846ce8e | 2012-11-15 22:44:27 +0000 | [diff] [blame] | 548 | |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 549 | setTargetDAGCombine(ISD::INTRINSIC_VOID); |
| 550 | setTargetDAGCombine(ISD::INTRINSIC_W_CHAIN); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 551 | setTargetDAGCombine(ISD::INTRINSIC_WO_CHAIN); |
| 552 | setTargetDAGCombine(ISD::SHL); |
| 553 | setTargetDAGCombine(ISD::SRL); |
| 554 | setTargetDAGCombine(ISD::SRA); |
| 555 | setTargetDAGCombine(ISD::SIGN_EXTEND); |
| 556 | setTargetDAGCombine(ISD::ZERO_EXTEND); |
| 557 | setTargetDAGCombine(ISD::ANY_EXTEND); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 558 | setTargetDAGCombine(ISD::SELECT_CC); |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 559 | setTargetDAGCombine(ISD::BUILD_VECTOR); |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 560 | setTargetDAGCombine(ISD::VECTOR_SHUFFLE); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 561 | setTargetDAGCombine(ISD::INSERT_VECTOR_ELT); |
| 562 | setTargetDAGCombine(ISD::STORE); |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 563 | setTargetDAGCombine(ISD::FP_TO_SINT); |
| 564 | setTargetDAGCombine(ISD::FP_TO_UINT); |
| 565 | setTargetDAGCombine(ISD::FDIV); |
Nadav Rotem | 004a24b | 2011-10-15 20:03:12 +0000 | [diff] [blame] | 566 | |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 567 | // It is legal to extload from v4i8 to v4i16 or v4i32. |
| 568 | MVT Tys[6] = {MVT::v8i8, MVT::v4i8, MVT::v2i8, |
| 569 | MVT::v4i16, MVT::v2i16, |
| 570 | MVT::v2i32}; |
| 571 | for (unsigned i = 0; i < 6; ++i) { |
| 572 | setLoadExtAction(ISD::EXTLOAD, Tys[i], Legal); |
| 573 | setLoadExtAction(ISD::ZEXTLOAD, Tys[i], Legal); |
| 574 | setLoadExtAction(ISD::SEXTLOAD, Tys[i], Legal); |
| 575 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 576 | } |
| 577 | |
Arnold Schwaighofer | 67514e9 | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 578 | // ARM and Thumb2 support UMLAL/SMLAL. |
| 579 | if (!Subtarget->isThumb1Only()) |
| 580 | setTargetDAGCombine(ISD::ADDC); |
| 581 | |
| 582 | |
Evan Cheng | 9f8cbd1 | 2007-05-18 00:19:34 +0000 | [diff] [blame] | 583 | computeRegisterProperties(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 584 | |
| 585 | // ARM does not have f32 extending load. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 586 | setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 587 | |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 588 | // ARM does not have i1 sign extending load. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 589 | setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote); |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 590 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 591 | // ARM supports all 4 flavors of integer indexed load / store. |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 592 | if (!Subtarget->isThumb1Only()) { |
| 593 | for (unsigned im = (unsigned)ISD::PRE_INC; |
| 594 | im != (unsigned)ISD::LAST_INDEXED_MODE; ++im) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 595 | setIndexedLoadAction(im, MVT::i1, Legal); |
| 596 | setIndexedLoadAction(im, MVT::i8, Legal); |
| 597 | setIndexedLoadAction(im, MVT::i16, Legal); |
| 598 | setIndexedLoadAction(im, MVT::i32, Legal); |
| 599 | setIndexedStoreAction(im, MVT::i1, Legal); |
| 600 | setIndexedStoreAction(im, MVT::i8, Legal); |
| 601 | setIndexedStoreAction(im, MVT::i16, Legal); |
| 602 | setIndexedStoreAction(im, MVT::i32, Legal); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 603 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | // i64 operation support. |
Eric Christopher | 2cc4013 | 2011-04-19 18:49:19 +0000 | [diff] [blame] | 607 | setOperationAction(ISD::MUL, MVT::i64, Expand); |
| 608 | setOperationAction(ISD::MULHU, MVT::i32, Expand); |
Evan Cheng | 5b9fcd1 | 2009-07-07 01:17:28 +0000 | [diff] [blame] | 609 | if (Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 610 | setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand); |
| 611 | setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 612 | } |
Jim Grosbach | a760398 | 2011-07-01 21:12:19 +0000 | [diff] [blame] | 613 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6Ops() |
| 614 | || (Subtarget->isThumb2() && !Subtarget->hasThumb2DSP())) |
Eric Christopher | 2cc4013 | 2011-04-19 18:49:19 +0000 | [diff] [blame] | 615 | setOperationAction(ISD::MULHS, MVT::i32, Expand); |
| 616 | |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 617 | setOperationAction(ISD::SHL_PARTS, MVT::i32, Custom); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 618 | setOperationAction(ISD::SRA_PARTS, MVT::i32, Custom); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 619 | setOperationAction(ISD::SRL_PARTS, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 620 | setOperationAction(ISD::SRL, MVT::i64, Custom); |
| 621 | setOperationAction(ISD::SRA, MVT::i64, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 622 | |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 623 | if (!Subtarget->isThumb1Only()) { |
| 624 | // FIXME: We should do this for Thumb1 as well. |
| 625 | setOperationAction(ISD::ADDC, MVT::i32, Custom); |
| 626 | setOperationAction(ISD::ADDE, MVT::i32, Custom); |
| 627 | setOperationAction(ISD::SUBC, MVT::i32, Custom); |
| 628 | setOperationAction(ISD::SUBE, MVT::i32, Custom); |
| 629 | } |
| 630 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 631 | // ARM does not have ROTL. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 632 | setOperationAction(ISD::ROTL, MVT::i32, Expand); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 633 | setOperationAction(ISD::CTTZ, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 634 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
David Goodwin | 24062ac | 2009-06-26 20:47:43 +0000 | [diff] [blame] | 635 | if (!Subtarget->hasV5TOps() || Subtarget->isThumb1Only()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 636 | setOperationAction(ISD::CTLZ, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 637 | |
Chandler Carruth | 63974b2 | 2011-12-13 01:56:10 +0000 | [diff] [blame] | 638 | // These just redirect to CTTZ and CTLZ on ARM. |
| 639 | setOperationAction(ISD::CTTZ_ZERO_UNDEF , MVT::i32 , Expand); |
| 640 | setOperationAction(ISD::CTLZ_ZERO_UNDEF , MVT::i32 , Expand); |
| 641 | |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 642 | // Only ARMv6 has BSWAP. |
| 643 | if (!Subtarget->hasV6Ops()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 644 | setOperationAction(ISD::BSWAP, MVT::i32, Expand); |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 645 | |
Bob Wilson | eb1641d | 2012-09-29 21:43:49 +0000 | [diff] [blame] | 646 | if (!(Subtarget->hasDivide() && Subtarget->isThumb2()) && |
| 647 | !(Subtarget->hasDivideInARMMode() && !Subtarget->isThumb())) { |
| 648 | // 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] | 649 | setOperationAction(ISD::SDIV, MVT::i32, Expand); |
| 650 | setOperationAction(ISD::UDIV, MVT::i32, Expand); |
| 651 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 652 | setOperationAction(ISD::SREM, MVT::i32, Expand); |
| 653 | setOperationAction(ISD::UREM, MVT::i32, Expand); |
| 654 | setOperationAction(ISD::SDIVREM, MVT::i32, Expand); |
| 655 | setOperationAction(ISD::UDIVREM, MVT::i32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 656 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 657 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
| 658 | setOperationAction(ISD::ConstantPool, MVT::i32, Custom); |
| 659 | setOperationAction(ISD::GLOBAL_OFFSET_TABLE, MVT::i32, Custom); |
| 660 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 661 | setOperationAction(ISD::BlockAddress, MVT::i32, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 662 | |
Evan Cheng | 4da0c7c | 2011-04-08 21:37:21 +0000 | [diff] [blame] | 663 | setOperationAction(ISD::TRAP, MVT::Other, Legal); |
Evan Cheng | fb3611d | 2010-05-11 07:26:32 +0000 | [diff] [blame] | 664 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 665 | // Use the default implementation. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 666 | setOperationAction(ISD::VASTART, MVT::Other, Custom); |
| 667 | setOperationAction(ISD::VAARG, MVT::Other, Expand); |
| 668 | setOperationAction(ISD::VACOPY, MVT::Other, Expand); |
| 669 | setOperationAction(ISD::VAEND, MVT::Other, Expand); |
| 670 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
| 671 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
Bill Wendling | bdf9db6 | 2012-02-13 23:47:16 +0000 | [diff] [blame] | 672 | |
| 673 | if (!Subtarget->isTargetDarwin()) { |
| 674 | // Non-Darwin platforms may return values in these registers via the |
| 675 | // personality function. |
| 676 | setOperationAction(ISD::EHSELECTION, MVT::i32, Expand); |
| 677 | setOperationAction(ISD::EXCEPTIONADDR, MVT::i32, Expand); |
| 678 | setExceptionPointerRegister(ARM::R0); |
| 679 | setExceptionSelectorRegister(ARM::R1); |
| 680 | } |
Anton Korobeynikov | 5899a60 | 2011-01-24 22:38:45 +0000 | [diff] [blame] | 681 | |
Evan Cheng | 3a1588a | 2010-04-15 22:20:34 +0000 | [diff] [blame] | 682 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Expand); |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 683 | // ARMv6 Thumb1 (except for CPUs that support dmb / dsb) and earlier use |
| 684 | // the default expansion. |
Eli Friedman | 4db5aca | 2011-08-29 18:23:02 +0000 | [diff] [blame] | 685 | // FIXME: This should be checking for v6k, not just v6. |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 686 | if (Subtarget->hasDataBarrier() || |
Bob Wilson | 54f9256 | 2010-11-09 22:50:44 +0000 | [diff] [blame] | 687 | (Subtarget->hasV6Ops() && !Subtarget->isThumb())) { |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 688 | // membarrier needs custom lowering; the rest are legal and handled |
| 689 | // normally. |
| 690 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Custom); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 691 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Custom); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 692 | // Custom lowering for 64-bit ops |
| 693 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i64, Custom); |
| 694 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i64, Custom); |
| 695 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i64, Custom); |
| 696 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i64, Custom); |
| 697 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i64, Custom); |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 698 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i64, Custom); |
| 699 | setOperationAction(ISD::ATOMIC_LOAD_MIN, MVT::i64, Custom); |
| 700 | setOperationAction(ISD::ATOMIC_LOAD_MAX, MVT::i64, Custom); |
| 701 | setOperationAction(ISD::ATOMIC_LOAD_UMIN, MVT::i64, Custom); |
| 702 | setOperationAction(ISD::ATOMIC_LOAD_UMAX, MVT::i64, Custom); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 703 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i64, Custom); |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 704 | // Automatically insert fences (dmb ist) around ATOMIC_SWAP etc. |
| 705 | setInsertFencesForAtomic(true); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 706 | } else { |
| 707 | // Set them all for expansion, which will force libcalls. |
| 708 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Expand); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 709 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 710 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i32, Expand); |
Jim Grosbach | ef6eb9c | 2010-06-18 23:03:10 +0000 | [diff] [blame] | 711 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 712 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 713 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 714 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 715 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 716 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 717 | setOperationAction(ISD::ATOMIC_LOAD_NAND, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 718 | setOperationAction(ISD::ATOMIC_LOAD_MIN, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 719 | setOperationAction(ISD::ATOMIC_LOAD_MAX, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 720 | setOperationAction(ISD::ATOMIC_LOAD_UMIN, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 721 | setOperationAction(ISD::ATOMIC_LOAD_UMAX, MVT::i32, Expand); |
Eli Friedman | 7cc1566 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 722 | // Mark ATOMIC_LOAD and ATOMIC_STORE custom so we can handle the |
| 723 | // Unordered/Monotonic case. |
| 724 | setOperationAction(ISD::ATOMIC_LOAD, MVT::i32, Custom); |
| 725 | setOperationAction(ISD::ATOMIC_STORE, MVT::i32, Custom); |
Jim Grosbach | 5def57a | 2010-06-23 16:08:49 +0000 | [diff] [blame] | 726 | // Since the libcalls include locking, fold in the fences |
| 727 | setShouldFoldAtomicFences(true); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 728 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 729 | |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 730 | setOperationAction(ISD::PREFETCH, MVT::Other, Custom); |
Evan Cheng | bc7deb0 | 2010-11-03 05:14:24 +0000 | [diff] [blame] | 731 | |
Eli Friedman | a2c6f45 | 2010-06-26 04:36:50 +0000 | [diff] [blame] | 732 | // Requires SXTB/SXTH, available on v6 and up in both ARM and Thumb modes. |
| 733 | if (!Subtarget->hasV6Ops()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 734 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand); |
| 735 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 736 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 737 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 738 | |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 739 | if (!TM.Options.UseSoftFloat && Subtarget->hasVFP2() && |
| 740 | !Subtarget->isThumb1Only()) { |
Bob Wilson | cb9a6aa | 2010-01-19 22:56:26 +0000 | [diff] [blame] | 741 | // Turn f64->i64 into VMOVRRD, i64 -> f64 to VMOVDRR |
Sylvestre Ledru | 94c2271 | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 742 | // iff target supports vfp2. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 743 | setOperationAction(ISD::BITCAST, MVT::i64, Custom); |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 744 | setOperationAction(ISD::FLT_ROUNDS_, MVT::i32, Custom); |
| 745 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 746 | |
| 747 | // We want to custom lower some of our intrinsics. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 748 | setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); |
Jim Grosbach | e97f968 | 2010-07-07 00:07:57 +0000 | [diff] [blame] | 749 | if (Subtarget->isTargetDarwin()) { |
| 750 | setOperationAction(ISD::EH_SJLJ_SETJMP, MVT::i32, Custom); |
| 751 | setOperationAction(ISD::EH_SJLJ_LONGJMP, MVT::Other, Custom); |
John McCall | 5f8fd54 | 2011-05-29 19:50:32 +0000 | [diff] [blame] | 752 | setLibcallName(RTLIB::UNWIND_RESUME, "_Unwind_SjLj_Resume"); |
Jim Grosbach | e97f968 | 2010-07-07 00:07:57 +0000 | [diff] [blame] | 753 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 754 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 755 | setOperationAction(ISD::SETCC, MVT::i32, Expand); |
| 756 | setOperationAction(ISD::SETCC, MVT::f32, Expand); |
| 757 | setOperationAction(ISD::SETCC, MVT::f64, Expand); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 758 | setOperationAction(ISD::SELECT, MVT::i32, Custom); |
| 759 | setOperationAction(ISD::SELECT, MVT::f32, Custom); |
| 760 | setOperationAction(ISD::SELECT, MVT::f64, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 761 | setOperationAction(ISD::SELECT_CC, MVT::i32, Custom); |
| 762 | setOperationAction(ISD::SELECT_CC, MVT::f32, Custom); |
| 763 | setOperationAction(ISD::SELECT_CC, MVT::f64, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 764 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 765 | setOperationAction(ISD::BRCOND, MVT::Other, Expand); |
| 766 | setOperationAction(ISD::BR_CC, MVT::i32, Custom); |
| 767 | setOperationAction(ISD::BR_CC, MVT::f32, Custom); |
| 768 | setOperationAction(ISD::BR_CC, MVT::f64, Custom); |
| 769 | setOperationAction(ISD::BR_JT, MVT::Other, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 770 | |
Dan Gohman | f96e4de | 2007-10-11 23:21:31 +0000 | [diff] [blame] | 771 | // We don't support sin/cos/fmod/copysign/pow |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 772 | setOperationAction(ISD::FSIN, MVT::f64, Expand); |
| 773 | setOperationAction(ISD::FSIN, MVT::f32, Expand); |
| 774 | setOperationAction(ISD::FCOS, MVT::f32, Expand); |
| 775 | setOperationAction(ISD::FCOS, MVT::f64, Expand); |
| 776 | setOperationAction(ISD::FREM, MVT::f64, Expand); |
| 777 | setOperationAction(ISD::FREM, MVT::f32, Expand); |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 778 | if (!TM.Options.UseSoftFloat && Subtarget->hasVFP2() && |
| 779 | !Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 780 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Custom); |
| 781 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Custom); |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 782 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 783 | setOperationAction(ISD::FPOW, MVT::f64, Expand); |
| 784 | setOperationAction(ISD::FPOW, MVT::f32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 785 | |
Evan Cheng | 3aef2ff | 2012-04-10 21:40:28 +0000 | [diff] [blame] | 786 | if (!Subtarget->hasVFP4()) { |
| 787 | setOperationAction(ISD::FMA, MVT::f64, Expand); |
| 788 | setOperationAction(ISD::FMA, MVT::f32, Expand); |
| 789 | } |
Cameron Zwarich | 3339084 | 2011-07-08 21:39:21 +0000 | [diff] [blame] | 790 | |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 791 | // Various VFP goodness |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 792 | if (!TM.Options.UseSoftFloat && !Subtarget->isThumb1Only()) { |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 793 | // int <-> fp are custom expanded into bit_convert + ARMISD ops. |
| 794 | if (Subtarget->hasVFP2()) { |
| 795 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom); |
| 796 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Custom); |
| 797 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom); |
| 798 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); |
| 799 | } |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 800 | // Special handling for half-precision FP. |
Anton Korobeynikov | f0d5007 | 2010-03-18 22:35:37 +0000 | [diff] [blame] | 801 | if (!Subtarget->hasFP16()) { |
| 802 | setOperationAction(ISD::FP16_TO_FP32, MVT::f32, Expand); |
| 803 | setOperationAction(ISD::FP32_TO_FP16, MVT::i32, Expand); |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 804 | } |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 805 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 806 | |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 807 | // We have target-specific dag combine patterns for the following nodes: |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 808 | // ARMISD::VMOVRRD - No need to call setTargetDAGCombine |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 809 | setTargetDAGCombine(ISD::ADD); |
| 810 | setTargetDAGCombine(ISD::SUB); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 811 | setTargetDAGCombine(ISD::MUL); |
Jakob Stoklund Olesen | a7390fa | 2012-09-07 17:34:15 +0000 | [diff] [blame] | 812 | setTargetDAGCombine(ISD::AND); |
| 813 | setTargetDAGCombine(ISD::OR); |
| 814 | setTargetDAGCombine(ISD::XOR); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 815 | |
Evan Cheng | 5fb468a | 2012-02-23 02:58:19 +0000 | [diff] [blame] | 816 | if (Subtarget->hasV6Ops()) |
| 817 | setTargetDAGCombine(ISD::SRL); |
| 818 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 819 | setStackPointerRegisterToSaveRestore(ARM::SP); |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 820 | |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 821 | if (TM.Options.UseSoftFloat || Subtarget->isThumb1Only() || |
| 822 | !Subtarget->hasVFP2()) |
Evan Cheng | f7d87ee | 2010-05-21 00:43:17 +0000 | [diff] [blame] | 823 | setSchedulingPreference(Sched::RegPressure); |
| 824 | else |
| 825 | setSchedulingPreference(Sched::Hybrid); |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 826 | |
Evan Cheng | 0521928 | 2011-01-06 06:52:41 +0000 | [diff] [blame] | 827 | //// temporary - rewrite interface to use type |
| 828 | maxStoresPerMemcpy = maxStoresPerMemcpyOptSize = 1; |
Lang Hames | 75757f9 | 2011-10-26 20:56:52 +0000 | [diff] [blame] | 829 | maxStoresPerMemset = 16; |
| 830 | maxStoresPerMemsetOptSize = Subtarget->isTargetDarwin() ? 8 : 4; |
Evan Cheng | f679939 | 2010-06-26 01:52:05 +0000 | [diff] [blame] | 831 | |
Rafael Espindola | cbeeae2 | 2010-07-11 04:01:49 +0000 | [diff] [blame] | 832 | // On ARM arguments smaller than 4 bytes are extended, so all arguments |
| 833 | // are at least 4 bytes aligned. |
| 834 | setMinStackArgumentAlignment(4); |
| 835 | |
Evan Cheng | fff606d | 2010-09-24 19:07:23 +0000 | [diff] [blame] | 836 | benefitFromCodePlacementOpt = true; |
Eli Friedman | fc5d305 | 2011-05-06 20:34:06 +0000 | [diff] [blame] | 837 | |
Benjamin Kramer | aaf723d | 2012-05-05 12:49:14 +0000 | [diff] [blame] | 838 | // Prefer likely predicted branches to selects on out-of-order cores. |
Silviu Baranga | 616471d | 2012-09-13 15:05:10 +0000 | [diff] [blame] | 839 | predictableSelectIsExpensive = Subtarget->isLikeA9(); |
Benjamin Kramer | aaf723d | 2012-05-05 12:49:14 +0000 | [diff] [blame] | 840 | |
Eli Friedman | fc5d305 | 2011-05-06 20:34:06 +0000 | [diff] [blame] | 841 | setMinFunctionAlignment(Subtarget->isThumb() ? 1 : 2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 842 | } |
| 843 | |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 844 | // FIXME: It might make sense to define the representative register class as the |
| 845 | // nearest super-register that has a non-null superset. For example, DPR_VFP2 is |
| 846 | // a super-register of SPR, and DPR is a superset if DPR_VFP2. Consequently, |
| 847 | // SPR's representative would be DPR_VFP2. This should work well if register |
| 848 | // pressure tracking were modified such that a register use would increment the |
| 849 | // pressure of the register class's representative and all of it's super |
| 850 | // classes' representatives transitively. We have not implemented this because |
| 851 | // of the difficulty prior to coalescing of modeling operand register classes |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 852 | // due to the common occurrence of cross class copies and subregister insertions |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 853 | // and extractions. |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 854 | std::pair<const TargetRegisterClass*, uint8_t> |
| 855 | ARMTargetLowering::findRepresentativeClass(EVT VT) const{ |
| 856 | const TargetRegisterClass *RRC = 0; |
| 857 | uint8_t Cost = 1; |
| 858 | switch (VT.getSimpleVT().SimpleTy) { |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 859 | default: |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 860 | return TargetLowering::findRepresentativeClass(VT); |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 861 | // Use DPR as representative register class for all floating point |
| 862 | // and vector types. Since there are 32 SPR registers and 32 DPR registers so |
| 863 | // the cost is 1 for both f32 and f64. |
| 864 | case MVT::f32: case MVT::f64: case MVT::v8i8: case MVT::v4i16: |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 865 | case MVT::v2i32: case MVT::v1i64: case MVT::v2f32: |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 866 | RRC = &ARM::DPRRegClass; |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 867 | // When NEON is used for SP, only half of the register file is available |
| 868 | // because operations that define both SP and DP results will be constrained |
| 869 | // to the VFP2 class (D0-D15). We currently model this constraint prior to |
| 870 | // coalescing by double-counting the SP regs. See the FIXME above. |
| 871 | if (Subtarget->useNEONForSinglePrecisionFP()) |
| 872 | Cost = 2; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 873 | break; |
| 874 | case MVT::v16i8: case MVT::v8i16: case MVT::v4i32: case MVT::v2i64: |
| 875 | case MVT::v4f32: case MVT::v2f64: |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 876 | RRC = &ARM::DPRRegClass; |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 877 | Cost = 2; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 878 | break; |
| 879 | case MVT::v4i64: |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 880 | RRC = &ARM::DPRRegClass; |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 881 | Cost = 4; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 882 | break; |
| 883 | case MVT::v8i64: |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 884 | RRC = &ARM::DPRRegClass; |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 885 | Cost = 8; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 886 | break; |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 887 | } |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 888 | return std::make_pair(RRC, Cost); |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 889 | } |
| 890 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 891 | const char *ARMTargetLowering::getTargetNodeName(unsigned Opcode) const { |
| 892 | switch (Opcode) { |
| 893 | default: return 0; |
| 894 | case ARMISD::Wrapper: return "ARMISD::Wrapper"; |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 895 | case ARMISD::WrapperDYN: return "ARMISD::WrapperDYN"; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 896 | case ARMISD::WrapperPIC: return "ARMISD::WrapperPIC"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 897 | case ARMISD::WrapperJT: return "ARMISD::WrapperJT"; |
| 898 | case ARMISD::CALL: return "ARMISD::CALL"; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 899 | case ARMISD::CALL_PRED: return "ARMISD::CALL_PRED"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 900 | case ARMISD::CALL_NOLINK: return "ARMISD::CALL_NOLINK"; |
| 901 | case ARMISD::tCALL: return "ARMISD::tCALL"; |
| 902 | case ARMISD::BRCOND: return "ARMISD::BRCOND"; |
| 903 | case ARMISD::BR_JT: return "ARMISD::BR_JT"; |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 904 | case ARMISD::BR2_JT: return "ARMISD::BR2_JT"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 905 | case ARMISD::RET_FLAG: return "ARMISD::RET_FLAG"; |
| 906 | case ARMISD::PIC_ADD: return "ARMISD::PIC_ADD"; |
| 907 | case ARMISD::CMP: return "ARMISD::CMP"; |
Bill Wendling | ad5c880 | 2012-06-11 08:07:26 +0000 | [diff] [blame] | 908 | case ARMISD::CMN: return "ARMISD::CMN"; |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 909 | case ARMISD::CMPZ: return "ARMISD::CMPZ"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 910 | case ARMISD::CMPFP: return "ARMISD::CMPFP"; |
| 911 | case ARMISD::CMPFPw0: return "ARMISD::CMPFPw0"; |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 912 | case ARMISD::BCC_i64: return "ARMISD::BCC_i64"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 913 | case ARMISD::FMSTAT: return "ARMISD::FMSTAT"; |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 914 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 915 | case ARMISD::CMOV: return "ARMISD::CMOV"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 916 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 917 | case ARMISD::RBIT: return "ARMISD::RBIT"; |
| 918 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 919 | case ARMISD::FTOSI: return "ARMISD::FTOSI"; |
| 920 | case ARMISD::FTOUI: return "ARMISD::FTOUI"; |
| 921 | case ARMISD::SITOF: return "ARMISD::SITOF"; |
| 922 | case ARMISD::UITOF: return "ARMISD::UITOF"; |
| 923 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 924 | case ARMISD::SRL_FLAG: return "ARMISD::SRL_FLAG"; |
| 925 | case ARMISD::SRA_FLAG: return "ARMISD::SRA_FLAG"; |
| 926 | case ARMISD::RRX: return "ARMISD::RRX"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 927 | |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 928 | case ARMISD::ADDC: return "ARMISD::ADDC"; |
| 929 | case ARMISD::ADDE: return "ARMISD::ADDE"; |
| 930 | case ARMISD::SUBC: return "ARMISD::SUBC"; |
| 931 | case ARMISD::SUBE: return "ARMISD::SUBE"; |
| 932 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 933 | case ARMISD::VMOVRRD: return "ARMISD::VMOVRRD"; |
| 934 | case ARMISD::VMOVDRR: return "ARMISD::VMOVDRR"; |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 935 | |
Evan Cheng | c594208 | 2009-10-28 06:55:03 +0000 | [diff] [blame] | 936 | case ARMISD::EH_SJLJ_SETJMP: return "ARMISD::EH_SJLJ_SETJMP"; |
| 937 | case ARMISD::EH_SJLJ_LONGJMP:return "ARMISD::EH_SJLJ_LONGJMP"; |
| 938 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 939 | case ARMISD::TC_RETURN: return "ARMISD::TC_RETURN"; |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 940 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 941 | case ARMISD::THREAD_POINTER:return "ARMISD::THREAD_POINTER"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 942 | |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 943 | case ARMISD::DYN_ALLOC: return "ARMISD::DYN_ALLOC"; |
| 944 | |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 945 | case ARMISD::MEMBARRIER: return "ARMISD::MEMBARRIER"; |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 946 | case ARMISD::MEMBARRIER_MCR: return "ARMISD::MEMBARRIER_MCR"; |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 947 | |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 948 | case ARMISD::PRELOAD: return "ARMISD::PRELOAD"; |
| 949 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 950 | case ARMISD::VCEQ: return "ARMISD::VCEQ"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 951 | case ARMISD::VCEQZ: return "ARMISD::VCEQZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 952 | case ARMISD::VCGE: return "ARMISD::VCGE"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 953 | case ARMISD::VCGEZ: return "ARMISD::VCGEZ"; |
| 954 | case ARMISD::VCLEZ: return "ARMISD::VCLEZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 955 | case ARMISD::VCGEU: return "ARMISD::VCGEU"; |
| 956 | case ARMISD::VCGT: return "ARMISD::VCGT"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 957 | case ARMISD::VCGTZ: return "ARMISD::VCGTZ"; |
| 958 | case ARMISD::VCLTZ: return "ARMISD::VCLTZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 959 | case ARMISD::VCGTU: return "ARMISD::VCGTU"; |
| 960 | case ARMISD::VTST: return "ARMISD::VTST"; |
| 961 | |
| 962 | case ARMISD::VSHL: return "ARMISD::VSHL"; |
| 963 | case ARMISD::VSHRs: return "ARMISD::VSHRs"; |
| 964 | case ARMISD::VSHRu: return "ARMISD::VSHRu"; |
| 965 | case ARMISD::VSHLLs: return "ARMISD::VSHLLs"; |
| 966 | case ARMISD::VSHLLu: return "ARMISD::VSHLLu"; |
| 967 | case ARMISD::VSHLLi: return "ARMISD::VSHLLi"; |
| 968 | case ARMISD::VSHRN: return "ARMISD::VSHRN"; |
| 969 | case ARMISD::VRSHRs: return "ARMISD::VRSHRs"; |
| 970 | case ARMISD::VRSHRu: return "ARMISD::VRSHRu"; |
| 971 | case ARMISD::VRSHRN: return "ARMISD::VRSHRN"; |
| 972 | case ARMISD::VQSHLs: return "ARMISD::VQSHLs"; |
| 973 | case ARMISD::VQSHLu: return "ARMISD::VQSHLu"; |
| 974 | case ARMISD::VQSHLsu: return "ARMISD::VQSHLsu"; |
| 975 | case ARMISD::VQSHRNs: return "ARMISD::VQSHRNs"; |
| 976 | case ARMISD::VQSHRNu: return "ARMISD::VQSHRNu"; |
| 977 | case ARMISD::VQSHRNsu: return "ARMISD::VQSHRNsu"; |
| 978 | case ARMISD::VQRSHRNs: return "ARMISD::VQRSHRNs"; |
| 979 | case ARMISD::VQRSHRNu: return "ARMISD::VQRSHRNu"; |
| 980 | case ARMISD::VQRSHRNsu: return "ARMISD::VQRSHRNsu"; |
| 981 | case ARMISD::VGETLANEu: return "ARMISD::VGETLANEu"; |
| 982 | case ARMISD::VGETLANEs: return "ARMISD::VGETLANEs"; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 983 | case ARMISD::VMOVIMM: return "ARMISD::VMOVIMM"; |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 984 | case ARMISD::VMVNIMM: return "ARMISD::VMVNIMM"; |
Evan Cheng | eaa192a | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 985 | case ARMISD::VMOVFPIMM: return "ARMISD::VMOVFPIMM"; |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 986 | case ARMISD::VDUP: return "ARMISD::VDUP"; |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 987 | case ARMISD::VDUPLANE: return "ARMISD::VDUPLANE"; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 988 | case ARMISD::VEXT: return "ARMISD::VEXT"; |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 989 | case ARMISD::VREV64: return "ARMISD::VREV64"; |
| 990 | case ARMISD::VREV32: return "ARMISD::VREV32"; |
| 991 | case ARMISD::VREV16: return "ARMISD::VREV16"; |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 992 | case ARMISD::VZIP: return "ARMISD::VZIP"; |
| 993 | case ARMISD::VUZP: return "ARMISD::VUZP"; |
| 994 | case ARMISD::VTRN: return "ARMISD::VTRN"; |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 995 | case ARMISD::VTBL1: return "ARMISD::VTBL1"; |
| 996 | case ARMISD::VTBL2: return "ARMISD::VTBL2"; |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 997 | case ARMISD::VMULLs: return "ARMISD::VMULLs"; |
| 998 | case ARMISD::VMULLu: return "ARMISD::VMULLu"; |
Arnold Schwaighofer | 67514e9 | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 999 | case ARMISD::UMLAL: return "ARMISD::UMLAL"; |
| 1000 | case ARMISD::SMLAL: return "ARMISD::SMLAL"; |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 1001 | case ARMISD::BUILD_VECTOR: return "ARMISD::BUILD_VECTOR"; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 1002 | case ARMISD::FMAX: return "ARMISD::FMAX"; |
| 1003 | case ARMISD::FMIN: return "ARMISD::FMIN"; |
Jim Grosbach | dd7d28a | 2010-07-17 01:50:57 +0000 | [diff] [blame] | 1004 | case ARMISD::BFI: return "ARMISD::BFI"; |
Bob Wilson | 364a72a | 2010-11-28 06:51:11 +0000 | [diff] [blame] | 1005 | case ARMISD::VORRIMM: return "ARMISD::VORRIMM"; |
| 1006 | case ARMISD::VBICIMM: return "ARMISD::VBICIMM"; |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 1007 | case ARMISD::VBSL: return "ARMISD::VBSL"; |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 1008 | case ARMISD::VLD2DUP: return "ARMISD::VLD2DUP"; |
| 1009 | case ARMISD::VLD3DUP: return "ARMISD::VLD3DUP"; |
| 1010 | case ARMISD::VLD4DUP: return "ARMISD::VLD4DUP"; |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 1011 | case ARMISD::VLD1_UPD: return "ARMISD::VLD1_UPD"; |
| 1012 | case ARMISD::VLD2_UPD: return "ARMISD::VLD2_UPD"; |
| 1013 | case ARMISD::VLD3_UPD: return "ARMISD::VLD3_UPD"; |
| 1014 | case ARMISD::VLD4_UPD: return "ARMISD::VLD4_UPD"; |
| 1015 | case ARMISD::VLD2LN_UPD: return "ARMISD::VLD2LN_UPD"; |
| 1016 | case ARMISD::VLD3LN_UPD: return "ARMISD::VLD3LN_UPD"; |
| 1017 | case ARMISD::VLD4LN_UPD: return "ARMISD::VLD4LN_UPD"; |
| 1018 | case ARMISD::VLD2DUP_UPD: return "ARMISD::VLD2DUP_UPD"; |
| 1019 | case ARMISD::VLD3DUP_UPD: return "ARMISD::VLD3DUP_UPD"; |
| 1020 | case ARMISD::VLD4DUP_UPD: return "ARMISD::VLD4DUP_UPD"; |
| 1021 | case ARMISD::VST1_UPD: return "ARMISD::VST1_UPD"; |
| 1022 | case ARMISD::VST2_UPD: return "ARMISD::VST2_UPD"; |
| 1023 | case ARMISD::VST3_UPD: return "ARMISD::VST3_UPD"; |
| 1024 | case ARMISD::VST4_UPD: return "ARMISD::VST4_UPD"; |
| 1025 | case ARMISD::VST2LN_UPD: return "ARMISD::VST2LN_UPD"; |
| 1026 | case ARMISD::VST3LN_UPD: return "ARMISD::VST3LN_UPD"; |
| 1027 | case ARMISD::VST4LN_UPD: return "ARMISD::VST4LN_UPD"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1028 | } |
| 1029 | } |
| 1030 | |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 1031 | EVT ARMTargetLowering::getSetCCResultType(EVT VT) const { |
| 1032 | if (!VT.isVector()) return getPointerTy(); |
| 1033 | return VT.changeVectorElementTypeToInteger(); |
| 1034 | } |
| 1035 | |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1036 | /// getRegClassFor - Return the register class that should be used for the |
| 1037 | /// specified value type. |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 1038 | const TargetRegisterClass *ARMTargetLowering::getRegClassFor(EVT VT) const { |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1039 | // Map v4i64 to QQ registers but do not make the type legal. Similarly map |
| 1040 | // v8i64 to QQQQ registers. v4i64 and v8i64 are only used for REG_SEQUENCE to |
| 1041 | // load / store 4 to 8 consecutive D registers. |
Evan Cheng | 4782b1e | 2010-05-15 02:20:21 +0000 | [diff] [blame] | 1042 | if (Subtarget->hasNEON()) { |
| 1043 | if (VT == MVT::v4i64) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1044 | return &ARM::QQPRRegClass; |
| 1045 | if (VT == MVT::v8i64) |
| 1046 | return &ARM::QQQQPRRegClass; |
Evan Cheng | 4782b1e | 2010-05-15 02:20:21 +0000 | [diff] [blame] | 1047 | } |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1048 | return TargetLowering::getRegClassFor(VT); |
| 1049 | } |
| 1050 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1051 | // Create a fast isel object. |
| 1052 | FastISel * |
Bob Wilson | d49edb7 | 2012-08-03 04:06:28 +0000 | [diff] [blame] | 1053 | ARMTargetLowering::createFastISel(FunctionLoweringInfo &funcInfo, |
| 1054 | const TargetLibraryInfo *libInfo) const { |
| 1055 | return ARM::createFastISel(funcInfo, libInfo); |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1056 | } |
| 1057 | |
Anton Korobeynikov | cec36f4 | 2010-07-24 21:52:08 +0000 | [diff] [blame] | 1058 | /// getMaximalGlobalOffset - Returns the maximal possible offset which can |
| 1059 | /// be used for loads / stores from the global. |
| 1060 | unsigned ARMTargetLowering::getMaximalGlobalOffset() const { |
| 1061 | return (Subtarget->isThumb1Only() ? 127 : 4095); |
| 1062 | } |
| 1063 | |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1064 | Sched::Preference ARMTargetLowering::getSchedulingPreference(SDNode *N) const { |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1065 | unsigned NumVals = N->getNumValues(); |
| 1066 | if (!NumVals) |
| 1067 | return Sched::RegPressure; |
| 1068 | |
| 1069 | for (unsigned i = 0; i != NumVals; ++i) { |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1070 | EVT VT = N->getValueType(i); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1071 | if (VT == MVT::Glue || VT == MVT::Other) |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1072 | continue; |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1073 | if (VT.isFloatingPoint() || VT.isVector()) |
Dan Gohman | 692c1d8 | 2011-10-24 17:55:11 +0000 | [diff] [blame] | 1074 | return Sched::ILP; |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1075 | } |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1076 | |
| 1077 | if (!N->isMachineOpcode()) |
| 1078 | return Sched::RegPressure; |
| 1079 | |
| 1080 | // Load are scheduled for latency even if there instruction itinerary |
| 1081 | // is not available. |
| 1082 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1083 | const MCInstrDesc &MCID = TII->get(N->getMachineOpcode()); |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1084 | |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1085 | if (MCID.getNumDefs() == 0) |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1086 | return Sched::RegPressure; |
| 1087 | if (!Itins->isEmpty() && |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1088 | Itins->getOperandCycle(MCID.getSchedClass(), 0) > 2) |
Dan Gohman | 692c1d8 | 2011-10-24 17:55:11 +0000 | [diff] [blame] | 1089 | return Sched::ILP; |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1090 | |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1091 | return Sched::RegPressure; |
| 1092 | } |
| 1093 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1094 | //===----------------------------------------------------------------------===// |
| 1095 | // Lowering Code |
| 1096 | //===----------------------------------------------------------------------===// |
| 1097 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1098 | /// IntCCToARMCC - Convert a DAG integer condition code to an ARM CC |
| 1099 | static ARMCC::CondCodes IntCCToARMCC(ISD::CondCode CC) { |
| 1100 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1101 | default: llvm_unreachable("Unknown condition code!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1102 | case ISD::SETNE: return ARMCC::NE; |
| 1103 | case ISD::SETEQ: return ARMCC::EQ; |
| 1104 | case ISD::SETGT: return ARMCC::GT; |
| 1105 | case ISD::SETGE: return ARMCC::GE; |
| 1106 | case ISD::SETLT: return ARMCC::LT; |
| 1107 | case ISD::SETLE: return ARMCC::LE; |
| 1108 | case ISD::SETUGT: return ARMCC::HI; |
| 1109 | case ISD::SETUGE: return ARMCC::HS; |
| 1110 | case ISD::SETULT: return ARMCC::LO; |
| 1111 | case ISD::SETULE: return ARMCC::LS; |
| 1112 | } |
| 1113 | } |
| 1114 | |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 1115 | /// FPCCToARMCC - Convert a DAG fp condition code to an ARM CC. |
| 1116 | static void FPCCToARMCC(ISD::CondCode CC, ARMCC::CondCodes &CondCode, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1117 | ARMCC::CondCodes &CondCode2) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1118 | CondCode2 = ARMCC::AL; |
| 1119 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1120 | default: llvm_unreachable("Unknown FP condition!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1121 | case ISD::SETEQ: |
| 1122 | case ISD::SETOEQ: CondCode = ARMCC::EQ; break; |
| 1123 | case ISD::SETGT: |
| 1124 | case ISD::SETOGT: CondCode = ARMCC::GT; break; |
| 1125 | case ISD::SETGE: |
| 1126 | case ISD::SETOGE: CondCode = ARMCC::GE; break; |
| 1127 | case ISD::SETOLT: CondCode = ARMCC::MI; break; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 1128 | case ISD::SETOLE: CondCode = ARMCC::LS; break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1129 | case ISD::SETONE: CondCode = ARMCC::MI; CondCode2 = ARMCC::GT; break; |
| 1130 | case ISD::SETO: CondCode = ARMCC::VC; break; |
| 1131 | case ISD::SETUO: CondCode = ARMCC::VS; break; |
| 1132 | case ISD::SETUEQ: CondCode = ARMCC::EQ; CondCode2 = ARMCC::VS; break; |
| 1133 | case ISD::SETUGT: CondCode = ARMCC::HI; break; |
| 1134 | case ISD::SETUGE: CondCode = ARMCC::PL; break; |
| 1135 | case ISD::SETLT: |
| 1136 | case ISD::SETULT: CondCode = ARMCC::LT; break; |
| 1137 | case ISD::SETLE: |
| 1138 | case ISD::SETULE: CondCode = ARMCC::LE; break; |
| 1139 | case ISD::SETNE: |
| 1140 | case ISD::SETUNE: CondCode = ARMCC::NE; break; |
| 1141 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1144 | //===----------------------------------------------------------------------===// |
| 1145 | // Calling Convention Implementation |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1146 | //===----------------------------------------------------------------------===// |
| 1147 | |
| 1148 | #include "ARMGenCallingConv.inc" |
| 1149 | |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1150 | /// CCAssignFnForNode - Selects the correct CCAssignFn for a the |
| 1151 | /// given CallingConvention value. |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1152 | CCAssignFn *ARMTargetLowering::CCAssignFnForNode(CallingConv::ID CC, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1153 | bool Return, |
| 1154 | bool isVarArg) const { |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1155 | switch (CC) { |
| 1156 | default: |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1157 | llvm_unreachable("Unsupported calling convention"); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1158 | case CallingConv::Fast: |
Evan Cheng | 5c2d428 | 2010-10-23 02:19:37 +0000 | [diff] [blame] | 1159 | if (Subtarget->hasVFP2() && !isVarArg) { |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1160 | if (!Subtarget->isAAPCS_ABI()) |
| 1161 | return (Return ? RetFastCC_ARM_APCS : FastCC_ARM_APCS); |
| 1162 | // For AAPCS ABI targets, just use VFP variant of the calling convention. |
| 1163 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1164 | } |
| 1165 | // Fallthrough |
| 1166 | case CallingConv::C: { |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1167 | // Use target triple & subtarget features to do actual dispatch. |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1168 | if (!Subtarget->isAAPCS_ABI()) |
| 1169 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS); |
| 1170 | else if (Subtarget->hasVFP2() && |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 1171 | getTargetMachine().Options.FloatABIType == FloatABI::Hard && |
| 1172 | !isVarArg) |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1173 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1174 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); |
| 1175 | } |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1176 | case CallingConv::ARM_AAPCS_VFP: |
Anton Korobeynikov | f349cb8 | 2012-01-29 09:06:09 +0000 | [diff] [blame] | 1177 | if (!isVarArg) |
| 1178 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1179 | // Fallthrough |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1180 | case CallingConv::ARM_AAPCS: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1181 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1182 | case CallingConv::ARM_APCS: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1183 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS); |
Eric Christopher | e94ac88 | 2012-08-03 00:05:53 +0000 | [diff] [blame] | 1184 | case CallingConv::GHC: |
| 1185 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS_GHC); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1186 | } |
| 1187 | } |
| 1188 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1189 | /// LowerCallResult - Lower the result values of a call into the |
| 1190 | /// appropriate copies out of appropriate physical registers. |
| 1191 | SDValue |
| 1192 | ARMTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1193 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1194 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1195 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1196 | SmallVectorImpl<SDValue> &InVals) const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1197 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1198 | // Assign locations to each value returned by this call. |
| 1199 | SmallVector<CCValAssign, 16> RVLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1200 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 1201 | getTargetMachine(), RVLocs, *DAG.getContext(), Call); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1202 | CCInfo.AnalyzeCallResult(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1203 | CCAssignFnForNode(CallConv, /* Return*/ true, |
| 1204 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1205 | |
| 1206 | // Copy all of the result registers out of their specified physreg. |
| 1207 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 1208 | CCValAssign VA = RVLocs[i]; |
| 1209 | |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1210 | SDValue Val; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1211 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1212 | // Handle f64 or half of a v2f64. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1213 | SDValue Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1214 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1215 | Chain = Lo.getValue(1); |
| 1216 | InFlag = Lo.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1217 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1218 | SDValue Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1219 | InFlag); |
| 1220 | Chain = Hi.getValue(1); |
| 1221 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1222 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1223 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1224 | if (VA.getLocVT() == MVT::v2f64) { |
| 1225 | SDValue Vec = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 1226 | Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 1227 | DAG.getConstant(0, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1228 | |
| 1229 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1230 | Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1231 | Chain = Lo.getValue(1); |
| 1232 | InFlag = Lo.getValue(2); |
| 1233 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1234 | Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1235 | Chain = Hi.getValue(1); |
| 1236 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1237 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1238 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 1239 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1240 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1241 | } else { |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1242 | Val = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), VA.getLocVT(), |
| 1243 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1244 | Chain = Val.getValue(1); |
| 1245 | InFlag = Val.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1246 | } |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1247 | |
| 1248 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1249 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1250 | case CCValAssign::Full: break; |
| 1251 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1252 | Val = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), Val); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1253 | break; |
| 1254 | } |
| 1255 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1256 | InVals.push_back(Val); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1257 | } |
| 1258 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1259 | return Chain; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1260 | } |
| 1261 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1262 | /// LowerMemOpCallTo - Store the argument to the stack. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1263 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1264 | ARMTargetLowering::LowerMemOpCallTo(SDValue Chain, |
| 1265 | SDValue StackPtr, SDValue Arg, |
| 1266 | DebugLoc dl, SelectionDAG &DAG, |
| 1267 | const CCValAssign &VA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1268 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1269 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| 1270 | SDValue PtrOff = DAG.getIntPtrConstant(LocMemOffset); |
| 1271 | PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, PtrOff); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1272 | return DAG.getStore(Chain, dl, Arg, PtrOff, |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 1273 | MachinePointerInfo::getStack(LocMemOffset), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1274 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1277 | void ARMTargetLowering::PassF64ArgInRegs(DebugLoc dl, SelectionDAG &DAG, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1278 | SDValue Chain, SDValue &Arg, |
| 1279 | RegsToPassVector &RegsToPass, |
| 1280 | CCValAssign &VA, CCValAssign &NextVA, |
| 1281 | SDValue &StackPtr, |
| 1282 | SmallVector<SDValue, 8> &MemOpChains, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1283 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1284 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1285 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1286 | DAG.getVTList(MVT::i32, MVT::i32), Arg); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1287 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), fmrrd)); |
| 1288 | |
| 1289 | if (NextVA.isRegLoc()) |
| 1290 | RegsToPass.push_back(std::make_pair(NextVA.getLocReg(), fmrrd.getValue(1))); |
| 1291 | else { |
| 1292 | assert(NextVA.isMemLoc()); |
| 1293 | if (StackPtr.getNode() == 0) |
| 1294 | StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
| 1295 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1296 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, fmrrd.getValue(1), |
| 1297 | dl, DAG, NextVA, |
| 1298 | Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1299 | } |
| 1300 | } |
| 1301 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1302 | /// LowerCall - Lowering a call into a callseq_start <- |
Evan Cheng | fc40342 | 2007-02-03 08:53:01 +0000 | [diff] [blame] | 1303 | /// ARMISD:CALL <- callseq_end chain. Also add input and output parameter |
| 1304 | /// nodes. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1305 | SDValue |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 1306 | ARMTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1307 | SmallVectorImpl<SDValue> &InVals) const { |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 1308 | SelectionDAG &DAG = CLI.DAG; |
| 1309 | DebugLoc &dl = CLI.DL; |
| 1310 | SmallVector<ISD::OutputArg, 32> &Outs = CLI.Outs; |
| 1311 | SmallVector<SDValue, 32> &OutVals = CLI.OutVals; |
| 1312 | SmallVector<ISD::InputArg, 32> &Ins = CLI.Ins; |
| 1313 | SDValue Chain = CLI.Chain; |
| 1314 | SDValue Callee = CLI.Callee; |
| 1315 | bool &isTailCall = CLI.IsTailCall; |
| 1316 | CallingConv::ID CallConv = CLI.CallConv; |
| 1317 | bool doesNotRet = CLI.DoesNotReturn; |
| 1318 | bool isVarArg = CLI.IsVarArg; |
| 1319 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1320 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1321 | bool IsStructRet = (Outs.empty()) ? false : Outs[0].Flags.isSRet(); |
| 1322 | bool IsSibCall = false; |
Bob Wilson | 6d2f9ce | 2011-10-07 17:17:49 +0000 | [diff] [blame] | 1323 | // Disable tail calls if they're not supported. |
| 1324 | if (!EnableARMTailCalls && !Subtarget->supportsTailCall()) |
Bob Wilson | 703af3a | 2010-08-13 22:43:33 +0000 | [diff] [blame] | 1325 | isTailCall = false; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1326 | if (isTailCall) { |
| 1327 | // Check if it's really possible to do a tail call. |
| 1328 | isTailCall = IsEligibleForTailCallOptimization(Callee, CallConv, |
| 1329 | isVarArg, IsStructRet, MF.getFunction()->hasStructRetAttr(), |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1330 | Outs, OutVals, Ins, DAG); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1331 | // We don't support GuaranteedTailCallOpt for ARM, only automatically |
| 1332 | // detected sibcalls. |
| 1333 | if (isTailCall) { |
| 1334 | ++NumTailCalls; |
| 1335 | IsSibCall = true; |
| 1336 | } |
| 1337 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1338 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1339 | // Analyze operands of the call, assigning locations to each operand. |
| 1340 | SmallVector<CCValAssign, 16> ArgLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1341 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 1342 | getTargetMachine(), ArgLocs, *DAG.getContext(), Call); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1343 | CCInfo.AnalyzeCallOperands(Outs, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1344 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 1345 | isVarArg)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1346 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1347 | // Get a count of how many bytes are to be pushed on the stack. |
| 1348 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1349 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1350 | // For tail calls, memory operands are available in our caller's stack. |
| 1351 | if (IsSibCall) |
| 1352 | NumBytes = 0; |
| 1353 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1354 | // Adjust the stack pointer for the new arguments... |
| 1355 | // These operations are automatically eliminated by the prolog/epilog pass |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1356 | if (!IsSibCall) |
| 1357 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumBytes, true)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1358 | |
Jim Grosbach | f9a4b76 | 2010-02-24 01:43:03 +0000 | [diff] [blame] | 1359 | SDValue StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1360 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1361 | RegsToPassVector RegsToPass; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1362 | SmallVector<SDValue, 8> MemOpChains; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1363 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1364 | // Walk the register/memloc assignments, inserting copies/loads. In the case |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1365 | // of tail call optimization, arguments are handled later. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1366 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 1367 | i != e; |
| 1368 | ++i, ++realArgIdx) { |
| 1369 | CCValAssign &VA = ArgLocs[i]; |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1370 | SDValue Arg = OutVals[realArgIdx]; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1371 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1372 | bool isByVal = Flags.isByVal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1373 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1374 | // Promote the value if needed. |
| 1375 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1376 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1377 | case CCValAssign::Full: break; |
| 1378 | case CCValAssign::SExt: |
| 1379 | Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); |
| 1380 | break; |
| 1381 | case CCValAssign::ZExt: |
| 1382 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); |
| 1383 | break; |
| 1384 | case CCValAssign::AExt: |
| 1385 | Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); |
| 1386 | break; |
| 1387 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1388 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1389 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1390 | } |
| 1391 | |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1392 | // 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] | 1393 | if (VA.needsCustom()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1394 | if (VA.getLocVT() == MVT::v2f64) { |
| 1395 | SDValue Op0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1396 | DAG.getConstant(0, MVT::i32)); |
| 1397 | SDValue Op1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1398 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1399 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1400 | PassF64ArgInRegs(dl, DAG, Chain, Op0, RegsToPass, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1401 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1402 | |
| 1403 | VA = ArgLocs[++i]; // skip ahead to next loc |
| 1404 | if (VA.isRegLoc()) { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1405 | PassF64ArgInRegs(dl, DAG, Chain, Op1, RegsToPass, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1406 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1407 | } else { |
| 1408 | assert(VA.isMemLoc()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1409 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1410 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Op1, |
| 1411 | dl, DAG, VA, Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1412 | } |
| 1413 | } else { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1414 | PassF64ArgInRegs(dl, DAG, Chain, Arg, RegsToPass, VA, ArgLocs[++i], |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1415 | StackPtr, MemOpChains, Flags); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1416 | } |
| 1417 | } else if (VA.isRegLoc()) { |
| 1418 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1419 | } else if (isByVal) { |
| 1420 | assert(VA.isMemLoc()); |
| 1421 | unsigned offset = 0; |
| 1422 | |
| 1423 | // True if this byval aggregate will be split between registers |
| 1424 | // and memory. |
| 1425 | if (CCInfo.isFirstByValRegValid()) { |
| 1426 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
| 1427 | unsigned int i, j; |
| 1428 | for (i = 0, j = CCInfo.getFirstByValReg(); j < ARM::R4; i++, j++) { |
| 1429 | SDValue Const = DAG.getConstant(4*i, MVT::i32); |
| 1430 | SDValue AddArg = DAG.getNode(ISD::ADD, dl, PtrVT, Arg, Const); |
| 1431 | SDValue Load = DAG.getLoad(PtrVT, dl, Chain, AddArg, |
| 1432 | MachinePointerInfo(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1433 | false, false, false, 0); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1434 | MemOpChains.push_back(Load.getValue(1)); |
| 1435 | RegsToPass.push_back(std::make_pair(j, Load)); |
| 1436 | } |
| 1437 | offset = ARM::R4 - CCInfo.getFirstByValReg(); |
| 1438 | CCInfo.clearFirstByValReg(); |
| 1439 | } |
| 1440 | |
Manman Ren | 763a75d | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 1441 | if (Flags.getByValSize() - 4*offset > 0) { |
| 1442 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| 1443 | SDValue StkPtrOff = DAG.getIntPtrConstant(LocMemOffset); |
| 1444 | SDValue Dst = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, |
| 1445 | StkPtrOff); |
| 1446 | SDValue SrcOffset = DAG.getIntPtrConstant(4*offset); |
| 1447 | SDValue Src = DAG.getNode(ISD::ADD, dl, getPointerTy(), Arg, SrcOffset); |
| 1448 | SDValue SizeNode = DAG.getConstant(Flags.getByValSize() - 4*offset, |
| 1449 | MVT::i32); |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 1450 | SDValue AlignNode = DAG.getConstant(Flags.getByValAlign(), MVT::i32); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1451 | |
Manman Ren | 763a75d | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 1452 | SDVTList VTs = DAG.getVTList(MVT::Other, MVT::Glue); |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 1453 | SDValue Ops[] = { Chain, Dst, Src, SizeNode, AlignNode}; |
Manman Ren | 763a75d | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 1454 | MemOpChains.push_back(DAG.getNode(ARMISD::COPY_STRUCT_BYVAL, dl, VTs, |
| 1455 | Ops, array_lengthof(Ops))); |
| 1456 | } |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1457 | } else if (!IsSibCall) { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1458 | assert(VA.isMemLoc()); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1459 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1460 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Arg, |
| 1461 | dl, DAG, VA, Flags)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1462 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | if (!MemOpChains.empty()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1466 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1467 | &MemOpChains[0], MemOpChains.size()); |
| 1468 | |
| 1469 | // Build a sequence of copy-to-reg nodes chained together with token chain |
| 1470 | // and flag operands which copy the outgoing args into the appropriate regs. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1471 | SDValue InFlag; |
Dale Johannesen | 6470a11 | 2010-06-15 22:08:33 +0000 | [diff] [blame] | 1472 | // Tail call byval lowering might overwrite argument registers so in case of |
| 1473 | // tail call optimization the copies to registers are lowered later. |
| 1474 | if (!isTailCall) |
| 1475 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1476 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1477 | RegsToPass[i].second, InFlag); |
| 1478 | InFlag = Chain.getValue(1); |
| 1479 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1480 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1481 | // For tail calls lower the arguments to the 'real' stack slot. |
| 1482 | if (isTailCall) { |
| 1483 | // Force all the incoming stack arguments to be loaded from the stack |
| 1484 | // before any new outgoing arguments are stored to the stack, because the |
| 1485 | // outgoing stack slots may alias the incoming argument stack slots, and |
| 1486 | // the alias isn't otherwise explicit. This is slightly more conservative |
| 1487 | // than necessary, because it means that each store effectively depends |
| 1488 | // on every argument instead of just those arguments it would clobber. |
| 1489 | |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 1490 | // Do not flag preceding copytoreg stuff together with the following stuff. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1491 | InFlag = SDValue(); |
| 1492 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1493 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1494 | RegsToPass[i].second, InFlag); |
| 1495 | InFlag = Chain.getValue(1); |
| 1496 | } |
| 1497 | InFlag =SDValue(); |
| 1498 | } |
| 1499 | |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1500 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
| 1501 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 1502 | // node so that legalize doesn't hack it. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1503 | bool isDirect = false; |
| 1504 | bool isARMFunc = false; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1505 | bool isLocalARMFunc = false; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1506 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1507 | |
| 1508 | if (EnableARMLongCalls) { |
| 1509 | assert (getTargetMachine().getRelocationModel() == Reloc::Static |
| 1510 | && "long-calls with non-static relocation model!"); |
| 1511 | // Handle a global address or an external symbol. If it's not one of |
| 1512 | // those, the target's already in a register, so we don't need to do |
| 1513 | // anything extra. |
| 1514 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Anders Carlsson | 0dbdca5 | 2010-04-15 03:11:28 +0000 | [diff] [blame] | 1515 | const GlobalValue *GV = G->getGlobal(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1516 | // Create a constant pool entry for the callee address |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1517 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 1518 | ARMConstantPoolValue *CPV = |
| 1519 | ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex, ARMCP::CPValue, 0); |
| 1520 | |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1521 | // Get the address of the callee into a register |
| 1522 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1523 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1524 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1525 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1526 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1527 | false, false, false, 0); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1528 | } else if (ExternalSymbolSDNode *S=dyn_cast<ExternalSymbolSDNode>(Callee)) { |
| 1529 | const char *Sym = S->getSymbol(); |
| 1530 | |
| 1531 | // Create a constant pool entry for the callee address |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1532 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | fe31e67 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 1533 | ARMConstantPoolValue *CPV = |
| 1534 | ARMConstantPoolSymbol::Create(*DAG.getContext(), Sym, |
| 1535 | ARMPCLabelIndex, 0); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1536 | // Get the address of the callee into a register |
| 1537 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1538 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1539 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1540 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1541 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1542 | false, false, false, 0); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1543 | } |
| 1544 | } else if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1545 | const GlobalValue *GV = G->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1546 | isDirect = true; |
Chris Lattner | 4fb63d0 | 2009-07-15 04:12:33 +0000 | [diff] [blame] | 1547 | bool isExt = GV->isDeclaration() || GV->isWeakForLinker(); |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1548 | bool isStub = (isExt && Subtarget->isTargetDarwin()) && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1549 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1550 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1551 | // ARM call to a local ARM function is predicable. |
Evan Cheng | 46df4eb | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 1552 | isLocalARMFunc = !Subtarget->isThumb() && (!isExt || !ARMInterworking); |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1553 | // tBX takes a register source operand. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1554 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1555 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 1556 | ARMConstantPoolValue *CPV = |
| 1557 | ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex, ARMCP::CPValue, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1558 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1559 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1560 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1561 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1562 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1563 | false, false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1564 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1565 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1566 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | 637d89f | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1567 | } else { |
| 1568 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1569 | unsigned OpFlags = 0; |
| 1570 | if (Subtarget->isTargetELF() && |
| 1571 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1572 | OpFlags = ARMII::MO_PLT; |
| 1573 | Callee = DAG.getTargetGlobalAddress(GV, dl, getPointerTy(), 0, OpFlags); |
| 1574 | } |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1575 | } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1576 | isDirect = true; |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1577 | bool isStub = Subtarget->isTargetDarwin() && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1578 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1579 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1580 | // tBX takes a register source operand. |
| 1581 | const char *Sym = S->getSymbol(); |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1582 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1583 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | fe31e67 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 1584 | ARMConstantPoolValue *CPV = |
| 1585 | ARMConstantPoolSymbol::Create(*DAG.getContext(), Sym, |
| 1586 | ARMPCLabelIndex, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1587 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1588 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1589 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1590 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1591 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 1592 | false, false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1593 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1594 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1595 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | 637d89f | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1596 | } else { |
| 1597 | unsigned OpFlags = 0; |
| 1598 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1599 | if (Subtarget->isTargetELF() && |
| 1600 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1601 | OpFlags = ARMII::MO_PLT; |
| 1602 | Callee = DAG.getTargetExternalSymbol(Sym, getPointerTy(), OpFlags); |
| 1603 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1604 | } |
| 1605 | |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1606 | // FIXME: handle tail calls differently. |
| 1607 | unsigned CallOpc; |
Quentin Colombet | 9a419f6 | 2012-10-30 16:32:52 +0000 | [diff] [blame] | 1608 | bool HasMinSizeAttr = MF.getFunction()->getFnAttributes(). |
| 1609 | hasAttribute(Attributes::MinSize); |
Evan Cheng | b620724 | 2009-08-01 00:16:10 +0000 | [diff] [blame] | 1610 | if (Subtarget->isThumb()) { |
| 1611 | if ((!isDirect || isARMFunc) && !Subtarget->hasV5TOps()) |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1612 | CallOpc = ARMISD::CALL_NOLINK; |
| 1613 | else |
| 1614 | CallOpc = isARMFunc ? ARMISD::CALL : ARMISD::tCALL; |
| 1615 | } else { |
Evan Cheng | b341fac | 2012-11-10 02:09:05 +0000 | [diff] [blame] | 1616 | if (!isDirect && !Subtarget->hasV5TOps()) |
Evan Cheng | 4bfcd4a | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 1617 | CallOpc = ARMISD::CALL_NOLINK; |
Evan Cheng | b341fac | 2012-11-10 02:09:05 +0000 | [diff] [blame] | 1618 | else if (doesNotRet && isDirect && Subtarget->hasRAS() && |
Quentin Colombet | 43934ae | 2012-11-02 21:32:17 +0000 | [diff] [blame] | 1619 | // Emit regular call when code size is the priority |
| 1620 | !HasMinSizeAttr) |
Evan Cheng | 4bfcd4a | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 1621 | // "mov lr, pc; b _foo" to avoid confusing the RSP |
| 1622 | CallOpc = ARMISD::CALL_NOLINK; |
| 1623 | else |
| 1624 | CallOpc = isLocalARMFunc ? ARMISD::CALL_PRED : ARMISD::CALL; |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1625 | } |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1626 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1627 | std::vector<SDValue> Ops; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1628 | Ops.push_back(Chain); |
| 1629 | Ops.push_back(Callee); |
| 1630 | |
| 1631 | // Add argument registers to the end of the list so that they are known live |
| 1632 | // into the call. |
| 1633 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) |
| 1634 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 1635 | RegsToPass[i].second.getValueType())); |
| 1636 | |
Jakob Stoklund Olesen | c54f634 | 2012-02-24 01:19:29 +0000 | [diff] [blame] | 1637 | // Add a register mask operand representing the call-preserved registers. |
| 1638 | const TargetRegisterInfo *TRI = getTargetMachine().getRegisterInfo(); |
| 1639 | const uint32_t *Mask = TRI->getCallPreservedMask(CallConv); |
| 1640 | assert(Mask && "Missing call preserved mask for calling convention"); |
| 1641 | Ops.push_back(DAG.getRegisterMask(Mask)); |
| 1642 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1643 | if (InFlag.getNode()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1644 | Ops.push_back(InFlag); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1645 | |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1646 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1647 | if (isTailCall) |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1648 | return DAG.getNode(ARMISD::TC_RETURN, dl, NodeTys, &Ops[0], Ops.size()); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1649 | |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1650 | // Returns a chain and a flag for retval copy to use. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1651 | Chain = DAG.getNode(CallOpc, dl, NodeTys, &Ops[0], Ops.size()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1652 | InFlag = Chain.getValue(1); |
| 1653 | |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1654 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, true), |
| 1655 | DAG.getIntPtrConstant(0, true), InFlag); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1656 | if (!Ins.empty()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1657 | InFlag = Chain.getValue(1); |
| 1658 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1659 | // Handle result values, copying them out of physregs into vregs that we |
| 1660 | // return. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1661 | return LowerCallResult(Chain, InFlag, CallConv, isVarArg, Ins, |
| 1662 | dl, DAG, InVals); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1663 | } |
| 1664 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1665 | /// HandleByVal - Every parameter *after* a byval parameter is passed |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1666 | /// on the stack. Remember the next parameter register to allocate, |
| 1667 | /// and then confiscate the rest of the parameter registers to insure |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1668 | /// this. |
| 1669 | void |
Stepan Dyatkovskiy | b52ba9f | 2012-10-16 07:16:47 +0000 | [diff] [blame] | 1670 | ARMTargetLowering::HandleByVal( |
| 1671 | CCState *State, unsigned &size, unsigned Align) const { |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1672 | unsigned reg = State->AllocateReg(GPRArgRegs, 4); |
| 1673 | assert((State->getCallOrPrologue() == Prologue || |
| 1674 | State->getCallOrPrologue() == Call) && |
| 1675 | "unhandled ParmContext"); |
| 1676 | if ((!State->isFirstByValRegValid()) && |
| 1677 | (ARM::R0 <= reg) && (reg <= ARM::R3)) { |
Stepan Dyatkovskiy | b52ba9f | 2012-10-16 07:16:47 +0000 | [diff] [blame] | 1678 | if (Subtarget->isAAPCS_ABI() && Align > 4) { |
| 1679 | unsigned AlignInRegs = Align / 4; |
| 1680 | unsigned Waste = (ARM::R4 - reg) % AlignInRegs; |
| 1681 | for (unsigned i = 0; i < Waste; ++i) |
| 1682 | reg = State->AllocateReg(GPRArgRegs, 4); |
| 1683 | } |
| 1684 | if (reg != 0) { |
| 1685 | State->setFirstByValReg(reg); |
| 1686 | // At a call site, a byval parameter that is split between |
| 1687 | // registers and memory needs its size truncated here. In a |
| 1688 | // function prologue, such byval parameters are reassembled in |
| 1689 | // memory, and are not truncated. |
| 1690 | if (State->getCallOrPrologue() == Call) { |
| 1691 | unsigned excess = 4 * (ARM::R4 - reg); |
| 1692 | assert(size >= excess && "expected larger existing stack allocation"); |
| 1693 | size -= excess; |
| 1694 | } |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1695 | } |
| 1696 | } |
| 1697 | // Confiscate any remaining parameter registers to preclude their |
| 1698 | // assignment to subsequent parameters. |
| 1699 | while (State->AllocateReg(GPRArgRegs, 4)) |
| 1700 | ; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1701 | } |
| 1702 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1703 | /// MatchingStackOffset - Return true if the given stack call argument is |
| 1704 | /// already available in the same position (relatively) of the caller's |
| 1705 | /// incoming argument stack. |
| 1706 | static |
| 1707 | bool MatchingStackOffset(SDValue Arg, unsigned Offset, ISD::ArgFlagsTy Flags, |
| 1708 | MachineFrameInfo *MFI, const MachineRegisterInfo *MRI, |
Craig Topper | acf2077 | 2012-03-25 23:49:58 +0000 | [diff] [blame] | 1709 | const TargetInstrInfo *TII) { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1710 | unsigned Bytes = Arg.getValueType().getSizeInBits() / 8; |
| 1711 | int FI = INT_MAX; |
| 1712 | if (Arg.getOpcode() == ISD::CopyFromReg) { |
| 1713 | unsigned VR = cast<RegisterSDNode>(Arg.getOperand(1))->getReg(); |
Jakob Stoklund Olesen | c9df025 | 2011-01-10 02:58:51 +0000 | [diff] [blame] | 1714 | if (!TargetRegisterInfo::isVirtualRegister(VR)) |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1715 | return false; |
| 1716 | MachineInstr *Def = MRI->getVRegDef(VR); |
| 1717 | if (!Def) |
| 1718 | return false; |
| 1719 | if (!Flags.isByVal()) { |
| 1720 | if (!TII->isLoadFromStackSlot(Def, FI)) |
| 1721 | return false; |
| 1722 | } else { |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1723 | return false; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1724 | } |
| 1725 | } else if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Arg)) { |
| 1726 | if (Flags.isByVal()) |
| 1727 | // ByVal argument is passed in as a pointer but it's now being |
| 1728 | // dereferenced. e.g. |
| 1729 | // define @foo(%struct.X* %A) { |
| 1730 | // tail call @bar(%struct.X* byval %A) |
| 1731 | // } |
| 1732 | return false; |
| 1733 | SDValue Ptr = Ld->getBasePtr(); |
| 1734 | FrameIndexSDNode *FINode = dyn_cast<FrameIndexSDNode>(Ptr); |
| 1735 | if (!FINode) |
| 1736 | return false; |
| 1737 | FI = FINode->getIndex(); |
| 1738 | } else |
| 1739 | return false; |
| 1740 | |
| 1741 | assert(FI != INT_MAX); |
| 1742 | if (!MFI->isFixedObjectIndex(FI)) |
| 1743 | return false; |
| 1744 | return Offset == MFI->getObjectOffset(FI) && Bytes == MFI->getObjectSize(FI); |
| 1745 | } |
| 1746 | |
| 1747 | /// IsEligibleForTailCallOptimization - Check whether the call is eligible |
| 1748 | /// for tail call optimization. Targets which want to do tail call |
| 1749 | /// optimization should implement this function. |
| 1750 | bool |
| 1751 | ARMTargetLowering::IsEligibleForTailCallOptimization(SDValue Callee, |
| 1752 | CallingConv::ID CalleeCC, |
| 1753 | bool isVarArg, |
| 1754 | bool isCalleeStructRet, |
| 1755 | bool isCallerStructRet, |
| 1756 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1757 | const SmallVectorImpl<SDValue> &OutVals, |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1758 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1759 | SelectionDAG& DAG) const { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1760 | const Function *CallerF = DAG.getMachineFunction().getFunction(); |
| 1761 | CallingConv::ID CallerCC = CallerF->getCallingConv(); |
| 1762 | bool CCMatch = CallerCC == CalleeCC; |
| 1763 | |
| 1764 | // Look for obvious safe cases to perform tail call optimization that do not |
| 1765 | // require ABI changes. This is what gcc calls sibcall. |
| 1766 | |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 1767 | // Do not sibcall optimize vararg calls unless the call site is not passing |
| 1768 | // any arguments. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1769 | if (isVarArg && !Outs.empty()) |
| 1770 | return false; |
| 1771 | |
| 1772 | // Also avoid sibcall optimization if either caller or callee uses struct |
| 1773 | // return semantics. |
| 1774 | if (isCalleeStructRet || isCallerStructRet) |
| 1775 | return false; |
| 1776 | |
Dale Johannesen | e39fdbe | 2010-06-23 18:52:34 +0000 | [diff] [blame] | 1777 | // FIXME: Completely disable sibcall for Thumb1 since Thumb1RegisterInfo:: |
Jim Grosbach | 8dc41f3 | 2011-07-08 20:18:11 +0000 | [diff] [blame] | 1778 | // emitEpilogue is not ready for them. Thumb tail calls also use t2B, as |
| 1779 | // the Thumb1 16-bit unconditional branch doesn't have sufficient relocation |
| 1780 | // support in the assembler and linker to be used. This would need to be |
| 1781 | // fixed to fully support tail calls in Thumb1. |
| 1782 | // |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1783 | // Doing this is tricky, since the LDM/POP instruction on Thumb doesn't take |
| 1784 | // LR. This means if we need to reload LR, it takes an extra instructions, |
| 1785 | // which outweighs the value of the tail call; but here we don't know yet |
| 1786 | // 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] | 1787 | // 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] | 1788 | // emitEpilogue if LR is used. |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1789 | |
| 1790 | // Thumb1 PIC calls to external symbols use BX, so they can be tail calls, |
| 1791 | // but we need to make sure there are enough registers; the only valid |
| 1792 | // registers are the 4 used for parameters. We don't currently do this |
| 1793 | // case. |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1794 | if (Subtarget->isThumb1Only()) |
| 1795 | return false; |
Dale Johannesen | df50d7e | 2010-06-18 18:13:11 +0000 | [diff] [blame] | 1796 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1797 | // If the calling conventions do not match, then we'd better make sure the |
| 1798 | // results are returned in the same way as what the caller expects. |
| 1799 | if (!CCMatch) { |
| 1800 | SmallVector<CCValAssign, 16> RVLocs1; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1801 | ARMCCState CCInfo1(CalleeCC, false, DAG.getMachineFunction(), |
| 1802 | getTargetMachine(), RVLocs1, *DAG.getContext(), Call); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1803 | CCInfo1.AnalyzeCallResult(Ins, CCAssignFnForNode(CalleeCC, true, isVarArg)); |
| 1804 | |
| 1805 | SmallVector<CCValAssign, 16> RVLocs2; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1806 | ARMCCState CCInfo2(CallerCC, false, DAG.getMachineFunction(), |
| 1807 | getTargetMachine(), RVLocs2, *DAG.getContext(), Call); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1808 | CCInfo2.AnalyzeCallResult(Ins, CCAssignFnForNode(CallerCC, true, isVarArg)); |
| 1809 | |
| 1810 | if (RVLocs1.size() != RVLocs2.size()) |
| 1811 | return false; |
| 1812 | for (unsigned i = 0, e = RVLocs1.size(); i != e; ++i) { |
| 1813 | if (RVLocs1[i].isRegLoc() != RVLocs2[i].isRegLoc()) |
| 1814 | return false; |
| 1815 | if (RVLocs1[i].getLocInfo() != RVLocs2[i].getLocInfo()) |
| 1816 | return false; |
| 1817 | if (RVLocs1[i].isRegLoc()) { |
| 1818 | if (RVLocs1[i].getLocReg() != RVLocs2[i].getLocReg()) |
| 1819 | return false; |
| 1820 | } else { |
| 1821 | if (RVLocs1[i].getLocMemOffset() != RVLocs2[i].getLocMemOffset()) |
| 1822 | return false; |
| 1823 | } |
| 1824 | } |
| 1825 | } |
| 1826 | |
Manman Ren | e6c3cc8 | 2012-10-12 23:39:43 +0000 | [diff] [blame] | 1827 | // If Caller's vararg or byval argument has been split between registers and |
| 1828 | // stack, do not perform tail call, since part of the argument is in caller's |
| 1829 | // local frame. |
| 1830 | const ARMFunctionInfo *AFI_Caller = DAG.getMachineFunction(). |
| 1831 | getInfo<ARMFunctionInfo>(); |
| 1832 | if (AFI_Caller->getVarArgsRegSaveSize()) |
| 1833 | return false; |
| 1834 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1835 | // If the callee takes no arguments then go on to check the results of the |
| 1836 | // call. |
| 1837 | if (!Outs.empty()) { |
| 1838 | // Check if stack adjustment is needed. For now, do not do this if any |
| 1839 | // argument is passed on the stack. |
| 1840 | SmallVector<CCValAssign, 16> ArgLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1841 | ARMCCState CCInfo(CalleeCC, isVarArg, DAG.getMachineFunction(), |
| 1842 | getTargetMachine(), ArgLocs, *DAG.getContext(), Call); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1843 | CCInfo.AnalyzeCallOperands(Outs, |
| 1844 | CCAssignFnForNode(CalleeCC, false, isVarArg)); |
| 1845 | if (CCInfo.getNextStackOffset()) { |
| 1846 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1847 | |
| 1848 | // Check if the arguments are already laid out in the right way as |
| 1849 | // the caller's fixed stack objects. |
| 1850 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 1851 | const MachineRegisterInfo *MRI = &MF.getRegInfo(); |
Craig Topper | acf2077 | 2012-03-25 23:49:58 +0000 | [diff] [blame] | 1852 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1853 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 1854 | i != e; |
| 1855 | ++i, ++realArgIdx) { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1856 | CCValAssign &VA = ArgLocs[i]; |
| 1857 | EVT RegVT = VA.getLocVT(); |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1858 | SDValue Arg = OutVals[realArgIdx]; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1859 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1860 | if (VA.getLocInfo() == CCValAssign::Indirect) |
| 1861 | return false; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1862 | if (VA.needsCustom()) { |
| 1863 | // f64 and vector types are split into multiple registers or |
| 1864 | // register/stack-slot combinations. The types will not match |
| 1865 | // the registers; give up on memory f64 refs until we figure |
| 1866 | // out what to do about this. |
| 1867 | if (!VA.isRegLoc()) |
| 1868 | return false; |
| 1869 | if (!ArgLocs[++i].isRegLoc()) |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 1870 | return false; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1871 | if (RegVT == MVT::v2f64) { |
| 1872 | if (!ArgLocs[++i].isRegLoc()) |
| 1873 | return false; |
| 1874 | if (!ArgLocs[++i].isRegLoc()) |
| 1875 | return false; |
| 1876 | } |
| 1877 | } else if (!VA.isRegLoc()) { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1878 | if (!MatchingStackOffset(Arg, VA.getLocMemOffset(), Flags, |
| 1879 | MFI, MRI, TII)) |
| 1880 | return false; |
| 1881 | } |
| 1882 | } |
| 1883 | } |
| 1884 | } |
| 1885 | |
| 1886 | return true; |
| 1887 | } |
| 1888 | |
Benjamin Kramer | 350c008 | 2012-11-28 20:55:10 +0000 | [diff] [blame] | 1889 | bool |
| 1890 | ARMTargetLowering::CanLowerReturn(CallingConv::ID CallConv, |
| 1891 | MachineFunction &MF, bool isVarArg, |
| 1892 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 1893 | LLVMContext &Context) const { |
| 1894 | SmallVector<CCValAssign, 16> RVLocs; |
| 1895 | CCState CCInfo(CallConv, isVarArg, MF, getTargetMachine(), RVLocs, Context); |
| 1896 | return CCInfo.CheckReturn(Outs, CCAssignFnForNode(CallConv, /*Return=*/true, |
| 1897 | isVarArg)); |
| 1898 | } |
| 1899 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1900 | SDValue |
| 1901 | ARMTargetLowering::LowerReturn(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1902 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1903 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1904 | const SmallVectorImpl<SDValue> &OutVals, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1905 | DebugLoc dl, SelectionDAG &DAG) const { |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1906 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1907 | // CCValAssign - represent the assignment of the return value to a location. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1908 | SmallVector<CCValAssign, 16> RVLocs; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1909 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1910 | // CCState - Info about the registers and stack slots. |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1911 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 1912 | getTargetMachine(), RVLocs, *DAG.getContext(), Call); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1913 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1914 | // Analyze outgoing return values. |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1915 | CCInfo.AnalyzeReturn(Outs, CCAssignFnForNode(CallConv, /* Return */ true, |
| 1916 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1917 | |
| 1918 | // If this is the first return lowered for this function, add |
| 1919 | // the regs to the liveout set for the function. |
| 1920 | if (DAG.getMachineFunction().getRegInfo().liveout_empty()) { |
| 1921 | for (unsigned i = 0; i != RVLocs.size(); ++i) |
| 1922 | if (RVLocs[i].isRegLoc()) |
| 1923 | DAG.getMachineFunction().getRegInfo().addLiveOut(RVLocs[i].getLocReg()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1924 | } |
| 1925 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1926 | SDValue Flag; |
| 1927 | |
| 1928 | // Copy the result values into the output registers. |
| 1929 | for (unsigned i = 0, realRVLocIdx = 0; |
| 1930 | i != RVLocs.size(); |
| 1931 | ++i, ++realRVLocIdx) { |
| 1932 | CCValAssign &VA = RVLocs[i]; |
| 1933 | assert(VA.isRegLoc() && "Can only return in registers!"); |
| 1934 | |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1935 | SDValue Arg = OutVals[realRVLocIdx]; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1936 | |
| 1937 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1938 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1939 | case CCValAssign::Full: break; |
| 1940 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1941 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1942 | break; |
| 1943 | } |
| 1944 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1945 | if (VA.needsCustom()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1946 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1947 | // Extract the first half and return it in two registers. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1948 | SDValue Half = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1949 | DAG.getConstant(0, MVT::i32)); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1950 | SDValue HalfGPRs = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1951 | DAG.getVTList(MVT::i32, MVT::i32), Half); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1952 | |
| 1953 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), HalfGPRs, Flag); |
| 1954 | Flag = Chain.getValue(1); |
| 1955 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1956 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
| 1957 | HalfGPRs.getValue(1), Flag); |
| 1958 | Flag = Chain.getValue(1); |
| 1959 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1960 | |
| 1961 | // 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] | 1962 | Arg = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1963 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1964 | } |
| 1965 | // Legalize ret f64 -> ret 2 x i32. We always have fmrrd if f64 is |
| 1966 | // available. |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1967 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1968 | DAG.getVTList(MVT::i32, MVT::i32), &Arg, 1); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1969 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd, Flag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1970 | Flag = Chain.getValue(1); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1971 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1972 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd.getValue(1), |
| 1973 | Flag); |
| 1974 | } else |
| 1975 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), Arg, Flag); |
| 1976 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1977 | // Guarantee that all emitted copies are |
| 1978 | // stuck together, avoiding something bad. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1979 | Flag = Chain.getValue(1); |
| 1980 | } |
| 1981 | |
| 1982 | SDValue result; |
| 1983 | if (Flag.getNode()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1984 | result = DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, Chain, Flag); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1985 | else // Return Void |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1986 | result = DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, Chain); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1987 | |
| 1988 | return result; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1989 | } |
| 1990 | |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 1991 | bool ARMTargetLowering::isUsedByReturnOnly(SDNode *N, SDValue &Chain) const { |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1992 | if (N->getNumValues() != 1) |
| 1993 | return false; |
| 1994 | if (!N->hasNUsesOfValue(1, 0)) |
| 1995 | return false; |
| 1996 | |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 1997 | SDValue TCChain = Chain; |
| 1998 | SDNode *Copy = *N->use_begin(); |
| 1999 | if (Copy->getOpcode() == ISD::CopyToReg) { |
| 2000 | // If the copy has a glue operand, we conservatively assume it isn't safe to |
| 2001 | // perform a tail call. |
| 2002 | if (Copy->getOperand(Copy->getNumOperands()-1).getValueType() == MVT::Glue) |
| 2003 | return false; |
| 2004 | TCChain = Copy->getOperand(0); |
| 2005 | } else if (Copy->getOpcode() == ARMISD::VMOVRRD) { |
| 2006 | SDNode *VMov = Copy; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2007 | // f64 returned in a pair of GPRs. |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2008 | SmallPtrSet<SDNode*, 2> Copies; |
| 2009 | for (SDNode::use_iterator UI = VMov->use_begin(), UE = VMov->use_end(); |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2010 | UI != UE; ++UI) { |
| 2011 | if (UI->getOpcode() != ISD::CopyToReg) |
| 2012 | return false; |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2013 | Copies.insert(*UI); |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2014 | } |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2015 | if (Copies.size() > 2) |
| 2016 | return false; |
| 2017 | |
| 2018 | for (SDNode::use_iterator UI = VMov->use_begin(), UE = VMov->use_end(); |
| 2019 | UI != UE; ++UI) { |
| 2020 | SDValue UseChain = UI->getOperand(0); |
| 2021 | if (Copies.count(UseChain.getNode())) |
| 2022 | // Second CopyToReg |
| 2023 | Copy = *UI; |
| 2024 | else |
| 2025 | // First CopyToReg |
| 2026 | TCChain = UseChain; |
| 2027 | } |
| 2028 | } else if (Copy->getOpcode() == ISD::BITCAST) { |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2029 | // f32 returned in a single GPR. |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2030 | if (!Copy->hasOneUse()) |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2031 | return false; |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2032 | Copy = *Copy->use_begin(); |
| 2033 | if (Copy->getOpcode() != ISD::CopyToReg || !Copy->hasNUsesOfValue(1, 0)) |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2034 | return false; |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2035 | Chain = Copy->getOperand(0); |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2036 | } else { |
| 2037 | return false; |
| 2038 | } |
| 2039 | |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 2040 | bool HasRet = false; |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2041 | for (SDNode::use_iterator UI = Copy->use_begin(), UE = Copy->use_end(); |
| 2042 | UI != UE; ++UI) { |
| 2043 | if (UI->getOpcode() != ARMISD::RET_FLAG) |
| 2044 | return false; |
| 2045 | HasRet = true; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2046 | } |
| 2047 | |
Evan Cheng | bf010eb | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2048 | if (!HasRet) |
| 2049 | return false; |
| 2050 | |
| 2051 | Chain = TCChain; |
| 2052 | return true; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2053 | } |
| 2054 | |
Evan Cheng | 485fafc | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 2055 | bool ARMTargetLowering::mayBeEmittedAsTailCall(CallInst *CI) const { |
Evan Cheng | 1c80f56 | 2012-03-30 01:24:39 +0000 | [diff] [blame] | 2056 | if (!EnableARMTailCalls && !Subtarget->supportsTailCall()) |
Evan Cheng | 485fafc | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 2057 | return false; |
| 2058 | |
| 2059 | if (!CI->isTailCall()) |
| 2060 | return false; |
| 2061 | |
| 2062 | return !Subtarget->isThumb1Only(); |
| 2063 | } |
| 2064 | |
Bob Wilson | b62d257 | 2009-11-03 00:02:05 +0000 | [diff] [blame] | 2065 | // ConstantPool, JumpTable, GlobalAddress, and ExternalSymbol are lowered as |
| 2066 | // their target counterpart wrapped in the ARMISD::Wrapper node. Suppose N is |
| 2067 | // one of the above mentioned nodes. It has to be wrapped because otherwise |
| 2068 | // Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only |
| 2069 | // be used to form addressing mode. These wrapped nodes will be selected |
| 2070 | // into MOVi. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2071 | static SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2072 | EVT PtrVT = Op.getValueType(); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 2073 | // FIXME there is no actual debug info here |
| 2074 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2075 | ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2076 | SDValue Res; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2077 | if (CP->isMachineConstantPoolEntry()) |
| 2078 | Res = DAG.getTargetConstantPool(CP->getMachineCPVal(), PtrVT, |
| 2079 | CP->getAlignment()); |
| 2080 | else |
| 2081 | Res = DAG.getTargetConstantPool(CP->getConstVal(), PtrVT, |
| 2082 | CP->getAlignment()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2083 | return DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Res); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2084 | } |
| 2085 | |
Jim Grosbach | e1102ca | 2010-07-19 17:20:38 +0000 | [diff] [blame] | 2086 | unsigned ARMTargetLowering::getJumpTableEncoding() const { |
| 2087 | return MachineJumpTableInfo::EK_Inline; |
| 2088 | } |
| 2089 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2090 | SDValue ARMTargetLowering::LowerBlockAddress(SDValue Op, |
| 2091 | SelectionDAG &DAG) const { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2092 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2093 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2094 | unsigned ARMPCLabelIndex = 0; |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 2095 | DebugLoc DL = Op.getDebugLoc(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2096 | EVT PtrVT = getPointerTy(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2097 | const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2098 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2099 | SDValue CPAddr; |
| 2100 | if (RelocM == Reloc::Static) { |
| 2101 | CPAddr = DAG.getTargetConstantPool(BA, PtrVT, 4); |
| 2102 | } else { |
| 2103 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2104 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2105 | ARMConstantPoolValue *CPV = |
| 2106 | ARMConstantPoolConstant::Create(BA, ARMPCLabelIndex, |
| 2107 | ARMCP::CPBlockAddress, PCAdj); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2108 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| 2109 | } |
| 2110 | CPAddr = DAG.getNode(ARMISD::Wrapper, DL, PtrVT, CPAddr); |
| 2111 | SDValue Result = DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2112 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2113 | false, false, false, 0); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2114 | if (RelocM == Reloc::Static) |
| 2115 | return Result; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2116 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2117 | return DAG.getNode(ARMISD::PIC_ADD, DL, PtrVT, Result, PICLabel); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 2118 | } |
| 2119 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2120 | // Lower ISD::GlobalTLSAddress using the "general dynamic" model |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2121 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2122 | ARMTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2123 | SelectionDAG &DAG) const { |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2124 | DebugLoc dl = GA->getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2125 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2126 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2127 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2128 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2129 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2130 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2131 | ARMConstantPoolConstant::Create(GA->getGlobal(), ARMPCLabelIndex, |
| 2132 | ARMCP::CPValue, PCAdj, ARMCP::TLSGD, true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2133 | SDValue Argument = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2134 | Argument = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Argument); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2135 | Argument = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Argument, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2136 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2137 | false, false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2138 | SDValue Chain = Argument.getValue(1); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2139 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2140 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2141 | Argument = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Argument, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2142 | |
| 2143 | // call __tls_get_addr. |
| 2144 | ArgListTy Args; |
| 2145 | ArgListEntry Entry; |
| 2146 | Entry.Node = Argument; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2147 | Entry.Ty = (Type *) Type::getInt32Ty(*DAG.getContext()); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2148 | Args.push_back(Entry); |
Dale Johannesen | 7d2ad62 | 2009-01-30 23:10:59 +0000 | [diff] [blame] | 2149 | // FIXME: is there useful debug info available here? |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 2150 | TargetLowering::CallLoweringInfo CLI(Chain, |
| 2151 | (Type *) Type::getInt32Ty(*DAG.getContext()), |
Evan Cheng | 59bc060 | 2009-08-14 19:11:20 +0000 | [diff] [blame] | 2152 | false, false, false, false, |
Evan Cheng | 4bfcd4a | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 2153 | 0, CallingConv::C, /*isTailCall=*/false, |
| 2154 | /*doesNotRet=*/false, /*isReturnValueUsed=*/true, |
Bill Wendling | 46ada19 | 2010-03-02 01:55:18 +0000 | [diff] [blame] | 2155 | DAG.getExternalSymbol("__tls_get_addr", PtrVT), Args, DAG, dl); |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 2156 | std::pair<SDValue, SDValue> CallResult = LowerCallTo(CLI); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2157 | return CallResult.first; |
| 2158 | } |
| 2159 | |
| 2160 | // Lower ISD::GlobalTLSAddress using the "initial exec" or |
| 2161 | // "local exec" model. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2162 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2163 | ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA, |
Hans Wennborg | fd5abd5 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2164 | SelectionDAG &DAG, |
| 2165 | TLSModel::Model model) const { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2166 | const GlobalValue *GV = GA->getGlobal(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2167 | DebugLoc dl = GA->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2168 | SDValue Offset; |
| 2169 | SDValue Chain = DAG.getEntryNode(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2170 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2171 | // Get the Thread Pointer |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2172 | SDValue ThreadPointer = DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2173 | |
Hans Wennborg | fd5abd5 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2174 | if (model == TLSModel::InitialExec) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2175 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2176 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2177 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2178 | // Initial exec model. |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2179 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
| 2180 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2181 | ARMConstantPoolConstant::Create(GA->getGlobal(), ARMPCLabelIndex, |
| 2182 | ARMCP::CPValue, PCAdj, ARMCP::GOTTPOFF, |
| 2183 | true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2184 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2185 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2186 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2187 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2188 | false, false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2189 | Chain = Offset.getValue(1); |
| 2190 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2191 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2192 | Offset = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Offset, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2193 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2194 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2195 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2196 | false, false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2197 | } else { |
| 2198 | // local exec model |
Hans Wennborg | fd5abd5 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2199 | assert(model == TLSModel::LocalExec); |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2200 | ARMConstantPoolValue *CPV = |
| 2201 | ARMConstantPoolConstant::Create(GV, ARMCP::TPOFF); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2202 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2203 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2204 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2205 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2206 | false, false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2207 | } |
| 2208 | |
| 2209 | // The address of the thread local variable is the add of the thread |
| 2210 | // pointer with the offset of the variable. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2211 | return DAG.getNode(ISD::ADD, dl, PtrVT, ThreadPointer, Offset); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2212 | } |
| 2213 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2214 | SDValue |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2215 | ARMTargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const { |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2216 | // TODO: implement the "local dynamic" model |
| 2217 | assert(Subtarget->isTargetELF() && |
| 2218 | "TLS not implemented for non-ELF targets"); |
| 2219 | GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); |
Hans Wennborg | fd5abd5 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2220 | |
| 2221 | TLSModel::Model model = getTargetMachine().getTLSModel(GA->getGlobal()); |
| 2222 | |
| 2223 | switch (model) { |
| 2224 | case TLSModel::GeneralDynamic: |
| 2225 | case TLSModel::LocalDynamic: |
| 2226 | return LowerToTLSGeneralDynamicModel(GA, DAG); |
| 2227 | case TLSModel::InitialExec: |
| 2228 | case TLSModel::LocalExec: |
| 2229 | return LowerToTLSExecModels(GA, DAG, model); |
| 2230 | } |
Matt Beaumont-Gay | 39af944 | 2012-05-04 18:34:27 +0000 | [diff] [blame] | 2231 | llvm_unreachable("bogus TLS model"); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2232 | } |
| 2233 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2234 | SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2235 | SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2236 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2237 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2238 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2239 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2240 | if (RelocM == Reloc::PIC_) { |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 2241 | bool UseGOTOFF = GV->hasLocalLinkage() || GV->hasHiddenVisibility(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2242 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2243 | ARMConstantPoolConstant::Create(GV, |
| 2244 | UseGOTOFF ? ARMCP::GOTOFF : ARMCP::GOT); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2245 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2246 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2247 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2248 | CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2249 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2250 | false, false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2251 | SDValue Chain = Result.getValue(1); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 2252 | SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(PtrVT); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2253 | Result = DAG.getNode(ISD::ADD, dl, PtrVT, Result, GOT); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2254 | if (!UseGOTOFF) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2255 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2256 | MachinePointerInfo::getGOT(), |
| 2257 | false, false, false, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2258 | return Result; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2259 | } |
| 2260 | |
| 2261 | // 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] | 2262 | // pair. This is always cheaper. |
| 2263 | if (Subtarget->useMovt()) { |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2264 | ++NumMovwMovt; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2265 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2266 | // operands, expand this into two nodes. |
| 2267 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 2268 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2269 | } else { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2270 | SDValue CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
| 2271 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 2272 | return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
| 2273 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2274 | false, false, false, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2275 | } |
| 2276 | } |
| 2277 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2278 | SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2279 | SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2280 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2281 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2282 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2283 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2284 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2285 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2286 | |
Jakob Stoklund Olesen | 8f37a24 | 2012-01-07 20:49:15 +0000 | [diff] [blame] | 2287 | // FIXME: Enable this for static codegen when tool issues are fixed. Also |
| 2288 | // update ARMFastISel::ARMMaterializeGV. |
Evan Cheng | f31151f | 2011-10-26 01:17:44 +0000 | [diff] [blame] | 2289 | if (Subtarget->useMovt() && RelocM != Reloc::Static) { |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2290 | ++NumMovwMovt; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2291 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2292 | // operands, expand this into two nodes. |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 2293 | if (RelocM == Reloc::Static) |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2294 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 2295 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
| 2296 | |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 2297 | unsigned Wrapper = (RelocM == Reloc::PIC_) |
| 2298 | ? ARMISD::WrapperPIC : ARMISD::WrapperDYN; |
| 2299 | SDValue Result = DAG.getNode(Wrapper, dl, PtrVT, |
Evan Cheng | 9fe2009 | 2011-01-20 08:34:58 +0000 | [diff] [blame] | 2300 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2301 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
| 2302 | Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Result, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2303 | MachinePointerInfo::getGOT(), |
| 2304 | false, false, false, 0); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2305 | return Result; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2306 | } |
| 2307 | |
| 2308 | unsigned ARMPCLabelIndex = 0; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2309 | SDValue CPAddr; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2310 | if (RelocM == Reloc::Static) { |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2311 | CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2312 | } else { |
| 2313 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2314 | unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : (Subtarget->isThumb()?4:8); |
| 2315 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2316 | ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex, ARMCP::CPValue, |
| 2317 | PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2318 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2319 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2320 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2321 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2322 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2323 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2324 | false, false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2325 | SDValue Chain = Result.getValue(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2326 | |
| 2327 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2328 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2329 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2330 | } |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2331 | |
Evan Cheng | 63476a8 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 2332 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2333 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, MachinePointerInfo::getGOT(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2334 | false, false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2335 | |
| 2336 | return Result; |
| 2337 | } |
| 2338 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2339 | SDValue ARMTargetLowering::LowerGLOBAL_OFFSET_TABLE(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2340 | SelectionDAG &DAG) const { |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2341 | assert(Subtarget->isTargetELF() && |
| 2342 | "GLOBAL OFFSET TABLE not implemented for non-ELF targets"); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2343 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2344 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2345 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2346 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2347 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2348 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Bill Wendling | fe31e67 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 2349 | ARMConstantPoolValue *CPV = |
| 2350 | ARMConstantPoolSymbol::Create(*DAG.getContext(), "_GLOBAL_OFFSET_TABLE_", |
| 2351 | ARMPCLabelIndex, PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2352 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2353 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2354 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2355 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2356 | false, false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2357 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2358 | return DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2359 | } |
| 2360 | |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2361 | SDValue |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2362 | ARMTargetLowering::LowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const { |
| 2363 | DebugLoc dl = Op.getDebugLoc(); |
Jim Grosbach | 0798edd | 2010-05-27 23:49:24 +0000 | [diff] [blame] | 2364 | SDValue Val = DAG.getConstant(0, MVT::i32); |
Bill Wendling | ce370cf | 2011-10-07 21:25:38 +0000 | [diff] [blame] | 2365 | return DAG.getNode(ARMISD::EH_SJLJ_SETJMP, dl, |
| 2366 | DAG.getVTList(MVT::i32, MVT::Other), Op.getOperand(0), |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2367 | Op.getOperand(1), Val); |
| 2368 | } |
| 2369 | |
| 2370 | SDValue |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 2371 | ARMTargetLowering::LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const { |
| 2372 | DebugLoc dl = Op.getDebugLoc(); |
| 2373 | return DAG.getNode(ARMISD::EH_SJLJ_LONGJMP, dl, MVT::Other, Op.getOperand(0), |
| 2374 | Op.getOperand(1), DAG.getConstant(0, MVT::i32)); |
| 2375 | } |
| 2376 | |
| 2377 | SDValue |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 2378 | ARMTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG, |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2379 | const ARMSubtarget *Subtarget) const { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2380 | unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2381 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2382 | switch (IntNo) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2383 | default: return SDValue(); // Don't custom lower most intrinsics. |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2384 | case Intrinsic::arm_thread_pointer: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2385 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2386 | return DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
| 2387 | } |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2388 | case Intrinsic::eh_sjlj_lsda: { |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2389 | MachineFunction &MF = DAG.getMachineFunction(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2390 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2391 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2392 | EVT PtrVT = getPointerTy(); |
| 2393 | DebugLoc dl = Op.getDebugLoc(); |
| 2394 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2395 | SDValue CPAddr; |
| 2396 | unsigned PCAdj = (RelocM != Reloc::PIC_) |
| 2397 | ? 0 : (Subtarget->isThumb() ? 4 : 8); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2398 | ARMConstantPoolValue *CPV = |
Bill Wendling | 5bb7799 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2399 | ARMConstantPoolConstant::Create(MF.getFunction(), ARMPCLabelIndex, |
| 2400 | ARMCP::CPLSDA, PCAdj); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2401 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2402 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2403 | SDValue Result = |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2404 | DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2405 | MachinePointerInfo::getConstantPool(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2406 | false, false, false, 0); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2407 | |
| 2408 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2409 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2410 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
| 2411 | } |
| 2412 | return Result; |
| 2413 | } |
Evan Cheng | 92e3916 | 2011-03-29 23:06:19 +0000 | [diff] [blame] | 2414 | case Intrinsic::arm_neon_vmulls: |
| 2415 | case Intrinsic::arm_neon_vmullu: { |
| 2416 | unsigned NewOpc = (IntNo == Intrinsic::arm_neon_vmulls) |
| 2417 | ? ARMISD::VMULLs : ARMISD::VMULLu; |
| 2418 | return DAG.getNode(NewOpc, Op.getDebugLoc(), Op.getValueType(), |
| 2419 | Op.getOperand(1), Op.getOperand(2)); |
| 2420 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2421 | } |
| 2422 | } |
| 2423 | |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 2424 | static SDValue LowerMEMBARRIER(SDValue Op, SelectionDAG &DAG, |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2425 | const ARMSubtarget *Subtarget) { |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 2426 | DebugLoc dl = Op.getDebugLoc(); |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2427 | if (!Subtarget->hasDataBarrier()) { |
| 2428 | // Some ARMv6 cpus can support data barriers with an mcr instruction. |
| 2429 | // Thumb1 and pre-v6 ARM mode use a libcall instead and should never get |
| 2430 | // here. |
Bob Wilson | 54f9256 | 2010-11-09 22:50:44 +0000 | [diff] [blame] | 2431 | assert(Subtarget->hasV6Ops() && !Subtarget->isThumb() && |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 2432 | "Unexpected ISD::MEMBARRIER encountered. Should be libcall!"); |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2433 | return DAG.getNode(ARMISD::MEMBARRIER_MCR, dl, MVT::Other, Op.getOperand(0), |
Jim Grosbach | c73993b | 2010-06-17 01:37:00 +0000 | [diff] [blame] | 2434 | DAG.getConstant(0, MVT::i32)); |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 2435 | } |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2436 | |
| 2437 | SDValue Op5 = Op.getOperand(5); |
| 2438 | bool isDeviceBarrier = cast<ConstantSDNode>(Op5)->getZExtValue() != 0; |
| 2439 | unsigned isLL = cast<ConstantSDNode>(Op.getOperand(1))->getZExtValue(); |
| 2440 | unsigned isLS = cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue(); |
| 2441 | bool isOnlyStoreBarrier = (isLL == 0 && isLS == 0); |
| 2442 | |
| 2443 | ARM_MB::MemBOpt DMBOpt; |
| 2444 | if (isDeviceBarrier) |
| 2445 | DMBOpt = isOnlyStoreBarrier ? ARM_MB::ST : ARM_MB::SY; |
| 2446 | else |
| 2447 | DMBOpt = isOnlyStoreBarrier ? ARM_MB::ISHST : ARM_MB::ISH; |
| 2448 | return DAG.getNode(ARMISD::MEMBARRIER, dl, MVT::Other, Op.getOperand(0), |
| 2449 | DAG.getConstant(DMBOpt, MVT::i32)); |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 2450 | } |
| 2451 | |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2452 | |
| 2453 | static SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG &DAG, |
| 2454 | const ARMSubtarget *Subtarget) { |
| 2455 | // FIXME: handle "fence singlethread" more efficiently. |
| 2456 | DebugLoc dl = Op.getDebugLoc(); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2457 | if (!Subtarget->hasDataBarrier()) { |
| 2458 | // Some ARMv6 cpus can support data barriers with an mcr instruction. |
| 2459 | // Thumb1 and pre-v6 ARM mode use a libcall instead and should never get |
| 2460 | // here. |
| 2461 | assert(Subtarget->hasV6Ops() && !Subtarget->isThumb() && |
| 2462 | "Unexpected ISD::MEMBARRIER encountered. Should be libcall!"); |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2463 | return DAG.getNode(ARMISD::MEMBARRIER_MCR, dl, MVT::Other, Op.getOperand(0), |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2464 | DAG.getConstant(0, MVT::i32)); |
| 2465 | } |
| 2466 | |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2467 | return DAG.getNode(ARMISD::MEMBARRIER, dl, MVT::Other, Op.getOperand(0), |
Eli Friedman | 989f61e | 2011-08-02 22:44:16 +0000 | [diff] [blame] | 2468 | DAG.getConstant(ARM_MB::ISH, MVT::i32)); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2469 | } |
| 2470 | |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2471 | static SDValue LowerPREFETCH(SDValue Op, SelectionDAG &DAG, |
| 2472 | const ARMSubtarget *Subtarget) { |
| 2473 | // ARM pre v5TE and Thumb1 does not have preload instructions. |
| 2474 | if (!(Subtarget->isThumb2() || |
| 2475 | (!Subtarget->isThumb1Only() && Subtarget->hasV5TEOps()))) |
| 2476 | // Just preserve the chain. |
| 2477 | return Op.getOperand(0); |
| 2478 | |
| 2479 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2480 | unsigned isRead = ~cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue() & 1; |
| 2481 | if (!isRead && |
| 2482 | (!Subtarget->hasV7Ops() || !Subtarget->hasMPExtension())) |
| 2483 | // ARMv7 with MP extension has PLDW. |
| 2484 | return Op.getOperand(0); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2485 | |
Bruno Cardoso Lopes | 9a76733 | 2011-06-14 04:58:37 +0000 | [diff] [blame] | 2486 | unsigned isData = cast<ConstantSDNode>(Op.getOperand(4))->getZExtValue(); |
| 2487 | if (Subtarget->isThumb()) { |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2488 | // Invert the bits. |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2489 | isRead = ~isRead & 1; |
Bruno Cardoso Lopes | 9a76733 | 2011-06-14 04:58:37 +0000 | [diff] [blame] | 2490 | isData = ~isData & 1; |
| 2491 | } |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2492 | |
| 2493 | return DAG.getNode(ARMISD::PRELOAD, dl, MVT::Other, Op.getOperand(0), |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2494 | Op.getOperand(1), DAG.getConstant(isRead, MVT::i32), |
| 2495 | DAG.getConstant(isData, MVT::i32)); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2496 | } |
| 2497 | |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2498 | static SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) { |
| 2499 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2500 | ARMFunctionInfo *FuncInfo = MF.getInfo<ARMFunctionInfo>(); |
| 2501 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2502 | // vastart just stores the address of the VarArgsFrameIndex slot into the |
| 2503 | // memory location argument. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2504 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2505 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2506 | SDValue FR = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), PtrVT); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 2507 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 2508 | return DAG.getStore(Op.getOperand(0), dl, FR, Op.getOperand(1), |
| 2509 | MachinePointerInfo(SV), false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2510 | } |
| 2511 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2512 | SDValue |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2513 | ARMTargetLowering::GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA, |
| 2514 | SDValue &Root, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2515 | DebugLoc dl) const { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2516 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2517 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2518 | |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2519 | const TargetRegisterClass *RC; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 2520 | if (AFI->isThumb1OnlyFunction()) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2521 | RC = &ARM::tGPRRegClass; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2522 | else |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2523 | RC = &ARM::GPRRegClass; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2524 | |
| 2525 | // Transform the arguments stored in physical registers into virtual ones. |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2526 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2527 | SDValue ArgValue = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2528 | |
| 2529 | SDValue ArgValue2; |
| 2530 | if (NextVA.isMemLoc()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2531 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2532 | int FI = MFI->CreateFixedObject(4, NextVA.getLocMemOffset(), true); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2533 | |
| 2534 | // Create load node to retrieve arguments from the stack. |
| 2535 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2536 | ArgValue2 = DAG.getLoad(MVT::i32, dl, Root, FIN, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2537 | MachinePointerInfo::getFixedStack(FI), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2538 | false, false, false, 0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2539 | } else { |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2540 | Reg = MF.addLiveIn(NextVA.getLocReg(), RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2541 | ArgValue2 = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2542 | } |
| 2543 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2544 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, ArgValue, ArgValue2); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2545 | } |
| 2546 | |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2547 | void |
| 2548 | ARMTargetLowering::computeRegArea(CCState &CCInfo, MachineFunction &MF, |
| 2549 | unsigned &VARegSize, unsigned &VARegSaveSize) |
| 2550 | const { |
| 2551 | unsigned NumGPRs; |
| 2552 | if (CCInfo.isFirstByValRegValid()) |
| 2553 | NumGPRs = ARM::R4 - CCInfo.getFirstByValReg(); |
| 2554 | else { |
| 2555 | unsigned int firstUnalloced; |
| 2556 | firstUnalloced = CCInfo.getFirstUnallocated(GPRArgRegs, |
| 2557 | sizeof(GPRArgRegs) / |
| 2558 | sizeof(GPRArgRegs[0])); |
| 2559 | NumGPRs = (firstUnalloced <= 3) ? (4 - firstUnalloced) : 0; |
| 2560 | } |
| 2561 | |
| 2562 | unsigned Align = MF.getTarget().getFrameLowering()->getStackAlignment(); |
| 2563 | VARegSize = NumGPRs * 4; |
| 2564 | VARegSaveSize = (VARegSize + Align - 1) & ~(Align - 1); |
| 2565 | } |
| 2566 | |
| 2567 | // The remaining GPRs hold either the beginning of variable-argument |
| 2568 | // data, or the beginning of an aggregate passed by value (usuall |
| 2569 | // byval). Either way, we allocate stack slots adjacent to the data |
| 2570 | // provided by our caller, and store the unallocated registers there. |
| 2571 | // If this is a variadic function, the va_list pointer will begin with |
| 2572 | // these values; otherwise, this reassembles a (byval) structure that |
| 2573 | // was split between registers and memory. |
| 2574 | void |
| 2575 | ARMTargetLowering::VarArgStyleRegisters(CCState &CCInfo, SelectionDAG &DAG, |
| 2576 | DebugLoc dl, SDValue &Chain, |
Stepan Dyatkovskiy | 661afe7 | 2012-10-10 11:37:36 +0000 | [diff] [blame] | 2577 | const Value *OrigArg, |
| 2578 | unsigned OffsetFromOrigArg, |
Stepan Dyatkovskiy | 0d3c8d5 | 2012-10-19 08:23:06 +0000 | [diff] [blame] | 2579 | unsigned ArgOffset, |
| 2580 | bool ForceMutable) const { |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2581 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2582 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 2583 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2584 | unsigned firstRegToSaveIndex; |
| 2585 | if (CCInfo.isFirstByValRegValid()) |
| 2586 | firstRegToSaveIndex = CCInfo.getFirstByValReg() - ARM::R0; |
| 2587 | else { |
| 2588 | firstRegToSaveIndex = CCInfo.getFirstUnallocated |
| 2589 | (GPRArgRegs, sizeof(GPRArgRegs) / sizeof(GPRArgRegs[0])); |
| 2590 | } |
| 2591 | |
| 2592 | unsigned VARegSize, VARegSaveSize; |
| 2593 | computeRegArea(CCInfo, MF, VARegSize, VARegSaveSize); |
| 2594 | if (VARegSaveSize) { |
| 2595 | // If this function is vararg, store any remaining integer argument regs |
| 2596 | // to their spots on the stack so that they may be loaded by deferencing |
| 2597 | // the result of va_next. |
| 2598 | AFI->setVarArgsRegSaveSize(VARegSaveSize); |
Eric Christopher | 5ac179c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 2599 | AFI->setVarArgsFrameIndex(MFI->CreateFixedObject(VARegSaveSize, |
| 2600 | ArgOffset + VARegSaveSize |
| 2601 | - VARegSize, |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2602 | false)); |
| 2603 | SDValue FIN = DAG.getFrameIndex(AFI->getVarArgsFrameIndex(), |
| 2604 | getPointerTy()); |
| 2605 | |
| 2606 | SmallVector<SDValue, 4> MemOps; |
Stepan Dyatkovskiy | 661afe7 | 2012-10-10 11:37:36 +0000 | [diff] [blame] | 2607 | for (unsigned i = 0; firstRegToSaveIndex < 4; ++firstRegToSaveIndex, ++i) { |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2608 | const TargetRegisterClass *RC; |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2609 | if (AFI->isThumb1OnlyFunction()) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2610 | RC = &ARM::tGPRRegClass; |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2611 | else |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2612 | RC = &ARM::GPRRegClass; |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2613 | |
| 2614 | unsigned VReg = MF.addLiveIn(GPRArgRegs[firstRegToSaveIndex], RC); |
| 2615 | SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i32); |
| 2616 | SDValue Store = |
| 2617 | DAG.getStore(Val.getValue(1), dl, Val, FIN, |
Stepan Dyatkovskiy | 661afe7 | 2012-10-10 11:37:36 +0000 | [diff] [blame] | 2618 | MachinePointerInfo(OrigArg, OffsetFromOrigArg + 4*i), |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2619 | false, false, 0); |
| 2620 | MemOps.push_back(Store); |
| 2621 | FIN = DAG.getNode(ISD::ADD, dl, getPointerTy(), FIN, |
| 2622 | DAG.getConstant(4, getPointerTy())); |
| 2623 | } |
| 2624 | if (!MemOps.empty()) |
| 2625 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
| 2626 | &MemOps[0], MemOps.size()); |
| 2627 | } else |
| 2628 | // This will point to the next argument passed via stack. |
Stepan Dyatkovskiy | 0d3c8d5 | 2012-10-19 08:23:06 +0000 | [diff] [blame] | 2629 | AFI->setVarArgsFrameIndex( |
| 2630 | MFI->CreateFixedObject(4, ArgOffset, !ForceMutable)); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2631 | } |
| 2632 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2633 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2634 | ARMTargetLowering::LowerFormalArguments(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 2635 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2636 | const SmallVectorImpl<ISD::InputArg> |
| 2637 | &Ins, |
| 2638 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2639 | SmallVectorImpl<SDValue> &InVals) |
| 2640 | const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2641 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2642 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 2643 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2644 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2645 | |
| 2646 | // Assign locations to all of the incoming arguments. |
| 2647 | SmallVector<CCValAssign, 16> ArgLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 2648 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 2649 | getTargetMachine(), ArgLocs, *DAG.getContext(), Prologue); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2650 | CCInfo.AnalyzeFormalArguments(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2651 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 2652 | isVarArg)); |
Stepan Dyatkovskiy | 661afe7 | 2012-10-10 11:37:36 +0000 | [diff] [blame] | 2653 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2654 | SmallVector<SDValue, 16> ArgValues; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2655 | int lastInsIndex = -1; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2656 | SDValue ArgValue; |
Stepan Dyatkovskiy | 661afe7 | 2012-10-10 11:37:36 +0000 | [diff] [blame] | 2657 | Function::const_arg_iterator CurOrigArg = MF.getFunction()->arg_begin(); |
| 2658 | unsigned CurArgIdx = 0; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2659 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 2660 | CCValAssign &VA = ArgLocs[i]; |
Stepan Dyatkovskiy | 661afe7 | 2012-10-10 11:37:36 +0000 | [diff] [blame] | 2661 | std::advance(CurOrigArg, Ins[VA.getValNo()].OrigArgIndex - CurArgIdx); |
| 2662 | CurArgIdx = Ins[VA.getValNo()].OrigArgIndex; |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2663 | // Arguments stored in registers. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2664 | if (VA.isRegLoc()) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2665 | EVT RegVT = VA.getLocVT(); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2666 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2667 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2668 | // f64 and vector types are split up into multiple registers or |
| 2669 | // combinations of registers and stack slots. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2670 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2671 | SDValue ArgValue1 = GetF64FormalArgument(VA, ArgLocs[++i], |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2672 | Chain, DAG, dl); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2673 | VA = ArgLocs[++i]; // skip ahead to next loc |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2674 | SDValue ArgValue2; |
| 2675 | if (VA.isMemLoc()) { |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2676 | int FI = MFI->CreateFixedObject(8, VA.getLocMemOffset(), true); |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2677 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 2678 | ArgValue2 = DAG.getLoad(MVT::f64, dl, Chain, FIN, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2679 | MachinePointerInfo::getFixedStack(FI), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2680 | false, false, false, 0); |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2681 | } else { |
| 2682 | ArgValue2 = GetF64FormalArgument(VA, ArgLocs[++i], |
| 2683 | Chain, DAG, dl); |
| 2684 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2685 | ArgValue = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 2686 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2687 | ArgValue, ArgValue1, DAG.getIntPtrConstant(0)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2688 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2689 | ArgValue, ArgValue2, DAG.getIntPtrConstant(1)); |
| 2690 | } else |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2691 | ArgValue = GetF64FormalArgument(VA, ArgLocs[++i], Chain, DAG, dl); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2692 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2693 | } else { |
Craig Topper | 44d2382 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2694 | const TargetRegisterClass *RC; |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2695 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2696 | if (RegVT == MVT::f32) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2697 | RC = &ARM::SPRRegClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2698 | else if (RegVT == MVT::f64) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2699 | RC = &ARM::DPRRegClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2700 | else if (RegVT == MVT::v2f64) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2701 | RC = &ARM::QPRRegClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2702 | else if (RegVT == MVT::i32) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2703 | RC = AFI->isThumb1OnlyFunction() ? |
| 2704 | (const TargetRegisterClass*)&ARM::tGPRRegClass : |
| 2705 | (const TargetRegisterClass*)&ARM::GPRRegClass; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2706 | else |
Anton Korobeynikov | 058c251 | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 2707 | llvm_unreachable("RegVT not supported by FORMAL_ARGUMENTS Lowering"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2708 | |
| 2709 | // Transform the arguments in physical registers into virtual ones. |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2710 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2711 | ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, RegVT); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2712 | } |
| 2713 | |
| 2714 | // If this is an 8 or 16-bit value, it is really passed promoted |
| 2715 | // to 32 bits. Insert an assert[sz]ext to capture this, then |
| 2716 | // truncate to the right size. |
| 2717 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2718 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2719 | case CCValAssign::Full: break; |
| 2720 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2721 | ArgValue = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), ArgValue); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2722 | break; |
| 2723 | case CCValAssign::SExt: |
| 2724 | ArgValue = DAG.getNode(ISD::AssertSext, dl, RegVT, ArgValue, |
| 2725 | DAG.getValueType(VA.getValVT())); |
| 2726 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 2727 | break; |
| 2728 | case CCValAssign::ZExt: |
| 2729 | ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue, |
| 2730 | DAG.getValueType(VA.getValVT())); |
| 2731 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 2732 | break; |
| 2733 | } |
| 2734 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2735 | InVals.push_back(ArgValue); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2736 | |
| 2737 | } else { // VA.isRegLoc() |
| 2738 | |
| 2739 | // sanity check |
| 2740 | assert(VA.isMemLoc()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2741 | assert(VA.getValVT() != MVT::i64 && "i64 should already be lowered"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2742 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2743 | int index = ArgLocs[i].getValNo(); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 2744 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2745 | // Some Ins[] entries become multiple ArgLoc[] entries. |
| 2746 | // Process them only once. |
| 2747 | if (index != lastInsIndex) |
| 2748 | { |
| 2749 | ISD::ArgFlagsTy Flags = Ins[index].Flags; |
Eric Christopher | 471e422 | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 2750 | // FIXME: For now, all byval parameter objects are marked mutable. |
Eric Christopher | 5ac179c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 2751 | // This can be changed with more analysis. |
| 2752 | // In case of tail call optimization mark all arguments mutable. |
| 2753 | // Since they could be overwritten by lowering of arguments in case of |
| 2754 | // a tail call. |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2755 | if (Flags.isByVal()) { |
Stepan Dyatkovskiy | 0d3c8d5 | 2012-10-19 08:23:06 +0000 | [diff] [blame] | 2756 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2757 | if (!AFI->getVarArgsFrameIndex()) { |
| 2758 | VarArgStyleRegisters(CCInfo, DAG, |
| 2759 | dl, Chain, CurOrigArg, |
| 2760 | Ins[VA.getValNo()].PartOffset, |
| 2761 | VA.getLocMemOffset(), |
| 2762 | true /*force mutable frames*/); |
| 2763 | int VAFrameIndex = AFI->getVarArgsFrameIndex(); |
| 2764 | InVals.push_back(DAG.getFrameIndex(VAFrameIndex, getPointerTy())); |
| 2765 | } else { |
| 2766 | int FI = MFI->CreateFixedObject(Flags.getByValSize(), |
| 2767 | VA.getLocMemOffset(), false); |
| 2768 | InVals.push_back(DAG.getFrameIndex(FI, getPointerTy())); |
| 2769 | } |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2770 | } else { |
| 2771 | int FI = MFI->CreateFixedObject(VA.getLocVT().getSizeInBits()/8, |
| 2772 | VA.getLocMemOffset(), true); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2773 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2774 | // Create load nodes to retrieve arguments from the stack. |
| 2775 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 2776 | InVals.push_back(DAG.getLoad(VA.getValVT(), dl, Chain, FIN, |
| 2777 | MachinePointerInfo::getFixedStack(FI), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2778 | false, false, false, 0)); |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2779 | } |
| 2780 | lastInsIndex = index; |
| 2781 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2782 | } |
| 2783 | } |
| 2784 | |
| 2785 | // varargs |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2786 | if (isVarArg) |
Stepan Dyatkovskiy | 661afe7 | 2012-10-10 11:37:36 +0000 | [diff] [blame] | 2787 | VarArgStyleRegisters(CCInfo, DAG, dl, Chain, 0, 0, |
| 2788 | CCInfo.getNextStackOffset()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2789 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2790 | return Chain; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2791 | } |
| 2792 | |
| 2793 | /// isFloatingPointZero - Return true if this is +0.0. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2794 | static bool isFloatingPointZero(SDValue Op) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2795 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op)) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 2796 | return CFP->getValueAPF().isPosZero(); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2797 | else if (ISD::isEXTLoad(Op.getNode()) || ISD::isNON_EXTLoad(Op.getNode())) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2798 | // Maybe this has already been legalized into the constant pool? |
| 2799 | if (Op.getOperand(1).getOpcode() == ARMISD::Wrapper) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2800 | SDValue WrapperOp = Op.getOperand(1).getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2801 | if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(WrapperOp)) |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2802 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal())) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 2803 | return CFP->getValueAPF().isPosZero(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2804 | } |
| 2805 | } |
| 2806 | return false; |
| 2807 | } |
| 2808 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2809 | /// Returns appropriate ARM CMP (cmp) and corresponding condition code for |
| 2810 | /// the given operands. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2811 | SDValue |
| 2812 | ARMTargetLowering::getARMCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2813 | SDValue &ARMcc, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2814 | DebugLoc dl) const { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2815 | if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS.getNode())) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2816 | unsigned C = RHSC->getZExtValue(); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2817 | if (!isLegalICmpImmediate(C)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2818 | // Constant does not fit, try adjusting it by one? |
| 2819 | switch (CC) { |
| 2820 | default: break; |
| 2821 | case ISD::SETLT: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2822 | case ISD::SETGE: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2823 | if (C != 0x80000000 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2824 | CC = (CC == ISD::SETLT) ? ISD::SETLE : ISD::SETGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2825 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2826 | } |
| 2827 | break; |
| 2828 | case ISD::SETULT: |
| 2829 | case ISD::SETUGE: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2830 | if (C != 0 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2831 | CC = (CC == ISD::SETULT) ? ISD::SETULE : ISD::SETUGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2832 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2833 | } |
| 2834 | break; |
| 2835 | case ISD::SETLE: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2836 | case ISD::SETGT: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2837 | if (C != 0x7fffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2838 | CC = (CC == ISD::SETLE) ? ISD::SETLT : ISD::SETGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2839 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2840 | } |
| 2841 | break; |
| 2842 | case ISD::SETULE: |
| 2843 | case ISD::SETUGT: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2844 | if (C != 0xffffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2845 | CC = (CC == ISD::SETULE) ? ISD::SETULT : ISD::SETUGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2846 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2847 | } |
| 2848 | break; |
| 2849 | } |
| 2850 | } |
| 2851 | } |
| 2852 | |
| 2853 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 2854 | ARMISD::NodeType CompareType; |
| 2855 | switch (CondCode) { |
| 2856 | default: |
| 2857 | CompareType = ARMISD::CMP; |
| 2858 | break; |
| 2859 | case ARMCC::EQ: |
| 2860 | case ARMCC::NE: |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 2861 | // Uses only Z Flag |
| 2862 | CompareType = ARMISD::CMPZ; |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 2863 | break; |
| 2864 | } |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2865 | ARMcc = DAG.getConstant(CondCode, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2866 | return DAG.getNode(CompareType, dl, MVT::Glue, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2867 | } |
| 2868 | |
| 2869 | /// 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] | 2870 | SDValue |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2871 | ARMTargetLowering::getVFPCmp(SDValue LHS, SDValue RHS, SelectionDAG &DAG, |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 2872 | DebugLoc dl) const { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2873 | SDValue Cmp; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2874 | if (!isFloatingPointZero(RHS)) |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2875 | Cmp = DAG.getNode(ARMISD::CMPFP, dl, MVT::Glue, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2876 | else |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2877 | Cmp = DAG.getNode(ARMISD::CMPFPw0, dl, MVT::Glue, LHS); |
| 2878 | return DAG.getNode(ARMISD::FMSTAT, dl, MVT::Glue, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2879 | } |
| 2880 | |
Bob Wilson | 79f56c9 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 2881 | /// duplicateCmp - Glue values can have only one use, so this function |
| 2882 | /// duplicates a comparison node. |
| 2883 | SDValue |
| 2884 | ARMTargetLowering::duplicateCmp(SDValue Cmp, SelectionDAG &DAG) const { |
| 2885 | unsigned Opc = Cmp.getOpcode(); |
| 2886 | DebugLoc DL = Cmp.getDebugLoc(); |
| 2887 | if (Opc == ARMISD::CMP || Opc == ARMISD::CMPZ) |
| 2888 | return DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); |
| 2889 | |
| 2890 | assert(Opc == ARMISD::FMSTAT && "unexpected comparison operation"); |
| 2891 | Cmp = Cmp.getOperand(0); |
| 2892 | Opc = Cmp.getOpcode(); |
| 2893 | if (Opc == ARMISD::CMPFP) |
| 2894 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); |
| 2895 | else { |
| 2896 | assert(Opc == ARMISD::CMPFPw0 && "unexpected operand of FMSTAT"); |
| 2897 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0)); |
| 2898 | } |
| 2899 | return DAG.getNode(ARMISD::FMSTAT, DL, MVT::Glue, Cmp); |
| 2900 | } |
| 2901 | |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2902 | SDValue ARMTargetLowering::LowerSELECT(SDValue Op, SelectionDAG &DAG) const { |
| 2903 | SDValue Cond = Op.getOperand(0); |
| 2904 | SDValue SelectTrue = Op.getOperand(1); |
| 2905 | SDValue SelectFalse = Op.getOperand(2); |
| 2906 | DebugLoc dl = Op.getDebugLoc(); |
| 2907 | |
| 2908 | // Convert: |
| 2909 | // |
| 2910 | // (select (cmov 1, 0, cond), t, f) -> (cmov t, f, cond) |
| 2911 | // (select (cmov 0, 1, cond), t, f) -> (cmov f, t, cond) |
| 2912 | // |
| 2913 | if (Cond.getOpcode() == ARMISD::CMOV && Cond.hasOneUse()) { |
| 2914 | const ConstantSDNode *CMOVTrue = |
| 2915 | dyn_cast<ConstantSDNode>(Cond.getOperand(0)); |
| 2916 | const ConstantSDNode *CMOVFalse = |
| 2917 | dyn_cast<ConstantSDNode>(Cond.getOperand(1)); |
| 2918 | |
| 2919 | if (CMOVTrue && CMOVFalse) { |
| 2920 | unsigned CMOVTrueVal = CMOVTrue->getZExtValue(); |
| 2921 | unsigned CMOVFalseVal = CMOVFalse->getZExtValue(); |
| 2922 | |
| 2923 | SDValue True; |
| 2924 | SDValue False; |
| 2925 | if (CMOVTrueVal == 1 && CMOVFalseVal == 0) { |
| 2926 | True = SelectTrue; |
| 2927 | False = SelectFalse; |
| 2928 | } else if (CMOVTrueVal == 0 && CMOVFalseVal == 1) { |
| 2929 | True = SelectFalse; |
| 2930 | False = SelectTrue; |
| 2931 | } |
| 2932 | |
| 2933 | if (True.getNode() && False.getNode()) { |
Evan Cheng | b936e30 | 2011-05-18 18:59:17 +0000 | [diff] [blame] | 2934 | EVT VT = Op.getValueType(); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2935 | SDValue ARMcc = Cond.getOperand(2); |
| 2936 | SDValue CCR = Cond.getOperand(3); |
Bob Wilson | 79f56c9 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 2937 | SDValue Cmp = duplicateCmp(Cond.getOperand(4), DAG); |
Evan Cheng | b936e30 | 2011-05-18 18:59:17 +0000 | [diff] [blame] | 2938 | assert(True.getValueType() == VT); |
| 2939 | return DAG.getNode(ARMISD::CMOV, dl, VT, True, False, ARMcc, CCR, Cmp); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2940 | } |
| 2941 | } |
| 2942 | } |
| 2943 | |
Dan Gohman | db95389 | 2012-02-24 00:09:36 +0000 | [diff] [blame] | 2944 | // ARM's BooleanContents value is UndefinedBooleanContent. Mask out the |
| 2945 | // undefined bits before doing a full-word comparison with zero. |
| 2946 | Cond = DAG.getNode(ISD::AND, dl, Cond.getValueType(), Cond, |
| 2947 | DAG.getConstant(1, Cond.getValueType())); |
| 2948 | |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2949 | return DAG.getSelectCC(dl, Cond, |
| 2950 | DAG.getConstant(0, Cond.getValueType()), |
| 2951 | SelectTrue, SelectFalse, ISD::SETNE); |
| 2952 | } |
| 2953 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2954 | SDValue ARMTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2955 | EVT VT = Op.getValueType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2956 | SDValue LHS = Op.getOperand(0); |
| 2957 | SDValue RHS = Op.getOperand(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2958 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2959 | SDValue TrueVal = Op.getOperand(2); |
| 2960 | SDValue FalseVal = Op.getOperand(3); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2961 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2962 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2963 | if (LHS.getValueType() == MVT::i32) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2964 | SDValue ARMcc; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2965 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2966 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
Jim Grosbach | b04546f | 2011-09-13 20:30:37 +0000 | [diff] [blame] | 2967 | return DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, CCR,Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2968 | } |
| 2969 | |
| 2970 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 2971 | FPCCToARMCC(CC, CondCode, CondCode2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2972 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2973 | SDValue ARMcc = DAG.getConstant(CondCode, MVT::i32); |
| 2974 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2975 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2976 | SDValue Result = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2977 | ARMcc, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2978 | if (CondCode2 != ARMCC::AL) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2979 | SDValue ARMcc2 = DAG.getConstant(CondCode2, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2980 | // FIXME: Needs another CMP because flag can have but one use. |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2981 | SDValue Cmp2 = getVFPCmp(LHS, RHS, DAG, dl); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2982 | Result = DAG.getNode(ARMISD::CMOV, dl, VT, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2983 | Result, TrueVal, ARMcc2, CCR, Cmp2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2984 | } |
| 2985 | return Result; |
| 2986 | } |
| 2987 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2988 | /// canChangeToInt - Given the fp compare operand, return true if it is suitable |
| 2989 | /// to morph to an integer compare sequence. |
| 2990 | static bool canChangeToInt(SDValue Op, bool &SeenZero, |
| 2991 | const ARMSubtarget *Subtarget) { |
| 2992 | SDNode *N = Op.getNode(); |
| 2993 | if (!N->hasOneUse()) |
| 2994 | // Otherwise it requires moving the value from fp to integer registers. |
| 2995 | return false; |
| 2996 | if (!N->getNumValues()) |
| 2997 | return false; |
| 2998 | EVT VT = Op.getValueType(); |
| 2999 | if (VT != MVT::f32 && !Subtarget->isFPBrccSlow()) |
| 3000 | // f32 case is generally profitable. f64 case only makes sense when vcmpe + |
| 3001 | // vmrs are very slow, e.g. cortex-a8. |
| 3002 | return false; |
| 3003 | |
| 3004 | if (isFloatingPointZero(Op)) { |
| 3005 | SeenZero = true; |
| 3006 | return true; |
| 3007 | } |
| 3008 | return ISD::isNormalLoad(N); |
| 3009 | } |
| 3010 | |
| 3011 | static SDValue bitcastf32Toi32(SDValue Op, SelectionDAG &DAG) { |
| 3012 | if (isFloatingPointZero(Op)) |
| 3013 | return DAG.getConstant(0, MVT::i32); |
| 3014 | |
| 3015 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) |
| 3016 | return DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3017 | Ld->getChain(), Ld->getBasePtr(), Ld->getPointerInfo(), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3018 | Ld->isVolatile(), Ld->isNonTemporal(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3019 | Ld->isInvariant(), Ld->getAlignment()); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3020 | |
| 3021 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 3022 | } |
| 3023 | |
| 3024 | static void expandf64Toi32(SDValue Op, SelectionDAG &DAG, |
| 3025 | SDValue &RetVal1, SDValue &RetVal2) { |
| 3026 | if (isFloatingPointZero(Op)) { |
| 3027 | RetVal1 = DAG.getConstant(0, MVT::i32); |
| 3028 | RetVal2 = DAG.getConstant(0, MVT::i32); |
| 3029 | return; |
| 3030 | } |
| 3031 | |
| 3032 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) { |
| 3033 | SDValue Ptr = Ld->getBasePtr(); |
| 3034 | RetVal1 = DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
| 3035 | Ld->getChain(), Ptr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3036 | Ld->getPointerInfo(), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3037 | Ld->isVolatile(), Ld->isNonTemporal(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3038 | Ld->isInvariant(), Ld->getAlignment()); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3039 | |
| 3040 | EVT PtrType = Ptr.getValueType(); |
| 3041 | unsigned NewAlign = MinAlign(Ld->getAlignment(), 4); |
| 3042 | SDValue NewPtr = DAG.getNode(ISD::ADD, Op.getDebugLoc(), |
| 3043 | PtrType, Ptr, DAG.getConstant(4, PtrType)); |
| 3044 | RetVal2 = DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
| 3045 | Ld->getChain(), NewPtr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3046 | Ld->getPointerInfo().getWithOffset(4), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3047 | Ld->isVolatile(), Ld->isNonTemporal(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3048 | Ld->isInvariant(), NewAlign); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3049 | return; |
| 3050 | } |
| 3051 | |
| 3052 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 3053 | } |
| 3054 | |
| 3055 | /// OptimizeVFPBrcond - With -enable-unsafe-fp-math, it's legal to optimize some |
| 3056 | /// f32 and even f64 comparisons to integer ones. |
| 3057 | SDValue |
| 3058 | ARMTargetLowering::OptimizeVFPBrcond(SDValue Op, SelectionDAG &DAG) const { |
| 3059 | SDValue Chain = Op.getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3060 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3061 | SDValue LHS = Op.getOperand(2); |
| 3062 | SDValue RHS = Op.getOperand(3); |
| 3063 | SDValue Dest = Op.getOperand(4); |
| 3064 | DebugLoc dl = Op.getDebugLoc(); |
| 3065 | |
Evan Cheng | fc501a3 | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3066 | bool LHSSeenZero = false; |
| 3067 | bool LHSOk = canChangeToInt(LHS, LHSSeenZero, Subtarget); |
| 3068 | bool RHSSeenZero = false; |
| 3069 | bool RHSOk = canChangeToInt(RHS, RHSSeenZero, Subtarget); |
| 3070 | if (LHSOk && RHSOk && (LHSSeenZero || RHSSeenZero)) { |
Bob Wilson | 1b772f9 | 2011-03-08 01:17:16 +0000 | [diff] [blame] | 3071 | // If unsafe fp math optimization is enabled and there are no other uses of |
| 3072 | // 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] | 3073 | // to an integer comparison. |
| 3074 | if (CC == ISD::SETOEQ) |
| 3075 | CC = ISD::SETEQ; |
| 3076 | else if (CC == ISD::SETUNE) |
| 3077 | CC = ISD::SETNE; |
| 3078 | |
Evan Cheng | fc501a3 | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3079 | SDValue Mask = DAG.getConstant(0x7fffffff, MVT::i32); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3080 | SDValue ARMcc; |
| 3081 | if (LHS.getValueType() == MVT::f32) { |
Evan Cheng | fc501a3 | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3082 | LHS = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 3083 | bitcastf32Toi32(LHS, DAG), Mask); |
| 3084 | RHS = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 3085 | bitcastf32Toi32(RHS, DAG), Mask); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3086 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
| 3087 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3088 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
| 3089 | Chain, Dest, ARMcc, CCR, Cmp); |
| 3090 | } |
| 3091 | |
| 3092 | SDValue LHS1, LHS2; |
| 3093 | SDValue RHS1, RHS2; |
| 3094 | expandf64Toi32(LHS, DAG, LHS1, LHS2); |
| 3095 | expandf64Toi32(RHS, DAG, RHS1, RHS2); |
Evan Cheng | fc501a3 | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3096 | LHS2 = DAG.getNode(ISD::AND, dl, MVT::i32, LHS2, Mask); |
| 3097 | RHS2 = DAG.getNode(ISD::AND, dl, MVT::i32, RHS2, Mask); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3098 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
| 3099 | ARMcc = DAG.getConstant(CondCode, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3100 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3101 | SDValue Ops[] = { Chain, ARMcc, LHS1, LHS2, RHS1, RHS2, Dest }; |
| 3102 | return DAG.getNode(ARMISD::BCC_i64, dl, VTList, Ops, 7); |
| 3103 | } |
| 3104 | |
| 3105 | return SDValue(); |
| 3106 | } |
| 3107 | |
| 3108 | SDValue ARMTargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) const { |
| 3109 | SDValue Chain = Op.getOperand(0); |
| 3110 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
| 3111 | SDValue LHS = Op.getOperand(2); |
| 3112 | SDValue RHS = Op.getOperand(3); |
| 3113 | SDValue Dest = Op.getOperand(4); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3114 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3115 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3116 | if (LHS.getValueType() == MVT::i32) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3117 | SDValue ARMcc; |
| 3118 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3119 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3120 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3121 | Chain, Dest, ARMcc, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3122 | } |
| 3123 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3124 | assert(LHS.getValueType() == MVT::f32 || LHS.getValueType() == MVT::f64); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3125 | |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 3126 | if (getTargetMachine().Options.UnsafeFPMath && |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3127 | (CC == ISD::SETEQ || CC == ISD::SETOEQ || |
| 3128 | CC == ISD::SETNE || CC == ISD::SETUNE)) { |
| 3129 | SDValue Result = OptimizeVFPBrcond(Op, DAG); |
| 3130 | if (Result.getNode()) |
| 3131 | return Result; |
| 3132 | } |
| 3133 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3134 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 3135 | FPCCToARMCC(CC, CondCode, CondCode2); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3136 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3137 | SDValue ARMcc = DAG.getConstant(CondCode, MVT::i32); |
| 3138 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3139 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3140 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3141 | SDValue Ops[] = { Chain, Dest, ARMcc, CCR, Cmp }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3142 | SDValue Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3143 | if (CondCode2 != ARMCC::AL) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3144 | ARMcc = DAG.getConstant(CondCode2, MVT::i32); |
| 3145 | SDValue Ops[] = { Res, Dest, ARMcc, CCR, Res.getValue(1) }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3146 | Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3147 | } |
| 3148 | return Res; |
| 3149 | } |
| 3150 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3151 | SDValue ARMTargetLowering::LowerBR_JT(SDValue Op, SelectionDAG &DAG) const { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3152 | SDValue Chain = Op.getOperand(0); |
| 3153 | SDValue Table = Op.getOperand(1); |
| 3154 | SDValue Index = Op.getOperand(2); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 3155 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3156 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3157 | EVT PTy = getPointerTy(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3158 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Table); |
| 3159 | ARMFunctionInfo *AFI = DAG.getMachineFunction().getInfo<ARMFunctionInfo>(); |
Bob Wilson | 3eadf00 | 2009-07-14 18:44:34 +0000 | [diff] [blame] | 3160 | SDValue UId = DAG.getConstant(AFI->createJumpTableUId(), PTy); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3161 | SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PTy); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3162 | Table = DAG.getNode(ARMISD::WrapperJT, dl, MVT::i32, JTI, UId); |
Evan Cheng | e7c329b | 2009-07-28 20:53:24 +0000 | [diff] [blame] | 3163 | Index = DAG.getNode(ISD::MUL, dl, PTy, Index, DAG.getConstant(4, PTy)); |
| 3164 | SDValue Addr = DAG.getNode(ISD::ADD, dl, PTy, Index, Table); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3165 | if (Subtarget->isThumb2()) { |
| 3166 | // Thumb2 uses a two-level jump. That is, it jumps into the jump table |
| 3167 | // which does another jump to the destination. This also makes it easier |
| 3168 | // to translate it to TBB / TBH later. |
| 3169 | // FIXME: This might not work if the function is extremely large. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3170 | return DAG.getNode(ARMISD::BR2_JT, dl, MVT::Other, Chain, |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 3171 | Addr, Op.getOperand(2), JTI, UId); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3172 | } |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3173 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 3174 | Addr = DAG.getLoad((EVT)MVT::i32, dl, Chain, Addr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3175 | MachinePointerInfo::getJumpTable(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3176 | false, false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3177 | Chain = Addr.getValue(1); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 3178 | Addr = DAG.getNode(ISD::ADD, dl, PTy, Addr, Table); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3179 | 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] | 3180 | } else { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 3181 | Addr = DAG.getLoad(PTy, dl, Chain, Addr, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3182 | MachinePointerInfo::getJumpTable(), |
| 3183 | false, false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3184 | Chain = Addr.getValue(1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3185 | 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] | 3186 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3187 | } |
| 3188 | |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3189 | static SDValue LowerVectorFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 3190 | EVT VT = Op.getValueType(); |
| 3191 | DebugLoc dl = Op.getDebugLoc(); |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3192 | |
James Molloy | 873fd5f | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 3193 | if (Op.getValueType().getVectorElementType() == MVT::i32) { |
| 3194 | if (Op.getOperand(0).getValueType().getVectorElementType() == MVT::f32) |
| 3195 | return Op; |
| 3196 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3197 | } |
| 3198 | |
| 3199 | assert(Op.getOperand(0).getValueType() == MVT::v4f32 && |
| 3200 | "Invalid type for custom lowering!"); |
| 3201 | if (VT != MVT::v4i16) |
| 3202 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3203 | |
| 3204 | Op = DAG.getNode(Op.getOpcode(), dl, MVT::v4i32, Op.getOperand(0)); |
| 3205 | return DAG.getNode(ISD::TRUNCATE, dl, VT, Op); |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3206 | } |
| 3207 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3208 | static SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3209 | EVT VT = Op.getValueType(); |
| 3210 | if (VT.isVector()) |
| 3211 | return LowerVectorFP_TO_INT(Op, DAG); |
| 3212 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3213 | DebugLoc dl = Op.getDebugLoc(); |
| 3214 | unsigned Opc; |
| 3215 | |
| 3216 | switch (Op.getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3217 | default: llvm_unreachable("Invalid opcode!"); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3218 | case ISD::FP_TO_SINT: |
| 3219 | Opc = ARMISD::FTOSI; |
| 3220 | break; |
| 3221 | case ISD::FP_TO_UINT: |
| 3222 | Opc = ARMISD::FTOUI; |
| 3223 | break; |
| 3224 | } |
| 3225 | Op = DAG.getNode(Opc, dl, MVT::f32, Op.getOperand(0)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3226 | return DAG.getNode(ISD::BITCAST, dl, MVT::i32, Op); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3227 | } |
| 3228 | |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3229 | static SDValue LowerVectorINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 3230 | EVT VT = Op.getValueType(); |
| 3231 | DebugLoc dl = Op.getDebugLoc(); |
| 3232 | |
Eli Friedman | 14e809c | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3233 | if (Op.getOperand(0).getValueType().getVectorElementType() == MVT::i32) { |
| 3234 | if (VT.getVectorElementType() == MVT::f32) |
| 3235 | return Op; |
| 3236 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3237 | } |
| 3238 | |
Duncan Sands | 1f6a329 | 2011-08-12 14:54:45 +0000 | [diff] [blame] | 3239 | assert(Op.getOperand(0).getValueType() == MVT::v4i16 && |
| 3240 | "Invalid type for custom lowering!"); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3241 | if (VT != MVT::v4f32) |
| 3242 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3243 | |
| 3244 | unsigned CastOpc; |
| 3245 | unsigned Opc; |
| 3246 | switch (Op.getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3247 | default: llvm_unreachable("Invalid opcode!"); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3248 | case ISD::SINT_TO_FP: |
| 3249 | CastOpc = ISD::SIGN_EXTEND; |
| 3250 | Opc = ISD::SINT_TO_FP; |
| 3251 | break; |
| 3252 | case ISD::UINT_TO_FP: |
| 3253 | CastOpc = ISD::ZERO_EXTEND; |
| 3254 | Opc = ISD::UINT_TO_FP; |
| 3255 | break; |
| 3256 | } |
| 3257 | |
| 3258 | Op = DAG.getNode(CastOpc, dl, MVT::v4i32, Op.getOperand(0)); |
| 3259 | return DAG.getNode(Opc, dl, VT, Op); |
| 3260 | } |
| 3261 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3262 | static SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 3263 | EVT VT = Op.getValueType(); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3264 | if (VT.isVector()) |
| 3265 | return LowerVectorINT_TO_FP(Op, DAG); |
| 3266 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3267 | DebugLoc dl = Op.getDebugLoc(); |
| 3268 | unsigned Opc; |
| 3269 | |
| 3270 | switch (Op.getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3271 | default: llvm_unreachable("Invalid opcode!"); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3272 | case ISD::SINT_TO_FP: |
| 3273 | Opc = ARMISD::SITOF; |
| 3274 | break; |
| 3275 | case ISD::UINT_TO_FP: |
| 3276 | Opc = ARMISD::UITOF; |
| 3277 | break; |
| 3278 | } |
| 3279 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3280 | Op = DAG.getNode(ISD::BITCAST, dl, MVT::f32, Op.getOperand(0)); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3281 | return DAG.getNode(Opc, dl, VT, Op); |
| 3282 | } |
| 3283 | |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 3284 | SDValue ARMTargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3285 | // Implement fcopysign with a fabs and a conditional fneg. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3286 | SDValue Tmp0 = Op.getOperand(0); |
| 3287 | SDValue Tmp1 = Op.getOperand(1); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3288 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3289 | EVT VT = Op.getValueType(); |
| 3290 | EVT SrcVT = Tmp1.getValueType(); |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3291 | bool InGPR = Tmp0.getOpcode() == ISD::BITCAST || |
| 3292 | Tmp0.getOpcode() == ARMISD::VMOVDRR; |
| 3293 | bool UseNEON = !InGPR && Subtarget->hasNEON(); |
| 3294 | |
| 3295 | if (UseNEON) { |
| 3296 | // Use VBSL to copy the sign bit. |
| 3297 | unsigned EncodedVal = ARM_AM::createNEONModImm(0x6, 0x80); |
| 3298 | SDValue Mask = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v2i32, |
| 3299 | DAG.getTargetConstant(EncodedVal, MVT::i32)); |
| 3300 | EVT OpVT = (VT == MVT::f32) ? MVT::v2i32 : MVT::v1i64; |
| 3301 | if (VT == MVT::f64) |
| 3302 | Mask = DAG.getNode(ARMISD::VSHL, dl, OpVT, |
| 3303 | DAG.getNode(ISD::BITCAST, dl, OpVT, Mask), |
| 3304 | DAG.getConstant(32, MVT::i32)); |
| 3305 | else /*if (VT == MVT::f32)*/ |
| 3306 | Tmp0 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp0); |
| 3307 | if (SrcVT == MVT::f32) { |
| 3308 | Tmp1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp1); |
| 3309 | if (VT == MVT::f64) |
| 3310 | Tmp1 = DAG.getNode(ARMISD::VSHL, dl, OpVT, |
| 3311 | DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1), |
| 3312 | DAG.getConstant(32, MVT::i32)); |
Evan Cheng | 9eec66e | 2011-04-15 01:31:00 +0000 | [diff] [blame] | 3313 | } else if (VT == MVT::f32) |
| 3314 | Tmp1 = DAG.getNode(ARMISD::VSHRu, dl, MVT::v1i64, |
| 3315 | DAG.getNode(ISD::BITCAST, dl, MVT::v1i64, Tmp1), |
| 3316 | DAG.getConstant(32, MVT::i32)); |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3317 | Tmp0 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp0); |
| 3318 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1); |
| 3319 | |
| 3320 | SDValue AllOnes = DAG.getTargetConstant(ARM_AM::createNEONModImm(0xe, 0xff), |
| 3321 | MVT::i32); |
| 3322 | AllOnes = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v8i8, AllOnes); |
| 3323 | SDValue MaskNot = DAG.getNode(ISD::XOR, dl, OpVT, Mask, |
| 3324 | DAG.getNode(ISD::BITCAST, dl, OpVT, AllOnes)); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 3325 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3326 | SDValue Res = DAG.getNode(ISD::OR, dl, OpVT, |
| 3327 | DAG.getNode(ISD::AND, dl, OpVT, Tmp1, Mask), |
| 3328 | DAG.getNode(ISD::AND, dl, OpVT, Tmp0, MaskNot)); |
Evan Cheng | c24ab5c | 2011-02-28 18:45:27 +0000 | [diff] [blame] | 3329 | if (VT == MVT::f32) { |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3330 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::v2f32, Res); |
| 3331 | Res = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f32, Res, |
| 3332 | DAG.getConstant(0, MVT::i32)); |
| 3333 | } else { |
| 3334 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::f64, Res); |
| 3335 | } |
| 3336 | |
| 3337 | return Res; |
| 3338 | } |
Evan Cheng | c143dd4 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 3339 | |
| 3340 | // Bitcast operand 1 to i32. |
| 3341 | if (SrcVT == MVT::f64) |
| 3342 | Tmp1 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), |
| 3343 | &Tmp1, 1).getValue(1); |
| 3344 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp1); |
| 3345 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3346 | // Or in the signbit with integer operations. |
| 3347 | SDValue Mask1 = DAG.getConstant(0x80000000, MVT::i32); |
| 3348 | SDValue Mask2 = DAG.getConstant(0x7fffffff, MVT::i32); |
| 3349 | Tmp1 = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp1, Mask1); |
| 3350 | if (VT == MVT::f32) { |
| 3351 | Tmp0 = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 3352 | DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp0), Mask2); |
| 3353 | return DAG.getNode(ISD::BITCAST, dl, MVT::f32, |
| 3354 | DAG.getNode(ISD::OR, dl, MVT::i32, Tmp0, Tmp1)); |
Evan Cheng | c143dd4 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 3355 | } |
| 3356 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3357 | // f64: Or the high part with signbit and then combine two parts. |
| 3358 | Tmp0 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), |
| 3359 | &Tmp0, 1); |
| 3360 | SDValue Lo = Tmp0.getValue(0); |
| 3361 | SDValue Hi = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp0.getValue(1), Mask2); |
| 3362 | Hi = DAG.getNode(ISD::OR, dl, MVT::i32, Hi, Tmp1); |
| 3363 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3364 | } |
| 3365 | |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3366 | SDValue ARMTargetLowering::LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const{ |
| 3367 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3368 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 3369 | MFI->setReturnAddressIsTaken(true); |
| 3370 | |
| 3371 | EVT VT = Op.getValueType(); |
| 3372 | DebugLoc dl = Op.getDebugLoc(); |
| 3373 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 3374 | if (Depth) { |
| 3375 | SDValue FrameAddr = LowerFRAMEADDR(Op, DAG); |
| 3376 | SDValue Offset = DAG.getConstant(4, MVT::i32); |
| 3377 | return DAG.getLoad(VT, dl, DAG.getEntryNode(), |
| 3378 | DAG.getNode(ISD::ADD, dl, VT, FrameAddr, Offset), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3379 | MachinePointerInfo(), false, false, false, 0); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3380 | } |
| 3381 | |
| 3382 | // 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] | 3383 | unsigned Reg = MF.addLiveIn(ARM::LR, getRegClassFor(MVT::i32)); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3384 | return DAG.getCopyFromReg(DAG.getEntryNode(), dl, Reg, VT); |
| 3385 | } |
| 3386 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3387 | SDValue ARMTargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const { |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3388 | MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); |
| 3389 | MFI->setFrameAddressIsTaken(true); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3390 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3391 | EVT VT = Op.getValueType(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3392 | DebugLoc dl = Op.getDebugLoc(); // FIXME probably not meaningful |
| 3393 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Evan Cheng | cd82861 | 2009-06-18 23:14:30 +0000 | [diff] [blame] | 3394 | unsigned FrameReg = (Subtarget->isThumb() || Subtarget->isTargetDarwin()) |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3395 | ? ARM::R7 : ARM::R11; |
| 3396 | SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, FrameReg, VT); |
| 3397 | while (Depth--) |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3398 | FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr, |
| 3399 | MachinePointerInfo(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3400 | false, false, false, 0); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3401 | return FrameAddr; |
| 3402 | } |
| 3403 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3404 | /// ExpandBITCAST - If the target supports VFP, this function is called to |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3405 | /// expand a bit convert where either the source or destination type is i64 to |
| 3406 | /// use a VMOVDRR or VMOVRRD node. This should not be done when the non-i64 |
| 3407 | /// operand type is illegal (e.g., v2f32 for a target that doesn't support |
| 3408 | /// vectors), since the legalizer won't know what to do with that. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3409 | static SDValue ExpandBITCAST(SDNode *N, SelectionDAG &DAG) { |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3410 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 3411 | DebugLoc dl = N->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3412 | SDValue Op = N->getOperand(0); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3413 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3414 | // This function is only supposed to be called for i64 types, either as the |
| 3415 | // source or destination of the bit convert. |
| 3416 | EVT SrcVT = Op.getValueType(); |
| 3417 | EVT DstVT = N->getValueType(0); |
| 3418 | assert((SrcVT == MVT::i64 || DstVT == MVT::i64) && |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3419 | "ExpandBITCAST called for non-i64 type"); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3420 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3421 | // Turn i64->f64 into VMOVDRR. |
| 3422 | if (SrcVT == MVT::i64 && TLI.isTypeLegal(DstVT)) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3423 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 3424 | DAG.getConstant(0, MVT::i32)); |
| 3425 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 3426 | DAG.getConstant(1, MVT::i32)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3427 | return DAG.getNode(ISD::BITCAST, dl, DstVT, |
Bob Wilson | 1114f56 | 2010-06-11 22:45:25 +0000 | [diff] [blame] | 3428 | DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi)); |
Evan Cheng | c7c7729 | 2008-11-04 19:57:48 +0000 | [diff] [blame] | 3429 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3430 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 3431 | // Turn f64->i64 into VMOVRRD. |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3432 | if (DstVT == MVT::i64 && TLI.isTypeLegal(SrcVT)) { |
| 3433 | SDValue Cvt = DAG.getNode(ARMISD::VMOVRRD, dl, |
| 3434 | DAG.getVTList(MVT::i32, MVT::i32), &Op, 1); |
| 3435 | // Merge the pieces into a single i64 value. |
| 3436 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Cvt, Cvt.getValue(1)); |
| 3437 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3438 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3439 | return SDValue(); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3440 | } |
| 3441 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3442 | /// getZeroVector - Returns a vector of specified type with all zero elements. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3443 | /// Zero vectors are used to represent vector negation and in those cases |
| 3444 | /// will be implemented with the NEON VNEG instruction. However, VNEG does |
| 3445 | /// not support i64 elements, so sometimes the zero vectors will need to be |
| 3446 | /// explicitly constructed. Regardless, use a canonical VMOV to create the |
| 3447 | /// zero vector. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3448 | static SDValue getZeroVector(EVT VT, SelectionDAG &DAG, DebugLoc dl) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3449 | assert(VT.isVector() && "Expected a vector type"); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3450 | // The canonical modified immediate encoding of a zero vector is....0! |
| 3451 | SDValue EncodedVal = DAG.getTargetConstant(0, MVT::i32); |
| 3452 | EVT VmovVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 3453 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, EncodedVal); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3454 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3455 | } |
| 3456 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3457 | /// LowerShiftRightParts - Lower SRA_PARTS, which returns two |
| 3458 | /// 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] | 3459 | SDValue ARMTargetLowering::LowerShiftRightParts(SDValue Op, |
| 3460 | SelectionDAG &DAG) const { |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3461 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 3462 | EVT VT = Op.getValueType(); |
| 3463 | unsigned VTBits = VT.getSizeInBits(); |
| 3464 | DebugLoc dl = Op.getDebugLoc(); |
| 3465 | SDValue ShOpLo = Op.getOperand(0); |
| 3466 | SDValue ShOpHi = Op.getOperand(1); |
| 3467 | SDValue ShAmt = Op.getOperand(2); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3468 | SDValue ARMcc; |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3469 | unsigned Opc = (Op.getOpcode() == ISD::SRA_PARTS) ? ISD::SRA : ISD::SRL; |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3470 | |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3471 | assert(Op.getOpcode() == ISD::SRA_PARTS || Op.getOpcode() == ISD::SRL_PARTS); |
| 3472 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3473 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 3474 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 3475 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, ShAmt); |
| 3476 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 3477 | DAG.getConstant(VTBits, MVT::i32)); |
| 3478 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, RevShAmt); |
| 3479 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3480 | SDValue TrueVal = DAG.getNode(Opc, dl, VT, ShOpHi, ExtraShAmt); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3481 | |
| 3482 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3483 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3484 | ARMcc, DAG, dl); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3485 | SDValue Hi = DAG.getNode(Opc, dl, VT, ShOpHi, ShAmt); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3486 | SDValue Lo = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3487 | CCR, Cmp); |
| 3488 | |
| 3489 | SDValue Ops[2] = { Lo, Hi }; |
| 3490 | return DAG.getMergeValues(Ops, 2, dl); |
| 3491 | } |
| 3492 | |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3493 | /// LowerShiftLeftParts - Lower SHL_PARTS, which returns two |
| 3494 | /// 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] | 3495 | SDValue ARMTargetLowering::LowerShiftLeftParts(SDValue Op, |
| 3496 | SelectionDAG &DAG) const { |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3497 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 3498 | EVT VT = Op.getValueType(); |
| 3499 | unsigned VTBits = VT.getSizeInBits(); |
| 3500 | DebugLoc dl = Op.getDebugLoc(); |
| 3501 | SDValue ShOpLo = Op.getOperand(0); |
| 3502 | SDValue ShOpHi = Op.getOperand(1); |
| 3503 | SDValue ShAmt = Op.getOperand(2); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3504 | SDValue ARMcc; |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3505 | |
| 3506 | assert(Op.getOpcode() == ISD::SHL_PARTS); |
| 3507 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 3508 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 3509 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, RevShAmt); |
| 3510 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 3511 | DAG.getConstant(VTBits, MVT::i32)); |
| 3512 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, ShAmt); |
| 3513 | SDValue Tmp3 = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ExtraShAmt); |
| 3514 | |
| 3515 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
| 3516 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3517 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3518 | ARMcc, DAG, dl); |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3519 | SDValue Lo = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ShAmt); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3520 | SDValue Hi = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, Tmp3, ARMcc, |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3521 | CCR, Cmp); |
| 3522 | |
| 3523 | SDValue Ops[2] = { Lo, Hi }; |
| 3524 | return DAG.getMergeValues(Ops, 2, dl); |
| 3525 | } |
| 3526 | |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3527 | SDValue ARMTargetLowering::LowerFLT_ROUNDS_(SDValue Op, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3528 | SelectionDAG &DAG) const { |
| 3529 | // The rounding mode is in bits 23:22 of the FPSCR. |
| 3530 | // The ARM rounding mode value to FLT_ROUNDS mapping is 0->1, 1->2, 2->3, 3->0 |
| 3531 | // The formula we use to implement this is (((FPSCR + 1 << 22) >> 22) & 3) |
| 3532 | // so that the shift + and get folded into a bitfield extract. |
| 3533 | DebugLoc dl = Op.getDebugLoc(); |
| 3534 | SDValue FPSCR = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::i32, |
| 3535 | DAG.getConstant(Intrinsic::arm_get_fpscr, |
| 3536 | MVT::i32)); |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3537 | SDValue FltRounds = DAG.getNode(ISD::ADD, dl, MVT::i32, FPSCR, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3538 | DAG.getConstant(1U << 22, MVT::i32)); |
| 3539 | SDValue RMODE = DAG.getNode(ISD::SRL, dl, MVT::i32, FltRounds, |
| 3540 | DAG.getConstant(22, MVT::i32)); |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3541 | return DAG.getNode(ISD::AND, dl, MVT::i32, RMODE, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3542 | DAG.getConstant(3, MVT::i32)); |
| 3543 | } |
| 3544 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 3545 | static SDValue LowerCTTZ(SDNode *N, SelectionDAG &DAG, |
| 3546 | const ARMSubtarget *ST) { |
| 3547 | EVT VT = N->getValueType(0); |
| 3548 | DebugLoc dl = N->getDebugLoc(); |
| 3549 | |
| 3550 | if (!ST->hasV6T2Ops()) |
| 3551 | return SDValue(); |
| 3552 | |
| 3553 | SDValue rbit = DAG.getNode(ARMISD::RBIT, dl, VT, N->getOperand(0)); |
| 3554 | return DAG.getNode(ISD::CTLZ, dl, VT, rbit); |
| 3555 | } |
| 3556 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3557 | static SDValue LowerShift(SDNode *N, SelectionDAG &DAG, |
| 3558 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3559 | EVT VT = N->getValueType(0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3560 | DebugLoc dl = N->getDebugLoc(); |
| 3561 | |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3562 | if (!VT.isVector()) |
| 3563 | return SDValue(); |
| 3564 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3565 | // Lower vector shifts on NEON to use VSHL. |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3566 | assert(ST->hasNEON() && "unexpected vector shift"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3567 | |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3568 | // Left shifts translate directly to the vshiftu intrinsic. |
| 3569 | if (N->getOpcode() == ISD::SHL) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3570 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3571 | DAG.getConstant(Intrinsic::arm_neon_vshiftu, MVT::i32), |
| 3572 | N->getOperand(0), N->getOperand(1)); |
| 3573 | |
| 3574 | assert((N->getOpcode() == ISD::SRA || |
| 3575 | N->getOpcode() == ISD::SRL) && "unexpected vector shift opcode"); |
| 3576 | |
| 3577 | // NEON uses the same intrinsics for both left and right shifts. For |
| 3578 | // right shifts, the shift amounts are negative, so negate the vector of |
| 3579 | // shift amounts. |
| 3580 | EVT ShiftVT = N->getOperand(1).getValueType(); |
| 3581 | SDValue NegatedCount = DAG.getNode(ISD::SUB, dl, ShiftVT, |
| 3582 | getZeroVector(ShiftVT, DAG, dl), |
| 3583 | N->getOperand(1)); |
| 3584 | Intrinsic::ID vshiftInt = (N->getOpcode() == ISD::SRA ? |
| 3585 | Intrinsic::arm_neon_vshifts : |
| 3586 | Intrinsic::arm_neon_vshiftu); |
| 3587 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
| 3588 | DAG.getConstant(vshiftInt, MVT::i32), |
| 3589 | N->getOperand(0), NegatedCount); |
| 3590 | } |
| 3591 | |
| 3592 | static SDValue Expand64BitShift(SDNode *N, SelectionDAG &DAG, |
| 3593 | const ARMSubtarget *ST) { |
| 3594 | EVT VT = N->getValueType(0); |
| 3595 | DebugLoc dl = N->getDebugLoc(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3596 | |
Eli Friedman | ce392eb | 2009-08-22 03:13:10 +0000 | [diff] [blame] | 3597 | // We can get here for a node like i32 = ISD::SHL i32, i64 |
| 3598 | if (VT != MVT::i64) |
| 3599 | return SDValue(); |
| 3600 | |
| 3601 | assert((N->getOpcode() == ISD::SRL || N->getOpcode() == ISD::SRA) && |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3602 | "Unknown shift to lower!"); |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3603 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3604 | // We only lower SRA, SRL of 1 here, all others use generic lowering. |
| 3605 | if (!isa<ConstantSDNode>(N->getOperand(1)) || |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 3606 | cast<ConstantSDNode>(N->getOperand(1))->getZExtValue() != 1) |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3607 | return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3608 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3609 | // If we are in thumb mode, we don't have RRX. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 3610 | if (ST->isThumb1Only()) return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3611 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3612 | // 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] | 3613 | 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] | 3614 | DAG.getConstant(0, MVT::i32)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3615 | 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] | 3616 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3617 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3618 | // First, build a SRA_FLAG/SRL_FLAG op, which shifts the top part by one and |
| 3619 | // captures the result into a carry flag. |
| 3620 | unsigned Opc = N->getOpcode() == ISD::SRL ? ARMISD::SRL_FLAG:ARMISD::SRA_FLAG; |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3621 | 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] | 3622 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3623 | // 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] | 3624 | Lo = DAG.getNode(ARMISD::RRX, dl, MVT::i32, Lo, Hi.getValue(1)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3625 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3626 | // Merge the pieces into a single i64 value. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3627 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3628 | } |
| 3629 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3630 | static SDValue LowerVSETCC(SDValue Op, SelectionDAG &DAG) { |
| 3631 | SDValue TmpOp0, TmpOp1; |
| 3632 | bool Invert = false; |
| 3633 | bool Swap = false; |
| 3634 | unsigned Opc = 0; |
| 3635 | |
| 3636 | SDValue Op0 = Op.getOperand(0); |
| 3637 | SDValue Op1 = Op.getOperand(1); |
| 3638 | SDValue CC = Op.getOperand(2); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3639 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3640 | ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get(); |
| 3641 | DebugLoc dl = Op.getDebugLoc(); |
| 3642 | |
| 3643 | if (Op.getOperand(1).getValueType().isFloatingPoint()) { |
| 3644 | switch (SetCCOpcode) { |
David Blaikie | 4d6ccb5 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 3645 | default: llvm_unreachable("Illegal FP comparison"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3646 | case ISD::SETUNE: |
| 3647 | case ISD::SETNE: Invert = true; // Fallthrough |
| 3648 | case ISD::SETOEQ: |
| 3649 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 3650 | case ISD::SETOLT: |
| 3651 | case ISD::SETLT: Swap = true; // Fallthrough |
| 3652 | case ISD::SETOGT: |
| 3653 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 3654 | case ISD::SETOLE: |
| 3655 | case ISD::SETLE: Swap = true; // Fallthrough |
| 3656 | case ISD::SETOGE: |
| 3657 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 3658 | case ISD::SETUGE: Swap = true; // Fallthrough |
| 3659 | case ISD::SETULE: Invert = true; Opc = ARMISD::VCGT; break; |
| 3660 | case ISD::SETUGT: Swap = true; // Fallthrough |
| 3661 | case ISD::SETULT: Invert = true; Opc = ARMISD::VCGE; break; |
| 3662 | case ISD::SETUEQ: Invert = true; // Fallthrough |
| 3663 | case ISD::SETONE: |
| 3664 | // Expand this to (OLT | OGT). |
| 3665 | TmpOp0 = Op0; |
| 3666 | TmpOp1 = Op1; |
| 3667 | Opc = ISD::OR; |
| 3668 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 3669 | Op1 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp0, TmpOp1); |
| 3670 | break; |
| 3671 | case ISD::SETUO: Invert = true; // Fallthrough |
| 3672 | case ISD::SETO: |
| 3673 | // Expand this to (OLT | OGE). |
| 3674 | TmpOp0 = Op0; |
| 3675 | TmpOp1 = Op1; |
| 3676 | Opc = ISD::OR; |
| 3677 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 3678 | Op1 = DAG.getNode(ARMISD::VCGE, dl, VT, TmpOp0, TmpOp1); |
| 3679 | break; |
| 3680 | } |
| 3681 | } else { |
| 3682 | // Integer comparisons. |
| 3683 | switch (SetCCOpcode) { |
David Blaikie | 4d6ccb5 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 3684 | default: llvm_unreachable("Illegal integer comparison"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3685 | case ISD::SETNE: Invert = true; |
| 3686 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 3687 | case ISD::SETLT: Swap = true; |
| 3688 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 3689 | case ISD::SETLE: Swap = true; |
| 3690 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 3691 | case ISD::SETULT: Swap = true; |
| 3692 | case ISD::SETUGT: Opc = ARMISD::VCGTU; break; |
| 3693 | case ISD::SETULE: Swap = true; |
| 3694 | case ISD::SETUGE: Opc = ARMISD::VCGEU; break; |
| 3695 | } |
| 3696 | |
Nick Lewycky | 7f6aa2b | 2009-07-08 03:04:38 +0000 | [diff] [blame] | 3697 | // Detect VTST (Vector Test Bits) = icmp ne (and (op0, op1), zero). |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3698 | if (Opc == ARMISD::VCEQ) { |
| 3699 | |
| 3700 | SDValue AndOp; |
| 3701 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 3702 | AndOp = Op0; |
| 3703 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) |
| 3704 | AndOp = Op1; |
| 3705 | |
| 3706 | // Ignore bitconvert. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3707 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::BITCAST) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3708 | AndOp = AndOp.getOperand(0); |
| 3709 | |
| 3710 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::AND) { |
| 3711 | Opc = ARMISD::VTST; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3712 | Op0 = DAG.getNode(ISD::BITCAST, dl, VT, AndOp.getOperand(0)); |
| 3713 | Op1 = DAG.getNode(ISD::BITCAST, dl, VT, AndOp.getOperand(1)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3714 | Invert = !Invert; |
| 3715 | } |
| 3716 | } |
| 3717 | } |
| 3718 | |
| 3719 | if (Swap) |
| 3720 | std::swap(Op0, Op1); |
| 3721 | |
Owen Anderson | c24cb35 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 3722 | // If one of the operands is a constant vector zero, attempt to fold the |
| 3723 | // comparison to a specialized compare-against-zero form. |
| 3724 | SDValue SingleOp; |
| 3725 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 3726 | SingleOp = Op0; |
| 3727 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) { |
| 3728 | if (Opc == ARMISD::VCGE) |
| 3729 | Opc = ARMISD::VCLEZ; |
| 3730 | else if (Opc == ARMISD::VCGT) |
| 3731 | Opc = ARMISD::VCLTZ; |
| 3732 | SingleOp = Op1; |
| 3733 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3734 | |
Owen Anderson | c24cb35 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 3735 | SDValue Result; |
| 3736 | if (SingleOp.getNode()) { |
| 3737 | switch (Opc) { |
| 3738 | case ARMISD::VCEQ: |
| 3739 | Result = DAG.getNode(ARMISD::VCEQZ, dl, VT, SingleOp); break; |
| 3740 | case ARMISD::VCGE: |
| 3741 | Result = DAG.getNode(ARMISD::VCGEZ, dl, VT, SingleOp); break; |
| 3742 | case ARMISD::VCLEZ: |
| 3743 | Result = DAG.getNode(ARMISD::VCLEZ, dl, VT, SingleOp); break; |
| 3744 | case ARMISD::VCGT: |
| 3745 | Result = DAG.getNode(ARMISD::VCGTZ, dl, VT, SingleOp); break; |
| 3746 | case ARMISD::VCLTZ: |
| 3747 | Result = DAG.getNode(ARMISD::VCLTZ, dl, VT, SingleOp); break; |
| 3748 | default: |
| 3749 | Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 3750 | } |
| 3751 | } else { |
| 3752 | Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 3753 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3754 | |
| 3755 | if (Invert) |
| 3756 | Result = DAG.getNOT(dl, Result, VT); |
| 3757 | |
| 3758 | return Result; |
| 3759 | } |
| 3760 | |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3761 | /// isNEONModifiedImm - Check if the specified splat value corresponds to a |
| 3762 | /// valid vector constant for a NEON instruction with a "modified immediate" |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3763 | /// operand (e.g., VMOV). If so, return the encoded value. |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3764 | static SDValue isNEONModifiedImm(uint64_t SplatBits, uint64_t SplatUndef, |
| 3765 | unsigned SplatBitSize, SelectionDAG &DAG, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3766 | EVT &VT, bool is128Bits, NEONModImmType type) { |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3767 | unsigned OpCmode, Imm; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3768 | |
Bob Wilson | 827b210 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 3769 | // SplatBitSize is set to the smallest size that splats the vector, so a |
| 3770 | // zero vector will always have SplatBitSize == 8. However, NEON modified |
| 3771 | // immediate instructions others than VMOV do not support the 8-bit encoding |
| 3772 | // of a zero vector, and the default encoding of zero is supposed to be the |
| 3773 | // 32-bit version. |
| 3774 | if (SplatBits == 0) |
| 3775 | SplatBitSize = 32; |
| 3776 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3777 | switch (SplatBitSize) { |
| 3778 | case 8: |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3779 | if (type != VMOVModImm) |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3780 | return SDValue(); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3781 | // Any 1-byte value is OK. Op=0, Cmode=1110. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3782 | assert((SplatBits & ~0xff) == 0 && "one byte splat value is too big"); |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3783 | OpCmode = 0xe; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3784 | Imm = SplatBits; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3785 | VT = is128Bits ? MVT::v16i8 : MVT::v8i8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3786 | break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3787 | |
| 3788 | case 16: |
| 3789 | // 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] | 3790 | VT = is128Bits ? MVT::v8i16 : MVT::v4i16; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3791 | if ((SplatBits & ~0xff) == 0) { |
| 3792 | // Value = 0x00nn: Op=x, Cmode=100x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3793 | OpCmode = 0x8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3794 | Imm = SplatBits; |
| 3795 | break; |
| 3796 | } |
| 3797 | if ((SplatBits & ~0xff00) == 0) { |
| 3798 | // Value = 0xnn00: Op=x, Cmode=101x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3799 | OpCmode = 0xa; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3800 | Imm = SplatBits >> 8; |
| 3801 | break; |
| 3802 | } |
| 3803 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3804 | |
| 3805 | case 32: |
| 3806 | // NEON's 32-bit VMOV supports splat values where: |
| 3807 | // * only one byte is nonzero, or |
| 3808 | // * the least significant byte is 0xff and the second byte is nonzero, or |
| 3809 | // * the least significant 2 bytes are 0xff and the third is nonzero. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3810 | VT = is128Bits ? MVT::v4i32 : MVT::v2i32; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3811 | if ((SplatBits & ~0xff) == 0) { |
| 3812 | // Value = 0x000000nn: Op=x, Cmode=000x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3813 | OpCmode = 0; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3814 | Imm = SplatBits; |
| 3815 | break; |
| 3816 | } |
| 3817 | if ((SplatBits & ~0xff00) == 0) { |
| 3818 | // Value = 0x0000nn00: Op=x, Cmode=001x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3819 | OpCmode = 0x2; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3820 | Imm = SplatBits >> 8; |
| 3821 | break; |
| 3822 | } |
| 3823 | if ((SplatBits & ~0xff0000) == 0) { |
| 3824 | // Value = 0x00nn0000: Op=x, Cmode=010x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3825 | OpCmode = 0x4; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3826 | Imm = SplatBits >> 16; |
| 3827 | break; |
| 3828 | } |
| 3829 | if ((SplatBits & ~0xff000000) == 0) { |
| 3830 | // Value = 0xnn000000: Op=x, Cmode=011x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3831 | OpCmode = 0x6; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3832 | Imm = SplatBits >> 24; |
| 3833 | break; |
| 3834 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3835 | |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3836 | // cmode == 0b1100 and cmode == 0b1101 are not supported for VORR or VBIC |
| 3837 | if (type == OtherModImm) return SDValue(); |
| 3838 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3839 | if ((SplatBits & ~0xffff) == 0 && |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3840 | ((SplatBits | SplatUndef) & 0xff) == 0xff) { |
| 3841 | // Value = 0x0000nnff: Op=x, Cmode=1100. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3842 | OpCmode = 0xc; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3843 | Imm = SplatBits >> 8; |
| 3844 | SplatBits |= 0xff; |
| 3845 | break; |
| 3846 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3847 | |
| 3848 | if ((SplatBits & ~0xffffff) == 0 && |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3849 | ((SplatBits | SplatUndef) & 0xffff) == 0xffff) { |
| 3850 | // Value = 0x00nnffff: Op=x, Cmode=1101. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3851 | OpCmode = 0xd; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3852 | Imm = SplatBits >> 16; |
| 3853 | SplatBits |= 0xffff; |
| 3854 | break; |
| 3855 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3856 | |
| 3857 | // Note: there are a few 32-bit splat values (specifically: 00ffff00, |
| 3858 | // ff000000, ff0000ff, and ffff00ff) that are valid for VMOV.I64 but not |
| 3859 | // VMOV.I32. A (very) minor optimization would be to replicate the value |
| 3860 | // and fall through here to test for a valid 64-bit splat. But, then the |
| 3861 | // caller would also need to check and handle the change in size. |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3862 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3863 | |
| 3864 | case 64: { |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3865 | if (type != VMOVModImm) |
Bob Wilson | 827b210 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 3866 | return SDValue(); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3867 | // 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] | 3868 | uint64_t BitMask = 0xff; |
| 3869 | uint64_t Val = 0; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3870 | unsigned ImmMask = 1; |
| 3871 | Imm = 0; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3872 | for (int ByteNum = 0; ByteNum < 8; ++ByteNum) { |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3873 | if (((SplatBits | SplatUndef) & BitMask) == BitMask) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3874 | Val |= BitMask; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3875 | Imm |= ImmMask; |
| 3876 | } else if ((SplatBits & BitMask) != 0) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3877 | return SDValue(); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3878 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3879 | BitMask <<= 8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3880 | ImmMask <<= 1; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3881 | } |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3882 | // Op=1, Cmode=1110. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3883 | OpCmode = 0x1e; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3884 | SplatBits = Val; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3885 | VT = is128Bits ? MVT::v2i64 : MVT::v1i64; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3886 | break; |
| 3887 | } |
| 3888 | |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3889 | default: |
Bob Wilson | dc076da | 2010-06-19 05:32:09 +0000 | [diff] [blame] | 3890 | llvm_unreachable("unexpected size for isNEONModifiedImm"); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3891 | } |
| 3892 | |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3893 | unsigned EncodedVal = ARM_AM::createNEONModImm(OpCmode, Imm); |
| 3894 | return DAG.getTargetConstant(EncodedVal, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3895 | } |
| 3896 | |
Lang Hames | c0a9f82 | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 3897 | SDValue ARMTargetLowering::LowerConstantFP(SDValue Op, SelectionDAG &DAG, |
| 3898 | const ARMSubtarget *ST) const { |
| 3899 | if (!ST->useNEONForSinglePrecisionFP() || !ST->hasVFP3() || ST->hasD16()) |
| 3900 | return SDValue(); |
| 3901 | |
| 3902 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Op); |
| 3903 | assert(Op.getValueType() == MVT::f32 && |
| 3904 | "ConstantFP custom lowering should only occur for f32."); |
| 3905 | |
| 3906 | // Try splatting with a VMOV.f32... |
| 3907 | APFloat FPVal = CFP->getValueAPF(); |
| 3908 | int ImmVal = ARM_AM::getFP32Imm(FPVal); |
| 3909 | if (ImmVal != -1) { |
| 3910 | DebugLoc DL = Op.getDebugLoc(); |
| 3911 | SDValue NewVal = DAG.getTargetConstant(ImmVal, MVT::i32); |
| 3912 | SDValue VecConstant = DAG.getNode(ARMISD::VMOVFPIMM, DL, MVT::v2f32, |
| 3913 | NewVal); |
| 3914 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, VecConstant, |
| 3915 | DAG.getConstant(0, MVT::i32)); |
| 3916 | } |
| 3917 | |
| 3918 | // If that fails, try a VMOV.i32 |
| 3919 | EVT VMovVT; |
| 3920 | unsigned iVal = FPVal.bitcastToAPInt().getZExtValue(); |
| 3921 | SDValue NewVal = isNEONModifiedImm(iVal, 0, 32, DAG, VMovVT, false, |
| 3922 | VMOVModImm); |
| 3923 | if (NewVal != SDValue()) { |
| 3924 | DebugLoc DL = Op.getDebugLoc(); |
| 3925 | SDValue VecConstant = DAG.getNode(ARMISD::VMOVIMM, DL, VMovVT, |
| 3926 | NewVal); |
| 3927 | SDValue VecFConstant = DAG.getNode(ISD::BITCAST, DL, MVT::v2f32, |
| 3928 | VecConstant); |
| 3929 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, VecFConstant, |
| 3930 | DAG.getConstant(0, MVT::i32)); |
| 3931 | } |
| 3932 | |
| 3933 | // Finally, try a VMVN.i32 |
| 3934 | NewVal = isNEONModifiedImm(~iVal & 0xffffffff, 0, 32, DAG, VMovVT, false, |
| 3935 | VMVNModImm); |
| 3936 | if (NewVal != SDValue()) { |
| 3937 | DebugLoc DL = Op.getDebugLoc(); |
| 3938 | SDValue VecConstant = DAG.getNode(ARMISD::VMVNIMM, DL, VMovVT, NewVal); |
| 3939 | SDValue VecFConstant = DAG.getNode(ISD::BITCAST, DL, MVT::v2f32, |
| 3940 | VecConstant); |
| 3941 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, VecFConstant, |
| 3942 | DAG.getConstant(0, MVT::i32)); |
| 3943 | } |
| 3944 | |
| 3945 | return SDValue(); |
| 3946 | } |
| 3947 | |
Quentin Colombet | 43934ae | 2012-11-02 21:32:17 +0000 | [diff] [blame] | 3948 | // check if an VEXT instruction can handle the shuffle mask when the |
| 3949 | // vector sources of the shuffle are the same. |
| 3950 | static bool isSingletonVEXTMask(ArrayRef<int> M, EVT VT, unsigned &Imm) { |
| 3951 | unsigned NumElts = VT.getVectorNumElements(); |
| 3952 | |
| 3953 | // Assume that the first shuffle index is not UNDEF. Fail if it is. |
| 3954 | if (M[0] < 0) |
| 3955 | return false; |
| 3956 | |
| 3957 | Imm = M[0]; |
| 3958 | |
| 3959 | // If this is a VEXT shuffle, the immediate value is the index of the first |
| 3960 | // element. The other shuffle indices must be the successive elements after |
| 3961 | // the first one. |
| 3962 | unsigned ExpectedElt = Imm; |
| 3963 | for (unsigned i = 1; i < NumElts; ++i) { |
| 3964 | // Increment the expected index. If it wraps around, just follow it |
| 3965 | // back to index zero and keep going. |
| 3966 | ++ExpectedElt; |
| 3967 | if (ExpectedElt == NumElts) |
| 3968 | ExpectedElt = 0; |
| 3969 | |
| 3970 | if (M[i] < 0) continue; // ignore UNDEF indices |
| 3971 | if (ExpectedElt != static_cast<unsigned>(M[i])) |
| 3972 | return false; |
| 3973 | } |
| 3974 | |
| 3975 | return true; |
| 3976 | } |
| 3977 | |
Lang Hames | c0a9f82 | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 3978 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 3979 | static bool isVEXTMask(ArrayRef<int> M, EVT VT, |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3980 | bool &ReverseVEXT, unsigned &Imm) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3981 | unsigned NumElts = VT.getVectorNumElements(); |
| 3982 | ReverseVEXT = false; |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3983 | |
| 3984 | // Assume that the first shuffle index is not UNDEF. Fail if it is. |
| 3985 | if (M[0] < 0) |
| 3986 | return false; |
| 3987 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3988 | Imm = M[0]; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3989 | |
| 3990 | // If this is a VEXT shuffle, the immediate value is the index of the first |
| 3991 | // element. The other shuffle indices must be the successive elements after |
| 3992 | // the first one. |
| 3993 | unsigned ExpectedElt = Imm; |
| 3994 | for (unsigned i = 1; i < NumElts; ++i) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3995 | // Increment the expected index. If it wraps around, it may still be |
| 3996 | // a VEXT but the source vectors must be swapped. |
| 3997 | ExpectedElt += 1; |
| 3998 | if (ExpectedElt == NumElts * 2) { |
| 3999 | ExpectedElt = 0; |
| 4000 | ReverseVEXT = true; |
| 4001 | } |
| 4002 | |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4003 | if (M[i] < 0) continue; // ignore UNDEF indices |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4004 | if (ExpectedElt != static_cast<unsigned>(M[i])) |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4005 | return false; |
| 4006 | } |
| 4007 | |
| 4008 | // Adjust the index value if the source operands will be swapped. |
| 4009 | if (ReverseVEXT) |
| 4010 | Imm -= NumElts; |
| 4011 | |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4012 | return true; |
| 4013 | } |
| 4014 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 4015 | /// isVREVMask - Check if a vector shuffle corresponds to a VREV |
| 4016 | /// instruction with the specified blocksize. (The order of the elements |
| 4017 | /// within each block of the vector is reversed.) |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4018 | static bool isVREVMask(ArrayRef<int> M, EVT VT, unsigned BlockSize) { |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 4019 | assert((BlockSize==16 || BlockSize==32 || BlockSize==64) && |
| 4020 | "Only possible block sizes for VREV are: 16, 32, 64"); |
| 4021 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 4022 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 4023 | if (EltSz == 64) |
| 4024 | return false; |
| 4025 | |
| 4026 | unsigned NumElts = VT.getVectorNumElements(); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4027 | unsigned BlockElts = M[0] + 1; |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4028 | // If the first shuffle index is UNDEF, be optimistic. |
| 4029 | if (M[0] < 0) |
| 4030 | BlockElts = BlockSize / EltSz; |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 4031 | |
| 4032 | if (BlockSize <= EltSz || BlockSize != BlockElts * EltSz) |
| 4033 | return false; |
| 4034 | |
| 4035 | for (unsigned i = 0; i < NumElts; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4036 | if (M[i] < 0) continue; // ignore UNDEF indices |
| 4037 | if ((unsigned) M[i] != (i - i%BlockElts) + (BlockElts - 1 - i%BlockElts)) |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 4038 | return false; |
| 4039 | } |
| 4040 | |
| 4041 | return true; |
| 4042 | } |
| 4043 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4044 | static bool isVTBLMask(ArrayRef<int> M, EVT VT) { |
Bill Wendling | 0d4c9d9 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 4045 | // We can handle <8 x i8> vector shuffles. If the index in the mask is out of |
| 4046 | // range, then 0 is placed into the resulting vector. So pretty much any mask |
| 4047 | // of 8 elements can work here. |
| 4048 | return VT == MVT::v8i8 && M.size() == 8; |
| 4049 | } |
| 4050 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4051 | static bool isVTRNMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 4052 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 4053 | if (EltSz == 64) |
| 4054 | return false; |
| 4055 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4056 | unsigned NumElts = VT.getVectorNumElements(); |
| 4057 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 4058 | for (unsigned i = 0; i < NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4059 | if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) || |
| 4060 | (M[i+1] >= 0 && (unsigned) M[i+1] != i + NumElts + WhichResult)) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4061 | return false; |
| 4062 | } |
| 4063 | return true; |
| 4064 | } |
| 4065 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4066 | /// isVTRN_v_undef_Mask - Special case of isVTRNMask for canonical form of |
| 4067 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 4068 | /// 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] | 4069 | 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] | 4070 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 4071 | if (EltSz == 64) |
| 4072 | return false; |
| 4073 | |
| 4074 | unsigned NumElts = VT.getVectorNumElements(); |
| 4075 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 4076 | for (unsigned i = 0; i < NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4077 | if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) || |
| 4078 | (M[i+1] >= 0 && (unsigned) M[i+1] != i + WhichResult)) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4079 | return false; |
| 4080 | } |
| 4081 | return true; |
| 4082 | } |
| 4083 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4084 | static bool isVUZPMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 4085 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 4086 | if (EltSz == 64) |
| 4087 | return false; |
| 4088 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4089 | unsigned NumElts = VT.getVectorNumElements(); |
| 4090 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 4091 | for (unsigned i = 0; i != NumElts; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4092 | if (M[i] < 0) continue; // ignore UNDEF indices |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4093 | if ((unsigned) M[i] != 2 * i + WhichResult) |
| 4094 | return false; |
| 4095 | } |
| 4096 | |
| 4097 | // 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] | 4098 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4099 | return false; |
| 4100 | |
| 4101 | return true; |
| 4102 | } |
| 4103 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4104 | /// isVUZP_v_undef_Mask - Special case of isVUZPMask for canonical form of |
| 4105 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 4106 | /// 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] | 4107 | 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] | 4108 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 4109 | if (EltSz == 64) |
| 4110 | return false; |
| 4111 | |
| 4112 | unsigned Half = VT.getVectorNumElements() / 2; |
| 4113 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 4114 | for (unsigned j = 0; j != 2; ++j) { |
| 4115 | unsigned Idx = WhichResult; |
| 4116 | for (unsigned i = 0; i != Half; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4117 | int MIdx = M[i + j * Half]; |
| 4118 | if (MIdx >= 0 && (unsigned) MIdx != Idx) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4119 | return false; |
| 4120 | Idx += 2; |
| 4121 | } |
| 4122 | } |
| 4123 | |
| 4124 | // VUZP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 4125 | if (VT.is64BitVector() && EltSz == 32) |
| 4126 | return false; |
| 4127 | |
| 4128 | return true; |
| 4129 | } |
| 4130 | |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4131 | static bool isVZIPMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 4132 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 4133 | if (EltSz == 64) |
| 4134 | return false; |
| 4135 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4136 | unsigned NumElts = VT.getVectorNumElements(); |
| 4137 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 4138 | unsigned Idx = WhichResult * NumElts / 2; |
| 4139 | for (unsigned i = 0; i != NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4140 | if ((M[i] >= 0 && (unsigned) M[i] != Idx) || |
| 4141 | (M[i+1] >= 0 && (unsigned) M[i+1] != Idx + NumElts)) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4142 | return false; |
| 4143 | Idx += 1; |
| 4144 | } |
| 4145 | |
| 4146 | // 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] | 4147 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4148 | return false; |
| 4149 | |
| 4150 | return true; |
| 4151 | } |
| 4152 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4153 | /// isVZIP_v_undef_Mask - Special case of isVZIPMask for canonical form of |
| 4154 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 4155 | /// 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] | 4156 | 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] | 4157 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 4158 | if (EltSz == 64) |
| 4159 | return false; |
| 4160 | |
| 4161 | unsigned NumElts = VT.getVectorNumElements(); |
| 4162 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 4163 | unsigned Idx = WhichResult * NumElts / 2; |
| 4164 | for (unsigned i = 0; i != NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4165 | if ((M[i] >= 0 && (unsigned) M[i] != Idx) || |
| 4166 | (M[i+1] >= 0 && (unsigned) M[i+1] != Idx)) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4167 | return false; |
| 4168 | Idx += 1; |
| 4169 | } |
| 4170 | |
| 4171 | // VZIP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 4172 | if (VT.is64BitVector() && EltSz == 32) |
| 4173 | return false; |
| 4174 | |
| 4175 | return true; |
| 4176 | } |
| 4177 | |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4178 | // If N is an integer constant that can be moved into a register in one |
| 4179 | // instruction, return an SDValue of such a constant (will become a MOV |
| 4180 | // instruction). Otherwise return null. |
| 4181 | static SDValue IsSingleInstrConstant(SDValue N, SelectionDAG &DAG, |
| 4182 | const ARMSubtarget *ST, DebugLoc dl) { |
| 4183 | uint64_t Val; |
| 4184 | if (!isa<ConstantSDNode>(N)) |
| 4185 | return SDValue(); |
| 4186 | Val = cast<ConstantSDNode>(N)->getZExtValue(); |
| 4187 | |
| 4188 | if (ST->isThumb1Only()) { |
| 4189 | if (Val <= 255 || ~Val <= 255) |
| 4190 | return DAG.getConstant(Val, MVT::i32); |
| 4191 | } else { |
| 4192 | if (ARM_AM::getSOImmVal(Val) != -1 || ARM_AM::getSOImmVal(~Val) != -1) |
| 4193 | return DAG.getConstant(Val, MVT::i32); |
| 4194 | } |
| 4195 | return SDValue(); |
| 4196 | } |
| 4197 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4198 | // If this is a case we can't handle, return null and let the default |
| 4199 | // expansion code take care of it. |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4200 | SDValue ARMTargetLowering::LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG, |
| 4201 | const ARMSubtarget *ST) const { |
Bob Wilson | d06791f | 2009-08-13 01:57:47 +0000 | [diff] [blame] | 4202 | BuildVectorSDNode *BVN = cast<BuildVectorSDNode>(Op.getNode()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4203 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4204 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4205 | |
| 4206 | APInt SplatBits, SplatUndef; |
| 4207 | unsigned SplatBitSize; |
| 4208 | bool HasAnyUndefs; |
| 4209 | if (BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
Anton Korobeynikov | 71624cc | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 4210 | if (SplatBitSize <= 64) { |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 4211 | // Check if an immediate VMOV works. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4212 | EVT VmovVT; |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 4213 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4214 | SplatUndef.getZExtValue(), SplatBitSize, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4215 | DAG, VmovVT, VT.is128BitVector(), |
| 4216 | VMOVModImm); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4217 | if (Val.getNode()) { |
| 4218 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4219 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4220 | } |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4221 | |
| 4222 | // Try an immediate VMVN. |
Eli Friedman | 8e4d042 | 2011-10-13 22:40:23 +0000 | [diff] [blame] | 4223 | uint64_t NegatedImm = (~SplatBits).getZExtValue(); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4224 | Val = isNEONModifiedImm(NegatedImm, |
| 4225 | SplatUndef.getZExtValue(), SplatBitSize, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4226 | DAG, VmovVT, VT.is128BitVector(), |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4227 | VMVNModImm); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4228 | if (Val.getNode()) { |
| 4229 | SDValue Vmov = DAG.getNode(ARMISD::VMVNIMM, dl, VmovVT, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4230 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4231 | } |
Evan Cheng | eaa192a | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 4232 | |
| 4233 | // Use vmov.f32 to materialize other v2f32 and v4f32 splats. |
Eli Friedman | 2f21e8c | 2011-12-15 22:56:53 +0000 | [diff] [blame] | 4234 | if ((VT == MVT::v2f32 || VT == MVT::v4f32) && SplatBitSize == 32) { |
Eli Friedman | effab8f | 2011-12-09 23:54:42 +0000 | [diff] [blame] | 4235 | int ImmVal = ARM_AM::getFP32Imm(SplatBits); |
Evan Cheng | eaa192a | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 4236 | if (ImmVal != -1) { |
| 4237 | SDValue Val = DAG.getTargetConstant(ImmVal, MVT::i32); |
| 4238 | return DAG.getNode(ARMISD::VMOVFPIMM, dl, VT, Val); |
| 4239 | } |
| 4240 | } |
Anton Korobeynikov | 71624cc | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 4241 | } |
Bob Wilson | cf661e2 | 2009-07-30 00:31:25 +0000 | [diff] [blame] | 4242 | } |
| 4243 | |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4244 | // Scan through the operands to see if only one value is used. |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4245 | // |
| 4246 | // As an optimisation, even if more than one value is used it may be more |
| 4247 | // profitable to splat with one value then change some lanes. |
| 4248 | // |
| 4249 | // Heuristically we decide to do this if the vector has a "dominant" value, |
| 4250 | // defined as splatted to more than half of the lanes. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4251 | unsigned NumElts = VT.getVectorNumElements(); |
| 4252 | bool isOnlyLowElement = true; |
| 4253 | bool usesOnlyOneValue = true; |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4254 | bool hasDominantValue = false; |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4255 | bool isConstant = true; |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4256 | |
| 4257 | // Map of the number of times a particular SDValue appears in the |
| 4258 | // element list. |
James Molloy | 9515434 | 2012-09-06 10:32:08 +0000 | [diff] [blame] | 4259 | DenseMap<SDValue, unsigned> ValueCounts; |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4260 | SDValue Value; |
| 4261 | for (unsigned i = 0; i < NumElts; ++i) { |
| 4262 | SDValue V = Op.getOperand(i); |
| 4263 | if (V.getOpcode() == ISD::UNDEF) |
| 4264 | continue; |
| 4265 | if (i > 0) |
| 4266 | isOnlyLowElement = false; |
| 4267 | if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V)) |
| 4268 | isConstant = false; |
| 4269 | |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4270 | ValueCounts.insert(std::make_pair(V, 0)); |
James Molloy | 9515434 | 2012-09-06 10:32:08 +0000 | [diff] [blame] | 4271 | unsigned &Count = ValueCounts[V]; |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4272 | |
| 4273 | // Is this value dominant? (takes up more than half of the lanes) |
| 4274 | if (++Count > (NumElts / 2)) { |
| 4275 | hasDominantValue = true; |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4276 | Value = V; |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4277 | } |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4278 | } |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4279 | if (ValueCounts.size() != 1) |
| 4280 | usesOnlyOneValue = false; |
| 4281 | if (!Value.getNode() && ValueCounts.size() > 0) |
| 4282 | Value = ValueCounts.begin()->first; |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4283 | |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4284 | if (ValueCounts.size() == 0) |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4285 | return DAG.getUNDEF(VT); |
| 4286 | |
| 4287 | if (isOnlyLowElement) |
| 4288 | return DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, Value); |
| 4289 | |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4290 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4291 | |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 4292 | // Use VDUP for non-constant splats. For f32 constant splats, reduce to |
| 4293 | // i32 and try again. |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4294 | if (hasDominantValue && EltSize <= 32) { |
| 4295 | if (!isConstant) { |
| 4296 | SDValue N; |
| 4297 | |
| 4298 | // If we are VDUPing a value that comes directly from a vector, that will |
| 4299 | // cause an unnecessary move to and from a GPR, where instead we could |
| 4300 | // just use VDUPLANE. |
Silviu Baranga | bb1078e | 2012-10-15 09:41:32 +0000 | [diff] [blame] | 4301 | if (Value->getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
| 4302 | // We need to create a new undef vector to use for the VDUPLANE if the |
| 4303 | // size of the vector from which we get the value is different than the |
| 4304 | // size of the vector that we need to create. We will insert the element |
| 4305 | // such that the register coalescer will remove unnecessary copies. |
| 4306 | if (VT != Value->getOperand(0).getValueType()) { |
| 4307 | ConstantSDNode *constIndex; |
| 4308 | constIndex = dyn_cast<ConstantSDNode>(Value->getOperand(1)); |
| 4309 | assert(constIndex && "The index is not a constant!"); |
| 4310 | unsigned index = constIndex->getAPIntValue().getLimitedValue() % |
| 4311 | VT.getVectorNumElements(); |
| 4312 | N = DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
| 4313 | DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VT, DAG.getUNDEF(VT), |
| 4314 | Value, DAG.getConstant(index, MVT::i32)), |
| 4315 | DAG.getConstant(index, MVT::i32)); |
| 4316 | } else { |
| 4317 | N = DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4318 | Value->getOperand(0), Value->getOperand(1)); |
Silviu Baranga | bb1078e | 2012-10-15 09:41:32 +0000 | [diff] [blame] | 4319 | } |
| 4320 | } |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4321 | else |
| 4322 | N = DAG.getNode(ARMISD::VDUP, dl, VT, Value); |
| 4323 | |
| 4324 | if (!usesOnlyOneValue) { |
| 4325 | // The dominant value was splatted as 'N', but we now have to insert |
| 4326 | // all differing elements. |
| 4327 | for (unsigned I = 0; I < NumElts; ++I) { |
| 4328 | if (Op.getOperand(I) == Value) |
| 4329 | continue; |
| 4330 | SmallVector<SDValue, 3> Ops; |
| 4331 | Ops.push_back(N); |
| 4332 | Ops.push_back(Op.getOperand(I)); |
| 4333 | Ops.push_back(DAG.getConstant(I, MVT::i32)); |
| 4334 | N = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VT, &Ops[0], 3); |
| 4335 | } |
| 4336 | } |
| 4337 | return N; |
| 4338 | } |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 4339 | if (VT.getVectorElementType().isFloatingPoint()) { |
| 4340 | SmallVector<SDValue, 8> Ops; |
| 4341 | for (unsigned i = 0; i < NumElts; ++i) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4342 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, MVT::i32, |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 4343 | Op.getOperand(i))); |
Nate Begeman | bf5be26 | 2010-11-10 21:35:41 +0000 | [diff] [blame] | 4344 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), MVT::i32, NumElts); |
| 4345 | SDValue Val = DAG.getNode(ISD::BUILD_VECTOR, dl, VecVT, &Ops[0], NumElts); |
Dale Johannesen | e4d3159 | 2010-10-20 22:03:37 +0000 | [diff] [blame] | 4346 | Val = LowerBUILD_VECTOR(Val, DAG, ST); |
| 4347 | if (Val.getNode()) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4348 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4349 | } |
James Molloy | ba8562a | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 4350 | if (usesOnlyOneValue) { |
| 4351 | SDValue Val = IsSingleInstrConstant(Value, DAG, ST, dl); |
| 4352 | if (isConstant && Val.getNode()) |
| 4353 | return DAG.getNode(ARMISD::VDUP, dl, VT, Val); |
| 4354 | } |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4355 | } |
| 4356 | |
| 4357 | // If all elements are constants and the case above didn't get hit, fall back |
| 4358 | // to the default expansion, which will generate a load from the constant |
| 4359 | // pool. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4360 | if (isConstant) |
| 4361 | return SDValue(); |
| 4362 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4363 | // Empirical tests suggest this is rarely worth it for vectors of length <= 2. |
| 4364 | if (NumElts >= 4) { |
| 4365 | SDValue shuffle = ReconstructShuffle(Op, DAG); |
| 4366 | if (shuffle != SDValue()) |
| 4367 | return shuffle; |
| 4368 | } |
| 4369 | |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4370 | // 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] | 4371 | // the subregisters. Lower it to an ARMISD::BUILD_VECTOR so the operands |
| 4372 | // will be legalized. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4373 | if (EltSize >= 32) { |
| 4374 | // Do the expansion with floating-point types, since that is what the VFP |
| 4375 | // registers are defined to use, and since i64 is not legal. |
| 4376 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 4377 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4378 | SmallVector<SDValue, 8> Ops; |
| 4379 | for (unsigned i = 0; i < NumElts; ++i) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4380 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, EltVT, Op.getOperand(i))); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4381 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, &Ops[0],NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4382 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4383 | } |
| 4384 | |
| 4385 | return SDValue(); |
| 4386 | } |
| 4387 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4388 | // Gather data to see if the operation can be modelled as a |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4389 | // shuffle in combination with VEXTs. |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4390 | SDValue ARMTargetLowering::ReconstructShuffle(SDValue Op, |
| 4391 | SelectionDAG &DAG) const { |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4392 | DebugLoc dl = Op.getDebugLoc(); |
| 4393 | EVT VT = Op.getValueType(); |
| 4394 | unsigned NumElts = VT.getVectorNumElements(); |
| 4395 | |
| 4396 | SmallVector<SDValue, 2> SourceVecs; |
| 4397 | SmallVector<unsigned, 2> MinElts; |
| 4398 | SmallVector<unsigned, 2> MaxElts; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4399 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4400 | for (unsigned i = 0; i < NumElts; ++i) { |
| 4401 | SDValue V = Op.getOperand(i); |
| 4402 | if (V.getOpcode() == ISD::UNDEF) |
| 4403 | continue; |
| 4404 | else if (V.getOpcode() != ISD::EXTRACT_VECTOR_ELT) { |
| 4405 | // A shuffle can only come from building a vector from various |
| 4406 | // elements of other vectors. |
| 4407 | return SDValue(); |
Eli Friedman | 46995fa | 2011-10-14 23:58:49 +0000 | [diff] [blame] | 4408 | } else if (V.getOperand(0).getValueType().getVectorElementType() != |
| 4409 | VT.getVectorElementType()) { |
| 4410 | // This code doesn't know how to handle shuffles where the vector |
| 4411 | // element types do not match (this happens because type legalization |
| 4412 | // promotes the return type of EXTRACT_VECTOR_ELT). |
| 4413 | // FIXME: It might be appropriate to extend this code to handle |
| 4414 | // mismatched types. |
| 4415 | return SDValue(); |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4416 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4417 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4418 | // Record this extraction against the appropriate vector if possible... |
| 4419 | SDValue SourceVec = V.getOperand(0); |
Jim Grosbach | 2422047 | 2012-07-25 17:02:47 +0000 | [diff] [blame] | 4420 | // If the element number isn't a constant, we can't effectively |
| 4421 | // analyze what's going on. |
| 4422 | if (!isa<ConstantSDNode>(V.getOperand(1))) |
| 4423 | return SDValue(); |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4424 | unsigned EltNo = cast<ConstantSDNode>(V.getOperand(1))->getZExtValue(); |
| 4425 | bool FoundSource = false; |
| 4426 | for (unsigned j = 0; j < SourceVecs.size(); ++j) { |
| 4427 | if (SourceVecs[j] == SourceVec) { |
| 4428 | if (MinElts[j] > EltNo) |
| 4429 | MinElts[j] = EltNo; |
| 4430 | if (MaxElts[j] < EltNo) |
| 4431 | MaxElts[j] = EltNo; |
| 4432 | FoundSource = true; |
| 4433 | break; |
| 4434 | } |
| 4435 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4436 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4437 | // Or record a new source if not... |
| 4438 | if (!FoundSource) { |
| 4439 | SourceVecs.push_back(SourceVec); |
| 4440 | MinElts.push_back(EltNo); |
| 4441 | MaxElts.push_back(EltNo); |
| 4442 | } |
| 4443 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4444 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4445 | // Currently only do something sane when at most two source vectors |
| 4446 | // involved. |
| 4447 | if (SourceVecs.size() > 2) |
| 4448 | return SDValue(); |
| 4449 | |
| 4450 | SDValue ShuffleSrcs[2] = {DAG.getUNDEF(VT), DAG.getUNDEF(VT) }; |
| 4451 | int VEXTOffsets[2] = {0, 0}; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4452 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4453 | // This loop extracts the usage patterns of the source vectors |
| 4454 | // and prepares appropriate SDValues for a shuffle if possible. |
| 4455 | for (unsigned i = 0; i < SourceVecs.size(); ++i) { |
| 4456 | if (SourceVecs[i].getValueType() == VT) { |
| 4457 | // No VEXT necessary |
| 4458 | ShuffleSrcs[i] = SourceVecs[i]; |
| 4459 | VEXTOffsets[i] = 0; |
| 4460 | continue; |
| 4461 | } else if (SourceVecs[i].getValueType().getVectorNumElements() < NumElts) { |
| 4462 | // It probably isn't worth padding out a smaller vector just to |
| 4463 | // break it down again in a shuffle. |
| 4464 | return SDValue(); |
| 4465 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4466 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4467 | // Since only 64-bit and 128-bit vectors are legal on ARM and |
| 4468 | // we've eliminated the other cases... |
Bob Wilson | 70f8573 | 2011-01-07 23:40:46 +0000 | [diff] [blame] | 4469 | assert(SourceVecs[i].getValueType().getVectorNumElements() == 2*NumElts && |
| 4470 | "unexpected vector sizes in ReconstructShuffle"); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4471 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4472 | if (MaxElts[i] - MinElts[i] >= NumElts) { |
| 4473 | // Span too large for a VEXT to cope |
| 4474 | return SDValue(); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4475 | } |
| 4476 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4477 | if (MinElts[i] >= NumElts) { |
| 4478 | // The extraction can just take the second half |
| 4479 | VEXTOffsets[i] = NumElts; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4480 | ShuffleSrcs[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4481 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4482 | DAG.getIntPtrConstant(NumElts)); |
| 4483 | } else if (MaxElts[i] < NumElts) { |
| 4484 | // The extraction can just take the first half |
| 4485 | VEXTOffsets[i] = 0; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4486 | ShuffleSrcs[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4487 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4488 | DAG.getIntPtrConstant(0)); |
| 4489 | } else { |
| 4490 | // An actual VEXT is needed |
| 4491 | VEXTOffsets[i] = MinElts[i]; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4492 | SDValue VEXTSrc1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4493 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4494 | DAG.getIntPtrConstant(0)); |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4495 | SDValue VEXTSrc2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4496 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4497 | DAG.getIntPtrConstant(NumElts)); |
| 4498 | ShuffleSrcs[i] = DAG.getNode(ARMISD::VEXT, dl, VT, VEXTSrc1, VEXTSrc2, |
| 4499 | DAG.getConstant(VEXTOffsets[i], MVT::i32)); |
| 4500 | } |
| 4501 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4502 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4503 | SmallVector<int, 8> Mask; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4504 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4505 | for (unsigned i = 0; i < NumElts; ++i) { |
| 4506 | SDValue Entry = Op.getOperand(i); |
| 4507 | if (Entry.getOpcode() == ISD::UNDEF) { |
| 4508 | Mask.push_back(-1); |
| 4509 | continue; |
| 4510 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4511 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4512 | SDValue ExtractVec = Entry.getOperand(0); |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4513 | int ExtractElt = cast<ConstantSDNode>(Op.getOperand(i) |
| 4514 | .getOperand(1))->getSExtValue(); |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4515 | if (ExtractVec == SourceVecs[0]) { |
| 4516 | Mask.push_back(ExtractElt - VEXTOffsets[0]); |
| 4517 | } else { |
| 4518 | Mask.push_back(ExtractElt + NumElts - VEXTOffsets[1]); |
| 4519 | } |
| 4520 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4521 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4522 | // Final check before we try to produce nonsense... |
| 4523 | if (isShuffleMaskLegal(Mask, VT)) |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4524 | return DAG.getVectorShuffle(VT, dl, ShuffleSrcs[0], ShuffleSrcs[1], |
| 4525 | &Mask[0]); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4526 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4527 | return SDValue(); |
| 4528 | } |
| 4529 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4530 | /// isShuffleMaskLegal - Targets can use this to indicate that they only |
| 4531 | /// support *some* VECTOR_SHUFFLE operations, those with specific masks. |
| 4532 | /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values |
| 4533 | /// are assumed to be legal. |
| 4534 | bool |
| 4535 | ARMTargetLowering::isShuffleMaskLegal(const SmallVectorImpl<int> &M, |
| 4536 | EVT VT) const { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4537 | if (VT.getVectorNumElements() == 4 && |
| 4538 | (VT.is128BitVector() || VT.is64BitVector())) { |
| 4539 | unsigned PFIndexes[4]; |
| 4540 | for (unsigned i = 0; i != 4; ++i) { |
| 4541 | if (M[i] < 0) |
| 4542 | PFIndexes[i] = 8; |
| 4543 | else |
| 4544 | PFIndexes[i] = M[i]; |
| 4545 | } |
| 4546 | |
| 4547 | // Compute the index in the perfect shuffle table. |
| 4548 | unsigned PFTableIndex = |
| 4549 | PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3]; |
| 4550 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 4551 | unsigned Cost = (PFEntry >> 30); |
| 4552 | |
| 4553 | if (Cost <= 4) |
| 4554 | return true; |
| 4555 | } |
| 4556 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4557 | bool ReverseVEXT; |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4558 | unsigned Imm, WhichResult; |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4559 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4560 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4561 | return (EltSize >= 32 || |
| 4562 | ShuffleVectorSDNode::isSplatMask(&M[0], VT) || |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4563 | isVREVMask(M, VT, 64) || |
| 4564 | isVREVMask(M, VT, 32) || |
| 4565 | isVREVMask(M, VT, 16) || |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4566 | isVEXTMask(M, VT, ReverseVEXT, Imm) || |
Bill Wendling | 0d4c9d9 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 4567 | isVTBLMask(M, VT) || |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4568 | isVTRNMask(M, VT, WhichResult) || |
| 4569 | isVUZPMask(M, VT, WhichResult) || |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4570 | isVZIPMask(M, VT, WhichResult) || |
| 4571 | isVTRN_v_undef_Mask(M, VT, WhichResult) || |
| 4572 | isVUZP_v_undef_Mask(M, VT, WhichResult) || |
| 4573 | isVZIP_v_undef_Mask(M, VT, WhichResult)); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4574 | } |
| 4575 | |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4576 | /// GeneratePerfectShuffle - Given an entry in the perfect-shuffle table, emit |
| 4577 | /// the specified operations to build the shuffle. |
| 4578 | static SDValue GeneratePerfectShuffle(unsigned PFEntry, SDValue LHS, |
| 4579 | SDValue RHS, SelectionDAG &DAG, |
| 4580 | DebugLoc dl) { |
| 4581 | unsigned OpNum = (PFEntry >> 26) & 0x0F; |
| 4582 | unsigned LHSID = (PFEntry >> 13) & ((1 << 13)-1); |
| 4583 | unsigned RHSID = (PFEntry >> 0) & ((1 << 13)-1); |
| 4584 | |
| 4585 | enum { |
| 4586 | OP_COPY = 0, // Copy, used for things like <u,u,u,3> to say it is <0,1,2,3> |
| 4587 | OP_VREV, |
| 4588 | OP_VDUP0, |
| 4589 | OP_VDUP1, |
| 4590 | OP_VDUP2, |
| 4591 | OP_VDUP3, |
| 4592 | OP_VEXT1, |
| 4593 | OP_VEXT2, |
| 4594 | OP_VEXT3, |
| 4595 | OP_VUZPL, // VUZP, left result |
| 4596 | OP_VUZPR, // VUZP, right result |
| 4597 | OP_VZIPL, // VZIP, left result |
| 4598 | OP_VZIPR, // VZIP, right result |
| 4599 | OP_VTRNL, // VTRN, left result |
| 4600 | OP_VTRNR // VTRN, right result |
| 4601 | }; |
| 4602 | |
| 4603 | if (OpNum == OP_COPY) { |
| 4604 | if (LHSID == (1*9+2)*9+3) return LHS; |
| 4605 | assert(LHSID == ((4*9+5)*9+6)*9+7 && "Illegal OP_COPY!"); |
| 4606 | return RHS; |
| 4607 | } |
| 4608 | |
| 4609 | SDValue OpLHS, OpRHS; |
| 4610 | OpLHS = GeneratePerfectShuffle(PerfectShuffleTable[LHSID], LHS, RHS, DAG, dl); |
| 4611 | OpRHS = GeneratePerfectShuffle(PerfectShuffleTable[RHSID], LHS, RHS, DAG, dl); |
| 4612 | EVT VT = OpLHS.getValueType(); |
| 4613 | |
| 4614 | switch (OpNum) { |
| 4615 | default: llvm_unreachable("Unknown shuffle opcode!"); |
| 4616 | case OP_VREV: |
Tanya Lattner | 2a8eb72 | 2011-05-18 06:42:21 +0000 | [diff] [blame] | 4617 | // VREV divides the vector in half and swaps within the half. |
Tanya Lattner | db28247 | 2011-05-18 21:44:54 +0000 | [diff] [blame] | 4618 | if (VT.getVectorElementType() == MVT::i32 || |
| 4619 | VT.getVectorElementType() == MVT::f32) |
Tanya Lattner | 2a8eb72 | 2011-05-18 06:42:21 +0000 | [diff] [blame] | 4620 | return DAG.getNode(ARMISD::VREV64, dl, VT, OpLHS); |
| 4621 | // vrev <4 x i16> -> VREV32 |
| 4622 | if (VT.getVectorElementType() == MVT::i16) |
| 4623 | return DAG.getNode(ARMISD::VREV32, dl, VT, OpLHS); |
| 4624 | // vrev <4 x i8> -> VREV16 |
| 4625 | assert(VT.getVectorElementType() == MVT::i8); |
| 4626 | return DAG.getNode(ARMISD::VREV16, dl, VT, OpLHS); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4627 | case OP_VDUP0: |
| 4628 | case OP_VDUP1: |
| 4629 | case OP_VDUP2: |
| 4630 | case OP_VDUP3: |
| 4631 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4632 | OpLHS, DAG.getConstant(OpNum-OP_VDUP0, MVT::i32)); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4633 | case OP_VEXT1: |
| 4634 | case OP_VEXT2: |
| 4635 | case OP_VEXT3: |
| 4636 | return DAG.getNode(ARMISD::VEXT, dl, VT, |
| 4637 | OpLHS, OpRHS, |
| 4638 | DAG.getConstant(OpNum-OP_VEXT1+1, MVT::i32)); |
| 4639 | case OP_VUZPL: |
| 4640 | case OP_VUZPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4641 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4642 | OpLHS, OpRHS).getValue(OpNum-OP_VUZPL); |
| 4643 | case OP_VZIPL: |
| 4644 | case OP_VZIPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4645 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4646 | OpLHS, OpRHS).getValue(OpNum-OP_VZIPL); |
| 4647 | case OP_VTRNL: |
| 4648 | case OP_VTRNR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4649 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4650 | OpLHS, OpRHS).getValue(OpNum-OP_VTRNL); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4651 | } |
| 4652 | } |
| 4653 | |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4654 | static SDValue LowerVECTOR_SHUFFLEv8i8(SDValue Op, |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4655 | ArrayRef<int> ShuffleMask, |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4656 | SelectionDAG &DAG) { |
| 4657 | // Check to see if we can use the VTBL instruction. |
| 4658 | SDValue V1 = Op.getOperand(0); |
| 4659 | SDValue V2 = Op.getOperand(1); |
| 4660 | DebugLoc DL = Op.getDebugLoc(); |
| 4661 | |
| 4662 | SmallVector<SDValue, 8> VTBLMask; |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4663 | for (ArrayRef<int>::iterator |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4664 | I = ShuffleMask.begin(), E = ShuffleMask.end(); I != E; ++I) |
| 4665 | VTBLMask.push_back(DAG.getConstant(*I, MVT::i32)); |
| 4666 | |
| 4667 | if (V2.getNode()->getOpcode() == ISD::UNDEF) |
| 4668 | return DAG.getNode(ARMISD::VTBL1, DL, MVT::v8i8, V1, |
| 4669 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, |
| 4670 | &VTBLMask[0], 8)); |
Bill Wendling | a24cb40 | 2011-03-15 20:47:26 +0000 | [diff] [blame] | 4671 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4672 | return DAG.getNode(ARMISD::VTBL2, DL, MVT::v8i8, V1, V2, |
Bill Wendling | a24cb40 | 2011-03-15 20:47:26 +0000 | [diff] [blame] | 4673 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, |
| 4674 | &VTBLMask[0], 8)); |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4675 | } |
| 4676 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4677 | static SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4678 | SDValue V1 = Op.getOperand(0); |
| 4679 | SDValue V2 = Op.getOperand(1); |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4680 | DebugLoc dl = Op.getDebugLoc(); |
| 4681 | EVT VT = Op.getValueType(); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4682 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op.getNode()); |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4683 | |
Bob Wilson | 2886506 | 2009-08-13 02:13:04 +0000 | [diff] [blame] | 4684 | // Convert shuffles that are directly supported on NEON to target-specific |
| 4685 | // DAG nodes, instead of keeping them as shuffles and matching them again |
| 4686 | // during code selection. This is more efficient and avoids the possibility |
| 4687 | // of inconsistencies between legalization and selection. |
Bob Wilson | bfcbb50 | 2009-08-13 06:01:30 +0000 | [diff] [blame] | 4688 | // FIXME: floating-point vectors should be canonicalized to integer vectors |
| 4689 | // of the same time so that they get CSEd properly. |
Benjamin Kramer | ed4c8c6 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4690 | ArrayRef<int> ShuffleMask = SVN->getMask(); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4691 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4692 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4693 | if (EltSize <= 32) { |
| 4694 | if (ShuffleVectorSDNode::isSplatMask(&ShuffleMask[0], VT)) { |
| 4695 | int Lane = SVN->getSplatIndex(); |
| 4696 | // If this is undef splat, generate it via "just" vdup, if possible. |
| 4697 | if (Lane == -1) Lane = 0; |
Anton Korobeynikov | 2ae0eec | 2009-11-02 00:12:06 +0000 | [diff] [blame] | 4698 | |
Dan Gohman | 65fd656 | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 4699 | // Test if V1 is a SCALAR_TO_VECTOR. |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4700 | if (Lane == 0 && V1.getOpcode() == ISD::SCALAR_TO_VECTOR) { |
| 4701 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); |
| 4702 | } |
Dan Gohman | 65fd656 | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 4703 | // Test if V1 is a BUILD_VECTOR which is equivalent to a SCALAR_TO_VECTOR |
| 4704 | // (and probably will turn into a SCALAR_TO_VECTOR once legalization |
| 4705 | // reaches it). |
| 4706 | if (Lane == 0 && V1.getOpcode() == ISD::BUILD_VECTOR && |
| 4707 | !isa<ConstantSDNode>(V1.getOperand(0))) { |
| 4708 | bool IsScalarToVector = true; |
| 4709 | for (unsigned i = 1, e = V1.getNumOperands(); i != e; ++i) |
| 4710 | if (V1.getOperand(i).getOpcode() != ISD::UNDEF) { |
| 4711 | IsScalarToVector = false; |
| 4712 | break; |
| 4713 | } |
| 4714 | if (IsScalarToVector) |
| 4715 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); |
| 4716 | } |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4717 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, V1, |
| 4718 | DAG.getConstant(Lane, MVT::i32)); |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 4719 | } |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4720 | |
| 4721 | bool ReverseVEXT; |
| 4722 | unsigned Imm; |
| 4723 | if (isVEXTMask(ShuffleMask, VT, ReverseVEXT, Imm)) { |
| 4724 | if (ReverseVEXT) |
| 4725 | std::swap(V1, V2); |
| 4726 | return DAG.getNode(ARMISD::VEXT, dl, VT, V1, V2, |
| 4727 | DAG.getConstant(Imm, MVT::i32)); |
| 4728 | } |
| 4729 | |
| 4730 | if (isVREVMask(ShuffleMask, VT, 64)) |
| 4731 | return DAG.getNode(ARMISD::VREV64, dl, VT, V1); |
| 4732 | if (isVREVMask(ShuffleMask, VT, 32)) |
| 4733 | return DAG.getNode(ARMISD::VREV32, dl, VT, V1); |
| 4734 | if (isVREVMask(ShuffleMask, VT, 16)) |
| 4735 | return DAG.getNode(ARMISD::VREV16, dl, VT, V1); |
| 4736 | |
Quentin Colombet | 43934ae | 2012-11-02 21:32:17 +0000 | [diff] [blame] | 4737 | if (V2->getOpcode() == ISD::UNDEF && |
| 4738 | isSingletonVEXTMask(ShuffleMask, VT, Imm)) { |
| 4739 | return DAG.getNode(ARMISD::VEXT, dl, VT, V1, V1, |
| 4740 | DAG.getConstant(Imm, MVT::i32)); |
| 4741 | } |
| 4742 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4743 | // Check for Neon shuffles that modify both input vectors in place. |
| 4744 | // If both results are used, i.e., if there are two shuffles with the same |
| 4745 | // source operands and with masks corresponding to both results of one of |
| 4746 | // these operations, DAG memoization will ensure that a single node is |
| 4747 | // used for both shuffles. |
| 4748 | unsigned WhichResult; |
| 4749 | if (isVTRNMask(ShuffleMask, VT, WhichResult)) |
| 4750 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4751 | V1, V2).getValue(WhichResult); |
| 4752 | if (isVUZPMask(ShuffleMask, VT, WhichResult)) |
| 4753 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 4754 | V1, V2).getValue(WhichResult); |
| 4755 | if (isVZIPMask(ShuffleMask, VT, WhichResult)) |
| 4756 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 4757 | V1, V2).getValue(WhichResult); |
| 4758 | |
| 4759 | if (isVTRN_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4760 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4761 | V1, V1).getValue(WhichResult); |
| 4762 | if (isVUZP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4763 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 4764 | V1, V1).getValue(WhichResult); |
| 4765 | if (isVZIP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4766 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 4767 | V1, V1).getValue(WhichResult); |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 4768 | } |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4769 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4770 | // If the shuffle is not directly supported and it has 4 elements, use |
| 4771 | // the PerfectShuffle-generated table to synthesize it from other shuffles. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4772 | unsigned NumElts = VT.getVectorNumElements(); |
| 4773 | if (NumElts == 4) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4774 | unsigned PFIndexes[4]; |
| 4775 | for (unsigned i = 0; i != 4; ++i) { |
| 4776 | if (ShuffleMask[i] < 0) |
| 4777 | PFIndexes[i] = 8; |
| 4778 | else |
| 4779 | PFIndexes[i] = ShuffleMask[i]; |
| 4780 | } |
| 4781 | |
| 4782 | // Compute the index in the perfect shuffle table. |
| 4783 | unsigned PFTableIndex = |
| 4784 | 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] | 4785 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 4786 | unsigned Cost = (PFEntry >> 30); |
| 4787 | |
| 4788 | if (Cost <= 4) |
| 4789 | return GeneratePerfectShuffle(PFEntry, V1, V2, DAG, dl); |
| 4790 | } |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4791 | |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4792 | // Implement shuffles with 32- or 64-bit elements as ARMISD::BUILD_VECTORs. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4793 | if (EltSize >= 32) { |
| 4794 | // Do the expansion with floating-point types, since that is what the VFP |
| 4795 | // registers are defined to use, and since i64 is not legal. |
| 4796 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 4797 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4798 | V1 = DAG.getNode(ISD::BITCAST, dl, VecVT, V1); |
| 4799 | V2 = DAG.getNode(ISD::BITCAST, dl, VecVT, V2); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4800 | SmallVector<SDValue, 8> Ops; |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4801 | for (unsigned i = 0; i < NumElts; ++i) { |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4802 | if (ShuffleMask[i] < 0) |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4803 | Ops.push_back(DAG.getUNDEF(EltVT)); |
| 4804 | else |
| 4805 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, |
| 4806 | ShuffleMask[i] < (int)NumElts ? V1 : V2, |
| 4807 | DAG.getConstant(ShuffleMask[i] & (NumElts-1), |
| 4808 | MVT::i32))); |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4809 | } |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4810 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, &Ops[0],NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4811 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4812 | } |
| 4813 | |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4814 | if (VT == MVT::v8i8) { |
| 4815 | SDValue NewOp = LowerVECTOR_SHUFFLEv8i8(Op, ShuffleMask, DAG); |
| 4816 | if (NewOp.getNode()) |
| 4817 | return NewOp; |
| 4818 | } |
| 4819 | |
Bob Wilson | 22cac0d | 2009-08-14 05:16:33 +0000 | [diff] [blame] | 4820 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4821 | } |
| 4822 | |
Eli Friedman | 5c89cb8 | 2011-10-24 23:08:52 +0000 | [diff] [blame] | 4823 | static SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
| 4824 | // INSERT_VECTOR_ELT is legal only for immediate indexes. |
| 4825 | SDValue Lane = Op.getOperand(2); |
| 4826 | if (!isa<ConstantSDNode>(Lane)) |
| 4827 | return SDValue(); |
| 4828 | |
| 4829 | return Op; |
| 4830 | } |
| 4831 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4832 | static SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 4833 | // EXTRACT_VECTOR_ELT is legal only for immediate indexes. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4834 | SDValue Lane = Op.getOperand(1); |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 4835 | if (!isa<ConstantSDNode>(Lane)) |
| 4836 | return SDValue(); |
| 4837 | |
| 4838 | SDValue Vec = Op.getOperand(0); |
| 4839 | if (Op.getValueType() == MVT::i32 && |
| 4840 | Vec.getValueType().getVectorElementType().getSizeInBits() < 32) { |
| 4841 | DebugLoc dl = Op.getDebugLoc(); |
| 4842 | return DAG.getNode(ARMISD::VGETLANEu, dl, MVT::i32, Vec, Lane); |
| 4843 | } |
| 4844 | |
| 4845 | return Op; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4846 | } |
| 4847 | |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4848 | static SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) { |
| 4849 | // The only time a CONCAT_VECTORS operation can have legal types is when |
| 4850 | // two 64-bit vectors are concatenated to a 128-bit vector. |
| 4851 | assert(Op.getValueType().is128BitVector() && Op.getNumOperands() == 2 && |
| 4852 | "unexpected CONCAT_VECTORS"); |
| 4853 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4854 | SDValue Val = DAG.getUNDEF(MVT::v2f64); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4855 | SDValue Op0 = Op.getOperand(0); |
| 4856 | SDValue Op1 = Op.getOperand(1); |
| 4857 | if (Op0.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4858 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4859 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op0), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4860 | DAG.getIntPtrConstant(0)); |
| 4861 | if (Op1.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4862 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4863 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op1), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4864 | DAG.getIntPtrConstant(1)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4865 | return DAG.getNode(ISD::BITCAST, dl, Op.getValueType(), Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4866 | } |
| 4867 | |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4868 | /// isExtendedBUILD_VECTOR - Check if N is a constant BUILD_VECTOR where each |
| 4869 | /// element has been zero/sign-extended, depending on the isSigned parameter, |
| 4870 | /// from an integer type half its size. |
| 4871 | static bool isExtendedBUILD_VECTOR(SDNode *N, SelectionDAG &DAG, |
| 4872 | bool isSigned) { |
| 4873 | // A v2i64 BUILD_VECTOR will have been legalized to a BITCAST from v4i32. |
| 4874 | EVT VT = N->getValueType(0); |
| 4875 | if (VT == MVT::v2i64 && N->getOpcode() == ISD::BITCAST) { |
| 4876 | SDNode *BVN = N->getOperand(0).getNode(); |
| 4877 | if (BVN->getValueType(0) != MVT::v4i32 || |
| 4878 | BVN->getOpcode() != ISD::BUILD_VECTOR) |
| 4879 | return false; |
| 4880 | unsigned LoElt = DAG.getTargetLoweringInfo().isBigEndian() ? 1 : 0; |
| 4881 | unsigned HiElt = 1 - LoElt; |
| 4882 | ConstantSDNode *Lo0 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt)); |
| 4883 | ConstantSDNode *Hi0 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt)); |
| 4884 | ConstantSDNode *Lo1 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt+2)); |
| 4885 | ConstantSDNode *Hi1 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt+2)); |
| 4886 | if (!Lo0 || !Hi0 || !Lo1 || !Hi1) |
| 4887 | return false; |
| 4888 | if (isSigned) { |
| 4889 | if (Hi0->getSExtValue() == Lo0->getSExtValue() >> 32 && |
| 4890 | Hi1->getSExtValue() == Lo1->getSExtValue() >> 32) |
| 4891 | return true; |
| 4892 | } else { |
| 4893 | if (Hi0->isNullValue() && Hi1->isNullValue()) |
| 4894 | return true; |
| 4895 | } |
| 4896 | return false; |
| 4897 | } |
| 4898 | |
| 4899 | if (N->getOpcode() != ISD::BUILD_VECTOR) |
| 4900 | return false; |
| 4901 | |
| 4902 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
| 4903 | SDNode *Elt = N->getOperand(i).getNode(); |
| 4904 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Elt)) { |
| 4905 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4906 | unsigned HalfSize = EltSize / 2; |
| 4907 | if (isSigned) { |
Bob Wilson | 9d45de2 | 2011-10-18 18:46:49 +0000 | [diff] [blame] | 4908 | if (!isIntN(HalfSize, C->getSExtValue())) |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4909 | return false; |
| 4910 | } else { |
Bob Wilson | 9d45de2 | 2011-10-18 18:46:49 +0000 | [diff] [blame] | 4911 | if (!isUIntN(HalfSize, C->getZExtValue())) |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4912 | return false; |
| 4913 | } |
| 4914 | continue; |
| 4915 | } |
| 4916 | return false; |
| 4917 | } |
| 4918 | |
| 4919 | return true; |
| 4920 | } |
| 4921 | |
| 4922 | /// isSignExtended - Check if a node is a vector value that is sign-extended |
| 4923 | /// or a constant BUILD_VECTOR with sign-extended elements. |
| 4924 | static bool isSignExtended(SDNode *N, SelectionDAG &DAG) { |
| 4925 | if (N->getOpcode() == ISD::SIGN_EXTEND || ISD::isSEXTLoad(N)) |
| 4926 | return true; |
| 4927 | if (isExtendedBUILD_VECTOR(N, DAG, true)) |
| 4928 | return true; |
| 4929 | return false; |
| 4930 | } |
| 4931 | |
| 4932 | /// isZeroExtended - Check if a node is a vector value that is zero-extended |
| 4933 | /// or a constant BUILD_VECTOR with zero-extended elements. |
| 4934 | static bool isZeroExtended(SDNode *N, SelectionDAG &DAG) { |
| 4935 | if (N->getOpcode() == ISD::ZERO_EXTEND || ISD::isZEXTLoad(N)) |
| 4936 | return true; |
| 4937 | if (isExtendedBUILD_VECTOR(N, DAG, false)) |
| 4938 | return true; |
| 4939 | return false; |
| 4940 | } |
| 4941 | |
Sebastian Pop | cb49530 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 4942 | /// AddRequiredExtensionForVMULL - Add a sign/zero extension to extend the total |
| 4943 | /// value size to 64 bits. We need a 64-bit D register as an operand to VMULL. |
| 4944 | /// We insert the required extension here to get the vector to fill a D register. |
| 4945 | static SDValue AddRequiredExtensionForVMULL(SDValue N, SelectionDAG &DAG, |
| 4946 | const EVT &OrigTy, |
| 4947 | const EVT &ExtTy, |
| 4948 | unsigned ExtOpcode) { |
| 4949 | // The vector originally had a size of OrigTy. It was then extended to ExtTy. |
| 4950 | // We expect the ExtTy to be 128-bits total. If the OrigTy is less than |
| 4951 | // 64-bits we need to insert a new extension so that it will be 64-bits. |
| 4952 | assert(ExtTy.is128BitVector() && "Unexpected extension size"); |
| 4953 | if (OrigTy.getSizeInBits() >= 64) |
| 4954 | return N; |
| 4955 | |
| 4956 | // Must extend size to at least 64 bits to be used as an operand for VMULL. |
| 4957 | MVT::SimpleValueType OrigSimpleTy = OrigTy.getSimpleVT().SimpleTy; |
| 4958 | EVT NewVT; |
| 4959 | switch (OrigSimpleTy) { |
| 4960 | default: llvm_unreachable("Unexpected Orig Vector Type"); |
| 4961 | case MVT::v2i8: |
| 4962 | case MVT::v2i16: |
| 4963 | NewVT = MVT::v2i32; |
| 4964 | break; |
| 4965 | case MVT::v4i8: |
| 4966 | NewVT = MVT::v4i16; |
| 4967 | break; |
| 4968 | } |
| 4969 | return DAG.getNode(ExtOpcode, N->getDebugLoc(), NewVT, N); |
| 4970 | } |
| 4971 | |
| 4972 | /// SkipLoadExtensionForVMULL - return a load of the original vector size that |
| 4973 | /// does not do any sign/zero extension. If the original vector is less |
| 4974 | /// than 64 bits, an appropriate extension will be added after the load to |
| 4975 | /// reach a total size of 64 bits. We have to add the extension separately |
| 4976 | /// because ARM does not have a sign/zero extending load for vectors. |
| 4977 | static SDValue SkipLoadExtensionForVMULL(LoadSDNode *LD, SelectionDAG& DAG) { |
| 4978 | SDValue NonExtendingLoad = |
| 4979 | DAG.getLoad(LD->getMemoryVT(), LD->getDebugLoc(), LD->getChain(), |
| 4980 | LD->getBasePtr(), LD->getPointerInfo(), LD->isVolatile(), |
| 4981 | LD->isNonTemporal(), LD->isInvariant(), |
| 4982 | LD->getAlignment()); |
| 4983 | unsigned ExtOp = 0; |
| 4984 | switch (LD->getExtensionType()) { |
| 4985 | default: llvm_unreachable("Unexpected LoadExtType"); |
| 4986 | case ISD::EXTLOAD: |
| 4987 | case ISD::SEXTLOAD: ExtOp = ISD::SIGN_EXTEND; break; |
| 4988 | case ISD::ZEXTLOAD: ExtOp = ISD::ZERO_EXTEND; break; |
| 4989 | } |
| 4990 | MVT::SimpleValueType MemType = LD->getMemoryVT().getSimpleVT().SimpleTy; |
| 4991 | MVT::SimpleValueType ExtType = LD->getValueType(0).getSimpleVT().SimpleTy; |
| 4992 | return AddRequiredExtensionForVMULL(NonExtendingLoad, DAG, |
| 4993 | MemType, ExtType, ExtOp); |
| 4994 | } |
| 4995 | |
| 4996 | /// SkipExtensionForVMULL - For a node that is a SIGN_EXTEND, ZERO_EXTEND, |
| 4997 | /// extending load, or BUILD_VECTOR with extended elements, return the |
| 4998 | /// unextended value. The unextended vector should be 64 bits so that it can |
| 4999 | /// be used as an operand to a VMULL instruction. If the original vector size |
| 5000 | /// before extension is less than 64 bits we add a an extension to resize |
| 5001 | /// the vector to 64 bits. |
| 5002 | static SDValue SkipExtensionForVMULL(SDNode *N, SelectionDAG &DAG) { |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5003 | if (N->getOpcode() == ISD::SIGN_EXTEND || N->getOpcode() == ISD::ZERO_EXTEND) |
Sebastian Pop | cb49530 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5004 | return AddRequiredExtensionForVMULL(N->getOperand(0), DAG, |
| 5005 | N->getOperand(0)->getValueType(0), |
| 5006 | N->getValueType(0), |
| 5007 | N->getOpcode()); |
| 5008 | |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 5009 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) |
Sebastian Pop | cb49530 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5010 | return SkipLoadExtensionForVMULL(LD, DAG); |
| 5011 | |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 5012 | // Otherwise, the value must be a BUILD_VECTOR. For v2i64, it will |
| 5013 | // have been legalized as a BITCAST from v4i32. |
| 5014 | if (N->getOpcode() == ISD::BITCAST) { |
| 5015 | SDNode *BVN = N->getOperand(0).getNode(); |
| 5016 | assert(BVN->getOpcode() == ISD::BUILD_VECTOR && |
| 5017 | BVN->getValueType(0) == MVT::v4i32 && "expected v4i32 BUILD_VECTOR"); |
| 5018 | unsigned LowElt = DAG.getTargetLoweringInfo().isBigEndian() ? 1 : 0; |
| 5019 | return DAG.getNode(ISD::BUILD_VECTOR, N->getDebugLoc(), MVT::v2i32, |
| 5020 | BVN->getOperand(LowElt), BVN->getOperand(LowElt+2)); |
| 5021 | } |
| 5022 | // Construct a new BUILD_VECTOR with elements truncated to half the size. |
| 5023 | assert(N->getOpcode() == ISD::BUILD_VECTOR && "expected BUILD_VECTOR"); |
| 5024 | EVT VT = N->getValueType(0); |
| 5025 | unsigned EltSize = VT.getVectorElementType().getSizeInBits() / 2; |
| 5026 | unsigned NumElts = VT.getVectorNumElements(); |
| 5027 | MVT TruncVT = MVT::getIntegerVT(EltSize); |
| 5028 | SmallVector<SDValue, 8> Ops; |
| 5029 | for (unsigned i = 0; i != NumElts; ++i) { |
| 5030 | ConstantSDNode *C = cast<ConstantSDNode>(N->getOperand(i)); |
| 5031 | const APInt &CInt = C->getAPIntValue(); |
Bob Wilson | ff73d8f | 2012-04-30 16:53:34 +0000 | [diff] [blame] | 5032 | // Element types smaller than 32 bits are not legal, so use i32 elements. |
| 5033 | // The values are implicitly truncated so sext vs. zext doesn't matter. |
| 5034 | Ops.push_back(DAG.getConstant(CInt.zextOrTrunc(32), MVT::i32)); |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 5035 | } |
| 5036 | return DAG.getNode(ISD::BUILD_VECTOR, N->getDebugLoc(), |
| 5037 | MVT::getVectorVT(TruncVT, NumElts), Ops.data(), NumElts); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5038 | } |
| 5039 | |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5040 | static bool isAddSubSExt(SDNode *N, SelectionDAG &DAG) { |
| 5041 | unsigned Opcode = N->getOpcode(); |
| 5042 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { |
| 5043 | SDNode *N0 = N->getOperand(0).getNode(); |
| 5044 | SDNode *N1 = N->getOperand(1).getNode(); |
| 5045 | return N0->hasOneUse() && N1->hasOneUse() && |
| 5046 | isSignExtended(N0, DAG) && isSignExtended(N1, DAG); |
| 5047 | } |
| 5048 | return false; |
| 5049 | } |
| 5050 | |
| 5051 | static bool isAddSubZExt(SDNode *N, SelectionDAG &DAG) { |
| 5052 | unsigned Opcode = N->getOpcode(); |
| 5053 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { |
| 5054 | SDNode *N0 = N->getOperand(0).getNode(); |
| 5055 | SDNode *N1 = N->getOperand(1).getNode(); |
| 5056 | return N0->hasOneUse() && N1->hasOneUse() && |
| 5057 | isZeroExtended(N0, DAG) && isZeroExtended(N1, DAG); |
| 5058 | } |
| 5059 | return false; |
| 5060 | } |
| 5061 | |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5062 | static SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) { |
| 5063 | // Multiplications are only custom-lowered for 128-bit vectors so that |
| 5064 | // VMULL can be detected. Otherwise v2i64 multiplications are not legal. |
| 5065 | EVT VT = Op.getValueType(); |
Sebastian Pop | cb49530 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5066 | assert(VT.is128BitVector() && VT.isInteger() && |
| 5067 | "unexpected type for custom-lowering ISD::MUL"); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5068 | SDNode *N0 = Op.getOperand(0).getNode(); |
| 5069 | SDNode *N1 = Op.getOperand(1).getNode(); |
| 5070 | unsigned NewOpc = 0; |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5071 | bool isMLA = false; |
| 5072 | bool isN0SExt = isSignExtended(N0, DAG); |
| 5073 | bool isN1SExt = isSignExtended(N1, DAG); |
| 5074 | if (isN0SExt && isN1SExt) |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5075 | NewOpc = ARMISD::VMULLs; |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5076 | else { |
| 5077 | bool isN0ZExt = isZeroExtended(N0, DAG); |
| 5078 | bool isN1ZExt = isZeroExtended(N1, DAG); |
| 5079 | if (isN0ZExt && isN1ZExt) |
| 5080 | NewOpc = ARMISD::VMULLu; |
| 5081 | else if (isN1SExt || isN1ZExt) { |
| 5082 | // Look for (s/zext A + s/zext B) * (s/zext C). We want to turn these |
| 5083 | // into (s/zext A * s/zext C) + (s/zext B * s/zext C) |
| 5084 | if (isN1SExt && isAddSubSExt(N0, DAG)) { |
| 5085 | NewOpc = ARMISD::VMULLs; |
| 5086 | isMLA = true; |
| 5087 | } else if (isN1ZExt && isAddSubZExt(N0, DAG)) { |
| 5088 | NewOpc = ARMISD::VMULLu; |
| 5089 | isMLA = true; |
| 5090 | } else if (isN0ZExt && isAddSubZExt(N1, DAG)) { |
| 5091 | std::swap(N0, N1); |
| 5092 | NewOpc = ARMISD::VMULLu; |
| 5093 | isMLA = true; |
| 5094 | } |
| 5095 | } |
| 5096 | |
| 5097 | if (!NewOpc) { |
| 5098 | if (VT == MVT::v2i64) |
| 5099 | // Fall through to expand this. It is not legal. |
| 5100 | return SDValue(); |
| 5101 | else |
| 5102 | // Other vector multiplications are legal. |
| 5103 | return Op; |
| 5104 | } |
| 5105 | } |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5106 | |
| 5107 | // Legalize to a VMULL instruction. |
| 5108 | DebugLoc DL = Op.getDebugLoc(); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5109 | SDValue Op0; |
Sebastian Pop | cb49530 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5110 | SDValue Op1 = SkipExtensionForVMULL(N1, DAG); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5111 | if (!isMLA) { |
Sebastian Pop | cb49530 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5112 | Op0 = SkipExtensionForVMULL(N0, DAG); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5113 | assert(Op0.getValueType().is64BitVector() && |
| 5114 | Op1.getValueType().is64BitVector() && |
| 5115 | "unexpected types for extended operands to VMULL"); |
| 5116 | return DAG.getNode(NewOpc, DL, VT, Op0, Op1); |
| 5117 | } |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5118 | |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5119 | // Optimizing (zext A + zext B) * C, to (VMULL A, C) + (VMULL B, C) during |
| 5120 | // isel lowering to take advantage of no-stall back to back vmul + vmla. |
| 5121 | // vmull q0, d4, d6 |
| 5122 | // vmlal q0, d5, d6 |
| 5123 | // is faster than |
| 5124 | // vaddl q0, d4, d5 |
| 5125 | // vmovl q1, d6 |
| 5126 | // vmul q0, q0, q1 |
Sebastian Pop | cb49530 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 5127 | SDValue N00 = SkipExtensionForVMULL(N0->getOperand(0).getNode(), DAG); |
| 5128 | SDValue N01 = SkipExtensionForVMULL(N0->getOperand(1).getNode(), DAG); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 5129 | EVT Op1VT = Op1.getValueType(); |
| 5130 | return DAG.getNode(N0->getOpcode(), DL, VT, |
| 5131 | DAG.getNode(NewOpc, DL, VT, |
| 5132 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N00), Op1), |
| 5133 | DAG.getNode(NewOpc, DL, VT, |
| 5134 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N01), Op1)); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5135 | } |
| 5136 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5137 | static SDValue |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5138 | LowerSDIV_v4i8(SDValue X, SDValue Y, DebugLoc dl, SelectionDAG &DAG) { |
| 5139 | // Convert to float |
| 5140 | // float4 xf = vcvt_f32_s32(vmovl_s16(a.lo)); |
| 5141 | // float4 yf = vcvt_f32_s32(vmovl_s16(b.lo)); |
| 5142 | X = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, X); |
| 5143 | Y = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, Y); |
| 5144 | X = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, X); |
| 5145 | Y = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, Y); |
| 5146 | // Get reciprocal estimate. |
| 5147 | // float4 recip = vrecpeq_f32(yf); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5148 | Y = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5149 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), Y); |
| 5150 | // Because char has a smaller range than uchar, we can actually get away |
| 5151 | // without any newton steps. This requires that we use a weird bias |
| 5152 | // of 0xb000, however (again, this has been exhaustively tested). |
| 5153 | // float4 result = as_float4(as_int4(xf*recip) + 0xb000); |
| 5154 | X = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, X, Y); |
| 5155 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, X); |
| 5156 | Y = DAG.getConstant(0xb000, MVT::i32); |
| 5157 | Y = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, Y, Y, Y, Y); |
| 5158 | X = DAG.getNode(ISD::ADD, dl, MVT::v4i32, X, Y); |
| 5159 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, X); |
| 5160 | // Convert back to short. |
| 5161 | X = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, X); |
| 5162 | X = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, X); |
| 5163 | return X; |
| 5164 | } |
| 5165 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5166 | static SDValue |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5167 | LowerSDIV_v4i16(SDValue N0, SDValue N1, DebugLoc dl, SelectionDAG &DAG) { |
| 5168 | SDValue N2; |
| 5169 | // Convert to float. |
| 5170 | // float4 yf = vcvt_f32_s32(vmovl_s16(y)); |
| 5171 | // float4 xf = vcvt_f32_s32(vmovl_s16(x)); |
| 5172 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N0); |
| 5173 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N1); |
| 5174 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); |
| 5175 | N1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5176 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5177 | // Use reciprocal estimate and one refinement step. |
| 5178 | // float4 recip = vrecpeq_f32(yf); |
| 5179 | // recip *= vrecpsq_f32(yf, recip); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5180 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5181 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5182 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5183 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
| 5184 | N1, N2); |
| 5185 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 5186 | // Because short has a smaller range than ushort, we can actually get away |
| 5187 | // with only a single newton step. This requires that we use a weird bias |
| 5188 | // of 89, however (again, this has been exhaustively tested). |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5189 | // float4 result = as_float4(as_int4(xf*recip) + 0x89); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5190 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
| 5191 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5192 | N1 = DAG.getConstant(0x89, MVT::i32); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5193 | N1 = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, N1, N1, N1, N1); |
| 5194 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); |
| 5195 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); |
| 5196 | // Convert back to integer and return. |
| 5197 | // return vmovn_s32(vcvt_s32_f32(result)); |
| 5198 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); |
| 5199 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); |
| 5200 | return N0; |
| 5201 | } |
| 5202 | |
| 5203 | static SDValue LowerSDIV(SDValue Op, SelectionDAG &DAG) { |
| 5204 | EVT VT = Op.getValueType(); |
| 5205 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && |
| 5206 | "unexpected type for custom-lowering ISD::SDIV"); |
| 5207 | |
| 5208 | DebugLoc dl = Op.getDebugLoc(); |
| 5209 | SDValue N0 = Op.getOperand(0); |
| 5210 | SDValue N1 = Op.getOperand(1); |
| 5211 | SDValue N2, N3; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5212 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5213 | if (VT == MVT::v8i8) { |
| 5214 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N0); |
| 5215 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5216 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5217 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 5218 | DAG.getIntPtrConstant(4)); |
| 5219 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5220 | DAG.getIntPtrConstant(4)); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5221 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 5222 | DAG.getIntPtrConstant(0)); |
| 5223 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| 5224 | DAG.getIntPtrConstant(0)); |
| 5225 | |
| 5226 | N0 = LowerSDIV_v4i8(N0, N1, dl, DAG); // v4i16 |
| 5227 | N2 = LowerSDIV_v4i8(N2, N3, dl, DAG); // v4i16 |
| 5228 | |
| 5229 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
| 5230 | N0 = LowerCONCAT_VECTORS(N0, DAG); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5231 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5232 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v8i8, N0); |
| 5233 | return N0; |
| 5234 | } |
| 5235 | return LowerSDIV_v4i16(N0, N1, dl, DAG); |
| 5236 | } |
| 5237 | |
| 5238 | static SDValue LowerUDIV(SDValue Op, SelectionDAG &DAG) { |
| 5239 | EVT VT = Op.getValueType(); |
| 5240 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && |
| 5241 | "unexpected type for custom-lowering ISD::UDIV"); |
| 5242 | |
| 5243 | DebugLoc dl = Op.getDebugLoc(); |
| 5244 | SDValue N0 = Op.getOperand(0); |
| 5245 | SDValue N1 = Op.getOperand(1); |
| 5246 | SDValue N2, N3; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5247 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5248 | if (VT == MVT::v8i8) { |
| 5249 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N0); |
| 5250 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5251 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5252 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 5253 | DAG.getIntPtrConstant(4)); |
| 5254 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5255 | DAG.getIntPtrConstant(4)); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5256 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 5257 | DAG.getIntPtrConstant(0)); |
| 5258 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| 5259 | DAG.getIntPtrConstant(0)); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5260 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5261 | N0 = LowerSDIV_v4i16(N0, N1, dl, DAG); // v4i16 |
| 5262 | N2 = LowerSDIV_v4i16(N2, N3, dl, DAG); // v4i16 |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5263 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5264 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
| 5265 | N0 = LowerCONCAT_VECTORS(N0, DAG); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5266 | |
| 5267 | N0 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v8i8, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5268 | DAG.getConstant(Intrinsic::arm_neon_vqmovnsu, MVT::i32), |
| 5269 | N0); |
| 5270 | return N0; |
| 5271 | } |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5272 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5273 | // v4i16 sdiv ... Convert to float. |
| 5274 | // float4 yf = vcvt_f32_s32(vmovl_u16(y)); |
| 5275 | // float4 xf = vcvt_f32_s32(vmovl_u16(x)); |
| 5276 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N0); |
| 5277 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N1); |
| 5278 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5279 | SDValue BN1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5280 | |
| 5281 | // Use reciprocal estimate and two refinement steps. |
| 5282 | // float4 recip = vrecpeq_f32(yf); |
| 5283 | // recip *= vrecpsq_f32(yf, recip); |
| 5284 | // recip *= vrecpsq_f32(yf, recip); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5285 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5286 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), BN1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5287 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5288 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5289 | BN1, N2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5290 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5291 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5292 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 5293 | BN1, N2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5294 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 5295 | // Simply multiplying by the reciprocal estimate can leave us a few ulps |
| 5296 | // too low, so we add 2 ulps (exhaustive testing shows that this is enough, |
| 5297 | // 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] | 5298 | // float4 result = as_float4(as_int4(xf*recip) + 2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5299 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
| 5300 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); |
| 5301 | N1 = DAG.getConstant(2, MVT::i32); |
| 5302 | N1 = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, N1, N1, N1, N1); |
| 5303 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); |
| 5304 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); |
| 5305 | // Convert back to integer and return. |
| 5306 | // return vmovn_u32(vcvt_s32_f32(result)); |
| 5307 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); |
| 5308 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); |
| 5309 | return N0; |
| 5310 | } |
| 5311 | |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 5312 | static SDValue LowerADDC_ADDE_SUBC_SUBE(SDValue Op, SelectionDAG &DAG) { |
| 5313 | EVT VT = Op.getNode()->getValueType(0); |
| 5314 | SDVTList VTs = DAG.getVTList(VT, MVT::i32); |
| 5315 | |
| 5316 | unsigned Opc; |
| 5317 | bool ExtraOp = false; |
| 5318 | switch (Op.getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 5319 | default: llvm_unreachable("Invalid code"); |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 5320 | case ISD::ADDC: Opc = ARMISD::ADDC; break; |
| 5321 | case ISD::ADDE: Opc = ARMISD::ADDE; ExtraOp = true; break; |
| 5322 | case ISD::SUBC: Opc = ARMISD::SUBC; break; |
| 5323 | case ISD::SUBE: Opc = ARMISD::SUBE; ExtraOp = true; break; |
| 5324 | } |
| 5325 | |
| 5326 | if (!ExtraOp) |
| 5327 | return DAG.getNode(Opc, Op->getDebugLoc(), VTs, Op.getOperand(0), |
| 5328 | Op.getOperand(1)); |
| 5329 | return DAG.getNode(Opc, Op->getDebugLoc(), VTs, Op.getOperand(0), |
| 5330 | Op.getOperand(1), Op.getOperand(2)); |
| 5331 | } |
| 5332 | |
Eli Friedman | 74bf18c | 2011-09-15 22:26:18 +0000 | [diff] [blame] | 5333 | static SDValue LowerAtomicLoadStore(SDValue Op, SelectionDAG &DAG) { |
Eli Friedman | 7cc1566 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 5334 | // Monotonic load/store is legal for all targets |
| 5335 | if (cast<AtomicSDNode>(Op)->getOrdering() <= Monotonic) |
| 5336 | return Op; |
| 5337 | |
| 5338 | // Aquire/Release load/store is not legal for targets without a |
| 5339 | // dmb or equivalent available. |
| 5340 | return SDValue(); |
| 5341 | } |
| 5342 | |
| 5343 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5344 | static void |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5345 | ReplaceATOMIC_OP_64(SDNode *Node, SmallVectorImpl<SDValue>& Results, |
| 5346 | SelectionDAG &DAG, unsigned NewOp) { |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5347 | DebugLoc dl = Node->getDebugLoc(); |
Duncan Sands | 17001ce | 2011-10-18 12:44:00 +0000 | [diff] [blame] | 5348 | assert (Node->getValueType(0) == MVT::i64 && |
| 5349 | "Only know how to expand i64 atomics"); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5350 | |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5351 | SmallVector<SDValue, 6> Ops; |
| 5352 | Ops.push_back(Node->getOperand(0)); // Chain |
| 5353 | Ops.push_back(Node->getOperand(1)); // Ptr |
| 5354 | // Low part of Val1 |
| 5355 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5356 | Node->getOperand(2), DAG.getIntPtrConstant(0))); |
| 5357 | // High part of Val1 |
| 5358 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5359 | Node->getOperand(2), DAG.getIntPtrConstant(1))); |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 5360 | if (NewOp == ARMISD::ATOMCMPXCHG64_DAG) { |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5361 | // High part of Val1 |
| 5362 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5363 | Node->getOperand(3), DAG.getIntPtrConstant(0))); |
| 5364 | // High part of Val2 |
| 5365 | Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, |
| 5366 | Node->getOperand(3), DAG.getIntPtrConstant(1))); |
| 5367 | } |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5368 | SDVTList Tys = DAG.getVTList(MVT::i32, MVT::i32, MVT::Other); |
| 5369 | SDValue Result = |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5370 | DAG.getMemIntrinsicNode(NewOp, dl, Tys, Ops.data(), Ops.size(), MVT::i64, |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5371 | cast<MemSDNode>(Node)->getMemOperand()); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5372 | SDValue OpsF[] = { Result.getValue(0), Result.getValue(1) }; |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5373 | Results.push_back(DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, OpsF, 2)); |
| 5374 | Results.push_back(Result.getValue(2)); |
| 5375 | } |
| 5376 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 5377 | SDValue ARMTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5378 | switch (Op.getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 5379 | default: llvm_unreachable("Don't know how to custom lower this!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5380 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 5381 | case ISD::BlockAddress: return LowerBlockAddress(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 5382 | case ISD::GlobalAddress: |
| 5383 | return Subtarget->isTargetDarwin() ? LowerGlobalAddressDarwin(Op, DAG) : |
| 5384 | LowerGlobalAddressELF(Op, DAG); |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 5385 | case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 5386 | case ISD::SELECT: return LowerSELECT(Op, DAG); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 5387 | case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG); |
| 5388 | case ISD::BR_CC: return LowerBR_CC(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5389 | case ISD::BR_JT: return LowerBR_JT(Op, DAG); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 5390 | case ISD::VASTART: return LowerVASTART(Op, DAG); |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 5391 | case ISD::MEMBARRIER: return LowerMEMBARRIER(Op, DAG, Subtarget); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 5392 | case ISD::ATOMIC_FENCE: return LowerATOMIC_FENCE(Op, DAG, Subtarget); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 5393 | case ISD::PREFETCH: return LowerPREFETCH(Op, DAG, Subtarget); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 5394 | case ISD::SINT_TO_FP: |
| 5395 | case ISD::UINT_TO_FP: return LowerINT_TO_FP(Op, DAG); |
| 5396 | case ISD::FP_TO_SINT: |
| 5397 | case ISD::FP_TO_UINT: return LowerFP_TO_INT(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5398 | case ISD::FCOPYSIGN: return LowerFCOPYSIGN(Op, DAG); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 5399 | case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 5400 | case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 5401 | case ISD::GLOBAL_OFFSET_TABLE: return LowerGLOBAL_OFFSET_TABLE(Op, DAG); |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 5402 | case ISD::EH_SJLJ_SETJMP: return LowerEH_SJLJ_SETJMP(Op, DAG); |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 5403 | case ISD::EH_SJLJ_LONGJMP: return LowerEH_SJLJ_LONGJMP(Op, DAG); |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 5404 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG, |
| 5405 | Subtarget); |
Evan Cheng | 21a6179 | 2011-03-14 18:02:30 +0000 | [diff] [blame] | 5406 | case ISD::BITCAST: return ExpandBITCAST(Op.getNode(), DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5407 | case ISD::SHL: |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5408 | case ISD::SRL: |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5409 | case ISD::SRA: return LowerShift(Op.getNode(), DAG, Subtarget); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 5410 | case ISD::SHL_PARTS: return LowerShiftLeftParts(Op, DAG); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 5411 | case ISD::SRL_PARTS: |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 5412 | case ISD::SRA_PARTS: return LowerShiftRightParts(Op, DAG); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 5413 | case ISD::CTTZ: return LowerCTTZ(Op.getNode(), DAG, Subtarget); |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 5414 | case ISD::SETCC: return LowerVSETCC(Op, DAG); |
Lang Hames | 45b5f88 | 2012-03-15 18:49:02 +0000 | [diff] [blame] | 5415 | case ISD::ConstantFP: return LowerConstantFP(Op, DAG, Subtarget); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 5416 | case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5417 | case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG); |
Eli Friedman | 5c89cb8 | 2011-10-24 23:08:52 +0000 | [diff] [blame] | 5418 | case ISD::INSERT_VECTOR_ELT: return LowerINSERT_VECTOR_ELT(Op, DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5419 | case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 5420 | case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG); |
Bob Wilson | b31a11b | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 5421 | case ISD::FLT_ROUNDS_: return LowerFLT_ROUNDS_(Op, DAG); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 5422 | case ISD::MUL: return LowerMUL(Op, DAG); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 5423 | case ISD::SDIV: return LowerSDIV(Op, DAG); |
| 5424 | case ISD::UDIV: return LowerUDIV(Op, DAG); |
Evan Cheng | 342e316 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 5425 | case ISD::ADDC: |
| 5426 | case ISD::ADDE: |
| 5427 | case ISD::SUBC: |
| 5428 | case ISD::SUBE: return LowerADDC_ADDE_SUBC_SUBE(Op, DAG); |
Eli Friedman | 7cc1566 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 5429 | case ISD::ATOMIC_LOAD: |
Eli Friedman | 74bf18c | 2011-09-15 22:26:18 +0000 | [diff] [blame] | 5430 | case ISD::ATOMIC_STORE: return LowerAtomicLoadStore(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5431 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5432 | } |
| 5433 | |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5434 | /// ReplaceNodeResults - Replace the results of node with an illegal result |
| 5435 | /// type with new values built out of custom code. |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5436 | void ARMTargetLowering::ReplaceNodeResults(SDNode *N, |
| 5437 | SmallVectorImpl<SDValue>&Results, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 5438 | SelectionDAG &DAG) const { |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5439 | SDValue Res; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5440 | switch (N->getOpcode()) { |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5441 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 5442 | llvm_unreachable("Don't know how to custom expand this!"); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5443 | case ISD::BITCAST: |
| 5444 | Res = ExpandBITCAST(N, DAG); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5445 | break; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5446 | case ISD::SRL: |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5447 | case ISD::SRA: |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 5448 | Res = Expand64BitShift(N, DAG, Subtarget); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5449 | break; |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5450 | case ISD::ATOMIC_LOAD_ADD: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5451 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMADD64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5452 | return; |
| 5453 | case ISD::ATOMIC_LOAD_AND: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5454 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMAND64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5455 | return; |
| 5456 | case ISD::ATOMIC_LOAD_NAND: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5457 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMNAND64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5458 | return; |
| 5459 | case ISD::ATOMIC_LOAD_OR: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5460 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMOR64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5461 | return; |
| 5462 | case ISD::ATOMIC_LOAD_SUB: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5463 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMSUB64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5464 | return; |
| 5465 | case ISD::ATOMIC_LOAD_XOR: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5466 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMXOR64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5467 | return; |
| 5468 | case ISD::ATOMIC_SWAP: |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5469 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMSWAP64_DAG); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5470 | return; |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5471 | case ISD::ATOMIC_CMP_SWAP: |
| 5472 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMCMPXCHG64_DAG); |
| 5473 | return; |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 5474 | case ISD::ATOMIC_LOAD_MIN: |
| 5475 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMMIN64_DAG); |
| 5476 | return; |
| 5477 | case ISD::ATOMIC_LOAD_UMIN: |
| 5478 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMUMIN64_DAG); |
| 5479 | return; |
| 5480 | case ISD::ATOMIC_LOAD_MAX: |
| 5481 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMMAX64_DAG); |
| 5482 | return; |
| 5483 | case ISD::ATOMIC_LOAD_UMAX: |
| 5484 | ReplaceATOMIC_OP_64(N, Results, DAG, ARMISD::ATOMUMAX64_DAG); |
| 5485 | return; |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 5486 | } |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 5487 | if (Res.getNode()) |
| 5488 | Results.push_back(Res); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5489 | } |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 5490 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5491 | //===----------------------------------------------------------------------===// |
| 5492 | // ARM Scheduler Hooks |
| 5493 | //===----------------------------------------------------------------------===// |
| 5494 | |
| 5495 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5496 | ARMTargetLowering::EmitAtomicCmpSwap(MachineInstr *MI, |
| 5497 | MachineBasicBlock *BB, |
| 5498 | unsigned Size) const { |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5499 | unsigned dest = MI->getOperand(0).getReg(); |
| 5500 | unsigned ptr = MI->getOperand(1).getReg(); |
| 5501 | unsigned oldval = MI->getOperand(2).getReg(); |
| 5502 | unsigned newval = MI->getOperand(3).getReg(); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5503 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5504 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5505 | bool isThumb2 = Subtarget->isThumb2(); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5506 | |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 5507 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5508 | unsigned scratch = MRI.createVirtualRegister(isThumb2 ? |
| 5509 | (const TargetRegisterClass*)&ARM::rGPRRegClass : |
| 5510 | (const TargetRegisterClass*)&ARM::GPRRegClass); |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 5511 | |
| 5512 | if (isThumb2) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5513 | MRI.constrainRegClass(dest, &ARM::rGPRRegClass); |
| 5514 | MRI.constrainRegClass(oldval, &ARM::rGPRRegClass); |
| 5515 | MRI.constrainRegClass(newval, &ARM::rGPRRegClass); |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 5516 | } |
| 5517 | |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5518 | unsigned ldrOpc, strOpc; |
| 5519 | switch (Size) { |
| 5520 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5521 | case 1: |
| 5522 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
Evan Cheng | aa26102 | 2011-02-07 18:50:47 +0000 | [diff] [blame] | 5523 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5524 | break; |
| 5525 | case 2: |
| 5526 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 5527 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 5528 | break; |
| 5529 | case 4: |
| 5530 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 5531 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 5532 | break; |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5533 | } |
| 5534 | |
| 5535 | MachineFunction *MF = BB->getParent(); |
| 5536 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 5537 | MachineFunction::iterator It = BB; |
| 5538 | ++It; // insert the new blocks after the current block |
| 5539 | |
| 5540 | MachineBasicBlock *loop1MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5541 | MachineBasicBlock *loop2MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5542 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5543 | MF->insert(It, loop1MBB); |
| 5544 | MF->insert(It, loop2MBB); |
| 5545 | MF->insert(It, exitMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5546 | |
| 5547 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5548 | exitMBB->splice(exitMBB->begin(), BB, |
| 5549 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5550 | BB->end()); |
| 5551 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5552 | |
| 5553 | // thisMBB: |
| 5554 | // ... |
| 5555 | // fallthrough --> loop1MBB |
| 5556 | BB->addSuccessor(loop1MBB); |
| 5557 | |
| 5558 | // loop1MBB: |
| 5559 | // ldrex dest, [ptr] |
| 5560 | // cmp dest, oldval |
| 5561 | // bne exitMBB |
| 5562 | BB = loop1MBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5563 | MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr); |
| 5564 | if (ldrOpc == ARM::t2LDREX) |
| 5565 | MIB.addImm(0); |
| 5566 | AddDefaultPred(MIB); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5567 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5568 | .addReg(dest).addReg(oldval)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5569 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5570 | .addMBB(exitMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5571 | BB->addSuccessor(loop2MBB); |
| 5572 | BB->addSuccessor(exitMBB); |
| 5573 | |
| 5574 | // loop2MBB: |
| 5575 | // strex scratch, newval, [ptr] |
| 5576 | // cmp scratch, #0 |
| 5577 | // bne loop1MBB |
| 5578 | BB = loop2MBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5579 | MIB = BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(newval).addReg(ptr); |
| 5580 | if (strOpc == ARM::t2STREX) |
| 5581 | MIB.addImm(0); |
| 5582 | AddDefaultPred(MIB); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5583 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5584 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5585 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5586 | .addMBB(loop1MBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5587 | BB->addSuccessor(loop1MBB); |
| 5588 | BB->addSuccessor(exitMBB); |
| 5589 | |
| 5590 | // exitMBB: |
| 5591 | // ... |
| 5592 | BB = exitMBB; |
Jim Grosbach | 5efaed3 | 2010-01-15 00:18:34 +0000 | [diff] [blame] | 5593 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5594 | MI->eraseFromParent(); // The instruction is gone now. |
Jim Grosbach | 5efaed3 | 2010-01-15 00:18:34 +0000 | [diff] [blame] | 5595 | |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5596 | return BB; |
| 5597 | } |
| 5598 | |
| 5599 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5600 | ARMTargetLowering::EmitAtomicBinary(MachineInstr *MI, MachineBasicBlock *BB, |
| 5601 | unsigned Size, unsigned BinOpcode) const { |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5602 | // This also handles ATOMIC_SWAP, indicated by BinOpcode==0. |
| 5603 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5604 | |
| 5605 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 5606 | MachineFunction *MF = BB->getParent(); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5607 | MachineFunction::iterator It = BB; |
| 5608 | ++It; |
| 5609 | |
| 5610 | unsigned dest = MI->getOperand(0).getReg(); |
| 5611 | unsigned ptr = MI->getOperand(1).getReg(); |
| 5612 | unsigned incr = MI->getOperand(2).getReg(); |
| 5613 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5614 | bool isThumb2 = Subtarget->isThumb2(); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5615 | |
| 5616 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 5617 | if (isThumb2) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5618 | MRI.constrainRegClass(dest, &ARM::rGPRRegClass); |
| 5619 | MRI.constrainRegClass(ptr, &ARM::rGPRRegClass); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5620 | } |
| 5621 | |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5622 | unsigned ldrOpc, strOpc; |
| 5623 | switch (Size) { |
| 5624 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5625 | case 1: |
| 5626 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
Jakob Stoklund Olesen | 15913c9 | 2010-01-13 19:54:39 +0000 | [diff] [blame] | 5627 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5628 | break; |
| 5629 | case 2: |
| 5630 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 5631 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 5632 | break; |
| 5633 | case 4: |
| 5634 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 5635 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 5636 | break; |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5637 | } |
| 5638 | |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 5639 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5640 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5641 | MF->insert(It, loopMBB); |
| 5642 | MF->insert(It, exitMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5643 | |
| 5644 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5645 | exitMBB->splice(exitMBB->begin(), BB, |
| 5646 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5647 | BB->end()); |
| 5648 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5649 | |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5650 | const TargetRegisterClass *TRC = isThumb2 ? |
Jakob Stoklund Olesen | 05e80f2 | 2012-08-31 02:08:34 +0000 | [diff] [blame] | 5651 | (const TargetRegisterClass*)&ARM::rGPRRegClass : |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5652 | (const TargetRegisterClass*)&ARM::GPRRegClass; |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5653 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| 5654 | unsigned scratch2 = (!BinOpcode) ? incr : MRI.createVirtualRegister(TRC); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5655 | |
| 5656 | // thisMBB: |
| 5657 | // ... |
| 5658 | // fallthrough --> loopMBB |
| 5659 | BB->addSuccessor(loopMBB); |
| 5660 | |
| 5661 | // loopMBB: |
| 5662 | // ldrex dest, ptr |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5663 | // <binop> scratch2, dest, incr |
| 5664 | // strex scratch, scratch2, ptr |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5665 | // cmp scratch, #0 |
| 5666 | // bne- loopMBB |
| 5667 | // fallthrough --> exitMBB |
| 5668 | BB = loopMBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5669 | MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr); |
| 5670 | if (ldrOpc == ARM::t2LDREX) |
| 5671 | MIB.addImm(0); |
| 5672 | AddDefaultPred(MIB); |
Jim Grosbach | c67b556 | 2009-12-15 00:12:35 +0000 | [diff] [blame] | 5673 | if (BinOpcode) { |
| 5674 | // operand order needs to go the other way for NAND |
| 5675 | if (BinOpcode == ARM::BICrr || BinOpcode == ARM::t2BICrr) |
| 5676 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 5677 | addReg(incr).addReg(dest)).addReg(0); |
| 5678 | else |
| 5679 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 5680 | addReg(dest).addReg(incr)).addReg(0); |
| 5681 | } |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5682 | |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5683 | MIB = BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(scratch2).addReg(ptr); |
| 5684 | if (strOpc == ARM::t2STREX) |
| 5685 | MIB.addImm(0); |
| 5686 | AddDefaultPred(MIB); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5687 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5688 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5689 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5690 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5691 | |
| 5692 | BB->addSuccessor(loopMBB); |
| 5693 | BB->addSuccessor(exitMBB); |
| 5694 | |
| 5695 | // exitMBB: |
| 5696 | // ... |
| 5697 | BB = exitMBB; |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 5698 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5699 | MI->eraseFromParent(); // The instruction is gone now. |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 5700 | |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5701 | return BB; |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5702 | } |
| 5703 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5704 | MachineBasicBlock * |
| 5705 | ARMTargetLowering::EmitAtomicBinaryMinMax(MachineInstr *MI, |
| 5706 | MachineBasicBlock *BB, |
| 5707 | unsigned Size, |
| 5708 | bool signExtend, |
| 5709 | ARMCC::CondCodes Cond) const { |
| 5710 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5711 | |
| 5712 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 5713 | MachineFunction *MF = BB->getParent(); |
| 5714 | MachineFunction::iterator It = BB; |
| 5715 | ++It; |
| 5716 | |
| 5717 | unsigned dest = MI->getOperand(0).getReg(); |
| 5718 | unsigned ptr = MI->getOperand(1).getReg(); |
| 5719 | unsigned incr = MI->getOperand(2).getReg(); |
| 5720 | unsigned oldval = dest; |
| 5721 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5722 | bool isThumb2 = Subtarget->isThumb2(); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5723 | |
| 5724 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 5725 | if (isThumb2) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5726 | MRI.constrainRegClass(dest, &ARM::rGPRRegClass); |
| 5727 | MRI.constrainRegClass(ptr, &ARM::rGPRRegClass); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5728 | } |
| 5729 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5730 | unsigned ldrOpc, strOpc, extendOpc; |
| 5731 | switch (Size) { |
| 5732 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
| 5733 | case 1: |
| 5734 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
| 5735 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 5736 | extendOpc = isThumb2 ? ARM::t2SXTB : ARM::SXTB; |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5737 | break; |
| 5738 | case 2: |
| 5739 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 5740 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 5741 | extendOpc = isThumb2 ? ARM::t2SXTH : ARM::SXTH; |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5742 | break; |
| 5743 | case 4: |
| 5744 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 5745 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 5746 | extendOpc = 0; |
| 5747 | break; |
| 5748 | } |
| 5749 | |
| 5750 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5751 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5752 | MF->insert(It, loopMBB); |
| 5753 | MF->insert(It, exitMBB); |
| 5754 | |
| 5755 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5756 | exitMBB->splice(exitMBB->begin(), BB, |
| 5757 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5758 | BB->end()); |
| 5759 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 5760 | |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5761 | const TargetRegisterClass *TRC = isThumb2 ? |
Jakob Stoklund Olesen | 05e80f2 | 2012-08-31 02:08:34 +0000 | [diff] [blame] | 5762 | (const TargetRegisterClass*)&ARM::rGPRRegClass : |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5763 | (const TargetRegisterClass*)&ARM::GPRRegClass; |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5764 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| 5765 | unsigned scratch2 = MRI.createVirtualRegister(TRC); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5766 | |
| 5767 | // thisMBB: |
| 5768 | // ... |
| 5769 | // fallthrough --> loopMBB |
| 5770 | BB->addSuccessor(loopMBB); |
| 5771 | |
| 5772 | // loopMBB: |
| 5773 | // ldrex dest, ptr |
| 5774 | // (sign extend dest, if required) |
| 5775 | // cmp dest, incr |
James Molloy | d6d10ae | 2012-09-26 09:48:32 +0000 | [diff] [blame] | 5776 | // cmov.cond scratch2, incr, dest |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5777 | // strex scratch, scratch2, ptr |
| 5778 | // cmp scratch, #0 |
| 5779 | // bne- loopMBB |
| 5780 | // fallthrough --> exitMBB |
| 5781 | BB = loopMBB; |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5782 | MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr); |
| 5783 | if (ldrOpc == ARM::t2LDREX) |
| 5784 | MIB.addImm(0); |
| 5785 | AddDefaultPred(MIB); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5786 | |
| 5787 | // Sign extend the value, if necessary. |
| 5788 | if (signExtend && extendOpc) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5789 | oldval = MRI.createVirtualRegister(&ARM::GPRRegClass); |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 5790 | AddDefaultPred(BuildMI(BB, dl, TII->get(extendOpc), oldval) |
| 5791 | .addReg(dest) |
| 5792 | .addImm(0)); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5793 | } |
| 5794 | |
| 5795 | // Build compare and cmov instructions. |
| 5796 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 5797 | .addReg(oldval).addReg(incr)); |
| 5798 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2MOVCCr : ARM::MOVCCr), scratch2) |
James Molloy | d6d10ae | 2012-09-26 09:48:32 +0000 | [diff] [blame] | 5799 | .addReg(incr).addReg(oldval).addImm(Cond).addReg(ARM::CPSR); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5800 | |
Jim Grosbach | b6aed50 | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 5801 | MIB = BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(scratch2).addReg(ptr); |
| 5802 | if (strOpc == ARM::t2STREX) |
| 5803 | MIB.addImm(0); |
| 5804 | AddDefaultPred(MIB); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5805 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 5806 | .addReg(scratch).addImm(0)); |
| 5807 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5808 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 5809 | |
| 5810 | BB->addSuccessor(loopMBB); |
| 5811 | BB->addSuccessor(exitMBB); |
| 5812 | |
| 5813 | // exitMBB: |
| 5814 | // ... |
| 5815 | BB = exitMBB; |
| 5816 | |
| 5817 | MI->eraseFromParent(); // The instruction is gone now. |
| 5818 | |
| 5819 | return BB; |
| 5820 | } |
| 5821 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5822 | MachineBasicBlock * |
| 5823 | ARMTargetLowering::EmitAtomicBinary64(MachineInstr *MI, MachineBasicBlock *BB, |
| 5824 | unsigned Op1, unsigned Op2, |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 5825 | bool NeedsCarry, bool IsCmpxchg, |
| 5826 | bool IsMinMax, ARMCC::CondCodes CC) const { |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5827 | // This also handles ATOMIC_SWAP, indicated by Op1==0. |
| 5828 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5829 | |
| 5830 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 5831 | MachineFunction *MF = BB->getParent(); |
| 5832 | MachineFunction::iterator It = BB; |
| 5833 | ++It; |
| 5834 | |
| 5835 | unsigned destlo = MI->getOperand(0).getReg(); |
| 5836 | unsigned desthi = MI->getOperand(1).getReg(); |
| 5837 | unsigned ptr = MI->getOperand(2).getReg(); |
| 5838 | unsigned vallo = MI->getOperand(3).getReg(); |
| 5839 | unsigned valhi = MI->getOperand(4).getReg(); |
| 5840 | DebugLoc dl = MI->getDebugLoc(); |
| 5841 | bool isThumb2 = Subtarget->isThumb2(); |
| 5842 | |
| 5843 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 5844 | if (isThumb2) { |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5845 | MRI.constrainRegClass(destlo, &ARM::rGPRRegClass); |
| 5846 | MRI.constrainRegClass(desthi, &ARM::rGPRRegClass); |
| 5847 | MRI.constrainRegClass(ptr, &ARM::rGPRRegClass); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5848 | } |
| 5849 | |
| 5850 | unsigned ldrOpc = isThumb2 ? ARM::t2LDREXD : ARM::LDREXD; |
| 5851 | unsigned strOpc = isThumb2 ? ARM::t2STREXD : ARM::STREXD; |
| 5852 | |
| 5853 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
Eli Friedman | 7df496d | 2011-09-01 22:27:41 +0000 | [diff] [blame] | 5854 | MachineBasicBlock *contBB = 0, *cont2BB = 0; |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 5855 | if (IsCmpxchg || IsMinMax) |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5856 | contBB = MF->CreateMachineBasicBlock(LLVM_BB); |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 5857 | if (IsCmpxchg) |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5858 | cont2BB = MF->CreateMachineBasicBlock(LLVM_BB); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5859 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 5860 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5861 | MF->insert(It, loopMBB); |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 5862 | if (IsCmpxchg || IsMinMax) MF->insert(It, contBB); |
| 5863 | if (IsCmpxchg) MF->insert(It, cont2BB); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5864 | MF->insert(It, exitMBB); |
| 5865 | |
| 5866 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5867 | exitMBB->splice(exitMBB->begin(), BB, |
| 5868 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5869 | BB->end()); |
| 5870 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 5871 | |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 5872 | const TargetRegisterClass *TRC = isThumb2 ? |
| 5873 | (const TargetRegisterClass*)&ARM::tGPRRegClass : |
| 5874 | (const TargetRegisterClass*)&ARM::GPRRegClass; |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5875 | unsigned storesuccess = MRI.createVirtualRegister(TRC); |
| 5876 | |
| 5877 | // thisMBB: |
| 5878 | // ... |
| 5879 | // fallthrough --> loopMBB |
| 5880 | BB->addSuccessor(loopMBB); |
| 5881 | |
| 5882 | // loopMBB: |
| 5883 | // ldrexd r2, r3, ptr |
| 5884 | // <binopa> r0, r2, incr |
| 5885 | // <binopb> r1, r3, incr |
| 5886 | // strexd storesuccess, r0, r1, ptr |
| 5887 | // cmp storesuccess, #0 |
| 5888 | // bne- loopMBB |
| 5889 | // fallthrough --> exitMBB |
| 5890 | // |
| 5891 | // Note that the registers are explicitly specified because there is not any |
| 5892 | // way to force the register allocator to allocate a register pair. |
| 5893 | // |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 5894 | // FIXME: The hardcoded registers are not necessary for Thumb2, but we |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5895 | // need to properly enforce the restriction that the two output registers |
| 5896 | // for ldrexd must be different. |
| 5897 | BB = loopMBB; |
| 5898 | // Load |
Weiming Zhao | e56764b | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5899 | unsigned GPRPair0 = MRI.createVirtualRegister(&ARM::GPRPairRegClass); |
| 5900 | unsigned GPRPair1 = MRI.createVirtualRegister(&ARM::GPRPairRegClass); |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 5901 | unsigned GPRPair2; |
| 5902 | if (IsMinMax) { |
| 5903 | //We need an extra double register for doing min/max. |
| 5904 | unsigned undef = MRI.createVirtualRegister(&ARM::GPRPairRegClass); |
| 5905 | unsigned r1 = MRI.createVirtualRegister(&ARM::GPRPairRegClass); |
| 5906 | GPRPair2 = MRI.createVirtualRegister(&ARM::GPRPairRegClass); |
| 5907 | BuildMI(BB, dl, TII->get(TargetOpcode::IMPLICIT_DEF), undef); |
| 5908 | BuildMI(BB, dl, TII->get(TargetOpcode::INSERT_SUBREG), r1) |
| 5909 | .addReg(undef) |
| 5910 | .addReg(vallo) |
| 5911 | .addImm(ARM::gsub_0); |
| 5912 | BuildMI(BB, dl, TII->get(TargetOpcode::INSERT_SUBREG), GPRPair2) |
| 5913 | .addReg(r1) |
| 5914 | .addReg(valhi) |
| 5915 | .addImm(ARM::gsub_1); |
| 5916 | } |
Weiming Zhao | e56764b | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5917 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5918 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc)) |
Weiming Zhao | e56764b | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5919 | .addReg(GPRPair0, RegState::Define).addReg(ptr)); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5920 | // Copy r2/r3 into dest. (This copy will normally be coalesced.) |
Weiming Zhao | e56764b | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5921 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), destlo) |
| 5922 | .addReg(GPRPair0, 0, ARM::gsub_0); |
| 5923 | BuildMI(BB, dl, TII->get(TargetOpcode::COPY), desthi) |
| 5924 | .addReg(GPRPair0, 0, ARM::gsub_1); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5925 | |
| 5926 | if (IsCmpxchg) { |
| 5927 | // Add early exit |
| 5928 | for (unsigned i = 0; i < 2; i++) { |
| 5929 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : |
| 5930 | ARM::CMPrr)) |
| 5931 | .addReg(i == 0 ? destlo : desthi) |
| 5932 | .addReg(i == 0 ? vallo : valhi)); |
| 5933 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5934 | .addMBB(exitMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 5935 | BB->addSuccessor(exitMBB); |
| 5936 | BB->addSuccessor(i == 0 ? contBB : cont2BB); |
| 5937 | BB = (i == 0 ? contBB : cont2BB); |
| 5938 | } |
| 5939 | |
| 5940 | // Copy to physregs for strexd |
| 5941 | unsigned setlo = MI->getOperand(5).getReg(); |
| 5942 | unsigned sethi = MI->getOperand(6).getReg(); |
Weiming Zhao | e56764b | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5943 | unsigned undef = MRI.createVirtualRegister(&ARM::GPRPairRegClass); |
| 5944 | unsigned r1 = MRI.createVirtualRegister(&ARM::GPRPairRegClass); |
| 5945 | BuildMI(BB, dl, TII->get(TargetOpcode::IMPLICIT_DEF), undef); |
| 5946 | BuildMI(BB, dl, TII->get(TargetOpcode::INSERT_SUBREG), r1) |
| 5947 | .addReg(undef) |
| 5948 | .addReg(setlo) |
| 5949 | .addImm(ARM::gsub_0); |
| 5950 | BuildMI(BB, dl, TII->get(TargetOpcode::INSERT_SUBREG), GPRPair1) |
| 5951 | .addReg(r1) |
| 5952 | .addReg(sethi) |
| 5953 | .addImm(ARM::gsub_1); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 5954 | } else if (Op1) { |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5955 | // Perform binary operation |
Weiming Zhao | e56764b | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5956 | unsigned tmpRegLo = MRI.createVirtualRegister(TRC); |
| 5957 | AddDefaultPred(BuildMI(BB, dl, TII->get(Op1), tmpRegLo) |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5958 | .addReg(destlo).addReg(vallo)) |
| 5959 | .addReg(NeedsCarry ? ARM::CPSR : 0, getDefRegState(NeedsCarry)); |
Weiming Zhao | e56764b | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5960 | unsigned tmpRegHi = MRI.createVirtualRegister(TRC); |
| 5961 | AddDefaultPred(BuildMI(BB, dl, TII->get(Op2), tmpRegHi) |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 5962 | .addReg(desthi).addReg(valhi)) |
| 5963 | .addReg(IsMinMax ? ARM::CPSR : 0, getDefRegState(IsMinMax)); |
Weiming Zhao | e56764b | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5964 | |
| 5965 | unsigned UndefPair = MRI.createVirtualRegister(&ARM::GPRPairRegClass); |
| 5966 | BuildMI(BB, dl, TII->get(TargetOpcode::IMPLICIT_DEF), UndefPair); |
| 5967 | unsigned r1 = MRI.createVirtualRegister(&ARM::GPRPairRegClass); |
| 5968 | BuildMI(BB, dl, TII->get(TargetOpcode::INSERT_SUBREG), r1) |
| 5969 | .addReg(UndefPair) |
| 5970 | .addReg(tmpRegLo) |
| 5971 | .addImm(ARM::gsub_0); |
| 5972 | BuildMI(BB, dl, TII->get(TargetOpcode::INSERT_SUBREG), GPRPair1) |
| 5973 | .addReg(r1) |
| 5974 | .addReg(tmpRegHi) |
| 5975 | .addImm(ARM::gsub_1); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5976 | } else { |
| 5977 | // Copy to physregs for strexd |
Weiming Zhao | e56764b | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5978 | unsigned UndefPair = MRI.createVirtualRegister(&ARM::GPRPairRegClass); |
| 5979 | unsigned r1 = MRI.createVirtualRegister(&ARM::GPRPairRegClass); |
| 5980 | BuildMI(BB, dl, TII->get(TargetOpcode::IMPLICIT_DEF), UndefPair); |
| 5981 | BuildMI(BB, dl, TII->get(TargetOpcode::INSERT_SUBREG), r1) |
| 5982 | .addReg(UndefPair) |
| 5983 | .addReg(vallo) |
| 5984 | .addImm(ARM::gsub_0); |
| 5985 | BuildMI(BB, dl, TII->get(TargetOpcode::INSERT_SUBREG), GPRPair1) |
| 5986 | .addReg(r1) |
| 5987 | .addReg(valhi) |
| 5988 | .addImm(ARM::gsub_1); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 5989 | } |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 5990 | unsigned GPRPairStore = GPRPair1; |
| 5991 | if (IsMinMax) { |
| 5992 | // Compare and branch to exit block. |
| 5993 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5994 | .addMBB(exitMBB).addImm(CC).addReg(ARM::CPSR); |
| 5995 | BB->addSuccessor(exitMBB); |
| 5996 | BB->addSuccessor(contBB); |
| 5997 | BB = contBB; |
| 5998 | GPRPairStore = GPRPair2; |
| 5999 | } |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6000 | |
| 6001 | // Store |
| 6002 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), storesuccess) |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 6003 | .addReg(GPRPairStore).addReg(ptr)); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6004 | // Cmp+jump |
| 6005 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 6006 | .addReg(storesuccess).addImm(0)); |
| 6007 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 6008 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 6009 | |
| 6010 | BB->addSuccessor(loopMBB); |
| 6011 | BB->addSuccessor(exitMBB); |
| 6012 | |
| 6013 | // exitMBB: |
| 6014 | // ... |
| 6015 | BB = exitMBB; |
| 6016 | |
| 6017 | MI->eraseFromParent(); // The instruction is gone now. |
| 6018 | |
| 6019 | return BB; |
| 6020 | } |
| 6021 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6022 | /// SetupEntryBlockForSjLj - Insert code into the entry block that creates and |
| 6023 | /// registers the function context. |
| 6024 | void ARMTargetLowering:: |
| 6025 | SetupEntryBlockForSjLj(MachineInstr *MI, MachineBasicBlock *MBB, |
| 6026 | MachineBasicBlock *DispatchBB, int FI) const { |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6027 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 6028 | DebugLoc dl = MI->getDebugLoc(); |
| 6029 | MachineFunction *MF = MBB->getParent(); |
| 6030 | MachineRegisterInfo *MRI = &MF->getRegInfo(); |
| 6031 | MachineConstantPool *MCP = MF->getConstantPool(); |
| 6032 | ARMFunctionInfo *AFI = MF->getInfo<ARMFunctionInfo>(); |
| 6033 | const Function *F = MF->getFunction(); |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6034 | |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6035 | bool isThumb = Subtarget->isThumb(); |
Bill Wendling | ff4216a | 2011-10-03 22:44:15 +0000 | [diff] [blame] | 6036 | bool isThumb2 = Subtarget->isThumb2(); |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6037 | |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6038 | unsigned PCLabelId = AFI->createPICLabelUId(); |
Bill Wendling | ff4216a | 2011-10-03 22:44:15 +0000 | [diff] [blame] | 6039 | unsigned PCAdj = (isThumb || isThumb2) ? 4 : 8; |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6040 | ARMConstantPoolValue *CPV = |
| 6041 | ARMConstantPoolMBB::Create(F->getContext(), DispatchBB, PCLabelId, PCAdj); |
| 6042 | unsigned CPI = MCP->getConstantPoolIndex(CPV, 4); |
| 6043 | |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6044 | const TargetRegisterClass *TRC = isThumb ? |
| 6045 | (const TargetRegisterClass*)&ARM::tGPRRegClass : |
| 6046 | (const TargetRegisterClass*)&ARM::GPRRegClass; |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6047 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6048 | // Grab constant pool and fixed stack memory operands. |
| 6049 | MachineMemOperand *CPMMO = |
| 6050 | MF->getMachineMemOperand(MachinePointerInfo::getConstantPool(), |
| 6051 | MachineMemOperand::MOLoad, 4, 4); |
| 6052 | |
| 6053 | MachineMemOperand *FIMMOSt = |
| 6054 | MF->getMachineMemOperand(MachinePointerInfo::getFixedStack(FI), |
| 6055 | MachineMemOperand::MOStore, 4, 4); |
| 6056 | |
| 6057 | // Load the address of the dispatch MBB into the jump buffer. |
| 6058 | if (isThumb2) { |
| 6059 | // Incoming value: jbuf |
| 6060 | // ldr.n r5, LCPI1_1 |
| 6061 | // orr r5, r5, #1 |
| 6062 | // add r5, pc |
| 6063 | // str r5, [$jbuf, #+4] ; &jbuf[1] |
| 6064 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 6065 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2LDRpci), NewVReg1) |
| 6066 | .addConstantPoolIndex(CPI) |
| 6067 | .addMemOperand(CPMMO)); |
| 6068 | // Set the low bit because of thumb mode. |
| 6069 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 6070 | AddDefaultCC( |
| 6071 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2ORRri), NewVReg2) |
| 6072 | .addReg(NewVReg1, RegState::Kill) |
| 6073 | .addImm(0x01))); |
| 6074 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 6075 | BuildMI(*MBB, MI, dl, TII->get(ARM::tPICADD), NewVReg3) |
| 6076 | .addReg(NewVReg2, RegState::Kill) |
| 6077 | .addImm(PCLabelId); |
| 6078 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2STRi12)) |
| 6079 | .addReg(NewVReg3, RegState::Kill) |
| 6080 | .addFrameIndex(FI) |
| 6081 | .addImm(36) // &jbuf[1] :: pc |
| 6082 | .addMemOperand(FIMMOSt)); |
| 6083 | } else if (isThumb) { |
| 6084 | // Incoming value: jbuf |
| 6085 | // ldr.n r1, LCPI1_4 |
| 6086 | // add r1, pc |
| 6087 | // mov r2, #1 |
| 6088 | // orrs r1, r2 |
| 6089 | // add r2, $jbuf, #+4 ; &jbuf[1] |
| 6090 | // str r1, [r2] |
| 6091 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 6092 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tLDRpci), NewVReg1) |
| 6093 | .addConstantPoolIndex(CPI) |
| 6094 | .addMemOperand(CPMMO)); |
| 6095 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 6096 | BuildMI(*MBB, MI, dl, TII->get(ARM::tPICADD), NewVReg2) |
| 6097 | .addReg(NewVReg1, RegState::Kill) |
| 6098 | .addImm(PCLabelId); |
| 6099 | // Set the low bit because of thumb mode. |
| 6100 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 6101 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tMOVi8), NewVReg3) |
| 6102 | .addReg(ARM::CPSR, RegState::Define) |
| 6103 | .addImm(1)); |
| 6104 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 6105 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tORR), NewVReg4) |
| 6106 | .addReg(ARM::CPSR, RegState::Define) |
| 6107 | .addReg(NewVReg2, RegState::Kill) |
| 6108 | .addReg(NewVReg3, RegState::Kill)); |
| 6109 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
| 6110 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tADDrSPi), NewVReg5) |
| 6111 | .addFrameIndex(FI) |
| 6112 | .addImm(36)); // &jbuf[1] :: pc |
| 6113 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tSTRi)) |
| 6114 | .addReg(NewVReg4, RegState::Kill) |
| 6115 | .addReg(NewVReg5, RegState::Kill) |
| 6116 | .addImm(0) |
| 6117 | .addMemOperand(FIMMOSt)); |
| 6118 | } else { |
| 6119 | // Incoming value: jbuf |
| 6120 | // ldr r1, LCPI1_1 |
| 6121 | // add r1, pc, r1 |
| 6122 | // str r1, [$jbuf, #+4] ; &jbuf[1] |
| 6123 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 6124 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::LDRi12), NewVReg1) |
| 6125 | .addConstantPoolIndex(CPI) |
| 6126 | .addImm(0) |
| 6127 | .addMemOperand(CPMMO)); |
| 6128 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 6129 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::PICADD), NewVReg2) |
| 6130 | .addReg(NewVReg1, RegState::Kill) |
| 6131 | .addImm(PCLabelId)); |
| 6132 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::STRi12)) |
| 6133 | .addReg(NewVReg2, RegState::Kill) |
| 6134 | .addFrameIndex(FI) |
| 6135 | .addImm(36) // &jbuf[1] :: pc |
| 6136 | .addMemOperand(FIMMOSt)); |
| 6137 | } |
| 6138 | } |
| 6139 | |
| 6140 | MachineBasicBlock *ARMTargetLowering:: |
| 6141 | EmitSjLjDispatchBlock(MachineInstr *MI, MachineBasicBlock *MBB) const { |
| 6142 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 6143 | DebugLoc dl = MI->getDebugLoc(); |
| 6144 | MachineFunction *MF = MBB->getParent(); |
| 6145 | MachineRegisterInfo *MRI = &MF->getRegInfo(); |
| 6146 | ARMFunctionInfo *AFI = MF->getInfo<ARMFunctionInfo>(); |
| 6147 | MachineFrameInfo *MFI = MF->getFrameInfo(); |
| 6148 | int FI = MFI->getFunctionContextIndex(); |
| 6149 | |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6150 | const TargetRegisterClass *TRC = Subtarget->isThumb() ? |
| 6151 | (const TargetRegisterClass*)&ARM::tGPRRegClass : |
Jakob Stoklund Olesen | 027c32a | 2012-05-20 06:38:47 +0000 | [diff] [blame] | 6152 | (const TargetRegisterClass*)&ARM::GPRnopcRegClass; |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6153 | |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 6154 | // Get a mapping of the call site numbers to all of the landing pads they're |
| 6155 | // associated with. |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6156 | DenseMap<unsigned, SmallVector<MachineBasicBlock*, 2> > CallSiteNumToLPad; |
| 6157 | unsigned MaxCSNum = 0; |
| 6158 | MachineModuleInfo &MMI = MF->getMMI(); |
Jim Grosbach | d4f020a | 2012-04-06 23:43:50 +0000 | [diff] [blame] | 6159 | for (MachineFunction::iterator BB = MF->begin(), E = MF->end(); BB != E; |
| 6160 | ++BB) { |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6161 | if (!BB->isLandingPad()) continue; |
| 6162 | |
| 6163 | // FIXME: We should assert that the EH_LABEL is the first MI in the landing |
| 6164 | // pad. |
| 6165 | for (MachineBasicBlock::iterator |
| 6166 | II = BB->begin(), IE = BB->end(); II != IE; ++II) { |
| 6167 | if (!II->isEHLabel()) continue; |
| 6168 | |
| 6169 | MCSymbol *Sym = II->getOperand(0).getMCSymbol(); |
Bill Wendling | 5cbef19 | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 6170 | if (!MMI.hasCallSiteLandingPad(Sym)) continue; |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6171 | |
Bill Wendling | 5cbef19 | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 6172 | SmallVectorImpl<unsigned> &CallSiteIdxs = MMI.getCallSiteLandingPad(Sym); |
| 6173 | for (SmallVectorImpl<unsigned>::iterator |
| 6174 | CSI = CallSiteIdxs.begin(), CSE = CallSiteIdxs.end(); |
| 6175 | CSI != CSE; ++CSI) { |
| 6176 | CallSiteNumToLPad[*CSI].push_back(BB); |
| 6177 | MaxCSNum = std::max(MaxCSNum, *CSI); |
| 6178 | } |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6179 | break; |
| 6180 | } |
| 6181 | } |
| 6182 | |
| 6183 | // Get an ordered list of the machine basic blocks for the jump table. |
| 6184 | std::vector<MachineBasicBlock*> LPadList; |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6185 | SmallPtrSet<MachineBasicBlock*, 64> InvokeBBs; |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6186 | LPadList.reserve(CallSiteNumToLPad.size()); |
| 6187 | for (unsigned I = 1; I <= MaxCSNum; ++I) { |
| 6188 | SmallVectorImpl<MachineBasicBlock*> &MBBList = CallSiteNumToLPad[I]; |
| 6189 | for (SmallVectorImpl<MachineBasicBlock*>::iterator |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6190 | II = MBBList.begin(), IE = MBBList.end(); II != IE; ++II) { |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6191 | LPadList.push_back(*II); |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6192 | InvokeBBs.insert((*II)->pred_begin(), (*II)->pred_end()); |
| 6193 | } |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6194 | } |
| 6195 | |
Bill Wendling | 5cbef19 | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 6196 | assert(!LPadList.empty() && |
| 6197 | "No landing pad destinations for the dispatch jump table!"); |
| 6198 | |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 6199 | // Create the jump table and associated information. |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6200 | MachineJumpTableInfo *JTI = |
| 6201 | MF->getOrCreateJumpTableInfo(MachineJumpTableInfo::EK_Inline); |
| 6202 | unsigned MJTI = JTI->createJumpTableIndex(LPadList); |
| 6203 | unsigned UId = AFI->createJumpTableUId(); |
| 6204 | |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 6205 | // Create the MBBs for the dispatch code. |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6206 | |
| 6207 | // Shove the dispatch's address into the return slot in the function context. |
| 6208 | MachineBasicBlock *DispatchBB = MF->CreateMachineBasicBlock(); |
| 6209 | DispatchBB->setIsLandingPad(); |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6210 | |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6211 | MachineBasicBlock *TrapBB = MF->CreateMachineBasicBlock(); |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 6212 | BuildMI(TrapBB, dl, TII->get(Subtarget->isThumb() ? ARM::tTRAP : ARM::TRAP)); |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6213 | DispatchBB->addSuccessor(TrapBB); |
| 6214 | |
| 6215 | MachineBasicBlock *DispContBB = MF->CreateMachineBasicBlock(); |
| 6216 | DispatchBB->addSuccessor(DispContBB); |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6217 | |
Bill Wendling | a48ed4f | 2011-10-17 21:32:56 +0000 | [diff] [blame] | 6218 | // Insert and MBBs. |
Bill Wendling | 930193c | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 6219 | MF->insert(MF->end(), DispatchBB); |
| 6220 | MF->insert(MF->end(), DispContBB); |
| 6221 | MF->insert(MF->end(), TrapBB); |
Bill Wendling | 930193c | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 6222 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6223 | // Insert code into the entry block that creates and registers the function |
| 6224 | // context. |
| 6225 | SetupEntryBlockForSjLj(MI, MBB, DispatchBB, FI); |
| 6226 | |
Bill Wendling | e29fa1d | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6227 | MachineMemOperand *FIMMOLd = |
Bill Wendling | 04f15b4 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 6228 | MF->getMachineMemOperand(MachinePointerInfo::getFixedStack(FI), |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 6229 | MachineMemOperand::MOLoad | |
| 6230 | MachineMemOperand::MOVolatile, 4, 4); |
Bill Wendling | 930193c | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 6231 | |
Chad Rosier | e7bd519 | 2012-11-06 23:05:24 +0000 | [diff] [blame] | 6232 | MachineInstrBuilder MIB; |
| 6233 | MIB = BuildMI(DispatchBB, dl, TII->get(ARM::Int_eh_sjlj_dispatchsetup)); |
| 6234 | |
| 6235 | const ARMBaseInstrInfo *AII = static_cast<const ARMBaseInstrInfo*>(TII); |
| 6236 | const ARMBaseRegisterInfo &RI = AII->getRegisterInfo(); |
| 6237 | |
| 6238 | // Add a register mask with no preserved registers. This results in all |
| 6239 | // registers being marked as clobbered. |
| 6240 | MIB.addRegMask(RI.getNoPreservedMask()); |
Bob Wilson | eaab6ef | 2011-11-16 07:11:57 +0000 | [diff] [blame] | 6241 | |
Bill Wendling | 952cb50 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 6242 | unsigned NumLPads = LPadList.size(); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6243 | if (Subtarget->isThumb2()) { |
| 6244 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 6245 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2LDRi12), NewVReg1) |
| 6246 | .addFrameIndex(FI) |
| 6247 | .addImm(4) |
| 6248 | .addMemOperand(FIMMOLd)); |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 6249 | |
Bill Wendling | 952cb50 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 6250 | if (NumLPads < 256) { |
| 6251 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2CMPri)) |
| 6252 | .addReg(NewVReg1) |
| 6253 | .addImm(LPadList.size())); |
| 6254 | } else { |
| 6255 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 6256 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2MOVi16), VReg1) |
Bill Wendling | 15a1a22 | 2011-10-18 23:19:55 +0000 | [diff] [blame] | 6257 | .addImm(NumLPads & 0xFFFF)); |
| 6258 | |
| 6259 | unsigned VReg2 = VReg1; |
| 6260 | if ((NumLPads & 0xFFFF0000) != 0) { |
| 6261 | VReg2 = MRI->createVirtualRegister(TRC); |
| 6262 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2MOVTi16), VReg2) |
| 6263 | .addReg(VReg1) |
| 6264 | .addImm(NumLPads >> 16)); |
| 6265 | } |
| 6266 | |
Bill Wendling | 952cb50 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 6267 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2CMPrr)) |
| 6268 | .addReg(NewVReg1) |
| 6269 | .addReg(VReg2)); |
| 6270 | } |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 6271 | |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6272 | BuildMI(DispatchBB, dl, TII->get(ARM::t2Bcc)) |
| 6273 | .addMBB(TrapBB) |
| 6274 | .addImm(ARMCC::HI) |
| 6275 | .addReg(ARM::CPSR); |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6276 | |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 6277 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 6278 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::t2LEApcrelJT),NewVReg3) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6279 | .addJumpTableIndex(MJTI) |
| 6280 | .addImm(UId)); |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6281 | |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 6282 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6283 | AddDefaultCC( |
| 6284 | AddDefaultPred( |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 6285 | BuildMI(DispContBB, dl, TII->get(ARM::t2ADDrs), NewVReg4) |
| 6286 | .addReg(NewVReg3, RegState::Kill) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6287 | .addReg(NewVReg1) |
| 6288 | .addImm(ARM_AM::getSORegOpc(ARM_AM::lsl, 2)))); |
| 6289 | |
| 6290 | BuildMI(DispContBB, dl, TII->get(ARM::t2BR_JT)) |
Bill Wendling | b9fecf4 | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 6291 | .addReg(NewVReg4, RegState::Kill) |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6292 | .addReg(NewVReg1) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6293 | .addJumpTableIndex(MJTI) |
| 6294 | .addImm(UId); |
| 6295 | } else if (Subtarget->isThumb()) { |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 6296 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 6297 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tLDRspi), NewVReg1) |
| 6298 | .addFrameIndex(FI) |
| 6299 | .addImm(1) |
| 6300 | .addMemOperand(FIMMOLd)); |
Bill Wendling | f1083d4 | 2011-10-07 22:08:37 +0000 | [diff] [blame] | 6301 | |
Bill Wendling | a5871dc | 2011-10-18 23:11:05 +0000 | [diff] [blame] | 6302 | if (NumLPads < 256) { |
| 6303 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tCMPi8)) |
| 6304 | .addReg(NewVReg1) |
| 6305 | .addImm(NumLPads)); |
| 6306 | } else { |
| 6307 | MachineConstantPool *ConstantPool = MF->getConstantPool(); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6308 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); |
| 6309 | const Constant *C = ConstantInt::get(Int32Ty, NumLPads); |
| 6310 | |
| 6311 | // MachineConstantPool wants an explicit alignment. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 6312 | unsigned Align = getDataLayout()->getPrefTypeAlignment(Int32Ty); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6313 | if (Align == 0) |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 6314 | Align = getDataLayout()->getTypeAllocSize(C->getType()); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6315 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
Bill Wendling | a5871dc | 2011-10-18 23:11:05 +0000 | [diff] [blame] | 6316 | |
| 6317 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 6318 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tLDRpci)) |
| 6319 | .addReg(VReg1, RegState::Define) |
| 6320 | .addConstantPoolIndex(Idx)); |
| 6321 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tCMPr)) |
| 6322 | .addReg(NewVReg1) |
| 6323 | .addReg(VReg1)); |
| 6324 | } |
| 6325 | |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 6326 | BuildMI(DispatchBB, dl, TII->get(ARM::tBcc)) |
| 6327 | .addMBB(TrapBB) |
| 6328 | .addImm(ARMCC::HI) |
| 6329 | .addReg(ARM::CPSR); |
| 6330 | |
| 6331 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 6332 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLSLri), NewVReg2) |
| 6333 | .addReg(ARM::CPSR, RegState::Define) |
| 6334 | .addReg(NewVReg1) |
| 6335 | .addImm(2)); |
| 6336 | |
| 6337 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 217f0e9 | 2011-10-06 23:41:14 +0000 | [diff] [blame] | 6338 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLEApcrelJT), NewVReg3) |
Bill Wendling | 083a8eb | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 6339 | .addJumpTableIndex(MJTI) |
| 6340 | .addImm(UId)); |
| 6341 | |
| 6342 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 6343 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tADDrr), NewVReg4) |
| 6344 | .addReg(ARM::CPSR, RegState::Define) |
| 6345 | .addReg(NewVReg2, RegState::Kill) |
| 6346 | .addReg(NewVReg3)); |
| 6347 | |
| 6348 | MachineMemOperand *JTMMOLd = |
| 6349 | MF->getMachineMemOperand(MachinePointerInfo::getJumpTable(), |
| 6350 | MachineMemOperand::MOLoad, 4, 4); |
| 6351 | |
| 6352 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
| 6353 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLDRi), NewVReg5) |
| 6354 | .addReg(NewVReg4, RegState::Kill) |
| 6355 | .addImm(0) |
| 6356 | .addMemOperand(JTMMOLd)); |
| 6357 | |
| 6358 | unsigned NewVReg6 = MRI->createVirtualRegister(TRC); |
| 6359 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tADDrr), NewVReg6) |
| 6360 | .addReg(ARM::CPSR, RegState::Define) |
| 6361 | .addReg(NewVReg5, RegState::Kill) |
| 6362 | .addReg(NewVReg3)); |
| 6363 | |
| 6364 | BuildMI(DispContBB, dl, TII->get(ARM::tBR_JTr)) |
| 6365 | .addReg(NewVReg6, RegState::Kill) |
| 6366 | .addJumpTableIndex(MJTI) |
| 6367 | .addImm(UId); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6368 | } else { |
| 6369 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 6370 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::LDRi12), NewVReg1) |
| 6371 | .addFrameIndex(FI) |
| 6372 | .addImm(4) |
| 6373 | .addMemOperand(FIMMOLd)); |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6374 | |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6375 | if (NumLPads < 256) { |
| 6376 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPri)) |
| 6377 | .addReg(NewVReg1) |
| 6378 | .addImm(NumLPads)); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6379 | } else if (Subtarget->hasV6T2Ops() && isUInt<16>(NumLPads)) { |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6380 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 6381 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::MOVi16), VReg1) |
Bill Wendling | 15a1a22 | 2011-10-18 23:19:55 +0000 | [diff] [blame] | 6382 | .addImm(NumLPads & 0xFFFF)); |
| 6383 | |
| 6384 | unsigned VReg2 = VReg1; |
| 6385 | if ((NumLPads & 0xFFFF0000) != 0) { |
| 6386 | VReg2 = MRI->createVirtualRegister(TRC); |
| 6387 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::MOVTi16), VReg2) |
| 6388 | .addReg(VReg1) |
| 6389 | .addImm(NumLPads >> 16)); |
| 6390 | } |
| 6391 | |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6392 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPrr)) |
| 6393 | .addReg(NewVReg1) |
| 6394 | .addReg(VReg2)); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6395 | } else { |
| 6396 | MachineConstantPool *ConstantPool = MF->getConstantPool(); |
| 6397 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); |
| 6398 | const Constant *C = ConstantInt::get(Int32Ty, NumLPads); |
| 6399 | |
| 6400 | // MachineConstantPool wants an explicit alignment. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 6401 | unsigned Align = getDataLayout()->getPrefTypeAlignment(Int32Ty); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6402 | if (Align == 0) |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 6403 | Align = getDataLayout()->getTypeAllocSize(C->getType()); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6404 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
| 6405 | |
| 6406 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 6407 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::LDRcp)) |
| 6408 | .addReg(VReg1, RegState::Define) |
Bill Wendling | 767f8be | 2011-10-20 20:37:11 +0000 | [diff] [blame] | 6409 | .addConstantPoolIndex(Idx) |
| 6410 | .addImm(0)); |
Bill Wendling | 922ad78 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 6411 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPrr)) |
| 6412 | .addReg(NewVReg1) |
| 6413 | .addReg(VReg1, RegState::Kill)); |
Bill Wendling | 85f3a0a | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 6414 | } |
| 6415 | |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6416 | BuildMI(DispatchBB, dl, TII->get(ARM::Bcc)) |
| 6417 | .addMBB(TrapBB) |
| 6418 | .addImm(ARMCC::HI) |
| 6419 | .addReg(ARM::CPSR); |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6420 | |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6421 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6422 | AddDefaultCC( |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6423 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::MOVsi), NewVReg3) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6424 | .addReg(NewVReg1) |
| 6425 | .addImm(ARM_AM::getSORegOpc(ARM_AM::lsl, 2)))); |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6426 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 6427 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::LEApcrelJT), NewVReg4) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6428 | .addJumpTableIndex(MJTI) |
| 6429 | .addImm(UId)); |
| 6430 | |
| 6431 | MachineMemOperand *JTMMOLd = |
| 6432 | MF->getMachineMemOperand(MachinePointerInfo::getJumpTable(), |
| 6433 | MachineMemOperand::MOLoad, 4, 4); |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6434 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6435 | AddDefaultPred( |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6436 | BuildMI(DispContBB, dl, TII->get(ARM::LDRrs), NewVReg5) |
| 6437 | .addReg(NewVReg3, RegState::Kill) |
| 6438 | .addReg(NewVReg4) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6439 | .addImm(0) |
| 6440 | .addMemOperand(JTMMOLd)); |
| 6441 | |
| 6442 | BuildMI(DispContBB, dl, TII->get(ARM::BR_JTadd)) |
Bill Wendling | 564392b | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 6443 | .addReg(NewVReg5, RegState::Kill) |
| 6444 | .addReg(NewVReg4) |
Bill Wendling | 95ce2e9 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 6445 | .addJumpTableIndex(MJTI) |
| 6446 | .addImm(UId); |
| 6447 | } |
Bill Wendling | 2a85015 | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 6448 | |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6449 | // Add the jump table entries as successors to the MBB. |
Jakob Stoklund Olesen | a0708d1 | 2012-08-20 20:52:03 +0000 | [diff] [blame] | 6450 | SmallPtrSet<MachineBasicBlock*, 8> SeenMBBs; |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6451 | for (std::vector<MachineBasicBlock*>::iterator |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6452 | I = LPadList.begin(), E = LPadList.end(); I != E; ++I) { |
| 6453 | MachineBasicBlock *CurMBB = *I; |
Jakob Stoklund Olesen | a0708d1 | 2012-08-20 20:52:03 +0000 | [diff] [blame] | 6454 | if (SeenMBBs.insert(CurMBB)) |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6455 | DispContBB->addSuccessor(CurMBB); |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6456 | } |
| 6457 | |
Bill Wendling | 24bb925 | 2011-10-17 05:25:09 +0000 | [diff] [blame] | 6458 | // 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] | 6459 | const uint16_t *SavedRegs = RI.getCalleeSavedRegs(MF); |
Bill Wendling | f7b0207 | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 6460 | SmallVector<MachineBasicBlock*, 64> MBBLPads; |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6461 | for (SmallPtrSet<MachineBasicBlock*, 64>::iterator |
| 6462 | I = InvokeBBs.begin(), E = InvokeBBs.end(); I != E; ++I) { |
| 6463 | MachineBasicBlock *BB = *I; |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6464 | |
| 6465 | // Remove the landing pad successor from the invoke block and replace it |
| 6466 | // with the new dispatch block. |
Bill Wendling | de39d86 | 2011-10-26 07:16:18 +0000 | [diff] [blame] | 6467 | SmallVector<MachineBasicBlock*, 4> Successors(BB->succ_begin(), |
| 6468 | BB->succ_end()); |
| 6469 | while (!Successors.empty()) { |
| 6470 | MachineBasicBlock *SMBB = Successors.pop_back_val(); |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6471 | if (SMBB->isLandingPad()) { |
| 6472 | BB->removeSuccessor(SMBB); |
Bill Wendling | f7b0207 | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 6473 | MBBLPads.push_back(SMBB); |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6474 | } |
| 6475 | } |
| 6476 | |
| 6477 | BB->addSuccessor(DispatchBB); |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6478 | |
| 6479 | // Find the invoke call and mark all of the callee-saved registers as |
| 6480 | // 'implicit defined' so that they're spilled. This prevents code from |
| 6481 | // moving instructions to before the EH block, where they will never be |
| 6482 | // executed. |
| 6483 | for (MachineBasicBlock::reverse_iterator |
| 6484 | II = BB->rbegin(), IE = BB->rend(); II != IE; ++II) { |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 6485 | if (!II->isCall()) continue; |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6486 | |
| 6487 | DenseMap<unsigned, bool> DefRegs; |
| 6488 | for (MachineInstr::mop_iterator |
| 6489 | OI = II->operands_begin(), OE = II->operands_end(); |
| 6490 | OI != OE; ++OI) { |
| 6491 | if (!OI->isReg()) continue; |
| 6492 | DefRegs[OI->getReg()] = true; |
| 6493 | } |
| 6494 | |
| 6495 | MachineInstrBuilder MIB(&*II); |
| 6496 | |
Bill Wendling | 5d79859 | 2011-10-14 23:55:44 +0000 | [diff] [blame] | 6497 | for (unsigned i = 0; SavedRegs[i] != 0; ++i) { |
Bill Wendling | b8dcb31 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 6498 | unsigned Reg = SavedRegs[i]; |
| 6499 | if (Subtarget->isThumb2() && |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6500 | !ARM::tGPRRegClass.contains(Reg) && |
| 6501 | !ARM::hGPRRegClass.contains(Reg)) |
Bill Wendling | b8dcb31 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 6502 | continue; |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6503 | if (Subtarget->isThumb1Only() && !ARM::tGPRRegClass.contains(Reg)) |
Bill Wendling | b8dcb31 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 6504 | continue; |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 6505 | if (!Subtarget->isThumb() && !ARM::GPRRegClass.contains(Reg)) |
Bill Wendling | b8dcb31 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 6506 | continue; |
| 6507 | if (!DefRegs[Reg]) |
| 6508 | MIB.addReg(Reg, RegState::ImplicitDefine | RegState::Dead); |
Bill Wendling | 5d79859 | 2011-10-14 23:55:44 +0000 | [diff] [blame] | 6509 | } |
Bill Wendling | 969c9ef | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 6510 | |
| 6511 | break; |
| 6512 | } |
Bill Wendling | 2acf638 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 6513 | } |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6514 | |
Bill Wendling | f7b0207 | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 6515 | // Mark all former landing pads as non-landing pads. The dispatch is the only |
| 6516 | // landing pad now. |
| 6517 | for (SmallVectorImpl<MachineBasicBlock*>::iterator |
| 6518 | I = MBBLPads.begin(), E = MBBLPads.end(); I != E; ++I) |
| 6519 | (*I)->setIsLandingPad(false); |
| 6520 | |
Bill Wendling | bb73468 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 6521 | // The instruction is gone now. |
| 6522 | MI->eraseFromParent(); |
| 6523 | |
Bill Wendling | f7e4aef | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6524 | return MBB; |
| 6525 | } |
| 6526 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 6527 | static |
| 6528 | MachineBasicBlock *OtherSucc(MachineBasicBlock *MBB, MachineBasicBlock *Succ) { |
| 6529 | for (MachineBasicBlock::succ_iterator I = MBB->succ_begin(), |
| 6530 | E = MBB->succ_end(); I != E; ++I) |
| 6531 | if (*I != Succ) |
| 6532 | return *I; |
| 6533 | llvm_unreachable("Expecting a BB with two successors!"); |
| 6534 | } |
| 6535 | |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6536 | MachineBasicBlock *ARMTargetLowering:: |
| 6537 | EmitStructByval(MachineInstr *MI, MachineBasicBlock *BB) const { |
| 6538 | // This pseudo instruction has 3 operands: dst, src, size |
| 6539 | // We expand it to a loop if size > Subtarget->getMaxInlineSizeThreshold(). |
| 6540 | // Otherwise, we will generate unrolled scalar copies. |
| 6541 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 6542 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 6543 | MachineFunction::iterator It = BB; |
| 6544 | ++It; |
| 6545 | |
| 6546 | unsigned dest = MI->getOperand(0).getReg(); |
| 6547 | unsigned src = MI->getOperand(1).getReg(); |
| 6548 | unsigned SizeVal = MI->getOperand(2).getImm(); |
| 6549 | unsigned Align = MI->getOperand(3).getImm(); |
| 6550 | DebugLoc dl = MI->getDebugLoc(); |
| 6551 | |
| 6552 | bool isThumb2 = Subtarget->isThumb2(); |
| 6553 | MachineFunction *MF = BB->getParent(); |
| 6554 | MachineRegisterInfo &MRI = MF->getRegInfo(); |
Manman Ren | eda9fdf | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6555 | unsigned ldrOpc, strOpc, UnitSize = 0; |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6556 | |
| 6557 | const TargetRegisterClass *TRC = isThumb2 ? |
| 6558 | (const TargetRegisterClass*)&ARM::tGPRRegClass : |
| 6559 | (const TargetRegisterClass*)&ARM::GPRRegClass; |
Manman Ren | eda9fdf | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6560 | const TargetRegisterClass *TRC_Vec = 0; |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6561 | |
| 6562 | if (Align & 1) { |
| 6563 | ldrOpc = isThumb2 ? ARM::t2LDRB_POST : ARM::LDRB_POST_IMM; |
| 6564 | strOpc = isThumb2 ? ARM::t2STRB_POST : ARM::STRB_POST_IMM; |
| 6565 | UnitSize = 1; |
| 6566 | } else if (Align & 2) { |
| 6567 | ldrOpc = isThumb2 ? ARM::t2LDRH_POST : ARM::LDRH_POST; |
| 6568 | strOpc = isThumb2 ? ARM::t2STRH_POST : ARM::STRH_POST; |
| 6569 | UnitSize = 2; |
| 6570 | } else { |
Manman Ren | eda9fdf | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6571 | // Check whether we can use NEON instructions. |
Bill Wendling | 6765834 | 2012-10-09 07:45:08 +0000 | [diff] [blame] | 6572 | if (!MF->getFunction()->getFnAttributes(). |
| 6573 | hasAttribute(Attributes::NoImplicitFloat) && |
Manman Ren | eda9fdf | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6574 | Subtarget->hasNEON()) { |
| 6575 | if ((Align % 16 == 0) && SizeVal >= 16) { |
| 6576 | ldrOpc = ARM::VLD1q32wb_fixed; |
| 6577 | strOpc = ARM::VST1q32wb_fixed; |
| 6578 | UnitSize = 16; |
| 6579 | TRC_Vec = (const TargetRegisterClass*)&ARM::DPairRegClass; |
| 6580 | } |
| 6581 | else if ((Align % 8 == 0) && SizeVal >= 8) { |
| 6582 | ldrOpc = ARM::VLD1d32wb_fixed; |
| 6583 | strOpc = ARM::VST1d32wb_fixed; |
| 6584 | UnitSize = 8; |
| 6585 | TRC_Vec = (const TargetRegisterClass*)&ARM::DPRRegClass; |
| 6586 | } |
| 6587 | } |
| 6588 | // Can't use NEON instructions. |
| 6589 | if (UnitSize == 0) { |
| 6590 | ldrOpc = isThumb2 ? ARM::t2LDR_POST : ARM::LDR_POST_IMM; |
| 6591 | strOpc = isThumb2 ? ARM::t2STR_POST : ARM::STR_POST_IMM; |
| 6592 | UnitSize = 4; |
| 6593 | } |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6594 | } |
Manman Ren | eda9fdf | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6595 | |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6596 | unsigned BytesLeft = SizeVal % UnitSize; |
| 6597 | unsigned LoopSize = SizeVal - BytesLeft; |
| 6598 | |
| 6599 | if (SizeVal <= Subtarget->getMaxInlineSizeThreshold()) { |
| 6600 | // Use LDR and STR to copy. |
| 6601 | // [scratch, srcOut] = LDR_POST(srcIn, UnitSize) |
| 6602 | // [destOut] = STR_POST(scratch, destIn, UnitSize) |
| 6603 | unsigned srcIn = src; |
| 6604 | unsigned destIn = dest; |
| 6605 | for (unsigned i = 0; i < LoopSize; i+=UnitSize) { |
Manman Ren | eda9fdf | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6606 | unsigned scratch = MRI.createVirtualRegister(UnitSize >= 8 ? TRC_Vec:TRC); |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6607 | unsigned srcOut = MRI.createVirtualRegister(TRC); |
| 6608 | unsigned destOut = MRI.createVirtualRegister(TRC); |
Manman Ren | eda9fdf | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6609 | if (UnitSize >= 8) { |
| 6610 | AddDefaultPred(BuildMI(*BB, MI, dl, |
| 6611 | TII->get(ldrOpc), scratch) |
| 6612 | .addReg(srcOut, RegState::Define).addReg(srcIn).addImm(0)); |
| 6613 | |
| 6614 | AddDefaultPred(BuildMI(*BB, MI, dl, TII->get(strOpc), destOut) |
| 6615 | .addReg(destIn).addImm(0).addReg(scratch)); |
| 6616 | } else if (isThumb2) { |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6617 | AddDefaultPred(BuildMI(*BB, MI, dl, |
| 6618 | TII->get(ldrOpc), scratch) |
| 6619 | .addReg(srcOut, RegState::Define).addReg(srcIn).addImm(UnitSize)); |
| 6620 | |
| 6621 | AddDefaultPred(BuildMI(*BB, MI, dl, TII->get(strOpc), destOut) |
| 6622 | .addReg(scratch).addReg(destIn) |
| 6623 | .addImm(UnitSize)); |
| 6624 | } else { |
| 6625 | AddDefaultPred(BuildMI(*BB, MI, dl, |
| 6626 | TII->get(ldrOpc), scratch) |
| 6627 | .addReg(srcOut, RegState::Define).addReg(srcIn).addReg(0) |
| 6628 | .addImm(UnitSize)); |
| 6629 | |
| 6630 | AddDefaultPred(BuildMI(*BB, MI, dl, TII->get(strOpc), destOut) |
| 6631 | .addReg(scratch).addReg(destIn) |
| 6632 | .addReg(0).addImm(UnitSize)); |
| 6633 | } |
| 6634 | srcIn = srcOut; |
| 6635 | destIn = destOut; |
| 6636 | } |
| 6637 | |
| 6638 | // Handle the leftover bytes with LDRB and STRB. |
| 6639 | // [scratch, srcOut] = LDRB_POST(srcIn, 1) |
| 6640 | // [destOut] = STRB_POST(scratch, destIn, 1) |
| 6641 | ldrOpc = isThumb2 ? ARM::t2LDRB_POST : ARM::LDRB_POST_IMM; |
| 6642 | strOpc = isThumb2 ? ARM::t2STRB_POST : ARM::STRB_POST_IMM; |
| 6643 | for (unsigned i = 0; i < BytesLeft; i++) { |
| 6644 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| 6645 | unsigned srcOut = MRI.createVirtualRegister(TRC); |
| 6646 | unsigned destOut = MRI.createVirtualRegister(TRC); |
| 6647 | if (isThumb2) { |
| 6648 | AddDefaultPred(BuildMI(*BB, MI, dl, |
| 6649 | TII->get(ldrOpc),scratch) |
| 6650 | .addReg(srcOut, RegState::Define).addReg(srcIn).addImm(1)); |
| 6651 | |
| 6652 | AddDefaultPred(BuildMI(*BB, MI, dl, TII->get(strOpc), destOut) |
| 6653 | .addReg(scratch).addReg(destIn) |
| 6654 | .addReg(0).addImm(1)); |
| 6655 | } else { |
| 6656 | AddDefaultPred(BuildMI(*BB, MI, dl, |
| 6657 | TII->get(ldrOpc),scratch) |
Stepan Dyatkovskiy | 2c2cb3c | 2012-10-10 11:43:40 +0000 | [diff] [blame] | 6658 | .addReg(srcOut, RegState::Define).addReg(srcIn) |
| 6659 | .addReg(0).addImm(1)); |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6660 | |
| 6661 | AddDefaultPred(BuildMI(*BB, MI, dl, TII->get(strOpc), destOut) |
| 6662 | .addReg(scratch).addReg(destIn) |
| 6663 | .addReg(0).addImm(1)); |
| 6664 | } |
| 6665 | srcIn = srcOut; |
| 6666 | destIn = destOut; |
| 6667 | } |
| 6668 | MI->eraseFromParent(); // The instruction is gone now. |
| 6669 | return BB; |
| 6670 | } |
| 6671 | |
| 6672 | // Expand the pseudo op to a loop. |
| 6673 | // thisMBB: |
| 6674 | // ... |
| 6675 | // movw varEnd, # --> with thumb2 |
| 6676 | // movt varEnd, # |
| 6677 | // ldrcp varEnd, idx --> without thumb2 |
| 6678 | // fallthrough --> loopMBB |
| 6679 | // loopMBB: |
| 6680 | // PHI varPhi, varEnd, varLoop |
| 6681 | // PHI srcPhi, src, srcLoop |
| 6682 | // PHI destPhi, dst, destLoop |
| 6683 | // [scratch, srcLoop] = LDR_POST(srcPhi, UnitSize) |
| 6684 | // [destLoop] = STR_POST(scratch, destPhi, UnitSize) |
| 6685 | // subs varLoop, varPhi, #UnitSize |
| 6686 | // bne loopMBB |
| 6687 | // fallthrough --> exitMBB |
| 6688 | // exitMBB: |
| 6689 | // epilogue to handle left-over bytes |
| 6690 | // [scratch, srcOut] = LDRB_POST(srcLoop, 1) |
| 6691 | // [destOut] = STRB_POST(scratch, destLoop, 1) |
| 6692 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 6693 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 6694 | MF->insert(It, loopMBB); |
| 6695 | MF->insert(It, exitMBB); |
| 6696 | |
| 6697 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 6698 | exitMBB->splice(exitMBB->begin(), BB, |
| 6699 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 6700 | BB->end()); |
| 6701 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 6702 | |
| 6703 | // Load an immediate to varEnd. |
| 6704 | unsigned varEnd = MRI.createVirtualRegister(TRC); |
| 6705 | if (isThumb2) { |
| 6706 | unsigned VReg1 = varEnd; |
| 6707 | if ((LoopSize & 0xFFFF0000) != 0) |
| 6708 | VReg1 = MRI.createVirtualRegister(TRC); |
| 6709 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::t2MOVi16), VReg1) |
| 6710 | .addImm(LoopSize & 0xFFFF)); |
| 6711 | |
| 6712 | if ((LoopSize & 0xFFFF0000) != 0) |
| 6713 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::t2MOVTi16), varEnd) |
| 6714 | .addReg(VReg1) |
| 6715 | .addImm(LoopSize >> 16)); |
| 6716 | } else { |
| 6717 | MachineConstantPool *ConstantPool = MF->getConstantPool(); |
| 6718 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); |
| 6719 | const Constant *C = ConstantInt::get(Int32Ty, LoopSize); |
| 6720 | |
| 6721 | // MachineConstantPool wants an explicit alignment. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 6722 | unsigned Align = getDataLayout()->getPrefTypeAlignment(Int32Ty); |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6723 | if (Align == 0) |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 6724 | Align = getDataLayout()->getTypeAllocSize(C->getType()); |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6725 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
| 6726 | |
| 6727 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::LDRcp)) |
| 6728 | .addReg(varEnd, RegState::Define) |
| 6729 | .addConstantPoolIndex(Idx) |
| 6730 | .addImm(0)); |
| 6731 | } |
| 6732 | BB->addSuccessor(loopMBB); |
| 6733 | |
| 6734 | // Generate the loop body: |
| 6735 | // varPhi = PHI(varLoop, varEnd) |
| 6736 | // srcPhi = PHI(srcLoop, src) |
| 6737 | // destPhi = PHI(destLoop, dst) |
| 6738 | MachineBasicBlock *entryBB = BB; |
| 6739 | BB = loopMBB; |
| 6740 | unsigned varLoop = MRI.createVirtualRegister(TRC); |
| 6741 | unsigned varPhi = MRI.createVirtualRegister(TRC); |
| 6742 | unsigned srcLoop = MRI.createVirtualRegister(TRC); |
| 6743 | unsigned srcPhi = MRI.createVirtualRegister(TRC); |
| 6744 | unsigned destLoop = MRI.createVirtualRegister(TRC); |
| 6745 | unsigned destPhi = MRI.createVirtualRegister(TRC); |
| 6746 | |
| 6747 | BuildMI(*BB, BB->begin(), dl, TII->get(ARM::PHI), varPhi) |
| 6748 | .addReg(varLoop).addMBB(loopMBB) |
| 6749 | .addReg(varEnd).addMBB(entryBB); |
| 6750 | BuildMI(BB, dl, TII->get(ARM::PHI), srcPhi) |
| 6751 | .addReg(srcLoop).addMBB(loopMBB) |
| 6752 | .addReg(src).addMBB(entryBB); |
| 6753 | BuildMI(BB, dl, TII->get(ARM::PHI), destPhi) |
| 6754 | .addReg(destLoop).addMBB(loopMBB) |
| 6755 | .addReg(dest).addMBB(entryBB); |
| 6756 | |
| 6757 | // [scratch, srcLoop] = LDR_POST(srcPhi, UnitSize) |
| 6758 | // [destLoop] = STR_POST(scratch, destPhi, UnitSiz) |
Manman Ren | eda9fdf | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 6759 | unsigned scratch = MRI.createVirtualRegister(UnitSize >= 8 ? TRC_Vec:TRC); |
| 6760 | if (UnitSize >= 8) { |
| 6761 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc), scratch) |
| 6762 | .addReg(srcLoop, RegState::Define).addReg(srcPhi).addImm(0)); |
| 6763 | |
| 6764 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), destLoop) |
| 6765 | .addReg(destPhi).addImm(0).addReg(scratch)); |
| 6766 | } else if (isThumb2) { |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 6767 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc), scratch) |
| 6768 | .addReg(srcLoop, RegState::Define).addReg(srcPhi).addImm(UnitSize)); |
| 6769 | |
| 6770 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), destLoop) |
| 6771 | .addReg(scratch).addReg(destPhi) |
| 6772 | .addImm(UnitSize)); |
| 6773 | } else { |
| 6774 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc), scratch) |
| 6775 | .addReg(srcLoop, RegState::Define).addReg(srcPhi).addReg(0) |
| 6776 | .addImm(UnitSize)); |
| 6777 | |
| 6778 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), destLoop) |
| 6779 | .addReg(scratch).addReg(destPhi) |
| 6780 | .addReg(0).addImm(UnitSize)); |
| 6781 | } |
| 6782 | |
| 6783 | // Decrement loop variable by UnitSize. |
| 6784 | MachineInstrBuilder MIB = BuildMI(BB, dl, |
| 6785 | TII->get(isThumb2 ? ARM::t2SUBri : ARM::SUBri), varLoop); |
| 6786 | AddDefaultCC(AddDefaultPred(MIB.addReg(varPhi).addImm(UnitSize))); |
| 6787 | MIB->getOperand(5).setReg(ARM::CPSR); |
| 6788 | MIB->getOperand(5).setIsDef(true); |
| 6789 | |
| 6790 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 6791 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 6792 | |
| 6793 | // loopMBB can loop back to loopMBB or fall through to exitMBB. |
| 6794 | BB->addSuccessor(loopMBB); |
| 6795 | BB->addSuccessor(exitMBB); |
| 6796 | |
| 6797 | // Add epilogue to handle BytesLeft. |
| 6798 | BB = exitMBB; |
| 6799 | MachineInstr *StartOfExit = exitMBB->begin(); |
| 6800 | ldrOpc = isThumb2 ? ARM::t2LDRB_POST : ARM::LDRB_POST_IMM; |
| 6801 | strOpc = isThumb2 ? ARM::t2STRB_POST : ARM::STRB_POST_IMM; |
| 6802 | |
| 6803 | // [scratch, srcOut] = LDRB_POST(srcLoop, 1) |
| 6804 | // [destOut] = STRB_POST(scratch, destLoop, 1) |
| 6805 | unsigned srcIn = srcLoop; |
| 6806 | unsigned destIn = destLoop; |
| 6807 | for (unsigned i = 0; i < BytesLeft; i++) { |
| 6808 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| 6809 | unsigned srcOut = MRI.createVirtualRegister(TRC); |
| 6810 | unsigned destOut = MRI.createVirtualRegister(TRC); |
| 6811 | if (isThumb2) { |
| 6812 | AddDefaultPred(BuildMI(*BB, StartOfExit, dl, |
| 6813 | TII->get(ldrOpc),scratch) |
| 6814 | .addReg(srcOut, RegState::Define).addReg(srcIn).addImm(1)); |
| 6815 | |
| 6816 | AddDefaultPred(BuildMI(*BB, StartOfExit, dl, TII->get(strOpc), destOut) |
| 6817 | .addReg(scratch).addReg(destIn) |
| 6818 | .addImm(1)); |
| 6819 | } else { |
| 6820 | AddDefaultPred(BuildMI(*BB, StartOfExit, dl, |
| 6821 | TII->get(ldrOpc),scratch) |
| 6822 | .addReg(srcOut, RegState::Define).addReg(srcIn).addReg(0).addImm(1)); |
| 6823 | |
| 6824 | AddDefaultPred(BuildMI(*BB, StartOfExit, dl, TII->get(strOpc), destOut) |
| 6825 | .addReg(scratch).addReg(destIn) |
| 6826 | .addReg(0).addImm(1)); |
| 6827 | } |
| 6828 | srcIn = srcOut; |
| 6829 | destIn = destOut; |
| 6830 | } |
| 6831 | |
| 6832 | MI->eraseFromParent(); // The instruction is gone now. |
| 6833 | return BB; |
| 6834 | } |
| 6835 | |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6836 | MachineBasicBlock * |
Evan Cheng | ff9b373 | 2008-01-30 18:18:23 +0000 | [diff] [blame] | 6837 | ARMTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
Dan Gohman | af1d8ca | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 6838 | MachineBasicBlock *BB) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6839 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Dale Johannesen | b672840 | 2009-02-13 02:25:56 +0000 | [diff] [blame] | 6840 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6841 | bool isThumb2 = Subtarget->isThumb2(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6842 | switch (MI->getOpcode()) { |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 6843 | default: { |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6844 | MI->dump(); |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 6845 | llvm_unreachable("Unexpected instr type to insert"); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 6846 | } |
Jim Grosbach | ee2c2a4 | 2011-09-16 21:55:56 +0000 | [diff] [blame] | 6847 | // The Thumb2 pre-indexed stores have the same MI operands, they just |
| 6848 | // define them differently in the .td files from the isel patterns, so |
| 6849 | // they need pseudos. |
| 6850 | case ARM::t2STR_preidx: |
| 6851 | MI->setDesc(TII->get(ARM::t2STR_PRE)); |
| 6852 | return BB; |
| 6853 | case ARM::t2STRB_preidx: |
| 6854 | MI->setDesc(TII->get(ARM::t2STRB_PRE)); |
| 6855 | return BB; |
| 6856 | case ARM::t2STRH_preidx: |
| 6857 | MI->setDesc(TII->get(ARM::t2STRH_PRE)); |
| 6858 | return BB; |
| 6859 | |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6860 | case ARM::STRi_preidx: |
| 6861 | case ARM::STRBi_preidx: { |
Jim Grosbach | 6cd5716 | 2011-08-09 21:22:41 +0000 | [diff] [blame] | 6862 | unsigned NewOpc = MI->getOpcode() == ARM::STRi_preidx ? |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6863 | ARM::STR_PRE_IMM : ARM::STRB_PRE_IMM; |
| 6864 | // Decode the offset. |
| 6865 | unsigned Offset = MI->getOperand(4).getImm(); |
| 6866 | bool isSub = ARM_AM::getAM2Op(Offset) == ARM_AM::sub; |
| 6867 | Offset = ARM_AM::getAM2Offset(Offset); |
| 6868 | if (isSub) |
| 6869 | Offset = -Offset; |
| 6870 | |
Jim Grosbach | 4dfe220 | 2011-08-12 21:02:34 +0000 | [diff] [blame] | 6871 | MachineMemOperand *MMO = *MI->memoperands_begin(); |
Benjamin Kramer | 2753ae3 | 2011-08-27 17:36:14 +0000 | [diff] [blame] | 6872 | BuildMI(*BB, MI, dl, TII->get(NewOpc)) |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6873 | .addOperand(MI->getOperand(0)) // Rn_wb |
| 6874 | .addOperand(MI->getOperand(1)) // Rt |
| 6875 | .addOperand(MI->getOperand(2)) // Rn |
| 6876 | .addImm(Offset) // offset (skip GPR==zero_reg) |
| 6877 | .addOperand(MI->getOperand(5)) // pred |
Jim Grosbach | 4dfe220 | 2011-08-12 21:02:34 +0000 | [diff] [blame] | 6878 | .addOperand(MI->getOperand(6)) |
| 6879 | .addMemOperand(MMO); |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6880 | MI->eraseFromParent(); |
| 6881 | return BB; |
| 6882 | } |
| 6883 | case ARM::STRr_preidx: |
Jim Grosbach | 7b8f46c | 2011-08-11 21:17:22 +0000 | [diff] [blame] | 6884 | case ARM::STRBr_preidx: |
| 6885 | case ARM::STRH_preidx: { |
| 6886 | unsigned NewOpc; |
| 6887 | switch (MI->getOpcode()) { |
| 6888 | default: llvm_unreachable("unexpected opcode!"); |
| 6889 | case ARM::STRr_preidx: NewOpc = ARM::STR_PRE_REG; break; |
| 6890 | case ARM::STRBr_preidx: NewOpc = ARM::STRB_PRE_REG; break; |
| 6891 | case ARM::STRH_preidx: NewOpc = ARM::STRH_PRE; break; |
| 6892 | } |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 6893 | MachineInstrBuilder MIB = BuildMI(*BB, MI, dl, TII->get(NewOpc)); |
| 6894 | for (unsigned i = 0; i < MI->getNumOperands(); ++i) |
| 6895 | MIB.addOperand(MI->getOperand(i)); |
| 6896 | MI->eraseFromParent(); |
| 6897 | return BB; |
| 6898 | } |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6899 | case ARM::ATOMIC_LOAD_ADD_I8: |
| 6900 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 6901 | case ARM::ATOMIC_LOAD_ADD_I16: |
| 6902 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 6903 | case ARM::ATOMIC_LOAD_ADD_I32: |
| 6904 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6905 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6906 | case ARM::ATOMIC_LOAD_AND_I8: |
| 6907 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 6908 | case ARM::ATOMIC_LOAD_AND_I16: |
| 6909 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 6910 | case ARM::ATOMIC_LOAD_AND_I32: |
| 6911 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6912 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6913 | case ARM::ATOMIC_LOAD_OR_I8: |
| 6914 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 6915 | case ARM::ATOMIC_LOAD_OR_I16: |
| 6916 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 6917 | case ARM::ATOMIC_LOAD_OR_I32: |
| 6918 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6919 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6920 | case ARM::ATOMIC_LOAD_XOR_I8: |
| 6921 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 6922 | case ARM::ATOMIC_LOAD_XOR_I16: |
| 6923 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 6924 | case ARM::ATOMIC_LOAD_XOR_I32: |
| 6925 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6926 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6927 | case ARM::ATOMIC_LOAD_NAND_I8: |
| 6928 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 6929 | case ARM::ATOMIC_LOAD_NAND_I16: |
| 6930 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 6931 | case ARM::ATOMIC_LOAD_NAND_I32: |
| 6932 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6933 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6934 | case ARM::ATOMIC_LOAD_SUB_I8: |
| 6935 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 6936 | case ARM::ATOMIC_LOAD_SUB_I16: |
| 6937 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 6938 | case ARM::ATOMIC_LOAD_SUB_I32: |
| 6939 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6940 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 6941 | case ARM::ATOMIC_LOAD_MIN_I8: |
| 6942 | return EmitAtomicBinaryMinMax(MI, BB, 1, true, ARMCC::LT); |
| 6943 | case ARM::ATOMIC_LOAD_MIN_I16: |
| 6944 | return EmitAtomicBinaryMinMax(MI, BB, 2, true, ARMCC::LT); |
| 6945 | case ARM::ATOMIC_LOAD_MIN_I32: |
| 6946 | return EmitAtomicBinaryMinMax(MI, BB, 4, true, ARMCC::LT); |
| 6947 | |
| 6948 | case ARM::ATOMIC_LOAD_MAX_I8: |
| 6949 | return EmitAtomicBinaryMinMax(MI, BB, 1, true, ARMCC::GT); |
| 6950 | case ARM::ATOMIC_LOAD_MAX_I16: |
| 6951 | return EmitAtomicBinaryMinMax(MI, BB, 2, true, ARMCC::GT); |
| 6952 | case ARM::ATOMIC_LOAD_MAX_I32: |
| 6953 | return EmitAtomicBinaryMinMax(MI, BB, 4, true, ARMCC::GT); |
| 6954 | |
| 6955 | case ARM::ATOMIC_LOAD_UMIN_I8: |
| 6956 | return EmitAtomicBinaryMinMax(MI, BB, 1, false, ARMCC::LO); |
| 6957 | case ARM::ATOMIC_LOAD_UMIN_I16: |
| 6958 | return EmitAtomicBinaryMinMax(MI, BB, 2, false, ARMCC::LO); |
| 6959 | case ARM::ATOMIC_LOAD_UMIN_I32: |
| 6960 | return EmitAtomicBinaryMinMax(MI, BB, 4, false, ARMCC::LO); |
| 6961 | |
| 6962 | case ARM::ATOMIC_LOAD_UMAX_I8: |
| 6963 | return EmitAtomicBinaryMinMax(MI, BB, 1, false, ARMCC::HI); |
| 6964 | case ARM::ATOMIC_LOAD_UMAX_I16: |
| 6965 | return EmitAtomicBinaryMinMax(MI, BB, 2, false, ARMCC::HI); |
| 6966 | case ARM::ATOMIC_LOAD_UMAX_I32: |
| 6967 | return EmitAtomicBinaryMinMax(MI, BB, 4, false, ARMCC::HI); |
| 6968 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 6969 | case ARM::ATOMIC_SWAP_I8: return EmitAtomicBinary(MI, BB, 1, 0); |
| 6970 | case ARM::ATOMIC_SWAP_I16: return EmitAtomicBinary(MI, BB, 2, 0); |
| 6971 | case ARM::ATOMIC_SWAP_I32: return EmitAtomicBinary(MI, BB, 4, 0); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 6972 | |
| 6973 | case ARM::ATOMIC_CMP_SWAP_I8: return EmitAtomicCmpSwap(MI, BB, 1); |
| 6974 | case ARM::ATOMIC_CMP_SWAP_I16: return EmitAtomicCmpSwap(MI, BB, 2); |
| 6975 | case ARM::ATOMIC_CMP_SWAP_I32: return EmitAtomicCmpSwap(MI, BB, 4); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 6976 | |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6977 | |
| 6978 | case ARM::ATOMADD6432: |
| 6979 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6980 | isThumb2 ? ARM::t2ADCrr : ARM::ADCrr, |
| 6981 | /*NeedsCarry*/ true); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6982 | case ARM::ATOMSUB6432: |
| 6983 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6984 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 6985 | /*NeedsCarry*/ true); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6986 | case ARM::ATOMOR6432: |
| 6987 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6988 | isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6989 | case ARM::ATOMXOR6432: |
| 6990 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2EORrr : ARM::EORrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6991 | isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6992 | case ARM::ATOMAND6432: |
| 6993 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr, |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6994 | isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 6995 | case ARM::ATOMSWAP6432: |
| 6996 | return EmitAtomicBinary64(MI, BB, 0, 0, false); |
Eli Friedman | 4d3f329 | 2011-08-31 17:52:22 +0000 | [diff] [blame] | 6997 | case ARM::ATOMCMPXCHG6432: |
| 6998 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
| 6999 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 7000 | /*NeedsCarry*/ false, /*IsCmpxchg*/true); |
Silviu Baranga | 35b3df6 | 2012-11-29 14:41:25 +0000 | [diff] [blame] | 7001 | case ARM::ATOMMIN6432: |
| 7002 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
| 7003 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 7004 | /*NeedsCarry*/ true, /*IsCmpxchg*/false, |
| 7005 | /*IsMinMax*/ true, ARMCC::LE); |
| 7006 | case ARM::ATOMMAX6432: |
| 7007 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
| 7008 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 7009 | /*NeedsCarry*/ true, /*IsCmpxchg*/false, |
| 7010 | /*IsMinMax*/ true, ARMCC::GE); |
| 7011 | case ARM::ATOMUMIN6432: |
| 7012 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
| 7013 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 7014 | /*NeedsCarry*/ true, /*IsCmpxchg*/false, |
| 7015 | /*IsMinMax*/ true, ARMCC::LS); |
| 7016 | case ARM::ATOMUMAX6432: |
| 7017 | return EmitAtomicBinary64(MI, BB, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr, |
| 7018 | isThumb2 ? ARM::t2SBCrr : ARM::SBCrr, |
| 7019 | /*NeedsCarry*/ true, /*IsCmpxchg*/false, |
| 7020 | /*IsMinMax*/ true, ARMCC::HS); |
Eli Friedman | 2bdffe4 | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 7021 | |
Evan Cheng | 007ea27 | 2009-08-12 05:17:19 +0000 | [diff] [blame] | 7022 | case ARM::tMOVCCr_pseudo: { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7023 | // To "insert" a SELECT_CC instruction, we actually have to insert the |
| 7024 | // diamond control-flow pattern. The incoming instruction knows the |
| 7025 | // destination vreg to set, the condition code register to branch on, the |
| 7026 | // true/false values to select between, and a branch opcode to use. |
| 7027 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 7028 | MachineFunction::iterator It = BB; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7029 | ++It; |
| 7030 | |
| 7031 | // thisMBB: |
| 7032 | // ... |
| 7033 | // TrueVal = ... |
| 7034 | // cmpTY ccX, r1, r2 |
| 7035 | // bCC copy1MBB |
| 7036 | // fallthrough --> copy0MBB |
| 7037 | MachineBasicBlock *thisMBB = BB; |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 7038 | MachineFunction *F = BB->getParent(); |
| 7039 | MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 7040 | MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); |
Dan Gohman | 258c58c | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 7041 | F->insert(It, copy0MBB); |
| 7042 | F->insert(It, sinkMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 7043 | |
| 7044 | // Transfer the remainder of BB and its successor edges to sinkMBB. |
| 7045 | sinkMBB->splice(sinkMBB->begin(), BB, |
| 7046 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 7047 | BB->end()); |
| 7048 | sinkMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 7049 | |
Dan Gohman | 258c58c | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 7050 | BB->addSuccessor(copy0MBB); |
| 7051 | BB->addSuccessor(sinkMBB); |
Dan Gohman | b81c771 | 2010-07-06 15:18:19 +0000 | [diff] [blame] | 7052 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 7053 | BuildMI(BB, dl, TII->get(ARM::tBcc)).addMBB(sinkMBB) |
| 7054 | .addImm(MI->getOperand(3).getImm()).addReg(MI->getOperand(4).getReg()); |
| 7055 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7056 | // copy0MBB: |
| 7057 | // %FalseValue = ... |
| 7058 | // # fallthrough to sinkMBB |
| 7059 | BB = copy0MBB; |
| 7060 | |
| 7061 | // Update machine-CFG edges |
| 7062 | BB->addSuccessor(sinkMBB); |
| 7063 | |
| 7064 | // sinkMBB: |
| 7065 | // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] |
| 7066 | // ... |
| 7067 | BB = sinkMBB; |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 7068 | BuildMI(*BB, BB->begin(), dl, |
| 7069 | TII->get(ARM::PHI), MI->getOperand(0).getReg()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7070 | .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB) |
| 7071 | .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB); |
| 7072 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 7073 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7074 | return BB; |
| 7075 | } |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 7076 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 7077 | case ARM::BCCi64: |
| 7078 | case ARM::BCCZi64: { |
Bob Wilson | 3c90469 | 2010-12-23 22:45:49 +0000 | [diff] [blame] | 7079 | // If there is an unconditional branch to the other successor, remove it. |
| 7080 | BB->erase(llvm::next(MachineBasicBlock::iterator(MI)), BB->end()); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 7081 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 7082 | // Compare both parts that make up the double comparison separately for |
| 7083 | // equality. |
| 7084 | bool RHSisZero = MI->getOpcode() == ARM::BCCZi64; |
| 7085 | |
| 7086 | unsigned LHS1 = MI->getOperand(1).getReg(); |
| 7087 | unsigned LHS2 = MI->getOperand(2).getReg(); |
| 7088 | if (RHSisZero) { |
| 7089 | AddDefaultPred(BuildMI(BB, dl, |
| 7090 | TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 7091 | .addReg(LHS1).addImm(0)); |
| 7092 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 7093 | .addReg(LHS2).addImm(0) |
| 7094 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 7095 | } else { |
| 7096 | unsigned RHS1 = MI->getOperand(3).getReg(); |
| 7097 | unsigned RHS2 = MI->getOperand(4).getReg(); |
| 7098 | AddDefaultPred(BuildMI(BB, dl, |
| 7099 | TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 7100 | .addReg(LHS1).addReg(RHS1)); |
| 7101 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 7102 | .addReg(LHS2).addReg(RHS2) |
| 7103 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 7104 | } |
| 7105 | |
| 7106 | MachineBasicBlock *destMBB = MI->getOperand(RHSisZero ? 3 : 5).getMBB(); |
| 7107 | MachineBasicBlock *exitMBB = OtherSucc(BB, destMBB); |
| 7108 | if (MI->getOperand(0).getImm() == ARMCC::NE) |
| 7109 | std::swap(destMBB, exitMBB); |
| 7110 | |
| 7111 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 7112 | .addMBB(destMBB).addImm(ARMCC::EQ).addReg(ARM::CPSR); |
Owen Anderson | 51f6a7a | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 7113 | if (isThumb2) |
| 7114 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::t2B)).addMBB(exitMBB)); |
| 7115 | else |
| 7116 | BuildMI(BB, dl, TII->get(ARM::B)) .addMBB(exitMBB); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 7117 | |
| 7118 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
| 7119 | return BB; |
| 7120 | } |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7121 | |
Bill Wendling | 5bc8528 | 2011-10-17 20:37:20 +0000 | [diff] [blame] | 7122 | case ARM::Int_eh_sjlj_setjmp: |
| 7123 | case ARM::Int_eh_sjlj_setjmp_nofp: |
| 7124 | case ARM::tInt_eh_sjlj_setjmp: |
| 7125 | case ARM::t2Int_eh_sjlj_setjmp: |
| 7126 | case ARM::t2Int_eh_sjlj_setjmp_nofp: |
| 7127 | EmitSjLjDispatchBlock(MI, BB); |
| 7128 | return BB; |
| 7129 | |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7130 | case ARM::ABS: |
| 7131 | case ARM::t2ABS: { |
| 7132 | // To insert an ABS instruction, we have to insert the |
| 7133 | // diamond control-flow pattern. The incoming instruction knows the |
| 7134 | // source vreg to test against 0, the destination vreg to set, |
| 7135 | // the condition code register to branch on, the |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 7136 | // true/false values to select between, and a branch opcode to use. |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7137 | // It transforms |
| 7138 | // V1 = ABS V0 |
| 7139 | // into |
| 7140 | // V2 = MOVS V0 |
| 7141 | // BCC (branch to SinkBB if V0 >= 0) |
| 7142 | // RSBBB: V3 = RSBri V2, 0 (compute ABS if V2 < 0) |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 7143 | // SinkBB: V1 = PHI(V2, V3) |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7144 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 7145 | MachineFunction::iterator BBI = BB; |
| 7146 | ++BBI; |
| 7147 | MachineFunction *Fn = BB->getParent(); |
| 7148 | MachineBasicBlock *RSBBB = Fn->CreateMachineBasicBlock(LLVM_BB); |
| 7149 | MachineBasicBlock *SinkBB = Fn->CreateMachineBasicBlock(LLVM_BB); |
| 7150 | Fn->insert(BBI, RSBBB); |
| 7151 | Fn->insert(BBI, SinkBB); |
| 7152 | |
| 7153 | unsigned int ABSSrcReg = MI->getOperand(1).getReg(); |
| 7154 | unsigned int ABSDstReg = MI->getOperand(0).getReg(); |
| 7155 | bool isThumb2 = Subtarget->isThumb2(); |
| 7156 | MachineRegisterInfo &MRI = Fn->getRegInfo(); |
| 7157 | // In Thumb mode S must not be specified if source register is the SP or |
| 7158 | // PC and if destination register is the SP, so restrict register class |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 7159 | unsigned NewRsbDstReg = MRI.createVirtualRegister(isThumb2 ? |
| 7160 | (const TargetRegisterClass*)&ARM::rGPRRegClass : |
| 7161 | (const TargetRegisterClass*)&ARM::GPRRegClass); |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7162 | |
| 7163 | // Transfer the remainder of BB and its successor edges to sinkMBB. |
| 7164 | SinkBB->splice(SinkBB->begin(), BB, |
| 7165 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 7166 | BB->end()); |
| 7167 | SinkBB->transferSuccessorsAndUpdatePHIs(BB); |
| 7168 | |
| 7169 | BB->addSuccessor(RSBBB); |
| 7170 | BB->addSuccessor(SinkBB); |
| 7171 | |
| 7172 | // fall through to SinkMBB |
| 7173 | RSBBB->addSuccessor(SinkBB); |
| 7174 | |
Manman Ren | 307473d | 2012-06-15 21:32:12 +0000 | [diff] [blame] | 7175 | // insert a cmp at the end of BB |
Andrew Trick | 49b446f | 2012-07-18 18:34:24 +0000 | [diff] [blame] | 7176 | AddDefaultPred(BuildMI(BB, dl, |
Manman Ren | 307473d | 2012-06-15 21:32:12 +0000 | [diff] [blame] | 7177 | TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 7178 | .addReg(ABSSrcReg).addImm(0)); |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7179 | |
| 7180 | // 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] | 7181 | BuildMI(BB, dl, |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7182 | TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)).addMBB(SinkBB) |
| 7183 | .addImm(ARMCC::getOppositeCondition(ARMCC::MI)).addReg(ARM::CPSR); |
| 7184 | |
| 7185 | // insert rsbri in RSBBB |
| 7186 | // Note: BCC and rsbri will be converted into predicated rsbmi |
| 7187 | // by if-conversion pass |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 7188 | BuildMI(*RSBBB, RSBBB->begin(), dl, |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7189 | TII->get(isThumb2 ? ARM::t2RSBri : ARM::RSBri), NewRsbDstReg) |
Manman Ren | 307473d | 2012-06-15 21:32:12 +0000 | [diff] [blame] | 7190 | .addReg(ABSSrcReg, RegState::Kill) |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7191 | .addImm(0).addImm((unsigned)ARMCC::AL).addReg(0).addReg(0); |
| 7192 | |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 7193 | // insert PHI in SinkBB, |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7194 | // reuse ABSDstReg to not change uses of ABS instruction |
| 7195 | BuildMI(*SinkBB, SinkBB->begin(), dl, |
| 7196 | TII->get(ARM::PHI), ABSDstReg) |
| 7197 | .addReg(NewRsbDstReg).addMBB(RSBBB) |
Manman Ren | 307473d | 2012-06-15 21:32:12 +0000 | [diff] [blame] | 7198 | .addReg(ABSSrcReg).addMBB(BB); |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7199 | |
| 7200 | // remove ABS instruction |
Andrew Trick | 7f5f0da | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 7201 | MI->eraseFromParent(); |
Bill Wendling | ef2c86f | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 7202 | |
| 7203 | // return last added BB |
| 7204 | return SinkBB; |
| 7205 | } |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7206 | case ARM::COPY_STRUCT_BYVAL_I32: |
Manman Ren | 763a75d | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 7207 | ++NumLoopByVals; |
Manman Ren | 68f2557 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7208 | return EmitStructByval(MI, BB); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7209 | } |
| 7210 | } |
| 7211 | |
Evan Cheng | 37fefc2 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 7212 | void ARMTargetLowering::AdjustInstrPostInstrSelection(MachineInstr *MI, |
| 7213 | SDNode *Node) const { |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 7214 | if (!MI->hasPostISelHook()) { |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7215 | assert(!convertAddSubFlagsOpcode(MI->getOpcode()) && |
| 7216 | "Pseudo flag-setting opcodes must be marked with 'hasPostISelHook'"); |
| 7217 | return; |
| 7218 | } |
| 7219 | |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 7220 | const MCInstrDesc *MCID = &MI->getDesc(); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7221 | // Adjust potentially 's' setting instructions after isel, i.e. ADC, SBC, RSB, |
| 7222 | // RSC. Coming out of isel, they have an implicit CPSR def, but the optional |
| 7223 | // operand is still set to noreg. If needed, set the optional operand's |
| 7224 | // register to CPSR, and remove the redundant implicit def. |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7225 | // |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 7226 | // e.g. ADCS (..., CPSR<imp-def>) -> ADC (... opt:CPSR<def>). |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7227 | |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7228 | // Rename pseudo opcodes. |
| 7229 | unsigned NewOpc = convertAddSubFlagsOpcode(MI->getOpcode()); |
| 7230 | if (NewOpc) { |
| 7231 | const ARMBaseInstrInfo *TII = |
| 7232 | static_cast<const ARMBaseInstrInfo*>(getTargetMachine().getInstrInfo()); |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 7233 | MCID = &TII->get(NewOpc); |
| 7234 | |
| 7235 | assert(MCID->getNumOperands() == MI->getDesc().getNumOperands() + 1 && |
| 7236 | "converted opcode should be the same except for cc_out"); |
| 7237 | |
| 7238 | MI->setDesc(*MCID); |
| 7239 | |
| 7240 | // Add the optional cc_out operand |
| 7241 | MI->addOperand(MachineOperand::CreateReg(0, /*isDef=*/true)); |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7242 | } |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 7243 | unsigned ccOutIdx = MCID->getNumOperands() - 1; |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7244 | |
| 7245 | // Any ARM instruction that sets the 's' bit should specify an optional |
| 7246 | // "cc_out" operand in the last operand position. |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 7247 | if (!MI->hasOptionalDef() || !MCID->OpInfo[ccOutIdx].isOptionalDef()) { |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7248 | assert(!NewOpc && "Optional cc_out operand required"); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7249 | return; |
| 7250 | } |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7251 | // Look for an implicit def of CPSR added by MachineInstr ctor. Remove it |
| 7252 | // since we already have an optional CPSR def. |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7253 | bool definesCPSR = false; |
| 7254 | bool deadCPSR = false; |
Andrew Trick | 90b7b12 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 7255 | for (unsigned i = MCID->getNumOperands(), e = MI->getNumOperands(); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7256 | i != e; ++i) { |
| 7257 | const MachineOperand &MO = MI->getOperand(i); |
| 7258 | if (MO.isReg() && MO.isDef() && MO.getReg() == ARM::CPSR) { |
| 7259 | definesCPSR = true; |
| 7260 | if (MO.isDead()) |
| 7261 | deadCPSR = true; |
| 7262 | MI->RemoveOperand(i); |
| 7263 | break; |
Evan Cheng | 37fefc2 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 7264 | } |
| 7265 | } |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7266 | if (!definesCPSR) { |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7267 | assert(!NewOpc && "Optional cc_out operand required"); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7268 | return; |
| 7269 | } |
| 7270 | assert(deadCPSR == !Node->hasAnyUseOfValue(1) && "inconsistent dead flag"); |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7271 | if (deadCPSR) { |
| 7272 | assert(!MI->getOperand(ccOutIdx).getReg() && |
| 7273 | "expect uninitialized optional cc_out operand"); |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7274 | return; |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7275 | } |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7276 | |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 7277 | // If this instruction was defined with an optional CPSR def and its dag node |
| 7278 | // had a live implicit CPSR def, then activate the optional CPSR def. |
Andrew Trick | 4815d56 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 7279 | MachineOperand &MO = MI->getOperand(ccOutIdx); |
| 7280 | MO.setReg(ARM::CPSR); |
| 7281 | MO.setIsDef(true); |
Evan Cheng | 37fefc2 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 7282 | } |
| 7283 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7284 | //===----------------------------------------------------------------------===// |
| 7285 | // ARM Optimization Hooks |
| 7286 | //===----------------------------------------------------------------------===// |
| 7287 | |
Jakob Stoklund Olesen | 1f1ab3e | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7288 | // Helper function that checks if N is a null or all ones constant. |
| 7289 | static inline bool isZeroOrAllOnes(SDValue N, bool AllOnes) { |
| 7290 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(N); |
| 7291 | if (!C) |
| 7292 | return false; |
| 7293 | return AllOnes ? C->isAllOnesValue() : C->isNullValue(); |
| 7294 | } |
| 7295 | |
Jakob Stoklund Olesen | 864c870 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7296 | // Return true if N is conditionally 0 or all ones. |
| 7297 | // Detects these expressions where cc is an i1 value: |
| 7298 | // |
| 7299 | // (select cc 0, y) [AllOnes=0] |
| 7300 | // (select cc y, 0) [AllOnes=0] |
| 7301 | // (zext cc) [AllOnes=0] |
| 7302 | // (sext cc) [AllOnes=0/1] |
| 7303 | // (select cc -1, y) [AllOnes=1] |
| 7304 | // (select cc y, -1) [AllOnes=1] |
| 7305 | // |
| 7306 | // Invert is set when N is the null/all ones constant when CC is false. |
| 7307 | // OtherOp is set to the alternative value of N. |
| 7308 | static bool isConditionalZeroOrAllOnes(SDNode *N, bool AllOnes, |
| 7309 | SDValue &CC, bool &Invert, |
| 7310 | SDValue &OtherOp, |
| 7311 | SelectionDAG &DAG) { |
| 7312 | switch (N->getOpcode()) { |
| 7313 | default: return false; |
| 7314 | case ISD::SELECT: { |
| 7315 | CC = N->getOperand(0); |
| 7316 | SDValue N1 = N->getOperand(1); |
| 7317 | SDValue N2 = N->getOperand(2); |
| 7318 | if (isZeroOrAllOnes(N1, AllOnes)) { |
| 7319 | Invert = false; |
| 7320 | OtherOp = N2; |
| 7321 | return true; |
| 7322 | } |
| 7323 | if (isZeroOrAllOnes(N2, AllOnes)) { |
| 7324 | Invert = true; |
| 7325 | OtherOp = N1; |
| 7326 | return true; |
| 7327 | } |
| 7328 | return false; |
| 7329 | } |
| 7330 | case ISD::ZERO_EXTEND: |
| 7331 | // (zext cc) can never be the all ones value. |
| 7332 | if (AllOnes) |
| 7333 | return false; |
| 7334 | // Fall through. |
| 7335 | case ISD::SIGN_EXTEND: { |
| 7336 | EVT VT = N->getValueType(0); |
| 7337 | CC = N->getOperand(0); |
| 7338 | if (CC.getValueType() != MVT::i1) |
| 7339 | return false; |
| 7340 | Invert = !AllOnes; |
| 7341 | if (AllOnes) |
| 7342 | // When looking for an AllOnes constant, N is an sext, and the 'other' |
| 7343 | // value is 0. |
| 7344 | OtherOp = DAG.getConstant(0, VT); |
| 7345 | else if (N->getOpcode() == ISD::ZERO_EXTEND) |
| 7346 | // When looking for a 0 constant, N can be zext or sext. |
| 7347 | OtherOp = DAG.getConstant(1, VT); |
| 7348 | else |
| 7349 | OtherOp = DAG.getConstant(APInt::getAllOnesValue(VT.getSizeInBits()), VT); |
| 7350 | return true; |
| 7351 | } |
| 7352 | } |
| 7353 | } |
| 7354 | |
Jakob Stoklund Olesen | 1f1ab3e | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7355 | // Combine a constant select operand into its use: |
| 7356 | // |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7357 | // (add (select cc, 0, c), x) -> (select cc, x, (add, x, c)) |
| 7358 | // (sub x, (select cc, 0, c)) -> (select cc, x, (sub, x, c)) |
| 7359 | // (and (select cc, -1, c), x) -> (select cc, x, (and, x, c)) [AllOnes=1] |
| 7360 | // (or (select cc, 0, c), x) -> (select cc, x, (or, x, c)) |
| 7361 | // (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] | 7362 | // |
| 7363 | // 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] | 7364 | // is null, or all ones when AllOnes is set. |
Jakob Stoklund Olesen | 1f1ab3e | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7365 | // |
Jakob Stoklund Olesen | 864c870 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7366 | // Also recognize sext/zext from i1: |
| 7367 | // |
| 7368 | // (add (zext cc), x) -> (select cc (add x, 1), x) |
| 7369 | // (add (sext cc), x) -> (select cc (add x, -1), x) |
| 7370 | // |
| 7371 | // These transformations eventually create predicated instructions. |
| 7372 | // |
Jakob Stoklund Olesen | 1f1ab3e | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7373 | // @param N The node to transform. |
| 7374 | // @param Slct The N operand that is a select. |
| 7375 | // @param OtherOp The other N operand (x above). |
| 7376 | // @param DCI Context. |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7377 | // @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] | 7378 | // @returns The new node, or SDValue() on failure. |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7379 | static |
| 7380 | SDValue combineSelectAndUse(SDNode *N, SDValue Slct, SDValue OtherOp, |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7381 | TargetLowering::DAGCombinerInfo &DCI, |
| 7382 | bool AllOnes = false) { |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7383 | SelectionDAG &DAG = DCI.DAG; |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7384 | EVT VT = N->getValueType(0); |
Jakob Stoklund Olesen | 864c870 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7385 | SDValue NonConstantVal; |
| 7386 | SDValue CCOp; |
| 7387 | bool SwapSelectOps; |
| 7388 | if (!isConditionalZeroOrAllOnes(Slct.getNode(), AllOnes, CCOp, SwapSelectOps, |
| 7389 | NonConstantVal, DAG)) |
Jakob Stoklund Olesen | 1f1ab3e | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7390 | return SDValue(); |
| 7391 | |
Jakob Stoklund Olesen | 864c870 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7392 | // Slct is now know to be the desired identity constant when CC is true. |
| 7393 | SDValue TrueVal = OtherOp; |
| 7394 | SDValue FalseVal = DAG.getNode(N->getOpcode(), N->getDebugLoc(), VT, |
| 7395 | OtherOp, NonConstantVal); |
| 7396 | // Unless SwapSelectOps says CC should be false. |
| 7397 | if (SwapSelectOps) |
| 7398 | std::swap(TrueVal, FalseVal); |
| 7399 | |
Jakob Stoklund Olesen | 1f1ab3e | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 7400 | return DAG.getNode(ISD::SELECT, N->getDebugLoc(), VT, |
Jakob Stoklund Olesen | 864c870 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7401 | CCOp, TrueVal, FalseVal); |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7402 | } |
| 7403 | |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7404 | // Attempt combineSelectAndUse on each operand of a commutative operator N. |
| 7405 | static |
| 7406 | SDValue combineSelectAndUseCommutative(SDNode *N, bool AllOnes, |
| 7407 | TargetLowering::DAGCombinerInfo &DCI) { |
| 7408 | SDValue N0 = N->getOperand(0); |
| 7409 | SDValue N1 = N->getOperand(1); |
Jakob Stoklund Olesen | 864c870 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7410 | if (N0.getNode()->hasOneUse()) { |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7411 | SDValue Result = combineSelectAndUse(N, N0, N1, DCI, AllOnes); |
| 7412 | if (Result.getNode()) |
| 7413 | return Result; |
| 7414 | } |
Jakob Stoklund Olesen | 864c870 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 7415 | if (N1.getNode()->hasOneUse()) { |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7416 | SDValue Result = combineSelectAndUse(N, N1, N0, DCI, AllOnes); |
| 7417 | if (Result.getNode()) |
| 7418 | return Result; |
| 7419 | } |
| 7420 | return SDValue(); |
| 7421 | } |
| 7422 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7423 | // AddCombineToVPADDL- For pair-wise add on neon, use the vpaddl instruction |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7424 | // (only after legalization). |
| 7425 | static SDValue AddCombineToVPADDL(SDNode *N, SDValue N0, SDValue N1, |
| 7426 | TargetLowering::DAGCombinerInfo &DCI, |
| 7427 | const ARMSubtarget *Subtarget) { |
| 7428 | |
| 7429 | // Only perform optimization if after legalize, and if NEON is available. We |
| 7430 | // also expected both operands to be BUILD_VECTORs. |
| 7431 | if (DCI.isBeforeLegalize() || !Subtarget->hasNEON() |
| 7432 | || N0.getOpcode() != ISD::BUILD_VECTOR |
| 7433 | || N1.getOpcode() != ISD::BUILD_VECTOR) |
| 7434 | return SDValue(); |
| 7435 | |
| 7436 | // Check output type since VPADDL operand elements can only be 8, 16, or 32. |
| 7437 | EVT VT = N->getValueType(0); |
| 7438 | if (!VT.isInteger() || VT.getVectorElementType() == MVT::i64) |
| 7439 | return SDValue(); |
| 7440 | |
| 7441 | // Check that the vector operands are of the right form. |
| 7442 | // N0 and N1 are BUILD_VECTOR nodes with N number of EXTRACT_VECTOR |
| 7443 | // operands, where N is the size of the formed vector. |
| 7444 | // Each EXTRACT_VECTOR should have the same input vector and odd or even |
| 7445 | // index such that we have a pair wise add pattern. |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7446 | |
| 7447 | // Grab the vector that all EXTRACT_VECTOR nodes should be referencing. |
Bob Wilson | 7a10ab7 | 2011-06-15 06:04:34 +0000 | [diff] [blame] | 7448 | if (N0->getOperand(0)->getOpcode() != ISD::EXTRACT_VECTOR_ELT) |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7449 | return SDValue(); |
Bob Wilson | 7a10ab7 | 2011-06-15 06:04:34 +0000 | [diff] [blame] | 7450 | SDValue Vec = N0->getOperand(0)->getOperand(0); |
| 7451 | SDNode *V = Vec.getNode(); |
| 7452 | unsigned nextIndex = 0; |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7453 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7454 | // For each operands to the ADD which are BUILD_VECTORs, |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7455 | // check to see if each of their operands are an EXTRACT_VECTOR with |
| 7456 | // the same vector and appropriate index. |
| 7457 | for (unsigned i = 0, e = N0->getNumOperands(); i != e; ++i) { |
| 7458 | if (N0->getOperand(i)->getOpcode() == ISD::EXTRACT_VECTOR_ELT |
| 7459 | && N1->getOperand(i)->getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7460 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7461 | SDValue ExtVec0 = N0->getOperand(i); |
| 7462 | SDValue ExtVec1 = N1->getOperand(i); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7463 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7464 | // First operand is the vector, verify its the same. |
| 7465 | if (V != ExtVec0->getOperand(0).getNode() || |
| 7466 | V != ExtVec1->getOperand(0).getNode()) |
| 7467 | return SDValue(); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7468 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7469 | // Second is the constant, verify its correct. |
| 7470 | ConstantSDNode *C0 = dyn_cast<ConstantSDNode>(ExtVec0->getOperand(1)); |
| 7471 | ConstantSDNode *C1 = dyn_cast<ConstantSDNode>(ExtVec1->getOperand(1)); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7472 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7473 | // For the constant, we want to see all the even or all the odd. |
| 7474 | if (!C0 || !C1 || C0->getZExtValue() != nextIndex |
| 7475 | || C1->getZExtValue() != nextIndex+1) |
| 7476 | return SDValue(); |
| 7477 | |
| 7478 | // Increment index. |
| 7479 | nextIndex+=2; |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7480 | } else |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7481 | return SDValue(); |
| 7482 | } |
| 7483 | |
| 7484 | // Create VPADDL node. |
| 7485 | SelectionDAG &DAG = DCI.DAG; |
| 7486 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7487 | |
| 7488 | // Build operand list. |
| 7489 | SmallVector<SDValue, 8> Ops; |
| 7490 | Ops.push_back(DAG.getConstant(Intrinsic::arm_neon_vpaddls, |
| 7491 | TLI.getPointerTy())); |
| 7492 | |
| 7493 | // Input is the vector. |
| 7494 | Ops.push_back(Vec); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7495 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7496 | // Get widened type and narrowed type. |
| 7497 | MVT widenType; |
| 7498 | unsigned numElem = VT.getVectorNumElements(); |
| 7499 | switch (VT.getVectorElementType().getSimpleVT().SimpleTy) { |
| 7500 | case MVT::i8: widenType = MVT::getVectorVT(MVT::i16, numElem); break; |
| 7501 | case MVT::i16: widenType = MVT::getVectorVT(MVT::i32, numElem); break; |
| 7502 | case MVT::i32: widenType = MVT::getVectorVT(MVT::i64, numElem); break; |
| 7503 | default: |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 7504 | llvm_unreachable("Invalid vector element type for padd optimization."); |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7505 | } |
| 7506 | |
| 7507 | SDValue tmp = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, N->getDebugLoc(), |
| 7508 | widenType, &Ops[0], Ops.size()); |
| 7509 | return DAG.getNode(ISD::TRUNCATE, N->getDebugLoc(), VT, tmp); |
| 7510 | } |
| 7511 | |
Arnold Schwaighofer | 67514e9 | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 7512 | static SDValue findMUL_LOHI(SDValue V) { |
| 7513 | if (V->getOpcode() == ISD::UMUL_LOHI || |
| 7514 | V->getOpcode() == ISD::SMUL_LOHI) |
| 7515 | return V; |
| 7516 | return SDValue(); |
| 7517 | } |
| 7518 | |
| 7519 | static SDValue AddCombineTo64bitMLAL(SDNode *AddcNode, |
| 7520 | TargetLowering::DAGCombinerInfo &DCI, |
| 7521 | const ARMSubtarget *Subtarget) { |
| 7522 | |
| 7523 | if (Subtarget->isThumb1Only()) return SDValue(); |
| 7524 | |
| 7525 | // Only perform the checks after legalize when the pattern is available. |
| 7526 | if (DCI.isBeforeLegalize()) return SDValue(); |
| 7527 | |
| 7528 | // Look for multiply add opportunities. |
| 7529 | // The pattern is a ISD::UMUL_LOHI followed by two add nodes, where |
| 7530 | // each add nodes consumes a value from ISD::UMUL_LOHI and there is |
| 7531 | // a glue link from the first add to the second add. |
| 7532 | // If we find this pattern, we can replace the U/SMUL_LOHI, ADDC, and ADDE by |
| 7533 | // a S/UMLAL instruction. |
| 7534 | // loAdd UMUL_LOHI |
| 7535 | // \ / :lo \ :hi |
| 7536 | // \ / \ [no multiline comment] |
| 7537 | // ADDC | hiAdd |
| 7538 | // \ :glue / / |
| 7539 | // \ / / |
| 7540 | // ADDE |
| 7541 | // |
| 7542 | assert(AddcNode->getOpcode() == ISD::ADDC && "Expect an ADDC"); |
| 7543 | SDValue AddcOp0 = AddcNode->getOperand(0); |
| 7544 | SDValue AddcOp1 = AddcNode->getOperand(1); |
| 7545 | |
| 7546 | // Check if the two operands are from the same mul_lohi node. |
| 7547 | if (AddcOp0.getNode() == AddcOp1.getNode()) |
| 7548 | return SDValue(); |
| 7549 | |
| 7550 | assert(AddcNode->getNumValues() == 2 && |
| 7551 | AddcNode->getValueType(0) == MVT::i32 && |
| 7552 | AddcNode->getValueType(1) == MVT::Glue && |
| 7553 | "Expect ADDC with two result values: i32, glue"); |
| 7554 | |
| 7555 | // Check that the ADDC adds the low result of the S/UMUL_LOHI. |
| 7556 | if (AddcOp0->getOpcode() != ISD::UMUL_LOHI && |
| 7557 | AddcOp0->getOpcode() != ISD::SMUL_LOHI && |
| 7558 | AddcOp1->getOpcode() != ISD::UMUL_LOHI && |
| 7559 | AddcOp1->getOpcode() != ISD::SMUL_LOHI) |
| 7560 | return SDValue(); |
| 7561 | |
| 7562 | // Look for the glued ADDE. |
| 7563 | SDNode* AddeNode = AddcNode->getGluedUser(); |
| 7564 | if (AddeNode == NULL) |
| 7565 | return SDValue(); |
| 7566 | |
| 7567 | // Make sure it is really an ADDE. |
| 7568 | if (AddeNode->getOpcode() != ISD::ADDE) |
| 7569 | return SDValue(); |
| 7570 | |
| 7571 | assert(AddeNode->getNumOperands() == 3 && |
| 7572 | AddeNode->getOperand(2).getValueType() == MVT::Glue && |
| 7573 | "ADDE node has the wrong inputs"); |
| 7574 | |
| 7575 | // Check for the triangle shape. |
| 7576 | SDValue AddeOp0 = AddeNode->getOperand(0); |
| 7577 | SDValue AddeOp1 = AddeNode->getOperand(1); |
| 7578 | |
| 7579 | // Make sure that the ADDE operands are not coming from the same node. |
| 7580 | if (AddeOp0.getNode() == AddeOp1.getNode()) |
| 7581 | return SDValue(); |
| 7582 | |
| 7583 | // Find the MUL_LOHI node walking up ADDE's operands. |
| 7584 | bool IsLeftOperandMUL = false; |
| 7585 | SDValue MULOp = findMUL_LOHI(AddeOp0); |
| 7586 | if (MULOp == SDValue()) |
| 7587 | MULOp = findMUL_LOHI(AddeOp1); |
| 7588 | else |
| 7589 | IsLeftOperandMUL = true; |
| 7590 | if (MULOp == SDValue()) |
| 7591 | return SDValue(); |
| 7592 | |
| 7593 | // Figure out the right opcode. |
| 7594 | unsigned Opc = MULOp->getOpcode(); |
| 7595 | unsigned FinalOpc = (Opc == ISD::SMUL_LOHI) ? ARMISD::SMLAL : ARMISD::UMLAL; |
| 7596 | |
| 7597 | // Figure out the high and low input values to the MLAL node. |
| 7598 | SDValue* HiMul = &MULOp; |
| 7599 | SDValue* HiAdd = NULL; |
| 7600 | SDValue* LoMul = NULL; |
| 7601 | SDValue* LowAdd = NULL; |
| 7602 | |
| 7603 | if (IsLeftOperandMUL) |
| 7604 | HiAdd = &AddeOp1; |
| 7605 | else |
| 7606 | HiAdd = &AddeOp0; |
| 7607 | |
| 7608 | |
| 7609 | if (AddcOp0->getOpcode() == Opc) { |
| 7610 | LoMul = &AddcOp0; |
| 7611 | LowAdd = &AddcOp1; |
| 7612 | } |
| 7613 | if (AddcOp1->getOpcode() == Opc) { |
| 7614 | LoMul = &AddcOp1; |
| 7615 | LowAdd = &AddcOp0; |
| 7616 | } |
| 7617 | |
| 7618 | if (LoMul == NULL) |
| 7619 | return SDValue(); |
| 7620 | |
| 7621 | if (LoMul->getNode() != HiMul->getNode()) |
| 7622 | return SDValue(); |
| 7623 | |
| 7624 | // Create the merged node. |
| 7625 | SelectionDAG &DAG = DCI.DAG; |
| 7626 | |
| 7627 | // Build operand list. |
| 7628 | SmallVector<SDValue, 8> Ops; |
| 7629 | Ops.push_back(LoMul->getOperand(0)); |
| 7630 | Ops.push_back(LoMul->getOperand(1)); |
| 7631 | Ops.push_back(*LowAdd); |
| 7632 | Ops.push_back(*HiAdd); |
| 7633 | |
| 7634 | SDValue MLALNode = DAG.getNode(FinalOpc, AddcNode->getDebugLoc(), |
| 7635 | DAG.getVTList(MVT::i32, MVT::i32), |
| 7636 | &Ops[0], Ops.size()); |
| 7637 | |
| 7638 | // Replace the ADDs' nodes uses by the MLA node's values. |
| 7639 | SDValue HiMLALResult(MLALNode.getNode(), 1); |
| 7640 | DAG.ReplaceAllUsesOfValueWith(SDValue(AddeNode, 0), HiMLALResult); |
| 7641 | |
| 7642 | SDValue LoMLALResult(MLALNode.getNode(), 0); |
| 7643 | DAG.ReplaceAllUsesOfValueWith(SDValue(AddcNode, 0), LoMLALResult); |
| 7644 | |
| 7645 | // Return original node to notify the driver to stop replacing. |
| 7646 | SDValue resNode(AddcNode, 0); |
| 7647 | return resNode; |
| 7648 | } |
| 7649 | |
| 7650 | /// PerformADDCCombine - Target-specific dag combine transform from |
| 7651 | /// ISD::ADDC, ISD::ADDE, and ISD::MUL_LOHI to MLAL. |
| 7652 | static SDValue PerformADDCCombine(SDNode *N, |
| 7653 | TargetLowering::DAGCombinerInfo &DCI, |
| 7654 | const ARMSubtarget *Subtarget) { |
| 7655 | |
| 7656 | return AddCombineTo64bitMLAL(N, DCI, Subtarget); |
| 7657 | |
| 7658 | } |
| 7659 | |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 7660 | /// PerformADDCombineWithOperands - Try DAG combinations for an ADD with |
| 7661 | /// operands N0 and N1. This is a helper for PerformADDCombine that is |
| 7662 | /// called with the default operands, and if that fails, with commuted |
| 7663 | /// operands. |
| 7664 | static SDValue PerformADDCombineWithOperands(SDNode *N, SDValue N0, SDValue N1, |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7665 | TargetLowering::DAGCombinerInfo &DCI, |
| 7666 | const ARMSubtarget *Subtarget){ |
| 7667 | |
| 7668 | // Attempt to create vpaddl for this add. |
| 7669 | SDValue Result = AddCombineToVPADDL(N, N0, N1, DCI, Subtarget); |
| 7670 | if (Result.getNode()) |
| 7671 | return Result; |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 7672 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7673 | // 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] | 7674 | if (N0.getNode()->hasOneUse()) { |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7675 | SDValue Result = combineSelectAndUse(N, N0, N1, DCI); |
| 7676 | if (Result.getNode()) return Result; |
| 7677 | } |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7678 | return SDValue(); |
| 7679 | } |
| 7680 | |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 7681 | /// PerformADDCombine - Target-specific dag combine xforms for ISD::ADD. |
| 7682 | /// |
| 7683 | static SDValue PerformADDCombine(SDNode *N, |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7684 | TargetLowering::DAGCombinerInfo &DCI, |
| 7685 | const ARMSubtarget *Subtarget) { |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 7686 | SDValue N0 = N->getOperand(0); |
| 7687 | SDValue N1 = N->getOperand(1); |
| 7688 | |
| 7689 | // First try with the default operand order. |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7690 | SDValue Result = PerformADDCombineWithOperands(N, N0, N1, DCI, Subtarget); |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 7691 | if (Result.getNode()) |
| 7692 | return Result; |
| 7693 | |
| 7694 | // If that didn't work, try again with the operands commuted. |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7695 | return PerformADDCombineWithOperands(N, N1, N0, DCI, Subtarget); |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 7696 | } |
| 7697 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7698 | /// PerformSUBCombine - Target-specific dag combine xforms for ISD::SUB. |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 7699 | /// |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7700 | static SDValue PerformSUBCombine(SDNode *N, |
| 7701 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 7702 | SDValue N0 = N->getOperand(0); |
| 7703 | SDValue N1 = N->getOperand(1); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 7704 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7705 | // 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] | 7706 | if (N1.getNode()->hasOneUse()) { |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7707 | SDValue Result = combineSelectAndUse(N, N1, N0, DCI); |
| 7708 | if (Result.getNode()) return Result; |
| 7709 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 7710 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 7711 | return SDValue(); |
| 7712 | } |
| 7713 | |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 7714 | /// PerformVMULCombine |
| 7715 | /// Distribute (A + B) * C to (A * C) + (B * C) to take advantage of the |
| 7716 | /// special multiplier accumulator forwarding. |
| 7717 | /// vmul d3, d0, d2 |
| 7718 | /// vmla d3, d1, d2 |
| 7719 | /// is faster than |
| 7720 | /// vadd d3, d0, d1 |
| 7721 | /// vmul d3, d3, d2 |
| 7722 | static SDValue PerformVMULCombine(SDNode *N, |
| 7723 | TargetLowering::DAGCombinerInfo &DCI, |
| 7724 | const ARMSubtarget *Subtarget) { |
| 7725 | if (!Subtarget->hasVMLxForwarding()) |
| 7726 | return SDValue(); |
| 7727 | |
| 7728 | SelectionDAG &DAG = DCI.DAG; |
| 7729 | SDValue N0 = N->getOperand(0); |
| 7730 | SDValue N1 = N->getOperand(1); |
| 7731 | unsigned Opcode = N0.getOpcode(); |
| 7732 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
| 7733 | Opcode != ISD::FADD && Opcode != ISD::FSUB) { |
Chad Rosier | 689edc8 | 2011-06-16 01:21:54 +0000 | [diff] [blame] | 7734 | Opcode = N1.getOpcode(); |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 7735 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
| 7736 | Opcode != ISD::FADD && Opcode != ISD::FSUB) |
| 7737 | return SDValue(); |
| 7738 | std::swap(N0, N1); |
| 7739 | } |
| 7740 | |
| 7741 | EVT VT = N->getValueType(0); |
| 7742 | DebugLoc DL = N->getDebugLoc(); |
| 7743 | SDValue N00 = N0->getOperand(0); |
| 7744 | SDValue N01 = N0->getOperand(1); |
| 7745 | return DAG.getNode(Opcode, DL, VT, |
| 7746 | DAG.getNode(ISD::MUL, DL, VT, N00, N1), |
| 7747 | DAG.getNode(ISD::MUL, DL, VT, N01, N1)); |
| 7748 | } |
| 7749 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 7750 | static SDValue PerformMULCombine(SDNode *N, |
| 7751 | TargetLowering::DAGCombinerInfo &DCI, |
| 7752 | const ARMSubtarget *Subtarget) { |
| 7753 | SelectionDAG &DAG = DCI.DAG; |
| 7754 | |
| 7755 | if (Subtarget->isThumb1Only()) |
| 7756 | return SDValue(); |
| 7757 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 7758 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 7759 | return SDValue(); |
| 7760 | |
| 7761 | EVT VT = N->getValueType(0); |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 7762 | if (VT.is64BitVector() || VT.is128BitVector()) |
| 7763 | return PerformVMULCombine(N, DCI, Subtarget); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 7764 | if (VT != MVT::i32) |
| 7765 | return SDValue(); |
| 7766 | |
| 7767 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1)); |
| 7768 | if (!C) |
| 7769 | return SDValue(); |
| 7770 | |
Anton Korobeynikov | 2d7ea04 | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 7771 | int64_t MulAmt = C->getSExtValue(); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 7772 | unsigned ShiftAmt = CountTrailingZeros_64(MulAmt); |
Anton Korobeynikov | 2d7ea04 | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 7773 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 7774 | ShiftAmt = ShiftAmt & (32 - 1); |
| 7775 | SDValue V = N->getOperand(0); |
| 7776 | DebugLoc DL = N->getDebugLoc(); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 7777 | |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 7778 | SDValue Res; |
| 7779 | MulAmt >>= ShiftAmt; |
Anton Korobeynikov | 2d7ea04 | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 7780 | |
| 7781 | if (MulAmt >= 0) { |
| 7782 | if (isPowerOf2_32(MulAmt - 1)) { |
| 7783 | // (mul x, 2^N + 1) => (add (shl x, N), x) |
| 7784 | Res = DAG.getNode(ISD::ADD, DL, VT, |
| 7785 | V, |
| 7786 | DAG.getNode(ISD::SHL, DL, VT, |
| 7787 | V, |
| 7788 | DAG.getConstant(Log2_32(MulAmt - 1), |
| 7789 | MVT::i32))); |
| 7790 | } else if (isPowerOf2_32(MulAmt + 1)) { |
| 7791 | // (mul x, 2^N - 1) => (sub (shl x, N), x) |
| 7792 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 7793 | DAG.getNode(ISD::SHL, DL, VT, |
| 7794 | V, |
| 7795 | DAG.getConstant(Log2_32(MulAmt + 1), |
| 7796 | MVT::i32)), |
| 7797 | V); |
| 7798 | } else |
| 7799 | return SDValue(); |
| 7800 | } else { |
| 7801 | uint64_t MulAmtAbs = -MulAmt; |
| 7802 | if (isPowerOf2_32(MulAmtAbs + 1)) { |
| 7803 | // (mul x, -(2^N - 1)) => (sub x, (shl x, N)) |
| 7804 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 7805 | V, |
| 7806 | DAG.getNode(ISD::SHL, DL, VT, |
| 7807 | V, |
| 7808 | DAG.getConstant(Log2_32(MulAmtAbs + 1), |
| 7809 | MVT::i32))); |
| 7810 | } else if (isPowerOf2_32(MulAmtAbs - 1)) { |
| 7811 | // (mul x, -(2^N + 1)) => - (add (shl x, N), x) |
| 7812 | Res = DAG.getNode(ISD::ADD, DL, VT, |
| 7813 | V, |
| 7814 | DAG.getNode(ISD::SHL, DL, VT, |
| 7815 | V, |
| 7816 | DAG.getConstant(Log2_32(MulAmtAbs-1), |
| 7817 | MVT::i32))); |
| 7818 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 7819 | DAG.getConstant(0, MVT::i32),Res); |
| 7820 | |
| 7821 | } else |
| 7822 | return SDValue(); |
| 7823 | } |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 7824 | |
| 7825 | if (ShiftAmt != 0) |
Anton Korobeynikov | 2d7ea04 | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 7826 | Res = DAG.getNode(ISD::SHL, DL, VT, |
| 7827 | Res, DAG.getConstant(ShiftAmt, MVT::i32)); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 7828 | |
| 7829 | // Do not add new nodes to DAG combiner worklist. |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 7830 | DCI.CombineTo(N, Res, false); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 7831 | return SDValue(); |
| 7832 | } |
| 7833 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 7834 | static SDValue PerformANDCombine(SDNode *N, |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 7835 | TargetLowering::DAGCombinerInfo &DCI, |
| 7836 | const ARMSubtarget *Subtarget) { |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 7837 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 7838 | // Attempt to use immediate-form VBIC |
| 7839 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| 7840 | DebugLoc dl = N->getDebugLoc(); |
| 7841 | EVT VT = N->getValueType(0); |
| 7842 | SelectionDAG &DAG = DCI.DAG; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7843 | |
Tanya Lattner | 0433b21 | 2011-04-07 15:24:20 +0000 | [diff] [blame] | 7844 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 7845 | return SDValue(); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 7846 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 7847 | APInt SplatBits, SplatUndef; |
| 7848 | unsigned SplatBitSize; |
| 7849 | bool HasAnyUndefs; |
| 7850 | if (BVN && |
| 7851 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 7852 | if (SplatBitSize <= 64) { |
| 7853 | EVT VbicVT; |
| 7854 | SDValue Val = isNEONModifiedImm((~SplatBits).getZExtValue(), |
| 7855 | SplatUndef.getZExtValue(), SplatBitSize, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7856 | DAG, VbicVT, VT.is128BitVector(), |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 7857 | OtherModImm); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 7858 | if (Val.getNode()) { |
| 7859 | SDValue Input = |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7860 | DAG.getNode(ISD::BITCAST, dl, VbicVT, N->getOperand(0)); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 7861 | SDValue Vbic = DAG.getNode(ARMISD::VBICIMM, dl, VbicVT, Input, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7862 | return DAG.getNode(ISD::BITCAST, dl, VT, Vbic); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 7863 | } |
| 7864 | } |
| 7865 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7866 | |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 7867 | if (!Subtarget->isThumb1Only()) { |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7868 | // fold (and (select cc, -1, c), x) -> (select cc, x, (and, x, c)) |
| 7869 | SDValue Result = combineSelectAndUseCommutative(N, true, DCI); |
| 7870 | if (Result.getNode()) |
| 7871 | return Result; |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 7872 | } |
| 7873 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 7874 | return SDValue(); |
| 7875 | } |
| 7876 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7877 | /// PerformORCombine - Target-specific dag combine xforms for ISD::OR |
| 7878 | static SDValue PerformORCombine(SDNode *N, |
| 7879 | TargetLowering::DAGCombinerInfo &DCI, |
| 7880 | const ARMSubtarget *Subtarget) { |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 7881 | // Attempt to use immediate-form VORR |
| 7882 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| 7883 | DebugLoc dl = N->getDebugLoc(); |
| 7884 | EVT VT = N->getValueType(0); |
| 7885 | SelectionDAG &DAG = DCI.DAG; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7886 | |
Tanya Lattner | 0433b21 | 2011-04-07 15:24:20 +0000 | [diff] [blame] | 7887 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 7888 | return SDValue(); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 7889 | |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 7890 | APInt SplatBits, SplatUndef; |
| 7891 | unsigned SplatBitSize; |
| 7892 | bool HasAnyUndefs; |
| 7893 | if (BVN && Subtarget->hasNEON() && |
| 7894 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 7895 | if (SplatBitSize <= 64) { |
| 7896 | EVT VorrVT; |
| 7897 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
| 7898 | SplatUndef.getZExtValue(), SplatBitSize, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 7899 | DAG, VorrVT, VT.is128BitVector(), |
| 7900 | OtherModImm); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 7901 | if (Val.getNode()) { |
| 7902 | SDValue Input = |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7903 | DAG.getNode(ISD::BITCAST, dl, VorrVT, N->getOperand(0)); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 7904 | SDValue Vorr = DAG.getNode(ARMISD::VORRIMM, dl, VorrVT, Input, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7905 | return DAG.getNode(ISD::BITCAST, dl, VT, Vorr); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 7906 | } |
| 7907 | } |
| 7908 | } |
| 7909 | |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 7910 | if (!Subtarget->isThumb1Only()) { |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 7911 | // fold (or (select cc, 0, c), x) -> (select cc, x, (or, x, c)) |
| 7912 | SDValue Result = combineSelectAndUseCommutative(N, false, DCI); |
| 7913 | if (Result.getNode()) |
| 7914 | return Result; |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 7915 | } |
| 7916 | |
Nadav Rotem | df83203 | 2012-08-13 18:52:44 +0000 | [diff] [blame] | 7917 | // The code below optimizes (or (and X, Y), Z). |
| 7918 | // The AND operand needs to have a single user to make these optimizations |
| 7919 | // profitable. |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 7920 | SDValue N0 = N->getOperand(0); |
Nadav Rotem | df83203 | 2012-08-13 18:52:44 +0000 | [diff] [blame] | 7921 | if (N0.getOpcode() != ISD::AND || !N0.hasOneUse()) |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 7922 | return SDValue(); |
| 7923 | SDValue N1 = N->getOperand(1); |
| 7924 | |
| 7925 | // (or (and B, A), (and C, ~A)) => (VBSL A, B, C) when A is a constant. |
| 7926 | if (Subtarget->hasNEON() && N1.getOpcode() == ISD::AND && VT.isVector() && |
| 7927 | DAG.getTargetLoweringInfo().isTypeLegal(VT)) { |
| 7928 | APInt SplatUndef; |
| 7929 | unsigned SplatBitSize; |
| 7930 | bool HasAnyUndefs; |
| 7931 | |
| 7932 | BuildVectorSDNode *BVN0 = dyn_cast<BuildVectorSDNode>(N0->getOperand(1)); |
| 7933 | APInt SplatBits0; |
| 7934 | if (BVN0 && BVN0->isConstantSplat(SplatBits0, SplatUndef, SplatBitSize, |
| 7935 | HasAnyUndefs) && !HasAnyUndefs) { |
| 7936 | BuildVectorSDNode *BVN1 = dyn_cast<BuildVectorSDNode>(N1->getOperand(1)); |
| 7937 | APInt SplatBits1; |
| 7938 | if (BVN1 && BVN1->isConstantSplat(SplatBits1, SplatUndef, SplatBitSize, |
| 7939 | HasAnyUndefs) && !HasAnyUndefs && |
| 7940 | SplatBits0 == ~SplatBits1) { |
| 7941 | // Canonicalize the vector type to make instruction selection simpler. |
| 7942 | EVT CanonicalVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 7943 | SDValue Result = DAG.getNode(ARMISD::VBSL, dl, CanonicalVT, |
| 7944 | N0->getOperand(1), N0->getOperand(0), |
Cameron Zwarich | 5af60ce | 2011-04-13 21:01:19 +0000 | [diff] [blame] | 7945 | N1->getOperand(0)); |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 7946 | return DAG.getNode(ISD::BITCAST, dl, VT, Result); |
| 7947 | } |
| 7948 | } |
| 7949 | } |
| 7950 | |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7951 | // Try to use the ARM/Thumb2 BFI (bitfield insert) instruction when |
| 7952 | // reasonable. |
| 7953 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7954 | // BFI is only available on V6T2+ |
| 7955 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6T2Ops()) |
| 7956 | return SDValue(); |
| 7957 | |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7958 | DebugLoc DL = N->getDebugLoc(); |
| 7959 | // 1) or (and A, mask), val => ARMbfi A, val, mask |
Sylvestre Ledru | 94c2271 | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 7960 | // iff (val & mask) == val |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7961 | // |
| 7962 | // 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] | 7963 | // 2a) iff isBitFieldInvertedMask(mask) && isBitFieldInvertedMask(~mask2) |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7964 | // && mask == ~mask2 |
Sylvestre Ledru | 94c2271 | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 7965 | // 2b) iff isBitFieldInvertedMask(~mask) && isBitFieldInvertedMask(mask2) |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 7966 | // && ~mask == mask2 |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7967 | // (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] | 7968 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7969 | if (VT != MVT::i32) |
| 7970 | return SDValue(); |
| 7971 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7972 | SDValue N00 = N0.getOperand(0); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7973 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7974 | // The value and the mask need to be constants so we can verify this is |
| 7975 | // actually a bitfield set. If the mask is 0xffff, we can do better |
| 7976 | // via a movt instruction, so don't use BFI in that case. |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7977 | SDValue MaskOp = N0.getOperand(1); |
| 7978 | ConstantSDNode *MaskC = dyn_cast<ConstantSDNode>(MaskOp); |
| 7979 | if (!MaskC) |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7980 | return SDValue(); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7981 | unsigned Mask = MaskC->getZExtValue(); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7982 | if (Mask == 0xffff) |
| 7983 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7984 | SDValue Res; |
| 7985 | // Case (1): or (and A, mask), val => ARMbfi A, val, mask |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7986 | ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1); |
| 7987 | if (N1C) { |
| 7988 | unsigned Val = N1C->getZExtValue(); |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 7989 | if ((Val & ~Mask) != Val) |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 7990 | return SDValue(); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7991 | |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 7992 | if (ARM::isBitFieldInvertedMask(Mask)) { |
| 7993 | Val >>= CountTrailingZeros_32(~Mask); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7994 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 7995 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 7996 | DAG.getConstant(Val, MVT::i32), |
| 7997 | DAG.getConstant(Mask, MVT::i32)); |
| 7998 | |
| 7999 | // Do not add new nodes to DAG combiner worklist. |
| 8000 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8001 | return SDValue(); |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 8002 | } |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8003 | } else if (N1.getOpcode() == ISD::AND) { |
| 8004 | // 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] | 8005 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 8006 | if (!N11C) |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8007 | return SDValue(); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8008 | unsigned Mask2 = N11C->getZExtValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8009 | |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8010 | // Mask and ~Mask2 (or reverse) must be equivalent for the BFI pattern |
| 8011 | // as is to match. |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8012 | if (ARM::isBitFieldInvertedMask(Mask) && |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8013 | (Mask == ~Mask2)) { |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8014 | // The pack halfword instruction works better for masks that fit it, |
| 8015 | // so use that when it's available. |
| 8016 | if (Subtarget->hasT2ExtractPack() && |
| 8017 | (Mask == 0xffff || Mask == 0xffff0000)) |
| 8018 | return SDValue(); |
| 8019 | // 2a |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8020 | unsigned amt = CountTrailingZeros_32(Mask2); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8021 | Res = DAG.getNode(ISD::SRL, DL, VT, N1.getOperand(0), |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8022 | DAG.getConstant(amt, MVT::i32)); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8023 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, Res, |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8024 | DAG.getConstant(Mask, MVT::i32)); |
| 8025 | // Do not add new nodes to DAG combiner worklist. |
| 8026 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8027 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8028 | } else if (ARM::isBitFieldInvertedMask(~Mask) && |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8029 | (~Mask == Mask2)) { |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8030 | // The pack halfword instruction works better for masks that fit it, |
| 8031 | // so use that when it's available. |
| 8032 | if (Subtarget->hasT2ExtractPack() && |
| 8033 | (Mask2 == 0xffff || Mask2 == 0xffff0000)) |
| 8034 | return SDValue(); |
| 8035 | // 2b |
| 8036 | unsigned lsb = CountTrailingZeros_32(Mask); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8037 | Res = DAG.getNode(ISD::SRL, DL, VT, N00, |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8038 | DAG.getConstant(lsb, MVT::i32)); |
| 8039 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1.getOperand(0), Res, |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8040 | DAG.getConstant(Mask2, MVT::i32)); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8041 | // Do not add new nodes to DAG combiner worklist. |
| 8042 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8043 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8044 | } |
| 8045 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8046 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8047 | if (DAG.MaskedValueIsZero(N1, MaskC->getAPIntValue()) && |
| 8048 | N00.getOpcode() == ISD::SHL && isa<ConstantSDNode>(N00.getOperand(1)) && |
| 8049 | ARM::isBitFieldInvertedMask(~Mask)) { |
| 8050 | // Case (3): or (and (shl A, #shamt), mask), B => ARMbfi B, A, ~mask |
| 8051 | // where lsb(mask) == #shamt and masked bits of B are known zero. |
| 8052 | SDValue ShAmt = N00.getOperand(1); |
| 8053 | unsigned ShAmtC = cast<ConstantSDNode>(ShAmt)->getZExtValue(); |
| 8054 | unsigned LSB = CountTrailingZeros_32(Mask); |
| 8055 | if (ShAmtC != LSB) |
| 8056 | return SDValue(); |
| 8057 | |
| 8058 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1, N00.getOperand(0), |
| 8059 | DAG.getConstant(~Mask, MVT::i32)); |
| 8060 | |
| 8061 | // Do not add new nodes to DAG combiner worklist. |
| 8062 | DCI.CombineTo(N, Res, false); |
| 8063 | } |
| 8064 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8065 | return SDValue(); |
| 8066 | } |
| 8067 | |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8068 | static SDValue PerformXORCombine(SDNode *N, |
| 8069 | TargetLowering::DAGCombinerInfo &DCI, |
| 8070 | const ARMSubtarget *Subtarget) { |
| 8071 | EVT VT = N->getValueType(0); |
| 8072 | SelectionDAG &DAG = DCI.DAG; |
| 8073 | |
| 8074 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 8075 | return SDValue(); |
| 8076 | |
| 8077 | if (!Subtarget->isThumb1Only()) { |
Jakob Stoklund Olesen | dcd2342 | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8078 | // fold (xor (select cc, 0, c), x) -> (select cc, x, (xor, x, c)) |
| 8079 | SDValue Result = combineSelectAndUseCommutative(N, false, DCI); |
| 8080 | if (Result.getNode()) |
| 8081 | return Result; |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8082 | } |
| 8083 | |
| 8084 | return SDValue(); |
| 8085 | } |
| 8086 | |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 8087 | /// PerformBFICombine - (bfi A, (and B, Mask1), Mask2) -> (bfi A, B, Mask2) iff |
| 8088 | /// 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] | 8089 | static SDValue PerformBFICombine(SDNode *N, |
| 8090 | TargetLowering::DAGCombinerInfo &DCI) { |
| 8091 | SDValue N1 = N->getOperand(1); |
| 8092 | if (N1.getOpcode() == ISD::AND) { |
| 8093 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 8094 | if (!N11C) |
| 8095 | return SDValue(); |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 8096 | unsigned InvMask = cast<ConstantSDNode>(N->getOperand(2))->getZExtValue(); |
| 8097 | unsigned LSB = CountTrailingZeros_32(~InvMask); |
| 8098 | unsigned Width = (32 - CountLeadingZeros_32(~InvMask)) - LSB; |
| 8099 | unsigned Mask = (1 << Width)-1; |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 8100 | unsigned Mask2 = N11C->getZExtValue(); |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 8101 | if ((Mask & (~Mask2)) == 0) |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 8102 | return DCI.DAG.getNode(ARMISD::BFI, N->getDebugLoc(), N->getValueType(0), |
| 8103 | N->getOperand(0), N1.getOperand(0), |
| 8104 | N->getOperand(2)); |
| 8105 | } |
| 8106 | return SDValue(); |
| 8107 | } |
| 8108 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 8109 | /// PerformVMOVRRDCombine - Target-specific dag combine xforms for |
| 8110 | /// ARMISD::VMOVRRD. |
| 8111 | static SDValue PerformVMOVRRDCombine(SDNode *N, |
| 8112 | TargetLowering::DAGCombinerInfo &DCI) { |
| 8113 | // vmovrrd(vmovdrr x, y) -> x,y |
| 8114 | SDValue InDouble = N->getOperand(0); |
| 8115 | if (InDouble.getOpcode() == ARMISD::VMOVDRR) |
| 8116 | return DCI.CombineTo(N, InDouble.getOperand(0), InDouble.getOperand(1)); |
Cameron Zwarich | 4071a71 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 8117 | |
| 8118 | // vmovrrd(load f64) -> (load i32), (load i32) |
| 8119 | SDNode *InNode = InDouble.getNode(); |
| 8120 | if (ISD::isNormalLoad(InNode) && InNode->hasOneUse() && |
| 8121 | InNode->getValueType(0) == MVT::f64 && |
| 8122 | InNode->getOperand(1).getOpcode() == ISD::FrameIndex && |
| 8123 | !cast<LoadSDNode>(InNode)->isVolatile()) { |
| 8124 | // TODO: Should this be done for non-FrameIndex operands? |
| 8125 | LoadSDNode *LD = cast<LoadSDNode>(InNode); |
| 8126 | |
| 8127 | SelectionDAG &DAG = DCI.DAG; |
| 8128 | DebugLoc DL = LD->getDebugLoc(); |
| 8129 | SDValue BasePtr = LD->getBasePtr(); |
| 8130 | SDValue NewLD1 = DAG.getLoad(MVT::i32, DL, LD->getChain(), BasePtr, |
| 8131 | LD->getPointerInfo(), LD->isVolatile(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 8132 | LD->isNonTemporal(), LD->isInvariant(), |
| 8133 | LD->getAlignment()); |
Cameron Zwarich | 4071a71 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 8134 | |
| 8135 | SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, |
| 8136 | DAG.getConstant(4, MVT::i32)); |
| 8137 | SDValue NewLD2 = DAG.getLoad(MVT::i32, DL, NewLD1.getValue(1), OffsetPtr, |
| 8138 | LD->getPointerInfo(), LD->isVolatile(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 8139 | LD->isNonTemporal(), LD->isInvariant(), |
Cameron Zwarich | 4071a71 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 8140 | std::min(4U, LD->getAlignment() / 2)); |
| 8141 | |
| 8142 | DAG.ReplaceAllUsesOfValueWith(SDValue(LD, 1), NewLD2.getValue(1)); |
| 8143 | SDValue Result = DCI.CombineTo(N, NewLD1, NewLD2); |
| 8144 | DCI.RemoveFromWorklist(LD); |
| 8145 | DAG.DeleteNode(LD); |
| 8146 | return Result; |
| 8147 | } |
| 8148 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 8149 | return SDValue(); |
| 8150 | } |
| 8151 | |
| 8152 | /// PerformVMOVDRRCombine - Target-specific dag combine xforms for |
| 8153 | /// ARMISD::VMOVDRR. This is also used for BUILD_VECTORs with 2 operands. |
| 8154 | static SDValue PerformVMOVDRRCombine(SDNode *N, SelectionDAG &DAG) { |
| 8155 | // N=vmovrrd(X); vmovdrr(N:0, N:1) -> bit_convert(X) |
| 8156 | SDValue Op0 = N->getOperand(0); |
| 8157 | SDValue Op1 = N->getOperand(1); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8158 | if (Op0.getOpcode() == ISD::BITCAST) |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 8159 | Op0 = Op0.getOperand(0); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8160 | if (Op1.getOpcode() == ISD::BITCAST) |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 8161 | Op1 = Op1.getOperand(0); |
| 8162 | if (Op0.getOpcode() == ARMISD::VMOVRRD && |
| 8163 | Op0.getNode() == Op1.getNode() && |
| 8164 | Op0.getResNo() == 0 && Op1.getResNo() == 1) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8165 | return DAG.getNode(ISD::BITCAST, N->getDebugLoc(), |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 8166 | N->getValueType(0), Op0.getOperand(0)); |
| 8167 | return SDValue(); |
| 8168 | } |
| 8169 | |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8170 | /// PerformSTORECombine - Target-specific dag combine xforms for |
| 8171 | /// ISD::STORE. |
| 8172 | static SDValue PerformSTORECombine(SDNode *N, |
| 8173 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8174 | StoreSDNode *St = cast<StoreSDNode>(N); |
Chad Rosier | 7f35455 | 2012-04-09 20:32:02 +0000 | [diff] [blame] | 8175 | if (St->isVolatile()) |
| 8176 | return SDValue(); |
| 8177 | |
Andrew Trick | 49b446f | 2012-07-18 18:34:24 +0000 | [diff] [blame] | 8178 | // Optimize trunc store (of multiple scalars) to shuffle and store. First, |
Chad Rosier | 7f35455 | 2012-04-09 20:32:02 +0000 | [diff] [blame] | 8179 | // pack all of the elements in one place. Next, store to memory in fewer |
| 8180 | // chunks. |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8181 | SDValue StVal = St->getValue(); |
Chad Rosier | 7f35455 | 2012-04-09 20:32:02 +0000 | [diff] [blame] | 8182 | EVT VT = StVal.getValueType(); |
| 8183 | if (St->isTruncatingStore() && VT.isVector()) { |
| 8184 | SelectionDAG &DAG = DCI.DAG; |
| 8185 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 8186 | EVT StVT = St->getMemoryVT(); |
| 8187 | unsigned NumElems = VT.getVectorNumElements(); |
| 8188 | assert(StVT != VT && "Cannot truncate to the same type"); |
| 8189 | unsigned FromEltSz = VT.getVectorElementType().getSizeInBits(); |
| 8190 | unsigned ToEltSz = StVT.getVectorElementType().getSizeInBits(); |
| 8191 | |
| 8192 | // From, To sizes and ElemCount must be pow of two |
| 8193 | if (!isPowerOf2_32(NumElems * FromEltSz * ToEltSz)) return SDValue(); |
| 8194 | |
| 8195 | // We are going to use the original vector elt for storing. |
| 8196 | // Accumulated smaller vector elements must be a multiple of the store size. |
| 8197 | if (0 != (NumElems * FromEltSz) % ToEltSz) return SDValue(); |
| 8198 | |
| 8199 | unsigned SizeRatio = FromEltSz / ToEltSz; |
| 8200 | assert(SizeRatio * NumElems * ToEltSz == VT.getSizeInBits()); |
| 8201 | |
| 8202 | // Create a type on which we perform the shuffle. |
| 8203 | EVT WideVecVT = EVT::getVectorVT(*DAG.getContext(), StVT.getScalarType(), |
| 8204 | NumElems*SizeRatio); |
| 8205 | assert(WideVecVT.getSizeInBits() == VT.getSizeInBits()); |
| 8206 | |
| 8207 | DebugLoc DL = St->getDebugLoc(); |
| 8208 | SDValue WideVec = DAG.getNode(ISD::BITCAST, DL, WideVecVT, StVal); |
| 8209 | SmallVector<int, 8> ShuffleVec(NumElems * SizeRatio, -1); |
| 8210 | for (unsigned i = 0; i < NumElems; ++i) ShuffleVec[i] = i * SizeRatio; |
| 8211 | |
| 8212 | // Can't shuffle using an illegal type. |
| 8213 | if (!TLI.isTypeLegal(WideVecVT)) return SDValue(); |
| 8214 | |
| 8215 | SDValue Shuff = DAG.getVectorShuffle(WideVecVT, DL, WideVec, |
| 8216 | DAG.getUNDEF(WideVec.getValueType()), |
| 8217 | ShuffleVec.data()); |
| 8218 | // At this point all of the data is stored at the bottom of the |
| 8219 | // register. We now need to save it to mem. |
| 8220 | |
| 8221 | // Find the largest store unit |
| 8222 | MVT StoreType = MVT::i8; |
| 8223 | for (unsigned tp = MVT::FIRST_INTEGER_VALUETYPE; |
| 8224 | tp < MVT::LAST_INTEGER_VALUETYPE; ++tp) { |
| 8225 | MVT Tp = (MVT::SimpleValueType)tp; |
| 8226 | if (TLI.isTypeLegal(Tp) && Tp.getSizeInBits() <= NumElems * ToEltSz) |
| 8227 | StoreType = Tp; |
| 8228 | } |
| 8229 | // Didn't find a legal store type. |
| 8230 | if (!TLI.isTypeLegal(StoreType)) |
| 8231 | return SDValue(); |
| 8232 | |
| 8233 | // Bitcast the original vector into a vector of store-size units |
| 8234 | EVT StoreVecVT = EVT::getVectorVT(*DAG.getContext(), |
| 8235 | StoreType, VT.getSizeInBits()/EVT(StoreType).getSizeInBits()); |
| 8236 | assert(StoreVecVT.getSizeInBits() == VT.getSizeInBits()); |
| 8237 | SDValue ShuffWide = DAG.getNode(ISD::BITCAST, DL, StoreVecVT, Shuff); |
| 8238 | SmallVector<SDValue, 8> Chains; |
| 8239 | SDValue Increment = DAG.getConstant(StoreType.getSizeInBits()/8, |
| 8240 | TLI.getPointerTy()); |
| 8241 | SDValue BasePtr = St->getBasePtr(); |
| 8242 | |
| 8243 | // Perform one or more big stores into memory. |
| 8244 | unsigned E = (ToEltSz*NumElems)/StoreType.getSizeInBits(); |
| 8245 | for (unsigned I = 0; I < E; I++) { |
| 8246 | SDValue SubVec = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, |
| 8247 | StoreType, ShuffWide, |
| 8248 | DAG.getIntPtrConstant(I)); |
| 8249 | SDValue Ch = DAG.getStore(St->getChain(), DL, SubVec, BasePtr, |
| 8250 | St->getPointerInfo(), St->isVolatile(), |
| 8251 | St->isNonTemporal(), St->getAlignment()); |
| 8252 | BasePtr = DAG.getNode(ISD::ADD, DL, BasePtr.getValueType(), BasePtr, |
| 8253 | Increment); |
| 8254 | Chains.push_back(Ch); |
| 8255 | } |
| 8256 | return DAG.getNode(ISD::TokenFactor, DL, MVT::Other, &Chains[0], |
| 8257 | Chains.size()); |
| 8258 | } |
| 8259 | |
| 8260 | if (!ISD::isNormalStore(St)) |
Cameron Zwarich | d0aacbc | 2011-04-12 02:24:17 +0000 | [diff] [blame] | 8261 | return SDValue(); |
| 8262 | |
Chad Rosier | 96b66d6 | 2012-04-09 19:38:15 +0000 | [diff] [blame] | 8263 | // Split a store of a VMOVDRR into two integer stores to avoid mixing NEON and |
| 8264 | // ARM stores of arguments in the same cache line. |
Cameron Zwarich | d0aacbc | 2011-04-12 02:24:17 +0000 | [diff] [blame] | 8265 | if (StVal.getNode()->getOpcode() == ARMISD::VMOVDRR && |
Chad Rosier | 96b66d6 | 2012-04-09 19:38:15 +0000 | [diff] [blame] | 8266 | StVal.getNode()->hasOneUse()) { |
Cameron Zwarich | d0aacbc | 2011-04-12 02:24:17 +0000 | [diff] [blame] | 8267 | SelectionDAG &DAG = DCI.DAG; |
| 8268 | DebugLoc DL = St->getDebugLoc(); |
| 8269 | SDValue BasePtr = St->getBasePtr(); |
| 8270 | SDValue NewST1 = DAG.getStore(St->getChain(), DL, |
| 8271 | StVal.getNode()->getOperand(0), BasePtr, |
| 8272 | St->getPointerInfo(), St->isVolatile(), |
| 8273 | St->isNonTemporal(), St->getAlignment()); |
| 8274 | |
| 8275 | SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, |
| 8276 | DAG.getConstant(4, MVT::i32)); |
| 8277 | return DAG.getStore(NewST1.getValue(0), DL, StVal.getNode()->getOperand(1), |
| 8278 | OffsetPtr, St->getPointerInfo(), St->isVolatile(), |
| 8279 | St->isNonTemporal(), |
| 8280 | std::min(4U, St->getAlignment() / 2)); |
| 8281 | } |
| 8282 | |
| 8283 | if (StVal.getValueType() != MVT::i64 || |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8284 | StVal.getNode()->getOpcode() != ISD::EXTRACT_VECTOR_ELT) |
| 8285 | return SDValue(); |
| 8286 | |
Chad Rosier | 96b66d6 | 2012-04-09 19:38:15 +0000 | [diff] [blame] | 8287 | // Bitcast an i64 store extracted from a vector to f64. |
| 8288 | // 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] | 8289 | SelectionDAG &DAG = DCI.DAG; |
| 8290 | DebugLoc dl = StVal.getDebugLoc(); |
| 8291 | SDValue IntVec = StVal.getOperand(0); |
| 8292 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 8293 | IntVec.getValueType().getVectorNumElements()); |
| 8294 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, IntVec); |
| 8295 | SDValue ExtElt = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, |
| 8296 | Vec, StVal.getOperand(1)); |
| 8297 | dl = N->getDebugLoc(); |
| 8298 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::i64, ExtElt); |
| 8299 | // Make the DAGCombiner fold the bitcasts. |
| 8300 | DCI.AddToWorklist(Vec.getNode()); |
| 8301 | DCI.AddToWorklist(ExtElt.getNode()); |
| 8302 | DCI.AddToWorklist(V.getNode()); |
| 8303 | return DAG.getStore(St->getChain(), dl, V, St->getBasePtr(), |
| 8304 | St->getPointerInfo(), St->isVolatile(), |
| 8305 | St->isNonTemporal(), St->getAlignment(), |
| 8306 | St->getTBAAInfo()); |
| 8307 | } |
| 8308 | |
| 8309 | /// hasNormalLoadOperand - Check if any of the operands of a BUILD_VECTOR node |
| 8310 | /// are normal, non-volatile loads. If so, it is profitable to bitcast an |
| 8311 | /// i64 vector to have f64 elements, since the value can then be loaded |
| 8312 | /// directly into a VFP register. |
| 8313 | static bool hasNormalLoadOperand(SDNode *N) { |
| 8314 | unsigned NumElts = N->getValueType(0).getVectorNumElements(); |
| 8315 | for (unsigned i = 0; i < NumElts; ++i) { |
| 8316 | SDNode *Elt = N->getOperand(i).getNode(); |
| 8317 | if (ISD::isNormalLoad(Elt) && !cast<LoadSDNode>(Elt)->isVolatile()) |
| 8318 | return true; |
| 8319 | } |
| 8320 | return false; |
| 8321 | } |
| 8322 | |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 8323 | /// PerformBUILD_VECTORCombine - Target-specific dag combine xforms for |
| 8324 | /// ISD::BUILD_VECTOR. |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8325 | static SDValue PerformBUILD_VECTORCombine(SDNode *N, |
| 8326 | TargetLowering::DAGCombinerInfo &DCI){ |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 8327 | // build_vector(N=ARMISD::VMOVRRD(X), N:1) -> bit_convert(X): |
| 8328 | // VMOVRRD is introduced when legalizing i64 types. It forces the i64 value |
| 8329 | // into a pair of GPRs, which is fine when the value is used as a scalar, |
| 8330 | // 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] | 8331 | SelectionDAG &DAG = DCI.DAG; |
| 8332 | if (N->getNumOperands() == 2) { |
| 8333 | SDValue RV = PerformVMOVDRRCombine(N, DAG); |
| 8334 | if (RV.getNode()) |
| 8335 | return RV; |
| 8336 | } |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 8337 | |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 8338 | // Load i64 elements as f64 values so that type legalization does not split |
| 8339 | // them up into i32 values. |
| 8340 | EVT VT = N->getValueType(0); |
| 8341 | if (VT.getVectorElementType() != MVT::i64 || !hasNormalLoadOperand(N)) |
| 8342 | return SDValue(); |
| 8343 | DebugLoc dl = N->getDebugLoc(); |
| 8344 | SmallVector<SDValue, 8> Ops; |
| 8345 | unsigned NumElts = VT.getVectorNumElements(); |
| 8346 | for (unsigned i = 0; i < NumElts; ++i) { |
| 8347 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(i)); |
| 8348 | Ops.push_back(V); |
| 8349 | // Make the DAGCombiner fold the bitcast. |
| 8350 | DCI.AddToWorklist(V.getNode()); |
| 8351 | } |
| 8352 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, NumElts); |
| 8353 | SDValue BV = DAG.getNode(ISD::BUILD_VECTOR, dl, FloatVT, Ops.data(), NumElts); |
| 8354 | return DAG.getNode(ISD::BITCAST, dl, VT, BV); |
| 8355 | } |
| 8356 | |
| 8357 | /// PerformInsertEltCombine - Target-specific dag combine xforms for |
| 8358 | /// ISD::INSERT_VECTOR_ELT. |
| 8359 | static SDValue PerformInsertEltCombine(SDNode *N, |
| 8360 | TargetLowering::DAGCombinerInfo &DCI) { |
| 8361 | // Bitcast an i64 load inserted into a vector to f64. |
| 8362 | // Otherwise, the i64 value will be legalized to a pair of i32 values. |
| 8363 | EVT VT = N->getValueType(0); |
| 8364 | SDNode *Elt = N->getOperand(1).getNode(); |
| 8365 | if (VT.getVectorElementType() != MVT::i64 || |
| 8366 | !ISD::isNormalLoad(Elt) || cast<LoadSDNode>(Elt)->isVolatile()) |
| 8367 | return SDValue(); |
| 8368 | |
| 8369 | SelectionDAG &DAG = DCI.DAG; |
| 8370 | DebugLoc dl = N->getDebugLoc(); |
| 8371 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 8372 | VT.getVectorNumElements()); |
| 8373 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, N->getOperand(0)); |
| 8374 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(1)); |
| 8375 | // Make the DAGCombiner fold the bitcasts. |
| 8376 | DCI.AddToWorklist(Vec.getNode()); |
| 8377 | DCI.AddToWorklist(V.getNode()); |
| 8378 | SDValue InsElt = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, FloatVT, |
| 8379 | Vec, V, N->getOperand(2)); |
| 8380 | return DAG.getNode(ISD::BITCAST, dl, VT, InsElt); |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 8381 | } |
| 8382 | |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 8383 | /// PerformVECTOR_SHUFFLECombine - Target-specific dag combine xforms for |
| 8384 | /// ISD::VECTOR_SHUFFLE. |
| 8385 | static SDValue PerformVECTOR_SHUFFLECombine(SDNode *N, SelectionDAG &DAG) { |
| 8386 | // The LLVM shufflevector instruction does not require the shuffle mask |
| 8387 | // length to match the operand vector length, but ISD::VECTOR_SHUFFLE does |
| 8388 | // have that requirement. When translating to ISD::VECTOR_SHUFFLE, if the |
| 8389 | // operands do not match the mask length, they are extended by concatenating |
| 8390 | // them with undef vectors. That is probably the right thing for other |
| 8391 | // targets, but for NEON it is better to concatenate two double-register |
| 8392 | // size vector operands into a single quad-register size vector. Do that |
| 8393 | // transformation here: |
| 8394 | // shuffle(concat(v1, undef), concat(v2, undef)) -> |
| 8395 | // shuffle(concat(v1, v2), undef) |
| 8396 | SDValue Op0 = N->getOperand(0); |
| 8397 | SDValue Op1 = N->getOperand(1); |
| 8398 | if (Op0.getOpcode() != ISD::CONCAT_VECTORS || |
| 8399 | Op1.getOpcode() != ISD::CONCAT_VECTORS || |
| 8400 | Op0.getNumOperands() != 2 || |
| 8401 | Op1.getNumOperands() != 2) |
| 8402 | return SDValue(); |
| 8403 | SDValue Concat0Op1 = Op0.getOperand(1); |
| 8404 | SDValue Concat1Op1 = Op1.getOperand(1); |
| 8405 | if (Concat0Op1.getOpcode() != ISD::UNDEF || |
| 8406 | Concat1Op1.getOpcode() != ISD::UNDEF) |
| 8407 | return SDValue(); |
| 8408 | // Skip the transformation if any of the types are illegal. |
| 8409 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 8410 | EVT VT = N->getValueType(0); |
| 8411 | if (!TLI.isTypeLegal(VT) || |
| 8412 | !TLI.isTypeLegal(Concat0Op1.getValueType()) || |
| 8413 | !TLI.isTypeLegal(Concat1Op1.getValueType())) |
| 8414 | return SDValue(); |
| 8415 | |
| 8416 | SDValue NewConcat = DAG.getNode(ISD::CONCAT_VECTORS, N->getDebugLoc(), VT, |
| 8417 | Op0.getOperand(0), Op1.getOperand(0)); |
| 8418 | // Translate the shuffle mask. |
| 8419 | SmallVector<int, 16> NewMask; |
| 8420 | unsigned NumElts = VT.getVectorNumElements(); |
| 8421 | unsigned HalfElts = NumElts/2; |
| 8422 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(N); |
| 8423 | for (unsigned n = 0; n < NumElts; ++n) { |
| 8424 | int MaskElt = SVN->getMaskElt(n); |
| 8425 | int NewElt = -1; |
Bob Wilson | 1fa9d30 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 8426 | if (MaskElt < (int)HalfElts) |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 8427 | NewElt = MaskElt; |
Bob Wilson | 1fa9d30 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 8428 | else if (MaskElt >= (int)NumElts && MaskElt < (int)(NumElts + HalfElts)) |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 8429 | NewElt = HalfElts + MaskElt - NumElts; |
| 8430 | NewMask.push_back(NewElt); |
| 8431 | } |
| 8432 | return DAG.getVectorShuffle(VT, N->getDebugLoc(), NewConcat, |
| 8433 | DAG.getUNDEF(VT), NewMask.data()); |
| 8434 | } |
| 8435 | |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8436 | /// CombineBaseUpdate - Target-specific DAG combine function for VLDDUP and |
| 8437 | /// NEON load/store intrinsics to merge base address updates. |
| 8438 | static SDValue CombineBaseUpdate(SDNode *N, |
| 8439 | TargetLowering::DAGCombinerInfo &DCI) { |
| 8440 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 8441 | return SDValue(); |
| 8442 | |
| 8443 | SelectionDAG &DAG = DCI.DAG; |
| 8444 | bool isIntrinsic = (N->getOpcode() == ISD::INTRINSIC_VOID || |
| 8445 | N->getOpcode() == ISD::INTRINSIC_W_CHAIN); |
| 8446 | unsigned AddrOpIdx = (isIntrinsic ? 2 : 1); |
| 8447 | SDValue Addr = N->getOperand(AddrOpIdx); |
| 8448 | |
| 8449 | // Search for a use of the address operand that is an increment. |
| 8450 | for (SDNode::use_iterator UI = Addr.getNode()->use_begin(), |
| 8451 | UE = Addr.getNode()->use_end(); UI != UE; ++UI) { |
| 8452 | SDNode *User = *UI; |
| 8453 | if (User->getOpcode() != ISD::ADD || |
| 8454 | UI.getUse().getResNo() != Addr.getResNo()) |
| 8455 | continue; |
| 8456 | |
| 8457 | // Check that the add is independent of the load/store. Otherwise, folding |
| 8458 | // it would create a cycle. |
| 8459 | if (User->isPredecessorOf(N) || N->isPredecessorOf(User)) |
| 8460 | continue; |
| 8461 | |
| 8462 | // Find the new opcode for the updating load/store. |
| 8463 | bool isLoad = true; |
| 8464 | bool isLaneOp = false; |
| 8465 | unsigned NewOpc = 0; |
| 8466 | unsigned NumVecs = 0; |
| 8467 | if (isIntrinsic) { |
| 8468 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue(); |
| 8469 | switch (IntNo) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 8470 | default: llvm_unreachable("unexpected intrinsic for Neon base update"); |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8471 | case Intrinsic::arm_neon_vld1: NewOpc = ARMISD::VLD1_UPD; |
| 8472 | NumVecs = 1; break; |
| 8473 | case Intrinsic::arm_neon_vld2: NewOpc = ARMISD::VLD2_UPD; |
| 8474 | NumVecs = 2; break; |
| 8475 | case Intrinsic::arm_neon_vld3: NewOpc = ARMISD::VLD3_UPD; |
| 8476 | NumVecs = 3; break; |
| 8477 | case Intrinsic::arm_neon_vld4: NewOpc = ARMISD::VLD4_UPD; |
| 8478 | NumVecs = 4; break; |
| 8479 | case Intrinsic::arm_neon_vld2lane: NewOpc = ARMISD::VLD2LN_UPD; |
| 8480 | NumVecs = 2; isLaneOp = true; break; |
| 8481 | case Intrinsic::arm_neon_vld3lane: NewOpc = ARMISD::VLD3LN_UPD; |
| 8482 | NumVecs = 3; isLaneOp = true; break; |
| 8483 | case Intrinsic::arm_neon_vld4lane: NewOpc = ARMISD::VLD4LN_UPD; |
| 8484 | NumVecs = 4; isLaneOp = true; break; |
| 8485 | case Intrinsic::arm_neon_vst1: NewOpc = ARMISD::VST1_UPD; |
| 8486 | NumVecs = 1; isLoad = false; break; |
| 8487 | case Intrinsic::arm_neon_vst2: NewOpc = ARMISD::VST2_UPD; |
| 8488 | NumVecs = 2; isLoad = false; break; |
| 8489 | case Intrinsic::arm_neon_vst3: NewOpc = ARMISD::VST3_UPD; |
| 8490 | NumVecs = 3; isLoad = false; break; |
| 8491 | case Intrinsic::arm_neon_vst4: NewOpc = ARMISD::VST4_UPD; |
| 8492 | NumVecs = 4; isLoad = false; break; |
| 8493 | case Intrinsic::arm_neon_vst2lane: NewOpc = ARMISD::VST2LN_UPD; |
| 8494 | NumVecs = 2; isLoad = false; isLaneOp = true; break; |
| 8495 | case Intrinsic::arm_neon_vst3lane: NewOpc = ARMISD::VST3LN_UPD; |
| 8496 | NumVecs = 3; isLoad = false; isLaneOp = true; break; |
| 8497 | case Intrinsic::arm_neon_vst4lane: NewOpc = ARMISD::VST4LN_UPD; |
| 8498 | NumVecs = 4; isLoad = false; isLaneOp = true; break; |
| 8499 | } |
| 8500 | } else { |
| 8501 | isLaneOp = true; |
| 8502 | switch (N->getOpcode()) { |
Craig Topper | bc21981 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 8503 | default: llvm_unreachable("unexpected opcode for Neon base update"); |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8504 | case ARMISD::VLD2DUP: NewOpc = ARMISD::VLD2DUP_UPD; NumVecs = 2; break; |
| 8505 | case ARMISD::VLD3DUP: NewOpc = ARMISD::VLD3DUP_UPD; NumVecs = 3; break; |
| 8506 | case ARMISD::VLD4DUP: NewOpc = ARMISD::VLD4DUP_UPD; NumVecs = 4; break; |
| 8507 | } |
| 8508 | } |
| 8509 | |
| 8510 | // Find the size of memory referenced by the load/store. |
| 8511 | EVT VecTy; |
| 8512 | if (isLoad) |
| 8513 | VecTy = N->getValueType(0); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 8514 | else |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8515 | VecTy = N->getOperand(AddrOpIdx+1).getValueType(); |
| 8516 | unsigned NumBytes = NumVecs * VecTy.getSizeInBits() / 8; |
| 8517 | if (isLaneOp) |
| 8518 | NumBytes /= VecTy.getVectorNumElements(); |
| 8519 | |
| 8520 | // If the increment is a constant, it must match the memory ref size. |
| 8521 | SDValue Inc = User->getOperand(User->getOperand(0) == Addr ? 1 : 0); |
| 8522 | if (ConstantSDNode *CInc = dyn_cast<ConstantSDNode>(Inc.getNode())) { |
| 8523 | uint64_t IncVal = CInc->getZExtValue(); |
| 8524 | if (IncVal != NumBytes) |
| 8525 | continue; |
| 8526 | } else if (NumBytes >= 3 * 16) { |
| 8527 | // VLD3/4 and VST3/4 for 128-bit vectors are implemented with two |
| 8528 | // separate instructions that make it harder to use a non-constant update. |
| 8529 | continue; |
| 8530 | } |
| 8531 | |
| 8532 | // Create the new updating load/store node. |
| 8533 | EVT Tys[6]; |
| 8534 | unsigned NumResultVecs = (isLoad ? NumVecs : 0); |
| 8535 | unsigned n; |
| 8536 | for (n = 0; n < NumResultVecs; ++n) |
| 8537 | Tys[n] = VecTy; |
| 8538 | Tys[n++] = MVT::i32; |
| 8539 | Tys[n] = MVT::Other; |
| 8540 | SDVTList SDTys = DAG.getVTList(Tys, NumResultVecs+2); |
| 8541 | SmallVector<SDValue, 8> Ops; |
| 8542 | Ops.push_back(N->getOperand(0)); // incoming chain |
| 8543 | Ops.push_back(N->getOperand(AddrOpIdx)); |
| 8544 | Ops.push_back(Inc); |
| 8545 | for (unsigned i = AddrOpIdx + 1; i < N->getNumOperands(); ++i) { |
| 8546 | Ops.push_back(N->getOperand(i)); |
| 8547 | } |
| 8548 | MemIntrinsicSDNode *MemInt = cast<MemIntrinsicSDNode>(N); |
| 8549 | SDValue UpdN = DAG.getMemIntrinsicNode(NewOpc, N->getDebugLoc(), SDTys, |
| 8550 | Ops.data(), Ops.size(), |
| 8551 | MemInt->getMemoryVT(), |
| 8552 | MemInt->getMemOperand()); |
| 8553 | |
| 8554 | // Update the uses. |
| 8555 | std::vector<SDValue> NewResults; |
| 8556 | for (unsigned i = 0; i < NumResultVecs; ++i) { |
| 8557 | NewResults.push_back(SDValue(UpdN.getNode(), i)); |
| 8558 | } |
| 8559 | NewResults.push_back(SDValue(UpdN.getNode(), NumResultVecs+1)); // chain |
| 8560 | DCI.CombineTo(N, NewResults); |
| 8561 | DCI.CombineTo(User, SDValue(UpdN.getNode(), NumResultVecs)); |
| 8562 | |
| 8563 | break; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 8564 | } |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 8565 | return SDValue(); |
| 8566 | } |
| 8567 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 8568 | /// CombineVLDDUP - For a VDUPLANE node N, check if its source operand is a |
| 8569 | /// vldN-lane (N > 1) intrinsic, and if all the other uses of that intrinsic |
| 8570 | /// are also VDUPLANEs. If so, combine them to a vldN-dup operation and |
| 8571 | /// return true. |
| 8572 | static bool CombineVLDDUP(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) { |
| 8573 | SelectionDAG &DAG = DCI.DAG; |
| 8574 | EVT VT = N->getValueType(0); |
| 8575 | // vldN-dup instructions only support 64-bit vectors for N > 1. |
| 8576 | if (!VT.is64BitVector()) |
| 8577 | return false; |
| 8578 | |
| 8579 | // Check if the VDUPLANE operand is a vldN-dup intrinsic. |
| 8580 | SDNode *VLD = N->getOperand(0).getNode(); |
| 8581 | if (VLD->getOpcode() != ISD::INTRINSIC_W_CHAIN) |
| 8582 | return false; |
| 8583 | unsigned NumVecs = 0; |
| 8584 | unsigned NewOpc = 0; |
| 8585 | unsigned IntNo = cast<ConstantSDNode>(VLD->getOperand(1))->getZExtValue(); |
| 8586 | if (IntNo == Intrinsic::arm_neon_vld2lane) { |
| 8587 | NumVecs = 2; |
| 8588 | NewOpc = ARMISD::VLD2DUP; |
| 8589 | } else if (IntNo == Intrinsic::arm_neon_vld3lane) { |
| 8590 | NumVecs = 3; |
| 8591 | NewOpc = ARMISD::VLD3DUP; |
| 8592 | } else if (IntNo == Intrinsic::arm_neon_vld4lane) { |
| 8593 | NumVecs = 4; |
| 8594 | NewOpc = ARMISD::VLD4DUP; |
| 8595 | } else { |
| 8596 | return false; |
| 8597 | } |
| 8598 | |
| 8599 | // First check that all the vldN-lane uses are VDUPLANEs and that the lane |
| 8600 | // numbers match the load. |
| 8601 | unsigned VLDLaneNo = |
| 8602 | cast<ConstantSDNode>(VLD->getOperand(NumVecs+3))->getZExtValue(); |
| 8603 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 8604 | UI != UE; ++UI) { |
| 8605 | // Ignore uses of the chain result. |
| 8606 | if (UI.getUse().getResNo() == NumVecs) |
| 8607 | continue; |
| 8608 | SDNode *User = *UI; |
| 8609 | if (User->getOpcode() != ARMISD::VDUPLANE || |
| 8610 | VLDLaneNo != cast<ConstantSDNode>(User->getOperand(1))->getZExtValue()) |
| 8611 | return false; |
| 8612 | } |
| 8613 | |
| 8614 | // Create the vldN-dup node. |
| 8615 | EVT Tys[5]; |
| 8616 | unsigned n; |
| 8617 | for (n = 0; n < NumVecs; ++n) |
| 8618 | Tys[n] = VT; |
| 8619 | Tys[n] = MVT::Other; |
| 8620 | SDVTList SDTys = DAG.getVTList(Tys, NumVecs+1); |
| 8621 | SDValue Ops[] = { VLD->getOperand(0), VLD->getOperand(2) }; |
| 8622 | MemIntrinsicSDNode *VLDMemInt = cast<MemIntrinsicSDNode>(VLD); |
| 8623 | SDValue VLDDup = DAG.getMemIntrinsicNode(NewOpc, VLD->getDebugLoc(), SDTys, |
| 8624 | Ops, 2, VLDMemInt->getMemoryVT(), |
| 8625 | VLDMemInt->getMemOperand()); |
| 8626 | |
| 8627 | // Update the uses. |
| 8628 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 8629 | UI != UE; ++UI) { |
| 8630 | unsigned ResNo = UI.getUse().getResNo(); |
| 8631 | // Ignore uses of the chain result. |
| 8632 | if (ResNo == NumVecs) |
| 8633 | continue; |
| 8634 | SDNode *User = *UI; |
| 8635 | DCI.CombineTo(User, SDValue(VLDDup.getNode(), ResNo)); |
| 8636 | } |
| 8637 | |
| 8638 | // Now the vldN-lane intrinsic is dead except for its chain result. |
| 8639 | // Update uses of the chain. |
| 8640 | std::vector<SDValue> VLDDupResults; |
| 8641 | for (unsigned n = 0; n < NumVecs; ++n) |
| 8642 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), n)); |
| 8643 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), NumVecs)); |
| 8644 | DCI.CombineTo(VLD, VLDDupResults); |
| 8645 | |
| 8646 | return true; |
| 8647 | } |
| 8648 | |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 8649 | /// PerformVDUPLANECombine - Target-specific dag combine xforms for |
| 8650 | /// ARMISD::VDUPLANE. |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 8651 | static SDValue PerformVDUPLANECombine(SDNode *N, |
| 8652 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 8653 | SDValue Op = N->getOperand(0); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 8654 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 8655 | // If the source is a vldN-lane (N > 1) intrinsic, and all the other uses |
| 8656 | // of that intrinsic are also VDUPLANEs, combine them to a vldN-dup operation. |
| 8657 | if (CombineVLDDUP(N, DCI)) |
| 8658 | return SDValue(N, 0); |
| 8659 | |
| 8660 | // If the source is already a VMOVIMM or VMVNIMM splat, the VDUPLANE is |
| 8661 | // redundant. Ignore bit_converts for now; element sizes are checked below. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8662 | while (Op.getOpcode() == ISD::BITCAST) |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 8663 | Op = Op.getOperand(0); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 8664 | if (Op.getOpcode() != ARMISD::VMOVIMM && Op.getOpcode() != ARMISD::VMVNIMM) |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 8665 | return SDValue(); |
| 8666 | |
| 8667 | // Make sure the VMOV element size is not bigger than the VDUPLANE elements. |
| 8668 | unsigned EltSize = Op.getValueType().getVectorElementType().getSizeInBits(); |
| 8669 | // The canonical VMOV for a zero vector uses a 32-bit element size. |
| 8670 | unsigned Imm = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 8671 | unsigned EltBits; |
| 8672 | if (ARM_AM::decodeNEONModImm(Imm, EltBits) == 0) |
| 8673 | EltSize = 8; |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 8674 | EVT VT = N->getValueType(0); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 8675 | if (EltSize > VT.getVectorElementType().getSizeInBits()) |
| 8676 | return SDValue(); |
| 8677 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 8678 | return DCI.DAG.getNode(ISD::BITCAST, N->getDebugLoc(), VT, Op); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 8679 | } |
| 8680 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8681 | // 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] | 8682 | // elements are the same constant, C, and Log2(C) ranges from 1 to 32. |
| 8683 | static bool isConstVecPow2(SDValue ConstVec, bool isSigned, uint64_t &C) |
| 8684 | { |
Chad Rosier | 118c9a0 | 2011-06-28 17:26:57 +0000 | [diff] [blame] | 8685 | integerPart cN; |
| 8686 | integerPart c0 = 0; |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 8687 | for (unsigned I = 0, E = ConstVec.getValueType().getVectorNumElements(); |
| 8688 | I != E; I++) { |
| 8689 | ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(ConstVec.getOperand(I)); |
| 8690 | if (!C) |
| 8691 | return false; |
| 8692 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8693 | bool isExact; |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 8694 | APFloat APF = C->getValueAPF(); |
| 8695 | if (APF.convertToInteger(&cN, 64, isSigned, APFloat::rmTowardZero, &isExact) |
| 8696 | != APFloat::opOK || !isExact) |
| 8697 | return false; |
| 8698 | |
| 8699 | c0 = (I == 0) ? cN : c0; |
| 8700 | if (!isPowerOf2_64(cN) || c0 != cN || Log2_64(c0) < 1 || Log2_64(c0) > 32) |
| 8701 | return false; |
| 8702 | } |
| 8703 | C = c0; |
| 8704 | return true; |
| 8705 | } |
| 8706 | |
| 8707 | /// PerformVCVTCombine - VCVT (floating-point to fixed-point, Advanced SIMD) |
| 8708 | /// can replace combinations of VMUL and VCVT (floating-point to integer) |
| 8709 | /// when the VMUL has a constant operand that is a power of 2. |
| 8710 | /// |
| 8711 | /// Example (assume d17 = <float 8.000000e+00, float 8.000000e+00>): |
| 8712 | /// vmul.f32 d16, d17, d16 |
| 8713 | /// vcvt.s32.f32 d16, d16 |
| 8714 | /// becomes: |
| 8715 | /// vcvt.s32.f32 d16, d16, #3 |
| 8716 | static SDValue PerformVCVTCombine(SDNode *N, |
| 8717 | TargetLowering::DAGCombinerInfo &DCI, |
| 8718 | const ARMSubtarget *Subtarget) { |
| 8719 | SelectionDAG &DAG = DCI.DAG; |
| 8720 | SDValue Op = N->getOperand(0); |
| 8721 | |
| 8722 | if (!Subtarget->hasNEON() || !Op.getValueType().isVector() || |
| 8723 | Op.getOpcode() != ISD::FMUL) |
| 8724 | return SDValue(); |
| 8725 | |
| 8726 | uint64_t C; |
| 8727 | SDValue N0 = Op->getOperand(0); |
| 8728 | SDValue ConstVec = Op->getOperand(1); |
| 8729 | bool isSigned = N->getOpcode() == ISD::FP_TO_SINT; |
| 8730 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8731 | if (ConstVec.getOpcode() != ISD::BUILD_VECTOR || |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 8732 | !isConstVecPow2(ConstVec, isSigned, C)) |
| 8733 | return SDValue(); |
| 8734 | |
| 8735 | unsigned IntrinsicOpcode = isSigned ? Intrinsic::arm_neon_vcvtfp2fxs : |
| 8736 | Intrinsic::arm_neon_vcvtfp2fxu; |
| 8737 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, N->getDebugLoc(), |
| 8738 | N->getValueType(0), |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8739 | DAG.getConstant(IntrinsicOpcode, MVT::i32), N0, |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 8740 | DAG.getConstant(Log2_64(C), MVT::i32)); |
| 8741 | } |
| 8742 | |
| 8743 | /// PerformVDIVCombine - VCVT (fixed-point to floating-point, Advanced SIMD) |
| 8744 | /// can replace combinations of VCVT (integer to floating-point) and VDIV |
| 8745 | /// when the VDIV has a constant operand that is a power of 2. |
| 8746 | /// |
| 8747 | /// Example (assume d17 = <float 8.000000e+00, float 8.000000e+00>): |
| 8748 | /// vcvt.f32.s32 d16, d16 |
| 8749 | /// vdiv.f32 d16, d17, d16 |
| 8750 | /// becomes: |
| 8751 | /// vcvt.f32.s32 d16, d16, #3 |
| 8752 | static SDValue PerformVDIVCombine(SDNode *N, |
| 8753 | TargetLowering::DAGCombinerInfo &DCI, |
| 8754 | const ARMSubtarget *Subtarget) { |
| 8755 | SelectionDAG &DAG = DCI.DAG; |
| 8756 | SDValue Op = N->getOperand(0); |
| 8757 | unsigned OpOpcode = Op.getNode()->getOpcode(); |
| 8758 | |
| 8759 | if (!Subtarget->hasNEON() || !N->getValueType(0).isVector() || |
| 8760 | (OpOpcode != ISD::SINT_TO_FP && OpOpcode != ISD::UINT_TO_FP)) |
| 8761 | return SDValue(); |
| 8762 | |
| 8763 | uint64_t C; |
| 8764 | SDValue ConstVec = N->getOperand(1); |
| 8765 | bool isSigned = OpOpcode == ISD::SINT_TO_FP; |
| 8766 | |
| 8767 | if (ConstVec.getOpcode() != ISD::BUILD_VECTOR || |
| 8768 | !isConstVecPow2(ConstVec, isSigned, C)) |
| 8769 | return SDValue(); |
| 8770 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8771 | unsigned IntrinsicOpcode = isSigned ? Intrinsic::arm_neon_vcvtfxs2fp : |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 8772 | Intrinsic::arm_neon_vcvtfxu2fp; |
| 8773 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, N->getDebugLoc(), |
| 8774 | Op.getValueType(), |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8775 | DAG.getConstant(IntrinsicOpcode, MVT::i32), |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 8776 | Op.getOperand(0), DAG.getConstant(Log2_64(C), MVT::i32)); |
| 8777 | } |
| 8778 | |
| 8779 | /// Getvshiftimm - Check if this is a valid build_vector for the immediate |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8780 | /// operand of a vector shift operation, where all the elements of the |
| 8781 | /// build_vector must have the same constant integer value. |
| 8782 | static bool getVShiftImm(SDValue Op, unsigned ElementBits, int64_t &Cnt) { |
| 8783 | // Ignore bit_converts. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8784 | while (Op.getOpcode() == ISD::BITCAST) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8785 | Op = Op.getOperand(0); |
| 8786 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(Op.getNode()); |
| 8787 | APInt SplatBits, SplatUndef; |
| 8788 | unsigned SplatBitSize; |
| 8789 | bool HasAnyUndefs; |
| 8790 | if (! BVN || ! BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, |
| 8791 | HasAnyUndefs, ElementBits) || |
| 8792 | SplatBitSize > ElementBits) |
| 8793 | return false; |
| 8794 | Cnt = SplatBits.getSExtValue(); |
| 8795 | return true; |
| 8796 | } |
| 8797 | |
| 8798 | /// isVShiftLImm - Check if this is a valid build_vector for the immediate |
| 8799 | /// operand of a vector shift left operation. That value must be in the range: |
| 8800 | /// 0 <= Value < ElementBits for a left shift; or |
| 8801 | /// 0 <= Value <= ElementBits for a long left shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8802 | static bool isVShiftLImm(SDValue Op, EVT VT, bool isLong, int64_t &Cnt) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8803 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 8804 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 8805 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 8806 | return false; |
| 8807 | return (Cnt >= 0 && (isLong ? Cnt-1 : Cnt) < ElementBits); |
| 8808 | } |
| 8809 | |
| 8810 | /// isVShiftRImm - Check if this is a valid build_vector for the immediate |
| 8811 | /// operand of a vector shift right operation. For a shift opcode, the value |
| 8812 | /// is positive, but for an intrinsic the value count must be negative. The |
| 8813 | /// absolute value must be in the range: |
| 8814 | /// 1 <= |Value| <= ElementBits for a right shift; or |
| 8815 | /// 1 <= |Value| <= ElementBits/2 for a narrow right shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8816 | static bool isVShiftRImm(SDValue Op, EVT VT, bool isNarrow, bool isIntrinsic, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8817 | int64_t &Cnt) { |
| 8818 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 8819 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 8820 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 8821 | return false; |
| 8822 | if (isIntrinsic) |
| 8823 | Cnt = -Cnt; |
| 8824 | return (Cnt >= 1 && Cnt <= (isNarrow ? ElementBits/2 : ElementBits)); |
| 8825 | } |
| 8826 | |
| 8827 | /// PerformIntrinsicCombine - ARM-specific DAG combining for intrinsics. |
| 8828 | static SDValue PerformIntrinsicCombine(SDNode *N, SelectionDAG &DAG) { |
| 8829 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue(); |
| 8830 | switch (IntNo) { |
| 8831 | default: |
| 8832 | // Don't do anything for most intrinsics. |
| 8833 | break; |
| 8834 | |
| 8835 | // Vector shifts: check for immediate versions and lower them. |
| 8836 | // Note: This is done during DAG combining instead of DAG legalizing because |
| 8837 | // the build_vectors for 64-bit vector element shift counts are generally |
| 8838 | // not legal, and it is hard to see their values after they get legalized to |
| 8839 | // loads from a constant pool. |
| 8840 | case Intrinsic::arm_neon_vshifts: |
| 8841 | case Intrinsic::arm_neon_vshiftu: |
| 8842 | case Intrinsic::arm_neon_vshiftls: |
| 8843 | case Intrinsic::arm_neon_vshiftlu: |
| 8844 | case Intrinsic::arm_neon_vshiftn: |
| 8845 | case Intrinsic::arm_neon_vrshifts: |
| 8846 | case Intrinsic::arm_neon_vrshiftu: |
| 8847 | case Intrinsic::arm_neon_vrshiftn: |
| 8848 | case Intrinsic::arm_neon_vqshifts: |
| 8849 | case Intrinsic::arm_neon_vqshiftu: |
| 8850 | case Intrinsic::arm_neon_vqshiftsu: |
| 8851 | case Intrinsic::arm_neon_vqshiftns: |
| 8852 | case Intrinsic::arm_neon_vqshiftnu: |
| 8853 | case Intrinsic::arm_neon_vqshiftnsu: |
| 8854 | case Intrinsic::arm_neon_vqrshiftns: |
| 8855 | case Intrinsic::arm_neon_vqrshiftnu: |
| 8856 | case Intrinsic::arm_neon_vqrshiftnsu: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8857 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8858 | int64_t Cnt; |
| 8859 | unsigned VShiftOpc = 0; |
| 8860 | |
| 8861 | switch (IntNo) { |
| 8862 | case Intrinsic::arm_neon_vshifts: |
| 8863 | case Intrinsic::arm_neon_vshiftu: |
| 8864 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) { |
| 8865 | VShiftOpc = ARMISD::VSHL; |
| 8866 | break; |
| 8867 | } |
| 8868 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) { |
| 8869 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshifts ? |
| 8870 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 8871 | break; |
| 8872 | } |
| 8873 | return SDValue(); |
| 8874 | |
| 8875 | case Intrinsic::arm_neon_vshiftls: |
| 8876 | case Intrinsic::arm_neon_vshiftlu: |
| 8877 | if (isVShiftLImm(N->getOperand(2), VT, true, Cnt)) |
| 8878 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 8879 | llvm_unreachable("invalid shift count for vshll intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8880 | |
| 8881 | case Intrinsic::arm_neon_vrshifts: |
| 8882 | case Intrinsic::arm_neon_vrshiftu: |
| 8883 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) |
| 8884 | break; |
| 8885 | return SDValue(); |
| 8886 | |
| 8887 | case Intrinsic::arm_neon_vqshifts: |
| 8888 | case Intrinsic::arm_neon_vqshiftu: |
| 8889 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 8890 | break; |
| 8891 | return SDValue(); |
| 8892 | |
| 8893 | case Intrinsic::arm_neon_vqshiftsu: |
| 8894 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 8895 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 8896 | llvm_unreachable("invalid shift count for vqshlu intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8897 | |
| 8898 | case Intrinsic::arm_neon_vshiftn: |
| 8899 | case Intrinsic::arm_neon_vrshiftn: |
| 8900 | case Intrinsic::arm_neon_vqshiftns: |
| 8901 | case Intrinsic::arm_neon_vqshiftnu: |
| 8902 | case Intrinsic::arm_neon_vqshiftnsu: |
| 8903 | case Intrinsic::arm_neon_vqrshiftns: |
| 8904 | case Intrinsic::arm_neon_vqrshiftnu: |
| 8905 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 8906 | // Narrowing shifts require an immediate right shift. |
| 8907 | if (isVShiftRImm(N->getOperand(2), VT, true, true, Cnt)) |
| 8908 | break; |
Jim Grosbach | 18f30e6 | 2010-06-02 21:53:11 +0000 | [diff] [blame] | 8909 | llvm_unreachable("invalid shift count for narrowing vector shift " |
| 8910 | "intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8911 | |
| 8912 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 8913 | llvm_unreachable("unhandled vector shift"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8914 | } |
| 8915 | |
| 8916 | switch (IntNo) { |
| 8917 | case Intrinsic::arm_neon_vshifts: |
| 8918 | case Intrinsic::arm_neon_vshiftu: |
| 8919 | // Opcode already set above. |
| 8920 | break; |
| 8921 | case Intrinsic::arm_neon_vshiftls: |
| 8922 | case Intrinsic::arm_neon_vshiftlu: |
| 8923 | if (Cnt == VT.getVectorElementType().getSizeInBits()) |
| 8924 | VShiftOpc = ARMISD::VSHLLi; |
| 8925 | else |
| 8926 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshiftls ? |
| 8927 | ARMISD::VSHLLs : ARMISD::VSHLLu); |
| 8928 | break; |
| 8929 | case Intrinsic::arm_neon_vshiftn: |
| 8930 | VShiftOpc = ARMISD::VSHRN; break; |
| 8931 | case Intrinsic::arm_neon_vrshifts: |
| 8932 | VShiftOpc = ARMISD::VRSHRs; break; |
| 8933 | case Intrinsic::arm_neon_vrshiftu: |
| 8934 | VShiftOpc = ARMISD::VRSHRu; break; |
| 8935 | case Intrinsic::arm_neon_vrshiftn: |
| 8936 | VShiftOpc = ARMISD::VRSHRN; break; |
| 8937 | case Intrinsic::arm_neon_vqshifts: |
| 8938 | VShiftOpc = ARMISD::VQSHLs; break; |
| 8939 | case Intrinsic::arm_neon_vqshiftu: |
| 8940 | VShiftOpc = ARMISD::VQSHLu; break; |
| 8941 | case Intrinsic::arm_neon_vqshiftsu: |
| 8942 | VShiftOpc = ARMISD::VQSHLsu; break; |
| 8943 | case Intrinsic::arm_neon_vqshiftns: |
| 8944 | VShiftOpc = ARMISD::VQSHRNs; break; |
| 8945 | case Intrinsic::arm_neon_vqshiftnu: |
| 8946 | VShiftOpc = ARMISD::VQSHRNu; break; |
| 8947 | case Intrinsic::arm_neon_vqshiftnsu: |
| 8948 | VShiftOpc = ARMISD::VQSHRNsu; break; |
| 8949 | case Intrinsic::arm_neon_vqrshiftns: |
| 8950 | VShiftOpc = ARMISD::VQRSHRNs; break; |
| 8951 | case Intrinsic::arm_neon_vqrshiftnu: |
| 8952 | VShiftOpc = ARMISD::VQRSHRNu; break; |
| 8953 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 8954 | VShiftOpc = ARMISD::VQRSHRNsu; break; |
| 8955 | } |
| 8956 | |
| 8957 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8958 | N->getOperand(1), DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8959 | } |
| 8960 | |
| 8961 | case Intrinsic::arm_neon_vshiftins: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8962 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8963 | int64_t Cnt; |
| 8964 | unsigned VShiftOpc = 0; |
| 8965 | |
| 8966 | if (isVShiftLImm(N->getOperand(3), VT, false, Cnt)) |
| 8967 | VShiftOpc = ARMISD::VSLI; |
| 8968 | else if (isVShiftRImm(N->getOperand(3), VT, false, true, Cnt)) |
| 8969 | VShiftOpc = ARMISD::VSRI; |
| 8970 | else { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 8971 | llvm_unreachable("invalid shift count for vsli/vsri intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8972 | } |
| 8973 | |
| 8974 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
| 8975 | N->getOperand(1), N->getOperand(2), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8976 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 8977 | } |
| 8978 | |
| 8979 | case Intrinsic::arm_neon_vqrshifts: |
| 8980 | case Intrinsic::arm_neon_vqrshiftu: |
| 8981 | // No immediate versions of these to check for. |
| 8982 | break; |
| 8983 | } |
| 8984 | |
| 8985 | return SDValue(); |
| 8986 | } |
| 8987 | |
| 8988 | /// PerformShiftCombine - Checks for immediate versions of vector shifts and |
| 8989 | /// lowers them. As with the vector shift intrinsics, this is done during DAG |
| 8990 | /// combining instead of DAG legalizing because the build_vectors for 64-bit |
| 8991 | /// vector element shift counts are generally not legal, and it is hard to see |
| 8992 | /// their values after they get legalized to loads from a constant pool. |
| 8993 | static SDValue PerformShiftCombine(SDNode *N, SelectionDAG &DAG, |
| 8994 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8995 | EVT VT = N->getValueType(0); |
Evan Cheng | 5fb468a | 2012-02-23 02:58:19 +0000 | [diff] [blame] | 8996 | if (N->getOpcode() == ISD::SRL && VT == MVT::i32 && ST->hasV6Ops()) { |
| 8997 | // Canonicalize (srl (bswap x), 16) to (rotr (bswap x), 16) if the high |
| 8998 | // 16-bits of x is zero. This optimizes rev + lsr 16 to rev16. |
| 8999 | SDValue N1 = N->getOperand(1); |
| 9000 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N1)) { |
| 9001 | SDValue N0 = N->getOperand(0); |
| 9002 | if (C->getZExtValue() == 16 && N0.getOpcode() == ISD::BSWAP && |
| 9003 | DAG.MaskedValueIsZero(N0.getOperand(0), |
| 9004 | APInt::getHighBitsSet(32, 16))) |
| 9005 | return DAG.getNode(ISD::ROTR, N->getDebugLoc(), VT, N0, N1); |
| 9006 | } |
| 9007 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9008 | |
| 9009 | // Nothing to be done for scalar shifts. |
Tanya Lattner | 9684a7c | 2010-11-18 22:06:46 +0000 | [diff] [blame] | 9010 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 9011 | if (!VT.isVector() || !TLI.isTypeLegal(VT)) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9012 | return SDValue(); |
| 9013 | |
| 9014 | assert(ST->hasNEON() && "unexpected vector shift"); |
| 9015 | int64_t Cnt; |
| 9016 | |
| 9017 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 9018 | default: llvm_unreachable("unexpected shift opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9019 | |
| 9020 | case ISD::SHL: |
| 9021 | if (isVShiftLImm(N->getOperand(1), VT, false, Cnt)) |
| 9022 | return DAG.getNode(ARMISD::VSHL, N->getDebugLoc(), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9023 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9024 | break; |
| 9025 | |
| 9026 | case ISD::SRA: |
| 9027 | case ISD::SRL: |
| 9028 | if (isVShiftRImm(N->getOperand(1), VT, false, false, Cnt)) { |
| 9029 | unsigned VShiftOpc = (N->getOpcode() == ISD::SRA ? |
| 9030 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 9031 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9032 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9033 | } |
| 9034 | } |
| 9035 | return SDValue(); |
| 9036 | } |
| 9037 | |
| 9038 | /// PerformExtendCombine - Target-specific DAG combining for ISD::SIGN_EXTEND, |
| 9039 | /// ISD::ZERO_EXTEND, and ISD::ANY_EXTEND. |
| 9040 | static SDValue PerformExtendCombine(SDNode *N, SelectionDAG &DAG, |
| 9041 | const ARMSubtarget *ST) { |
| 9042 | SDValue N0 = N->getOperand(0); |
| 9043 | |
| 9044 | // Check for sign- and zero-extensions of vector extract operations of 8- |
| 9045 | // and 16-bit vector elements. NEON supports these directly. They are |
| 9046 | // handled during DAG combining because type legalization will promote them |
| 9047 | // to 32-bit types and it is messy to recognize the operations after that. |
| 9048 | if (ST->hasNEON() && N0.getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
| 9049 | SDValue Vec = N0.getOperand(0); |
| 9050 | SDValue Lane = N0.getOperand(1); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9051 | EVT VT = N->getValueType(0); |
| 9052 | EVT EltVT = N0.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9053 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 9054 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9055 | if (VT == MVT::i32 && |
| 9056 | (EltVT == MVT::i8 || EltVT == MVT::i16) && |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 9057 | TLI.isTypeLegal(Vec.getValueType()) && |
| 9058 | isa<ConstantSDNode>(Lane)) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9059 | |
| 9060 | unsigned Opc = 0; |
| 9061 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 9062 | default: llvm_unreachable("unexpected opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9063 | case ISD::SIGN_EXTEND: |
| 9064 | Opc = ARMISD::VGETLANEs; |
| 9065 | break; |
| 9066 | case ISD::ZERO_EXTEND: |
| 9067 | case ISD::ANY_EXTEND: |
| 9068 | Opc = ARMISD::VGETLANEu; |
| 9069 | break; |
| 9070 | } |
| 9071 | return DAG.getNode(Opc, N->getDebugLoc(), VT, Vec, Lane); |
| 9072 | } |
| 9073 | } |
| 9074 | |
| 9075 | return SDValue(); |
| 9076 | } |
| 9077 | |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9078 | /// PerformSELECT_CCCombine - Target-specific DAG combining for ISD::SELECT_CC |
| 9079 | /// to match f32 max/min patterns to use NEON vmax/vmin instructions. |
| 9080 | static SDValue PerformSELECT_CCCombine(SDNode *N, SelectionDAG &DAG, |
| 9081 | const ARMSubtarget *ST) { |
| 9082 | // 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] | 9083 | // selects like "x < y ? x : y". Unless the NoNaNsFPMath option is set, |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9084 | // be careful about NaNs: NEON's vmax/vmin return NaN if either operand is |
| 9085 | // a NaN; only do the transformation when it matches that behavior. |
| 9086 | |
| 9087 | // For now only do this when using NEON for FP operations; if using VFP, it |
| 9088 | // is not obvious that the benefit outweighs the cost of switching to the |
| 9089 | // NEON pipeline. |
| 9090 | if (!ST->hasNEON() || !ST->useNEONForSinglePrecisionFP() || |
| 9091 | N->getValueType(0) != MVT::f32) |
| 9092 | return SDValue(); |
| 9093 | |
| 9094 | SDValue CondLHS = N->getOperand(0); |
| 9095 | SDValue CondRHS = N->getOperand(1); |
| 9096 | SDValue LHS = N->getOperand(2); |
| 9097 | SDValue RHS = N->getOperand(3); |
| 9098 | ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(4))->get(); |
| 9099 | |
| 9100 | unsigned Opcode = 0; |
| 9101 | bool IsReversed; |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9102 | if (DAG.isEqualTo(LHS, CondLHS) && DAG.isEqualTo(RHS, CondRHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9103 | IsReversed = false; // x CC y ? x : y |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9104 | } else if (DAG.isEqualTo(LHS, CondRHS) && DAG.isEqualTo(RHS, CondLHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9105 | IsReversed = true ; // x CC y ? y : x |
| 9106 | } else { |
| 9107 | return SDValue(); |
| 9108 | } |
| 9109 | |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9110 | bool IsUnordered; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9111 | switch (CC) { |
| 9112 | default: break; |
| 9113 | case ISD::SETOLT: |
| 9114 | case ISD::SETOLE: |
| 9115 | case ISD::SETLT: |
| 9116 | case ISD::SETLE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9117 | case ISD::SETULT: |
| 9118 | case ISD::SETULE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9119 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 9120 | // be the RHS, but vmin(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 9121 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 9122 | IsUnordered = (CC == ISD::SETULT || CC == ISD::SETULE); |
| 9123 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 9124 | break; |
| 9125 | // For less-than-or-equal comparisons, "+0 <= -0" will be true but vmin |
| 9126 | // will return -0, so vmin can only be used for unsafe math or if one of |
| 9127 | // the operands is known to be nonzero. |
| 9128 | if ((CC == ISD::SETLE || CC == ISD::SETOLE || CC == ISD::SETULE) && |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 9129 | !DAG.getTarget().Options.UnsafeFPMath && |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9130 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 9131 | break; |
| 9132 | Opcode = IsReversed ? ARMISD::FMAX : ARMISD::FMIN; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9133 | break; |
| 9134 | |
| 9135 | case ISD::SETOGT: |
| 9136 | case ISD::SETOGE: |
| 9137 | case ISD::SETGT: |
| 9138 | case ISD::SETGE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9139 | case ISD::SETUGT: |
| 9140 | case ISD::SETUGE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9141 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 9142 | // be the RHS, but vmax(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 9143 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 9144 | IsUnordered = (CC == ISD::SETUGT || CC == ISD::SETUGE); |
| 9145 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 9146 | break; |
| 9147 | // For greater-than-or-equal comparisons, "-0 >= +0" will be true but vmax |
| 9148 | // will return +0, so vmax can only be used for unsafe math or if one of |
| 9149 | // the operands is known to be nonzero. |
| 9150 | if ((CC == ISD::SETGE || CC == ISD::SETOGE || CC == ISD::SETUGE) && |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 9151 | !DAG.getTarget().Options.UnsafeFPMath && |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 9152 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 9153 | break; |
| 9154 | Opcode = IsReversed ? ARMISD::FMIN : ARMISD::FMAX; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9155 | break; |
| 9156 | } |
| 9157 | |
| 9158 | if (!Opcode) |
| 9159 | return SDValue(); |
| 9160 | return DAG.getNode(Opcode, N->getDebugLoc(), N->getValueType(0), LHS, RHS); |
| 9161 | } |
| 9162 | |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 9163 | /// PerformCMOVCombine - Target-specific DAG combining for ARMISD::CMOV. |
| 9164 | SDValue |
| 9165 | ARMTargetLowering::PerformCMOVCombine(SDNode *N, SelectionDAG &DAG) const { |
| 9166 | SDValue Cmp = N->getOperand(4); |
| 9167 | if (Cmp.getOpcode() != ARMISD::CMPZ) |
| 9168 | // Only looking at EQ and NE cases. |
| 9169 | return SDValue(); |
| 9170 | |
| 9171 | EVT VT = N->getValueType(0); |
| 9172 | DebugLoc dl = N->getDebugLoc(); |
| 9173 | SDValue LHS = Cmp.getOperand(0); |
| 9174 | SDValue RHS = Cmp.getOperand(1); |
| 9175 | SDValue FalseVal = N->getOperand(0); |
| 9176 | SDValue TrueVal = N->getOperand(1); |
| 9177 | SDValue ARMcc = N->getOperand(2); |
Jim Grosbach | b04546f | 2011-09-13 20:30:37 +0000 | [diff] [blame] | 9178 | ARMCC::CondCodes CC = |
| 9179 | (ARMCC::CondCodes)cast<ConstantSDNode>(ARMcc)->getZExtValue(); |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 9180 | |
| 9181 | // Simplify |
| 9182 | // mov r1, r0 |
| 9183 | // cmp r1, x |
| 9184 | // mov r0, y |
| 9185 | // moveq r0, x |
| 9186 | // to |
| 9187 | // cmp r0, x |
| 9188 | // movne r0, y |
| 9189 | // |
| 9190 | // mov r1, r0 |
| 9191 | // cmp r1, x |
| 9192 | // mov r0, x |
| 9193 | // movne r0, y |
| 9194 | // to |
| 9195 | // cmp r0, x |
| 9196 | // movne r0, y |
| 9197 | /// FIXME: Turn this into a target neutral optimization? |
| 9198 | SDValue Res; |
Evan Cheng | 9b88d2d | 2011-09-28 23:16:31 +0000 | [diff] [blame] | 9199 | if (CC == ARMCC::NE && FalseVal == RHS && FalseVal != LHS) { |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 9200 | Res = DAG.getNode(ARMISD::CMOV, dl, VT, LHS, TrueVal, ARMcc, |
| 9201 | N->getOperand(3), Cmp); |
| 9202 | } else if (CC == ARMCC::EQ && TrueVal == RHS) { |
| 9203 | SDValue ARMcc; |
| 9204 | SDValue NewCmp = getARMCmp(LHS, RHS, ISD::SETNE, ARMcc, DAG, dl); |
| 9205 | Res = DAG.getNode(ARMISD::CMOV, dl, VT, LHS, FalseVal, ARMcc, |
| 9206 | N->getOperand(3), NewCmp); |
| 9207 | } |
| 9208 | |
| 9209 | if (Res.getNode()) { |
| 9210 | APInt KnownZero, KnownOne; |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 9211 | DAG.ComputeMaskedBits(SDValue(N,0), KnownZero, KnownOne); |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 9212 | // Capture demanded bits information that would be otherwise lost. |
| 9213 | if (KnownZero == 0xfffffffe) |
| 9214 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 9215 | DAG.getValueType(MVT::i1)); |
| 9216 | else if (KnownZero == 0xffffff00) |
| 9217 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 9218 | DAG.getValueType(MVT::i8)); |
| 9219 | else if (KnownZero == 0xffff0000) |
| 9220 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 9221 | DAG.getValueType(MVT::i16)); |
| 9222 | } |
| 9223 | |
| 9224 | return Res; |
| 9225 | } |
| 9226 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 9227 | SDValue ARMTargetLowering::PerformDAGCombine(SDNode *N, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9228 | DAGCombinerInfo &DCI) const { |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 9229 | switch (N->getOpcode()) { |
| 9230 | default: break; |
Arnold Schwaighofer | 67514e9 | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 9231 | case ISD::ADDC: return PerformADDCCombine(N, DCI, Subtarget); |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 9232 | case ISD::ADD: return PerformADDCombine(N, DCI, Subtarget); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9233 | case ISD::SUB: return PerformSUBCombine(N, DCI); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 9234 | case ISD::MUL: return PerformMULCombine(N, DCI, Subtarget); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 9235 | case ISD::OR: return PerformORCombine(N, DCI, Subtarget); |
Evan Cheng | c892aeb | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 9236 | case ISD::XOR: return PerformXORCombine(N, DCI, Subtarget); |
| 9237 | case ISD::AND: return PerformANDCombine(N, DCI, Subtarget); |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 9238 | case ARMISD::BFI: return PerformBFICombine(N, DCI); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 9239 | case ARMISD::VMOVRRD: return PerformVMOVRRDCombine(N, DCI); |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 9240 | case ARMISD::VMOVDRR: return PerformVMOVDRRCombine(N, DCI.DAG); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 9241 | case ISD::STORE: return PerformSTORECombine(N, DCI); |
| 9242 | case ISD::BUILD_VECTOR: return PerformBUILD_VECTORCombine(N, DCI); |
| 9243 | case ISD::INSERT_VECTOR_ELT: return PerformInsertEltCombine(N, DCI); |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 9244 | case ISD::VECTOR_SHUFFLE: return PerformVECTOR_SHUFFLECombine(N, DCI.DAG); |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 9245 | case ARMISD::VDUPLANE: return PerformVDUPLANECombine(N, DCI); |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9246 | case ISD::FP_TO_SINT: |
| 9247 | case ISD::FP_TO_UINT: return PerformVCVTCombine(N, DCI, Subtarget); |
| 9248 | case ISD::FDIV: return PerformVDIVCombine(N, DCI, Subtarget); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9249 | case ISD::INTRINSIC_WO_CHAIN: return PerformIntrinsicCombine(N, DCI.DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9250 | case ISD::SHL: |
| 9251 | case ISD::SRA: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9252 | case ISD::SRL: return PerformShiftCombine(N, DCI.DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9253 | case ISD::SIGN_EXTEND: |
| 9254 | case ISD::ZERO_EXTEND: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 9255 | case ISD::ANY_EXTEND: return PerformExtendCombine(N, DCI.DAG, Subtarget); |
| 9256 | case ISD::SELECT_CC: return PerformSELECT_CCCombine(N, DCI.DAG, Subtarget); |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 9257 | case ARMISD::CMOV: return PerformCMOVCombine(N, DCI.DAG); |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9258 | case ARMISD::VLD2DUP: |
| 9259 | case ARMISD::VLD3DUP: |
| 9260 | case ARMISD::VLD4DUP: |
| 9261 | return CombineBaseUpdate(N, DCI); |
| 9262 | case ISD::INTRINSIC_VOID: |
| 9263 | case ISD::INTRINSIC_W_CHAIN: |
| 9264 | switch (cast<ConstantSDNode>(N->getOperand(1))->getZExtValue()) { |
| 9265 | case Intrinsic::arm_neon_vld1: |
| 9266 | case Intrinsic::arm_neon_vld2: |
| 9267 | case Intrinsic::arm_neon_vld3: |
| 9268 | case Intrinsic::arm_neon_vld4: |
| 9269 | case Intrinsic::arm_neon_vld2lane: |
| 9270 | case Intrinsic::arm_neon_vld3lane: |
| 9271 | case Intrinsic::arm_neon_vld4lane: |
| 9272 | case Intrinsic::arm_neon_vst1: |
| 9273 | case Intrinsic::arm_neon_vst2: |
| 9274 | case Intrinsic::arm_neon_vst3: |
| 9275 | case Intrinsic::arm_neon_vst4: |
| 9276 | case Intrinsic::arm_neon_vst2lane: |
| 9277 | case Intrinsic::arm_neon_vst3lane: |
| 9278 | case Intrinsic::arm_neon_vst4lane: |
| 9279 | return CombineBaseUpdate(N, DCI); |
| 9280 | default: break; |
| 9281 | } |
| 9282 | break; |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 9283 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 9284 | return SDValue(); |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 9285 | } |
| 9286 | |
Evan Cheng | 31959b1 | 2011-02-02 01:06:55 +0000 | [diff] [blame] | 9287 | bool ARMTargetLowering::isDesirableToTransformToIntegerOp(unsigned Opc, |
| 9288 | EVT VT) const { |
| 9289 | return (VT == MVT::f32) && (Opc == ISD::LOAD || Opc == ISD::STORE); |
| 9290 | } |
| 9291 | |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 9292 | bool ARMTargetLowering::allowsUnalignedMemoryAccesses(EVT VT) const { |
Evan Cheng | d10eab0 | 2012-09-18 01:42:45 +0000 | [diff] [blame] | 9293 | // The AllowsUnaliged flag models the SCTLR.A setting in ARM cpus |
Chad Rosier | b3235b1 | 2012-11-09 18:25:27 +0000 | [diff] [blame] | 9294 | bool AllowsUnaligned = Subtarget->allowsUnalignedMem(); |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 9295 | |
| 9296 | switch (VT.getSimpleVT().SimpleTy) { |
| 9297 | default: |
| 9298 | return false; |
| 9299 | case MVT::i8: |
| 9300 | case MVT::i16: |
| 9301 | case MVT::i32: |
Evan Cheng | d10eab0 | 2012-09-18 01:42:45 +0000 | [diff] [blame] | 9302 | // Unaligned access can use (for example) LRDB, LRDH, LDR |
| 9303 | return AllowsUnaligned; |
Evan Cheng | a99c508 | 2012-08-15 17:44:53 +0000 | [diff] [blame] | 9304 | case MVT::f64: |
Evan Cheng | d10eab0 | 2012-09-18 01:42:45 +0000 | [diff] [blame] | 9305 | case MVT::v2f64: |
| 9306 | // For any little-endian targets with neon, we can support unaligned ld/st |
| 9307 | // of D and Q (e.g. {D0,D1}) registers by using vld1.i8/vst1.i8. |
| 9308 | // A big-endian target may also explictly support unaligned accesses |
| 9309 | return Subtarget->hasNEON() && (AllowsUnaligned || isLittleEndian()); |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 9310 | } |
| 9311 | } |
| 9312 | |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 9313 | static bool memOpAlign(unsigned DstAlign, unsigned SrcAlign, |
| 9314 | unsigned AlignCheck) { |
| 9315 | return ((SrcAlign == 0 || SrcAlign % AlignCheck == 0) && |
| 9316 | (DstAlign == 0 || DstAlign % AlignCheck == 0)); |
| 9317 | } |
| 9318 | |
| 9319 | EVT ARMTargetLowering::getOptimalMemOpType(uint64_t Size, |
| 9320 | unsigned DstAlign, unsigned SrcAlign, |
Lang Hames | a1e7888 | 2011-11-02 23:37:04 +0000 | [diff] [blame] | 9321 | bool IsZeroVal, |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 9322 | bool MemcpyStrSrc, |
| 9323 | MachineFunction &MF) const { |
| 9324 | const Function *F = MF.getFunction(); |
| 9325 | |
| 9326 | // See if we can use NEON instructions for this... |
Lang Hames | a1e7888 | 2011-11-02 23:37:04 +0000 | [diff] [blame] | 9327 | if (IsZeroVal && |
Bill Wendling | 6765834 | 2012-10-09 07:45:08 +0000 | [diff] [blame] | 9328 | !F->getFnAttributes().hasAttribute(Attributes::NoImplicitFloat) && |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 9329 | Subtarget->hasNEON()) { |
| 9330 | if (memOpAlign(SrcAlign, DstAlign, 16) && Size >= 16) { |
| 9331 | return MVT::v4i32; |
| 9332 | } else if (memOpAlign(SrcAlign, DstAlign, 8) && Size >= 8) { |
| 9333 | return MVT::v2i32; |
| 9334 | } |
| 9335 | } |
| 9336 | |
Lang Hames | 5207bf2 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 9337 | // Lowering to i32/i16 if the size permits. |
| 9338 | if (Size >= 4) { |
| 9339 | return MVT::i32; |
| 9340 | } else if (Size >= 2) { |
| 9341 | return MVT::i16; |
| 9342 | } |
| 9343 | |
Lang Hames | 1a1d1fc | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 9344 | // Let the target-independent logic figure it out. |
| 9345 | return MVT::Other; |
| 9346 | } |
| 9347 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9348 | static bool isLegalT1AddressImmediate(int64_t V, EVT VT) { |
| 9349 | if (V < 0) |
| 9350 | return false; |
| 9351 | |
| 9352 | unsigned Scale = 1; |
| 9353 | switch (VT.getSimpleVT().SimpleTy) { |
| 9354 | default: return false; |
| 9355 | case MVT::i1: |
| 9356 | case MVT::i8: |
| 9357 | // Scale == 1; |
| 9358 | break; |
| 9359 | case MVT::i16: |
| 9360 | // Scale == 2; |
| 9361 | Scale = 2; |
| 9362 | break; |
| 9363 | case MVT::i32: |
| 9364 | // Scale == 4; |
| 9365 | Scale = 4; |
| 9366 | break; |
| 9367 | } |
| 9368 | |
| 9369 | if ((V & (Scale - 1)) != 0) |
| 9370 | return false; |
| 9371 | V /= Scale; |
| 9372 | return V == (V & ((1LL << 5) - 1)); |
| 9373 | } |
| 9374 | |
| 9375 | static bool isLegalT2AddressImmediate(int64_t V, EVT VT, |
| 9376 | const ARMSubtarget *Subtarget) { |
| 9377 | bool isNeg = false; |
| 9378 | if (V < 0) { |
| 9379 | isNeg = true; |
| 9380 | V = - V; |
| 9381 | } |
| 9382 | |
| 9383 | switch (VT.getSimpleVT().SimpleTy) { |
| 9384 | default: return false; |
| 9385 | case MVT::i1: |
| 9386 | case MVT::i8: |
| 9387 | case MVT::i16: |
| 9388 | case MVT::i32: |
| 9389 | // + imm12 or - imm8 |
| 9390 | if (isNeg) |
| 9391 | return V == (V & ((1LL << 8) - 1)); |
| 9392 | return V == (V & ((1LL << 12) - 1)); |
| 9393 | case MVT::f32: |
| 9394 | case MVT::f64: |
| 9395 | // Same as ARM mode. FIXME: NEON? |
| 9396 | if (!Subtarget->hasVFP2()) |
| 9397 | return false; |
| 9398 | if ((V & 3) != 0) |
| 9399 | return false; |
| 9400 | V >>= 2; |
| 9401 | return V == (V & ((1LL << 8) - 1)); |
| 9402 | } |
| 9403 | } |
| 9404 | |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9405 | /// isLegalAddressImmediate - Return true if the integer value can be used |
| 9406 | /// as the offset of the target addressing mode for load / store of the |
| 9407 | /// given type. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9408 | static bool isLegalAddressImmediate(int64_t V, EVT VT, |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9409 | const ARMSubtarget *Subtarget) { |
Evan Cheng | 961f879 | 2007-03-13 20:37:59 +0000 | [diff] [blame] | 9410 | if (V == 0) |
| 9411 | return true; |
| 9412 | |
Evan Cheng | 6501153 | 2009-03-09 19:15:00 +0000 | [diff] [blame] | 9413 | if (!VT.isSimple()) |
| 9414 | return false; |
| 9415 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9416 | if (Subtarget->isThumb1Only()) |
| 9417 | return isLegalT1AddressImmediate(V, VT); |
| 9418 | else if (Subtarget->isThumb2()) |
| 9419 | return isLegalT2AddressImmediate(V, VT, Subtarget); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9420 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9421 | // ARM mode. |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9422 | if (V < 0) |
| 9423 | V = - V; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9424 | switch (VT.getSimpleVT().SimpleTy) { |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9425 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9426 | case MVT::i1: |
| 9427 | case MVT::i8: |
| 9428 | case MVT::i32: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9429 | // +- imm12 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 9430 | return V == (V & ((1LL << 12) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9431 | case MVT::i16: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9432 | // +- imm8 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 9433 | return V == (V & ((1LL << 8) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9434 | case MVT::f32: |
| 9435 | case MVT::f64: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9436 | if (!Subtarget->hasVFP2()) // FIXME: NEON? |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9437 | return false; |
Evan Cheng | 0b0a9a9 | 2007-05-03 02:00:18 +0000 | [diff] [blame] | 9438 | if ((V & 3) != 0) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9439 | return false; |
| 9440 | V >>= 2; |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 9441 | return V == (V & ((1LL << 8) - 1)); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9442 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9443 | } |
| 9444 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9445 | bool ARMTargetLowering::isLegalT2ScaledAddressingMode(const AddrMode &AM, |
| 9446 | EVT VT) const { |
| 9447 | int Scale = AM.Scale; |
| 9448 | if (Scale < 0) |
| 9449 | return false; |
| 9450 | |
| 9451 | switch (VT.getSimpleVT().SimpleTy) { |
| 9452 | default: return false; |
| 9453 | case MVT::i1: |
| 9454 | case MVT::i8: |
| 9455 | case MVT::i16: |
| 9456 | case MVT::i32: |
| 9457 | if (Scale == 1) |
| 9458 | return true; |
| 9459 | // r + r << imm |
| 9460 | Scale = Scale & ~1; |
| 9461 | return Scale == 2 || Scale == 4 || Scale == 8; |
| 9462 | case MVT::i64: |
| 9463 | // r + r |
| 9464 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
| 9465 | return true; |
| 9466 | return false; |
| 9467 | case MVT::isVoid: |
| 9468 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 9469 | // stores), because arm allows folding a scale into many arithmetic |
| 9470 | // operations. This should be made more precise and revisited later. |
| 9471 | |
| 9472 | // Allow r << imm, but the imm has to be a multiple of two. |
| 9473 | if (Scale & 1) return false; |
| 9474 | return isPowerOf2_32(Scale); |
| 9475 | } |
| 9476 | } |
| 9477 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9478 | /// isLegalAddressingMode - Return true if the addressing mode represented |
| 9479 | /// 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] | 9480 | bool ARMTargetLowering::isLegalAddressingMode(const AddrMode &AM, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 9481 | Type *Ty) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9482 | EVT VT = getValueType(Ty, true); |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 9483 | if (!isLegalAddressImmediate(AM.BaseOffs, VT, Subtarget)) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9484 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9485 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9486 | // Can never fold addr of global into load/store. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9487 | if (AM.BaseGV) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9488 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9489 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9490 | switch (AM.Scale) { |
| 9491 | case 0: // no scale reg, must be "r+i" or "r", or "i". |
| 9492 | break; |
| 9493 | case 1: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9494 | if (Subtarget->isThumb1Only()) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9495 | return false; |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 9496 | // FALL THROUGH. |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9497 | default: |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 9498 | // ARM doesn't support any R+R*scale+imm addr modes. |
| 9499 | if (AM.BaseOffs) |
| 9500 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9501 | |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 9502 | if (!VT.isSimple()) |
| 9503 | return false; |
| 9504 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9505 | if (Subtarget->isThumb2()) |
| 9506 | return isLegalT2ScaledAddressingMode(AM, VT); |
| 9507 | |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 9508 | int Scale = AM.Scale; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9509 | switch (VT.getSimpleVT().SimpleTy) { |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9510 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9511 | case MVT::i1: |
| 9512 | case MVT::i8: |
| 9513 | case MVT::i32: |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 9514 | if (Scale < 0) Scale = -Scale; |
| 9515 | if (Scale == 1) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9516 | return true; |
| 9517 | // r + r << imm |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 9518 | return isPowerOf2_32(Scale & ~1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9519 | case MVT::i16: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9520 | case MVT::i64: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9521 | // r + r |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 9522 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9523 | return true; |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 9524 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9525 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9526 | case MVT::isVoid: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9527 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 9528 | // stores), because arm allows folding a scale into many arithmetic |
| 9529 | // operations. This should be made more precise and revisited later. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9530 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9531 | // 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] | 9532 | if (Scale & 1) return false; |
| 9533 | return isPowerOf2_32(Scale); |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9534 | } |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9535 | } |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 9536 | return true; |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 9537 | } |
| 9538 | |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 9539 | /// isLegalICmpImmediate - Return true if the specified immediate is legal |
| 9540 | /// icmp immediate, that is the target has icmp instructions which can compare |
| 9541 | /// a register against the immediate without having to materialize the |
| 9542 | /// immediate into a register. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 9543 | bool ARMTargetLowering::isLegalICmpImmediate(int64_t Imm) const { |
Jakob Stoklund Olesen | 70fbea7 | 2012-04-06 17:45:04 +0000 | [diff] [blame] | 9544 | // Thumb2 and ARM modes can use cmn for negative immediates. |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 9545 | if (!Subtarget->isThumb()) |
Chandler Carruth | ba4d457 | 2012-04-06 20:10:52 +0000 | [diff] [blame] | 9546 | return ARM_AM::getSOImmVal(llvm::abs64(Imm)) != -1; |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 9547 | if (Subtarget->isThumb2()) |
Chandler Carruth | ba4d457 | 2012-04-06 20:10:52 +0000 | [diff] [blame] | 9548 | return ARM_AM::getT2SOImmVal(llvm::abs64(Imm)) != -1; |
Jakob Stoklund Olesen | 70fbea7 | 2012-04-06 17:45:04 +0000 | [diff] [blame] | 9549 | // Thumb1 doesn't have cmn, and only 8-bit immediates. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 9550 | return Imm >= 0 && Imm <= 255; |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 9551 | } |
| 9552 | |
Andrew Trick | 8d8d961 | 2012-07-18 18:34:27 +0000 | [diff] [blame] | 9553 | /// isLegalAddImmediate - Return true if the specified immediate is a legal add |
| 9554 | /// *or sub* immediate, that is the target has add or sub instructions which can |
| 9555 | /// add a register with the immediate without having to materialize the |
Dan Gohman | cca8214 | 2011-05-03 00:46:49 +0000 | [diff] [blame] | 9556 | /// immediate into a register. |
| 9557 | bool ARMTargetLowering::isLegalAddImmediate(int64_t Imm) const { |
Andrew Trick | 8d8d961 | 2012-07-18 18:34:27 +0000 | [diff] [blame] | 9558 | // Same encoding for add/sub, just flip the sign. |
| 9559 | int64_t AbsImm = llvm::abs64(Imm); |
| 9560 | if (!Subtarget->isThumb()) |
| 9561 | return ARM_AM::getSOImmVal(AbsImm) != -1; |
| 9562 | if (Subtarget->isThumb2()) |
| 9563 | return ARM_AM::getT2SOImmVal(AbsImm) != -1; |
| 9564 | // Thumb1 only has 8-bit unsigned immediate. |
| 9565 | return AbsImm >= 0 && AbsImm <= 255; |
Dan Gohman | cca8214 | 2011-05-03 00:46:49 +0000 | [diff] [blame] | 9566 | } |
| 9567 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9568 | static bool getARMIndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9569 | bool isSEXTLoad, SDValue &Base, |
| 9570 | SDValue &Offset, bool &isInc, |
| 9571 | SelectionDAG &DAG) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9572 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 9573 | return false; |
| 9574 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9575 | if (VT == MVT::i16 || ((VT == MVT::i8 || VT == MVT::i1) && isSEXTLoad)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9576 | // AddressingMode 3 |
| 9577 | Base = Ptr->getOperand(0); |
| 9578 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 9579 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9580 | if (RHSC < 0 && RHSC > -256) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9581 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9582 | isInc = false; |
| 9583 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 9584 | return true; |
| 9585 | } |
| 9586 | } |
| 9587 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 9588 | Offset = Ptr->getOperand(1); |
| 9589 | return true; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9590 | } else if (VT == MVT::i32 || VT == MVT::i8 || VT == MVT::i1) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9591 | // AddressingMode 2 |
| 9592 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 9593 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9594 | if (RHSC < 0 && RHSC > -0x1000) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9595 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9596 | isInc = false; |
| 9597 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 9598 | Base = Ptr->getOperand(0); |
| 9599 | return true; |
| 9600 | } |
| 9601 | } |
| 9602 | |
| 9603 | if (Ptr->getOpcode() == ISD::ADD) { |
| 9604 | isInc = true; |
Evan Cheng | ee04a6d | 2011-07-20 23:34:39 +0000 | [diff] [blame] | 9605 | ARM_AM::ShiftOpc ShOpcVal= |
| 9606 | ARM_AM::getShiftOpcForNode(Ptr->getOperand(0).getOpcode()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9607 | if (ShOpcVal != ARM_AM::no_shift) { |
| 9608 | Base = Ptr->getOperand(1); |
| 9609 | Offset = Ptr->getOperand(0); |
| 9610 | } else { |
| 9611 | Base = Ptr->getOperand(0); |
| 9612 | Offset = Ptr->getOperand(1); |
| 9613 | } |
| 9614 | return true; |
| 9615 | } |
| 9616 | |
| 9617 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 9618 | Base = Ptr->getOperand(0); |
| 9619 | Offset = Ptr->getOperand(1); |
| 9620 | return true; |
| 9621 | } |
| 9622 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 9623 | // FIXME: Use VLDM / VSTM to emulate indexed FP load / store. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9624 | return false; |
| 9625 | } |
| 9626 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9627 | static bool getT2IndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9628 | bool isSEXTLoad, SDValue &Base, |
| 9629 | SDValue &Offset, bool &isInc, |
| 9630 | SelectionDAG &DAG) { |
| 9631 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 9632 | return false; |
| 9633 | |
| 9634 | Base = Ptr->getOperand(0); |
| 9635 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
| 9636 | int RHSC = (int)RHS->getZExtValue(); |
| 9637 | if (RHSC < 0 && RHSC > -0x100) { // 8 bits. |
| 9638 | assert(Ptr->getOpcode() == ISD::ADD); |
| 9639 | isInc = false; |
| 9640 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 9641 | return true; |
| 9642 | } else if (RHSC > 0 && RHSC < 0x100) { // 8 bit, no zero. |
| 9643 | isInc = Ptr->getOpcode() == ISD::ADD; |
| 9644 | Offset = DAG.getConstant(RHSC, RHS->getValueType(0)); |
| 9645 | return true; |
| 9646 | } |
| 9647 | } |
| 9648 | |
| 9649 | return false; |
| 9650 | } |
| 9651 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9652 | /// getPreIndexedAddressParts - returns true by value, base pointer and |
| 9653 | /// offset pointer and addressing mode by reference if the node's address |
| 9654 | /// can be legally represented as pre-indexed load / store address. |
| 9655 | bool |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 9656 | ARMTargetLowering::getPreIndexedAddressParts(SDNode *N, SDValue &Base, |
| 9657 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9658 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 9659 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9660 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9661 | return false; |
| 9662 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9663 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 9664 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9665 | bool isSEXTLoad = false; |
| 9666 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
| 9667 | Ptr = LD->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 9668 | VT = LD->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9669 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 9670 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
| 9671 | Ptr = ST->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 9672 | VT = ST->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9673 | } else |
| 9674 | return false; |
| 9675 | |
| 9676 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9677 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9678 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9679 | isLegal = getT2IndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
| 9680 | Offset, isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 9681 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9682 | isLegal = getARMIndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
Evan Cheng | 0412957 | 2009-07-02 06:44:30 +0000 | [diff] [blame] | 9683 | Offset, isInc, DAG); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9684 | if (!isLegal) |
| 9685 | return false; |
| 9686 | |
| 9687 | AM = isInc ? ISD::PRE_INC : ISD::PRE_DEC; |
| 9688 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9689 | } |
| 9690 | |
| 9691 | /// getPostIndexedAddressParts - returns true by value, base pointer and |
| 9692 | /// offset pointer and addressing mode by reference if this node can be |
| 9693 | /// combined with a load / store to form a post-indexed load / store. |
| 9694 | bool ARMTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 9695 | SDValue &Base, |
| 9696 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9697 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 9698 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9699 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9700 | return false; |
| 9701 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9702 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 9703 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9704 | bool isSEXTLoad = false; |
| 9705 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 9706 | VT = LD->getMemoryVT(); |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 9707 | Ptr = LD->getBasePtr(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9708 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 9709 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 9710 | VT = ST->getMemoryVT(); |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 9711 | Ptr = ST->getBasePtr(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9712 | } else |
| 9713 | return false; |
| 9714 | |
| 9715 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9716 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 9717 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9718 | isLegal = getT2IndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 9719 | isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 9720 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9721 | isLegal = getARMIndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
| 9722 | isInc, DAG); |
| 9723 | if (!isLegal) |
| 9724 | return false; |
| 9725 | |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 9726 | if (Ptr != Base) { |
| 9727 | // Swap base ptr and offset to catch more post-index load / store when |
| 9728 | // it's legal. In Thumb2 mode, offset must be an immediate. |
| 9729 | if (Ptr == Offset && Op->getOpcode() == ISD::ADD && |
| 9730 | !Subtarget->isThumb2()) |
| 9731 | std::swap(Base, Offset); |
| 9732 | |
| 9733 | // Post-indexed load / store update the base pointer. |
| 9734 | if (Ptr != Base) |
| 9735 | return false; |
| 9736 | } |
| 9737 | |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 9738 | AM = isInc ? ISD::POST_INC : ISD::POST_DEC; |
| 9739 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9740 | } |
| 9741 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 9742 | void ARMTargetLowering::computeMaskedBitsForTargetNode(const SDValue Op, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 9743 | APInt &KnownZero, |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 9744 | APInt &KnownOne, |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 9745 | const SelectionDAG &DAG, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9746 | unsigned Depth) const { |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 9747 | KnownZero = KnownOne = APInt(KnownOne.getBitWidth(), 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9748 | switch (Op.getOpcode()) { |
| 9749 | default: break; |
| 9750 | case ARMISD::CMOV: { |
| 9751 | // Bits are known zero/one if known on the LHS and RHS. |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 9752 | DAG.ComputeMaskedBits(Op.getOperand(0), KnownZero, KnownOne, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9753 | if (KnownZero == 0 && KnownOne == 0) return; |
| 9754 | |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 9755 | APInt KnownZeroRHS, KnownOneRHS; |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 9756 | DAG.ComputeMaskedBits(Op.getOperand(1), KnownZeroRHS, KnownOneRHS, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9757 | KnownZero &= KnownZeroRHS; |
| 9758 | KnownOne &= KnownOneRHS; |
| 9759 | return; |
| 9760 | } |
| 9761 | } |
| 9762 | } |
| 9763 | |
| 9764 | //===----------------------------------------------------------------------===// |
| 9765 | // ARM Inline Assembly Support |
| 9766 | //===----------------------------------------------------------------------===// |
| 9767 | |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 9768 | bool ARMTargetLowering::ExpandInlineAsm(CallInst *CI) const { |
| 9769 | // Looking for "rev" which is V6+. |
| 9770 | if (!Subtarget->hasV6Ops()) |
| 9771 | return false; |
| 9772 | |
| 9773 | InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue()); |
| 9774 | std::string AsmStr = IA->getAsmString(); |
| 9775 | SmallVector<StringRef, 4> AsmPieces; |
| 9776 | SplitString(AsmStr, AsmPieces, ";\n"); |
| 9777 | |
| 9778 | switch (AsmPieces.size()) { |
| 9779 | default: return false; |
| 9780 | case 1: |
| 9781 | AsmStr = AsmPieces[0]; |
| 9782 | AsmPieces.clear(); |
| 9783 | SplitString(AsmStr, AsmPieces, " \t,"); |
| 9784 | |
| 9785 | // rev $0, $1 |
| 9786 | if (AsmPieces.size() == 3 && |
| 9787 | AsmPieces[0] == "rev" && AsmPieces[1] == "$0" && AsmPieces[2] == "$1" && |
| 9788 | IA->getConstraintString().compare(0, 4, "=l,l") == 0) { |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 9789 | IntegerType *Ty = dyn_cast<IntegerType>(CI->getType()); |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 9790 | if (Ty && Ty->getBitWidth() == 32) |
| 9791 | return IntrinsicLowering::LowerToByteSwap(CI); |
| 9792 | } |
| 9793 | break; |
| 9794 | } |
| 9795 | |
| 9796 | return false; |
| 9797 | } |
| 9798 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9799 | /// getConstraintType - Given a constraint letter, return the type of |
| 9800 | /// constraint it is for this target. |
| 9801 | ARMTargetLowering::ConstraintType |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 9802 | ARMTargetLowering::getConstraintType(const std::string &Constraint) const { |
| 9803 | if (Constraint.size() == 1) { |
| 9804 | switch (Constraint[0]) { |
| 9805 | default: break; |
| 9806 | case 'l': return C_RegisterClass; |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 9807 | case 'w': return C_RegisterClass; |
Eric Christopher | 73744df | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 9808 | case 'h': return C_RegisterClass; |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 9809 | case 'x': return C_RegisterClass; |
Eric Christopher | d5dc9ec | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 9810 | case 't': return C_RegisterClass; |
Eric Christopher | 5e653c9 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 9811 | case 'j': return C_Other; // Constant for movw. |
Eric Christopher | ef7f1e7 | 2011-07-29 21:18:58 +0000 | [diff] [blame] | 9812 | // An address with a single base register. Due to the way we |
| 9813 | // currently handle addresses it is the same as an 'r' memory constraint. |
| 9814 | case 'Q': return C_Memory; |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 9815 | } |
Eric Christopher | 1312ca8 | 2011-06-21 22:10:57 +0000 | [diff] [blame] | 9816 | } else if (Constraint.size() == 2) { |
| 9817 | switch (Constraint[0]) { |
| 9818 | default: break; |
| 9819 | // All 'U+' constraints are addresses. |
| 9820 | case 'U': return C_Memory; |
| 9821 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9822 | } |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 9823 | return TargetLowering::getConstraintType(Constraint); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9824 | } |
| 9825 | |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 9826 | /// Examine constraint type and operand type and determine a weight value. |
| 9827 | /// This object must already have been set up with the operand type |
| 9828 | /// and the current alternative constraint selected. |
| 9829 | TargetLowering::ConstraintWeight |
| 9830 | ARMTargetLowering::getSingleConstraintMatchWeight( |
| 9831 | AsmOperandInfo &info, const char *constraint) const { |
| 9832 | ConstraintWeight weight = CW_Invalid; |
| 9833 | Value *CallOperandVal = info.CallOperandVal; |
| 9834 | // If we don't have a value, we can't do a match, |
| 9835 | // but allow it at the lowest weight. |
| 9836 | if (CallOperandVal == NULL) |
| 9837 | return CW_Default; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 9838 | Type *type = CallOperandVal->getType(); |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 9839 | // Look at the constraint type. |
| 9840 | switch (*constraint) { |
| 9841 | default: |
| 9842 | weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint); |
| 9843 | break; |
| 9844 | case 'l': |
| 9845 | if (type->isIntegerTy()) { |
| 9846 | if (Subtarget->isThumb()) |
| 9847 | weight = CW_SpecificReg; |
| 9848 | else |
| 9849 | weight = CW_Register; |
| 9850 | } |
| 9851 | break; |
| 9852 | case 'w': |
| 9853 | if (type->isFloatingPointTy()) |
| 9854 | weight = CW_Register; |
| 9855 | break; |
| 9856 | } |
| 9857 | return weight; |
| 9858 | } |
| 9859 | |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 9860 | typedef std::pair<unsigned, const TargetRegisterClass*> RCPair; |
| 9861 | RCPair |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9862 | ARMTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9863 | EVT VT) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9864 | if (Constraint.size() == 1) { |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 9865 | // GCC ARM Constraint Letters |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9866 | switch (Constraint[0]) { |
Eric Christopher | 73744df | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 9867 | case 'l': // Low regs or general regs. |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 9868 | if (Subtarget->isThumb()) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 9869 | return RCPair(0U, &ARM::tGPRRegClass); |
| 9870 | return RCPair(0U, &ARM::GPRRegClass); |
Eric Christopher | 73744df | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 9871 | case 'h': // High regs or no regs. |
| 9872 | if (Subtarget->isThumb()) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 9873 | return RCPair(0U, &ARM::hGPRRegClass); |
Eric Christopher | 1070f82 | 2011-07-01 00:19:27 +0000 | [diff] [blame] | 9874 | break; |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 9875 | case 'r': |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 9876 | return RCPair(0U, &ARM::GPRRegClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 9877 | case 'w': |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 9878 | if (VT == MVT::f32) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 9879 | return RCPair(0U, &ARM::SPRRegClass); |
Bob Wilson | 5afffae | 2009-12-18 01:03:29 +0000 | [diff] [blame] | 9880 | if (VT.getSizeInBits() == 64) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 9881 | return RCPair(0U, &ARM::DPRRegClass); |
Evan Cheng | d831cda | 2009-12-08 23:06:22 +0000 | [diff] [blame] | 9882 | if (VT.getSizeInBits() == 128) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 9883 | return RCPair(0U, &ARM::QPRRegClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 9884 | break; |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 9885 | case 'x': |
| 9886 | if (VT == MVT::f32) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 9887 | return RCPair(0U, &ARM::SPR_8RegClass); |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 9888 | if (VT.getSizeInBits() == 64) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 9889 | return RCPair(0U, &ARM::DPR_8RegClass); |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 9890 | if (VT.getSizeInBits() == 128) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 9891 | return RCPair(0U, &ARM::QPR_8RegClass); |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 9892 | break; |
Eric Christopher | d5dc9ec | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 9893 | case 't': |
| 9894 | if (VT == MVT::f32) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 9895 | return RCPair(0U, &ARM::SPRRegClass); |
Eric Christopher | d5dc9ec | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 9896 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9897 | } |
| 9898 | } |
Bob Wilson | 33cc5cb | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 9899 | if (StringRef("{cc}").equals_lower(Constraint)) |
Craig Topper | 420761a | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 9900 | return std::make_pair(unsigned(ARM::CPSR), &ARM::CCRRegClass); |
Bob Wilson | 33cc5cb | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 9901 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 9902 | return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); |
| 9903 | } |
| 9904 | |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9905 | /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops |
| 9906 | /// vector. If it is invalid, don't add anything to Ops. |
| 9907 | void ARMTargetLowering::LowerAsmOperandForConstraint(SDValue Op, |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 9908 | std::string &Constraint, |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9909 | std::vector<SDValue>&Ops, |
| 9910 | SelectionDAG &DAG) const { |
| 9911 | SDValue Result(0, 0); |
| 9912 | |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 9913 | // Currently only support length 1 constraints. |
| 9914 | if (Constraint.length() != 1) return; |
Eric Christopher | 471e422 | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 9915 | |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 9916 | char ConstraintLetter = Constraint[0]; |
| 9917 | switch (ConstraintLetter) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9918 | default: break; |
Eric Christopher | 5e653c9 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 9919 | case 'j': |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9920 | case 'I': case 'J': case 'K': case 'L': |
| 9921 | case 'M': case 'N': case 'O': |
| 9922 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op); |
| 9923 | if (!C) |
| 9924 | return; |
| 9925 | |
| 9926 | int64_t CVal64 = C->getSExtValue(); |
| 9927 | int CVal = (int) CVal64; |
| 9928 | // None of these constraints allow values larger than 32 bits. Check |
| 9929 | // that the value fits in an int. |
| 9930 | if (CVal != CVal64) |
| 9931 | return; |
| 9932 | |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 9933 | switch (ConstraintLetter) { |
Eric Christopher | 5e653c9 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 9934 | case 'j': |
Andrew Trick | 3af7a67 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 9935 | // Constant suitable for movw, must be between 0 and |
| 9936 | // 65535. |
| 9937 | if (Subtarget->hasV6T2Ops()) |
| 9938 | if (CVal >= 0 && CVal <= 65535) |
| 9939 | break; |
| 9940 | return; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9941 | case 'I': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9942 | if (Subtarget->isThumb1Only()) { |
| 9943 | // This must be a constant between 0 and 255, for ADD |
| 9944 | // immediates. |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9945 | if (CVal >= 0 && CVal <= 255) |
| 9946 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9947 | } else if (Subtarget->isThumb2()) { |
| 9948 | // A constant that can be used as an immediate value in a |
| 9949 | // data-processing instruction. |
| 9950 | if (ARM_AM::getT2SOImmVal(CVal) != -1) |
| 9951 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9952 | } else { |
| 9953 | // A constant that can be used as an immediate value in a |
| 9954 | // data-processing instruction. |
| 9955 | if (ARM_AM::getSOImmVal(CVal) != -1) |
| 9956 | break; |
| 9957 | } |
| 9958 | return; |
| 9959 | |
| 9960 | case 'J': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9961 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9962 | // This must be a constant between -255 and -1, for negated ADD |
| 9963 | // immediates. This can be used in GCC with an "n" modifier that |
| 9964 | // prints the negated value, for use with SUB instructions. It is |
| 9965 | // not useful otherwise but is implemented for compatibility. |
| 9966 | if (CVal >= -255 && CVal <= -1) |
| 9967 | break; |
| 9968 | } else { |
| 9969 | // This must be a constant between -4095 and 4095. It is not clear |
| 9970 | // what this constraint is intended for. Implemented for |
| 9971 | // compatibility with GCC. |
| 9972 | if (CVal >= -4095 && CVal <= 4095) |
| 9973 | break; |
| 9974 | } |
| 9975 | return; |
| 9976 | |
| 9977 | case 'K': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9978 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9979 | // A 32-bit value where only one byte has a nonzero value. Exclude |
| 9980 | // zero to match GCC. This constraint is used by GCC internally for |
| 9981 | // constants that can be loaded with a move/shift combination. |
| 9982 | // It is not useful otherwise but is implemented for compatibility. |
| 9983 | if (CVal != 0 && ARM_AM::isThumbImmShiftedVal(CVal)) |
| 9984 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 9985 | } else if (Subtarget->isThumb2()) { |
| 9986 | // A constant whose bitwise inverse can be used as an immediate |
| 9987 | // value in a data-processing instruction. This can be used in GCC |
| 9988 | // with a "B" modifier that prints the inverted value, for use with |
| 9989 | // BIC and MVN instructions. It is not useful otherwise but is |
| 9990 | // implemented for compatibility. |
| 9991 | if (ARM_AM::getT2SOImmVal(~CVal) != -1) |
| 9992 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 9993 | } else { |
| 9994 | // A constant whose bitwise inverse can be used as an immediate |
| 9995 | // value in a data-processing instruction. This can be used in GCC |
| 9996 | // with a "B" modifier that prints the inverted value, for use with |
| 9997 | // BIC and MVN instructions. It is not useful otherwise but is |
| 9998 | // implemented for compatibility. |
| 9999 | if (ARM_AM::getSOImmVal(~CVal) != -1) |
| 10000 | break; |
| 10001 | } |
| 10002 | return; |
| 10003 | |
| 10004 | case 'L': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10005 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10006 | // This must be a constant between -7 and 7, |
| 10007 | // for 3-operand ADD/SUB immediate instructions. |
| 10008 | if (CVal >= -7 && CVal < 7) |
| 10009 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10010 | } else if (Subtarget->isThumb2()) { |
| 10011 | // A constant whose negation can be used as an immediate value in a |
| 10012 | // data-processing instruction. This can be used in GCC with an "n" |
| 10013 | // modifier that prints the negated value, for use with SUB |
| 10014 | // instructions. It is not useful otherwise but is implemented for |
| 10015 | // compatibility. |
| 10016 | if (ARM_AM::getT2SOImmVal(-CVal) != -1) |
| 10017 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10018 | } else { |
| 10019 | // A constant whose negation can be used as an immediate value in a |
| 10020 | // data-processing instruction. This can be used in GCC with an "n" |
| 10021 | // modifier that prints the negated value, for use with SUB |
| 10022 | // instructions. It is not useful otherwise but is implemented for |
| 10023 | // compatibility. |
| 10024 | if (ARM_AM::getSOImmVal(-CVal) != -1) |
| 10025 | break; |
| 10026 | } |
| 10027 | return; |
| 10028 | |
| 10029 | case 'M': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10030 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10031 | // This must be a multiple of 4 between 0 and 1020, for |
| 10032 | // ADD sp + immediate. |
| 10033 | if ((CVal >= 0 && CVal <= 1020) && ((CVal & 3) == 0)) |
| 10034 | break; |
| 10035 | } else { |
| 10036 | // A power of two or a constant between 0 and 32. This is used in |
| 10037 | // GCC for the shift amount on shifted register operands, but it is |
| 10038 | // useful in general for any shift amounts. |
| 10039 | if ((CVal >= 0 && CVal <= 32) || ((CVal & (CVal - 1)) == 0)) |
| 10040 | break; |
| 10041 | } |
| 10042 | return; |
| 10043 | |
| 10044 | case 'N': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10045 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10046 | // This must be a constant between 0 and 31, for shift amounts. |
| 10047 | if (CVal >= 0 && CVal <= 31) |
| 10048 | break; |
| 10049 | } |
| 10050 | return; |
| 10051 | |
| 10052 | case 'O': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 10053 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10054 | // This must be a multiple of 4 between -508 and 508, for |
| 10055 | // ADD/SUB sp = sp + immediate. |
| 10056 | if ((CVal >= -508 && CVal <= 508) && ((CVal & 3) == 0)) |
| 10057 | break; |
| 10058 | } |
| 10059 | return; |
| 10060 | } |
| 10061 | Result = DAG.getTargetConstant(CVal, Op.getValueType()); |
| 10062 | break; |
| 10063 | } |
| 10064 | |
| 10065 | if (Result.getNode()) { |
| 10066 | Ops.push_back(Result); |
| 10067 | return; |
| 10068 | } |
Dale Johannesen | 1784d16 | 2010-06-25 21:55:36 +0000 | [diff] [blame] | 10069 | return TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG); |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 10070 | } |
Anton Korobeynikov | 48e1935 | 2009-09-23 19:04:09 +0000 | [diff] [blame] | 10071 | |
| 10072 | bool |
| 10073 | ARMTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { |
| 10074 | // The ARM target isn't yet aware of offsets. |
| 10075 | return false; |
| 10076 | } |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 10077 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 10078 | bool ARM::isBitFieldInvertedMask(unsigned v) { |
| 10079 | if (v == 0xffffffff) |
| 10080 | return 0; |
| 10081 | // there can be 1's on either or both "outsides", all the "inside" |
| 10082 | // bits must be 0's |
| 10083 | unsigned int lsb = 0, msb = 31; |
| 10084 | while (v & (1 << msb)) --msb; |
| 10085 | while (v & (1 << lsb)) ++lsb; |
| 10086 | for (unsigned int i = lsb; i <= msb; ++i) { |
| 10087 | if (v & (1 << i)) |
| 10088 | return 0; |
| 10089 | } |
| 10090 | return 1; |
| 10091 | } |
| 10092 | |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 10093 | /// isFPImmLegal - Returns true if the target can instruction select the |
| 10094 | /// specified FP immediate natively. If false, the legalizer will |
| 10095 | /// materialize the FP immediate as a load from a constant pool. |
| 10096 | bool ARMTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const { |
| 10097 | if (!Subtarget->hasVFP3()) |
| 10098 | return false; |
| 10099 | if (VT == MVT::f32) |
Jim Grosbach | 4ebbf7b | 2011-09-30 00:50:06 +0000 | [diff] [blame] | 10100 | return ARM_AM::getFP32Imm(Imm) != -1; |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 10101 | if (VT == MVT::f64) |
Jim Grosbach | 4ebbf7b | 2011-09-30 00:50:06 +0000 | [diff] [blame] | 10102 | return ARM_AM::getFP64Imm(Imm) != -1; |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 10103 | return false; |
| 10104 | } |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 10105 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 10106 | /// getTgtMemIntrinsic - Represent NEON load and store intrinsics as |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 10107 | /// MemIntrinsicNodes. The associated MachineMemOperands record the alignment |
| 10108 | /// specified in the intrinsic calls. |
| 10109 | bool ARMTargetLowering::getTgtMemIntrinsic(IntrinsicInfo &Info, |
| 10110 | const CallInst &I, |
| 10111 | unsigned Intrinsic) const { |
| 10112 | switch (Intrinsic) { |
| 10113 | case Intrinsic::arm_neon_vld1: |
| 10114 | case Intrinsic::arm_neon_vld2: |
| 10115 | case Intrinsic::arm_neon_vld3: |
| 10116 | case Intrinsic::arm_neon_vld4: |
| 10117 | case Intrinsic::arm_neon_vld2lane: |
| 10118 | case Intrinsic::arm_neon_vld3lane: |
| 10119 | case Intrinsic::arm_neon_vld4lane: { |
| 10120 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 10121 | // Conservatively set memVT to the entire set of vectors loaded. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 10122 | uint64_t NumElts = getDataLayout()->getTypeAllocSize(I.getType()) / 8; |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 10123 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 10124 | Info.ptrVal = I.getArgOperand(0); |
| 10125 | Info.offset = 0; |
| 10126 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 10127 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 10128 | Info.vol = false; // volatile loads with NEON intrinsics not supported |
| 10129 | Info.readMem = true; |
| 10130 | Info.writeMem = false; |
| 10131 | return true; |
| 10132 | } |
| 10133 | case Intrinsic::arm_neon_vst1: |
| 10134 | case Intrinsic::arm_neon_vst2: |
| 10135 | case Intrinsic::arm_neon_vst3: |
| 10136 | case Intrinsic::arm_neon_vst4: |
| 10137 | case Intrinsic::arm_neon_vst2lane: |
| 10138 | case Intrinsic::arm_neon_vst3lane: |
| 10139 | case Intrinsic::arm_neon_vst4lane: { |
| 10140 | Info.opc = ISD::INTRINSIC_VOID; |
| 10141 | // Conservatively set memVT to the entire set of vectors stored. |
| 10142 | unsigned NumElts = 0; |
| 10143 | for (unsigned ArgI = 1, ArgE = I.getNumArgOperands(); ArgI < ArgE; ++ArgI) { |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 10144 | Type *ArgTy = I.getArgOperand(ArgI)->getType(); |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 10145 | if (!ArgTy->isVectorTy()) |
| 10146 | break; |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 10147 | NumElts += getDataLayout()->getTypeAllocSize(ArgTy) / 8; |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 10148 | } |
| 10149 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 10150 | Info.ptrVal = I.getArgOperand(0); |
| 10151 | Info.offset = 0; |
| 10152 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 10153 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 10154 | Info.vol = false; // volatile stores with NEON intrinsics not supported |
| 10155 | Info.readMem = false; |
| 10156 | Info.writeMem = true; |
| 10157 | return true; |
| 10158 | } |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 10159 | case Intrinsic::arm_strexd: { |
| 10160 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 10161 | Info.memVT = MVT::i64; |
| 10162 | Info.ptrVal = I.getArgOperand(2); |
| 10163 | Info.offset = 0; |
| 10164 | Info.align = 8; |
Bruno Cardoso Lopes | c75448c | 2011-06-16 18:11:32 +0000 | [diff] [blame] | 10165 | Info.vol = true; |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 10166 | Info.readMem = false; |
| 10167 | Info.writeMem = true; |
| 10168 | return true; |
| 10169 | } |
| 10170 | case Intrinsic::arm_ldrexd: { |
| 10171 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 10172 | Info.memVT = MVT::i64; |
| 10173 | Info.ptrVal = I.getArgOperand(0); |
| 10174 | Info.offset = 0; |
| 10175 | Info.align = 8; |
Bruno Cardoso Lopes | c75448c | 2011-06-16 18:11:32 +0000 | [diff] [blame] | 10176 | Info.vol = true; |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 10177 | Info.readMem = true; |
| 10178 | Info.writeMem = false; |
| 10179 | return true; |
| 10180 | } |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 10181 | default: |
| 10182 | break; |
| 10183 | } |
| 10184 | |
| 10185 | return false; |
| 10186 | } |